diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-12-11 22:09:16 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-12-11 22:19:17 -0500 |
commit | 70f6149889511f61f91f525eba5a82e938cb41ec (patch) | |
tree | 20ed08e39ee1d0c7ec561721231f36e98a89c1b9 /src/bin/2022/day5.rs | |
parent | e2d219b331a878bbb3c9dcef9ea4e218b2e3ee06 (diff) | |
download | advent-of-code-70f6149889511f61f91f525eba5a82e938cb41ec.tar.gz advent-of-code-70f6149889511f61f91f525eba5a82e938cb41ec.zip |
support string solutions
Diffstat (limited to 'src/bin/2022/day5.rs')
-rw-r--r-- | src/bin/2022/day5.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/bin/2022/day5.rs b/src/bin/2022/day5.rs index da1e5a2..b09e2e0 100644 --- a/src/bin/2022/day5.rs +++ b/src/bin/2022/day5.rs @@ -86,7 +86,7 @@ pub fn parse(fh: File) -> Result<Crates> { }) } -fn part1_str(mut crates: Crates) -> Result<String> { +pub fn part1(mut crates: Crates) -> Result<String> { for Instruction { count, from, to } in crates.instructions { for _ in 0..count { let c = crates.piles[from - 1].pop().unwrap(); @@ -100,12 +100,7 @@ fn part1_str(mut crates: Crates) -> Result<String> { .collect()) } -pub fn part1(crates: Crates) -> Result<i64> { - println!("{}", part1_str(crates)?); - Ok(0) -} - -fn part2_str(mut crates: Crates) -> Result<String> { +pub fn part2(mut crates: Crates) -> Result<String> { for Instruction { count, from, to } in crates.instructions { let mut tmp = vec![]; for _ in 0..count { @@ -123,19 +118,14 @@ fn part2_str(mut crates: Crates) -> Result<String> { .collect()) } -pub fn part2(crates: Crates) -> Result<i64> { - println!("{}", part2_str(crates)?); - Ok(0) -} - #[test] fn test() { assert_eq!( - part1_str(parse(parse::data(2022, 5).unwrap()).unwrap()).unwrap(), + part1(parse(parse::data(2022, 5).unwrap()).unwrap()).unwrap(), "PSNRGBTFT" ); assert_eq!( - part2_str(parse(parse::data(2022, 5).unwrap()).unwrap()).unwrap(), + part2(parse(parse::data(2022, 5).unwrap()).unwrap()).unwrap(), "BNTZFPMMW" ); } |