【激突】関数型言語 VS オブジェクト指向言語2
■ このスレッドは過去ログ倉庫に格納されています
0514デフォルトの名無しさん
2012/04/21(土) 01:27:35.30Squeak Smalltalk で。
| ui stock player |
ui := UIManager default.
stock := (1 to: 9) gather: [:each | Array new: 4 withAll: each].
stock := stock shuffled asOrderedCollection.
player := (stock removeFirst: 7) asOrderedCollection.
[ | choice |
[ | input |
input := ui request: player asSortedArray asString, 'から合計が15になるようにチョイス'.
choice := input subStrings collect: #asInteger.
choice ifEmpty: [(ui confirm: 'ギブアップ?')
ifTrue: [^self] ifFalse: [choice := {nil}]].
(choice allSatisfy: #isInteger)
and: [choice sum = 15]
and: (player includesAllOf: choice)
and: [choice asSet allSatisfy: [:card | (player occurrencesOf: card) >= (choice occurrencesOf: card)]]
] whileFalse.
player removeAll: choice.
player addAll: (stock removeFirst: (choice size min: stock size)).
player notEmpty] whileTrue.
ui inform: 'おめでとう!'
■ このスレッドは過去ログ倉庫に格納されています