Zomis / Brainduck

Brainfuck Interpreter in Java/Groovy, with a Groovy DSL
40 stars 1 forks source link

Detecting patterns in while-loop analysis #21

Open Zomis opened 9 years ago

Zomis commented 9 years ago

There can be a lot of patterns in the while loop analysis. Try to detect these patterns and write in a more compact way

Compact ways can be:

1013 [(49..58) x 4, 49, 50, 51, 52, 53, 54]
1191 [(1 * 9, 0) x 26, 1 * 6]

Some examples: (from the two existing Brainfuck questions on Code Review)

1013 [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 49, 50, 51, 52, 53, 54]
1191 [1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 9, 0, 1 * 6]
1694 [48 * 9, 49 * 10, 50 * 10, 51 * 10, 52 * 10, 53 * 10, 54 * 10, 55 * 10, 56 * 10, 57 * 10, 58, 48 * 9, 49 * 10, 50 * 10, 51 * 10, 52 * 10, 53 * 10, 54 * 10, 55 * 10, 56 * 10, 57 * 10, 58, 48 * 9, 49 * 10, 50 * 10, 51 * 10, 52 * 10, 53 * 7]
1872 [1 * 99, 0, 1 * 99, 0, 1 * 56]
2378 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 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 31, 32, 34, 37, 38, 41, 43, 44, 46, 47, 49, 52, 53, 56, 58, 59, 61, 62, 64, 67, 68, 71, 73, 74, 76, 77, 79, 82, 83, 86, 88, 89, 91, 92, 94, 97, 98]
Zomis commented 9 years ago

This pattern is also interesting:

770 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144]

From http://codereview.stackexchange.com/questions/112194/printing-multiplication-tables-to-12-in-bf