init
This commit is contained in:
7
d05/Cargo.lock
generated
Normal file
7
d05/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "d05"
|
||||
version = "0.1.0"
|
8
d05/Cargo.toml
Normal file
8
d05/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "d05"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
513
d05/input.txt
Normal file
513
d05/input.txt
Normal file
@ -0,0 +1,513 @@
|
||||
[H] [H] [V]
|
||||
[V] [V] [J] [F] [F]
|
||||
[S] [L] [M] [B] [L] [J]
|
||||
[C] [N] [B] [W] [D] [D] [M]
|
||||
[G] [L] [M] [S] [S] [C] [T] [V]
|
||||
[P] [B] [B] [P] [Q] [S] [L] [H] [B]
|
||||
[N] [J] [D] [V] [C] [Q] [Q] [M] [P]
|
||||
[R] [T] [T] [R] [G] [W] [F] [W] [L]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 3 from 3 to 7
|
||||
move 4 from 1 to 9
|
||||
move 5 from 6 to 3
|
||||
move 6 from 9 to 8
|
||||
move 2 from 9 to 5
|
||||
move 4 from 3 to 7
|
||||
move 1 from 3 to 6
|
||||
move 3 from 5 to 7
|
||||
move 1 from 2 to 1
|
||||
move 4 from 7 to 8
|
||||
move 17 from 8 to 7
|
||||
move 1 from 6 to 2
|
||||
move 2 from 6 to 7
|
||||
move 1 from 8 to 3
|
||||
move 2 from 4 to 6
|
||||
move 3 from 9 to 6
|
||||
move 5 from 6 to 3
|
||||
move 5 from 2 to 1
|
||||
move 9 from 3 to 4
|
||||
move 20 from 7 to 3
|
||||
move 7 from 5 to 3
|
||||
move 6 from 3 to 5
|
||||
move 4 from 1 to 9
|
||||
move 4 from 5 to 6
|
||||
move 2 from 1 to 8
|
||||
move 2 from 7 to 3
|
||||
move 3 from 6 to 3
|
||||
move 2 from 5 to 8
|
||||
move 2 from 9 to 3
|
||||
move 1 from 9 to 6
|
||||
move 2 from 2 to 4
|
||||
move 26 from 3 to 4
|
||||
move 28 from 4 to 6
|
||||
move 8 from 6 to 1
|
||||
move 4 from 8 to 6
|
||||
move 1 from 9 to 3
|
||||
move 2 from 3 to 6
|
||||
move 1 from 3 to 9
|
||||
move 26 from 6 to 9
|
||||
move 2 from 7 to 3
|
||||
move 5 from 1 to 4
|
||||
move 1 from 1 to 4
|
||||
move 1 from 6 to 5
|
||||
move 1 from 2 to 5
|
||||
move 2 from 3 to 7
|
||||
move 2 from 5 to 8
|
||||
move 10 from 4 to 5
|
||||
move 1 from 6 to 1
|
||||
move 1 from 8 to 5
|
||||
move 2 from 7 to 2
|
||||
move 4 from 4 to 3
|
||||
move 4 from 7 to 2
|
||||
move 2 from 1 to 8
|
||||
move 12 from 9 to 2
|
||||
move 5 from 2 to 3
|
||||
move 3 from 3 to 1
|
||||
move 1 from 1 to 7
|
||||
move 6 from 3 to 8
|
||||
move 1 from 5 to 3
|
||||
move 10 from 9 to 1
|
||||
move 7 from 8 to 7
|
||||
move 1 from 3 to 9
|
||||
move 7 from 7 to 2
|
||||
move 3 from 2 to 9
|
||||
move 6 from 2 to 9
|
||||
move 5 from 9 to 1
|
||||
move 7 from 2 to 1
|
||||
move 21 from 1 to 7
|
||||
move 2 from 1 to 2
|
||||
move 5 from 2 to 3
|
||||
move 2 from 4 to 3
|
||||
move 10 from 5 to 4
|
||||
move 11 from 4 to 7
|
||||
move 5 from 3 to 1
|
||||
move 1 from 4 to 2
|
||||
move 2 from 8 to 3
|
||||
move 7 from 9 to 3
|
||||
move 3 from 9 to 1
|
||||
move 9 from 7 to 9
|
||||
move 1 from 3 to 4
|
||||
move 3 from 9 to 4
|
||||
move 5 from 9 to 3
|
||||
move 4 from 3 to 8
|
||||
move 22 from 7 to 8
|
||||
move 10 from 3 to 5
|
||||
move 1 from 9 to 4
|
||||
move 8 from 1 to 5
|
||||
move 3 from 4 to 9
|
||||
move 1 from 3 to 6
|
||||
move 2 from 1 to 7
|
||||
move 1 from 4 to 3
|
||||
move 1 from 4 to 7
|
||||
move 1 from 2 to 1
|
||||
move 1 from 6 to 9
|
||||
move 1 from 3 to 7
|
||||
move 1 from 1 to 7
|
||||
move 4 from 9 to 3
|
||||
move 22 from 8 to 5
|
||||
move 37 from 5 to 9
|
||||
move 37 from 9 to 6
|
||||
move 3 from 7 to 9
|
||||
move 2 from 8 to 6
|
||||
move 1 from 9 to 3
|
||||
move 2 from 5 to 1
|
||||
move 1 from 2 to 5
|
||||
move 7 from 6 to 4
|
||||
move 18 from 6 to 2
|
||||
move 1 from 3 to 7
|
||||
move 1 from 5 to 4
|
||||
move 1 from 8 to 5
|
||||
move 9 from 2 to 5
|
||||
move 3 from 4 to 6
|
||||
move 2 from 2 to 7
|
||||
move 5 from 2 to 3
|
||||
move 1 from 8 to 1
|
||||
move 1 from 9 to 4
|
||||
move 2 from 7 to 8
|
||||
move 7 from 3 to 7
|
||||
move 3 from 1 to 3
|
||||
move 1 from 9 to 5
|
||||
move 17 from 6 to 2
|
||||
move 12 from 7 to 9
|
||||
move 1 from 4 to 8
|
||||
move 1 from 8 to 4
|
||||
move 4 from 5 to 2
|
||||
move 2 from 8 to 9
|
||||
move 3 from 4 to 2
|
||||
move 3 from 3 to 7
|
||||
move 2 from 4 to 3
|
||||
move 8 from 9 to 1
|
||||
move 1 from 4 to 2
|
||||
move 24 from 2 to 1
|
||||
move 6 from 5 to 1
|
||||
move 1 from 7 to 4
|
||||
move 3 from 2 to 8
|
||||
move 3 from 3 to 7
|
||||
move 1 from 4 to 6
|
||||
move 2 from 8 to 5
|
||||
move 3 from 9 to 4
|
||||
move 1 from 5 to 3
|
||||
move 1 from 3 to 5
|
||||
move 3 from 9 to 8
|
||||
move 1 from 5 to 7
|
||||
move 5 from 7 to 9
|
||||
move 2 from 8 to 4
|
||||
move 1 from 3 to 2
|
||||
move 1 from 7 to 3
|
||||
move 1 from 8 to 5
|
||||
move 1 from 2 to 9
|
||||
move 1 from 6 to 2
|
||||
move 2 from 9 to 8
|
||||
move 1 from 3 to 7
|
||||
move 24 from 1 to 3
|
||||
move 1 from 7 to 6
|
||||
move 3 from 5 to 1
|
||||
move 1 from 4 to 3
|
||||
move 1 from 8 to 6
|
||||
move 1 from 6 to 4
|
||||
move 1 from 5 to 4
|
||||
move 1 from 8 to 5
|
||||
move 1 from 5 to 7
|
||||
move 1 from 2 to 5
|
||||
move 1 from 6 to 3
|
||||
move 1 from 4 to 9
|
||||
move 1 from 5 to 7
|
||||
move 2 from 9 to 2
|
||||
move 3 from 4 to 8
|
||||
move 2 from 4 to 3
|
||||
move 11 from 1 to 9
|
||||
move 7 from 9 to 1
|
||||
move 9 from 1 to 9
|
||||
move 1 from 3 to 7
|
||||
move 3 from 7 to 4
|
||||
move 2 from 2 to 6
|
||||
move 2 from 4 to 1
|
||||
move 1 from 6 to 7
|
||||
move 22 from 3 to 7
|
||||
move 1 from 3 to 5
|
||||
move 1 from 5 to 2
|
||||
move 1 from 6 to 7
|
||||
move 5 from 1 to 9
|
||||
move 1 from 8 to 5
|
||||
move 1 from 2 to 1
|
||||
move 15 from 9 to 4
|
||||
move 6 from 9 to 6
|
||||
move 14 from 4 to 1
|
||||
move 5 from 6 to 2
|
||||
move 1 from 5 to 1
|
||||
move 9 from 1 to 4
|
||||
move 5 from 1 to 3
|
||||
move 3 from 2 to 6
|
||||
move 2 from 8 to 1
|
||||
move 5 from 1 to 9
|
||||
move 10 from 7 to 8
|
||||
move 3 from 3 to 8
|
||||
move 2 from 8 to 7
|
||||
move 5 from 4 to 9
|
||||
move 3 from 3 to 5
|
||||
move 1 from 6 to 9
|
||||
move 1 from 3 to 9
|
||||
move 1 from 3 to 6
|
||||
move 1 from 3 to 7
|
||||
move 2 from 6 to 9
|
||||
move 2 from 4 to 1
|
||||
move 13 from 9 to 8
|
||||
move 2 from 1 to 4
|
||||
move 6 from 4 to 9
|
||||
move 1 from 6 to 2
|
||||
move 1 from 2 to 3
|
||||
move 3 from 5 to 3
|
||||
move 4 from 3 to 2
|
||||
move 7 from 9 to 2
|
||||
move 1 from 6 to 4
|
||||
move 4 from 2 to 5
|
||||
move 2 from 2 to 1
|
||||
move 4 from 5 to 8
|
||||
move 1 from 4 to 2
|
||||
move 6 from 2 to 1
|
||||
move 2 from 2 to 1
|
||||
move 22 from 8 to 2
|
||||
move 16 from 7 to 4
|
||||
move 14 from 2 to 7
|
||||
move 7 from 8 to 2
|
||||
move 4 from 7 to 1
|
||||
move 14 from 2 to 1
|
||||
move 10 from 7 to 1
|
||||
move 1 from 7 to 3
|
||||
move 1 from 3 to 4
|
||||
move 1 from 2 to 5
|
||||
move 25 from 1 to 5
|
||||
move 1 from 5 to 3
|
||||
move 4 from 4 to 2
|
||||
move 13 from 4 to 6
|
||||
move 4 from 2 to 1
|
||||
move 3 from 6 to 2
|
||||
move 9 from 1 to 2
|
||||
move 22 from 5 to 4
|
||||
move 1 from 2 to 7
|
||||
move 8 from 1 to 5
|
||||
move 1 from 4 to 5
|
||||
move 15 from 4 to 3
|
||||
move 11 from 2 to 1
|
||||
move 1 from 7 to 3
|
||||
move 2 from 5 to 1
|
||||
move 13 from 3 to 5
|
||||
move 10 from 6 to 7
|
||||
move 1 from 3 to 4
|
||||
move 1 from 3 to 6
|
||||
move 1 from 3 to 9
|
||||
move 1 from 9 to 5
|
||||
move 1 from 6 to 2
|
||||
move 6 from 4 to 9
|
||||
move 1 from 3 to 7
|
||||
move 1 from 5 to 1
|
||||
move 3 from 5 to 6
|
||||
move 1 from 4 to 3
|
||||
move 12 from 5 to 6
|
||||
move 1 from 2 to 8
|
||||
move 4 from 1 to 7
|
||||
move 1 from 3 to 2
|
||||
move 1 from 2 to 6
|
||||
move 9 from 6 to 4
|
||||
move 1 from 8 to 7
|
||||
move 3 from 1 to 2
|
||||
move 2 from 2 to 5
|
||||
move 5 from 4 to 6
|
||||
move 1 from 4 to 6
|
||||
move 6 from 7 to 3
|
||||
move 6 from 5 to 7
|
||||
move 12 from 7 to 4
|
||||
move 1 from 2 to 8
|
||||
move 6 from 9 to 5
|
||||
move 1 from 8 to 9
|
||||
move 1 from 3 to 6
|
||||
move 4 from 4 to 1
|
||||
move 1 from 7 to 9
|
||||
move 4 from 4 to 6
|
||||
move 2 from 9 to 7
|
||||
move 7 from 5 to 1
|
||||
move 3 from 1 to 4
|
||||
move 4 from 3 to 1
|
||||
move 10 from 6 to 9
|
||||
move 1 from 3 to 5
|
||||
move 8 from 4 to 6
|
||||
move 2 from 5 to 2
|
||||
move 4 from 7 to 4
|
||||
move 1 from 5 to 9
|
||||
move 5 from 4 to 7
|
||||
move 1 from 4 to 8
|
||||
move 2 from 2 to 6
|
||||
move 1 from 5 to 3
|
||||
move 4 from 9 to 6
|
||||
move 11 from 6 to 8
|
||||
move 1 from 1 to 4
|
||||
move 1 from 4 to 1
|
||||
move 1 from 3 to 1
|
||||
move 10 from 1 to 4
|
||||
move 3 from 9 to 5
|
||||
move 1 from 9 to 3
|
||||
move 2 from 7 to 4
|
||||
move 3 from 9 to 4
|
||||
move 3 from 5 to 8
|
||||
move 1 from 3 to 5
|
||||
move 15 from 8 to 2
|
||||
move 8 from 1 to 4
|
||||
move 2 from 1 to 2
|
||||
move 10 from 2 to 3
|
||||
move 1 from 5 to 7
|
||||
move 3 from 7 to 8
|
||||
move 10 from 3 to 5
|
||||
move 4 from 4 to 2
|
||||
move 7 from 4 to 1
|
||||
move 2 from 7 to 4
|
||||
move 1 from 8 to 9
|
||||
move 5 from 1 to 6
|
||||
move 13 from 6 to 2
|
||||
move 2 from 1 to 4
|
||||
move 15 from 4 to 5
|
||||
move 1 from 9 to 3
|
||||
move 1 from 3 to 4
|
||||
move 2 from 8 to 3
|
||||
move 20 from 2 to 6
|
||||
move 3 from 2 to 8
|
||||
move 2 from 3 to 8
|
||||
move 9 from 5 to 2
|
||||
move 6 from 5 to 9
|
||||
move 2 from 4 to 1
|
||||
move 8 from 5 to 4
|
||||
move 2 from 8 to 1
|
||||
move 5 from 9 to 5
|
||||
move 3 from 5 to 7
|
||||
move 1 from 8 to 2
|
||||
move 2 from 4 to 1
|
||||
move 14 from 6 to 4
|
||||
move 2 from 1 to 8
|
||||
move 5 from 6 to 3
|
||||
move 3 from 1 to 6
|
||||
move 5 from 3 to 2
|
||||
move 1 from 9 to 6
|
||||
move 8 from 6 to 2
|
||||
move 2 from 7 to 4
|
||||
move 1 from 1 to 3
|
||||
move 2 from 5 to 8
|
||||
move 5 from 4 to 3
|
||||
move 2 from 5 to 3
|
||||
move 1 from 7 to 5
|
||||
move 4 from 4 to 3
|
||||
move 2 from 4 to 2
|
||||
move 1 from 3 to 7
|
||||
move 5 from 3 to 7
|
||||
move 1 from 7 to 3
|
||||
move 3 from 3 to 2
|
||||
move 1 from 5 to 9
|
||||
move 2 from 7 to 9
|
||||
move 1 from 9 to 5
|
||||
move 1 from 5 to 3
|
||||
move 10 from 4 to 9
|
||||
move 3 from 3 to 9
|
||||
move 27 from 2 to 5
|
||||
move 3 from 8 to 3
|
||||
move 2 from 2 to 6
|
||||
move 4 from 9 to 7
|
||||
move 5 from 3 to 8
|
||||
move 5 from 7 to 3
|
||||
move 25 from 5 to 1
|
||||
move 3 from 9 to 8
|
||||
move 1 from 3 to 2
|
||||
move 1 from 5 to 3
|
||||
move 2 from 7 to 9
|
||||
move 10 from 8 to 7
|
||||
move 1 from 2 to 3
|
||||
move 13 from 1 to 7
|
||||
move 3 from 9 to 7
|
||||
move 3 from 3 to 1
|
||||
move 1 from 5 to 8
|
||||
move 2 from 8 to 6
|
||||
move 4 from 6 to 5
|
||||
move 4 from 5 to 6
|
||||
move 1 from 4 to 6
|
||||
move 23 from 7 to 9
|
||||
move 2 from 6 to 8
|
||||
move 28 from 9 to 1
|
||||
move 1 from 8 to 1
|
||||
move 3 from 7 to 3
|
||||
move 1 from 9 to 4
|
||||
move 3 from 3 to 6
|
||||
move 3 from 3 to 4
|
||||
move 6 from 6 to 8
|
||||
move 12 from 1 to 7
|
||||
move 9 from 1 to 6
|
||||
move 3 from 6 to 3
|
||||
move 2 from 4 to 7
|
||||
move 4 from 8 to 7
|
||||
move 1 from 8 to 5
|
||||
move 1 from 8 to 4
|
||||
move 8 from 1 to 7
|
||||
move 1 from 3 to 4
|
||||
move 1 from 8 to 3
|
||||
move 3 from 7 to 5
|
||||
move 9 from 1 to 3
|
||||
move 3 from 6 to 5
|
||||
move 3 from 1 to 7
|
||||
move 4 from 4 to 2
|
||||
move 3 from 1 to 4
|
||||
move 4 from 2 to 8
|
||||
move 1 from 6 to 2
|
||||
move 3 from 5 to 6
|
||||
move 4 from 8 to 5
|
||||
move 9 from 7 to 6
|
||||
move 12 from 7 to 1
|
||||
move 5 from 7 to 3
|
||||
move 1 from 9 to 7
|
||||
move 1 from 2 to 9
|
||||
move 1 from 9 to 4
|
||||
move 7 from 6 to 3
|
||||
move 5 from 6 to 2
|
||||
move 1 from 7 to 6
|
||||
move 3 from 6 to 1
|
||||
move 2 from 4 to 9
|
||||
move 7 from 5 to 8
|
||||
move 2 from 9 to 4
|
||||
move 1 from 5 to 8
|
||||
move 4 from 4 to 1
|
||||
move 11 from 1 to 7
|
||||
move 8 from 3 to 1
|
||||
move 8 from 8 to 6
|
||||
move 3 from 3 to 5
|
||||
move 5 from 6 to 1
|
||||
move 2 from 1 to 2
|
||||
move 6 from 2 to 3
|
||||
move 2 from 6 to 7
|
||||
move 3 from 5 to 4
|
||||
move 7 from 3 to 9
|
||||
move 5 from 9 to 5
|
||||
move 3 from 4 to 3
|
||||
move 4 from 5 to 2
|
||||
move 2 from 9 to 4
|
||||
move 6 from 1 to 9
|
||||
move 1 from 6 to 9
|
||||
move 7 from 7 to 1
|
||||
move 1 from 7 to 3
|
||||
move 2 from 4 to 5
|
||||
move 1 from 9 to 1
|
||||
move 4 from 2 to 3
|
||||
move 2 from 5 to 2
|
||||
move 9 from 3 to 1
|
||||
move 3 from 2 to 4
|
||||
move 28 from 1 to 6
|
||||
move 2 from 1 to 3
|
||||
move 17 from 6 to 3
|
||||
move 2 from 9 to 5
|
||||
move 2 from 6 to 7
|
||||
move 1 from 5 to 7
|
||||
move 1 from 9 to 4
|
||||
move 5 from 6 to 9
|
||||
move 14 from 3 to 5
|
||||
move 15 from 5 to 9
|
||||
move 1 from 4 to 9
|
||||
move 1 from 5 to 6
|
||||
move 1 from 4 to 1
|
||||
move 11 from 3 to 6
|
||||
move 1 from 1 to 6
|
||||
move 12 from 6 to 8
|
||||
move 4 from 9 to 7
|
||||
move 20 from 9 to 4
|
||||
move 18 from 4 to 5
|
||||
move 6 from 5 to 8
|
||||
move 12 from 8 to 2
|
||||
move 2 from 2 to 6
|
||||
move 1 from 5 to 2
|
||||
move 4 from 4 to 8
|
||||
move 5 from 5 to 9
|
||||
move 4 from 3 to 6
|
||||
move 1 from 3 to 8
|
||||
move 7 from 7 to 8
|
||||
move 10 from 2 to 8
|
||||
move 1 from 6 to 3
|
||||
move 10 from 6 to 5
|
||||
move 10 from 5 to 2
|
||||
move 2 from 7 to 5
|
||||
move 9 from 2 to 1
|
||||
move 27 from 8 to 9
|
||||
move 2 from 2 to 7
|
||||
move 9 from 1 to 2
|
||||
move 1 from 5 to 3
|
||||
move 9 from 2 to 1
|
||||
move 1 from 8 to 7
|
||||
move 2 from 1 to 3
|
||||
move 19 from 9 to 1
|
||||
move 5 from 5 to 1
|
||||
move 3 from 9 to 2
|
||||
move 2 from 3 to 9
|
||||
move 1 from 3 to 4
|
||||
move 5 from 7 to 4
|
||||
move 1 from 7 to 3
|
||||
move 17 from 1 to 2
|
||||
move 1 from 5 to 3
|
||||
move 9 from 9 to 5
|
||||
move 2 from 1 to 2
|
||||
move 1 from 4 to 9
|
||||
move 2 from 4 to 6
|
||||
move 1 from 4 to 7
|
||||
move 6 from 1 to 8
|
117
d05/src/a1.rs
Normal file
117
d05/src/a1.rs
Normal file
@ -0,0 +1,117 @@
|
||||
|
||||
struct CargoDock {
|
||||
stacks : Vec<Vec<char>>,
|
||||
}
|
||||
|
||||
impl CargoDock {
|
||||
|
||||
fn new() -> Self {
|
||||
CargoDock { stacks: vec![] }
|
||||
}
|
||||
|
||||
fn add_stacks(&mut self, s : Vec<Vec<char>>) {
|
||||
self.stacks = s;
|
||||
}
|
||||
|
||||
fn parse_move(inp : String) -> Vec<i32> {
|
||||
let mut out_vec = vec![];
|
||||
inp.split(' ').for_each(|elem| {
|
||||
match elem.parse::<i32>() {
|
||||
Ok(r) => {
|
||||
out_vec.push(r);
|
||||
}
|
||||
|
||||
Err(_) => {}
|
||||
}
|
||||
});
|
||||
|
||||
out_vec
|
||||
}
|
||||
|
||||
fn execute_move(&mut self, m : String) {
|
||||
|
||||
let parsed_move = CargoDock::parse_move(m);
|
||||
|
||||
let count = parsed_move[0];
|
||||
let origin : usize = (parsed_move[1] - 1) as usize;
|
||||
let destination : usize = (parsed_move[2] - 1) as usize;
|
||||
|
||||
for _ in 0..count {
|
||||
let top = self.stacks[origin].pop().unwrap();
|
||||
self.stacks[destination].push(top);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn get_top_layer(&self) -> String {
|
||||
let mut s = String::new();
|
||||
|
||||
self.stacks.iter().for_each(|vec| {
|
||||
s.push(*vec.last().unwrap());
|
||||
});
|
||||
|
||||
s
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn parse_stack(inp : Vec<String>) -> Vec<Vec<char>> {
|
||||
let mut vec : Vec<Vec<char>> = vec![];
|
||||
vec.push(vec![]);
|
||||
|
||||
inp.iter().for_each(|elem| {
|
||||
if elem.contains('1') {
|
||||
return;
|
||||
}
|
||||
|
||||
let res = elem.split(' ').collect::<Vec<&str>>();
|
||||
let mut space_count = 0;
|
||||
let mut index = 0;
|
||||
for s in &res {
|
||||
if s.is_empty() {
|
||||
space_count += 1;
|
||||
|
||||
} else {
|
||||
let found_char = s.chars().nth(1).unwrap();
|
||||
index += space_count / 4;
|
||||
space_count = 0;
|
||||
while vec.len() < index + 1 {
|
||||
vec.push(vec![]);
|
||||
}
|
||||
vec[index].push(found_char);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
for v in &mut vec {
|
||||
v.reverse();
|
||||
}
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn run(inp :Vec<String>) {
|
||||
|
||||
let mut prev = 0;
|
||||
|
||||
let mut cd = CargoDock::new();
|
||||
|
||||
for i in 0..inp.len() {
|
||||
if inp[i].is_empty() {
|
||||
let stacks = parse_stack(inp[0..i].to_vec());
|
||||
cd.add_stacks(stacks);
|
||||
prev = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for i in (prev+1)..inp.len() {
|
||||
cd.execute_move(inp[i].clone());
|
||||
}
|
||||
|
||||
println!("a1: {:?}", cd.get_top_layer());
|
||||
|
||||
}
|
116
d05/src/a2.rs
Normal file
116
d05/src/a2.rs
Normal file
@ -0,0 +1,116 @@
|
||||
|
||||
struct CargoDock {
|
||||
stacks : Vec<Vec<char>>,
|
||||
}
|
||||
|
||||
impl CargoDock {
|
||||
|
||||
fn new() -> Self {
|
||||
CargoDock { stacks: vec![] }
|
||||
}
|
||||
|
||||
fn add_stacks(&mut self, s : Vec<Vec<char>>) {
|
||||
self.stacks = s;
|
||||
}
|
||||
|
||||
fn parse_move(inp : String) -> Vec<i32> {
|
||||
let mut out_vec = vec![];
|
||||
inp.split(' ').for_each(|elem| {
|
||||
match elem.parse::<i32>() {
|
||||
Ok(i) => { out_vec.push(i); }
|
||||
|
||||
Err(_) => {}
|
||||
}
|
||||
});
|
||||
|
||||
out_vec
|
||||
}
|
||||
|
||||
fn execute_move(&mut self, m : String) {
|
||||
|
||||
let parsed_move = CargoDock::parse_move(m);
|
||||
|
||||
let count = parsed_move[0];
|
||||
let origin : usize = (parsed_move[1] - 1) as usize;
|
||||
let destination : usize = (parsed_move[2] - 1) as usize;
|
||||
let mut tmp_vec : Vec<char> = vec![];
|
||||
for _ in 0..count {
|
||||
let top = self.stacks[origin].pop().unwrap();
|
||||
tmp_vec.push(top);
|
||||
}
|
||||
tmp_vec.reverse();
|
||||
self.stacks[destination].append(&mut tmp_vec);
|
||||
|
||||
}
|
||||
|
||||
fn get_top_layer(&self) -> String {
|
||||
let mut s = String::new();
|
||||
|
||||
self.stacks.iter().for_each(|vec| {
|
||||
s.push(*vec.last().unwrap());
|
||||
});
|
||||
|
||||
s
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn parse_stack(inp : Vec<String>) -> Vec<Vec<char>> {
|
||||
let mut vec : Vec<Vec<char>> = vec![vec![]];
|
||||
|
||||
inp.iter().for_each(|elem| {
|
||||
if elem.contains('1') {
|
||||
return;
|
||||
}
|
||||
|
||||
let res = elem.split(' ').collect::<Vec<&str>>();
|
||||
let mut space_count = 0;
|
||||
let mut index = 0;
|
||||
for s in &res {
|
||||
if s.is_empty() {
|
||||
space_count += 1;
|
||||
|
||||
} else {
|
||||
let found_char = s.chars().nth(1).unwrap();
|
||||
index += space_count / 4;
|
||||
space_count = 0;
|
||||
while vec.len() < index + 1 {
|
||||
vec.push(vec![]);
|
||||
}
|
||||
vec[index].push(found_char);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
for v in &mut vec {
|
||||
v.reverse();
|
||||
}
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn run(inp :Vec<String>) {
|
||||
|
||||
let mut prev = 0;
|
||||
|
||||
let mut cd = CargoDock::new();
|
||||
|
||||
for i in 0..inp.len() {
|
||||
if inp[i].is_empty() {
|
||||
let stacks = parse_stack(inp[0..i].to_vec());
|
||||
cd.add_stacks(stacks);
|
||||
prev = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for i in (prev+1)..inp.len() {
|
||||
cd.execute_move(inp[i].clone());
|
||||
}
|
||||
|
||||
println!("a2: {:?}", cd.get_top_layer());
|
||||
|
||||
}
|
38
d05/src/main.rs
Normal file
38
d05/src/main.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use std::io::BufRead;
|
||||
|
||||
mod a1;
|
||||
mod a2;
|
||||
|
||||
fn read_file(path :&str) -> Vec<String> {
|
||||
|
||||
return match std::fs::File::open(path) {
|
||||
|
||||
Ok(handle) => {
|
||||
|
||||
let reader = std::io::BufReader::new(handle);
|
||||
|
||||
let mut vec : Vec<String> = vec![];
|
||||
|
||||
reader.lines().for_each(|elem| {
|
||||
vec.push(elem.unwrap());
|
||||
});
|
||||
|
||||
vec
|
||||
|
||||
}
|
||||
|
||||
Err(_) => vec![]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let inp :Vec<String> = read_file("input.txt");
|
||||
|
||||
a1::run(inp.clone());
|
||||
|
||||
a2::run(inp);
|
||||
|
||||
}
|
1
d05/target/.rustc_info.json
Normal file
1
d05/target/.rustc_info.json
Normal file
@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":15594459422025777716,"outputs":{"8204103499295538959":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\tfuec\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.65.0 (897e37553 2022-11-02)\nbinary: rustc\ncommit-hash: 897e37553bba8b42751c67658967889d11ecd120\ncommit-date: 2022-11-02\nhost: x86_64-pc-windows-msvc\nrelease: 1.65.0\nLLVM version: 15.0.0\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"8623966523033996810":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\tfuec\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
3
d05/target/CACHEDIR.TAG
Normal file
3
d05/target/CACHEDIR.TAG
Normal file
@ -0,0 +1,3 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
0
d05/target/debug/.cargo-lock
Normal file
0
d05/target/debug/.cargo-lock
Normal file
@ -0,0 +1 @@
|
||||
a62220af2acc103e
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":7309141686862299243,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-54bad1502471c435\\dep-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
BIN
d05/target/debug/.fingerprint/d05-54bad1502471c435/dep-bin-d05
Normal file
BIN
d05/target/debug/.fingerprint/d05-54bad1502471c435/dep-bin-d05
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
e737b342d3e62e08
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":9251013656241001069,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-60235cbe9d69ff8a\\dep-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
BIN
d05/target/debug/.fingerprint/d05-60235cbe9d69ff8a/dep-bin-d05
Normal file
BIN
d05/target/debug/.fingerprint/d05-60235cbe9d69ff8a/dep-bin-d05
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
f0fa31a79957e157
|
@ -0,0 +1 @@
|
||||
{"rustc":2347157018072859861,"features":"[]","target":16997346216964277088,"profile":1021633075455700787,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\d05-cd6375c08847f9de\\dep-test-bin-d05"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
1
d05/target/debug/d05.d
Normal file
1
d05/target/debug/d05.d
Normal file
@ -0,0 +1 @@
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\d05.exe: C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\src\a1.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\src\a2.rs C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\src\main.rs
|
BIN
d05/target/debug/d05.exe
Normal file
BIN
d05/target/debug/d05.exe
Normal file
Binary file not shown.
BIN
d05/target/debug/d05.pdb
Normal file
BIN
d05/target/debug/d05.pdb
Normal file
Binary file not shown.
7
d05/target/debug/deps/d05-54bad1502471c435.d
Normal file
7
d05/target/debug/deps/d05-54bad1502471c435.d
Normal file
@ -0,0 +1,7 @@
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05-54bad1502471c435.rmeta: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05-54bad1502471c435.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
7
d05/target/debug/deps/d05-cd6375c08847f9de.d
Normal file
7
d05/target/debug/deps/d05-cd6375c08847f9de.d
Normal file
@ -0,0 +1,7 @@
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05-cd6375c08847f9de.rmeta: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
c:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05-cd6375c08847f9de.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
7
d05/target/debug/deps/d05.d
Normal file
7
d05/target/debug/deps/d05.d
Normal file
@ -0,0 +1,7 @@
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05.exe: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
C:\personal\Programmierdaten\rust\advent_of_code\y2022\d05\target\debug\deps\d05.d: src\main.rs src\a1.rs src\a2.rs
|
||||
|
||||
src\main.rs:
|
||||
src\a1.rs:
|
||||
src\a2.rs:
|
BIN
d05/target/debug/deps/d05.exe
Normal file
BIN
d05/target/debug/deps/d05.exe
Normal file
Binary file not shown.
BIN
d05/target/debug/deps/d05.pdb
Normal file
BIN
d05/target/debug/deps/d05.pdb
Normal file
Binary file not shown.
0
d05/target/debug/deps/libd05-54bad1502471c435.rmeta
Normal file
0
d05/target/debug/deps/libd05-54bad1502471c435.rmeta
Normal file
0
d05/target/debug/deps/libd05-cd6375c08847f9de.rmeta
Normal file
0
d05/target/debug/deps/libd05-cd6375c08847f9de.rmeta
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user