March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
9
Task/Search-a-list/Maxima/search-a-list-1.maxima
Normal file
9
Task/Search-a-list/Maxima/search-a-list-1.maxima
Normal 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));
|
||||
12
Task/Search-a-list/Maxima/search-a-list-2.maxima
Normal file
12
Task/Search-a-list/Maxima/search-a-list-2.maxima
Normal 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
|
||||
8
Task/Search-a-list/Objective-C/search-a-list.m
Normal file
8
Task/Search-a-list/Objective-C/search-a-list.m
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue