Comment detail

FizzBuzz問題の一般化 (Nested Flatten)
Squeak Smalltalk で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
| gFizzBuzz |
gFizzBuzz := [:ints :specPairs |
    | cycles |
    cycles := specPairs pairsCollect: [:size :label |
        (Array new: size withAll: '') atLast: 1 put: label; yourself].
    World findATranscript: nil.
    ints do: [:int |
        | fizzBuzzStr |
        fizzBuzzStr := cycles inject: '' into: [:str :cyc | str, (cyc atWrap: int)].
        fizzBuzzStr ifEmpty: [fizzBuzzStr := #hoge].
        Transcript cr; show: int printString, ': ', fizzBuzzStr]].

gFizzBuzz value: (101 to: 120) value: #(3 Pizz 5 Quzz 7 Razz)

Index

Feed

Other

Link

Pathtraq

loading...