day 9 pt1

This commit is contained in:
RussellChamp committed 2024-12-19 18:21:55 +00:00
1 parent 8f6d81b669
commit 4d3be56120
3 files changed
+111 -18

No files matched your search

+5 -9
View File
@@ -4,7 +4,7 @@ use itertools::Itertools;
advent_of_code::solution!(9);
pub fn part_one(input: &str) -> Option<u32> {
pub fn part_one(input: &str) -> Option<u64> {
// println!("INPUT:");
// println!("{}", input);
@@ -20,7 +20,7 @@ pub fn part_one(input: &str) -> Option<u32> {
let checksum = get_checksum(compressed_blocks);
Some(checksum as u32)
Some(checksum as u64)
}
pub fn part_two(_input: &str) -> Option<u32> {
@@ -83,13 +83,9 @@ mod tests {
let input = "2333133121414131402\n";
let blocks = create_blocks(input.chars().collect_vec());
let result_str = blocks.iter().fold("".to_string(), |cur, next| {
if *next == None {
cur + "."
} else {
cur + &next.unwrap().to_string()
}
});
let result_str: String = blocks.iter().map(|b| {
if Option::is_some(b) { b.unwrap().to_string() } else { ".".to_string() }
}).collect();
assert_eq!(result_str, "00...111...2...333.44.5555.6666.777.888899");
}