mirror of
https://github.com/RussellChamp/advent-of-code-2024-rust.git
synced 2026-10-27 23:52:29 +00:00
day 9 pt1
This commit is contained in:
1 parent
8f6d81b669
commit
4d3be56120
3 files changed
+111
-18
No files matched your search
+5
-9
@@ -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");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user