Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Search-a-list/Smalltalk/search-a-list-1.st
Normal file
15
Task/Search-a-list/Smalltalk/search-a-list-1.st
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
| haystack |
|
||||
haystack := 'Zig,Zag,Wally,Ronald,Bush,Krusty,Charlie,Bush,Bozo' subStrings: $,.
|
||||
{ 'Washington' . 'Bush' } do: [:word |
|
||||
|t|
|
||||
|
||||
((t := haystack indexOf: word) = 0)
|
||||
ifTrue: [ ('%1 is not in the haystack' % { word }) displayNl ]
|
||||
ifFalse: [
|
||||
|l|
|
||||
('%1 is at index %2' % { word . t }) displayNl.
|
||||
l := ( (haystack size) - (haystack reverse indexOf: word) + 1 ).
|
||||
( t = l ) ifFalse: [
|
||||
('last occurence of %1 is at index %2' % { word . l }) displayNl ]
|
||||
]
|
||||
].
|
||||
22
Task/Search-a-list/Smalltalk/search-a-list-2.st
Normal file
22
Task/Search-a-list/Smalltalk/search-a-list-2.st
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
| haystack |
|
||||
haystack := 'Zig,Zag,Wally,Ronald,Bush,Krusty,Charlie,Bush,Bozo' subStrings: $,.
|
||||
[
|
||||
{ 'Washington' . 'Bush' . 'Ronald' } do: [:word |
|
||||
|firstIdx lastIdx|
|
||||
|
||||
firstIdx := haystack
|
||||
indexOf:word
|
||||
ifAbsent:[
|
||||
ProceedableError raiseRequestWith:word errorString:'not found'.
|
||||
0
|
||||
].
|
||||
firstIdx = 0 ifFalse:[
|
||||
(lastIdx := haystack lastIndexOf:word) = firstIdx
|
||||
ifTrue:[ e'the first index of {word} is {firstIdx}' printCR ]
|
||||
ifFalse:[ e'the last index of {word} is {lastIdx}' printCR ]]
|
||||
]
|
||||
] on:Error do:[:ex |
|
||||
e'{ex description} exception raised for: {ex parameter}' printCR.
|
||||
'but I don''t care and proceed...' printCR.
|
||||
ex proceed.
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue