Day 5 completed, finally haha
This commit is contained in:
parent
f2836e45e1
commit
2a9e8eab51
@ -12,3 +12,4 @@ rpath = true
|
||||
|
||||
[dependencies]
|
||||
nom = "7.1.1"
|
||||
itertools = "0.10.5"
|
||||
|
511
prob5_part2.txt
Normal file
511
prob5_part2.txt
Normal file
@ -0,0 +1,511 @@
|
||||
[B] [N] [H]
|
||||
[V] [P] [T] [V] [P]
|
||||
[W] [C] [T] [S] [H] [N]
|
||||
[T] [J] [Z] [M] [N] [F] [L]
|
||||
[Q] [W] [N] [J] [T] [Q] [R] [B]
|
||||
[N] [B] [Q] [R] [V] [F] [D] [F] [M]
|
||||
[H] [W] [S] [J] [P] [W] [L] [P] [S]
|
||||
[D] [D] [T] [F] [G] [B] [B] [H] [Z]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 2 from 8 to 1
|
||||
move 4 from 9 to 8
|
||||
move 2 from 1 to 6
|
||||
move 7 from 4 to 2
|
||||
move 10 from 2 to 7
|
||||
move 2 from 1 to 6
|
||||
move 1 from 9 to 4
|
||||
move 1 from 4 to 1
|
||||
move 8 from 6 to 4
|
||||
move 7 from 1 to 8
|
||||
move 6 from 8 to 1
|
||||
move 1 from 4 to 1
|
||||
move 8 from 7 to 3
|
||||
move 2 from 5 to 2
|
||||
move 5 from 3 to 2
|
||||
move 5 from 2 to 1
|
||||
move 1 from 6 to 5
|
||||
move 2 from 2 to 6
|
||||
move 5 from 8 to 7
|
||||
move 12 from 7 to 4
|
||||
move 3 from 5 to 4
|
||||
move 2 from 6 to 4
|
||||
move 9 from 1 to 7
|
||||
move 4 from 3 to 7
|
||||
move 4 from 3 to 4
|
||||
move 3 from 1 to 7
|
||||
move 1 from 9 to 1
|
||||
move 1 from 1 to 4
|
||||
move 2 from 5 to 2
|
||||
move 1 from 3 to 7
|
||||
move 15 from 7 to 2
|
||||
move 4 from 7 to 9
|
||||
move 6 from 9 to 2
|
||||
move 2 from 8 to 3
|
||||
move 3 from 2 to 8
|
||||
move 1 from 7 to 6
|
||||
move 8 from 2 to 5
|
||||
move 2 from 8 to 4
|
||||
move 2 from 3 to 8
|
||||
move 9 from 5 to 9
|
||||
move 7 from 4 to 2
|
||||
move 1 from 8 to 6
|
||||
move 6 from 9 to 2
|
||||
move 3 from 9 to 7
|
||||
move 2 from 8 to 4
|
||||
move 7 from 2 to 6
|
||||
move 7 from 4 to 1
|
||||
move 3 from 1 to 8
|
||||
move 2 from 1 to 8
|
||||
move 4 from 8 to 2
|
||||
move 2 from 1 to 5
|
||||
move 19 from 2 to 7
|
||||
move 8 from 4 to 7
|
||||
move 18 from 7 to 1
|
||||
move 11 from 7 to 4
|
||||
move 15 from 1 to 7
|
||||
move 9 from 4 to 3
|
||||
move 2 from 3 to 1
|
||||
move 9 from 4 to 5
|
||||
move 1 from 8 to 1
|
||||
move 8 from 6 to 5
|
||||
move 3 from 2 to 5
|
||||
move 1 from 6 to 7
|
||||
move 4 from 4 to 3
|
||||
move 8 from 5 to 1
|
||||
move 13 from 1 to 6
|
||||
move 12 from 7 to 1
|
||||
move 12 from 6 to 3
|
||||
move 1 from 7 to 6
|
||||
move 1 from 7 to 5
|
||||
move 1 from 1 to 9
|
||||
move 1 from 3 to 1
|
||||
move 3 from 1 to 9
|
||||
move 12 from 3 to 8
|
||||
move 1 from 9 to 3
|
||||
move 1 from 6 to 8
|
||||
move 5 from 5 to 1
|
||||
move 1 from 6 to 2
|
||||
move 10 from 8 to 9
|
||||
move 13 from 9 to 2
|
||||
move 10 from 3 to 4
|
||||
move 1 from 8 to 9
|
||||
move 2 from 8 to 7
|
||||
move 1 from 3 to 1
|
||||
move 1 from 5 to 6
|
||||
move 13 from 2 to 5
|
||||
move 1 from 9 to 2
|
||||
move 7 from 1 to 4
|
||||
move 2 from 2 to 5
|
||||
move 2 from 7 to 8
|
||||
move 1 from 6 to 8
|
||||
move 10 from 5 to 8
|
||||
move 3 from 7 to 2
|
||||
move 4 from 1 to 4
|
||||
move 12 from 4 to 2
|
||||
move 10 from 5 to 3
|
||||
move 6 from 2 to 1
|
||||
move 2 from 4 to 8
|
||||
move 3 from 4 to 8
|
||||
move 6 from 1 to 7
|
||||
move 1 from 7 to 5
|
||||
move 12 from 8 to 2
|
||||
move 3 from 4 to 9
|
||||
move 1 from 4 to 3
|
||||
move 2 from 9 to 6
|
||||
move 2 from 6 to 8
|
||||
move 1 from 1 to 3
|
||||
move 8 from 2 to 6
|
||||
move 4 from 1 to 8
|
||||
move 12 from 2 to 3
|
||||
move 4 from 6 to 8
|
||||
move 10 from 8 to 3
|
||||
move 14 from 3 to 8
|
||||
move 5 from 5 to 8
|
||||
move 1 from 7 to 8
|
||||
move 5 from 3 to 5
|
||||
move 4 from 7 to 2
|
||||
move 2 from 6 to 1
|
||||
move 4 from 3 to 7
|
||||
move 4 from 5 to 1
|
||||
move 21 from 8 to 6
|
||||
move 7 from 3 to 2
|
||||
move 1 from 5 to 1
|
||||
move 4 from 8 to 9
|
||||
move 16 from 6 to 1
|
||||
move 1 from 8 to 4
|
||||
move 5 from 9 to 2
|
||||
move 7 from 1 to 7
|
||||
move 10 from 1 to 3
|
||||
move 1 from 4 to 2
|
||||
move 6 from 6 to 5
|
||||
move 6 from 1 to 4
|
||||
move 4 from 7 to 9
|
||||
move 1 from 6 to 5
|
||||
move 5 from 7 to 6
|
||||
move 3 from 6 to 8
|
||||
move 1 from 7 to 6
|
||||
move 6 from 4 to 8
|
||||
move 4 from 8 to 3
|
||||
move 4 from 8 to 4
|
||||
move 17 from 2 to 1
|
||||
move 8 from 3 to 4
|
||||
move 5 from 4 to 3
|
||||
move 10 from 1 to 5
|
||||
move 11 from 3 to 5
|
||||
move 1 from 7 to 9
|
||||
move 3 from 6 to 4
|
||||
move 9 from 4 to 9
|
||||
move 7 from 1 to 3
|
||||
move 1 from 4 to 8
|
||||
move 7 from 5 to 4
|
||||
move 18 from 5 to 1
|
||||
move 13 from 1 to 6
|
||||
move 1 from 1 to 5
|
||||
move 1 from 1 to 6
|
||||
move 2 from 3 to 1
|
||||
move 1 from 3 to 1
|
||||
move 5 from 1 to 6
|
||||
move 4 from 5 to 8
|
||||
move 2 from 4 to 9
|
||||
move 1 from 1 to 9
|
||||
move 6 from 3 to 8
|
||||
move 1 from 4 to 5
|
||||
move 10 from 8 to 7
|
||||
move 16 from 6 to 7
|
||||
move 1 from 5 to 4
|
||||
move 1 from 7 to 2
|
||||
move 2 from 2 to 6
|
||||
move 2 from 8 to 5
|
||||
move 5 from 4 to 9
|
||||
move 2 from 5 to 9
|
||||
move 7 from 9 to 8
|
||||
move 2 from 6 to 9
|
||||
move 4 from 8 to 9
|
||||
move 7 from 9 to 7
|
||||
move 13 from 9 to 5
|
||||
move 10 from 5 to 1
|
||||
move 3 from 8 to 4
|
||||
move 5 from 1 to 3
|
||||
move 3 from 5 to 6
|
||||
move 3 from 9 to 7
|
||||
move 1 from 1 to 7
|
||||
move 2 from 1 to 3
|
||||
move 1 from 6 to 1
|
||||
move 4 from 3 to 8
|
||||
move 1 from 8 to 9
|
||||
move 1 from 8 to 7
|
||||
move 1 from 8 to 4
|
||||
move 1 from 9 to 7
|
||||
move 1 from 8 to 5
|
||||
move 2 from 4 to 3
|
||||
move 4 from 6 to 3
|
||||
move 1 from 5 to 1
|
||||
move 1 from 6 to 4
|
||||
move 2 from 4 to 5
|
||||
move 1 from 4 to 6
|
||||
move 1 from 6 to 4
|
||||
move 30 from 7 to 3
|
||||
move 1 from 5 to 1
|
||||
move 6 from 7 to 3
|
||||
move 2 from 1 to 7
|
||||
move 2 from 1 to 2
|
||||
move 2 from 2 to 1
|
||||
move 1 from 4 to 9
|
||||
move 3 from 1 to 2
|
||||
move 1 from 9 to 5
|
||||
move 2 from 7 to 1
|
||||
move 1 from 7 to 3
|
||||
move 1 from 1 to 9
|
||||
move 1 from 5 to 8
|
||||
move 1 from 1 to 2
|
||||
move 1 from 7 to 3
|
||||
move 1 from 9 to 4
|
||||
move 18 from 3 to 4
|
||||
move 1 from 5 to 9
|
||||
move 1 from 9 to 6
|
||||
move 1 from 2 to 7
|
||||
move 1 from 8 to 7
|
||||
move 1 from 6 to 3
|
||||
move 1 from 7 to 2
|
||||
move 14 from 4 to 6
|
||||
move 1 from 7 to 6
|
||||
move 15 from 6 to 4
|
||||
move 20 from 3 to 1
|
||||
move 5 from 4 to 9
|
||||
move 5 from 4 to 2
|
||||
move 15 from 1 to 7
|
||||
move 11 from 7 to 9
|
||||
move 2 from 7 to 6
|
||||
move 1 from 6 to 4
|
||||
move 1 from 6 to 3
|
||||
move 2 from 7 to 8
|
||||
move 10 from 4 to 3
|
||||
move 15 from 9 to 3
|
||||
move 1 from 9 to 7
|
||||
move 29 from 3 to 6
|
||||
move 3 from 1 to 6
|
||||
move 1 from 8 to 4
|
||||
move 2 from 4 to 3
|
||||
move 1 from 8 to 9
|
||||
move 4 from 6 to 1
|
||||
move 20 from 6 to 2
|
||||
move 5 from 1 to 9
|
||||
move 3 from 6 to 2
|
||||
move 4 from 6 to 3
|
||||
move 4 from 3 to 1
|
||||
move 4 from 1 to 4
|
||||
move 3 from 4 to 8
|
||||
move 6 from 3 to 4
|
||||
move 6 from 2 to 6
|
||||
move 1 from 7 to 1
|
||||
move 3 from 6 to 8
|
||||
move 6 from 9 to 3
|
||||
move 1 from 1 to 4
|
||||
move 1 from 1 to 7
|
||||
move 3 from 4 to 5
|
||||
move 2 from 6 to 4
|
||||
move 2 from 5 to 6
|
||||
move 4 from 8 to 7
|
||||
move 1 from 5 to 6
|
||||
move 1 from 8 to 4
|
||||
move 1 from 8 to 4
|
||||
move 2 from 4 to 9
|
||||
move 4 from 7 to 8
|
||||
move 4 from 4 to 3
|
||||
move 1 from 7 to 9
|
||||
move 4 from 8 to 6
|
||||
move 1 from 3 to 4
|
||||
move 1 from 3 to 5
|
||||
move 2 from 4 to 7
|
||||
move 4 from 6 to 3
|
||||
move 2 from 9 to 1
|
||||
move 2 from 7 to 4
|
||||
move 1 from 5 to 1
|
||||
move 1 from 3 to 4
|
||||
move 1 from 9 to 3
|
||||
move 4 from 4 to 5
|
||||
move 2 from 5 to 3
|
||||
move 1 from 5 to 7
|
||||
move 1 from 5 to 8
|
||||
move 2 from 6 to 4
|
||||
move 3 from 1 to 3
|
||||
move 21 from 3 to 5
|
||||
move 3 from 6 to 1
|
||||
move 1 from 7 to 1
|
||||
move 4 from 2 to 6
|
||||
move 1 from 8 to 2
|
||||
move 10 from 2 to 4
|
||||
move 4 from 1 to 2
|
||||
move 1 from 6 to 5
|
||||
move 2 from 6 to 9
|
||||
move 7 from 4 to 9
|
||||
move 1 from 6 to 5
|
||||
move 3 from 9 to 4
|
||||
move 6 from 2 to 8
|
||||
move 3 from 9 to 1
|
||||
move 8 from 4 to 3
|
||||
move 1 from 9 to 4
|
||||
move 21 from 5 to 7
|
||||
move 1 from 1 to 3
|
||||
move 2 from 9 to 6
|
||||
move 14 from 7 to 1
|
||||
move 2 from 4 to 1
|
||||
move 2 from 8 to 7
|
||||
move 1 from 8 to 2
|
||||
move 11 from 2 to 9
|
||||
move 8 from 9 to 6
|
||||
move 4 from 7 to 1
|
||||
move 1 from 7 to 4
|
||||
move 2 from 3 to 5
|
||||
move 1 from 1 to 6
|
||||
move 1 from 8 to 2
|
||||
move 3 from 7 to 5
|
||||
move 6 from 1 to 7
|
||||
move 1 from 8 to 7
|
||||
move 1 from 4 to 5
|
||||
move 4 from 6 to 5
|
||||
move 6 from 7 to 6
|
||||
move 3 from 9 to 1
|
||||
move 1 from 7 to 3
|
||||
move 11 from 5 to 1
|
||||
move 1 from 5 to 2
|
||||
move 9 from 6 to 4
|
||||
move 1 from 7 to 3
|
||||
move 2 from 6 to 1
|
||||
move 1 from 2 to 1
|
||||
move 1 from 2 to 6
|
||||
move 14 from 1 to 5
|
||||
move 1 from 8 to 4
|
||||
move 10 from 1 to 5
|
||||
move 3 from 5 to 1
|
||||
move 8 from 3 to 8
|
||||
move 16 from 5 to 7
|
||||
move 2 from 1 to 9
|
||||
move 3 from 8 to 1
|
||||
move 1 from 2 to 4
|
||||
move 6 from 7 to 4
|
||||
move 3 from 5 to 8
|
||||
move 2 from 3 to 6
|
||||
move 7 from 1 to 7
|
||||
move 14 from 4 to 3
|
||||
move 9 from 7 to 8
|
||||
move 2 from 4 to 1
|
||||
move 9 from 8 to 4
|
||||
move 7 from 8 to 2
|
||||
move 6 from 1 to 8
|
||||
move 1 from 9 to 7
|
||||
move 1 from 1 to 6
|
||||
move 1 from 9 to 6
|
||||
move 1 from 5 to 9
|
||||
move 1 from 5 to 3
|
||||
move 9 from 4 to 9
|
||||
move 3 from 3 to 6
|
||||
move 8 from 6 to 3
|
||||
move 1 from 2 to 9
|
||||
move 8 from 9 to 8
|
||||
move 6 from 2 to 9
|
||||
move 2 from 6 to 1
|
||||
move 7 from 8 to 6
|
||||
move 2 from 9 to 6
|
||||
move 8 from 7 to 8
|
||||
move 1 from 4 to 5
|
||||
move 9 from 3 to 5
|
||||
move 2 from 1 to 4
|
||||
move 1 from 7 to 4
|
||||
move 2 from 4 to 3
|
||||
move 11 from 8 to 1
|
||||
move 1 from 4 to 7
|
||||
move 1 from 7 to 8
|
||||
move 5 from 1 to 3
|
||||
move 4 from 6 to 4
|
||||
move 2 from 4 to 8
|
||||
move 1 from 4 to 8
|
||||
move 7 from 8 to 9
|
||||
move 1 from 8 to 9
|
||||
move 1 from 8 to 5
|
||||
move 18 from 3 to 2
|
||||
move 17 from 2 to 7
|
||||
move 6 from 5 to 4
|
||||
move 1 from 2 to 5
|
||||
move 4 from 4 to 6
|
||||
move 4 from 6 to 9
|
||||
move 15 from 7 to 9
|
||||
move 2 from 1 to 6
|
||||
move 2 from 7 to 9
|
||||
move 28 from 9 to 2
|
||||
move 1 from 6 to 7
|
||||
move 4 from 6 to 9
|
||||
move 3 from 1 to 7
|
||||
move 2 from 6 to 3
|
||||
move 1 from 4 to 7
|
||||
move 8 from 9 to 5
|
||||
move 13 from 5 to 3
|
||||
move 1 from 5 to 7
|
||||
move 3 from 9 to 4
|
||||
move 8 from 3 to 7
|
||||
move 28 from 2 to 5
|
||||
move 1 from 9 to 8
|
||||
move 4 from 3 to 4
|
||||
move 4 from 7 to 5
|
||||
move 2 from 3 to 9
|
||||
move 21 from 5 to 4
|
||||
move 1 from 5 to 7
|
||||
move 1 from 3 to 5
|
||||
move 3 from 5 to 7
|
||||
move 1 from 1 to 3
|
||||
move 3 from 7 to 3
|
||||
move 5 from 7 to 6
|
||||
move 10 from 4 to 8
|
||||
move 6 from 5 to 4
|
||||
move 1 from 9 to 3
|
||||
move 15 from 4 to 5
|
||||
move 10 from 4 to 7
|
||||
move 3 from 3 to 7
|
||||
move 1 from 3 to 4
|
||||
move 1 from 3 to 4
|
||||
move 7 from 5 to 1
|
||||
move 2 from 4 to 7
|
||||
move 1 from 9 to 2
|
||||
move 2 from 6 to 9
|
||||
move 1 from 5 to 3
|
||||
move 1 from 3 to 8
|
||||
move 10 from 7 to 9
|
||||
move 2 from 8 to 1
|
||||
move 9 from 9 to 2
|
||||
move 1 from 4 to 3
|
||||
move 9 from 8 to 7
|
||||
move 1 from 2 to 8
|
||||
move 5 from 5 to 4
|
||||
move 1 from 3 to 2
|
||||
move 5 from 4 to 3
|
||||
move 3 from 5 to 9
|
||||
move 6 from 7 to 3
|
||||
move 1 from 6 to 5
|
||||
move 5 from 9 to 7
|
||||
move 2 from 5 to 6
|
||||
move 3 from 6 to 7
|
||||
move 4 from 1 to 4
|
||||
move 6 from 2 to 7
|
||||
move 17 from 7 to 5
|
||||
move 1 from 6 to 1
|
||||
move 5 from 3 to 6
|
||||
move 10 from 7 to 2
|
||||
move 1 from 8 to 4
|
||||
move 1 from 9 to 8
|
||||
move 3 from 4 to 1
|
||||
move 1 from 7 to 4
|
||||
move 5 from 5 to 9
|
||||
move 2 from 8 to 7
|
||||
move 3 from 3 to 7
|
||||
move 4 from 2 to 3
|
||||
move 3 from 4 to 6
|
||||
move 7 from 5 to 8
|
||||
move 7 from 2 to 8
|
||||
move 4 from 9 to 8
|
||||
move 12 from 8 to 3
|
||||
move 17 from 3 to 2
|
||||
move 1 from 7 to 9
|
||||
move 1 from 3 to 9
|
||||
move 3 from 9 to 1
|
||||
move 2 from 5 to 1
|
||||
move 1 from 3 to 5
|
||||
move 4 from 5 to 8
|
||||
move 6 from 8 to 1
|
||||
move 17 from 2 to 3
|
||||
move 13 from 3 to 2
|
||||
move 1 from 3 to 9
|
||||
move 1 from 8 to 4
|
||||
move 1 from 4 to 8
|
||||
move 1 from 9 to 1
|
||||
move 2 from 7 to 2
|
||||
move 8 from 6 to 2
|
||||
move 2 from 7 to 5
|
||||
move 9 from 1 to 3
|
||||
move 13 from 2 to 9
|
||||
move 6 from 1 to 4
|
||||
move 6 from 4 to 5
|
||||
move 3 from 8 to 1
|
||||
move 2 from 1 to 8
|
||||
move 8 from 5 to 7
|
||||
move 2 from 3 to 1
|
||||
move 9 from 3 to 1
|
||||
move 3 from 8 to 2
|
||||
move 1 from 1 to 9
|
||||
move 1 from 3 to 9
|
||||
move 6 from 7 to 3
|
||||
move 4 from 2 to 7
|
||||
move 14 from 1 to 6
|
||||
move 2 from 3 to 9
|
||||
move 3 from 3 to 7
|
||||
move 6 from 2 to 1
|
||||
move 2 from 1 to 2
|
||||
move 9 from 6 to 3
|
||||
move 11 from 9 to 5
|
||||
move 9 from 7 to 6
|
||||
move 6 from 6 to 2
|
||||
move 1 from 1 to 8
|
||||
move 5 from 9 to 4
|
||||
move 1 from 8 to 5
|
||||
move 9 from 2 to 7
|
||||
move 10 from 5 to 8
|
@ -38,4 +38,9 @@ fn main() {
|
||||
let max_part1 = prob5::solve_part1(file_path);
|
||||
println!("Solution for problem 5 part 1: {max_part1}");
|
||||
}
|
||||
{
|
||||
let file_path = "prob5_part2.txt";
|
||||
let max_part1 = prob5::solve_part2(file_path);
|
||||
println!("Solution for problem 5 part 2: {max_part1}");
|
||||
}
|
||||
}
|
||||
|
28
src/prob5.rs
28
src/prob5.rs
@ -1,5 +1,6 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use itertools::Itertools;
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::{tag, take, take_while1},
|
||||
@ -139,9 +140,30 @@ pub fn solve_part1(file_path: &str) -> String {
|
||||
.push_front(tmp);
|
||||
});
|
||||
});
|
||||
let mut answer = String::new();
|
||||
|
||||
crate_columns
|
||||
.iter()
|
||||
.for_each(|item| answer.push(*item.front().unwrap_or_else(|| panic!(""))));
|
||||
answer
|
||||
.map(|item| item.front().unwrap())
|
||||
.join("")
|
||||
}
|
||||
|
||||
pub fn solve_part2(file_path: &str) -> String {
|
||||
let content = std::fs::read_to_string(file_path).unwrap_or_else(|err| panic!("{err}"));
|
||||
let (mut crate_columns, instructions) = parser(&content);
|
||||
instructions.iter().for_each(|ins| {
|
||||
let mut test = vec!['\0'; ins.quantity];
|
||||
(0..ins.quantity).for_each(|i| {
|
||||
test[i] = crate_columns[ins.src]
|
||||
.pop_front()
|
||||
.unwrap_or_else(|| panic!("Could not pop front the column {}", ins.src));
|
||||
//crate_columns[ins.dst].push_front(tmp);
|
||||
});
|
||||
test.reverse();
|
||||
test.iter_mut()
|
||||
.for_each(|tmp| crate_columns[ins.dst].push_front(*tmp));
|
||||
});
|
||||
crate_columns
|
||||
.iter()
|
||||
.map(|item| item.front().unwrap())
|
||||
.join("")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user