day5 solution (no core/base)
This commit is contained in:
parent
57da947edf
commit
8bbfc83fc6
3 changed files with 569 additions and 0 deletions
4
bin/d5/dune
Normal file
4
bin/d5/dune
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
(executable
|
||||||
|
(public_name d5)
|
||||||
|
(name main)
|
||||||
|
(libraries utils))
|
512
bin/d5/input.txt
Normal file
512
bin/d5/input.txt
Normal file
|
@ -0,0 +1,512 @@
|
||||||
|
[M] [Z] [V]
|
||||||
|
[Z] [P] [L] [Z] [J]
|
||||||
|
[S] [D] [W] [W] [H] [Q]
|
||||||
|
[P] [V] [N] [D] [P] [C] [V]
|
||||||
|
[H] [B] [J] [V] [B] [M] [N] [P]
|
||||||
|
[V] [F] [L] [Z] [C] [S] [P] [S] [G]
|
||||||
|
[F] [J] [M] [G] [R] [R] [H] [R] [L]
|
||||||
|
[G] [G] [G] [N] [V] [V] [T] [Q] [F]
|
||||||
|
1 2 3 4 5 6 7 8 9
|
||||||
|
|
||||||
|
move 6 from 9 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 8 to 2
|
||||||
|
move 3 from 7 to 2
|
||||||
|
move 7 from 6 to 9
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 3 from 5 to 7
|
||||||
|
move 6 from 8 to 6
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 6 from 6 to 5
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 9 from 2 to 9
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 3 from 1 to 3
|
||||||
|
move 3 from 5 to 1
|
||||||
|
move 10 from 3 to 5
|
||||||
|
move 4 from 4 to 6
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 6 from 8 to 6
|
||||||
|
move 1 from 4 to 3
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 2 from 3 to 1
|
||||||
|
move 1 from 3 to 7
|
||||||
|
move 8 from 1 to 9
|
||||||
|
move 1 from 1 to 2
|
||||||
|
move 1 from 2 to 7
|
||||||
|
move 6 from 6 to 3
|
||||||
|
move 7 from 3 to 5
|
||||||
|
move 14 from 5 to 6
|
||||||
|
move 2 from 1 to 3
|
||||||
|
move 5 from 5 to 8
|
||||||
|
move 5 from 8 to 1
|
||||||
|
move 2 from 7 to 1
|
||||||
|
move 5 from 6 to 9
|
||||||
|
move 8 from 9 to 3
|
||||||
|
move 13 from 9 to 3
|
||||||
|
move 7 from 1 to 4
|
||||||
|
move 6 from 4 to 1
|
||||||
|
move 22 from 3 to 1
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 2 from 6 to 1
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 7 from 9 to 8
|
||||||
|
move 2 from 1 to 7
|
||||||
|
move 2 from 3 to 2
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 2 from 7 to 8
|
||||||
|
move 1 from 3 to 6
|
||||||
|
move 9 from 8 to 6
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 8 from 1 to 2
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 3 from 4 to 1
|
||||||
|
move 1 from 4 to 6
|
||||||
|
move 10 from 6 to 5
|
||||||
|
move 5 from 2 to 9
|
||||||
|
move 6 from 9 to 3
|
||||||
|
move 2 from 5 to 3
|
||||||
|
move 2 from 9 to 7
|
||||||
|
move 7 from 5 to 8
|
||||||
|
move 5 from 6 to 2
|
||||||
|
move 3 from 3 to 7
|
||||||
|
move 3 from 3 to 5
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 6 from 6 to 8
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 9 from 8 to 9
|
||||||
|
move 1 from 3 to 1
|
||||||
|
move 7 from 2 to 7
|
||||||
|
move 9 from 7 to 6
|
||||||
|
move 2 from 2 to 3
|
||||||
|
move 7 from 9 to 3
|
||||||
|
move 9 from 6 to 8
|
||||||
|
move 7 from 3 to 4
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 4 from 4 to 5
|
||||||
|
move 3 from 5 to 6
|
||||||
|
move 2 from 7 to 4
|
||||||
|
move 5 from 4 to 7
|
||||||
|
move 13 from 8 to 4
|
||||||
|
move 2 from 9 to 4
|
||||||
|
move 2 from 8 to 7
|
||||||
|
move 6 from 7 to 5
|
||||||
|
move 6 from 4 to 2
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 3 from 2 to 7
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 3 from 2 to 4
|
||||||
|
move 2 from 3 to 9
|
||||||
|
move 2 from 7 to 2
|
||||||
|
move 6 from 5 to 4
|
||||||
|
move 3 from 6 to 2
|
||||||
|
move 2 from 6 to 9
|
||||||
|
move 5 from 2 to 9
|
||||||
|
move 12 from 4 to 8
|
||||||
|
move 3 from 9 to 2
|
||||||
|
move 12 from 1 to 5
|
||||||
|
move 4 from 4 to 6
|
||||||
|
move 12 from 8 to 9
|
||||||
|
move 2 from 6 to 5
|
||||||
|
move 1 from 4 to 8
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 3 from 2 to 1
|
||||||
|
move 2 from 6 to 7
|
||||||
|
move 1 from 5 to 9
|
||||||
|
move 2 from 1 to 4
|
||||||
|
move 10 from 5 to 1
|
||||||
|
move 2 from 7 to 3
|
||||||
|
move 18 from 9 to 7
|
||||||
|
move 8 from 7 to 2
|
||||||
|
move 1 from 9 to 6
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 10 from 7 to 9
|
||||||
|
move 1 from 4 to 2
|
||||||
|
move 19 from 1 to 5
|
||||||
|
move 8 from 5 to 9
|
||||||
|
move 3 from 8 to 4
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 2 from 3 to 6
|
||||||
|
move 10 from 5 to 2
|
||||||
|
move 4 from 1 to 2
|
||||||
|
move 2 from 9 to 2
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 2 from 5 to 6
|
||||||
|
move 1 from 8 to 7
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 1 from 5 to 6
|
||||||
|
move 18 from 2 to 5
|
||||||
|
move 5 from 2 to 1
|
||||||
|
move 6 from 5 to 8
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 2 from 2 to 4
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 2 from 7 to 6
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 4 from 8 to 5
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 2 from 8 to 3
|
||||||
|
move 1 from 3 to 6
|
||||||
|
move 1 from 4 to 8
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 10 from 5 to 7
|
||||||
|
move 5 from 5 to 1
|
||||||
|
move 2 from 4 to 1
|
||||||
|
move 3 from 7 to 6
|
||||||
|
move 12 from 1 to 4
|
||||||
|
move 8 from 9 to 5
|
||||||
|
move 6 from 7 to 4
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 4 from 4 to 3
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 3 from 9 to 5
|
||||||
|
move 2 from 3 to 1
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 8 from 4 to 7
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 7 from 6 to 4
|
||||||
|
move 2 from 1 to 3
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 1 from 3 to 7
|
||||||
|
move 1 from 1 to 6
|
||||||
|
move 4 from 9 to 3
|
||||||
|
move 5 from 4 to 6
|
||||||
|
move 12 from 6 to 2
|
||||||
|
move 3 from 9 to 4
|
||||||
|
move 8 from 2 to 6
|
||||||
|
move 2 from 9 to 6
|
||||||
|
move 8 from 5 to 6
|
||||||
|
move 4 from 5 to 8
|
||||||
|
move 14 from 6 to 3
|
||||||
|
move 11 from 4 to 9
|
||||||
|
move 2 from 2 to 7
|
||||||
|
move 8 from 3 to 9
|
||||||
|
move 11 from 3 to 6
|
||||||
|
move 14 from 9 to 1
|
||||||
|
move 7 from 1 to 3
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 2 from 2 to 8
|
||||||
|
move 6 from 7 to 5
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 13 from 6 to 3
|
||||||
|
move 4 from 6 to 8
|
||||||
|
move 3 from 1 to 6
|
||||||
|
move 5 from 5 to 8
|
||||||
|
move 7 from 8 to 7
|
||||||
|
move 2 from 1 to 8
|
||||||
|
move 1 from 4 to 1
|
||||||
|
move 4 from 8 to 9
|
||||||
|
move 8 from 7 to 5
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 4 from 9 to 3
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 5 from 5 to 2
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 1 from 8 to 6
|
||||||
|
move 2 from 6 to 2
|
||||||
|
move 4 from 8 to 6
|
||||||
|
move 4 from 1 to 8
|
||||||
|
move 4 from 8 to 5
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 4 from 6 to 1
|
||||||
|
move 1 from 8 to 2
|
||||||
|
move 3 from 5 to 4
|
||||||
|
move 4 from 2 to 5
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 1 from 2 to 6
|
||||||
|
move 3 from 1 to 8
|
||||||
|
move 2 from 4 to 5
|
||||||
|
move 2 from 6 to 1
|
||||||
|
move 3 from 8 to 9
|
||||||
|
move 4 from 9 to 2
|
||||||
|
move 1 from 7 to 1
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 4 from 1 to 6
|
||||||
|
move 1 from 7 to 4
|
||||||
|
move 6 from 2 to 8
|
||||||
|
move 2 from 4 to 8
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 3 from 6 to 2
|
||||||
|
move 1 from 6 to 4
|
||||||
|
move 7 from 3 to 5
|
||||||
|
move 2 from 8 to 1
|
||||||
|
move 3 from 2 to 8
|
||||||
|
move 6 from 8 to 5
|
||||||
|
move 17 from 5 to 3
|
||||||
|
move 2 from 1 to 6
|
||||||
|
move 3 from 8 to 3
|
||||||
|
move 1 from 9 to 5
|
||||||
|
move 11 from 5 to 2
|
||||||
|
move 40 from 3 to 5
|
||||||
|
move 11 from 2 to 7
|
||||||
|
move 4 from 7 to 8
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 1 from 3 to 5
|
||||||
|
move 1 from 4 to 8
|
||||||
|
move 19 from 5 to 8
|
||||||
|
move 7 from 7 to 8
|
||||||
|
move 16 from 5 to 2
|
||||||
|
move 6 from 5 to 8
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 1 to 7
|
||||||
|
move 1 from 7 to 3
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 1 from 4 to 6
|
||||||
|
move 14 from 2 to 9
|
||||||
|
move 24 from 8 to 4
|
||||||
|
move 8 from 8 to 3
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 16 from 4 to 1
|
||||||
|
move 3 from 8 to 4
|
||||||
|
move 3 from 3 to 8
|
||||||
|
move 4 from 3 to 4
|
||||||
|
move 1 from 3 to 9
|
||||||
|
move 13 from 9 to 4
|
||||||
|
move 16 from 1 to 8
|
||||||
|
move 8 from 8 to 1
|
||||||
|
move 3 from 1 to 7
|
||||||
|
move 1 from 8 to 6
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 10 from 8 to 5
|
||||||
|
move 5 from 5 to 2
|
||||||
|
move 3 from 8 to 9
|
||||||
|
move 1 from 8 to 9
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 5 from 2 to 6
|
||||||
|
move 3 from 5 to 2
|
||||||
|
move 1 from 6 to 1
|
||||||
|
move 5 from 1 to 5
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 2 from 7 to 3
|
||||||
|
move 2 from 3 to 2
|
||||||
|
move 1 from 5 to 7
|
||||||
|
move 7 from 5 to 3
|
||||||
|
move 5 from 9 to 5
|
||||||
|
move 2 from 7 to 9
|
||||||
|
move 4 from 5 to 6
|
||||||
|
move 2 from 9 to 8
|
||||||
|
move 2 from 2 to 4
|
||||||
|
move 5 from 3 to 5
|
||||||
|
move 1 from 3 to 2
|
||||||
|
move 7 from 4 to 9
|
||||||
|
move 1 from 8 to 1
|
||||||
|
move 1 from 2 to 1
|
||||||
|
move 9 from 4 to 6
|
||||||
|
move 2 from 1 to 8
|
||||||
|
move 1 from 3 to 9
|
||||||
|
move 2 from 8 to 6
|
||||||
|
move 13 from 4 to 6
|
||||||
|
move 1 from 8 to 7
|
||||||
|
move 2 from 9 to 6
|
||||||
|
move 3 from 5 to 7
|
||||||
|
move 3 from 2 to 5
|
||||||
|
move 3 from 2 to 6
|
||||||
|
move 5 from 6 to 2
|
||||||
|
move 4 from 2 to 5
|
||||||
|
move 4 from 5 to 7
|
||||||
|
move 5 from 5 to 7
|
||||||
|
move 7 from 9 to 6
|
||||||
|
move 6 from 7 to 2
|
||||||
|
move 22 from 6 to 5
|
||||||
|
move 10 from 5 to 8
|
||||||
|
move 7 from 5 to 4
|
||||||
|
move 8 from 8 to 5
|
||||||
|
move 18 from 6 to 2
|
||||||
|
move 5 from 7 to 5
|
||||||
|
move 1 from 8 to 2
|
||||||
|
move 6 from 5 to 1
|
||||||
|
move 7 from 4 to 2
|
||||||
|
move 4 from 1 to 5
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 1 from 8 to 6
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 10 from 5 to 9
|
||||||
|
move 12 from 2 to 1
|
||||||
|
move 8 from 5 to 2
|
||||||
|
move 19 from 2 to 9
|
||||||
|
move 1 from 6 to 8
|
||||||
|
move 13 from 9 to 3
|
||||||
|
move 8 from 1 to 2
|
||||||
|
move 5 from 1 to 3
|
||||||
|
move 10 from 2 to 1
|
||||||
|
move 7 from 2 to 5
|
||||||
|
move 3 from 5 to 7
|
||||||
|
move 4 from 1 to 3
|
||||||
|
move 1 from 2 to 3
|
||||||
|
move 3 from 1 to 2
|
||||||
|
move 1 from 8 to 6
|
||||||
|
move 2 from 7 to 5
|
||||||
|
move 4 from 1 to 3
|
||||||
|
move 6 from 5 to 4
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 1 from 2 to 9
|
||||||
|
move 6 from 4 to 5
|
||||||
|
move 5 from 5 to 9
|
||||||
|
move 1 from 6 to 8
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 6 from 9 to 2
|
||||||
|
move 5 from 2 to 4
|
||||||
|
move 3 from 1 to 6
|
||||||
|
move 2 from 4 to 7
|
||||||
|
move 22 from 3 to 9
|
||||||
|
move 1 from 8 to 4
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 2 from 6 to 1
|
||||||
|
move 2 from 1 to 5
|
||||||
|
move 1 from 6 to 7
|
||||||
|
move 1 from 7 to 4
|
||||||
|
move 6 from 3 to 7
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 8 from 7 to 3
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 1 from 7 to 9
|
||||||
|
move 5 from 3 to 6
|
||||||
|
move 1 from 8 to 4
|
||||||
|
move 4 from 3 to 2
|
||||||
|
move 32 from 9 to 3
|
||||||
|
move 3 from 6 to 7
|
||||||
|
move 5 from 9 to 3
|
||||||
|
move 1 from 9 to 7
|
||||||
|
move 2 from 9 to 2
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 5 from 3 to 2
|
||||||
|
move 3 from 7 to 8
|
||||||
|
move 1 from 7 to 2
|
||||||
|
move 1 from 8 to 5
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 5 from 4 to 5
|
||||||
|
move 4 from 5 to 2
|
||||||
|
move 3 from 5 to 7
|
||||||
|
move 1 from 7 to 5
|
||||||
|
move 1 from 6 to 5
|
||||||
|
move 2 from 8 to 5
|
||||||
|
move 15 from 2 to 4
|
||||||
|
move 3 from 5 to 6
|
||||||
|
move 4 from 6 to 5
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 1 from 2 to 4
|
||||||
|
move 25 from 3 to 9
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 11 from 9 to 2
|
||||||
|
move 13 from 2 to 1
|
||||||
|
move 4 from 4 to 7
|
||||||
|
move 12 from 9 to 8
|
||||||
|
move 6 from 7 to 8
|
||||||
|
move 7 from 4 to 7
|
||||||
|
move 7 from 7 to 8
|
||||||
|
move 1 from 5 to 1
|
||||||
|
move 5 from 4 to 3
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 7 from 1 to 7
|
||||||
|
move 1 from 1 to 4
|
||||||
|
move 12 from 3 to 2
|
||||||
|
move 1 from 3 to 9
|
||||||
|
move 1 from 1 to 3
|
||||||
|
move 1 from 9 to 1
|
||||||
|
move 7 from 7 to 2
|
||||||
|
move 1 from 4 to 7
|
||||||
|
move 2 from 8 to 7
|
||||||
|
move 7 from 1 to 2
|
||||||
|
move 1 from 3 to 4
|
||||||
|
move 26 from 2 to 1
|
||||||
|
move 4 from 8 to 1
|
||||||
|
move 3 from 1 to 6
|
||||||
|
move 1 from 6 to 3
|
||||||
|
move 1 from 6 to 9
|
||||||
|
move 1 from 3 to 8
|
||||||
|
move 20 from 1 to 3
|
||||||
|
move 1 from 9 to 7
|
||||||
|
move 4 from 7 to 1
|
||||||
|
move 1 from 5 to 3
|
||||||
|
move 4 from 3 to 5
|
||||||
|
move 1 from 6 to 2
|
||||||
|
move 6 from 3 to 2
|
||||||
|
move 8 from 1 to 4
|
||||||
|
move 1 from 1 to 5
|
||||||
|
move 3 from 1 to 4
|
||||||
|
move 7 from 2 to 4
|
||||||
|
move 10 from 3 to 8
|
||||||
|
move 4 from 4 to 3
|
||||||
|
move 12 from 4 to 7
|
||||||
|
move 3 from 3 to 1
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 2 from 8 to 1
|
||||||
|
move 6 from 8 to 9
|
||||||
|
move 5 from 9 to 6
|
||||||
|
move 1 from 9 to 3
|
||||||
|
move 3 from 8 to 7
|
||||||
|
move 10 from 8 to 5
|
||||||
|
move 4 from 8 to 7
|
||||||
|
move 9 from 7 to 9
|
||||||
|
move 4 from 8 to 4
|
||||||
|
move 2 from 4 to 3
|
||||||
|
move 3 from 1 to 7
|
||||||
|
move 11 from 7 to 4
|
||||||
|
move 6 from 4 to 8
|
||||||
|
move 1 from 7 to 3
|
||||||
|
move 4 from 5 to 1
|
||||||
|
move 5 from 3 to 6
|
||||||
|
move 5 from 9 to 4
|
||||||
|
move 1 from 9 to 8
|
||||||
|
move 10 from 4 to 8
|
||||||
|
move 5 from 1 to 2
|
||||||
|
move 1 from 7 to 6
|
||||||
|
move 9 from 6 to 3
|
||||||
|
move 7 from 8 to 7
|
||||||
|
move 3 from 4 to 1
|
||||||
|
move 2 from 2 to 1
|
||||||
|
move 9 from 8 to 3
|
||||||
|
move 10 from 5 to 8
|
||||||
|
move 18 from 3 to 9
|
||||||
|
move 1 from 7 to 8
|
||||||
|
move 1 from 5 to 3
|
||||||
|
move 4 from 8 to 3
|
||||||
|
move 2 from 6 to 3
|
||||||
|
move 6 from 7 to 2
|
||||||
|
move 1 from 5 to 3
|
||||||
|
move 1 from 1 to 9
|
||||||
|
move 10 from 3 to 9
|
||||||
|
move 4 from 1 to 8
|
||||||
|
move 13 from 8 to 1
|
||||||
|
move 3 from 1 to 8
|
||||||
|
move 3 from 2 to 4
|
||||||
|
move 5 from 2 to 6
|
||||||
|
move 5 from 6 to 4
|
||||||
|
move 28 from 9 to 2
|
||||||
|
move 2 from 9 to 5
|
||||||
|
move 2 from 5 to 2
|
||||||
|
move 1 from 3 to 7
|
||||||
|
move 2 from 1 to 4
|
||||||
|
move 3 from 8 to 3
|
||||||
|
move 1 from 9 to 4
|
||||||
|
move 3 from 4 to 6
|
||||||
|
move 2 from 3 to 7
|
||||||
|
move 8 from 1 to 5
|
||||||
|
move 3 from 7 to 6
|
||||||
|
move 14 from 2 to 8
|
||||||
|
move 1 from 9 to 1
|
||||||
|
move 6 from 5 to 6
|
||||||
|
move 4 from 2 to 5
|
||||||
|
move 9 from 8 to 2
|
||||||
|
move 4 from 8 to 4
|
||||||
|
move 7 from 2 to 4
|
||||||
|
move 12 from 4 to 3
|
||||||
|
move 5 from 4 to 7
|
||||||
|
move 5 from 7 to 4
|
||||||
|
move 1 from 8 to 7
|
||||||
|
move 1 from 4 to 5
|
||||||
|
move 2 from 5 to 4
|
||||||
|
move 1 from 5 to 8
|
||||||
|
move 1 from 5 to 9
|
53
bin/d5/main.ml
Normal file
53
bin/d5/main.ml
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
open Utils
|
||||||
|
|
||||||
|
let initial_state =
|
||||||
|
let ht = Hashtbl.create 12345 in
|
||||||
|
let _ = Hashtbl.add ht 1 ["S"; "P"; "H"; "V"; "F"; "G"] in
|
||||||
|
let _ = Hashtbl.add ht 2 ["M"; "Z"; "D"; "V"; "B"; "F"; "J"; "G"] in
|
||||||
|
let _ = Hashtbl.add ht 3 ["N"; "J"; "L"; "M"; "G"] in
|
||||||
|
let _ = Hashtbl.add ht 4 ["P"; "W"; "D"; "V"; "Z"; "G"; "N"] in
|
||||||
|
let _ = Hashtbl.add ht 5 ["B"; "C"; "R"; "V"] in
|
||||||
|
let _ = Hashtbl.add ht 6 ["Z"; "L"; "W"; "P"; "M"; "S"; "R"; "V"] in
|
||||||
|
let _ = Hashtbl.add ht 7 ["P"; "H"; "T"] in
|
||||||
|
let _ = Hashtbl.add ht 8 ["V"; "Z"; "H"; "C"; "N"; "S"; "R"; "Q"] in
|
||||||
|
let _ = Hashtbl.add ht 9 ["J"; "Q"; "V"; "P"; "G"; "L"; "F"] in
|
||||||
|
ht
|
||||||
|
|
||||||
|
exception InvalidMoveLine
|
||||||
|
|
||||||
|
let parse_move line =
|
||||||
|
match String.split_on_char ' ' line with
|
||||||
|
| "move" :: count :: "from" :: st_from :: "to" :: st_to :: [] ->
|
||||||
|
(int_of_string count, int_of_string st_from, int_of_string st_to)
|
||||||
|
| _ -> raise InvalidMoveLine
|
||||||
|
|
||||||
|
let move stacks f (count, idx_from, idx_to) =
|
||||||
|
let from_stack = Hashtbl.find stacks idx_from in
|
||||||
|
let to_stack = Hashtbl.find stacks idx_to in
|
||||||
|
let rec aux count res_from append_to =
|
||||||
|
if count = 0 then (res_from, append_to)
|
||||||
|
else match res_from with
|
||||||
|
| h :: t -> aux (count - 1) t (h :: append_to)
|
||||||
|
| [] -> (res_from, append_to) in
|
||||||
|
let (res_from, res_to) = aux count from_stack [] in
|
||||||
|
let _ = Hashtbl.replace stacks idx_from res_from in
|
||||||
|
let _ = Hashtbl.replace stacks idx_to (List.append (f res_to) to_stack) in
|
||||||
|
stacks ;;
|
||||||
|
|
||||||
|
let parsed_moves = read_file "bin/d5/input.txt"
|
||||||
|
|> List.filter_map
|
||||||
|
(fun line ->
|
||||||
|
try Some(parse_move line)
|
||||||
|
with InvalidMoveLine -> let _ = print_endline ("invalid line " ^ line) in None) ;;
|
||||||
|
|
||||||
|
let solve f input =
|
||||||
|
let state = Hashtbl.copy initial_state in
|
||||||
|
let _ = input
|
||||||
|
|> List.map (move state f) in
|
||||||
|
let res = Hashtbl.length state
|
||||||
|
|> range
|
||||||
|
|> List.fold_left (fun acc x -> acc ^ (List.hd (Hashtbl.find state x))) "" in
|
||||||
|
print_endline ("\n" ^ res) ;;
|
||||||
|
|
||||||
|
solve id parsed_moves ;;
|
||||||
|
solve List.rev parsed_moves ;;
|
Loading…
Reference in a new issue