Day 5 + changes in tests

This commit is contained in:
Bizcochito 2022-12-05 10:50:03 +01:00
parent 837e429cc3
commit 864f0dac87
12 changed files with 4251 additions and 3645 deletions

4
Cargo.lock generated
View File

@ -18,6 +18,10 @@ version = "0.1.0"
name = "day04" name = "day04"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "day05"
version = "0.1.0"
[[package]] [[package]]
name = "tiesto" name = "tiesto"
version = "0.1.0" version = "0.1.0"

View File

@ -6,7 +6,7 @@ members = [
"day02", "day02",
"day03", "day03",
"day04", "day04",
# "day05", "day05",
# "day06", # "day06",
# "day07", # "day07",
# "day08", # "day08",

View File

@ -41,10 +41,7 @@ fn get_max_3_elf(elfs: &mut Vec<u32>) -> u32{
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; const INPUT: &str = r#"1000
#[test]
fn it_works() {
let input = r#"1000
2000 2000
3000 3000
@ -58,26 +55,15 @@ mod test {
9000 9000
10000"#; 10000"#;
let tst = get_elfs(input); use super::*;
#[test]
fn calories1() {
let tst = get_elfs(INPUT);
assert_eq!(get_max_elf(&tst), 24000); assert_eq!(get_max_elf(&tst), 24000);
} }
#[test] #[test]
fn it_works2() { fn calories2() {
let input = r#"1000 let mut tst = get_elfs(INPUT);
2000
3000
4000
5000
6000
7000
8000
9000
10000"#;
let mut tst = get_elfs(input);
assert_eq!(get_max_3_elf(&mut tst), 45000); assert_eq!(get_max_3_elf(&mut tst), 45000);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -61,19 +61,16 @@ fn get_points(input: &str, f: &dyn Fn(&str,&str) -> i32) -> i32 {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
const INPUT: &str = r#"A Y
B X
C Z"#;
use super::*; use super::*;
#[test] #[test]
fn it_works() { fn rps1() {
let input = r#"A Y assert_eq!(get_points(INPUT, &get_round), 15);
B X
C Z"#;
assert_eq!(get_points(input, &get_round), 15);
} }
#[test] #[test]
fn it_works2() { fn rps2() {
let input = r#"A Y assert_eq!(get_points(INPUT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SlcSc wBHQQZHVCcpwDgdZdMsZjvMZFn
frsBbWhtSRzSLfRf GPSzlNlJLfzzzvsWdWLMmFWLMM
qDCqddbsWrqzhsdNmdJNJHjTggFFVV NfqGSfrTNzRTqJfRbptQHFQFrwrFHBHw
NTWTDrSdFTLtPTGf sNjVMVNVMzPzQgghcMsNzJtjSJtTFDTJtJnnDLjDnL
lZqjHlVRvRltLtRWFMtFLL CHwrdCpvCrwrWdpZqcpFttJSFJTLLHLJfbnbfD
qvjWzzvVbZpjqllggscdchwDrCphwsdhrD qrlZCwlqZrqqpWdlRqCRqdqcVNsVMzQzmNgNPBsRhVQVVzMs

View File

@ -39,10 +39,10 @@ fn grup_repeat(grup: &Vec<&str>) -> char{
}; };
for c in repeated { for c in repeated {
if let Some(i) = grup[2].find(c){ if let Some(i) = grup[2].find(c){
return (grup[2].chars().nth(i).expect("should have failed before")); return grup[2].chars().nth(i).expect("should have failed before");
} }
}; };
return panic!(); panic!("Should not get here")
} }
fn get_repeat(s: &str) -> char{ fn get_repeat(s: &str) -> char{
@ -54,30 +54,24 @@ fn get_repeat(s: &str) -> char{
return s2.chars().nth(i).expect("should have failed before"); return s2.chars().nth(i).expect("should have failed before");
} }
}; };
return panic!(); panic!("Should not get here")
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
const INPUT: &str =r#"vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"#;
use super::*; use super::*;
#[test] #[test]
fn it_works() { fn backpacks1() {
let input = r#"vJrwpWtwJgWrhcsFMMfFFhFp assert_eq!(INPUT.lines().map(|l| get_priori(get_repeat(l))).sum::<u32>(), 157);
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"#;
assert_eq!(input.lines().map(|l| get_priori(get_repeat(l))).sum::<u32>(), 157);
} }
#[test] #[test]
fn it_works2() { fn backpacks2() {
let input = r#"vJrwpWtwJgWrhcsFMMfFFhFp assert_eq!(get_groups(INPUT).iter().map(|g| get_priori(grup_repeat(g))).sum::<u32>(), 70);
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"#;
assert_eq!(get_groups(input).iter().map(|g| get_priori(grup_repeat(g))).sum::<u32>(), 70);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,25 +31,19 @@ fn get_range(s: &str) -> (u32, u32){
#[cfg(test)] #[cfg(test)]
mod test { mod test {
const INPUT: &str = r#"2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"#;
use super::*; use super::*;
#[test] #[test]
fn it_works() { fn ranges1() {
let input = r#"2-4,6-8 assert_eq!(INPUT.lines().map(|l| get_ranges(l)).filter(|t| ranges_contain(t.0,t.1)).count(), 2);
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"#;
assert_eq!(input.lines().map(|l| get_ranges(l)).filter(|t| ranges_contain(t.0,t.1)).count(), 2);
} }
#[test] #[test]
fn it_works2() { fn ranges2() {
let input = r#"2-4,6-8 assert_eq!(INPUT.lines().map(|l| get_ranges(l)).filter(|t| ranges_overlap(t.0,t.1)).count(), 4);
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"#;
assert_eq!(input.lines().map(|l| get_ranges(l)).filter(|t| ranges_overlap(t.0,t.1)).count(), 4);
} }
} }

8
day05/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day05"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

514
day05/input Normal file
View File

@ -0,0 +1,514 @@
[V] [B] [F]
[N] [Q] [W] [R] [B]
[F] [D] [S] [B] [L] [P]
[S] [J] [C] [F] [C] [D] [G]
[M] [M] [H] [L] [P] [N] [P] [V]
[P] [L] [D] [C] [T] [Q] [R] [S] [J]
[H] [R] [Q] [S] [V] [R] [V] [Z] [S]
[J] [S] [N] [R] [M] [T] [G] [C] [D]
1 2 3 4 5 6 7 8 9
move 1 from 8 to 4
move 1 from 7 to 8
move 1 from 6 to 3
move 2 from 6 to 5
move 8 from 5 to 1
move 5 from 3 to 8
move 1 from 7 to 8
move 8 from 1 to 2
move 3 from 3 to 9
move 13 from 8 to 7
move 2 from 1 to 2
move 1 from 6 to 2
move 2 from 1 to 7
move 4 from 4 to 2
move 10 from 9 to 4
move 7 from 4 to 1
move 1 from 6 to 7
move 2 from 4 to 5
move 1 from 5 to 2
move 1 from 5 to 8
move 3 from 1 to 5
move 2 from 4 to 6
move 2 from 6 to 4
move 2 from 4 to 5
move 5 from 1 to 5
move 1 from 9 to 5
move 1 from 8 to 5
move 14 from 2 to 6
move 12 from 7 to 4
move 4 from 6 to 7
move 3 from 6 to 4
move 4 from 4 to 9
move 2 from 4 to 6
move 2 from 9 to 3
move 9 from 4 to 3
move 2 from 1 to 6
move 5 from 7 to 3
move 4 from 7 to 8
move 2 from 6 to 7
move 3 from 6 to 7
move 10 from 5 to 8
move 8 from 8 to 9
move 10 from 9 to 7
move 12 from 7 to 5
move 1 from 1 to 5
move 3 from 7 to 2
move 10 from 3 to 7
move 6 from 5 to 7
move 2 from 6 to 1
move 12 from 2 to 7
move 3 from 3 to 1
move 1 from 6 to 5
move 10 from 5 to 7
move 3 from 3 to 4
move 34 from 7 to 1
move 2 from 6 to 9
move 1 from 6 to 3
move 3 from 1 to 3
move 1 from 7 to 3
move 3 from 3 to 6
move 1 from 4 to 3
move 22 from 1 to 6
move 2 from 9 to 7
move 2 from 4 to 9
move 12 from 6 to 8
move 1 from 7 to 6
move 4 from 8 to 2
move 1 from 7 to 1
move 6 from 8 to 9
move 1 from 2 to 5
move 1 from 2 to 7
move 13 from 1 to 2
move 2 from 3 to 1
move 4 from 7 to 5
move 3 from 9 to 4
move 1 from 1 to 8
move 4 from 5 to 2
move 12 from 6 to 2
move 3 from 1 to 3
move 1 from 4 to 1
move 9 from 8 to 5
move 6 from 5 to 7
move 2 from 4 to 5
move 5 from 9 to 6
move 5 from 3 to 7
move 30 from 2 to 6
move 11 from 7 to 9
move 36 from 6 to 3
move 10 from 9 to 3
move 1 from 6 to 5
move 3 from 5 to 2
move 2 from 5 to 2
move 28 from 3 to 4
move 6 from 4 to 1
move 1 from 2 to 3
move 2 from 5 to 2
move 6 from 1 to 7
move 1 from 1 to 6
move 6 from 3 to 5
move 6 from 7 to 2
move 1 from 6 to 4
move 2 from 2 to 6
move 8 from 2 to 1
move 3 from 2 to 4
move 2 from 3 to 4
move 4 from 3 to 4
move 1 from 6 to 1
move 2 from 1 to 8
move 1 from 6 to 4
move 1 from 9 to 3
move 2 from 5 to 4
move 1 from 8 to 7
move 1 from 7 to 9
move 1 from 3 to 5
move 1 from 8 to 6
move 34 from 4 to 9
move 13 from 9 to 8
move 1 from 8 to 2
move 1 from 2 to 1
move 4 from 5 to 1
move 9 from 8 to 7
move 11 from 1 to 3
move 1 from 4 to 2
move 1 from 6 to 7
move 1 from 9 to 4
move 1 from 4 to 1
move 1 from 5 to 3
move 5 from 7 to 8
move 1 from 2 to 5
move 1 from 5 to 1
move 21 from 9 to 5
move 19 from 3 to 4
move 17 from 4 to 6
move 2 from 8 to 4
move 2 from 6 to 8
move 2 from 6 to 9
move 2 from 7 to 6
move 1 from 4 to 9
move 6 from 5 to 6
move 1 from 9 to 8
move 8 from 5 to 7
move 15 from 6 to 2
move 1 from 9 to 7
move 2 from 1 to 6
move 3 from 4 to 7
move 1 from 1 to 6
move 3 from 5 to 4
move 2 from 5 to 6
move 2 from 4 to 1
move 13 from 7 to 8
move 2 from 6 to 4
move 3 from 2 to 4
move 2 from 7 to 6
move 5 from 4 to 6
move 4 from 2 to 6
move 1 from 1 to 9
move 18 from 8 to 3
move 1 from 4 to 5
move 1 from 2 to 7
move 15 from 3 to 1
move 1 from 5 to 1
move 3 from 3 to 4
move 1 from 5 to 4
move 1 from 5 to 6
move 1 from 6 to 8
move 2 from 8 to 2
move 3 from 1 to 8
move 6 from 2 to 8
move 1 from 7 to 6
move 12 from 8 to 5
move 2 from 9 to 6
move 6 from 1 to 5
move 9 from 5 to 3
move 1 from 2 to 8
move 20 from 6 to 9
move 3 from 6 to 7
move 1 from 7 to 1
move 7 from 3 to 4
move 2 from 7 to 2
move 1 from 8 to 7
move 8 from 4 to 1
move 11 from 1 to 7
move 10 from 7 to 6
move 2 from 4 to 9
move 21 from 9 to 3
move 6 from 5 to 9
move 6 from 3 to 2
move 1 from 4 to 5
move 1 from 7 to 9
move 8 from 3 to 2
move 9 from 2 to 1
move 14 from 1 to 6
move 1 from 1 to 7
move 4 from 3 to 8
move 3 from 8 to 7
move 5 from 7 to 4
move 3 from 6 to 9
move 2 from 3 to 7
move 3 from 5 to 6
move 1 from 5 to 6
move 2 from 7 to 9
move 1 from 8 to 3
move 22 from 6 to 5
move 3 from 9 to 4
move 3 from 6 to 1
move 5 from 4 to 6
move 9 from 2 to 8
move 4 from 6 to 1
move 1 from 3 to 2
move 1 from 2 to 3
move 6 from 8 to 1
move 2 from 4 to 3
move 10 from 1 to 7
move 2 from 8 to 7
move 1 from 9 to 6
move 4 from 3 to 5
move 1 from 8 to 3
move 4 from 9 to 8
move 1 from 4 to 3
move 1 from 3 to 8
move 3 from 7 to 6
move 1 from 1 to 5
move 10 from 5 to 9
move 5 from 6 to 4
move 5 from 8 to 5
move 4 from 9 to 8
move 3 from 3 to 9
move 2 from 8 to 6
move 5 from 7 to 5
move 1 from 4 to 1
move 1 from 1 to 2
move 2 from 8 to 6
move 1 from 2 to 1
move 1 from 7 to 2
move 1 from 1 to 5
move 28 from 5 to 9
move 3 from 6 to 1
move 1 from 6 to 9
move 1 from 2 to 9
move 2 from 1 to 2
move 2 from 7 to 5
move 1 from 7 to 5
move 1 from 2 to 5
move 3 from 1 to 9
move 1 from 5 to 8
move 15 from 9 to 2
move 11 from 9 to 4
move 11 from 4 to 7
move 2 from 4 to 1
move 7 from 7 to 8
move 1 from 1 to 4
move 20 from 9 to 1
move 2 from 7 to 8
move 1 from 4 to 6
move 1 from 6 to 2
move 2 from 7 to 5
move 1 from 9 to 6
move 1 from 4 to 9
move 4 from 5 to 2
move 1 from 6 to 8
move 1 from 4 to 9
move 11 from 8 to 3
move 1 from 1 to 9
move 1 from 5 to 9
move 1 from 2 to 6
move 4 from 9 to 8
move 4 from 8 to 7
move 10 from 1 to 6
move 7 from 1 to 5
move 8 from 3 to 4
move 2 from 3 to 5
move 3 from 7 to 4
move 1 from 4 to 5
move 2 from 1 to 6
move 9 from 2 to 6
move 1 from 7 to 9
move 1 from 3 to 2
move 7 from 4 to 3
move 3 from 3 to 7
move 5 from 2 to 3
move 1 from 1 to 9
move 2 from 2 to 7
move 1 from 4 to 6
move 3 from 5 to 6
move 4 from 7 to 6
move 1 from 7 to 4
move 1 from 4 to 7
move 1 from 2 to 8
move 1 from 7 to 1
move 27 from 6 to 2
move 1 from 4 to 1
move 7 from 5 to 7
move 1 from 4 to 1
move 1 from 8 to 3
move 3 from 7 to 3
move 2 from 1 to 6
move 2 from 9 to 1
move 18 from 2 to 1
move 2 from 7 to 5
move 12 from 3 to 4
move 1 from 5 to 6
move 3 from 6 to 1
move 24 from 1 to 8
move 9 from 2 to 4
move 3 from 2 to 1
move 2 from 6 to 3
move 1 from 6 to 9
move 1 from 5 to 6
move 1 from 6 to 2
move 1 from 1 to 7
move 1 from 2 to 1
move 1 from 1 to 2
move 3 from 7 to 2
move 2 from 1 to 4
move 8 from 4 to 5
move 22 from 8 to 1
move 1 from 8 to 1
move 13 from 4 to 1
move 1 from 8 to 5
move 3 from 3 to 1
move 1 from 2 to 7
move 38 from 1 to 6
move 27 from 6 to 1
move 2 from 2 to 9
move 3 from 9 to 8
move 2 from 8 to 6
move 1 from 8 to 3
move 1 from 2 to 1
move 1 from 3 to 6
move 1 from 2 to 3
move 1 from 7 to 6
move 7 from 6 to 3
move 20 from 1 to 4
move 6 from 1 to 6
move 17 from 4 to 7
move 3 from 6 to 5
move 14 from 7 to 9
move 8 from 5 to 7
move 3 from 1 to 6
move 3 from 3 to 1
move 2 from 4 to 1
move 4 from 5 to 1
move 9 from 6 to 2
move 3 from 6 to 4
move 4 from 7 to 8
move 4 from 1 to 6
move 2 from 3 to 1
move 6 from 6 to 7
move 4 from 8 to 7
move 4 from 2 to 1
move 4 from 2 to 3
move 4 from 9 to 5
move 8 from 9 to 5
move 1 from 9 to 5
move 1 from 2 to 1
move 16 from 7 to 2
move 10 from 2 to 9
move 11 from 9 to 8
move 4 from 3 to 5
move 3 from 1 to 4
move 13 from 5 to 7
move 10 from 8 to 5
move 2 from 1 to 5
move 11 from 7 to 4
move 2 from 3 to 6
move 3 from 7 to 6
move 1 from 3 to 2
move 1 from 1 to 8
move 2 from 8 to 4
move 3 from 1 to 2
move 4 from 6 to 1
move 7 from 1 to 9
move 1 from 6 to 7
move 2 from 5 to 8
move 1 from 2 to 9
move 1 from 7 to 8
move 5 from 5 to 8
move 1 from 2 to 3
move 4 from 2 to 5
move 17 from 4 to 1
move 10 from 5 to 9
move 2 from 4 to 2
move 2 from 4 to 1
move 1 from 4 to 9
move 1 from 3 to 7
move 1 from 7 to 8
move 12 from 9 to 2
move 1 from 2 to 4
move 1 from 4 to 1
move 1 from 1 to 9
move 1 from 8 to 1
move 8 from 8 to 3
move 2 from 5 to 1
move 3 from 1 to 9
move 1 from 2 to 6
move 4 from 3 to 7
move 1 from 7 to 6
move 10 from 9 to 2
move 1 from 5 to 9
move 1 from 9 to 3
move 17 from 1 to 6
move 2 from 1 to 2
move 11 from 6 to 7
move 2 from 2 to 9
move 2 from 9 to 5
move 12 from 7 to 9
move 20 from 2 to 7
move 5 from 9 to 5
move 21 from 7 to 1
move 2 from 6 to 4
move 11 from 1 to 4
move 5 from 4 to 6
move 1 from 7 to 8
move 5 from 9 to 3
move 5 from 2 to 8
move 3 from 9 to 3
move 2 from 8 to 7
move 2 from 1 to 7
move 10 from 6 to 3
move 1 from 2 to 6
move 2 from 8 to 5
move 1 from 6 to 5
move 2 from 4 to 9
move 1 from 4 to 5
move 8 from 1 to 6
move 4 from 4 to 8
move 6 from 8 to 4
move 21 from 3 to 9
move 5 from 9 to 2
move 4 from 7 to 9
move 22 from 9 to 3
move 9 from 6 to 4
move 2 from 2 to 6
move 2 from 2 to 1
move 2 from 5 to 7
move 7 from 5 to 4
move 22 from 4 to 2
move 2 from 5 to 4
move 16 from 2 to 5
move 2 from 6 to 2
move 13 from 3 to 4
move 5 from 5 to 7
move 15 from 4 to 7
move 3 from 2 to 3
move 3 from 2 to 5
move 1 from 1 to 2
move 1 from 2 to 4
move 6 from 5 to 9
move 4 from 3 to 6
move 2 from 5 to 9
move 1 from 2 to 7
move 1 from 1 to 9
move 2 from 4 to 5
move 19 from 7 to 8
move 1 from 6 to 5
move 1 from 5 to 1
move 1 from 9 to 4
move 5 from 8 to 1
move 3 from 8 to 1
move 7 from 5 to 6
move 3 from 7 to 1
move 1 from 2 to 5
move 4 from 9 to 8
move 2 from 5 to 6
move 10 from 1 to 4
move 1 from 7 to 2
move 6 from 3 to 4
move 9 from 4 to 3
move 2 from 2 to 8
move 2 from 9 to 5
move 5 from 8 to 3
move 1 from 1 to 5
move 2 from 5 to 6
move 1 from 1 to 7
move 2 from 9 to 7
move 8 from 4 to 7
move 3 from 3 to 9
move 4 from 6 to 3
move 1 from 5 to 3
move 1 from 7 to 2
move 1 from 2 to 1
move 1 from 6 to 5
move 1 from 5 to 2
move 10 from 7 to 4
move 10 from 4 to 1
move 10 from 1 to 8
move 1 from 9 to 6
move 1 from 1 to 4
move 11 from 8 to 1
move 2 from 9 to 5
move 5 from 6 to 3
move 1 from 3 to 8
move 4 from 1 to 3
move 5 from 3 to 8
move 1 from 4 to 7
move 1 from 7 to 2
move 13 from 3 to 5
move 2 from 2 to 1
move 4 from 3 to 1
move 4 from 5 to 6
move 3 from 6 to 2
move 4 from 5 to 4
move 8 from 8 to 7
move 1 from 3 to 9

109
day05/src/main.rs Normal file
View File

@ -0,0 +1,109 @@
use std::fs;
use std::str::FromStr;
fn main() {
const FILE_PATH: &str = "input";
println!("Hi this is the fifth day of AOC2022, first we will read the file {}", FILE_PATH);
let contents = fs::read_to_string(FILE_PATH)
.expect("Should have been able to read the file");
println!("First we parse this mess");
let (snacks, moves) = parse(&contents);
println!("Then we do the moves as told!");
let snacks = operate9000(snacks, moves);
println!("Aaaand, the top crates are: {}", peek(&snacks));
println!("Aw, it was a CrateMover 9001, no problem we make snacks!");
let (snacks, moves) = parse(&contents);
println!("Then we do the moves as told, this time the correct way!");
let snacks = operate9001(snacks, moves);
println!("Aaaand, the top crates are: {}", peek(&snacks));
}
fn peek(snacks: &Vec<Vec<char>>) -> String{
let mut top = String::new();
for s in snacks{
let ptr = s.len()-1;
top.push(s[ptr]);
}
top
}
fn operate9000(snacks: Vec<Vec<char>>, moves: Vec<(usize, usize, usize)>) -> Vec<Vec<char>>{
let mut snacks = snacks.to_owned();
for mov in moves{
for _ in 0..mov.0{
let c = snacks[mov.1-1].pop().expect("You must be able to do the isntruction");
snacks[mov.2-1].push(c);
}
}
snacks
}
fn operate9001(snacks: Vec<Vec<char>>, moves: Vec<(usize, usize, usize)>) -> Vec<Vec<char>>{
let mut snacks = snacks.to_owned();
for mov in moves{
let mut c = Vec::new();
for _ in 0..mov.0{
c.push(snacks[mov.1-1].pop().expect("You must be able to do the isntruction"));
}
for _ in 0..c.len(){
snacks[mov.2-1].push(c.pop().expect("Always full here lemao"));
}
}
snacks
}
fn parse(s: &str) -> (Vec<Vec<char>>, Vec<(usize, usize, usize)>){
let mut s = s.split("\n\n");
let mut snacks = Vec::new();
let mut moves = Vec::new();
//Stacks
let mut stacks = s.next().expect("there must be things in the stacks").lines().rev();
let n: Vec<char> = stacks.next().expect("REASON").chars().rev().collect();
let n: usize = n[1].to_digit(10).expect("Must be a number") as usize;
for _ in 0..n{
snacks.push(Vec::new())
}
for line in stacks{
let line: Vec<char> = line.chars().collect();
for i in 0..n{
let caja = line[i*4+1];
if caja != ' '{
snacks[i].push(caja);
}
}
}
//Moves
for line in s.next().expect("There must be instructions").lines(){
let line: Vec<&str> = line.split(" ").collect();
moves.push((usize::from_str(line[1]).expect("Must be a number"), usize::from_str(line[3]).expect("Must be a number"), usize::from_str(line[5]).expect("Must be a number")));
}
(snacks, moves)
}
#[cfg(test)]
mod test {
const INPUT: &str = r#" [D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2"#;
use super::*;
#[test]
fn stacks1() {
let (snacks, moves) = parse(INPUT);
let snacks = operate9000(snacks, moves);
assert_eq!(peek(&snacks), "CMZ");
}
#[test]
fn stacks2() {
let (snacks, moves) = parse(INPUT);
let snacks = operate9001(snacks, moves);
assert_eq!(peek(&snacks), "MCD");
}
}