A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
7
Task/Search-a-list/J/search-a-list-1.j
Normal file
7
Task/Search-a-list/J/search-a-list-1.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Haystack =: ;:'Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo'
|
||||
Needles =: ;:'Washington Bush'
|
||||
|
||||
Haystack i. Needles NB. first positions
|
||||
9 4
|
||||
Haystack i: Needles NB. last positions
|
||||
9 7
|
||||
3
Task/Search-a-list/J/search-a-list-2.j
Normal file
3
Task/Search-a-list/J/search-a-list-2.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Haystack ;:^:_1@(] ,. [ ((<'is not in haystack')"_)`(#@[ I.@:= ])`(8!:0@])} i.) Needles
|
||||
Washington is not in haystack
|
||||
Bush 4
|
||||
8
Task/Search-a-list/J/search-a-list-3.j
Normal file
8
Task/Search-a-list/J/search-a-list-3.j
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
msg=: (<'is not in haystack')"_ NB. not found message
|
||||
idxmissing=: #@[ I.@:= ] NB. indices of items not found
|
||||
fmtdata=: 8!:0@] NB. format atoms as boxed strings
|
||||
findLastIndex=: ;:inv@(] ,. [ msg`idxmissing`fmtdata} i:)
|
||||
|
||||
Haystack findLastIndex Needles NB. usage
|
||||
Washington is not in haystack
|
||||
Bush 7
|
||||
Loading…
Add table
Add a link
Reference in a new issue