>>52 Squeak Smalltalk
| shiritori |
shiritori := Generator on: [:g |
  | keys |
  keys := {'11'}, ((1 to: 9) gather: [:hd | (hd+1 to: 9) gather: [:tl |
    {hd asString, tl},
    (hd = 1 ifTrue: [{tl asString, tl}] ifFalse: [{}]),
    {tl asString, (tl = 9 ifTrue: [hd = 8 ifTrue: [1] ifFalse: [hd+1]] ifFalse: [hd])}]]).

  keys do: [:pair |
    pair asSet size = 1 ifTrue: [g yield: pair first digitValue].
    g yield: pair asNumber].

  0 to: 9 do: [:m |
    keys do: [:pair | g yield: (pair first asString, m, pair last) asNumber]].

  g yield: 1001].

(shiritori next: 15) asArray. "=> #(1 11 12 2 22 21 13 3 33 31 14 4 44 41 15) "
shiritori contents last: 10. "=> #(896 699 997 798 897 799 998 899 991 1001) "