Debian Codegraph @

sample/trick2015/eregon/remarks.markdown

raw
1 ### Remarks
2
3 Just run it without arguments:
4
5 ruby entry.rb
6
7 I confirmed the following implementations and platforms:
8
9 * Linux:
10 * ruby 2.3.0dev (2015-10-30 trunk 52394) [x86\_64-linux]
11 * ruby 2.2.2p95 (2015-04-13 revision 50295) [x86\_64-linux]
12 * ruby 2.0.0p647 (2015-08-18) [x86\_64-linux]
13 * Darwin:
14 * ruby 2.0.0p247 (2013-06-27 revision 41674) [x86\_64-darwin10.8.0]
15 * jruby 9.0.3.0 (2.2.2) 2015-10-21 633c9aa Java HotSpot(TM) 64-Bit Server VM 25.11-b03 on 1.8.0\_11-b12 +jit [darwin-x86\_64]
16 * rubinius 2.2.6.n74 (2.1.0 94b3a9b4 2014-03-15 JI) [x86\_64-darwin12.5.0]
17
18 ### Description
19
20 This program shows all solutions of any sudoku puzzle.
21
22 The embedded sudoku puzzle can be changed at wish.
23
24 Giving an empty puzzle (all `0` or `_`), the program will print every possible completed sudoku puzzle.
25 We do not however make any time guarantee on such behavior.
26
27 The program is rather small for the task: the solver is actually 302 characters long,
28 assuming the sudoku puzzle is in a variable `s` and encoded as an array of rows of numbers.
29
30 ### Internals
31
32 * The program implements backtracking and keeps state in a very elegant way.
33 * The whole program never goes deeper than 9 stack frames,
34 but yet can backtrack up to 81 levels!
35 * The main loop of a program is a dance between cells.
36 On one end is the solutions, on the other the program ends.
37 * The program only uses *infinite* loops and no `break`.
38 * The program interleaves the creation of the solver and the puzzle.
39 * The program is easy to deobfuscate but finding how it works will be more challenging.
40 * The last line contains a smiley.
41
42 The author likes good numbers:
43
44 $ wc entry.rb
45 15 42 600
46
47 The inspiration for this entry comes from:
48
49 * A newspaper sudoku with multiple solutions
50 * An inspiring paper: `Revisiting Coroutines`
51
52 Various tricks used for brevity:
53
54 * The method defined is one of the fews which may contain neither parenthesis nor spaces.
55 * The program uses the return value of Fiber.yield without arguments.
56 * `String#b` is used as a very short `self`.
57
58 Design issues:
59
60 * Since `return`-ing from a Fiber is not allowed, the programs must `exit`.
61 * The program reveals that the cartesian product operator is still too long: `a.product(a)` while it could be `a*a`.
62
63 Note:
64
65 * In the original code, the last cell was: `C.new{loop{yield s; C.yield}}`,
66 implementing some sort of "forwarding coroutine".
67
68 ### Limitation
69
70 * The program does not want any *argument* with you and will quit quietly if you try some.