March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,9 @@
haystack: ["Zig","Zag","Wally","Ronald","Bush","Zig","Zag","Krusty","Charlie","Bush","Bozo"];
needle: "Zag";
findneedle(needle, haystack, [opt]):=block([idx],
idx: sublist_indices(haystack, lambda([w], w=needle)),
if emptyp(idx) then throw('notfound),
if emptyp(opt) then return(idx),
opt: first(opt),
if opt='f then first(idx) else if opt='l then last(idx) else throw('unknownmode));

View file

@ -0,0 +1,12 @@
(%i32) catch(findneedle("Zag", haystack, 'f));
(%o32) 2
(%i33) catch(findneedle("Zag", haystack, 'l));
(%o33) 7
(%i34) catch(findneedle("Washington", haystack));
(%o34) notfound
(%i35) catch(findneedle("Bush", haystack, 'f));
(%o35) 5
(%i36) catch(findneedle("Zag", haystack));
(%o36) [2, 7]
(%i37) catch(findneedle("Zag", haystack, 'l));
(%o37) 7

View file

@ -0,0 +1,8 @@
NSArray *haystack = @[@"Zig",@"Zag",@"Wally",@"Ronald",@"Bush",@"Krusty",@"Charlie",@"Bush",@"Bozo"];
for (id needle in @[@"Washington",@"Bush"]) {
int index = [haystack indexOfObject:needle];
if (index == NSNotFound)
NSLog(@"%@ is not in haystack", needle);
else
NSLog(@"%i %@", index, needle);
}