Comment detail

リストの並び (Nested Flatten)

Squeak Smalltalk で。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
| check |

check := [:list |
    (1 to: list size - 1) allSatisfy: [:idx |
        | first second |
        (first := list at: idx) = (second := list at: idx + 1) ifTrue: [false] ifFalse: [
            | sym |
            sym := first < second ifTrue: [#positive] ifFalse: [#negative].
            (list allButFirst: idx) - first allSatisfy: [:each | each perform: sym]]]].


check value: #(1 5 4 2).                       "=> true "
check value: #(1 2 3).                         "=> true "
check value: #(825 102 811 140 812 125 263).   "=> false "
check value: #(824 102 811 140 810 155 263).   "=> true "
check value: #(5 4 3 2 1).                     "=> true "
check value: #(4 2 5 3 1).                     "=> false "

Index

Feed

Other

Link

Pathtraq

loading...