Package Palindrome

Preinstall script

Postinstall script

Preuninstall script

Postuninstall script

Class hierarchy
Object
	Collection
		SequenceableCollection
			ArrayedCollection
	Palindrome
Loose methods
ArrayedCollection>>isBidirectionalWithEqualCondition: anEqualConditionBlock andSkipCondition: aSkipConditionBlock

	| forwardIndex reverseIndex |
	forwardIndex := 1.
	reverseIndex := self size.
	[ forwardIndex < reverseIndex ] whileTrue: [
		(anEqualConditionBlock value: (self at: forwardIndex) value: (self at: reverseIndex)) ifFalse: [
			^false.
		].
		forwardIndex := forwardIndex + 1.
		reverseIndex := reverseIndex - 1.
		[ forwardIndex < reverseIndex and: [ aSkipConditionBlock value: (self at: forwardIndex) ] ] whileTrue: [
			forwardIndex := forwardIndex + 1.
		].
		[ forwardIndex < reverseIndex and: [ aSkipConditionBlock value: (self at: reverseIndex) ] ] whileTrue: [
			reverseIndex := reverseIndex - 1.
		].
	].
	^true.

ArrayedCollection>>isPalindromeWithoutSpaces

	^self isPalindromeWithSkipCondition: [ :each | false ].

ArrayedCollection>>isPalindromeWithSkipCondition: aSkipConditionBlock

	^self isBidirectionalWithEqualCondition: [ :left :right | left = right ] andSkipCondition: aSkipConditionBlock.

ArrayedCollection>>isPalindromeWithSpaces

	^self isPalindromeWithSkipCondition: [ :each | each = Character space ].

Palindrome

Definition
Object subclass: #Palindrome
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	classInstanceVariableNames: ''
Class methods
main

	[
		| message |
		message := 'drawalevelaward'.
		Transcript
			nextPutAll: 'Is "' , message , '" a palindrome? ';
			nextPutAll: message isPalindromeWithoutSpaces displayString;
			nextPutAll: '.'; cr;
			yourself.
	] value.

	[
		| message |
		message := 'draw a level award'.
		Transcript
			nextPutAll: 'Is "' , message , '" a palindrome? ';
			nextPutAll: message isPalindromeWithSpaces displayString;
			nextPutAll: '.'; cr;
			yourself.
	] value.
Instance methods