Thanks Michal
I'm getting a nice introduction chapter on iterators driven by little
exercises.
Le 12/11/16 à 13:30, Michal Balda a écrit :
Hi,
#isPangramIn: should probably use #asLowercase as well:
'The quick brown fox jumps over a lazy dog' isEnglishPangram "false --
now the $t is missing, there is only $T"
Kicking things off, here are my solutions:
isPangramAllSatisfyIn: alphabet "Just a small change to the original."
| lowercase | lowercase := self asLowercase. ^ alphabet
allSatisfy: [ :aChar | lowercase includes: aChar ]
isPangramCopyWithoutAllIn: alphabet ^ (alphabet copyWithoutAll:
self asLowercase) isEmpty
isPangramDifferenceIn: alphabet ^ (alphabet difference: self
asLowercase) isEmpty
The performance:
[ 'The quick brown fox jumps over the lazy dog' isPangramIn:
'abcdefghijklmnopqrstuvwxyz' ] bench. "182,096 per second (I added
#asLowercase here as well)" [ 'The quick brown fox jumps over the lazy
dog' isPangramAllSatisfyIn: 'abcdefghijklmnopqrstuvwxyz' ] bench.
"159,546 per second" [ 'The quick brown fox jumps over the lazy dog'
isPangramCopyWithoutAllIn: 'abcdefghijklmnopqrstuvwxyz' ] bench.
"159,850 per second" [ 'The quick brown fox jumps over the lazy dog'
isPangramDifferenceIn: 'abcdefghijklmnopqrstuvwxyz' ] bench. "25,400
per second"
Michal
On 12.11.2016 09:07, stepharo wrote:
Hi
If you have some comments :)
Stef and Thibaut
testIsEnglishPangram
self assert: 'the quick brown fox jumps over the lazy dog'
isEnglishPangram.
self assert: 'the five boxing wizards jump quickly'
isEnglishPangram.
self deny: 'the quick brown fox jumps over the dog'
isEnglishPangram.
testIsPangramIn
self assert: ('The quick brown fox jumps over the lazy dog'
isPangramIn: 'abcdefghijklmnopqrstuvwxyz').
self assert: ('ma papa mama' isPangramIn: 'apm').
[[[
'portez ce vieux whisky au juge blond qui fume' isEnglishPangram
>>> true
'portons dix bons whiskys à l''avocat goujat qui fume au zoo.'
isEnglishPangram
>>> true
]]]
isEnglishPangram
"Returns true is the receiver is a pangram i.e., that it uses all
the characters of a given alphabet."
"'The quick brown fox jumps over the lazy dog' isEnglishPangram
>>> true"
"'The quick brown fox jumps over the dog' isEnglishPangram
>>> false"
^ self isPangramIn: 'abcdefghijklmnopqrstuvwxyz'.
isPangramIn: alphabet
"Returns true is the receiver is a pangram i.e., that it uses all
the characters of a given alphabet."
"'The quick brown fox jumps over the lazy dog' isPangramIn:
'abcdefghijklmnopqrstuvwxyz'
>>> true"
"'tata' isPangramIn: 'at'
>>> true"
alphabet do: [ :aChar |
(self includes: aChar)
ifFalse: [ ^ false ]
].
^ true