Trying to do advent of code in Rust. I am very new to rust so please help if you see me doing something stupid!!

Compare changes

Choose any two refs to compare.

+186
day10/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day10" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + ] 107 + 108 + [[package]] 109 + name = "heck" 110 + version = "0.5.0" 111 + source = "registry+https://github.com/rust-lang/crates.io-index" 112 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 113 + 114 + [[package]] 115 + name = "is_terminal_polyfill" 116 + version = "1.70.2" 117 + source = "registry+https://github.com/rust-lang/crates.io-index" 118 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 119 + 120 + [[package]] 121 + name = "once_cell_polyfill" 122 + version = "1.70.2" 123 + source = "registry+https://github.com/rust-lang/crates.io-index" 124 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 125 + 126 + [[package]] 127 + name = "proc-macro2" 128 + version = "1.0.103" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 131 + dependencies = [ 132 + "unicode-ident", 133 + ] 134 + 135 + [[package]] 136 + name = "quote" 137 + version = "1.0.42" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 140 + dependencies = [ 141 + "proc-macro2", 142 + ] 143 + 144 + [[package]] 145 + name = "strsim" 146 + version = "0.11.1" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 149 + 150 + [[package]] 151 + name = "syn" 152 + version = "2.0.111" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 155 + dependencies = [ 156 + "proc-macro2", 157 + "quote", 158 + "unicode-ident", 159 + ] 160 + 161 + [[package]] 162 + name = "unicode-ident" 163 + version = "1.0.22" 164 + source = "registry+https://github.com/rust-lang/crates.io-index" 165 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 166 + 167 + [[package]] 168 + name = "utf8parse" 169 + version = "0.2.2" 170 + source = "registry+https://github.com/rust-lang/crates.io-index" 171 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 172 + 173 + [[package]] 174 + name = "windows-link" 175 + version = "0.2.1" 176 + source = "registry+https://github.com/rust-lang/crates.io-index" 177 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 178 + 179 + [[package]] 180 + name = "windows-sys" 181 + version = "0.61.2" 182 + source = "registry+https://github.com/rust-lang/crates.io-index" 183 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 184 + dependencies = [ 185 + "windows-link", 186 + ]
+7
day10/Cargo.toml
···
··· 1 + [package] 2 + name = "day10" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] }
+3
day10/smallinput.txt
···
··· 1 + [.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7} 2 + [...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2} 3 + [.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}
+36
day10/src/button.rs
···
··· 1 + use crate::switchboard::SwitchBoard; 2 + use std::str::FromStr; 3 + 4 + #[derive(Debug, Eq, PartialEq, Clone)] 5 + pub struct Button { 6 + pub targets: Vec<usize>, 7 + } 8 + 9 + impl Button { 10 + pub fn new(targets: Vec<usize>) -> Self { 11 + Button { targets } 12 + } 13 + 14 + pub fn press(&self, switchboard: &mut SwitchBoard) { 15 + for &target in &self.targets { 16 + switchboard.toggle(target); 17 + } 18 + } 19 + 20 + pub fn toggles(&self, index: usize) -> bool { 21 + self.targets.contains(&index) 22 + } 23 + } 24 + 25 + impl FromStr for Button { 26 + type Err = String; 27 + 28 + fn from_str(s: &str) -> Result<Self, Self::Err> { 29 + //remove parens 30 + let targets = s[1..s.len() - 1] 31 + .split(',') 32 + .map(|t| t.parse().map_err(|_| "Invalid target".to_string())) 33 + .collect::<Result<Vec<usize>, _>>()?; 34 + Ok(Button::new(targets)) 35 + } 36 + }
+116
day10/src/main.rs
···
··· 1 + use button::Button; 2 + use clap::Parser; 3 + use switchboard::SwitchBoard; 4 + 5 + mod button; 6 + mod switchboard; 7 + 8 + #[derive(Parser)] 9 + struct Args { 10 + #[clap(short, long)] 11 + file: String, 12 + #[clap(short, long)] 13 + debug: bool, 14 + } 15 + 16 + fn mash_buttons(switchboard: &mut SwitchBoard, buttons: &[Button]) -> usize { 17 + let mut total_presses = 0; 18 + while !switchboard.is_solved() { 19 + if total_presses > 100 { 20 + println!("Max presses reached"); 21 + break; 22 + } 23 + for i in 0..switchboard.size { 24 + if !switchboard.is_correct(i) { 25 + // println!("Lightbulb {} is incorrect", i); 26 + let mut valid_buttons = buttons 27 + .iter() 28 + .filter(|b| b.toggles(i)) 29 + .collect::<Vec<&Button>>(); 30 + valid_buttons.sort_by(|a, b| a.targets.len().cmp(&b.targets.len())); 31 + let distance = switchboard.dist_from_solution(); 32 + println!( 33 + "Current button options: {:?}, distance: {}", 34 + valid_buttons, distance 35 + ); 36 + for btn in valid_buttons.iter() { 37 + btn.press(switchboard); 38 + total_presses += 1; 39 + if switchboard.dist_from_solution() < distance { 40 + println!("Toggled button {:?}", btn); 41 + println!("Switchboard: {}", switchboard); 42 + break; 43 + } else { 44 + btn.press(switchboard); 45 + } 46 + } 47 + } 48 + } 49 + } 50 + 51 + total_presses 52 + } 53 + 54 + fn solve_switches(switchboard: &mut SwitchBoard, buttons: &[Button]) -> usize { 55 + let mut opstack: Vec<Button> = Vec::new(); 56 + 57 + while !switchboard.is_solved() { 58 + if opstack.len() > 10 { 59 + println!("Failed in loop, {:?}", opstack); 60 + panic!("Too many operations"); 61 + } 62 + println!("Switchboard: {}", switchboard); 63 + println!("Current state: {:?}", opstack); 64 + // find first switch that is incorrect 65 + let first_wrong = switchboard.first_wrong(); 66 + // if we find a wrong switch, get its index 67 + if let Some(index) = first_wrong { 68 + // find all buttons that toggle this index 69 + let mut valid_buttons = buttons 70 + .iter() 71 + .filter(|b| b.toggles(index)) 72 + .collect::<Vec<&Button>>(); 73 + // don't press the same button twice in a row 74 + valid_buttons.retain(|b| !opstack.contains(b)); 75 + if !valid_buttons.is_empty() { 76 + opstack.push(valid_buttons[0].clone()); 77 + valid_buttons[0].press(switchboard); 78 + } else { 79 + let first_button = opstack[1].clone(); 80 + opstack.clear(); 81 + switchboard.reset(); 82 + println!( 83 + "Reset switchboard, first operation will be {:?}", 84 + first_button 85 + ); 86 + 87 + first_button.press(switchboard); 88 + opstack.push(first_button.clone()); 89 + } 90 + } 91 + } 92 + opstack.len() 93 + } 94 + 95 + fn main() { 96 + let args = Args::parse(); 97 + let file = std::fs::read_to_string(&args.file).expect("Failed to read file"); 98 + let lines = file.lines(); 99 + 100 + for line in lines { 101 + let tokens = line.split_whitespace().collect::<Vec<&str>>(); 102 + let mut switchboard = SwitchBoard::new(tokens[0]); 103 + let mut buttons = Vec::new(); 104 + 105 + for button_str in tokens[1..tokens.len() - 1].iter() { 106 + let button: Button = button_str 107 + .parse() 108 + .expect("Button expected to be in format (a,b,..,z)."); 109 + buttons.push(button); 110 + } 111 + 112 + solve_switches(&mut switchboard, &buttons); 113 + } 114 + 115 + println!("{}", file); 116 + }
+75
day10/src/switchboard.rs
···
··· 1 + use std::fmt::{Display, Formatter}; 2 + 3 + pub struct SwitchBoard { 4 + lights: Vec<bool>, 5 + target: Vec<bool>, 6 + pub size: usize, 7 + } 8 + 9 + impl SwitchBoard { 10 + pub fn new_empty(size: usize) -> Self { 11 + SwitchBoard { 12 + lights: vec![false; size], 13 + target: vec![false; size], 14 + size, 15 + } 16 + } 17 + 18 + pub fn new(schema: &str) -> Self { 19 + if schema.starts_with('[') && schema.ends_with(']') { 20 + let size = schema.len() - 2; 21 + let lights = vec![false; size]; 22 + let target: Vec<bool> = schema[0..size].chars().map(|c| c == '#').collect(); 23 + assert_eq!(lights.len(), target.len()); 24 + SwitchBoard { 25 + lights, 26 + target, 27 + size, 28 + } 29 + } else { 30 + panic!("Invalid schema for switchboard"); 31 + } 32 + } 33 + 34 + pub fn reset(&mut self) { 35 + self.lights = vec![false; self.size]; 36 + } 37 + 38 + pub fn is_correct(&self, index: usize) -> bool { 39 + self.lights[index] == self.target[index] 40 + } 41 + 42 + pub fn is_solved(&self) -> bool { 43 + self.lights == self.target 44 + } 45 + 46 + pub fn toggle(&mut self, i: usize) { 47 + self.lights[i] = !self.lights[i]; 48 + } 49 + 50 + pub fn dist_from_solution(&self) -> usize { 51 + self.lights 52 + .iter() 53 + .zip(self.target.iter()) 54 + .filter(|&(a, b)| a != b) 55 + .count() 56 + } 57 + 58 + pub fn first_wrong(&self) -> Option<usize> { 59 + self.lights 60 + .iter() 61 + .zip(self.target.iter()) 62 + .enumerate() 63 + .position(|(_, (a, b))| a != b) 64 + } 65 + } 66 + 67 + impl Display for SwitchBoard { 68 + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 69 + for light in self.lights.iter() { 70 + write!(f, "{}", if *light { '#' } else { '.' })?; 71 + } 72 + writeln!(f)?; 73 + Ok(()) 74 + } 75 + }
+186
day11/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day11" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + ] 107 + 108 + [[package]] 109 + name = "heck" 110 + version = "0.5.0" 111 + source = "registry+https://github.com/rust-lang/crates.io-index" 112 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 113 + 114 + [[package]] 115 + name = "is_terminal_polyfill" 116 + version = "1.70.2" 117 + source = "registry+https://github.com/rust-lang/crates.io-index" 118 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 119 + 120 + [[package]] 121 + name = "once_cell_polyfill" 122 + version = "1.70.2" 123 + source = "registry+https://github.com/rust-lang/crates.io-index" 124 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 125 + 126 + [[package]] 127 + name = "proc-macro2" 128 + version = "1.0.103" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 131 + dependencies = [ 132 + "unicode-ident", 133 + ] 134 + 135 + [[package]] 136 + name = "quote" 137 + version = "1.0.42" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 140 + dependencies = [ 141 + "proc-macro2", 142 + ] 143 + 144 + [[package]] 145 + name = "strsim" 146 + version = "0.11.1" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 149 + 150 + [[package]] 151 + name = "syn" 152 + version = "2.0.111" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 155 + dependencies = [ 156 + "proc-macro2", 157 + "quote", 158 + "unicode-ident", 159 + ] 160 + 161 + [[package]] 162 + name = "unicode-ident" 163 + version = "1.0.22" 164 + source = "registry+https://github.com/rust-lang/crates.io-index" 165 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 166 + 167 + [[package]] 168 + name = "utf8parse" 169 + version = "0.2.2" 170 + source = "registry+https://github.com/rust-lang/crates.io-index" 171 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 172 + 173 + [[package]] 174 + name = "windows-link" 175 + version = "0.2.1" 176 + source = "registry+https://github.com/rust-lang/crates.io-index" 177 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 178 + 179 + [[package]] 180 + name = "windows-sys" 181 + version = "0.61.2" 182 + source = "registry+https://github.com/rust-lang/crates.io-index" 183 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 184 + dependencies = [ 185 + "windows-link", 186 + ]
+7
day11/Cargo.toml
···
··· 1 + [package] 2 + name = "day11" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] }
+553
day11/input.txt
···
··· 1 + you: wms hkw ove qba ats 2 + imt: swz aev ams bhg yir 3 + grh: fph cuq pcx 4 + yae: qiu mef 5 + luf: zir jdx jmg 6 + ypt: ahf wov hai 7 + rlf: haj yxm 8 + xls: qnw ppg 9 + ggr: xmh vka 10 + xgr: hlc mzm 11 + mze: ljj ppg ysn qnw 12 + xfb: diw cxx vlb mgf 13 + wms: xcd hni 14 + lpm: dap 15 + wov: rbx skx ztu 16 + oop: djs rfy 17 + cnb: haj 18 + xaz: tur kmd wsw 19 + svr: qnf jjf xjh omn 20 + vya: mgq qqj asn 21 + zuk: xvf lff cju 22 + gvw: xfk jje gir 23 + ztu: hlr lka 24 + jmg: dap tei 25 + hxf: mjd vns mlo 26 + dsq: vkw vtp cwm 27 + jpr: izt esf 28 + qba: cju xvf lff fcg 29 + zyt: yek imd qsl 30 + wke: out 31 + hbz: nnz qck 32 + xru: wuh 33 + wsw: mgq 34 + ifh: ejn pif 35 + xpt: ouy 36 + elr: izi wke ljd oim 37 + bbg: xnn ove hbz gkv fdo frn vfi uxl rrt wms dcs vkn 38 + bye: jna xgr vcd 39 + ceb: cwa 40 + msa: hly gir 41 + gzq: byz 42 + ufd: ihs ped 43 + jev: wbn 44 + gix: wdt 45 + see: nfq 46 + rnu: nei wdt azn 47 + axr: oop pgu 48 + efu: aai ejn 49 + cnf: oaw ryk wpb 50 + vzq: lka hlr zkr aps 51 + ehj: out 52 + xup: esf 53 + tak: wld xob 54 + omn: xfb fry tvg fll pwt oka vwe rpp bja miw boq elm 55 + kmj: bsl xzx tco 56 + hpe: une tvs 57 + xzx: bbg gia fwk you 58 + qiu: bdv nkt uco 59 + sar: boc tfa qvo vzq 60 + wur: pdz wld xob 61 + zvs: bbg 62 + bez: kow tvs hju une 63 + esf: out 64 + taz: nft 65 + fgw: mzm hlc 66 + wqf: mka gko 67 + zab: wuh xzx 68 + ars: mjn jmd 69 + pmn: uug vzx 70 + lay: you bbg fwk 71 + imd: see 72 + rak: out 73 + ixj: kow tvs une 74 + pka: txb 75 + wrm: sjq kme 76 + bik: aps 77 + slz: tvs kow une 78 + wxx: nfe 79 + hju: ypt xls swg wci wth 80 + dcs: qvu 81 + yuo: xhd ryk 82 + ucg: lpm zaw zir 83 + vtp: out 84 + znh: vya phe wsw kmd 85 + slu: ulf msa gvw amb nkv 86 + qeh: yor 87 + ing: cji hlb 88 + ogh: gfk haj yxm 89 + mlo: ptn mmq alf nft 90 + nhx: skx 91 + wrf: jkp fhl 92 + ihw: cwa rlf xbu 93 + yut: hjx xmm 94 + drp: vkw vqp vtp 95 + ywc: com wxx ize 96 + bsl: fwk gia zvu bbg 97 + uhu: foi wrm qnt 98 + mcp: vqp cwm 99 + lce: nak uzi 100 + vax: auy fgw cwr 101 + fdo: qck lvi nnz 102 + lmn: han obk fuu 103 + ebx: nko kdd boe vht 104 + cdt: qiu 105 + oka: uug lkh 106 + zny: sef dxs fac elg 107 + bxj: gcd huk 108 + azn: tth aps 109 + aps: ufd ogt bxj jaf zpc ptb jev 110 + pvr: mjd vns 111 + kxq: vns 112 + fry: uug 113 + tth: hxe jev zpc bio yba enr mbw ujb bxj ogt ryr dkw slu 114 + ize: nfe hlc 115 + vfi: lvi qck 116 + qtx: xup ouy 117 + qck: piz ohg 118 + lft: ogh kgv 119 + iur: dlh lcc 120 + dqs: aps zkr hlr 121 + xci: ahf bhk hai 122 + ayn: tth hlr lka 123 + frn: lff 124 + fhh: lka tth zkr aps 125 + jkp: fnj vbv 126 + fka: fnj vbv 127 + lcc: hju tvs 128 + yrq: wrm 129 + zaw: dap 130 + ggb: pew lgw 131 + vkw: out 132 + nmm: ona ums vha xos 133 + kak: out 134 + ejn: ixj kyx 135 + yba: ftb 136 + hlb: vht 137 + lka: ryr zrk ufd slu lfc ptb bio zpc cqz hxe mbw jaf dkw cxk jzg smv jev ogt bxj ujb enr yba 138 + gfk: fmh znh aso qdl jdy qeh kot 139 + arh: fft eae 140 + gtw: tth lka 141 + imk: pdz wld xob 142 + mox: irm 143 + fuu: ftn 144 + nfe: cwe ndx etc qhv agt vzk dcm cmu oiu fwb ahr zgd mgz wyd byh ajh lkw fob rho sve sfj lce riq znt yut ogu 145 + bdv: you fwk zvu bbg 146 + asn: hju une 147 + yas: pif ejn 148 + cyr: fwa qpu mpw 149 + wdt: lka 150 + mef: bdv 151 + ihs: gua 152 + box: out 153 + sqj: ehj 154 + olv: dlh lcc rpb 155 + hsh: rnu gix nfq dus 156 + ifc: xup jpr 157 + nko: you zvu fwk gia 158 + oim: out 159 + fwk: ove dcs hbz gkv cnt frn vzo brh rrt 160 + djs: uco bdv nkt 161 + pew: dsq sjy epu 162 + vka: tvs kow hju 163 + mbw: amb ulf msa gvw 164 + mgz: zab xru pui kmj 165 + lvp: zny mgf 166 + bxp: hlc mzm 167 + lgw: epu mcp sjy drp 168 + mbu: out 169 + jdx: dap tei 170 + boq: lft 171 + ltz: sjy mcp dsq 172 + com: nfe 173 + fll: pqr luf gko 174 + obk: frk ftn 175 + vht: zvu gia fwk 176 + zyh: lgw mfj pew ltz 177 + hni: xym ggb bkg 178 + vsy: cdt dac yae 179 + kfc: gou fpc 180 + mka: zaw lpm jmg 181 + uoh: fwa qpu 182 + byu: rak mck 183 + pwf: rcr 184 + rxh: qtx 185 + zxf: tco wuh 186 + lvi: ohg kft dqx 187 + mfj: drp 188 + one: lka 189 + qsj: pif 190 + gko: jmg lpm jdx zaw zir 191 + boe: zvu bbg gia fwk 192 + pum: aps lka tth 193 + tvs: wci wji zyt dhn hwr vwl wrf ojn rab 194 + irl: gip 195 + bqb: kjs qmn lft 196 + qsl: see hsh 197 + kyx: hju 198 + the: yrq zco xcb uhu kbq 199 + fob: gzq uzi osb 200 + nfq: nei wdt azn 201 + ams: afp 202 + cwr: mzm 203 + gia: xnn brh hkw hbz irl dcs zuk cnt gkv gbv 204 + fmh: rxs xpf 205 + ndx: hou uoh qdj vwt 206 + fpc: hlc nfe 207 + ysn: wjd zuj pum 208 + cwa: yxm haj gfk 209 + lfq: kak ujn ehj box 210 + wth: imd 211 + hjx: hlb ebx cji aak 212 + vkn: hxf wax kxq 213 + afp: dkm lyf 214 + zgd: hjx 215 + fph: bao ewp 216 + riq: uoh hou qdj cyr vwt 217 + ajh: akx axr 218 + qvo: aps lka hlr tth zkr 219 + vzk: zab xru pui kmj 220 + wld: haj 221 + xym: pew mfj vnu 222 + akx: yae pgu oop cdt dac 223 + mmq: jzt byu 224 + nft: sdj byu 225 + ppl: bxp gou fpc 226 + dkm: yxm haj gfk 227 + wgp: aps hlr zkr 228 + vlb: sef 229 + gou: hlc nfe mzm 230 + vwe: ams aev 231 + qpu: you bbg zvu fwk gia 232 + rho: vwt hou 233 + han: ftn frk elr 234 + swp: dlh rpb 235 + wji: sar xos vha ums 236 + sef: wur 237 + jje: szq kfc 238 + xly: hlc nfe 239 + lkw: uoh hou cyr 240 + tvg: vzx uug 241 + tat: ljj ppg ysn 242 + fft: olv dyq 243 + tym: yxm haj 244 + cqz: gcd nmz 245 + xbu: haj yxm gfk 246 + enr: amb 247 + sjd: iwf 248 + piz: cuq pcx fph fgc 249 + kgv: haj yxm 250 + cwm: out 251 + ogu: zxf zab pui 252 + cxx: elg osd 253 + qfb: une 254 + ptb: ftb wbn 255 + pui: bsl 256 + zkr: dkw zrk jzg ryr cxk ufd lfc slu smv cqz bio ptb hxe jev ujb ogt jaf enr yba mbw 257 + pif: vjs ixj 258 + oaw: cir 259 + qjd: uhu xcb zco yrq 260 + pcx: otd sqj bao ewp 261 + pwt: lkh vzx 262 + szq: fpc bxp 263 + lfc: jvd 264 + haj: pwf yuo xdb znh aso asf aod kot srf fmh xaz qdl fzl 265 + etc: ing 266 + jdz: fwk gia zvu bbg 267 + sjq: aps lka hlr tth zkr 268 + cuq: ewp bao sqj 269 + qun: cwr fgw fbj 270 + pny: kjs lft qmn 271 + fwa: gia bbg zvu you 272 + mgf: fac 273 + uxl: hni 274 + vzo: cju xvf fcg lff 275 + alf: byu sdj 276 + xvf: pqj mgb isf pqf rxh 277 + dyq: rpb lcc 278 + yek: hca hsh 279 + wcn: rxs 280 + xcd: bkg ggb 281 + jcv: yxm haj gfk 282 + gqb: out 283 + rab: hpj jkp 284 + srf: efu qsj 285 + kme: hlr aps 286 + ahr: awd mcy 287 + ljd: out 288 + kmd: mgq 289 + swz: enh tla 290 + qnt: sjq gtw 291 + pqj: zzp 292 + bio: nmz gcd 293 + pbv: hlr tth zkr 294 + gip: taz 295 + dus: wdt nei 296 + vzx: ooc ceb ihw jix 297 + tii: ovj jna xly 298 + sve: uoh 299 + fcg: isf mgb pqj pqf 300 + irm: piz ohg kft grh 301 + osd: xlv imk 302 + ftn: ljd mbu izi 303 + xpf: lne bez hpe wau 304 + dlh: kow tvs une hju 305 + boc: zkr hlr 306 + lke: out 307 + fbf: bbg zvu fwk you 308 + zuj: hlr lka zkr tth 309 + kwq: gia bbg 310 + dac: mef djs 311 + vcd: nfe 312 + cju: pqf rxh 313 + ayb: xbu rlf 314 + jna: mzm hlc 315 + hfg: mzm 316 + ajl: fka hpj fhl 317 + dxs: imk tak 318 + vwv: kdb xpf 319 + iwf: ytn pgr jdz 320 + mcy: ytn 321 + qhv: osb gzq 322 + ove: hni gdl 323 + gdl: xym zyh 324 + fhl: vbv ebd 325 + oiu: xmm ing 326 + fbj: hlc 327 + lff: isf pqj 328 + rxs: hpe wau bez 329 + hxe: vax 330 + bkg: pew mfj 331 + jaf: nmz huk 332 + xhd: ggr cir how 333 + yor: eae 334 + zpc: qun nik 335 + ovj: mzm 336 + ixl: sjq kme gtw 337 + hlr: bxj bio dkw cxk ryr jzg zrk 338 + gbv: hni gdl 339 + kdd: you zvu fwk 340 + osb: lay zvs kwq fbf 341 + tfa: tth zkr lka 342 + qvu: lmn mjn 343 + jdy: ifh qsj efu yas 344 + nkv: jje 345 + ojn: ahf wov hai nhx bhk 346 + rfy: nkt 347 + xmm: ebx aak 348 + jzt: mck rak 349 + mio: lcc 350 + frk: izi oim 351 + kqf: hlc 352 + kft: fgc 353 + pqr: zir jdx 354 + kcx: zny 355 + ytn: fwk gia zvu bbg 356 + wau: une hju tvs 357 + ljj: wjd pum zuj 358 + jzg: huk gcd 359 + ryr: nik 360 + xcb: qnt 361 + uco: fwk bbg you 362 + pqf: xpt ifc 363 + mgb: zzp ifc 364 + diw: fac dxs elg osd 365 + aak: vht nko kdd boe 366 + vha: fhh vzq qvo boc 367 + pgu: rfy 368 + phe: mgq asn 369 + zir: dap bic 370 + vbv: pbv bik 371 + fwb: vsy 372 + ipq: swp olv dyq iur 373 + xlv: pdz gvy wld xob 374 + aai: ixj vjs 375 + qnf: kcx fjw tvg wqf pcm fry 376 + sym: aai ejn 377 + ppg: wjd zuj pum 378 + nak: fbf kwq zvs 379 + vqp: out 380 + hca: gix rnu 381 + tla: cnb dkm tym jcv 382 + xmh: tvs 383 + brj: iwf 384 + ohg: pcx fgc fph 385 + mck: out 386 + bne: zxf 387 + uug: ceb ooc 388 + wuh: gia fwk zvu you 389 + how: qfb slz vka 390 + glc: xcb yrq zco 391 + isf: ifc zzp 392 + elg: imk xlv wur 393 + mgq: hju kow 394 + upa: sdj jzt 395 + agt: xmm 396 + kot: phe wsw kmd tur 397 + ftb: ywc jox 398 + uzi: byz lay kwq fbf 399 + brh: wax pvr kxq 400 + aev: afp tla 401 + ats: nso jdo 402 + eae: mio olv iur swp 403 + foi: kme 404 + qdl: arh zal rcr yor 405 + ngp: yxm haj 406 + yir: enh 407 + cfh: out 408 + asf: yor arh zal 409 + vwl: ona ums xos sar 410 + lyf: yxm gfk 411 + hlc: sve lce sfj oiu brj zgd wyd byh ajh sjd etc vzk qhv cmu bne 412 + etm: out 413 + zrk: ihs jvd 414 + fse: nfe mzm 415 + rus: yek 416 + nei: zkr tth hlr lka 417 + izt: out 418 + ptn: jzt 419 + ebd: bik one 420 + rcr: ipq fft 421 + txb: ozj 422 + lkh: ceb ihw jix ayb 423 + zal: fft 424 + wpb: how 425 + ooc: rlf 426 + wjd: tth hlr lka 427 + ona: boc tfa fhh vzq 428 + qqj: tvs hju 429 + zco: qnt 430 + izi: out 431 + hpj: ebd fnj vbv 432 + rpb: tvs une 433 + miw: swz bhg ams 434 + qte: luf gko 435 + wpu: vcd xgr jna xly 436 + awd: pgr jdz 437 + byh: akx axr vsy 438 + fac: imk 439 + rbx: aps tth zkr lka hlr 440 + dwc: wpb oaw ryk 441 + wbn: txb jox 442 + hly: szq ppl 443 + sdj: mck lke 444 + une: qjd dhn rus wrf ojn ajl the ezl 445 + ujn: out 446 + ouy: gqb esf izt 447 + swg: yek 448 + amb: hly gir xfk 449 + dap: haj yxm 450 + nnz: ohg piz dqx kft grh 451 + xfk: ppl kfc 452 + nik: cwr hfg fgw auy 453 + nmz: bye 454 + bic: haj gfk 455 + enh: jcv tym dkm cnb lyf 456 + pcm: vlb cxx zny 457 + qnw: wgp pum zuj 458 + dhn: nhx 459 + dqx: pcx fgc fph 460 + skx: aps lka zkr tth 461 + mpw: gia fwk bbg 462 + wyd: zxf kmj pui xru 463 + nso: mjn 464 + mjd: nft alf upa mmq 465 + cmu: awd mcy 466 + jdo: mjn lmn jmd 467 + cxk: ihs ped jvd 468 + gua: nfe hlc 469 + ewp: etm ehj 470 + fzl: kmd tur wsw 471 + gkv: jdo qvu wzm 472 + cnt: lvi irm 473 + bja: diw cxx zny 474 + kbq: ixl 475 + ums: qvo boc tfa fhh vzq 476 + mjn: han pue 477 + qdj: fwa 478 + ulf: gir hly 479 + gcd: tii 480 + sjy: cwm cfh vqp vkw 481 + kow: ojn nmm wrf vwl qjd mze xci swg xls wth glc tat ypt rab hwr dhn rus zyt the wji ajl 482 + xjh: fjw fll pcm xfb pwt miw bja vwe rpp pmn kcx pny qte bqb 483 + ogt: vax qun nik 484 + znt: vsy akx 485 + jox: wxx ozj ize com 486 + bhg: afp tla 487 + xnn: wzm jdo ars 488 + wzm: lmn 489 + pgr: you zvu bbg 490 + kwb: ngp ogh 491 + elm: gko ucg luf pqr 492 + tei: yxm gfk 493 + gvy: gfk 494 + ryk: cir how 495 + dkw: nik 496 + epu: cwm vtp vqp vkw 497 + vwt: qpu 498 + hwr: qnw ysn 499 + jjf: pny oka kcx bqb lvp vwe rpp fjw xfb fry pcm imt 500 + cir: slz xva qfb 501 + yxm: srf kot cnf aod dwc asf aso qfo wcn znh xdb pwf yuo qeh jdy vwv qdl xaz fmh 502 + jvd: kqf fse 503 + byz: zvu bbg you 504 + rrt: cju xvf lff 505 + vjs: tvs kow une 506 + wax: taz 507 + xdb: yas sym efu qsj 508 + ozj: mzm 509 + bao: ehj box ujn 510 + pue: ftn 511 + fgc: lfq bao otd 512 + hkw: hni gdl 513 + xob: yxm haj 514 + smv: jvd ped 515 + vnu: sjy 516 + gir: kfc 517 + hou: mpw fwa 518 + lne: kow 519 + sfj: osb nak uzi 520 + qmn: ngp kgv 521 + otd: ujn kak box 522 + qfo: ifh yas 523 + ujb: ftb pka wbn 524 + ped: gua kqf fse 525 + dcm: gzq nak osb 526 + hai: ztu 527 + vns: upa alf 528 + kjs: ngp kgv 529 + aso: xpf rxs 530 + rpp: luf pqr gko ucg 531 + fjw: qmn kwb 532 + ezl: fka jkp fhl 533 + huk: wpu tii bye 534 + mzm: sve rho fob lkw yut riq brj fwb ajh byh zgd mgz etc sjd ndx dcm cmu vzk qhv bne cwe 535 + zzp: jpr 536 + ahf: skx rbx dqs 537 + auy: mzm nfe hlc 538 + xva: kow tvs 539 + wci: hpj 540 + bhk: skx ztu rbx 541 + tur: qqj 542 + zvu: wms vzo vfi brh mox fdo ove zuk irl vkn hbz 543 + nkt: you zvu bbg gia 544 + pdz: gfk haj 545 + fnj: ayn bik pbv 546 + tco: bbg fwk gia you 547 + jix: cwa 548 + cwe: mcy 549 + jmd: fuu obk pue 550 + cji: boe 551 + aod: vya kmd 552 + kdb: wau lne bez 553 + xos: vzq
+10
day11/smallinput.txt
···
··· 1 + aaa: you hhh 2 + you: bbb ccc 3 + bbb: ddd eee 4 + ccc: ddd eee fff 5 + ddd: ggg 6 + eee: out 7 + fff: out 8 + ggg: out 9 + hhh: ccc fff iii 10 + iii: out
+63
day11/src/main.rs
···
··· 1 + mod server; 2 + use clap::Parser; 3 + use server::Server; 4 + 5 + #[derive(Parser)] 6 + struct Args { 7 + #[clap(short, long)] 8 + file: String, 9 + #[clap(short, long)] 10 + debug: bool, 11 + } 12 + 13 + fn main() { 14 + let args = Args::parse(); 15 + if args.debug { 16 + println!("=== Debug mode enabled ==="); 17 + } 18 + 19 + let mut nodes: Vec<Server> = Vec::new(); 20 + let file_contents = std::fs::read_to_string(&args.file).expect("Failed to read file"); 21 + 22 + nodes.push(Server::new("out", 0)); 23 + 24 + for line in file_contents.lines() { 25 + let tokens = line.split_whitespace().collect::<Vec<_>>(); 26 + let source = tokens[0]; 27 + let server = Server::new(&source[..source.len() - 1], nodes.len()); 28 + nodes.push(server); 29 + } 30 + 31 + println!("Nodes: {:?}", nodes); 32 + 33 + for line in file_contents.lines() { 34 + let tokens = line.split_whitespace().collect::<Vec<_>>(); 35 + let source = &tokens[0][..tokens[0].len() - 1]; 36 + let destinations = &tokens[1..]; 37 + println!("Source: {}, Destinations: {:?}", source, destinations); 38 + let server_index = nodes.iter().position(|s| s.label == source).unwrap(); 39 + for next_label in destinations { 40 + let index = nodes.iter().position(|s| s.label == **next_label).unwrap(); 41 + nodes[server_index].add_next(index); 42 + } 43 + } 44 + 45 + let you = nodes.iter().position(|s| s.label == "you").unwrap(); 46 + 47 + let mut paths = 0; 48 + let mut path: Vec<usize> = Vec::new(); 49 + 50 + path.push(you); 51 + 52 + while let Some(next) = path.pop() { 53 + if next == 0 { 54 + paths += 1; 55 + continue; 56 + } 57 + for &neighbor in &nodes[next].next { 58 + path.push(neighbor); 59 + } 60 + } 61 + 62 + println!("Visited {} paths", paths); 63 + }
+22
day11/src/server.rs
···
··· 1 + use std::fmt::Debug; 2 + 3 + #[derive(Debug, Eq, PartialEq, Hash)] 4 + pub struct Server { 5 + pub label: String, 6 + pub index: usize, 7 + pub next: Vec<usize>, // Store indices instead of references 8 + } 9 + 10 + impl Server { 11 + pub fn new(label: &str, index: usize) -> Self { 12 + Server { 13 + label: label.to_string(), 14 + index, 15 + next: Vec::new(), 16 + } 17 + } 18 + 19 + pub fn add_next(&mut self, next_index: usize) { 20 + self.next.push(next_index); 21 + } 22 + }
+186
day2/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day2" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + ] 107 + 108 + [[package]] 109 + name = "heck" 110 + version = "0.5.0" 111 + source = "registry+https://github.com/rust-lang/crates.io-index" 112 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 113 + 114 + [[package]] 115 + name = "is_terminal_polyfill" 116 + version = "1.70.2" 117 + source = "registry+https://github.com/rust-lang/crates.io-index" 118 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 119 + 120 + [[package]] 121 + name = "once_cell_polyfill" 122 + version = "1.70.2" 123 + source = "registry+https://github.com/rust-lang/crates.io-index" 124 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 125 + 126 + [[package]] 127 + name = "proc-macro2" 128 + version = "1.0.103" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 131 + dependencies = [ 132 + "unicode-ident", 133 + ] 134 + 135 + [[package]] 136 + name = "quote" 137 + version = "1.0.42" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 140 + dependencies = [ 141 + "proc-macro2", 142 + ] 143 + 144 + [[package]] 145 + name = "strsim" 146 + version = "0.11.1" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 149 + 150 + [[package]] 151 + name = "syn" 152 + version = "2.0.111" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 155 + dependencies = [ 156 + "proc-macro2", 157 + "quote", 158 + "unicode-ident", 159 + ] 160 + 161 + [[package]] 162 + name = "unicode-ident" 163 + version = "1.0.22" 164 + source = "registry+https://github.com/rust-lang/crates.io-index" 165 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 166 + 167 + [[package]] 168 + name = "utf8parse" 169 + version = "0.2.2" 170 + source = "registry+https://github.com/rust-lang/crates.io-index" 171 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 172 + 173 + [[package]] 174 + name = "windows-link" 175 + version = "0.2.1" 176 + source = "registry+https://github.com/rust-lang/crates.io-index" 177 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 178 + 179 + [[package]] 180 + name = "windows-sys" 181 + version = "0.61.2" 182 + source = "registry+https://github.com/rust-lang/crates.io-index" 183 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 184 + dependencies = [ 185 + "windows-link", 186 + ]
+7
day2/Cargo.toml
···
··· 1 + [package] 2 + name = "day2" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] }
+1
day2/input.txt
···
··· 1 + 8123221734-8123333968,2665-4538,189952-274622,4975-9031,24163352-24202932,1233-1772,9898889349-9899037441,2-15,2147801-2281579,296141-327417,8989846734-8989940664,31172-42921,593312-632035,862987-983007,613600462-613621897,81807088-81833878,13258610-13489867,643517-782886,986483-1022745,113493-167913,10677-16867,372-518,3489007333-3489264175,1858-2534,18547-26982,16-29,247-366,55547-103861,57-74,30-56,1670594-1765773,76-129,134085905-134182567,441436-566415,7539123416-7539252430,668-1146,581563513-581619699
+3
day2/shortinput.txt
···
··· 1 + 11-22,95-115,998-1012,1188511880-1188511890,222220-222224, 2 + 1698522-1698528,446443-446449,38593856-38593862,565653-565659, 3 + 824824821-824824827,2121212118-2121212124
+114
day2/src/main.rs
···
··· 1 + use clap::Parser; 2 + use std::fs; 3 + 4 + #[derive(Parser, Debug)] 5 + #[command(author, version, about, long_about = None)] 6 + struct Args { 7 + #[arg(short, long)] 8 + file: String, 9 + } 10 + 11 + fn main() { 12 + let args = Args::parse(); 13 + 14 + let sum = sum_ids(&args.file); 15 + println!("Sum of all invalid ids is {}", sum); 16 + } 17 + 18 + fn is_invalid_id(id: u64) -> bool { 19 + let log_10 = (id as f64).log10().ceil() as u32; 20 + let magic_number = 10u64.pow(log_10 / 2); 21 + /* println!( 22 + "Checking ID: {}, divisor is {}, magic_number is {}", 23 + id, log_10, magic_number 24 + ); */ 25 + id / magic_number == id % magic_number 26 + } 27 + 28 + // Go through each log10 from 1..log10(n) 29 + // check last n digits of divisor == modulo 30 + // eg 121212 31 + // n = 121212, i = 1, mod = 2, ldigits = 1 32 + // n = 121212, i = 2, mod = 12, ldigits = 12 33 + // -> n = 1212, i = 2, mod = 12, ldigits = 12 !!! 34 + // 35 + // 101 -> 1) 10,1 ; 0 != 1 36 + // 101 -> 2) 1,1 1 < 10 !! 37 + 38 + fn is_invalid_id_hard(id: u64) -> bool { 39 + // println!("=== Checking ID: {} ===", id); 40 + let mut c_id = id; 41 + let mut cur_part; 42 + // i is the log value, ie the window size we are checking 43 + for i in 1..(id as f64).log10() as u32 + 1 { 44 + // trim off end of number 45 + // we saved the current part above 46 + let pow_10 = (10u32.pow(i) as u64); 47 + cur_part = c_id % pow_10; 48 + 49 + // println!("n = {}, i = {}, pow_10 = {}", id, i, pow_10); 50 + // repeat until the value drops below the target log 51 + while c_id > 10 { 52 + // remove last n digits from c_id 53 + c_id = c_id / pow_10; 54 + // last i digits of c_id 55 + let last_digits = c_id % pow_10; 56 + if last_digits == cur_part { 57 + // println!( 58 + // "For exponent {}, digits {} and {} matched in {}, id slice {}", 59 + // i, last_digits, cur_part, id, c_id 60 + // ); 61 + if last_digits >= (10u32.pow(i - 1) as u64) && c_id == last_digits { 62 + return true; 63 + } 64 + // set cur_part to last i+1 digits 65 + // cur_part = c_id / pow_10 % (10u32.pow(i + 1) as u64); 66 + } else { 67 + // println!( 68 + // "For exponent {}, digits {} and {} DO NOT MATCH in {}, id slice {}", 69 + // i, last_digits, cur_part, id, c_id 70 + // ); 71 + break; 72 + } 73 + } 74 + c_id = id; 75 + } 76 + return false; 77 + } 78 + 79 + // Finding repeated bits 80 + // 81 + // for i in 1..log10(n) 82 + // 83 + 84 + fn check_range(start: u64, end: u64) -> u64 { 85 + println!("Checking range from {} to {}", start, end); 86 + let mut invalid_sum: u64 = 0; 87 + for n in start..end + 1 { 88 + if is_invalid_id_hard(n) { 89 + println!("Invalid ID: {}", n); 90 + invalid_sum += n; 91 + } 92 + } 93 + invalid_sum 94 + } 95 + 96 + fn sum_ids(filename: &str) -> u64 { 97 + let file_contents = fs::read_to_string(filename).expect("Failed to read file"); 98 + let mut invalid_sum: u64 = 0; 99 + for range in file_contents.split(',') { 100 + let split_range: Vec<&str> = range.trim().split('-').collect(); 101 + let start = split_range 102 + .get(0) 103 + .unwrap_or(&&"") 104 + .parse::<u64>() 105 + .expect("Could not unwrap start value of range"); 106 + let end = split_range 107 + .get(1) 108 + .unwrap_or(&&"") 109 + .parse::<u64>() 110 + .expect("Could not unwrap end value of range"); 111 + invalid_sum += check_range(start, end); 112 + } 113 + return invalid_sum; 114 + }
+186
day3/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day3" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + ] 107 + 108 + [[package]] 109 + name = "heck" 110 + version = "0.5.0" 111 + source = "registry+https://github.com/rust-lang/crates.io-index" 112 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 113 + 114 + [[package]] 115 + name = "is_terminal_polyfill" 116 + version = "1.70.2" 117 + source = "registry+https://github.com/rust-lang/crates.io-index" 118 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 119 + 120 + [[package]] 121 + name = "once_cell_polyfill" 122 + version = "1.70.2" 123 + source = "registry+https://github.com/rust-lang/crates.io-index" 124 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 125 + 126 + [[package]] 127 + name = "proc-macro2" 128 + version = "1.0.103" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 131 + dependencies = [ 132 + "unicode-ident", 133 + ] 134 + 135 + [[package]] 136 + name = "quote" 137 + version = "1.0.42" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 140 + dependencies = [ 141 + "proc-macro2", 142 + ] 143 + 144 + [[package]] 145 + name = "strsim" 146 + version = "0.11.1" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 149 + 150 + [[package]] 151 + name = "syn" 152 + version = "2.0.111" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 155 + dependencies = [ 156 + "proc-macro2", 157 + "quote", 158 + "unicode-ident", 159 + ] 160 + 161 + [[package]] 162 + name = "unicode-ident" 163 + version = "1.0.22" 164 + source = "registry+https://github.com/rust-lang/crates.io-index" 165 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 166 + 167 + [[package]] 168 + name = "utf8parse" 169 + version = "0.2.2" 170 + source = "registry+https://github.com/rust-lang/crates.io-index" 171 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 172 + 173 + [[package]] 174 + name = "windows-link" 175 + version = "0.2.1" 176 + source = "registry+https://github.com/rust-lang/crates.io-index" 177 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 178 + 179 + [[package]] 180 + name = "windows-sys" 181 + version = "0.61.2" 182 + source = "registry+https://github.com/rust-lang/crates.io-index" 183 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 184 + dependencies = [ 185 + "windows-link", 186 + ]
+7
day3/Cargo.toml
···
··· 1 + [package] 2 + name = "day3" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] }
+200
day3/input.txt
···
··· 1 + 5336553644444345344544134246423443634474453456455433543434354444344554344336446734443434424442135474 2 + 2231552222211222122232222222153222143972321313222122221132199121111212232232222223322324232211141222 3 + 2772224762425225322223343411225274238762252256511426224222252321273712444222223222322212222372514722 4 + 2222332122223225222222231122322211162222222122222223222222112222222221222221122222211222221323211121 5 + 2442432212422332232212684452222313252425265641254324242452246232226535522434643524124524537424423362 6 + 2222233422111423621122222212311251411422222223222912458231222425211121231623223282223222522223222122 7 + 6222223242223652228324218422222362221764545245524242232623222297125251246222225724122121211122224222 8 + 4232224233342412225323232213216232342313322232223122122235533321125233534232433231314523232332322221 9 + 2122322222214334122221225332224135442322222222212222422222323226222122212232212224221122213432222122 10 + 2424223122212362222224552241443214224422422432222223843433512122232228212222124434222582122223222222 11 + 2432223333332221313232223422213342233315232323222331512443326233254223233333233636213322362222256222 12 + 7122126632562515224125225362667124227322322242224271222621716242222212522123121227432224225952272253 13 + 2222212212242122222232222221221722123232232212122212232222221222322221222233321212222421322222222212 14 + 2221221422211222212322322121412222222222122222222224241219222222222222221222112223222322212632122222 15 + 5534445456247653656757666664627455835542585748445743654764144452444387554884458915245555558444643884 16 + 9512534434375364134535574254437735656452833258371533854544254231533455464457764721474675412285253244 17 + 1222132235322123232352222234221222222232222343133534223311734323361424423343223254323262234232412232 18 + 3335393323363345233744353533723247497385344635743444543334136356167734741354933353336333373325323363 19 + 6246535473632347143443572543225451752532247667623444533348753324456165153345524525229354246267552136 20 + 3833423335226442242752254233438221626337276763855254394314383424391322976834897938339225342384484139 21 + 6566326325524467263334162556535653665353335233353664454455232456455242645465666454544553386416347535 22 + 4324186432313312134243423843486524124326333333433323213351442733425223432233323283333443833433213244 23 + 5331244255455613356533321313557625245322332438123334257346465238275342452343137252243454142412433412 24 + 3636221535225324121161754452223333432625253335323942128583211532241273421552322635332525352358633395 25 + 1434424644342423614412464334249543241223622174434228241426244444222346244218262266224444458241414316 26 + 4429643565232425335455432594493435463576463335543244433365262284343643434433375323444336235434367853 27 + 3333348355135625533433434354535533552333333254363623545454353346333355553533355333333335545375745333 28 + 9413365353252234324342233243221133223434433413483224344244114522232211446173522421253531512217333231 29 + 5355634553564545344643644465443354144553453444453345354624334535434345444544445634341555444557443455 30 + 1242224257112316335224222232243261832293222423332732225242234225232332382414535443333422422333222331 31 + 2221332115546245222243332562793281316628425355453522312122442428632218343424314238511422857223243245 32 + 3212222212222312212222224211242222112322232222222222151223211222252122524222222276222221212232212323 33 + 3222225222232221112232232222223342231221221223342212223134233222222332222315332222322212341222124232 34 + 2212334243133632233222232132122547323243313433286331313223512422233234232332223244323223327523226335 35 + 2122223432122231232152222122224122443212122222422222242253222212222222321225323232232211222223231232 36 + 2244622222232212222242224212142423222123323122422412232423323324432241321323364142423222223233411225 37 + 6222423434424455444354144148342344374233244314223355434444343114251222313122428334422422443428433223 38 + 3325133224211221234125132133262122322121125262222122273311632232111232122322423232324421233162432232 39 + 5637666677943457253454738838787924579339159539896464934479569377944395958548836349747363665486449333 40 + 2335224252512222332222512422323442312222432222121131222224422433531222232224321331123352233321361521 41 + 2132128512324422422435822243221724432283234851222824264222292232222264242333343231122258221452223252 42 + 5526862426624475574252856573796356754365634425536464563546663465229665555553346633385746235344462425 43 + 8222263129412219224258536469522726265398956353283431222762985937532863646362328356224222642445222111 44 + 6236221122224222122213221222126622145225272222226222121122422221631122222232223222223422231124224414 45 + 2122332124322232232222222221226112257422632232423232221216222222244232142443322321722212124222233223 46 + 2233222222211228282214322222227212222222212221244224212263712213342222232522142122415222232322283232 47 + 4633454261634464152435443124252423444372351444625334424633335426645322323226634643354242253135326245 48 + 5678982394685564845994548657644669444558464947748578335844998769476397766345944646499828444464863436 49 + 2432353123332533122523225323134434143222322323321442323223441143535334332344233333333433333332322432 50 + 5445354524444553433774155342432544354435484255854333514533562923334444543244335434343346344134333476 51 + 2321344223851236236322443422436332443414234464224817412442644242424222244632232542234532335324242334 52 + 2222223122523215222222222221362222122132322342254232325222125131222262231223222123212122223224111262 53 + 2533333663433435543462553544333464333233532345326332253233633453447435342242415433343655634335352266 54 + 2233432331345835321313332433222633566311333365337323237332444564333332432423334215232332224322433634 55 + 7224252465341134353224671212245243514323345312427223442242132255742541224325533433326331221432243212 56 + 3222232163134332123233342223322233383262222333123231232332243323533223234233334332422433334334232432 57 + 2154534332343514341333463325334645234573643247242544225243633435524224433432656273633324637523322143 58 + 5145513444512134242431353321552131334342142341531323351541353545355124411435413544254442343313346789 59 + 4634443444547564454535457334435334463553456444843344524344832442855447443844354754345448415474845343 60 + 1323131421243626533322324315621261232129463912228668231154214444517427321284416448333612262343332527 61 + 2322222322222157522321312232232271322222222234272246222221331322332413225221222322237212222213452222 62 + 3232522214322232222232324231232431722322222342342241443122222323322322322243222322231243123231233323 63 + 4345222132632322234242343613632223331222223328383242222632233133522435222633222221326123243621122436 64 + 7433257484523366444617242684443254482342134233331526534514323426271284776345312453344186353431639431 65 + 9214342212223723243326422342652224164271452123412422532623224322341231223212235212223221222634434435 66 + 3564546123223222531252252522121332524612412253222222232232224424422151215212522221342242211424222134 67 + 7453433853366853658525854223338553667352333585343344315442274459554343694755458365524564583734397265 68 + 3553515453526335821442323544154332433425255115455219523343223225655453383221253393442333635322232355 69 + 2323232322233122221224222111322222332322211222332221333232222323333222322314223222323112242233222333 70 + 4333331335432323737332423343343224333233273132433133323432342423833234352623142313332333343323233224 71 + 6322223221223223222222222222223122242122342212222222222212722122832322213212424331222212223222262214 72 + 1423443416323252424932416443425571522534322276431723266212255282578276186352235252224258522515621452 73 + 3573553334519433332763744335535636343362286677837432334354435463765235352664356363263356336532237237 74 + 6113635328352623431322232828262444746448414873243353662187252466123634264535262243834442323326254553 75 + 5486574862454574344447734335813467864444275314764454438848385373449844532533797368534836815543674567 76 + 5624241446642762525428236843434782152225343232123686742575651477545574442472256643243624145433545252 77 + 3322332325512323242112542327331233335355332323833223343232333363332231332222233233343143332633252212 78 + 2221221221211222332725232512221242213332122265225221224432263232212242232272272155254347725123524212 79 + 3435623433452254355334236443122433433774353441243343723523344354357333347323334346333324335331342396 80 + 3372133423342432543423233333332934423433223322263331333222323343333432332333622332433323624243323443 81 + 5153522485233336423557422642523125555232424314216363223931474143556314435424333333134344543353634724 82 + 4431333322223322122322133242332237223216217233262123423236336221233331323212332432321233212312233211 83 + 4273766364364364655646636764456566664486572444347935446768668666555466465466324635358758666626644765 84 + 8353428675276531424242352242842454528545321623173972565527756985264327342746265422243376731272443245 85 + 3244442364341425252371262243432122221422624233364335216334132224653452124253421225252422244133252363 86 + 3322112212722221225221222422123221111242264212622222542722232237122221222142222113322292222221222221 87 + 4224443345445736233345344453424443444443434454444341421433354334644445343543441444243378343524415483 88 + 5543555445444342555344353455333452553253432354364435334423551355454124334343433443463433245555334463 89 + 9459632664652175793511423543438453733546775296353233368372323633444893214375436376751336365296442933 90 + 6684956778789897766976966779578748656676877675996987448628697786699977485795996797799499599879366597 91 + 2332333353364332643333335332623333523332233332535523333313363222242362322333336443523335433314334333 92 + 2212333262343232222142224653123133133332336442332233223323323233322213231322233123222433632232533222 93 + 4244332443324312745322622221314464334132126237435332222214231553234233212232123234343435435224722323 94 + 5235454144443534343235442423344235444323432442454454454443444332233433544244633434554426345333434334 95 + 6162321135333124313242362623262352325228242354422226233323133113632326225333223332592222315163266232 96 + 6443453543334546545634524843553334424254145545425564345335534451472437755444765635244223453336533595 97 + 5235553432323222434353234554332212315224155332242483222543221135253533223242437333533242254334258542 98 + 5212231224312712512222124253421112212441424122122146222221262225232622112264322222223244124253233541 99 + 1561232212221221221721221327324642414342517662211357223356477323132351242122563322243213412522622512 100 + 2323969243372322938332526337221165933235227131687296213252662531524437527284729253511334229133235436 101 + 2342232222222146125316153626218245622433222236542233625353314232263222244513524321313222232322232823 102 + 1342334332323323434451123323233433233121144331322342315342522731333332122233371323326124423313224253 103 + 1223122222323222222344332322222512222223222222222222132222224224212333422331223234323233222123132224 104 + 5255323322222131232339223153323322221222223312325332225522333422333322213322236431421333333223232133 105 + 5774662565434662544452426446275286662563474232352644526648674554413544854255424662535673643565765663 106 + 4433545546337355545455654557555465733569744955683676558545454545549565344855554594454718565459546445 107 + 4336523445443593523464455244445738633353444454456234434533244534443445432312472334346234535433544553 108 + 2833324214522451212343233441642223232222313383222229514133245413412942232431434236244222332252246122 109 + 4457462445545666854155774823256874546455554516646457186727856445223576676267358538826287614348132732 110 + 1233223122223133221322221321221212132222211242122224222211213322323222232222212423222222212226222222 111 + 6424433252446633434461322433222433342133334476234523452345342132423436133236243232345434434933333454 112 + 3474443452446431344474444436443244223533242344244444443443444464344344342343463659435732344434447244 113 + 6224463414754576665425424544934552736357254143355333542564547555445335623322323693434433345453357453 114 + 4232422525233332345352243234256237325354742355315935122265254245275534322646144325262335634355243233 115 + 3421222232322235232225233242222235322451222222222221622222522221221352222222222123242113222322222232 116 + 4525354634252345424334662656165234433352556232316562562544345223343812143422473434632433632344232266 117 + 3333331462244343343343213342323233333333643333332223333211133433333144333333333433133334333342332323 118 + 3351444423337331433253625345533335333254522543375435453135433473442353233645534333453334333332444532 119 + 2231261133222247347224721312733322532223222222282233417132522424432343359324664322223233343212663331 120 + 2793725437323644653254435233353433425345335223554345423475334233523435623354323451622672343424346931 121 + 7561722372945437489223787771362729622836228356343333843917723462433378833638238394835351887379738939 122 + 3222262286724212792226485212314122752232242225327234734322322232136333264522231222715142731823223334 123 + 3312345432264325394217133433324213343222322445241241453125221432222132122351223212326435257232323222 124 + 2732332335423425242354262231123131929233152335311331233363573112323732123212232222413127381333814123 125 + 2336322233223332223443322371252223324223222333342222224312323331722242244243222323321224222223222412 126 + 6311751123743582558757672228658342222515356174644587274476221364232421756887783677887812824778636839 127 + 1421111442223124421441434411211222441313144121242441414413224322113124434423331124233143242113356789 128 + 1445245523424245334544553433315432342123525425435244256533533513434242225343254533524555456233224432 129 + 2123222311224132122212222221122231223222342222231322122222222212221242322232212231231122211322221222 130 + 8883985796555675426659999936373533987958952445479449677795598777858999733957599799545656875568335547 131 + 2112122623212322223331212212222226422222214172122523122642224222222242323421234123532222223321121249 132 + 8458686378754755587576576589759659886465778678778374653583587623886477867777584584684886675656756958 133 + 3223322133332333212231223224333221222251232331121212423134622122122223232332122254222333333131312212 134 + 4141542644444245445244432265424447445234422343354234444324683233258244684445364225538464926432442143 135 + 3228223453425236412466264333633533272367226881356944372356332332444323236327623433745523344538923323 136 + 2333313332332212222722222331221225143333133313232223322232223124213232122232243443422434321313432141 137 + 7342923454835333333223225633427423444122333272533453323472533585545331433323533728542233363447333336 138 + 2212232212121242233225222422222222421432421222423132142222221122221422322212533222522222222212122224 139 + 4622234322422124213121323333233233312174431342133231211242324323232421221233234223333342323332311333 140 + 2321232211222222212223222121222126123122123222212222222713222122122221212122212222222221132212241222 141 + 3332321222521221232324223413226223332213645322222222222222421332164412132122523232221121332532143222 142 + 3232328233423212123332333323432733423313433321231333532413232322314323311222334243233245323225433213 143 + 4736875381141534423854564745441756442425372355252315442444344425221525324555345527441547525234274422 144 + 3332355333332355333353443333352353433342413333323533333314333332334223333244333123333353433433313333 145 + 3223242252222112251255231122331222222112452424221221232312115222235222221212222222275212222212552125 146 + 4513232513422226322223622426222412252242432315264615452122324244441362543232243243543143415432123444 147 + 1242225222444327221222225524222322244123112632325122264221462222221363222229224423242222424562622252 148 + 4333531223234423332413333423463243434363235234334453422343231433233334441412433333415334333258333313 149 + 4448433512666323424233523547255464334345321633343458215355344466552336444317333333127434753334332333 150 + 7345354336432434223224313354453545434252434283344552223423328443342344455612425453344412312224425274 151 + 4221122232333322224122322232521124223221222222221222231236242222421222222231311222343292223323322252 152 + 2213212223323321232243221332134233321424332222122212232135222231932224221222225112221242321433222132 153 + 4253724445422452428224374464243663253445354661415412544424627465526524452334354534241532245612415423 154 + 2122214225223214222222443211212422217412125212525121224425346421223352221224213232342224442322224311 155 + 3322234333332321263333333933333333733323432553533333333323633351333333523661333331134332333323433233 156 + 3222721312222123412223432171222123223263322221332122232313322222123232312432223221129222121122132221 157 + 2522642322122524142231231422542242211122346222242324322322334423414322223212522326521335224321212524 158 + 7553353156356515584343226346544565558264254226827567475462364576544228552423461321682755526346356484 159 + 4435442344132654633442424443432364554344232245252233532473441344443343345431445153243434444437364644 160 + 2222226455121242221225227222221122222241634222141233324322722222722232167222122222332125321322222263 161 + 7254834412454523224344289334292442522324374251784354254324565948424741878316233472532363245233452233 162 + 2214324482133242143233644434321222114444322184532346242314337742123222342425145131344125232313323453 163 + 3152212772331422223213222322221321122326312534326222232125322233225312722212222222324236322572953482 164 + 2222425315422422242133422233622424323442461342142434221224122223214222432231242332444233223513232422 165 + 2211227222222216222222321212223332212221252231231222222222312222222222312213222222123322113222324122 166 + 7532455271643676366357643744618286355632783547834275943358643936546449636336433675848332749465865965 167 + 2187346795965575617164778898445362464673262395435955562262826331265972347286947324355426636242496642 168 + 2322422242221222222212122122232221222221322432322121212222212232231111232322223222222223222323212212 169 + 2233122126528772261371837532333324342772239253233622326643713535363522234117223231374315133572652228 170 + 5665546456565433655524616154465355565856519531236454485345645653613435834436545555555725665566655465 171 + 2222222222122221222221222222122132122222213212223222222221213222332222122233212212122221322122222122 172 + 6454665342425535613452653343646233543337326322643654552363523466535954553423457655246663542346683234 173 + 2324333343126133232362221432343432363433323323322333533643313222335333323236333533343543333333332235 174 + 1324223213232113321221222222223231312433321122512231422123241222223122223222222122322332123223422222 175 + 3475645674676475778545676874855755774336685398586375377655764858454755766636767775677477876667676336 176 + 3222412222512322112313232322222584222231781222322222251222222442222121485233112322224334222425121242 177 + 3223223224542333335232322732357332331242263392763752451262272231351236222223132134562126334742427322 178 + 2542252222231522856625152142232223221212521122419222122325112212122222122222422222222217254223222262 179 + 4547537513254245344346234124455433474433372433242538444452445755331312425442434554315527443241422325 180 + 4445335445556244762835243646283335359378432443745564643552444353345434587147443333334365255367356454 181 + 3234643355933222333323333133333244252142323323332333124334323323333312634333353353333123343233225532 182 + 5528234277872276744672842355726235847489732777137777824367399396996478652456491298349416453921854337 183 + 1223322542132222223323132222122222233412132322334221223243213223223112233332322241421223211222331323 184 + 2322225222222122235232112221242222422127222222431224222232123541254252222257431244122152321712322221 185 + 7657456331563216562634654224322452566143465272217643337113211677757511536441571276777725366617123589 186 + 3812813224822442932432242733222322142425241922249236226112221247222242273323313223232594223222253279 187 + 3857567657498655647688677456315675545174335342575756956565566645779787645754698334355685458746426456 188 + 2746424442421333364244543322434374364434624542878275422541337522434764724222454754733222343251453452 189 + 4243222222223122232514242122223343244444243322434432414232624363241441311434322223422422442122224225 190 + 5422323334251453444454343442444434444433444444424434464355445636343364223233547334243565463223543353 191 + 4333444243432413544332351334434323124522324325342433143343154344343322334233342223224443354424444424 192 + 2234442134457543366242252433532452522242824343224231342327717322434444724512416452223223754324715727 193 + 8332268533222112243243252346613483242232224132353122842733522684235222222571235232232253127222262222 194 + 2321231223322333213363333272323232323332416222733212233222332212221222233243243231223322313323233413 195 + 3423422124542223133242222222221632213224222222112422643222332422322541212451123232222233123222222227 196 + 2323332222215222232223227232222342323223221423113232232232322732221322242222312213223323112322223222 197 + 2245715272513133322434335464322323333232754364273424241423222463424522223533112411739542122823433443 198 + 8294484637572964647574463598342154393863775265338396542534532354545669212856524784298281514656455646 199 + 1136232521161566663356511554543612421615256265466164316421666416414542446556624131632223534212255789 200 + 8253243324523333532224546353152554242525224253255824125264455332262523225422354333245722624625223832
+4
day3/shortinput.txt
···
··· 1 + 987654321111111 2 + 811111111111119 3 + 234234234234278 4 + 818181911112111
+130
day3/src/main.rs
···
··· 1 + use clap::Parser; 2 + use std::{fs, ops::Sub}; 3 + 4 + #[derive(Parser, Debug)] 5 + #[command(author, version, about, long_about = None)] 6 + struct Args { 7 + #[arg(short, long)] 8 + file: String, 9 + } 10 + 11 + // Advent of Code Day 3 12 + // Joltage battery problem 13 + 14 + fn main() { 15 + let args = Args::parse(); 16 + 17 + let total_joltage = sum_joltage(&args.file); 18 + println!("Maximum battery joltage is {}", total_joltage); 19 + } 20 + 21 + fn sum_joltage(filename: &str) -> u64 { 22 + let contents = fs::read_to_string(filename).expect("Unable to read file"); 23 + let banks = contents.lines(); 24 + 25 + let mut total_joltage = 0; 26 + for bank in banks { 27 + total_joltage += get_12_joltage(bank); 28 + } 29 + 30 + return total_joltage; 31 + } 32 + 33 + // Naive approach with 2 for loops to parse string 34 + // Go to biggest number before the end and find max 35 + // Redo starting from index of previous number + 1 36 + fn get_max_joltage(bank: &str) -> u32 { 37 + // get biggest starting digit before last one 38 + let mut digit_a = 0; 39 + let mut digit_b_start = 0; 40 + for (index, c) in bank[..bank.len() - 1].chars().enumerate() { 41 + match c.to_digit(10) { 42 + Some(digit) => { 43 + if digit > digit_a { 44 + digit_a = digit; 45 + digit_b_start = index + 1; 46 + } 47 + } 48 + _ => { 49 + println!("invalid digit") 50 + } 51 + } 52 + } 53 + println!("Digit a is {} at index {}", digit_a, digit_b_start); 54 + 55 + let mut digit_b = 0; 56 + for c in bank[digit_b_start..].chars() { 57 + match c.to_digit(10) { 58 + Some(digit) => { 59 + if digit > digit_b { 60 + digit_b = digit; 61 + } 62 + } 63 + _ => { 64 + println!("invalid digit") 65 + } 66 + } 67 + } 68 + println!("Digit b is {}", digit_b); 69 + return digit_a * 10 + digit_b; 70 + } 71 + 72 + // Basically a sliding window approach, where you find the max value within each window 73 + // ensuring that you still have enough characters later on to fill out the required number 74 + // of batteries, represented here as K (the problem asks for 12 but generalized solution!! yay!!) 75 + fn get_k_joltages(bank: &str, k: usize) -> u64 { 76 + // initialize vector of len k for storing voltages (i cannot be bothered to use "joltage" everywhere) 77 + let mut voltages = vec![0; k]; 78 + 79 + // used to store global position from the slice positions 80 + let mut index_acc = 0; 81 + // used to store the relative positions in each slice 82 + let mut start_index = 0; 83 + // stores maximum value within each slice 84 + let mut max_voltage = 0; 85 + 86 + for n in (1..=k).rev() { 87 + // Get the chars from start_index to len(bank)-n, shouldn't underflow bc of assert 88 + assert!(n < bank.len()); 89 + let end_index = bank.len().sub(n - 1); 90 + let arr_slice = bank[start_index..end_index].chars(); 91 + // println!("arr_slice: {:?} from bank: {}", arr_slice.as_str(), bank); 92 + for (index, c) in arr_slice.enumerate() { 93 + // println!( 94 + // "n: {}, index: {}, c: {}, start_index: {}, end_index: {}, max_voltage: {}", 95 + // n, index, c, start_index, end_index, max_voltage 96 + // ); 97 + 98 + let cvalue = c.to_digit(10).unwrap(); 99 + if cvalue > max_voltage { 100 + max_voltage = cvalue; 101 + // this shit drove me so crazy. 102 + start_index = index_acc + index + 1; 103 + } 104 + } 105 + // Update global position to the location of last found maximum + 1 106 + index_acc = start_index; 107 + // after getting max value, set the nth voltage value and reset max_voltage value 108 + voltages[k - n] = max_voltage; 109 + max_voltage = 0; 110 + } 111 + // println!("Voltages: {:?}", voltages); 112 + return voltages 113 + .into_iter() 114 + .enumerate() 115 + .fold(0u64, |acc, (index, value)| { 116 + // println!("value: {}, index: {}, pow: {}", value, index, k.sub(index)); 117 + acc + (value as u64).strict_mul(10u64.pow(k.sub(index + 1) as u32)) 118 + }); 119 + } 120 + 121 + // Part 2 requires solving for 12 batteries 122 + // Likely should use recursion --PSYCH JK DIDN'T DO THAT LMAO 123 + // Basically want to find largest digit , next largest over and over 124 + // Maybe string manipulation is bad idea, using raw numbers lets powers of ten 125 + // function as indexes? So 9_000 would be bigger than 900 126 + // I think the problem can be recontextualized as "drop the lowest digits from left to right" 127 + // ^^ this was also wrong. i was dumb last night fr. 128 + fn get_12_joltage(bank: &str) -> u64 { 129 + get_k_joltages(bank, 12) 130 + }
+7
day4/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "day4" 7 + version = "0.1.0"
+4
day4/Cargo.toml
···
··· 1 + [package] 2 + name = "day4" 3 + version = "0.1.0" 4 + edition = "2024"
+136
day4/input.txt
···
··· 1 + .@..@@@@@.@.@@@..@.@@..@@@.@.@.....@@.@@.@@@@@@..@@@.@.@.@..@..@@@@@@@..@@@.@.@@.@@@@@@.@@@@@@@.@@@.@@@@@.@...@@@@@.@@.@...@.@@.@@.@@@@@ 2 + @@@.@@.@@@...@.@.@..@.@@...@@@@@@@@@.@@@@@.@@@@.@@@.@@@.@..@@@@..@...@@@@..@.@@..@.@@.@@@@@@..@@@.@@.@@@@@.@....@@@@@@...@.@@@.@@....@@@ 3 + ..@@@@.@.@@@@.@@@@@...@@@.@@...@@@@...@@.@@@@.@@@@@@@@@@@.@.@@@@@@@...@@@@@.@@.@@@@.@....@@@@@@.@@@.@@@@@@@.@...@@@...@@@.@..@@@@.@@@@.@ 4 + @@@@@@@.@.@@..@@.@@@@@@.@@@..@@@@.@@..@@@@@@@@@.@@@@@@....@..@.@@.@@.@@@@.@@@.@.@.@@@@@.@@@@..@..@@.@..@@@..@@.@@.@..@.@.@@@.@@@.@....@@ 5 + @.@@..@.@@.@@@@..@@@@@@@@.@@@@@@@@@@@@@....@@.@@@@@@.@@@@..@.@..@@@.@@@@..@.@@@.@@.@@@@@@.@@.@@@@@@.@@.@@@@.@.@@@@@.@@@.@@@.@@@@..@@@@@@ 6 + @@@@@.@...@.@..@@.@@..@..@@@.@.@.@.@@.@@@@.@@..@...@@@@@@@@@@@..@@@@..@@.@@..@@@@..@@@@@@@@.@@.@@@@@@@@@.@@...@...@@@..@@@@..@.@@@.@@@@. 7 + @@@@@@.@@@@@@@......@.@@@@@@@@@@@@.@@@@...@@@.@.@@@@@...@@.@@@@@.@@@.@@@.@@@@...@.@@@@@@@@.@.@@@..@@.@@.@@@..@@@..@@@@.@@@.@@.@@@..@..@@ 8 + @@.@@.@@.@.@.@@@@.@..@@@@@@..@@@@.@@@.@@..@@@@.@@...@@@.@..@@@.@@@@....@..@.@...@@@@@@@.@@..@@.@@@.@@@..@.@.@@@.@.@@@@@@@..@@@.@@@@@.@@. 9 + .@.@@@@.@@@@@@@@@@@@.@@@..@.@.@@..@.....@@..@@@@.@.@@.@..@.@@.@@..@.@@@@@@.@.@.@@.@@.@..@@.@.@..@..@@@@@.@.@@..@@@.@@@@@@.@@..@@@@@@@@.@ 10 + .@@.@@@@@.@.@@@@@@@@.@@@.@.@@..@...@@@...@.@..@.@.@.@@@..@.@@...@@@@@..@@.@@@..@@@@@.@@@@.@@@.@@@@@..@@@.@@.@.@...@.@@....@.@.@@@@@@@@@@ 11 + ...@@@@@..@@.@@.@...@@@.@...@..@@@@@@@..@.@..@@@..@.@@@@@@..@@...@@@@..@@@...@@@@.@@.@.@@@.@@@@@@@@@@..@.@@.@.@@@.@@@@@@.@.@..@@@@@.@@@@ 12 + @@@@.@@@@@@.@@@@..@@@@@@.@...@.@.@@.@@@@@.@.@.@@@@.@@..@@.@@..@.@.@@@@.@@@@@@..@.@.@@@@@@@@@@@@..@..@@@....@.@@@@@.@@@@..@@.@...@.@..@@@ 13 + .@@@@.@@@@@@@.....@..@@.@@@.@@@@..@@@@.@@..@@@@@..@@.@..@@@@@.@@@@.@@.@.@@..@.@@.@..@.@@@@@@@.@@@.@..@.@@@.@@@@@@.@@@@@@@@@.@@@@@@@@@@.. 14 + @..@@@..@..@@.@@@@.@..@...@@@.@@..@.@@.@@@.@@.@@@@@@.@@@@@.@@@@@@@@@@@.@@@@..@.@.@..@@.@@@@@@@@.@@@.@.@..@@@@@@.@@.@@.@@.@.@@@@@@@@.@@@@ 15 + @@.@...@..@@.@.@..@.@.@.@.@.@.@@.@@@.@@@@@@.@@.@.@....@@@@...@.@.@@@@@.@@.....@.@@@@....@.@.@.@.@@.@@.@@@@@@..@..@@@@.@.@...@@.......@@@ 16 + @....@@@@@@.@@.@@@..@.@@@@@.@.@.@@.@.@.@@@.@@@@.@@@@.@.@.@@@@@@@@.@@@@.@@.@.@@@@@@@@.@.@@.@@.@@..@@...@.@@@@.@@@@@@@@@..@@..@@.@.@@@@.@@ 17 + .@@@..@@@@@...@@.@@.@..@@@...@@.@@@@@@@..@@...@@.@@..@@..@.@.@@@.@@@..@@@@..@@@.@@@@@.@@@.@@...@@.@..@@@..@.@@@..@@@@@..@@.@..@...@@..@@ 18 + .@@@@.@@@.@@@@@...@@...@..@.@@@@@..@...@@@.@.@@.@@.@@.@.@.@...@.@@.@@@..@@@@@@@@.@@@@@@@.@@.@.@.@@.@@..@.@.@@@@@@.@@@.@@.@.@@@....@@@@.@ 19 + @@@..@@@@@@..@..@.@.@@@.@.@@.@@.@@@@@.@@..@@@@@@@@.@@@@@@@@@@@@.@.@@@@@@@.@@@@@@@.@@.@@@@@@@@@@@.@..@@.@@.@@@.@@@@@.@@.@@@.@.@@@..@@@@@. 20 + ..@@.@@@@@..@@@.@@@.@@@@@@@..@@@@@@@@.@@@...@@@@@.@.@@.@@@.@@..@@@@@@..@@@..@@.@@@@......@..@@@@@@.@.@.@@..@.@@@..@.@.@@@...@@.@..@.@@@. 21 + @@.@@@@.@@..@.@@.@...@@@@..@.@.@@@@@..@.@@..@@..@@@@.@.@.@@@@.@.@....@.@@@.@.@@@@@..@@@@@...@@@@@..@@..@@.@@.@@@@@.@@@.@@.@@.@@..@@@...@ 22 + .@@@@@@@.@.@@@.@@@.@@@@@@.@@@.@@@@@@@@@@@...@.@@.@@.@@..@@@@@@.@@@@@@.@@@...@...@@@.@@@.@..@@@@@@.@.@@@@@@@@@@@@@@@@@.@..@..@@@@@.@@@.@. 23 + .@.@@@@@.@.@@..@@.@.@@@@.@@@@...@.@..@..@@.@.@..@@@@@@.@...@@@.@@@@@@...@@@@@@@@.@@@@@.@.@.@.@@..@@.@@@.@..@@@.@@@@.@@@@@@.@..@@@@.@@@.@ 24 + ..@@..@@.@@.@.@@@@@@@@@@@.@@@@@@.@.@@.@@@@@@.@@..@.@@@.@@@@..@@.@...@.@@@@@@@@.@@@@@@@...@.@.@@@@@@.@@@@@@@@@@@@@@..@@@.@@@@.@@@@@.@@@.@ 25 + ..@.@@@@@@@@..@@@..@@@.@@@@@@@@..@@.@@@@@@@@@@@@@@.@@@.@@@@@@.@.@@@.@@@@@@.@@.@.@@.@@.@@..@@@.@@@..@.@@@@@@@.@.@.@@@@.@..@@@..@...@....@ 26 + .@@.@@@@.@@@@@.@..@.@.@.@@..@.@@@@@@@.@.@@..@@....@@@@.@@@..@.@.@@@@.@....@.@.@@@@.@.@.@@@@@@@.@@.@@@..@@@..@@@@...@@@..@@@.@.@..@@@@@@@ 27 + @.@.@...@.@.@@@@@@..@.@@.@@.@.@@@@...@@.@.@@@@.....@@@@@@@@..@....@.@@@@@@..@@@@@...@..@@@@@@@@@@@.@@@@@.@@@..@@.@..@@...@.@@@..@@@..@@@ 28 + @@@@@.@.@@..@..@@@...@@.@@.@@.@@@.@@@@@@@@@@@@@@.@@@@.@@...@@.@@.@@@.@..@@@..@@@@@@@...@@@@@....@..@.@.@.@@@.@@@@@@@@.@.@...@.@.@.@@@.@. 29 + @@@.@@.@@@.@@.@.@@..@@@@@.@@@.@@@@@@..@@..@.@..@@@@@@@.@@@@@..@@@@@...@@@.@@@@@@@.@@.@@@@..@@@@....@@..@@@@.@@...@@@@.@@.@..@@..@@@@@@.@ 30 + ....@@@@@@@@@@@@@@.@.@..@@@.@.@@.@@@.@@@@.@.@.@@@@..@@@...@....@..@@@@.@@.@@@@@.@@.@..@@.@@@.@@@@.@...@@@.....@@.@@.@@@@@..@@@@@@..@@@.. 31 + @@@@@@@.@.@@@..@@.@@@@@@@.@..@@@...@.@.@@..@@@@@@....@@@@@@@@..@@@...@.@..@@@.@.@.@...@@@@.@@.@@@@@.@@@@@.@@@.@.@.@@@@.@@@@@@@@@.@@@.@@@ 32 + @@..@@@@@@@@@.@@@..@..@@@@@.@@@@..@@.@@@.@...@.@@.@.@.@.@.@@@@@..@@@.@@@.@@@.@@.@@@@.@@.@.@.@.@.@@..@@.@@@@.@@...@@.@@@.@@.@@..@.@@@@@@@ 33 + .@@@...@@@@@@.@.@@@.@@.@@@@..@.@@.@@@@@@@.@@..@@@@@@@@.@.@..@..@@@@@@@.@@@@.@...@.@.@@..@@@@.@@.@...@@@.@@.@@.@..@@.@@.@.@.@@.@.@@@@@..@ 34 + @@@@@....@@@@..@@.@.@..@@..@@@....@@...@@.@@@.@@@@@..@..@..@@@@@@@@..@@..@@@@@...@@@@.@@@.@@..@..@@@..@..@@@@@.@.@.@.@@@@@@@@@.@..@@@@.. 35 + @@.@..@@@@@......@@.@.@.@..@@.@@.@.@@@@@@@@.@@@@@@@@..@@@@......@..@@.@.@@@.@.@..@@@.@.@@@@@@@.@.@..@....@..@@..@@@@@...@.@.@@@@.@.@..@@ 36 + .........@@@@@@@@@@@..@....@.@@@@@@@@@@.@..@.@@@@@@..@@@.@@@.@@@@@@@@.@@..@.@..@..@.@.@@.@@@...@@@@@@@.@..@@@@@@@..@.@@.@.@..@.@@@@@.@.@ 37 + @@@.@.@.@.@@@.@@.@@.@@@.@@..@.@@.@.@@.@@@...@@@@@@.@.@@@@.@@..@@.@.@@.@@@@@@@@..@.@@@@@@@@@@@@@@@@.@...@.@...@@@@@@@@.@@...@@@@.@.@@.@@@ 38 + .@.@@@.@@@@@....@@..@@..@@@@@@@@@..@@.@@@.@@...@@@@@@@....@..@.....@.@@...@@@@..@@.@@@@...@@@@@@..@@@..@.@.@@@..@@.....@@.......@.@@@@@@ 39 + ..@@@...@@..@..@.@.@@.@...@@...@@@@@@@.@@...@@@@@@@...@@..@@...@@@...@@@@@@.@@..@@@@@@@.@@@.@@@@@@@.@@@@@@@@..@.@@@@@@.@..@@.@.@@@@..@@. 40 + .@...@@.@@@@@@@@@....@.@@@@..@@@....@.@@@@@@@@@@@.@@@@@..@.@.@@..@@.@.@@.@@@..@@@@.@@@.@@...@.@@.@@.@@.@@@.@@.@.@@@@@..@..@..@@.@@@..@.. 41 + @@@@@.@@@@..@@.@@..@.@.@@.......@@@....@..@@@.@.@@@@@@@@@@@@@..@@....@.@.@@@@@@@.@@@@@@@.....@@@@..@.@@@.@@@@@@@@..@.@@@@@@@@@..@@@.@.@@ 42 + @@@@@@@@@@@@...@@..@@.@@.@@@@@.@@@@.@@@@@@@@@@..@@@.@.@@@@@.@.@@@@@@@.@@.@..@@.@...@..@.@@@.@@..@@...@@@@@@@@@.@.@@@.@.@.@.@.@@..@@.@@@@ 43 + @.@..@@@@@.@@@@@@@@.@@@@.@@.@@@@..@...@@@...@.@@@@@@@@..@@..@.@@.@@@@@...@.@@@.@@@@@.@@@@@@@@..@@@...@@@@@...@@@.@...@@@@@@@@@@.@@..@@@@ 44 + .....@.@..@......@@.@...@@@.@...@...@@@@..@@@.@.@@@.@.@...@@@.@@@@...@.@@@.@@..@@.@.@@@@..@@@@@@.@@.@@@.@@@..@..@.@@@@...@..@.@@@@..@@.. 45 + @@@.@.@@..@@.@@@@@@@..@@@.@@@..@@@@..@..@@..@.@@@@.@.@..@@@@@@@.@@@..@@@@@@..@@.@@@@.....@@@..@...@@..@@@@@@@@@...@@@@@@@.@@@@.@@@@.@@.@ 46 + ..@@.@@@@.@@.@@@..@@@..@.@.@@@@@@@..@.@@@.@@.@@@@.@@.@@@@@@.@@@@@@@@.@.@@@@@@@@@@@@@@@@.@@@@@@@@.@....@.@.@@@..@@@@.@.@@..@@@@@@.@.@@@@. 47 + .@@@@@@@@@@.@..@.@.@@.@@@.@@.@@.@@.@@.@@@@@@@@...@@@@@@.@.@..@@@@...@...@@@@.@@@@@@....@@@.@@.@.@@.@@@..@@@@@@.@.@@..@.@.@@@@@@@@@@@..@. 48 + .@@..@@.@.@@.@@.@@.@@@@@...@@.@@.@@@@@@.@.@@.@@@@@@@@@@.@@@.@.@@@@@@.@.@@..@@@@.@.@@@@..@@@@.@@.@@@@.@@...@...@@....@@.@@.@@@@@@@@...@@. 49 + ...@@@@@@@.@@..@@@@@..@@..@.@@..@..@@.@..@@..@.@@.@@.@.@.@.@@.@@@@@.@....@@@.@@@@.@....@@..@.@@.@.@.@@..@@@..@@@.@.@@@..@@@....@@@@@.@@@ 50 + @.@@..@@@@@.@.@@@@@.@.@.@@...@@@@@@@@..@@@@@@.@@..@.@@@.@@.@@@.@.@@@.@@@@@@@.@.@.@..@@.@.@.@@.@..@@@.@@.@.@@@@@@@.@..@@@..@.@@.@@@@.@@@@ 51 + @@@.@...@@@@@@@..@@@..@@@.@@@.@@..@.@.@.@.@@.@.@..@@.@.@.@.@@@@.@@@@@..@@..@..@.@@@@@..@.@@.@...@@..@.@@@@..@.@@@@.@@@.@@@.@@@@.@@..@@.@ 52 + .@.@@@@@@@@@@@@..@.@@@@.......@@.@@.@@@@@@.@.....@@@@@@@@@@@.@..@@..@@.@.@@@@..@@@@@.@@@@..@@.@@@...@@@..@..@@@@@@@.@...@@@@..@...@@.@@@ 53 + @@@@.@...@.@..@@@@...@@@@@...@.@@@..@.@@@...@@@@@@.@@.@.@.@.@@.@@@@@@..@@@.@@@@.@@..@..@@@@.@@...@...@..@@@.@@..@.@@.@@@@@.@.@@@@@@@@@.@ 54 + @@@@...@@.@@@....@@.@.@...@@.@@.@@@@.@.@@@@@@@@.@@@@@@.....@..@@@...@.@@@.@@...@.@@.@.@@@....@.@.@@@..@@@@.@.@@@@.@@.@.@@@.@@@@@@@.@@... 55 + @@@@@.@@@@.@@.@@..@.@@.@@.@@@.@@@@@@..@.@.@@.@.@@@.@@@@@@@.@@@@@@@@@@@@@@.@@.....@.@..@@@@..@..@@.@@@@@@@..@.@......@.@@@@.@@.@@@@@@@@@. 56 + @@@@.@@.@@@.@.@@@.@..@@..@@.@@.@.@@@@@@@@..@@@.@.@@..@..@@@.@.@@@@@@.@@.@...@@.@@@@@.@@.@@@@..@...@.@.@.@@@@@@@@.@.@.@@@@@@....@@.@..@.. 57 + ..@.@@@@@@@@@.@.@@...@@.@@@@.@....@@..@@@..@@@@@..@.@@@.@@@@.@...@@@@@..@.@.@.@..@@..@@@@@@.@.@@.@.@@@..@.@@@...@..@.@@...@@@@.@.@....@@ 58 + @@@@.@@@.@@@@@@.@.@@@@.@@.@@@...@@@..@@@.@@@@@..@@.@@@@@@@.@@.@@@@.@@@.@@.@.@@@.@..@@@...@@..@..@.@@.@@..@.@@@@@@@@@@@.@....@..@.@.@.@@@ 59 + @@@.@@@@@@...@.@@@.@@..@@.@@@@@@@...@@@@.@@@@@@.@@@@..@@...@@..@@@@.@@...@@..@@@@@..@@@@@.@@@.@@@@@@.@.@.@@...@.@.@.@@.@@.@..@@...@@@..@ 60 + .@@@@.@@@@.@...@@@@.@@@.@@@.@@@@@.@@@@...@@.@.@@@....@@@@@.@@@@@@@@@.@@@.@@@..@@.@...@@@@.@@@@..@@@.@@@.@@@@.@@@@.@.@@@@@@....@@.@@...@. 61 + @@@.@.@@@@@@@@.@@@@@@.@@@@.@...@@@..@@.@@@@.@.@.@@.@..@@@@@@.@@@@.@..@@@@.....@..@@@.@@.@@@.@.@.@@.@.@@@.@.@@@@@@@.@@.@@.@@@.@@@..@@@..@ 62 + @@..@.@.@.@@..@.@@.@@@@@.@@@..@.@@.@.@@.@@.@@@@@.@.@@@@@.....@@@.@....@@@..@@.@@@@@@@@@@@@..@@@@.@...@.@@.@@@@@.@@..@.@.@..@@@.@@..@@@.. 63 + @@@@@.@@@.@@.@.@.@...@@.@.@@@.@..@@.@@@@@@@.@@@.@.@@@.@@@@.@.@..@.@@@@..@.@@@@@.@@@@@@@@@@.@@@@@@.@@@@@.@@.@.@@@@@@@.@@@@@@@....@@.@@@@. 64 + @.@.@@@@..@@@@@.@@.@@@.@.@@@@@@@.@@@@.@@@@@@@...@.@.@.@...@@.@@..@@..@..@.@@.@.@.@..@.@@@.@@@@@@@.@...@.@@.@@..@@@@@@@..@@@..@@@.@@@...@ 65 + @@...@@@@.@@.@@...@.@@@.@@@.@@@.@@@@@@@@@@@@@@@.@@.@....@@@@@@@@.@..@@..@@...@@..@.@@..@.@@.@@@@@@..@@@@@@@@@@..@@@.@@.@@@.@.@.@@@@.@.@@ 66 + ..@.@.@@..@@.@@.@@..@@.@.@@@@.....@.@@@@@@.@.@@@..@....@@@@@@@.@.@@.@@@@@..@@@@..@@.@.@@@@@@.@.@.@.@@@..@@..@@.@@@@..@..@@...@...@@@.@@@ 67 + @.@@@@@.@@.@@..@@@@@.@@@@.@.........@.@@@...@@@.@..@@@@@@.@@@@.@@.@@.@@...@@@@@.@.@@@@..@@.@@@@@@.@@@@.@@.@@@@@@..@...@@@@.@..@..@...@@. 68 + @@@.@@@@@.@@@@@.@.@@.@@@@@@......@@@@@.@@@@@@@@@.....@...@..@...@.@..@.@@@@@.@@@@.@.@@@@@@.@..@@..@@.@@.@@.@.@@@@@@.@@..@@@.@@.@@.@@@@@. 69 + @.@@@@..@.@@.@@.@@.@@@@@@..@.@..@@....@@@@@@@@@.@@@@.@@@@...@@.@@..@.@...@...@@.@.@@@@..@.@@@@.@@@@..@@@@@@@@@@@@@@@@.@@@@@.@@@..@.@@@@. 70 + @..@@@@.@.@@..@@@@@@@@@@.@@@@@@.@.@@@@@@@.@@@.@@@@.@@@@@.@@.@@@.@@@@.@@@@@@@..@@@@@@@.@@.@@@@@@.@@.@.@@@.@@@.@.@@.@@@..@.@@@@@.@.@.@@@@. 71 + .@@@@@.@@@.@@@@@@..@@@@@@@@@@@@.@....@..@@.@@@@@.@.@@...@@@.@@@@.@@@@.@@.@.@..@@@@@..@@@..@@@...@@...@@..@.@..@@......@@@@@@...@.@@@.@@. 72 + @@@@@.@@.@@.@@@@@..@..@.@@@.@@@@@..@@@@@.@@...@@..@.@..@@.@..@@@@.@...@@@@.@.@@.@@...@@.@.@@.@.....@@@...@@@.@@@.@.@@@@@@.@@@.@@@..@@@@@ 73 + @@@.@@@@.@@@.@@.@@@@@@.@....@....@@@.@@.@@@@@@@@@@.@@.@..@..@@@.@@@@.@@@@.@.@.@.@@@.@@@...@.@@@@..@@.@@@@@@@@@@.@@@.@@..@@@.@@@.@.@..@.. 74 + @@@@.@.@.@@@@@...@@@.@@@@@@@@...@@.@@..@@@...@@@@@..@@.@@@@@@@@@.@@@@..@..@.@@.@@@@@@@@@@@..@@@...@.@@.@@..@.@@@@@@....@@..@..@@@.@..@@. 75 + @@@@@.@@@..@@@@.@@..@@@@.@.@@.@@.@@@....@@@@@.@.@@.@@@@@..@@@.@@..@.@....@@.@..@@@@.@@.@.@.@.@..@@.@.@@.@.@@@@@@.@@@@.@@@@@.@@@....@@@.@ 76 + @.@.@.@.@.@..@@.@@.@@@@.@..@@...@.@@@...@@....@@@@@.@....@..@@.....@...@@@.@@@@.@@@@@.@..@@@@.@@@@@.@@@...@....@@...@@.....@@@..@@..@..@ 77 + @@@@@..@..@..@@.@@.@@@@.@@.@@@@@@.@..@@..@@..@.@@.@@.@....@@@@@@..@@@@@.@@@...@.@@@.@.@@@@@@@.@@@@.@@...@@@.@....@.@@@@.@@@@@.@.@@...@@. 78 + .@@.@@@@.@.@@@.@.@.@..@@.@@@@.@.@@.@.@...@@@.@@@@@@@@@@.@@@@.@@.@@.@..@..@@.@@@@.@@.@@.@@@@..@@@.@@@@@.@@.@@@@@@@@@@@...@.@@@@@..@@@@... 79 + @.....@@@@@.@@@@.@@@.@.@.@...@@.@@@.@.@......@..@.@@@@.@.@@@@..@.@@.@..@@@..@...@@@.@@@..@@.@@@@@@@@.@@..@@@@.@@@@@@.@..@.@@@.@@@.@@@..@ 80 + @@@@.@@@@.@@@.@.@@@@.@.@..@@@@@@@@@@@@@@..@@.@..@..@@@@@@@.@@.@.@@@@@@.@@@@@@@.@@@..@.@@..@@.@.@.@@@@....@@@@@@@..@@.@.@@@@@@@@.@.@.@@@. 81 + .@@@@@@@@..@@@.@.@@@@@@@@@@@@...@.@@@.@@@@@...@.@@.@@.@@@@@@@@...@..@.@@@.@@@.@@...@@@@@..@@@.@@@.@@@...@..@@.@@@@@@@.@.@..@@@.@..@@@@.@ 82 + @.@@..@...@@@...@@@.@@.@.@@...@@@@@@@@@.@@@.@@@@@@@@@..@@..@..@.@@@.@@@@@...@@@@..@@.@.@@@@..@@@.@@.@@..@@...@@@@@@@.@.@@@@..@@@@.@.@@@. 83 + @.@@.@.@@....@.@.@..@.@@.@.@@@.@.....@@.@.@....@@@.@@.@@@@.@@@.@@@@@..@.@@@@@..@..@@..@@.@@@@...@@.@@@.@@@@@..@@..@@@@.@@@@@@..@..@.@..@ 84 + @@@@@@.@.@.@@.@.@@@..@.@.@@@@..@@@@.@.@.@.@.@...@@.@...@.@@@@@..@...@@..@@.@@@.@.@@.@@@..@@@.@@@.@.@@@@.@@@@..@@@.@@.@@@@@@.@...@.@@.@@@ 85 + @@@@@@..@@.@@.@@@.@@@@@@..@@@....@@@...@@@...@@@@@@@.@@@@.@@@@@@@.@@.@..@@@.@@@@@.@@@@@@...@@@.@@...@.@...@@@@@@..@@@@.@.@@@@@.@..@.@.@@ 86 + @@@@.@@@..@@.@@..@@@@@..@...@.@@.@.@@.@.@..@@..@@@@...@@@..@.@@@@.@..@@.@..@@.@@@@@@@@...@@@@@.@.@.@..@@@.@.@@@.@@.@@@@.@@@...@@@..@@..@ 87 + @@@@@@@@@@..@@@@.@.@.@@@@@..@@..@@@@@@@@@@@@@@@@@@.@@...@@@@@@@@..@.@@..@..@@...@@@@@@@.@@@.@@.@@@.@@..@@..@@@@..@@@@..@@@.@...@@@@..@@@ 88 + @@.@@@@@.@.@@.@.@@.@@@@.@.@.@..@@@@@.@@@.@@.@@@@.@@.@@@.@@..@@.@@..@@@.@@@@.@.@...@@..@@.@@@@@@@.@@@@@@@....@@@@.@.@@.@..@@@.@@@@@@@.@.@ 89 + @@.@@@.@@..@.@@.@...@@..@.@..@..@@@@@@@@@@@@@.@@@@.@@.@@@@@@@@@.@...@..@.@@.@@@@@@@..@.@.@@@.@@.@@@...@.@@@@@@@....@@@@@@@@@..@@.@.@@@@. 90 + @.@@@@@@@..@.@@@@@@.@@@@@@@@@@..@...@@@.@@@.@@@..@.@@@@@.@.@.@@@@...@@.@.@@@@@@@@@..@@@..@.@..@@.@.@@@@@@.@..@@@@.@@...@@.@@..@@@..@..@@ 91 + @@.@@@@@@.@.@@@@@..@@@@.@@@@@.@@@@@@@.@.@.@@@@.@@@@.@@@@.@@.@@@..@.@@@@@@.@.@..@@@@@@@@@.@@.@@.@@@@.@@...@@@.@@.@.@..@@...@@@..@@@@@@.@@ 92 + @@..@.@.@@@@.@@.@@@@@@@@@...@@@@@@.@.......@@.@.@@..@.@@.@..@@@.@.@@@@@..@.@@@..@......@.@.@@..@@@..@@.@@@@@.@@@..@.@...@@@@.@..@.@@.@@@ 93 + @@.@..@.@.@@.@@@.@..@@@@..@.@.@@@@@@@.@@..@@@.@@.@@..@.@@@@@.@.@.@.@@@.@@@@@@@@.@@...@..@.@.@@@@.@@@@.@.@@@@.@@@.@.@@@@...@@@@.@@@.@@..@ 94 + @@..@.@@@@@@.@.@....@.@@@@.@@@@.@@@.@@@@@@.@.@..@@..@.@@.@@..@@.@@.@@@@@.@@@@@@@@...@@@@..@@@@@.@@@@@..@.@@.@@@@@@@@@@.@.@@@@....@..@@.@ 95 + @.@..@.@@@@@@.@@.@@.@.@@.@@@@..@@@.@@@.@..@.@@@@@@@@@@@.@.@@...@@.@.@.@@@@@@..@@@@...@@@.@@@@@@@@@@@@@@@@.@.@@@@@.@.@.@@@@@@@@@@@@..@@.. 96 + @@@@.@@..@@@@@@@.@@@..@@@@.@@@.@.@@.@@@@....@.@@@.@.@..@@@.@@@@@..@@.@@@@@@@@@@@@@@@@@....@@@@@@.@@@@@@.@.@@@.@...@...@@@@@@.@.@@...@.@. 97 + .@.@@@@@@@@..@@@@@...@@@@@@...@@..@...@..@@.@...@.@@...@@@@@.@.@@@.@...@.@@.@.@.@@.@@@@@@.@@.....@@.@@@@..@.@@@.@.@@...@@@@@@@@@@@.@@.@@ 98 + @@@@...@@.@@.@@.@@@@..@@@.@.@@.@@@@.@@...@@@...@@@.@@.@@@@@@.@.@@@@..@@@.@@@..@@..@@.@.@@..@@@@@@.@@@..@@@..@@@...@@@.@@.@@...@@@@@@.@.@ 99 + @@@@...@..@@@@.@@@@@.....@@@..@@@..@.@@.@..@@...@..@@@..@@.@.@@@@@@@@@@.@@@@..@@@@@.@@...@@..@@.@...@@......@@.@.@@@@@@@@@@@@@@@.@@..@.. 100 + @@@@.@@@@@@@@.@.@@@.@@@.@@...@@@@@.@.@@@@..@@.@@@.@.@@@@@...@@@@.@.@.@@.@@@.@.@.@.@@@@@...@@@.@@@@..@@@.@@@..@@.@@@@@@@@@@@@.@@.@.@@@@@@ 101 + .@@....@@@@@@@@@@@@..@.@@..@..@@@...@.@......@@@@.@.@@@@@@@.@@..@@..@@..@@..@@@@@@@@@@.@@.@.@@@@.@@@..@@@@@.@@.@@@@.@..@@.@@...@@@@@@@@@ 102 + .@@@..@..@@@@.@@@..@@..@@@.@@..@@.@.@@@.@@@.@@..@.@@.@..@.@@.@..@@@.@..@@@.@..@@@.@@.@@@.@@.@@...@.@@@..@@@@.@.@@.@@.@..@@@@.@@.@.@@@@@. 103 + @.@@@@..@@.@.@@@@..@.@@.@@@.@.@@@.@.@..@@.@@@@@@.@@@.@@@..@@@@@.@@...@.@@.@@@.@@@...@@.@@@..@.@@@.@.@@@..@@.@@@@@@.@@@@@@@@@@@.@.@@.@@@@ 104 + @@@@@@@@.....@@@@@.@@@@.@@@@@@..@@...@..@@.@@@@@@@@@@@..@@@@@@@@@@@@@@@.@@@..@@@@..@@.@.@@@.@@@.@..@@..@@..@@@.@.@@@..@@..@@..@@@.@.@@@. 105 + @.@@@@..@@@..@@...@@.@@@@@..@@@@@@@@.@@...@..@@@@.@@.@.@@...@.@@.@@.@.@@@..@@@@@@.@@@@@@..@@@.@@...@@@@.@@@@.@@.@.@@.@..@@@.@.@.@@..@@.@ 106 + @.@@.@@@@@@..@..@@@.@@@..@@..@@@..@...@@@@@@.@@.@@@..@.@@@@.@.@.@@.@.@..@.@..@..@@@.@@@@.@@@.@@@@.@@@.@@.@..@@..@@.@@..@@@@@..@@.@@@.@.. 107 + .@@@@@@@.@..@@.@@@@@@@.@..@@@@@@@.@@@@@@@@@..@@@@.@..@.@.@@@.@@@@..@.@@@.@.@.@@@@@....@...@@@@@@@@.@@@@@@@@@.@@@...@@..@@@.@@@@@@@@.@@@. 108 + @@.@@@@@@@..@@@...@@.@@.@@.@...@@@@@@@@@@.@@.@@.@@@...@@..@@@@@@@.@@@.@.@@.@.@@..@@.....@@.@@@@..@@@@.@.@.@.@@..@..@.@.@.@@@@.@@@@@@..@@ 109 + @.@@@@.@@.@@@.@@...@@@.@.@@@..@@@@..@@@@@@.@@@..@@.@.@.@.@@@@@@.@@@@@@@.@@..@@..@@.@.@.@@@@.@.@....@@.@..@..@.@@@.@.@@@@..@@@@@..@..@@.. 110 + @..@@@.@.@@@.@@@..@.@.@@@.@@@@@@@..@@@@@.@.@.@@@.@.@.@.@@@.@@@.@@@..@@@.@@@...@...@@@.@.@..@@.@.......@@..@@.@..@@@.@...@..@@..@.@@@@@@@ 111 + ..@@@.@@@@@@@@@@@@.@.@.@@@@@.@@.@.@@@@@@@.@@@@.@@..@@..@@@@.@@@@@@.@@@.@@.@@.@@.@@@@@@@@@...@.@..@.@@@@@@@..@@@.@@@@@@...@...@.@.@.@.... 112 + @@@@.@@.@.@@@@..@.@@@@@..@.@.@.@.@@@@@@@@..@@@@@.@@..@@@@@.@@@...@.@@@..@@@.@.@@@@@.@..@..@@@@@@@..@@@@...@..@@.@@@@@@..@.@@..@@@@@..@.. 113 + @@.@@@@.@@@@@@@@@@..@@.@@.@@..@.@@...@..@@@.@@.@.@@.@@.@@@@..@@.@@.@@.@@.@@@@..@@@@@@@@@@@.@@.@.@@@.@@@@@@@@@@@@@@@@@@..@@@@.@@@.@..@..@ 114 + @@@..@@@@@.@..@@@@@@.@@.@@@@...@@@.@@@..@@@@.@@@.@..@.@.@@@@@.@@@@@@@@.@@@..@@@.@@.@@@...@@.@@.@@@...@@@@@@.@....@..@@@@@..@@.@@@@.@.@.@ 115 + .@@.@@@@@@.@@@@@@@@..@....@.@@@.@@@.@.@@@@@.@@.@@@@@@@.@.@..@.@.@@@.@@.@....@@@@.@@@@@.@@@@@.@@@@..@.@.@@@@@@@@@.@@@@@@.@@.@@@@.@.@.@@.@ 116 + .@.@@.@@@@.@@@@.@.@@@@@.@@@@....@..@@@@@@@@..@@.@@..@..@@@@..@@@@@@..@@.@@.@@.@.@@...@...@@@@@@.@@@@@.@.@.@.@@.@.@.@@@.@@@..@.@@@@@@@@.@ 117 + .@@@@.....@@.@@.@@.@@@@@@.@@@@@@@.@@@@@@.@...@@.@..@.@.@@@@@.@..@..@@..@.@..@@@.@@@@.@@@@@@@..@@.@.@@@@@@@.@@@@@..@.@@@@@...@.@@@@@@@.@@ 118 + @@..@@.@@@.@..@.@@...@.@..@.@@@@..@@.@@@.@@@@@@@@@.@@.@...@....@@@.@.@..@.@.@@@@.@.@@@@.@@@..@@@@@.@.@@@@@@@.@.@.@@@...@.@.@@@@@...@@@@@ 119 + ..@@@@.@..@@...@@@.@@@@.@..@@.@..@.@.@@.@@@@.@@@@@..@@@.@@..@.@@@.@@@@@@@@.@.@.@.@@@....@@@@@@.@..@.@..@@@@@..@@@.@@.@@@.@...@.@@@.@@@@@ 120 + @..@@..@.@..@@@@@...@@@.@@@@@@@@@@@@@@..@@@@@@@.....@@@..@@@@@.@@@@@.@@@@@.@..@@.@..@..@@..@..@@@@.@@.@@@@@@@@@@.@@@@@@@.@@@@@.@.@.@@@@. 121 + @....@@@@@@@@@...@@@@@@@@.@..@.@@.@@@@.@@@..@@@@..@@@@...@@@@@.@@@@@@.@@..@@@@@@@..@@@@@.@@@@@.@@@@.@@@..@.@.@@.@.@@@@.@@@@@.@@@@.@.@.@. 122 + @@@@@@@@.@...@.@.@@@@@@@@.@.....@@@@@..@.@@@@..@@.@@@@...@..@@@@.@@.@@@@@.@@@@@@@@@...@.@@@@@@@@@@@@...@..@..@@..@.@@.@.@@.@@@.@@@.@@@.@ 123 + @.@@@@@@@@@@@@@@@.@@.@@@@@.@.@@@@@.@....@....@@.@@@@..@@@@@@.@.@@.@@@@@.@....@.@@@@@@.@@@.@@..@@@@@@@.@@@@@@@@..@@.@@.@@@@...@@.@@.@..@@ 124 + .@@@@..@@@.@@@@.@@@@@..@@.@@@..@@.@.@....@.@@@@@@@.@.@...@@@@@@@..@@@.@.@@.@@@@.@.@.@.@@@..@.@@.@.@@@@@@@.@..@.@@@.@@@.@@@...@@.@.@@@@@. 125 + ..@@.@@@@.@.@.@.@@@.@.....@.@@@.@@...@.@.@@..@@@.@@..@@@@@@@@.@.@...@@@@@@.@@@@@..@.@.@@@@..@@@@.@@.@.@..@@@@@...@.@@@@.@@.@..@@@@.@@@@@ 126 + @@@@@@.@@.@@@@.@@.@@.@.@@@@@.@@.@@@.@..@@.@..@.@@@@.@@@...@@@@@@.@.@...@@@@.@@@.@@@@@.@@@@..@@.@@@@.@@@.@@@..@@.@@@@@@..@@@....@.@.@.@.@ 127 + .@@@@...@..@@@@....@@@..@@..@..@..@@.@.@@@@.@@@@@@@@@@..@.@@@@@@@@@..........@.@@.@.@@@.@@@.@@@@@@@@@@@.@.@@@@..@@.@.@@.@...@@.@@@...@@@ 128 + ..@..@.@@.@@@@@.@@@.@@.@.@@@@@@@@@@...@@@@@@@@.@@@@@@@@..@@@.@@@@..@.@@@..@...@.@@.@@@@@..@.@@@@@@@.@.@@.@@..@@@@@....@@@@@@@@@@.@@@...@ 129 + @..@@..@.@@..@..@@@@@.@.@@@@@.@@@@@@@.@@..@@.@.@@@.@.@@.@@@@@@@@@....@@@@.@@@@.@.@...@@@@@@@@@@@.....@.@@@@...@@...@.@@@@@@@@@...@..@@.. 130 + @..@.....@@@..@.@.@@@@.@.@@@@@.@@@.@@@@.@.@@@@....@@.@@@@.@@@@@.@@@@@@@@@@@@@..@@@@...@@@...@@@...@.@@@@.@@@.@@.@@@@@@@@..@.@@@@@.@@@.@@ 131 + @@@@@@.@.@@@@.@@..@@@.@@@@@@.@@@@@@@@@@@@.@@@..@@@@@@@@@@@@@@@@.@@....@@@..@@@@@...@@@@@@.@.@@..@@..@@@.@..@.@.@@..@@@.@@@@..@@@@.@.@@@@ 132 + @.@@@.@@@@..@@@.@@@@.@@@@@.@@@@@@@@.@@.@@@@@.@.@..@@@@@...@@@..@@..@@@.@.@.@@@..@@@@@@@@@@@@.@.@@.@.@@..@.@@.@@.@@@..@@@.@@.@@.@@@@.@@.@ 133 + @@.@@.@@@@.@.@@...@@@@@.@..@@@.@@@@.@..@.@..@@.@@..@@...@.@.@@@@.@@@@@@...@@.@@..@...@@@@@.@@.@@.@@..@@@@@..@.@@.@@.@..@@..@.@@@@@@@.@@@ 134 + @@.@.@..@@@@..@@@@.@..@.@@.....@.@.@@.@@@@@@@@@@@..@....@@@..@@@@..@@@.@@@@..@..@...@.@@@@@@.@@@.@..@.@@@.@.@.@@.@.@@@..@@@@@@.@@..@@@.@ 135 + ..@@@@..@@..@.@@..@@.@..@.@@..@@@.@.@....@.@..@@@..@@.@.@@@.@.@@.@..@@@..@.@@..@@@..@@@.@@@@@@@@@@.@@.@..@@@@@.@....@.@@.@@@@@.@@@@@@... 136 + @@@@@@@.@...@.@.@.@..@.@@@.@@..@@.@..@@@@@@@@...@@@@@@@..@@@.@@@@@..@@@.@@.@@@@@.@.@@@@.@.@@.@.@@..@@@..@@..@@@@@@@@.@.@@.@@.@..@.@.@.@@
+10
day4/shortinput.txt
···
··· 1 + ..@@.@@@@. 2 + @@@.@.@.@@ 3 + @@@@@.@.@@ 4 + @.@@@@..@. 5 + @@.@@@@.@@ 6 + .@@@@@@@.@ 7 + .@.@.@.@@@ 8 + @.@@@.@@@@ 9 + .@@@@@@@@. 10 + @.@.@@@.@.
+115
day4/src/main.rs
···
··· 1 + use std::fmt::Display; 2 + use std::ops::Add; 3 + 4 + // what will be used as my config here 5 + 6 + struct Warehouse { 7 + layout: Vec<Vec<Option<char>>>, 8 + width: u16, 9 + height: u16, 10 + } 11 + 12 + impl Warehouse { 13 + fn get(&self, x: u16, y: u16) -> Option<char> { 14 + *self.layout.get(y as usize)?.get(x as usize)? 15 + } 16 + 17 + fn set(&mut self, x: u16, y: u16, value: char) { 18 + // TODO : This is not a complete check, could cause issues 19 + if y < self.layout.len() as u16 && x < self.layout[0].len() as u16 { 20 + self.layout[y as usize][x as usize] = Some(value); 21 + } 22 + } 23 + 24 + fn load_from_file(filename: &str) -> Warehouse { 25 + let contents = std::fs::read_to_string(filename).expect("Failed to read file"); 26 + let width = contents.lines().next().unwrap().len() as u16; 27 + let height = contents.lines().count() as u16; 28 + let layout = contents 29 + .lines() 30 + .map(|line| line.chars().map(|c| Some(c)).collect()) 31 + .collect(); 32 + Warehouse { 33 + layout, 34 + width, 35 + height, 36 + } 37 + } 38 + 39 + fn count_neighbors(&self, x: u16, y: u16) -> Option<u8> { 40 + //println!("Counting neighbors at ({}, {})", x, y); 41 + let mut neighbors = 0u8; 42 + for n_y in y.saturating_sub(1)..y.add(2).min(self.height) { 43 + for n_x in x.saturating_sub(1)..x.add(2).min(self.width) { 44 + if n_y == y && n_x == x { 45 + continue; 46 + } 47 + if let Some(cell) = self.get(n_x, n_y) 48 + && cell == '@' 49 + { 50 + neighbors += 1; 51 + //println!("Neighbor found at ({}, {})", n_x, n_y); 52 + } 53 + } 54 + } 55 + Some(neighbors) 56 + } 57 + } 58 + 59 + impl Display for Warehouse { 60 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 61 + for row in &self.layout { 62 + for cell in row { 63 + match cell { 64 + Some(c) => write!(f, "{}", c)?, 65 + None => write!(f, ".")?, 66 + } 67 + } 68 + writeln!(f)?; 69 + } 70 + Ok(()) 71 + } 72 + } 73 + 74 + fn main() { 75 + // let printer_department = Warehouse::new(10, 10); 76 + let mut printer_department = Warehouse::load_from_file("input.txt"); 77 + // println!("{}", printer_department); 78 + 79 + let mut removed_rolls = 0; 80 + 81 + loop { 82 + let mut to_remove = Vec::<(u16, u16)>::new(); 83 + for (y, row) in printer_department.layout.iter().enumerate() { 84 + for (x, cell) in row.iter().enumerate() { 85 + match *cell { 86 + Some(c) => { 87 + if c != '.' 88 + && printer_department 89 + .count_neighbors(x as u16, y as u16) 90 + .unwrap_or(0) 91 + < 4 92 + { 93 + removed_rolls += 1; 94 + to_remove.push((x as u16, y as u16)); 95 + // print!("x"); // used for debug printing each removal 96 + } // else { 97 + // print!("{}", c); 98 + // } 99 + } 100 + None => continue, 101 + } 102 + } 103 + // println!(); 104 + } 105 + if to_remove.is_empty() { 106 + break; 107 + } 108 + // println!("== REMOVING ROLLS {:?}==", to_remove); 109 + for (x, y) in to_remove { 110 + printer_department.set(x, y, '.'); 111 + } 112 + } 113 + 114 + println!("Removed {} rolls", removed_rolls); 115 + }
+3
day4/tinyinput.txt
···
··· 1 + ... 2 + @.. 3 + ...
+7
day5/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "day5" 7 + version = "0.1.0"
+6
day5/Cargo.toml
···
··· 1 + [package] 2 + name = "day5" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies]
+1185
day5/input.txt
···
··· 1 + 318557298670257-320203701512914 2 + 257988476988123-258475833446953 3 + 239506567904360-239506567904360 4 + 159092054628984-160660945293660 5 + 33508345158641-33508345158641 6 + 535574085704173-542529962005080 7 + 259223906521657-259570839796231 8 + 107124201554838-107491094003520 9 + 408597058494409-408747547856220 10 + 204209427005525-210465015733810 11 + 191953754819394-199391870677509 12 + 184436261451506-184436261451506 13 + 121406307434528-126395493108292 14 + 112658959754792-119541264499023 15 + 256813240979222-257191182675058 16 + 332175956014557-336020407709884 17 + 464523147874452-468780439477643 18 + 232531131562106-239506567904359 19 + 342509931670831-347620075555999 20 + 426811759586883-431461654697663 21 + 439839000198979-440189239373558 22 + 403011203089000-403697076743498 23 + 448512942059195-448512942059195 24 + 156253640950711-157569806110925 25 + 251421563132760-251960455619173 26 + 398112870005920-400840791809897 27 + 100861951548231-101340153826899 28 + 154107174125987-155481194818161 29 + 257508907299303-257988476988123 30 + 133819578135252-136632073039210 31 + 104123582918543-104968750841600 32 + 184436261451506-188838397899786 33 + 332175956014557-340193057113421 34 + 254024671218444-254634357935069 35 + 555045546718845-557458510312174 36 + 278691141343404-278691141343404 37 + 151929590097255-153526138046265 38 + 256473364658796-257191182675058 39 + 432725624020435-432878755961614 40 + 258475833446953-258979453820001 41 + 324480674674584-327468520768647 42 + 487189958128745-489305554786541 43 + 258979453820001-259831289698809 44 + 464523147874452-468780439477643 45 + 405767867802154-406067415024783 46 + 41990583601801-45061077205808 47 + 500015871759798-500015871759798 48 + 484225921380653-486412962957727 49 + 304651067123422-304651067123422 50 + 533800261321103-540022648064188 51 + 353441667704321-353441667704321 52 + 104720320730834-104968750841600 53 + 545451540103685-548272447332504 54 + 22510857723859-26201750452168 55 + 439221468648944-439663125751322 56 + 263863291192092-270528054033512 57 + 453663492579662-460441395413883 58 + 455916630823649-458470769974642 59 + 93136449552056-98438193496736 60 + 43712435074116-46464447665378 61 + 489934131675069-492491491966818 62 + 292404508349024-296435676901232 63 + 12962748711021-13823901556693 64 + 241803800777576-250990864955492 65 + 71822914111739-78486465652574 66 + 163803575271182-166282219654900 67 + 436699299130440-437488761705197 68 + 67507238039571-67507238039571 69 + 384827465833201-391267382570300 70 + 52055743565975-55947047405059 71 + 517137606542460-517137606542460 72 + 258979453820001-259223906521657 73 + 109853241964515-110281944446380 74 + 123969110556818-129491689424227 75 + 393237605153585-398112870005919 76 + 45648012942048-48477330342057 77 + 443498917180170-448512942059194 78 + 108952789514451-109374697239108 79 + 504971441861239-504971441861239 80 + 366232624101834-371307608545744 81 + 154982085035971-156473607942708 82 + 483019280373478-485101299769667 83 + 260280997104942-261021440671940 84 + 434608879046753-434867431942059 85 + 47310201589553-49775776386431 86 + 142608154408580-146569928719869 87 + 153114560792153-154512136243567 88 + 245367798580245-247168810924172 89 + 504971441861240-511410956949751 90 + 33508345158642-37939174347816 91 + 311802197883901-313755547382940 92 + 476973628350800-481046003972184 93 + 85759202464201-87521049292436 94 + 434867431942059-435311241226934 95 + 224522975501310-224522975501310 96 + 282114346191942-289655666294587 97 + 107885790509049-108121508855821 98 + 204209427005525-210465015733810 99 + 212499002598797-218187340159585 100 + 405221184201814-405439379897830 101 + 493351197287739-500015871759798 102 + 114619739021463-119541264499023 103 + 12962748711021-17106469220194 104 + 410321932966948-410982165765586 105 + 260830316716054-261021440671940 106 + 409721402028905-410443784092950 107 + 105256379383318-105846682600140 108 + 410982165765586-411805528013507 109 + 191953754819394-197190347597413 110 + 157270149376538-158550670988883 111 + 304651067123423-310936291175759 112 + 104123582918543-104720320730834 113 + 323018780170447-329497189774964 114 + 434433235635983-435101512206974 115 + 314203834990153-315840075340999 116 + 224522975501311-226793429167677 117 + 485618768430852-487757349964637 118 + 108121508855821-108421275256953 119 + 402147590496262-402749531321637 120 + 93136449552056-98438193496736 121 + 441516025477630-441765884040631 122 + 81756097147094-85759202464200 123 + 403011203089000-403255095687272 124 + 407308394808999-408016333429624 125 + 158238289669174-159526745133770 126 + 22510857723859-22510857723859 127 + 105846682600140-106350504957250 128 + 525441196122647-528918996348353 129 + 107885790509049-108690501438205 130 + 104440211495288-104968750841600 131 + 63333534417946-67507238039571 132 + 267153965444620-270528054033512 133 + 405221184201814-405767867802154 134 + 517137606542460-521347912586979 135 + 434608879046753-435311241226934 136 + 433237812973147-433671371547544 137 + 146569928719870-149188887351209 138 + 55947047405061-59976032237880 139 + 108121508855821-108690501438205 140 + 363612595643658-371307608545744 141 + 548272447332505-551641667068045 142 + 171554731176337-180000120537402 143 + 74843767516526-77443282419030 144 + 413575018409280-420283064631895 145 + 215569833149966-220896023627176 146 + 374813016022946-380261722247188 147 + 402486554628055-402749531321637 148 + 408169057383042-409078101518613 149 + 404158298035408-404556671934584 150 + 488382308253085-490741973787156 151 + 410982165765586-411610821931150 152 + 256813240979222-257508907299303 153 + 254634357935069-255128613491785 154 + 255455830262853-255938247246850 155 + 374074078491165-377840557038758 156 + 528918996348355-530678154811398 157 + 440189239373558-440776066495384 158 + 319714571007773-321580011400603 159 + 411225455317183-411610821931150 160 + 405767867802154-406467195289725 161 + 257045072669014-257508907299303 162 + 296435676901234-300584980642373 163 + 555045546718845-562272716856118 164 + 151037256328463-152500642805976 165 + 40350923346059-43259798070735 166 + 7440229440341-7440229440341 167 + 353441667704321-357960876749346 168 + 101340153826899-101946384557823 169 + 2462495594404-7440229440340 170 + 312971566505111-314502885242088 171 + 424918186431834-431461654697663 172 + 275605880658566-278691141343404 173 + 166282219654902-168490278557120 174 + 315118427614421-316857056324219 175 + 391267382570300-391267382570300 176 + 406467195289725-406951299052331 177 + 420283064631896-420283064631896 178 + 104440211495288-105256379383318 179 + 317420151400595-319056588984946 180 + 405767867802154-406211743772719 181 + 316186859747657-318108067962593 182 + 407697148019654-408016333429624 183 + 282114346191942-289655666294587 184 + 437638848326748-437927366592594 185 + 186 + 253932478508595 187 + 317582963230954 188 + 52471958022190 189 + 250038996042557 190 + 407647306380552 191 + 342908718962756 192 + 413491567332151 193 + 379997117088510 194 + 538613020352278 195 + 399757383918344 196 + 405038096802314 197 + 300695214422203 198 + 216181876788044 199 + 522949808781270 200 + 24818913426113 201 + 451245343252549 202 + 120936605178104 203 + 119225977950819 204 + 93756667144572 205 + 212522289958346 206 + 363030478585169 207 + 102943869121228 208 + 141383746132358 209 + 485098589371458 210 + 423605169820291 211 + 399571724916437 212 + 122103266649435 213 + 439933856544340 214 + 123232491737980 215 + 386902507853563 216 + 338526345678745 217 + 272054660050370 218 + 27163120082066 219 + 262100887771803 220 + 459125147671757 221 + 288142435637425 222 + 332621516817201 223 + 172352058716879 224 + 72888390063207 225 + 212577133870962 226 + 162039961144769 227 + 544114738186162 228 + 169917716821406 229 + 545976691900201 230 + 381027839444792 231 + 399346094526851 232 + 51452571464274 233 + 339492967942305 234 + 208700751850325 235 + 34392192248127 236 + 404293761980203 237 + 330923771592139 238 + 136646636964563 239 + 548463076200365 240 + 157059970693394 241 + 282334357432701 242 + 1528838032103 243 + 149466541269418 244 + 420167949355328 245 + 197780378463380 246 + 287716899103587 247 + 158299814240174 248 + 17706271042564 249 + 151545075631931 250 + 213421196000977 251 + 71091934458061 252 + 258257891179383 253 + 76368269869328 254 + 389922376471388 255 + 190305989100564 256 + 319165942994578 257 + 21712638935643 258 + 21369969450479 259 + 349847941411359 260 + 503155141347499 261 + 457866952000318 262 + 37220498343129 263 + 403402485553331 264 + 305127746186265 265 + 13086202816653 266 + 432549445576850 267 + 428376958454482 268 + 525741123167172 269 + 113809062419966 270 + 416012652956251 271 + 203863653821072 272 + 257626118528048 273 + 39452582293299 274 + 393826881841383 275 + 281988645512054 276 + 161985770723364 277 + 64495664268201 278 + 310521270760313 279 + 264810585746910 280 + 108201501928320 281 + 473679012087538 282 + 173611277562695 283 + 233452422089184 284 + 521643447141518 285 + 52203546222835 286 + 394273620214695 287 + 448317618384812 288 + 494020286451699 289 + 18283632248201 290 + 473488690246194 291 + 158007612662936 292 + 541579738254221 293 + 88523058114911 294 + 489442102634815 295 + 326075892117989 296 + 557503415225380 297 + 551333644654929 298 + 21341173530715 299 + 249247248950347 300 + 65088282953078 301 + 142036853724438 302 + 273852963291246 303 + 410894174796130 304 + 366223265825771 305 + 391648097150706 306 + 227333902164766 307 + 400158047527511 308 + 485985022520678 309 + 47051584231968 310 + 255401031745840 311 + 79953240988978 312 + 551602948015558 313 + 267677655213518 314 + 55399518342110 315 + 455139809691823 316 + 322710592711681 317 + 436653807644691 318 + 478466730577335 319 + 343528849394987 320 + 122922996843125 321 + 127787202595429 322 + 500634740355107 323 + 235887709752081 324 + 327524977801643 325 + 248074804330917 326 + 208555165549018 327 + 58269433835548 328 + 394875831539994 329 + 328133879628149 330 + 258560394203412 331 + 73177111398944 332 + 332839510077612 333 + 408180561832062 334 + 130996579891120 335 + 380249273434073 336 + 343596955276789 337 + 413207342559042 338 + 143639672906602 339 + 200623984262232 340 + 179858196762612 341 + 267075038894268 342 + 380559339960826 343 + 207413309253406 344 + 464787320228955 345 + 115721397705984 346 + 34298288585801 347 + 484988220573461 348 + 446530152861903 349 + 523792812528670 350 + 417139166950494 351 + 211307402997765 352 + 406074848380085 353 + 295385310215574 354 + 192275235985894 355 + 531383858466557 356 + 264684678613826 357 + 92022293872966 358 + 429926312316036 359 + 517498813591110 360 + 428212114018729 361 + 561213247612918 362 + 522276402789799 363 + 259294085888844 364 + 367699052950485 365 + 390564673305694 366 + 471317050152974 367 + 93316734659549 368 + 393151393310090 369 + 240666668958735 370 + 345653805060190 371 + 325638472489480 372 + 346654523838066 373 + 54686108449989 374 + 29155337759355 375 + 462836132954649 376 + 339780861771704 377 + 48500514026498 378 + 182797093164354 379 + 429292019403435 380 + 454596784810224 381 + 404018705076883 382 + 237757044164680 383 + 139689401098042 384 + 90968392783363 385 + 322869483223650 386 + 292697678317882 387 + 160820364301252 388 + 524720609467074 389 + 49905318442482 390 + 476246770935825 391 + 494590242000267 392 + 543633171313563 393 + 416671176005950 394 + 15403363482040 395 + 445794572549205 396 + 113058484851727 397 + 167615949117600 398 + 486260543039851 399 + 450906359902314 400 + 520711637158078 401 + 51544960106321 402 + 258925435692659 403 + 200422989339272 404 + 331983738354694 405 + 504818287102847 406 + 259510897676599 407 + 65814270253958 408 + 487418808576010 409 + 307106738621600 410 + 314460589917270 411 + 474134202235420 412 + 399195025145944 413 + 281892816079820 414 + 180368722772451 415 + 282919208033775 416 + 309999159113467 417 + 396343546481930 418 + 8088912526534 419 + 81581030914716 420 + 60656204624474 421 + 176793388030887 422 + 455355745732776 423 + 233474166981484 424 + 372235773145736 425 + 118721760260192 426 + 53465826735240 427 + 435914801985371 428 + 61784445226062 429 + 161376445553953 430 + 183176424781241 431 + 311891033216879 432 + 78600789847978 433 + 528586933001160 434 + 203731397091407 435 + 131023302037537 436 + 162027341674939 437 + 456466136631601 438 + 284971054733535 439 + 560784053514275 440 + 128097407659848 441 + 326604671648835 442 + 552734578834712 443 + 227103050727334 444 + 432313281079465 445 + 561118220776172 446 + 515136355413419 447 + 225648239004611 448 + 96537046708460 449 + 64175761910723 450 + 427014095840641 451 + 299221088111105 452 + 325275854387412 453 + 332277430003557 454 + 219941702530241 455 + 265762132793619 456 + 467474259284078 457 + 548402522909022 458 + 113313326412104 459 + 351850762644854 460 + 415687153656172 461 + 154887249574064 462 + 80021499372120 463 + 508811223466176 464 + 174741997631677 465 + 488129889355668 466 + 384630558851716 467 + 317931718701723 468 + 254701072231501 469 + 357634696003184 470 + 156102283610764 471 + 242634477832383 472 + 276868380019300 473 + 471026864126240 474 + 205231706541251 475 + 486813007180662 476 + 269547577906026 477 + 362646679209105 478 + 483896776199671 479 + 150262698467317 480 + 230137375291516 481 + 444843664813148 482 + 145845670118554 483 + 401310375527225 484 + 339496180513682 485 + 495554091562556 486 + 440704972869073 487 + 163545534256593 488 + 496166048892866 489 + 438183532682010 490 + 82658105846369 491 + 333436973296592 492 + 15905005718940 493 + 380902300969305 494 + 431014053591305 495 + 270159289532956 496 + 300156539754786 497 + 284844920645908 498 + 197279843274989 499 + 179917081542839 500 + 559853732623767 501 + 540837344631004 502 + 12387978191133 503 + 21529631517041 504 + 427065774294569 505 + 148117196022748 506 + 508260565373413 507 + 375124315647621 508 + 68297661058779 509 + 217335217689508 510 + 249213600029904 511 + 325972363325921 512 + 350496903642645 513 + 463720864447496 514 + 349859468762092 515 + 313646811357853 516 + 406522442853403 517 + 507358368658917 518 + 299992908310413 519 + 55665568186093 520 + 16298915818136 521 + 275024837194107 522 + 71220993643373 523 + 321258438507095 524 + 101404914197112 525 + 463829180460562 526 + 19596270793450 527 + 419467744477641 528 + 367500840637610 529 + 109925235359841 530 + 29875247829500 531 + 200430360596060 532 + 249929282959231 533 + 171683296593433 534 + 249548562946130 535 + 293195096186756 536 + 162561929448143 537 + 22673662418162 538 + 438121934144793 539 + 106977936189179 540 + 422760684729986 541 + 450416659472110 542 + 545292692811594 543 + 427951610819977 544 + 483348276350127 545 + 108476622593143 546 + 141732182795544 547 + 305825177249304 548 + 541359277664585 549 + 291176827644393 550 + 69889245406164 551 + 185693283288783 552 + 222512186681104 553 + 218210130487616 554 + 501638545606091 555 + 2525568478926 556 + 148462337654502 557 + 226928142531503 558 + 98314997654931 559 + 530009592210782 560 + 435607601328184 561 + 466613903279462 562 + 245560000481580 563 + 140005956862947 564 + 93200012974495 565 + 104828070477292 566 + 270403058067215 567 + 3074786542026 568 + 81889304247313 569 + 101839346932631 570 + 521609718325654 571 + 548914839820183 572 + 480443408141661 573 + 528378449211382 574 + 194666780109334 575 + 528733903062244 576 + 96283611150697 577 + 446196422857499 578 + 359515510794553 579 + 40698352053019 580 + 175433087782045 581 + 214153593365764 582 + 321617507797814 583 + 541209180653480 584 + 413586507783936 585 + 371101462718581 586 + 469320335849368 587 + 113476602083598 588 + 153826199210990 589 + 149370793914426 590 + 44726664019104 591 + 497388741106419 592 + 49836179831550 593 + 126150336008965 594 + 188831489515857 595 + 451065153918529 596 + 480720330113732 597 + 464834558089319 598 + 208028429154334 599 + 77807204251261 600 + 50507451474499 601 + 53090473516133 602 + 42046513731740 603 + 472624254206858 604 + 503273421605004 605 + 200257371366627 606 + 257603662649025 607 + 117255601530787 608 + 297398079033621 609 + 326658848122114 610 + 487656522071304 611 + 551571538026462 612 + 213291587539462 613 + 418073966540833 614 + 115008266278175 615 + 505994103928125 616 + 527027589220682 617 + 508682738492780 618 + 301306415740377 619 + 279448837572342 620 + 245984408933922 621 + 285576915825001 622 + 220011144636709 623 + 550080239994596 624 + 116530350808545 625 + 166859266923516 626 + 461057104544242 627 + 171888343821730 628 + 29187829095763 629 + 206181405390433 630 + 360623065107172 631 + 233333971340132 632 + 238442238972824 633 + 28726790025007 634 + 508127426181859 635 + 133721097706499 636 + 54494061917734 637 + 521726709168763 638 + 376469304674263 639 + 483389589112456 640 + 355858251341210 641 + 429082118235359 642 + 440585177860173 643 + 355363538073330 644 + 232912201983176 645 + 560791464394793 646 + 37352757846155 647 + 421993085459534 648 + 242337035493668 649 + 20154860178782 650 + 131121298048311 651 + 205750065790128 652 + 62397940525695 653 + 532746253342683 654 + 468697161390839 655 + 97216214195907 656 + 52480317186951 657 + 491550370230602 658 + 361720930042219 659 + 99349860712326 660 + 182550076818466 661 + 248350221902725 662 + 180044693564332 663 + 219634680396051 664 + 371745678330162 665 + 429207995675157 666 + 79956420464383 667 + 220074403286938 668 + 122413916966381 669 + 217035618862249 670 + 101957929020393 671 + 368603901727588 672 + 535106259484673 673 + 368248728555169 674 + 455288034767614 675 + 157651037780741 676 + 477789664005485 677 + 381569545929046 678 + 448704798867135 679 + 253936059302686 680 + 277852827457461 681 + 509822915912206 682 + 123298746062901 683 + 344712343879804 684 + 478228093941569 685 + 9160348922678 686 + 529512490213927 687 + 56664936531787 688 + 33371486733596 689 + 323403280367371 690 + 403176442371370 691 + 86551517359334 692 + 34542761713742 693 + 131909592739112 694 + 229059689821133 695 + 397949984495095 696 + 350933216967145 697 + 60206646204804 698 + 418862123978140 699 + 152224161873623 700 + 470223521227437 701 + 138718704217033 702 + 122445937059673 703 + 329166625172646 704 + 445036354270330 705 + 94626353792047 706 + 386267834368894 707 + 167481058545048 708 + 250726976430298 709 + 328133827905108 710 + 460947073371709 711 + 239523303447832 712 + 268888169951704 713 + 225475969121729 714 + 537353577963372 715 + 547884259391883 716 + 210287450374244 717 + 484708677043034 718 + 324582756800218 719 + 488966309063557 720 + 362507202892588 721 + 313827291888214 722 + 425531258995075 723 + 8365432176181 724 + 464371050309571 725 + 427201590954297 726 + 268438381215193 727 + 227134776194744 728 + 12703022490514 729 + 529664446932252 730 + 117717389036717 731 + 126461703662404 732 + 210634147213341 733 + 532692643802953 734 + 113387869297222 735 + 354267368619846 736 + 291522555013297 737 + 550784047423763 738 + 87666840869227 739 + 411265706065271 740 + 35557698406498 741 + 286862173679123 742 + 35026256151068 743 + 100517399777238 744 + 150514811486409 745 + 473877588988298 746 + 40601247825393 747 + 514234957155861 748 + 281959625133199 749 + 288913140992968 750 + 154394513861065 751 + 186153722525037 752 + 279877412079207 753 + 277398150742413 754 + 209007848765395 755 + 417294148854056 756 + 356892889005701 757 + 76458880967028 758 + 503680815294858 759 + 477564187435117 760 + 318452187158338 761 + 195765024602408 762 + 138908187602004 763 + 466920937021984 764 + 486966182085911 765 + 48198196466432 766 + 531211831670028 767 + 393448585643725 768 + 559676653708482 769 + 159339271489214 770 + 313679416308261 771 + 531268115683535 772 + 535373053893382 773 + 543119538694763 774 + 194763470623674 775 + 435866212816353 776 + 183531074418132 777 + 297070152396296 778 + 60754000754876 779 + 555736186219624 780 + 166454071242990 781 + 203167923001876 782 + 557247368952147 783 + 200936825312484 784 + 340954709824320 785 + 373909666253526 786 + 266627467038837 787 + 346403578473335 788 + 66357690547789 789 + 495394997476733 790 + 358295907558196 791 + 548148053117400 792 + 386746311611340 793 + 299036823141682 794 + 325123753963551 795 + 294503877685009 796 + 486633379980972 797 + 1159612908559 798 + 333283675675631 799 + 75540243934769 800 + 213364985313122 801 + 5176156027629 802 + 422625975392713 803 + 316654480521149 804 + 430108985375376 805 + 472481233972128 806 + 326432768644360 807 + 240317688610141 808 + 443110882589595 809 + 164808840066936 810 + 45844367165449 811 + 56474500365305 812 + 458187762357811 813 + 364920068153011 814 + 504818169476379 815 + 95830680125331 816 + 55454860867730 817 + 526944773934958 818 + 333365909881138 819 + 468179645615350 820 + 338678529582984 821 + 493543720705733 822 + 545075293933663 823 + 215458757495907 824 + 329099085994127 825 + 48399063869652 826 + 34570669290290 827 + 219737157952563 828 + 217638086794194 829 + 73316487656634 830 + 234291058225143 831 + 423709741004940 832 + 550037083627142 833 + 7496497162163 834 + 535915266907493 835 + 409139244148443 836 + 410318017315601 837 + 296531909569991 838 + 27966871451838 839 + 205407218081768 840 + 220546188319572 841 + 370540148920139 842 + 323246113532973 843 + 349774483715030 844 + 297797163520553 845 + 80019757856447 846 + 117556310380943 847 + 328856536634050 848 + 555482280861581 849 + 450085725968659 850 + 454996844432936 851 + 74028997870862 852 + 473030773795171 853 + 373993631403962 854 + 215097882195098 855 + 386464105601899 856 + 502446517362725 857 + 363643213424338 858 + 386624326994388 859 + 190386810165339 860 + 209293543489729 861 + 353989177711741 862 + 29314555948420 863 + 394467572817249 864 + 40815459613043 865 + 60520405536443 866 + 343229790624275 867 + 232932213736127 868 + 315386219357987 869 + 345145798582480 870 + 48700928026469 871 + 543433102531486 872 + 137597147745150 873 + 196530576025351 874 + 491450841504140 875 + 399892449184217 876 + 321727065638239 877 + 401349427244773 878 + 224669708107653 879 + 279794356629597 880 + 247271094031845 881 + 361165500393950 882 + 234706639582531 883 + 90589333822122 884 + 506297852219039 885 + 323089929828482 886 + 293285771379189 887 + 76032857066728 888 + 136418227841690 889 + 224723573692472 890 + 141176336098743 891 + 238996649540047 892 + 338484119818263 893 + 323651468265407 894 + 52440011613420 895 + 489649806474095 896 + 214096496512921 897 + 345608877840855 898 + 505852782569407 899 + 456797842351556 900 + 317262926729138 901 + 4812517567062 902 + 270526787757620 903 + 408744981864565 904 + 164376729116018 905 + 275466227955051 906 + 209812622334707 907 + 491912438907119 908 + 109135485277775 909 + 123817034126823 910 + 399621571958563 911 + 520782514293756 912 + 254790342984468 913 + 111191529969102 914 + 467846701757082 915 + 132568258809928 916 + 386018804359988 917 + 507453013344478 918 + 278213485818594 919 + 110634765893177 920 + 305389830829258 921 + 142623347325635 922 + 178424936763061 923 + 267048906087097 924 + 227702719785542 925 + 460446577932815 926 + 520556496727220 927 + 46558047132292 928 + 146245545319069 929 + 65059118876957 930 + 332073694080391 931 + 8490135782184 932 + 384869246226665 933 + 349398784804407 934 + 488385303299432 935 + 329051639637505 936 + 187606879676981 937 + 163192301633269 938 + 429795491317419 939 + 490345555611422 940 + 173329302853208 941 + 142696593335928 942 + 379137255646752 943 + 159691758724257 944 + 313784011957110 945 + 130734926154346 946 + 558851024588212 947 + 267981781421281 948 + 351486746081409 949 + 471758132882562 950 + 130862877857712 951 + 316340368984521 952 + 472850369691085 953 + 165921646822514 954 + 7799816696727 955 + 530771265369328 956 + 267699330969556 957 + 155374461884050 958 + 145755132656173 959 + 553205668555979 960 + 561887815928521 961 + 335307215170989 962 + 312343773202694 963 + 524019355662679 964 + 365298549007777 965 + 321456419423876 966 + 146114310544980 967 + 273658943663396 968 + 305821110737857 969 + 174909988516754 970 + 135346474789749 971 + 264315450682530 972 + 481042453064618 973 + 54482385564562 974 + 89069366196314 975 + 269866128980247 976 + 461392839843788 977 + 118168659109710 978 + 392321270226785 979 + 148610531060055 980 + 294721723418072 981 + 234023718068868 982 + 46854837045053 983 + 489220500885653 984 + 446694192053962 985 + 381751756747609 986 + 234357555200021 987 + 531333474031029 988 + 492968154029377 989 + 536895039917821 990 + 358364676389755 991 + 313438131600508 992 + 30637256850977 993 + 460765654454012 994 + 74639656582961 995 + 75168850814906 996 + 480998212459385 997 + 338811499679797 998 + 351852267302818 999 + 387461514893971 1000 + 445342206719102 1001 + 311493688949119 1002 + 16760939544533 1003 + 80452459666232 1004 + 251529209731900 1005 + 109563959893472 1006 + 364485695995460 1007 + 338433003074373 1008 + 481501171329015 1009 + 319908888007719 1010 + 444691854946578 1011 + 321051105717536 1012 + 363264651632270 1013 + 480105834229108 1014 + 549107309178185 1015 + 549350518733577 1016 + 246845637696919 1017 + 58792957427917 1018 + 455205390859491 1019 + 346412492888322 1020 + 546725672007298 1021 + 485923395990339 1022 + 300894170428425 1023 + 373593379990704 1024 + 402347366077188 1025 + 44814225117018 1026 + 104060982495793 1027 + 540262302756503 1028 + 127996787469771 1029 + 32949868714313 1030 + 475084966587295 1031 + 103746308133941 1032 + 483732894508545 1033 + 212771491727568 1034 + 245745392475903 1035 + 101352906680274 1036 + 49261610546338 1037 + 557524604502825 1038 + 527007425566087 1039 + 370163984571210 1040 + 12254796754483 1041 + 101015362618722 1042 + 145212094981350 1043 + 43811851164691 1044 + 52750783207820 1045 + 269019865485451 1046 + 521808469681334 1047 + 145548546704607 1048 + 226908396439927 1049 + 208803477280480 1050 + 217133827631508 1051 + 219333762768287 1052 + 134923934026150 1053 + 417211011488863 1054 + 133765771506733 1055 + 168864905384834 1056 + 546955855743600 1057 + 465636893417656 1058 + 148100829291517 1059 + 237580312568967 1060 + 54334569354264 1061 + 443198973951184 1062 + 52087769049814 1063 + 267888871288082 1064 + 309108664269838 1065 + 212145387074971 1066 + 38695796784987 1067 + 72479582878332 1068 + 124459514549606 1069 + 98645605066114 1070 + 557158569872293 1071 + 377032312301138 1072 + 28572692989147 1073 + 127264939223211 1074 + 351760092872137 1075 + 175415741133810 1076 + 198922329116395 1077 + 115637252062171 1078 + 330546638821109 1079 + 49489721767485 1080 + 233483728598901 1081 + 372412841125723 1082 + 49869453791421 1083 + 230458425128604 1084 + 378330903771993 1085 + 195016335758222 1086 + 353649149980192 1087 + 264336950295167 1088 + 4675008244642 1089 + 244838066533953 1090 + 86380915635612 1091 + 373321323889030 1092 + 257018302696040 1093 + 317729975152833 1094 + 162821630418079 1095 + 51124731456710 1096 + 17521048328646 1097 + 244485151006487 1098 + 411459747565108 1099 + 505368276403700 1100 + 457152675626419 1101 + 115973709823526 1102 + 64997326037847 1103 + 384913615852591 1104 + 252777693200950 1105 + 102471307236593 1106 + 248246908607238 1107 + 399532688766128 1108 + 202742767493523 1109 + 25985180392431 1110 + 15749343373589 1111 + 43206582894726 1112 + 83039920783268 1113 + 245491426920792 1114 + 79547799536865 1115 + 336525939206498 1116 + 470302075672304 1117 + 98289916731124 1118 + 493081434330905 1119 + 227129571564834 1120 + 43382248228452 1121 + 41383720878603 1122 + 409015203991873 1123 + 379138448601500 1124 + 265770637863690 1125 + 369882766021769 1126 + 236749388970477 1127 + 13714547496397 1128 + 106916998510513 1129 + 146212494638758 1130 + 395355332494797 1131 + 510383682272307 1132 + 312867660111995 1133 + 491045869854993 1134 + 432346805589946 1135 + 142507900477620 1136 + 459437667431071 1137 + 475326095967763 1138 + 358780261354781 1139 + 495768093822832 1140 + 553783723287429 1141 + 238988372735656 1142 + 428037435579619 1143 + 555676629939986 1144 + 6569416135160 1145 + 40339825458446 1146 + 6805352333031 1147 + 406102882050559 1148 + 383675706554757 1149 + 469276503152653 1150 + 424244960992367 1151 + 430855515778841 1152 + 463510003020650 1153 + 507037663031647 1154 + 282964152294489 1155 + 43211162095545 1156 + 17596796127023 1157 + 431526400730170 1158 + 34221921264101 1159 + 230590892573244 1160 + 420660224485607 1161 + 431757341706063 1162 + 46679168937024 1163 + 423935002386417 1164 + 330890302847103 1165 + 148504854235777 1166 + 61089854104959 1167 + 464350750612206 1168 + 505291047655938 1169 + 292927188450580 1170 + 393259565407806 1171 + 205867651807804 1172 + 106082860951994 1173 + 422291641499795 1174 + 283552442624759 1175 + 385952211585238 1176 + 196296595800486 1177 + 510284000293178 1178 + 286504876483372 1179 + 221070050936993 1180 + 119713580986365 1181 + 546209693398181 1182 + 278008535048920 1183 + 552156651060434 1184 + 195803904631463 1185 + 364818531904503
+11
day5/smallinput.txt
···
··· 1 + 3-5 2 + 10-14 3 + 16-20 4 + 12-18 5 + 6 + 1 7 + 5 8 + 8 9 + 11 10 + 17 11 + 32
+201
day5/src/main.rs
···
··· 1 + use std::cmp::Ordering; 2 + use std::fmt::Debug; 3 + use std::{cmp, fs}; 4 + 5 + #[derive(Debug)] 6 + struct Ingredient { 7 + id: u64, 8 + } 9 + 10 + // Describes a range of ingredient ids 11 + struct IngredientRange { 12 + start: Ingredient, 13 + end: Ingredient, 14 + } 15 + 16 + // Used to store and manage IngredientRanges 17 + struct IngredientDB { 18 + ranges: Vec<IngredientRange>, 19 + } 20 + 21 + // #[derive(Debug, Clone, Copy, Eq)] 22 + // don't think i need to do this deriving stuff 23 + // i find it a bit scary tbh 24 + enum RangeCap { 25 + Start(u64), 26 + End(u64), 27 + } 28 + 29 + // If both elements have the same type and value, they are equal 30 + impl cmp::PartialEq for RangeCap { 31 + fn eq(&self, other: &Self) -> bool { 32 + match (self, other) { 33 + (RangeCap::Start(a), RangeCap::Start(b)) => a == b, 34 + (RangeCap::End(a), RangeCap::End(b)) => a == b, 35 + _ => false, 36 + } 37 + } 38 + } 39 + 40 + // Implementing an ordering for these Range Caps (better name? terminal?) 41 + impl cmp::PartialOrd for RangeCap { 42 + fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { 43 + match (self, other) { 44 + // if both values are Starts or both are Ends, compare values normally 45 + (RangeCap::Start(a), RangeCap::Start(b)) => a.partial_cmp(b), 46 + (RangeCap::End(a), RangeCap::End(b)) => a.partial_cmp(b), 47 + // If they are equal, make sure Starts always go before Ends 48 + (RangeCap::Start(a), RangeCap::End(b)) => { 49 + let result = a.partial_cmp(b); 50 + if result == Some(Ordering::Equal) { 51 + Some(Ordering::Less) 52 + } else { 53 + result 54 + } 55 + } 56 + (RangeCap::End(a), RangeCap::Start(b)) => { 57 + let result = a.partial_cmp(b); 58 + if result == Some(Ordering::Equal) { 59 + Some(Ordering::Greater) 60 + } else { 61 + result 62 + } 63 + } 64 + } 65 + } 66 + } 67 + 68 + impl IngredientDB { 69 + // Initializing an IngredientDB is basically parsing an input string and initializing the ranges vector. 70 + fn new(range_list: &str) -> IngredientDB { 71 + let mut ranges = Vec::new(); 72 + for l in range_list.lines() { 73 + let splitline = l.split('-').collect::<Vec<&str>>(); 74 + ranges.push(IngredientRange { 75 + start: Ingredient { 76 + id: splitline[0].parse().expect("Failed to parse ingredient ID"), 77 + }, 78 + end: Ingredient { 79 + id: splitline[1].parse().expect("Failed to parse ingredient ID"), 80 + }, 81 + }); 82 + } 83 + IngredientDB { ranges } 84 + } 85 + 86 + // We can check if an ingredient is fresh by comparing it to our ranges and seeing if it falls within any of them. 87 + fn is_fresh(&self, ingredient: Ingredient) -> bool { 88 + self.ranges 89 + .iter() 90 + .any(|range| range.start.id <= ingredient.id && ingredient.id <= range.end.id) 91 + } 92 + 93 + // This function is called clean_ranges_stack bc i initially tried to do something else and it was a nightmare 94 + // Basically we initialize a list of RangeCaps, then sort them by value 95 + // Then we go through and push to the stack when we find a Start, pop when we find an End 96 + // If the end we find leaves our stack empty, we push a new range to our ranges vector 97 + // Finally, we replace the internal ranges of this IngredientDB with our new, optimized ranges. 98 + fn clean_ranges_stack(&mut self) { 99 + let mut range_list = Vec::<RangeCap>::new(); 100 + for range in &self.ranges { 101 + range_list.push(RangeCap::Start(range.start.id)); 102 + range_list.push(RangeCap::End(range.end.id)); 103 + } 104 + // Sort range list by Partial Ordering 105 + // this shouldn't fail or something's wrong 106 + range_list.sort_by(|a, b| { 107 + a.partial_cmp(b) 108 + .expect("RangeCaps should be able to be compared") 109 + }); 110 + 111 + // initialize our stack and output range vectors 112 + let mut range_stack = Vec::<u64>::new(); 113 + let mut new_ranges = Vec::<IngredientRange>::new(); 114 + 115 + for range in &range_list { 116 + match *range { 117 + // always push Starts to the stack 118 + RangeCap::Start(id) => range_stack.push(id), 119 + RangeCap::End(id) => { 120 + // if stack has more than 1 element, pop the top and discard 121 + // otherwise construct an IngredientRange with the final element and push it to the new_ranges vector 122 + if range_stack.len() > 1 { 123 + range_stack.pop(); 124 + } else { 125 + new_ranges.push(IngredientRange { 126 + start: Ingredient { 127 + id: range_stack.pop().unwrap(), 128 + }, 129 + end: Ingredient { id }, 130 + }); 131 + } 132 + } 133 + } 134 + } 135 + 136 + self.ranges = new_ranges; 137 + } 138 + 139 + // Simple math function that subtracts ends of all the ranges from the starts and adds 1 to be **inclusive** 140 + fn count_fresh(&self) -> u64 { 141 + let mut fresh_count = 0u64; 142 + for range in &self.ranges { 143 + fresh_count += range.end.id.saturating_sub(range.start.id) + 1; 144 + } 145 + fresh_count 146 + } 147 + } 148 + 149 + impl Debug for IngredientRange { 150 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 151 + write!( 152 + f, 153 + "IngredientRange {{ \n\t[{}-{}] of length {}\n }}", 154 + self.start.id, 155 + self.end.id, 156 + self.end.id.saturating_sub(self.start.id) + 1 157 + ) 158 + } 159 + } 160 + 161 + impl Debug for IngredientDB { 162 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 163 + write!(f, "IngredientDB {{ ranges: {:?} }}", self.ranges) 164 + } 165 + } 166 + 167 + fn main() { 168 + let in_file = fs::read_to_string("input.txt").expect("Failed to read file"); 169 + 170 + // Split our input file into two parts based on newlines and make sure there are exactly 2 parts 171 + let file_sections = in_file.split("\n\n").collect::<Vec<&str>>(); 172 + assert!(file_sections.len() == 2); 173 + 174 + // Parse first part of the file and initialize an IngredientDB 175 + let mut ingredient_db = IngredientDB::new(file_sections[0]); 176 + 177 + // before range cleanup 178 + // println!("Ingredient Database: {:?}", ingredient_db); 179 + // cleaning our ranges up here gives us better performance for the first part! since there are less ranges to check in. 180 + ingredient_db.clean_ranges_stack(); 181 + // after range cleanup 182 + // println!("Ingredient Database: {:?}", ingredient_db); 183 + 184 + // to get our first star, we check each ingredient in the second section against our initialized DB and increment fresh_count 185 + let mut fresh_count = 0u64; 186 + for test_ingredient in file_sections[1].lines() { 187 + if ingredient_db.is_fresh(Ingredient { 188 + id: test_ingredient 189 + .parse() 190 + .expect("Failed to parse ingredient ID"), 191 + }) { 192 + fresh_count += 1; 193 + } 194 + } 195 + 196 + println!("Fresh Ingredients in Pantry: {}", fresh_count); 197 + println!( 198 + "Fresh Ingredients in Database: {}", 199 + ingredient_db.count_fresh() 200 + ); 201 + }
+11
day5/testinput.txt
···
··· 1 + 1-4 2 + 4-6 3 + 6-100 4 + 10-50 5 + 6 + 1 7 + 5 8 + 8 9 + 11 10 + 17 11 + 32
+7
day6/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "day6" 7 + version = "0.1.0"
+6
day6/Cargo.toml
···
··· 1 + [package] 2 + name = "day6" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies]
+5
day6/input.txt
···
··· 1 + 966 185 147 2533 13 79 2119 55 68 63 18 114 39 89 15 1871 869 3 66 4 92 544 387 8 2 555 986 579 42 682 5648 39 625 525 95 48 42 37 42 27 97 19 97 74 279 9373 77 46 412 4 6 5 564 7564 654 23 22 747 188 952 94 28 87 5 2 195 375 7 24 782 359 373 4829 2 34 69 8 25 5 12 84 2 22 2 81 88 83 7 73 6 31 52 85 56 94 72 78 835 5 4 47 967 115 819 92 93 88 7 25 8 83 31 396 752 7958 21 84 7 4 632 4 68 2 57 894 71 1739 22 55 826 9 8 38 74 61 424 943 14 94 55 922 69 41 2523 18 8 28 4 13 6 1 1246 54 411 4296 96 2 72 2822 7379 172 18 23 8 93 578 958 4722 1 8 4 9 987 76 3476 4 336 6 9645 299 53 852 1 111 75 52 61 9 92 93 943 68 31 8455 93 748 96 75 1 7 83 987 3 633 54 8 7111 54 818 64 25 19 4 17 85 88 5 25 6 9215 44 1 6 2 79 133 345 268 71 769 226 281 5217 1319 5 29 75 261 43 8 562 489 95 4 386 11 655 79 913 747 75 61 622 348 9 643 64 87 9466 919 59 93 695 2 49 18 217 94 34 64 9 2 18 7891 956 4 939 8 88 591 68 9 365 6 3 9536 73 384 762 546 789 429 35 29 538 585 828 3927 87 316 76 21 533 5925 917 24 91 22 468 7 4 4 1 27 51 4998 8512 482 773 17 44 25 434 79 58 71 3 1 75 713 968 6426 31 1 8 9 364 4273 51 619 7 62 2 387 83 8 774 3424 7 26 22 37 89 92 873 378 747 3776 32 965 39 9 91 97 26 295 749 13 9 892 41 871 94 5 1 715 3893 667 364 571 22 526 137 33 7922 9 988 91 39 7 698 83 99 22 872 2 1 468 469 45 8 98 6996 42 923 261 338 46 41 15 64 7 936 31 9 933 85 49 287 121 5 1 56 5 2914 2 43 831 22 65 862 869 14 6318 17 38 42 26 52 55 548 94 47 9 5 2 29 26 178 63 1 477 92 9557 98 841 8 66 142 83 57 74 6 2 346 242 495 92 6 42 376 6859 31 8 9142 35 262 714 71 51 551 82 8 8271 682 414 82 37 75 6 99 799 728 52 32 76 8 22 9 334 2 765 5462 73 4 31 835 7 22 58 51 569 272 181 8 72 64 976 649 41 945 7 14 934 11 7 8 38 556 649 56 25 7 817 9823 93 55 54 95 8487 77 6 221 9426 67 2 6 96 57 4 139 86 2 9 934 419 49 44 8 26 527 763 6556 826 58 49 3 8 91 51 562 9 834 589 2 99 8 7 66 918 13 667 48 53 7 8692 38 7955 996 73 76 91 67 951 14 83 293 97 68 11 718 81 69 54 79 93 81 186 92 8 644 616 7 53 22 6552 775 93 6 342 84 654 39 23 989 393 45 922 7699 34 683 8853 718 64 471 32 46 375 29 27 31 6985 526 716 85 1166 82 49 26 26 418 586 49 68 6 36 2286 723 85 5 5781 83 961 82 14 476 36 61 693 33 2 78 81 71 158 16 366 7 73 13 53 934 26 24 1 147 2 5 59 4 886 96 99 13 1971 14 35 896 7 582 1 461 72 42 2 23 1755 79 76 681 561 34 43 1 5 48 115 162 339 58 22 5 36 699 96 912 291 319 867 129 9 4136 89 24 44 29 3198 23 1733 635 8361 21 763 92 2 8 7 21 48 74 275 79 68 543 718 497 826 224 9 381 16 345 75 7134 95 4489 52 62 26 1 22 68 77 5637 38 5533 1 825 83 159 42 85 3 479 5 8 5339 4 719 945 49 81 9339 229 35 578 8683 4 3 47 1119 486 819 7 959 4956 7 282 32 15 257 372 967 2 125 258 63 168 593 14 49 6 8 847 131 3715 5 3 9274 94 78 66 795 56 46 7 29 138 6 786 38 23 3 99 64 981 537 246 44 3 1 252 2 7763 83 857 49 65 4 84 49 6 57 328 141 49 38 446 5 76 32 1796 56 16 22 9227 73 215 17 883 226 122 9 85 47 9316 254 359 99 32 2 59 5 8 278 51 57 3 22 855 958 45 11 7576 82 88 18 316 277 73 6 984 779 84 1 1 534 1823 5465 6 74 36 99 1 632 7 7693 54 69 4189 36 77 517 41 34 55 772 982 38 5191 27 298 48 235 44 2 35 6954 6 9 82 43 42 4 42 934 97 35 195 946 678 7 8 669 5764 4 72 91 22 5 123 9 4 6 4 795 568 73 78 79 71 1845 69 1 918 75 9 13 944 26 58 545 15 71 2 26 7 77 79 777 2 + 513 247 496 9374 65 12 5266 38 32 56 2485 825 73 19 328 1643 728 4 871 72 79 791 796 8 961 515 341 831 49 229 115 25 385 998 142 67 49 28 21 42 23 21 14 72 427 2237 97 11 441 37 12 48 131 9866 456 44 7287 649 138 251 78 81 18 6 27 392 981 38 44 918 514 646 7211 2 95 91 1 448 37 27 81 5 58 618 472 53 97 6 74 23 44 584 14 59 69 89 13 628 72 92 93 249 955 324 42 56 58 1 29 88 13 68 8491 36 7758 22 87 23 86 778 1 75 65 57 716 27 9135 75 21 915 7 568 77 87 73 154 989 58 257 414 631 75 77 7689 12 78 963 12 52 2 54 5312 952 399 5225 529 178 69 6495 632 919 6732 43 1 931 555 193 9596 57 8 67 1 248 16 1575 57 133 2 4976 435 1265 811 3 483 89 28 396 673 458 57 156 84 46 865 48 535 227 95 8 75 18 788 8 536 76 1 9752 96 816 68 15 59 839 51 95 37 19 647 34 6911 44 9 3 1 5 575 664 311 975 281 621 866 9624 9617 119 48 11 697 17 31 168 967 23 36 723 38 826 48 788 222 249 869 238 28 8 33 88 21 8312 79 751 22 119 43 62 36 7993 52 52 26 9 2 12 2392 252 73 489 88 31 628 285 22 198 3 86 226 5 979 241 222 392 422 58 37 599 779 988 7848 48 849 61 71 617 2139 5183 182 78 14 1312 572 594 739 55 333 15 1915 1754 677 793 74 91 938 681 17 49 54 47 41 8 552 74 6326 23 3 129 3 813 6485 22 47 22 22 6 239 13 535 297 2695 392 37 52 26 42 17 731 138 411 2614 733 6867 21 37 21 1 512 876 777 43 6 139 73 425 96 8 239 283 1659 511 527 776 575 546 299 46 922 9 978 68 32 36 382 656 26 32 665 19 63 8817 721 58 341 34 617 24 779 717 765 72 81 227 53 99 4512 59 38 698 793 995 688 547 17 9 54 595 8742 36 59 766 94 43 814 68 48 1539 361 382 62 68 34 66 35 13 61 9 8 813 346 18 735 74 155 718 44 4492 71 36 817 861 416 2 572 7 1 8 266 734 682 55 49 82 883 2638 19 76 1743 43 556 517 56 124 739 89 29 344 7699 763 351 41 16 245 715 491 974 21 849 73 94 44 3 579 588 36 5199 88 8 69 624 97 18 43 656 169 737 9667 1 79 31 123 235 27 137 57 76 958 22 8 8 86 315 954 88 12 7 181 2773 37 25 92 96 6712 58 2 628 9699 24 61 51 62 64 618 686 93 6 57 328 39 185 52 985 32 324 37 851 366 37 42 5 68 77 37 648 69 746 951 7 12 47 5 5479 633 74 529 796 41 7 1848 25 7915 245 3 49 17 13 441 67 66 458 75 59 684 161 65 18 16 47 61 696 37 719 9 662 671 5 53 82 3976 896 82 11 522 89 527 24 63 843 614 56 797 5198 6572 69 4613 545 373 921 89 55 844 43 22 47 7364 284 376 86 638 32 26 73 533 515 651 44 79 98 83 528 426 42 4 7855 97 766 45 17 669 5 41 112 978 3 32 61 38 95 54 879 218 79 52 16 236 22 61 49 8752 1 8 61 4 115 93 37 63 919 28 32 454 717 788 7 548 23 17 84 67 8775 39 76 475 252 51 99 21 37 39 127 972 531 84 94 6 91 455 98 697 513 287 714 685 3 7351 38 22 2265 927 9985 26 2461 38 589 98 824 24 13 9 9 69 48 85 859 31 85 831 461 862 512 969 48 663 573 357 18 7521 72 9965 91 766 63 37 22 119 56 5726 324 2672 6 858 8 697 36 1 1 864 84 6 2591 254 276 971 66 2739 824 886 81 378 2465 4 9 62 5738 138 343 25 56 9347 9444 1547 17 21 174 283 762 6323 263 14 2 333 484 17 94 93 337 212 542 9266 7 2 5118 47 56 22 8183 63 21 718 619 752 93 274 35 68 52 51 54 861 677 7266 27 158 69 925 22 6455 81 281 71 4955 63 24 66 4 32 743 238 71 82 845 4 87 79 1269 76 96 37 159 29 583 43 95 738 455 8 34 14 235 529 575 546 4141 85 29 83 3 895 59 255 53 76 288 4 91 64 7657 67 17 46 791 962 43 6 9316 3 48 163 25 886 1366 4577 79 35 19 16 7 343 52 2763 83 97 6568 71 91 826 98 77 363 753 879 59 966 58 255 12 758 167 69 753 1887 8 84 73 77 73 9 62 377 64 47 914 18 565 49 855 393 2429 92 499 65 92 9 944 566 3 882 82 894 113 35 64 333 94 495 16 866 862 771 8 98 372 94 36 734 72 86 11 87 87 2 36 674 3 + 72 656 21 499 94 23 4 82 85 79 2586 156 65 76 653 18 936 23 484 33 34 571 719 8 451 734 988 141 99 475 11 298 352 12 4717 95 72 11 62 22 193 17 57 3 748 7798 53 955 739 92 646 13 984 8421 336 8 8793 376 988 85 73 89 95 6 94 69 726 5918 92 326 962 139 431 819 23 55 61 4929 29 12 65 57 98 321 456 5 37 14 453 94 16 9874 489 12 78 86 17 998 62 49 65 182 558 584 889 44 91 95 57 655 41 67 4236 75 8533 31 58 48 47 825 1 75 84 78 92 73 76 62 92 72 5 1868 83 63 475 8 412 1 132 454 29 92 717 9144 44 93 273 47 39 95 81 855 883 622 953 774 877 791 5752 74 7432 6343 37 6 642 14 147 5315 52 43 435 61 1383 85 6585 96 97 39 82 254 7346 665 32 498 93 17 391 2588 864 311 183 38 92 163 35 939 182 28 71 584 25 587 773 673 647 96 4941 96 96 14 98 85 321 87 48 18 297 3738 12 121 918 7 86 12 9 17 7638 21 364 773 138 133 946 694 518 99 72 9 98 12 39 4394 46 6526 497 571 31 62 62 736 2695 953 352 63 19 5 36 71 6354 78 544 84 216 783 69 13 6425 68 82 23 1 413 12 4856 795 18 479 316 6 213 836 19 186 39 63 55 2 36 621 269 533 534 12 43 926 464 923 433 6 649 59 38 111 6668 1539 572 35 52 5151 231 518 499 21 879 37 598 38 58 711 69 59 3953 556 29 24 37 98 78 2 33 89 69 734 34 444 8 76 4566 91 2 14 87 79 973 49 679 556 5491 193 44 48 88 4 45 227 838 558 7582 625 6879 14 56 922 4 855 817 937 65 932 916 75 598 47 25 413 41 6741 172 32 648 785 97 21 243 95 28 224 19 633 99 195 2448 88 4 264 58 212 2247 293 33 727 61 84 83 988 159 47 13 69 388 69 12 3825 9 29 573 198 827 42 588 95 9 55 1653 552 791 35 215 61 3 489 86 55 4773 572 4593 24 3 17 13 62 6 7 2 7 694 571 819 868 87 377 75 65 94 16 59 385 9577 226 1 1673 5 42 1 178 8713 654 42 8228 76 75 7731 1 984 4846 95 64 784 56 556 695 91 3124 51 5893 172 146 34 85 227 268 9584 52 13 736 17 19 199 18 377 448 59 581 31 717 55 782 98 84 72 216 78 732 2311 32 24 6 816 556 54 165 11 47 637 45 485 19 524 97 935 37 16 927 12 8747 6 75 35 53 4836 92 9 37 2284 92 94 23 53 583 615 89 63 17 97 365 74 997 76 575 84 345 76 344 459 366 91 94 65 38 29 149 42 191 939 393 64 43 4 1824 17 1967 841 575 73 13 875 57 164 982 4 51 14 779 725 34 7 9372 43 97 125 323 2 84 459 67 363 219 19 251 62 233 2967 98 45 19 965 236 44 14 4864 5 588 53 313 5125 966 38 88 966 9248 72 619 556 132 484 377 75 849 76 71 42 4697 516 892 29 54 361 54 82 638 135 152 54 145 77 88 971 682 752 54 96 92 324 46 72 127 8 91 889 619 2 35 43 7 18 2 995 4849 46 16 33 622 81 5 739 2638 84 75 38 96 532 82 53 4 566 94 62 922 522 113 26 651 54 7 99 35 7412 7 75 468 45 34 25 84 17 343 33 486 254 19 26 77 893 73 21 884 69 434 484 775 333 433 65 58 6743 658 1623 22 1931 36 225 923 98 58 738 92 582 62 66 54 31 76 65 726 1 226 416 37 92 757 916 93 84 3197 29 94 11 481 7 663 453 886 538 5679 1898 35 19 255 5 893 24 2 97 184 75 7 7499 4883 86 16 4 1889 27 64 16 526 477 55 145 41 272 425 92 773 18 1366 6983 2612 85 27 188 448 8349 4274 147 39 1 923 653 62 51 59 4192 339 43 1315 76 26 7329 16 89 73 9125 31 15 942 7553 222 64 14 67 8 913 95 41 7224 392 5166 53 6643 16 2569 61 282 23 491 68 2187 38 439 723 5 39 8 322 47 37 58 23 256 92 547 19 14 87 234 6 849 33 55 987 658 883 57 65 289 957 788 299 2589 35 33 54 752 129 469 8645 666 87 98 2 34 7 339 1 93 58 158 549 37 24 5668 8 44 251 2464 123 723 4976 28 42 33 22 19 34 51 4497 32 42 669 6 998 999 56 99 5853 35 49 16 953 251 481 1 72 532 49 6562 976 65 38 92 71 98 52 16 291 91 52 599 95 564 74 477 8318 8664 689 654 2 76 61 317 111 1 747 22 356 253 57 75 347 87 49 6 471 619 649 518 42 155 73 33 63 71 331 587 45 28 5 27 811 4 + 1 914 15 398 72 47 1 68 58 1 2752 99 23 7 296 41 236 87 268 84 85 1 853 87 4677 522 218 286 16 9 89 882 653 9 7456 78 77 5 53 77 761 2 39 8 9 5214 89 724 312 28 161 87 862 478 3 9 7721 5 99 62 65 3 2 96 51 37 8 9772 85 738 88 153 58 854 692 81 74 2587 35 89 28 18 4 438 566 6 339 699 822 263 25 2252 874 68 19 47 47 73 25 93 9 69 813 437 784 4 13 79 33 163 79 46 9282 1 257 24 98 69 17 376 31 12 47 44 42 23 85 31 65 1 96 5258 24 3 323 4 7652 6 773 765 74 4 666 436 1 83 653 43 36 22 16 5 411 23 488 441 459 175 8252 53 8642 1244 42 88 574 7 23 9478 74 66 898 34 4879 49 938 59 1 519 5 938 8894 238 17 987 12 631 151 3571 649 759 63 68 7 3 22 227 286 8 43 117 92 9 437 62 443 71 4345 79 32 12 11 78 388 96 27 97 161 7241 33 36 621 67 37 72 8 4 7229 63 619 63 5 29 85 94 939 66 8 2 49 92 3 2988 32 8515 442 411 27 8 78 3 4114 819 648 5 96 7 4 12 465 75 612 478 33 3558 5 588 2936 13 39 15 46 671 57 758 136 58 63 571 5 499 157 94 81 438 73 6 4 36 148 962 591 19 55 11 59 98 631 73 3 76 83 19 83 539 9139 769 48 39 4757 229 8166 637 87 795 96 14 95 89 19 2 57 4589 264 23 33 81 788 772 6 92 2 76 233 51 157 73 6 147 224 9 613 82 65 64 95 893 4 9453 136 66 58 23 4 99 1 55 826 2596 635 6437 12 711 669 8 399 32 51 6 198 5 32 8 28 11 518 26 549 396 78 826 817 7 47 547 39 14 96 41 184 92 383 3315 35 1 274 17 484 9114 772 51 541 14 4 89 64 416 46 41 66 663 1 72 3777 4 14 941 596 419 54 897 52 14 46 4444 165 499 383 19 6 5 528 4 83 342 214 8194 79 3 65 17 1 4 4 733 15 711 966 199 393 3 248 15 4 59 96 5 821 1394 582 6 6171 6 69 49 7 7544 798 14 7727 8 29 823 9 525 8213 52 88 39 51 383 843 12 7832 5 6292 727 528 86 1 848 337 1966 7 45 585 45 19 811 79 899 8845 35 96 85 796 21 943 37 14 56 337 21 89 9438 18 76 9 17 7 7516 83 58 48 62 83 896 253 917 96 9887 68 7 699 63 5 9 22 48 4 59 36 77 95 42 38 29 52 64 714 937 58 58 79 75 145 88 379 31 867 22 9 66 49 6 886 41 26 49 1 15 872 74 734 691 988 17 26 379 5711 4 7934 799 848 98 58 75 5 71 351 2 313 43 7999 523 9 5 8372 13 97 632 787 1 8 141 7 994 844 13 666 92 91 2183 36 63 6 984 868 63 14 2472 6 733 49 289 7473 643 7 52 556 1935 52 666 44 368 922 255 36 478 86 528 3 935 11 6 7 8 837 85 37 9275 784 6 823 642 86 6 531 248 841 916 8 8 283 7 78 747 7 39 154 758 39 85 96 9 7 8 555 7217 61 35 8 84 16 4 376 3535 28 23 41 14 32 89 92 6 6 5 78 147 967 782 56 499 65 7 19 95 74 5 51 31 59 15 4 38 25 216 91 86 86 72 1 39 287 55 39 59 9 35 971 585 125 21 8 11 9232 947 1 51 45 71 6 264 5 15 576 93 697 45 9 5 33 4 92 728 9 472 234 44 56 751 733 31 77 215 29 5 81 164 6 943 826 385 415 368 8679 3 21 764 2 72 2 8 265 24 82 45 63 4347 9 2 7 7364 19 6 98 989 64 65 934 1 44 9 3 511 29 476 9632 2662 87 3 83 13 6262 3284 8 32 5 131 61 2 78 28 5921 8 5 7172 26 382 437 68 68 6 1263 95 32 362 2536 79 95 7 15 5 567 84 79 9836 643 4998 73 4171 14 8679 839 7 3 4 85 7951 99 861 343 74 66 5 86 7 17 44 98 228 42 87 84 32 22 55 7 325 39 73 336 272 292 45 1 523 273 35 224 7432 53 19 54 214 7 414 7159 569 29 41 8 51 8 966 4 26 78 664 716 52 858 5638 6 44 7329 4517 695 377 7971 75 7 88 94 76 89 87 167 43 6 484 5 445 467 22 77 9934 2 65 82 7 448 9 8 9 343 61 2631 914 944 1231 4 1 26 18 4 757 17 9 8 3 42 39 896 4142 8491 481 789 6 56 35 466 682 47 896 13 246 847 839 99 718 61 63 6 524 6 588 643 66 1 55 67 7 45 944 659 21 25 3 29 5 5 + * * + + + + + + * * + * + + * + * + * * + + * + + + * * + * + + * * + * * * + * * + * * * + * * * * + * * + * * + + * * * + * + + * + + * * + * + * + * * + + * * + * * * * * * + + * + + * + * * + * + * * * * * * * + * * * + + * + + + * * * + * + * + * + * + * + + * * * + + * * + * * * + * * * * * * + + * * + + * * + + + + + * + + + + * + * + + + + * * + + + + * * + * * * + * * + * * + + + + + + * + + * * * + + * + * + * * + * * + + + + * + + + * + + + + + * + + + + * * + + * * + + + * * + * * + + * + * * * * * + + * * + + + * + * + * * * + + + + + * * * * + + * + + + + * * + * * * * * * + * + * * * + + * * * + * + + + + * + + * + * + + * * + + + * * * * + + * * + * + + * * * + * * + + + * * * + + * + * + + * + * * * * + + * * * * * * + * + + + * * * + + * + + + * + * * * + + * + * * + + * + * + + * * * * * * * * + * + + + * * * * * * + + + * * + * + * + + * + + + * * + + * * * + * + + * * * + + * * + + * * + * * + + + * * + * * + + * + * * + * + * + + + + * * * + * * + + * * + + * * * + * + * * * + * + + + * * + + * + * * + * * * * + * * * + + + * + * + + * + + + * + + + + * + * * + + + * + * + * + + * * + + * + + + * * * * + * + * * * * + * + * * * * + * + * * * + + + + * + * * + * + + * * * + * * * + + * + * + + * * + + + + * + + * + + + * + * * * * * * + * + + * + * + + * * + + + * + + * + + + * + + + + + + * + + + * + * + + * * + * + + * * + * + * * + + * + + + + + + * * + + * * * + + + + * * * + + * * + * * + * * * + * * * * * + * + + * * + * + * + * + + * * + * + * * + * + + + * * + + + + * * * + + + + * * * + + * + + + + * * + * * + + + + + + + * + + + + * * + + * * + * * + * + + + + * * + + + * * * * * + * * + + + + * + + * * * + + * * + * * * * + + * + + + + * + + + * + + + * + + * + * + + * * * * * * * + * + + + * + * * * * * + * + * * * + + + + * + * + * + * + + + + * + * * + + * + + + + + + + + + + + + * * + + + * + + * * * + + * * + + * * * + * * + + + + * * * * * * + * * + * + * + + + * * * * * + * + * * * + * + * + * * + * + * * * * * * * * + + + + +
+4
day6/smallinput.txt
···
··· 1 + 123 328 51 64 2 + 45 64 387 23 3 + 6 98 215 314 4 + * + * +
+75
day6/src/main.rs
···
··· 1 + use std::fmt::Debug; 2 + use std::fs; 3 + 4 + mod parser; 5 + // what if signed but did, punch card then? 6 + // 7 + enum MathProblem { 8 + Sum(Vec<u64>), 9 + Mult(Vec<u64>), 10 + } 11 + 12 + impl Debug for MathProblem { 13 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 14 + match self { 15 + MathProblem::Sum(nums) => write!(f, "Sum({:?})", nums), 16 + MathProblem::Mult(nums) => write!(f, "Mult({:?})", nums), 17 + } 18 + } 19 + } 20 + 21 + impl MathProblem { 22 + fn new(mut nums: Vec<String>) -> MathProblem { 23 + println!("nums: {:?}", nums); 24 + //let mut mynums = nums.clone(); 25 + let operator: char = nums 26 + .pop() 27 + .expect("Unable to get final char from vector.") 28 + .chars() 29 + .next() 30 + .expect("Operator could not be parsed."); 31 + let values: Vec<u64> = nums.iter().map(|num| num.parse().unwrap()).collect(); 32 + match operator { 33 + '+' => MathProblem::Sum(values), 34 + '*' => MathProblem::Mult(values), 35 + _ => panic!("Invalid operator"), 36 + } 37 + } 38 + 39 + fn solve(&self) -> u64 { 40 + match self { 41 + MathProblem::Sum(nums) => nums.iter().sum(), 42 + MathProblem::Mult(nums) => nums.iter().product(), 43 + } 44 + } 45 + } 46 + 47 + fn main() { 48 + let input = fs::read_to_string("input.txt").expect("Unable to read input file"); 49 + 50 + // Go line by line through input and split each line by whitespace 51 + // create a Vector of Vectors that store each column 52 + /* let mut columns: Vec<Vec<&str>> = Vec::new(); 53 + 54 + for line in input.lines() { 55 + for (index, word) in line.split_whitespace().enumerate() { 56 + if index < columns.len() { 57 + columns[index].push(word); 58 + } else { 59 + columns.push(vec![word]); 60 + } 61 + } 62 + } */ 63 + 64 + let problems = parser::parse_columns(&input); 65 + 66 + let mut solutions: Vec<u64> = Vec::new(); 67 + for problem in problems { 68 + // let math_problem = MathProblem::new(&mut problem); 69 + let solution = problem.solve(); 70 + solutions.push(solution); 71 + println!("{:?} = {}", problem, solution); 72 + } 73 + 74 + println!("Grand total of {:?}", solutions.iter().sum::<u64>()); 75 + }
+76
day6/src/parser.rs
···
··· 1 + use crate::MathProblem; 2 + 3 + // how to read cephalopod grid: 4 + // 5 + // let Vec<Equations> 6 + // convert string -> lines, convert lines to Vec(chars) 7 + // let number = Vec<char> 8 + // for column in line.len -> 0 ; for row in lines.len : 9 + // if grid[row][col].parse() : 10 + // 11 + 12 + fn normalize_rows(char_grid: Vec<Vec<char>>) -> Vec<Vec<char>> { 13 + let max_row = char_grid.iter().map(|row| row.len()).max().unwrap_or(0); 14 + char_grid 15 + .into_iter() 16 + .map(|mut row| { 17 + row.resize(max_row, ' '); 18 + row 19 + }) 20 + .collect() 21 + } 22 + 23 + pub fn parse_columns(input: &str) -> Vec<MathProblem> { 24 + let mut problems = Vec::new(); 25 + // parse input into 2d array of chars 26 + let char_grid: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect(); 27 + let char_grid = normalize_rows(char_grid); 28 + 29 + println!("char_grid: {:?}", char_grid); 30 + 31 + let mut cur_problem = Vec::<String>::new(); 32 + // Flag for whether we should skip this col 33 + let mut skip_col = false; 34 + 35 + for col in 0..char_grid[0].len() { 36 + if skip_col { 37 + skip_col = false; 38 + continue; 39 + } 40 + let rcol = char_grid[0].len() - col - 1; 41 + let mut num_chars = Vec::<char>::new(); 42 + let mut found_operator = false; 43 + let p: String; 44 + 45 + for row in 0..char_grid.len() { 46 + if char_grid[row][rcol] == ' ' { 47 + continue; 48 + } 49 + num_chars.push(char_grid[row][rcol]); 50 + println!("num_chars: {:?}", num_chars); 51 + if char_grid[row][rcol] == '*' || char_grid[row][rcol] == '+' { 52 + found_operator = true; 53 + } 54 + } 55 + if !found_operator { 56 + // Surely there is a better way to do this repeated bit 57 + p = num_chars.iter().collect::<String>(); // } 58 + let parsed_problem = p.trim().to_string(); //} 59 + cur_problem.push(parsed_problem); // } 60 + } else { 61 + let operator = num_chars.pop().unwrap(); 62 + 63 + p = num_chars.iter().collect::<String>(); // } 64 + let parsed_problem = p.trim().to_string(); //} 65 + cur_problem.push(parsed_problem); // } 66 + 67 + cur_problem.push(operator.to_string()); 68 + println!("cur_problem: {:?}", cur_problem); 69 + let math_problem = MathProblem::new(cur_problem); 70 + problems.push(math_problem); 71 + cur_problem = Vec::new(); 72 + skip_col = true; 73 + } 74 + } 75 + problems 76 + }
+7
day7/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "day7" 7 + version = "0.1.0"
+6
day7/Cargo.toml
···
··· 1 + [package] 2 + name = "day7" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies]
+142
day7/input.txt
···
··· 1 + ......................................................................S...................................................................... 2 + ............................................................................................................................................. 3 + ......................................................................^...................................................................... 4 + ............................................................................................................................................. 5 + .....................................................................^.^..................................................................... 6 + ............................................................................................................................................. 7 + ....................................................................^...^.................................................................... 8 + ............................................................................................................................................. 9 + ...................................................................^.^...^................................................................... 10 + ............................................................................................................................................. 11 + ..................................................................^...^...^.................................................................. 12 + ............................................................................................................................................. 13 + .................................................................^.....^.^.^................................................................. 14 + ............................................................................................................................................. 15 + ................................................................^.^.^.^...^.^................................................................ 16 + ............................................................................................................................................. 17 + ...............................................................^.^.^.^.^.....^............................................................... 18 + ............................................................................................................................................. 19 + ..............................................................^.^.^.^.....^.^.^.............................................................. 20 + ............................................................................................................................................. 21 + .............................................................^.^...^...^.^...^.^............................................................. 22 + ............................................................................................................................................. 23 + ............................................................^.^.^.^.^.^...^.^.^.^............................................................ 24 + ............................................................................................................................................. 25 + ...........................................................^...^.^.......^.^...^.^........................................................... 26 + ............................................................................................................................................. 27 + ..........................................................^.^...^.^.^.^.^...^.^...^.......................................................... 28 + ............................................................................................................................................. 29 + .........................................................^.^.^...^.^.^.^.^.^.^.^...^......................................................... 30 + ............................................................................................................................................. 31 + ........................................................^.^.^.........^.^.^...^.....^........................................................ 32 + ............................................................................................................................................. 33 + .......................................................^.^.^...^...^.....^...^.^...^.^....................................................... 34 + ............................................................................................................................................. 35 + ......................................................^.^.......^.......^.......^.....^...................................................... 36 + ............................................................................................................................................. 37 + .....................................................^.^.^.....^.^.^.....^.^.^.^.^...^.^..................................................... 38 + ............................................................................................................................................. 39 + ....................................................^.^...^...^.^.^.^.^...^.....^.......^.................................................... 40 + ............................................................................................................................................. 41 + ...................................................^.^.^.^.^.^...^...^.^.^.^.^.^.....^...^................................................... 42 + ............................................................................................................................................. 43 + ..................................................^.^.^.^...^.^...^...^.^.....^.^...^.....^.................................................. 44 + ............................................................................................................................................. 45 + .................................................^.^.......^.^.....^...^.^...^.^...^.^...^.^................................................. 46 + ............................................................................................................................................. 47 + ................................................^...^.^.^.^.....^.^.^.^.^.^.^.....^.........^................................................ 48 + ............................................................................................................................................. 49 + ...............................................^.......^.^...^.^...^.^.^.^.^...^.^...^.^.^.^.^............................................... 50 + ............................................................................................................................................. 51 + ..............................................^...^.^...^...^.^.......^.^...^.^.^.^.^.....^.^.^.............................................. 52 + ............................................................................................................................................. 53 + .............................................^...^.^.^...^.....^...^...^.^...^...^.^.......^.^.^............................................. 54 + ............................................................................................................................................. 55 + ............................................^.^.^...^.^...^...^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^............................................ 56 + ............................................................................................................................................. 57 + ...........................................^.^.^...^.^.....^.^.^...^.......^.^.^.^.^.....^...^.^.^........................................... 58 + ............................................................................................................................................. 59 + ..........................................^.^.^.^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.......................................... 60 + ............................................................................................................................................. 61 + .........................................^.....^.^.^...^.^.^.....^.^...^.^...^.^.^.^...^.^.^.^.^...^......................................... 62 + ............................................................................................................................................. 63 + ........................................^.^...^.......^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.^........................................ 64 + ............................................................................................................................................. 65 + .......................................^...^.....^.......^.^.^...^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^....................................... 66 + ............................................................................................................................................. 67 + ......................................^.........^...^.^...^.^.^.^.^...^...^.^.^.^.^...^.^.^.....^...^.^...................................... 68 + ............................................................................................................................................. 69 + .....................................^.^.....^.^.^.^.^.^.^.^.^...^.......^.^.^.....^.......^.^.......^.^..................................... 70 + ............................................................................................................................................. 71 + ....................................^.^...^.....^.^.^...^.....^.^.^.^.^.^...^.^...^.....^.^.^.^.......^.^.................................... 72 + ............................................................................................................................................. 73 + ...................................^.^.^.^...^.^.^.^.^.^.^.^.^.....^.^.^.^.....^.^.....^.......^.^.^...^.^................................... 74 + ............................................................................................................................................. 75 + ..................................^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.....^.^...^.^.^.....^.^.^.^.^.^...^.^.................................. 76 + ............................................................................................................................................. 77 + .................................^...^.^.^...^...^...^.^.^.^.^.....^.^.^...^.^.....^.^.^.^.....^.^.^.^.^.^.^................................. 78 + ............................................................................................................................................. 79 + ................................^.^.^...^.........^.^.^...^.^.^.^...^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.^................................ 80 + ............................................................................................................................................. 81 + ...............................^.^.^.^.^.^.....^.^.^.^...^...........^.....^.....^.^.......^.^.^.....^.^.^...^............................... 82 + ............................................................................................................................................. 83 + ..............................^.^.^.^.^.^.^...^.^.^.....^.^.....^...^...^.^.^.^...^.^...^.^...^.......^...^.^.^.............................. 84 + ............................................................................................................................................. 85 + .............................^...^.^.....^.^.^.....^.^...^.^...^.^...^...^.^...^.^...^...^...^.^.^.....^.....^.^............................. 86 + ............................................................................................................................................. 87 + ............................^.^.....^.^.^.....^.^...^.^...^.....^.^...^...^.^.^...^...^.^.^...^.^.^.^.^.^...^...^............................ 88 + ............................................................................................................................................. 89 + ...........................^...^.^.^...^.^.^.......^.^.^...^.^.^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^.^...^...^...^........................... 90 + ............................................................................................................................................. 91 + ..........................^.^.^.^.^...^.^.^.....^.^...^.....^...^...^...^.^.^.....^...^.........^.^.^...^.^.^.^.^.^.......................... 92 + ............................................................................................................................................. 93 + .........................^...^.^.......^...^.......^...^.....^.^.^...^.....^...^...^...^.^...^.^.^.^...^.....^...^.^......................... 94 + ............................................................................................................................................. 95 + ........................^...^...^.^...^.^...^.^.^.^...^...^.^.^...^...^.^.^...^.....^...^.^.^.^.^...^.^.^.^.^...^...^........................ 96 + ............................................................................................................................................. 97 + .......................^...^.^...^...^.^.^.^...^.^...^.....^.^.^.^.^...^.^.^.^.^.........^.^.^.^.^.^.^.^...^.^...^...^....................... 98 + ............................................................................................................................................. 99 + ......................^...^.^.^.^.^.^.^.^.^.^...^.^...^...^.^...^...^.......^...^.....^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^...................... 100 + ............................................................................................................................................. 101 + .....................^...^.....^.^...^.^.^...^.^.^.^.^.^.^.^...^...^.^.^.^...........^.^.......^.....^.......^...^.^.^.^..................... 102 + ............................................................................................................................................. 103 + ....................^.^.^...^.^...^.^.....^.^.^.........^...^.^...^.^.....^.^.^.....^.......^.^.^...^.^.^.^.......^.^.^.^.................... 104 + ............................................................................................................................................. 105 + ...................^.^.^.^.....^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^...^.^.^.^...^.^.^...^.^...^...^.^.^.^.^................... 106 + ............................................................................................................................................. 107 + ..................^.....^.^...^.^.^.^.^.^.^...^.^.........^.^.^.^.^...^.^...^.......^.^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.................. 108 + ............................................................................................................................................. 109 + .................^...^.^.^.^.^.^.^...^.^...^.^.^...^.^...^.^.^...^.^...^...^.^...^.^...^.^...^...^.....^.^.....^.....^...^.^................. 110 + ............................................................................................................................................. 111 + ................^.....^.......^.^.^.^.^...^.^...^.^.^.^.^.....^.^...^.^.^.......^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^................ 112 + ............................................................................................................................................. 113 + ...............^.....^.^...^.^.^.^.^...^.........^...^.^.^.^...^.^.^.^.^...^...^.^.^.^...^.^.^.^.^.^.^...^.^.....^.^.^.^.^.^.^............... 114 + ............................................................................................................................................. 115 + ..............^.^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.....^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...^...^...^.^.^.............. 116 + ............................................................................................................................................. 117 + .............^.^.^.^.....^.^.^...^.....^.^.^.......^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^...^...^.^.......^...^...^.^.^...^.^............. 118 + ............................................................................................................................................. 119 + ............^.^.^.....^.^.^.^.^...^.^.^...^.^...^.^.^.^.^.....^.^...^.^.^.^...^.......^...^...^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^............ 120 + ............................................................................................................................................. 121 + ...........^.^...^.^...^.^.^...^.^.^.^.^.^.....^...^.^.....^...^...^.^.^.^...^.^.^.^.^...^.....^...^.^...^.....^.....^...^...^.^.^........... 122 + ............................................................................................................................................. 123 + ..........^.^.^.^.^.......^.....^...^...^...^...^...^.....^.^.^.^.^.....^.^...^.^.^.^.^.....^.^...^.^.^.^.....^.^.^.^.^.^...^...^.^.......... 124 + ............................................................................................................................................. 125 + .........^.^.^...^.^.^.^.^.^.^.^.^.........^.^...^...^.....^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^...^...^.^...^.^.^.^.^.^...^.^.^...^.^......... 126 + ............................................................................................................................................. 127 + ........^.^.....^.^.^.....^.^.^...^.^...^.^.^.....^...^.^.^...^.^.^.^.^.^.....^.....^.^.^.^...^.^...^.^.....^.....^...^.^.....^.^...^........ 128 + ............................................................................................................................................. 129 + .......^...^.^.......^.^...^.^...^.^...^.....^.^.^.^.^.^.^.^...^.^.^...^...^.^.^.^.^...^...^...^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^.^....... 130 + ............................................................................................................................................. 131 + ......^.......^.....^...^...^.^.....^.^...^.....^.^.^.^.^.^...^...^...^.^...^...^.........^.^...^.......^.^.^.^...^.....^.^.^.^.....^.^...... 132 + ............................................................................................................................................. 133 + .....^.^...^.^.^.....^...^.^...^.^...^.^.^.^.^.^.^.^.^.....^...^.......^.....^.^.^...^...^.^.^...^.^.^.......^.^.^.^...^...^.^.^.^.^.^.^..... 134 + ............................................................................................................................................. 135 + ....^.^.^.....^.^.^.^.^.^.^.....^.^.^.^.....^...^.........^.^.........^.^.^.^.^.^.^...^.^.^.^...^.^.^...^.^.^.....^...^.......^.^.^.^...^.... 136 + ............................................................................................................................................. 137 + ...^.^.....^.^...^.^.^.^.^.^.^.....^.^.......^...^...^...^.^...^...^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^...^...^... 138 + ............................................................................................................................................. 139 + ..^.^.^.^...^...^.......^...^.^...^.^.....^...^.^.^...^...^.....^...^.....^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.....^.^...^.^.. 140 + ............................................................................................................................................. 141 + .^.^.^.....^.........^.^.......^.^.^.^...^.^.^.^.........^.^.^.......^.^.......^.^.^.^.^.^.^...^...^...^.^.^...^.^.^.....^.^.^...^.^.^.^.^.^. 142 + .............................................................................................................................................
+16
day7/smallinput.txt
···
··· 1 + .......S....... 2 + ............... 3 + .......^....... 4 + ............... 5 + ......^.^...... 6 + ............... 7 + .....^.^.^..... 8 + ............... 9 + ....^.^...^.... 10 + ............... 11 + ...^.^...^.^... 12 + ............... 13 + ..^...^.....^.. 14 + ............... 15 + .^.^.^.^.^...^. 16 + ...............
+173
day7/src/main.rs
···
··· 1 + use std::collections::VecDeque; 2 + use std::fmt::Debug; 3 + use std::fs; 4 + 5 + struct TachyonManifold { 6 + data: Vec<Vec<char>>, 7 + height: usize, 8 + width: usize, 9 + } 10 + 11 + impl TachyonManifold { 12 + fn new(input: String) -> Self { 13 + let data: Vec<Vec<char>> = input.lines().map(|line| line.chars().collect()).collect(); 14 + let height = data.len(); 15 + let width = data[0].len(); 16 + Self { 17 + data, 18 + height, 19 + width, 20 + } 21 + } 22 + 23 + fn propagate_beam(&mut self, row: usize) -> u32 { 24 + let mut split_count = 0u32; 25 + let row_data = self.data[row].clone(); 26 + 27 + // THIS ANNOYINGLY CONTAINS AN IMMUTABLE BORROW for self.data[row] 28 + // SO IT BREAKS ALL MY MUTABLE REFERENCES. 29 + // THIS IS WHY THERE IS ALL THE CLONE()ING 30 + for (index, c) in row_data.iter().enumerate() { 31 + match c { 32 + 'S' | '|' => { 33 + if self.data[row + 1][index] == '.' { 34 + self.data[row + 1][index] = '|' 35 + } 36 + } 37 + '^' => { 38 + if self.data[row.saturating_sub(1)][index] == '|' { 39 + self.data[row][index + 1] = '|'; 40 + self.data[row][index.saturating_sub(1)] = '|'; 41 + split_count += 1; 42 + } 43 + } 44 + _ => continue, 45 + } 46 + } 47 + 48 + // ANNOYINGLY HAVE TO RE-CLONE DATA BC CANT FIGURE OUT HOW TO EDIT IN PLACE 49 + let row_data = self.data[row].clone(); 50 + 51 + for (index, c) in row_data.iter().enumerate() { 52 + match c { 53 + '|' => { 54 + if self.data[row + 1][index] == '.' { 55 + self.data[row + 1][index] = '|' 56 + } 57 + } 58 + _ => continue, 59 + } 60 + } 61 + split_count 62 + } 63 + } 64 + 65 + // NEW PLAN OKAY SO BASICALLY WE CAN PUSH EACH ROW/COL TO A STACK AND SEE IF IT HAS A LINE OF SIGHT TO THE BOTTOM, IF IT ENCOUNTERS A ^ WE PUSH TWO MORE, IF IT REACHES THE BOTTOM, WE POP 66 + 67 + impl TachyonManifold { 68 + fn ez_quantum(&mut self, row: usize) -> u64 { 69 + let mut path_stack = Vec::<QuantumSplit>::new(); 70 + let mut timelines = Vec::<Vec<QuantumSplit>>::new(); 71 + let mut cur_timeline = Vec::<QuantumSplit>::new(); 72 + // let mut success_paths = 0; 73 + // initialize two paths from starting node 74 + let start_col = self.data[row] 75 + .iter() 76 + .position(|c| *c == '^') 77 + .expect("No starting split found"); 78 + println!("Start column: {}", start_col); 79 + path_stack.push(QuantumSplit::Left(row, start_col.saturating_sub(1))); 80 + path_stack.push(QuantumSplit::Right(row, start_col.saturating_add(1))); 81 + 82 + while let Some(cur_path) = path_stack.pop() { 83 + //println!("Path stack: {:?}", path_stack); 84 + // Save the path we take 85 + match cur_path { 86 + QuantumSplit::Left(cur_row, cur_col) | QuantumSplit::Right(cur_row, cur_col) => { 87 + for row_index in cur_row..self.height { 88 + cur_timeline.push(cur_path.clone()); 89 + if row_index == self.height - 1 { 90 + // save the full path 91 + timelines.push(cur_timeline.clone()); 92 + cur_timeline.clear(); 93 + // success_paths += 1; 94 + // println!("Found {} paths", success_paths); 95 + // println!("Cur_path = {:?}", cur_path); 96 + // println!("Stack = {:?}", path_stack); 97 + // println!("Found {} paths", success_paths); 98 + } else if self.data[row_index][cur_col] == '^' { 99 + path_stack 100 + .push(QuantumSplit::Left(row_index, cur_col.saturating_sub(1))); 101 + path_stack 102 + .push(QuantumSplit::Right(row_index, cur_col.saturating_add(1))); 103 + self.data[row_index][cur_col] = 'x'; 104 + break; 105 + } else if self.data[row_index][cur_col] == 'x' { 106 + break; 107 + } else { 108 + self.data[row_index][cur_col] = '|'; 109 + } 110 + } 111 + println!("Data: {:?}", self); 112 + } 113 + } 114 + } 115 + 116 + println!("Explored map: {:?}", self); 117 + //println!("Timelines: {:?}", timelines); 118 + 119 + timelines.len() as u64 120 + } 121 + } 122 + 123 + // Quantum propagation thoughts 124 + // looks like a tree structure 125 + // every time we find a split, could push a new Tachyon Manifold onto the stack 126 + // --- Wait okay its one beam 127 + // so really we just need to store a stack of L/R decisions that represent 128 + // a map of outcomes 129 + // problem is... how do we distinguish whether tachyons path was unique? 130 + // save every path taken as a a string & convert to a set? 131 + // or are they just guaranteed unique structurally 132 + 133 + // Okay so quantum split will represent each time we encounter a ^ traversing the file 134 + #[derive(Debug, Clone)] 135 + enum QuantumSplit { 136 + Left(usize, usize), 137 + Right(usize, usize), 138 + } 139 + 140 + impl Debug for TachyonManifold { 141 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 142 + writeln!( 143 + f, 144 + "TachyonManifold of size {}, {} {{", 145 + self.width, self.height 146 + )?; 147 + for row in &self.data { 148 + for &cell in row { 149 + write!(f, "{}", cell)?; 150 + } 151 + writeln!(f)?; 152 + } 153 + writeln!(f, "}}")?; 154 + Ok(()) 155 + } 156 + } 157 + 158 + fn main() { 159 + let mut manifold = TachyonManifold::new(fs::read_to_string("smallinput.txt").unwrap()); 160 + 161 + // let mut splits = 0u32; 162 + // for row in 0..manifold.height - 1 { 163 + // splits += manifold.propagate_beam(row); 164 + // // println!("{:?}", manifold); 165 + // } 166 + 167 + // Weird observation: for the small example provided 168 + // answer for total number of paths == the number of beams 169 + let beam_count = manifold.ez_quantum(2); 170 + 171 + // println!("Beam split {} times.", splits); 172 + println!("Total possible paths: {}", beam_count); 173 + }
+5
day7/tinyinput.txt
···
··· 1 + ..S.. 2 + ..... 3 + ..^.. 4 + ..... 5 + .....
+160
day8/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "ahash" 7 + version = "0.7.8" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" 10 + dependencies = [ 11 + "getrandom", 12 + "once_cell", 13 + "version_check", 14 + ] 15 + 16 + [[package]] 17 + name = "cfg-if" 18 + version = "1.0.4" 19 + source = "registry+https://github.com/rust-lang/crates.io-index" 20 + checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 21 + 22 + [[package]] 23 + name = "day8" 24 + version = "0.1.0" 25 + dependencies = [ 26 + "itertools", 27 + "memoize", 28 + ] 29 + 30 + [[package]] 31 + name = "either" 32 + version = "1.15.0" 33 + source = "registry+https://github.com/rust-lang/crates.io-index" 34 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 35 + 36 + [[package]] 37 + name = "getrandom" 38 + version = "0.2.16" 39 + source = "registry+https://github.com/rust-lang/crates.io-index" 40 + checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" 41 + dependencies = [ 42 + "cfg-if", 43 + "libc", 44 + "wasi", 45 + ] 46 + 47 + [[package]] 48 + name = "hashbrown" 49 + version = "0.12.3" 50 + source = "registry+https://github.com/rust-lang/crates.io-index" 51 + checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 52 + dependencies = [ 53 + "ahash", 54 + ] 55 + 56 + [[package]] 57 + name = "itertools" 58 + version = "0.14.0" 59 + source = "registry+https://github.com/rust-lang/crates.io-index" 60 + checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 61 + dependencies = [ 62 + "either", 63 + ] 64 + 65 + [[package]] 66 + name = "lazy_static" 67 + version = "1.5.0" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 70 + 71 + [[package]] 72 + name = "libc" 73 + version = "0.2.178" 74 + source = "registry+https://github.com/rust-lang/crates.io-index" 75 + checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" 76 + 77 + [[package]] 78 + name = "lru" 79 + version = "0.7.8" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" 82 + dependencies = [ 83 + "hashbrown", 84 + ] 85 + 86 + [[package]] 87 + name = "memoize" 88 + version = "0.5.1" 89 + source = "registry+https://github.com/rust-lang/crates.io-index" 90 + checksum = "f8d1d5792299bab3f8b5d88d1b7a7cb50ad7ef039a8c4d45a6b84880a6526276" 91 + dependencies = [ 92 + "lazy_static", 93 + "lru", 94 + "memoize-inner", 95 + ] 96 + 97 + [[package]] 98 + name = "memoize-inner" 99 + version = "0.5.1" 100 + source = "registry+https://github.com/rust-lang/crates.io-index" 101 + checksum = "6dd8f89255d8ff313afabed9a3c83ef0993cc056679dfd001f5111a026f876f7" 102 + dependencies = [ 103 + "lazy_static", 104 + "proc-macro2", 105 + "quote", 106 + "syn", 107 + ] 108 + 109 + [[package]] 110 + name = "once_cell" 111 + version = "1.21.3" 112 + source = "registry+https://github.com/rust-lang/crates.io-index" 113 + checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 114 + 115 + [[package]] 116 + name = "proc-macro2" 117 + version = "1.0.103" 118 + source = "registry+https://github.com/rust-lang/crates.io-index" 119 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 120 + dependencies = [ 121 + "unicode-ident", 122 + ] 123 + 124 + [[package]] 125 + name = "quote" 126 + version = "1.0.42" 127 + source = "registry+https://github.com/rust-lang/crates.io-index" 128 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 129 + dependencies = [ 130 + "proc-macro2", 131 + ] 132 + 133 + [[package]] 134 + name = "syn" 135 + version = "1.0.109" 136 + source = "registry+https://github.com/rust-lang/crates.io-index" 137 + checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 138 + dependencies = [ 139 + "proc-macro2", 140 + "quote", 141 + "unicode-ident", 142 + ] 143 + 144 + [[package]] 145 + name = "unicode-ident" 146 + version = "1.0.22" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 149 + 150 + [[package]] 151 + name = "version_check" 152 + version = "0.9.5" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 155 + 156 + [[package]] 157 + name = "wasi" 158 + version = "0.11.1+wasi-snapshot-preview1" 159 + source = "registry+https://github.com/rust-lang/crates.io-index" 160 + checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
+8
day8/Cargo.toml
···
··· 1 + [package] 2 + name = "day8" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + itertools = "0.14.0" 8 + memoize = "0.5.1"
+1000
day8/input.txt
···
··· 1 + 34638,6460,34327 2 + 36136,80204,94922 3 + 63956,13532,82511 4 + 84989,77493,6979 5 + 15829,82900,53590 6 + 92975,67552,29527 7 + 29672,51392,96771 8 + 11638,67228,96760 9 + 82932,37026,3773 10 + 59566,71890,77458 11 + 97765,36341,39917 12 + 63471,23684,55263 13 + 22811,42924,1029 14 + 72549,52303,55154 15 + 87115,10949,18526 16 + 90246,42533,26156 17 + 31083,90606,99431 18 + 79655,86017,53601 19 + 55608,61629,97935 20 + 29865,56435,38011 21 + 20194,3999,57071 22 + 48752,28161,41236 23 + 19375,6057,66275 24 + 85485,52222,91989 25 + 76382,77447,56403 26 + 33801,8264,4638 27 + 62261,5872,21629 28 + 2791,21311,21900 29 + 88257,56684,24070 30 + 6189,92325,30826 31 + 2562,74409,63075 32 + 31063,44863,81385 33 + 96288,18232,3462 34 + 65258,77048,76802 35 + 42326,6326,85985 36 + 74530,7811,36895 37 + 92821,23857,64648 38 + 61479,35131,89736 39 + 44400,39520,75605 40 + 50351,64236,24544 41 + 89101,52346,88465 42 + 62365,70564,57698 43 + 93936,8711,78713 44 + 28673,28539,4676 45 + 47906,65604,5207 46 + 31977,54588,1127 47 + 83078,83383,15703 48 + 67238,53983,15314 49 + 7608,17892,72852 50 + 76869,16590,91177 51 + 61854,24017,89923 52 + 89308,42254,59822 53 + 31250,1199,37683 54 + 86149,40499,77339 55 + 75566,92843,8931 56 + 27601,37974,44797 57 + 49362,63633,72634 58 + 92312,33221,64470 59 + 33032,26692,65534 60 + 49013,32501,20927 61 + 9980,86127,50365 62 + 38779,65045,32592 63 + 43271,7429,33469 64 + 32973,86809,36444 65 + 47464,42282,91772 66 + 25201,46683,92077 67 + 16477,42340,22084 68 + 40115,87586,33745 69 + 62301,51031,72925 70 + 33167,78183,5570 71 + 42558,14486,51823 72 + 34957,50821,53240 73 + 7700,8015,59124 74 + 12914,42198,46053 75 + 54892,58312,63243 76 + 15433,58636,32788 77 + 81596,12623,22120 78 + 40878,89496,50699 79 + 24291,14895,48968 80 + 20263,56874,39063 81 + 61903,99044,42383 82 + 72853,85673,41771 83 + 48115,85203,2938 84 + 90673,295,51482 85 + 21658,4246,82759 86 + 7352,23307,31094 87 + 39954,19455,53552 88 + 31998,30020,57196 89 + 53122,28348,71489 90 + 7276,7554,82097 91 + 47719,1267,86366 92 + 71125,23336,54071 93 + 86036,45713,53547 94 + 78792,60916,44660 95 + 42313,32221,53608 96 + 22914,11697,99221 97 + 35922,32327,59977 98 + 77586,65679,91154 99 + 8479,25148,8536 100 + 40034,10039,64875 101 + 80596,78410,29295 102 + 62288,32761,97785 103 + 15707,32650,25004 104 + 20795,3719,57138 105 + 64648,38186,65528 106 + 80529,1359,31416 107 + 55486,85081,60077 108 + 25226,61630,32348 109 + 36341,32378,79794 110 + 96972,94080,8300 111 + 55207,83331,69444 112 + 5025,71638,80584 113 + 53937,6249,80721 114 + 26814,72103,94872 115 + 45750,84830,82197 116 + 84080,62442,86553 117 + 69473,67167,21270 118 + 49302,10353,71082 119 + 94806,64434,9333 120 + 46590,92390,79387 121 + 29047,83205,91552 122 + 50133,85570,90350 123 + 70014,8151,86508 124 + 54859,57632,29270 125 + 77341,37758,58828 126 + 90143,93330,55690 127 + 62628,69646,9179 128 + 51359,29242,79439 129 + 38752,66445,84746 130 + 61352,72279,14778 131 + 54282,54436,91296 132 + 14676,50382,35834 133 + 72583,80662,7775 134 + 65378,64903,25826 135 + 15872,91485,87456 136 + 68473,62086,97016 137 + 80619,28168,25228 138 + 8840,19484,96304 139 + 81174,58469,43476 140 + 61067,30487,47198 141 + 33242,93564,77864 142 + 35110,84346,75229 143 + 79784,76283,48937 144 + 82030,93038,63178 145 + 87374,80871,62307 146 + 11485,45375,31646 147 + 58807,16808,35000 148 + 95149,49023,89328 149 + 93991,94433,27760 150 + 29299,54660,63740 151 + 83392,40972,5518 152 + 94933,86033,5730 153 + 43899,83103,57243 154 + 95868,21358,8872 155 + 19211,22364,83955 156 + 29760,53550,75164 157 + 22864,93044,66955 158 + 49808,25786,10820 159 + 50092,14979,63423 160 + 38926,84794,81532 161 + 47061,86027,55767 162 + 93389,50651,10077 163 + 29632,97099,33834 164 + 75766,94828,21779 165 + 18961,89164,99323 166 + 40309,36376,61727 167 + 63359,1113,36391 168 + 4253,86038,46526 169 + 85122,7376,57033 170 + 36840,83837,25984 171 + 48179,10513,29691 172 + 73881,9538,52221 173 + 29647,27392,66225 174 + 46414,81641,83823 175 + 86966,39279,98074 176 + 76283,24200,54866 177 + 99926,89788,55114 178 + 38961,96192,86485 179 + 50298,78736,56914 180 + 37874,73779,47684 181 + 20561,88745,57756 182 + 98614,62415,77153 183 + 75021,6139,12379 184 + 94622,50201,91946 185 + 3322,55311,50785 186 + 38006,67773,17488 187 + 94459,55548,77276 188 + 57948,9375,71236 189 + 38533,83551,18223 190 + 70290,60188,94469 191 + 59980,92556,77814 192 + 12843,59969,68822 193 + 49495,6993,49769 194 + 57087,95216,75132 195 + 84205,52491,67729 196 + 80381,9041,99269 197 + 86103,29048,76338 198 + 91981,94248,61294 199 + 56507,68739,91181 200 + 33945,48398,37698 201 + 16919,52051,78968 202 + 45336,24048,83593 203 + 19356,60554,60088 204 + 31142,27484,71163 205 + 76838,48324,81901 206 + 41580,50370,66382 207 + 65621,74384,77020 208 + 28008,31344,29625 209 + 27540,28987,64399 210 + 49430,22077,12085 211 + 11677,90472,94300 212 + 87259,63301,1322 213 + 62975,14838,28859 214 + 77768,25699,57114 215 + 7028,58012,42258 216 + 4199,92050,66452 217 + 26658,13319,23629 218 + 4000,18025,70593 219 + 69741,2743,34407 220 + 20131,31244,90838 221 + 21210,88696,89681 222 + 41238,11486,22901 223 + 47883,35824,312 224 + 9419,68983,59320 225 + 64583,53269,31491 226 + 28746,5055,82055 227 + 33938,61806,54616 228 + 39717,96036,28462 229 + 48501,47260,77857 230 + 14660,34289,82546 231 + 33414,45979,65698 232 + 60332,9637,75610 233 + 60755,47747,20663 234 + 78783,56219,1294 235 + 65759,21600,83106 236 + 57771,7354,82363 237 + 57800,3329,94108 238 + 8302,97041,8866 239 + 58932,39181,48767 240 + 84377,69223,35272 241 + 92400,24428,78399 242 + 12796,18069,98025 243 + 65522,31834,93163 244 + 61734,40909,55396 245 + 73448,29297,97552 246 + 23421,4058,25449 247 + 53716,70703,80691 248 + 48573,34443,85840 249 + 33109,5461,97327 250 + 21016,39815,2563 251 + 9538,45821,55263 252 + 48892,12834,7105 253 + 7743,65098,75561 254 + 40192,18622,96543 255 + 75071,42754,71189 256 + 92535,691,3185 257 + 71909,62537,31615 258 + 91901,58390,28582 259 + 61556,11600,9445 260 + 12630,93555,35677 261 + 53762,81641,65466 262 + 80945,88199,1418 263 + 35596,89069,45726 264 + 54098,26036,72179 265 + 70440,61576,207 266 + 92508,94620,37431 267 + 23922,38311,85037 268 + 99309,3411,62362 269 + 55060,99648,7525 270 + 12845,80639,39357 271 + 8246,96145,25007 272 + 82267,27259,17983 273 + 64774,80175,65989 274 + 93182,22496,92884 275 + 51427,49441,84325 276 + 65317,24992,69545 277 + 10166,26396,81706 278 + 76921,4892,50605 279 + 72255,17258,97613 280 + 72970,71945,84494 281 + 89217,48290,3868 282 + 82101,52081,74163 283 + 55203,63552,58196 284 + 59246,16997,11764 285 + 39100,69848,886 286 + 62475,41826,62097 287 + 78319,56672,96449 288 + 38156,56323,91807 289 + 92117,14248,51641 290 + 89528,17150,68190 291 + 75317,81462,35071 292 + 33943,60866,46376 293 + 80211,21017,99903 294 + 87389,84664,74739 295 + 23618,81973,21452 296 + 28275,41032,49104 297 + 28233,74230,15457 298 + 75326,80960,49713 299 + 98822,6647,19638 300 + 57350,15024,17408 301 + 98613,61083,73756 302 + 95757,84324,1288 303 + 36364,62413,54580 304 + 72012,46388,53456 305 + 48671,23789,76285 306 + 26346,67830,79851 307 + 45081,82708,54936 308 + 39559,91796,72298 309 + 72411,49944,78787 310 + 44497,12675,40508 311 + 75527,30462,88639 312 + 75377,85035,68352 313 + 67675,94736,15449 314 + 62750,94294,9999 315 + 32043,98312,40262 316 + 26448,9351,96835 317 + 79583,87308,18297 318 + 20231,96229,34380 319 + 54180,22466,38811 320 + 34842,32941,48547 321 + 65740,29896,45720 322 + 64139,11611,68720 323 + 75950,85818,18175 324 + 27517,5034,18515 325 + 37050,6305,88375 326 + 6753,34242,471 327 + 94661,72376,25040 328 + 66207,9779,59940 329 + 90573,21759,99797 330 + 97550,81229,34405 331 + 62568,25144,86569 332 + 43919,62786,61022 333 + 11725,98463,61431 334 + 20302,9931,4505 335 + 32193,56607,34712 336 + 41341,98990,90202 337 + 59958,86611,55862 338 + 60567,58965,56304 339 + 75243,52671,50882 340 + 53276,21153,29775 341 + 59070,17008,7685 342 + 81929,51528,96422 343 + 67520,62515,2802 344 + 67462,87015,13721 345 + 37851,38354,76953 346 + 27093,29431,61326 347 + 61079,93827,49223 348 + 41112,9414,38085 349 + 60591,71807,27964 350 + 7709,68187,76271 351 + 50296,2570,51103 352 + 80856,95563,29445 353 + 35768,55112,49523 354 + 81798,59875,36515 355 + 54082,96643,26294 356 + 57109,22636,52567 357 + 96896,88074,25207 358 + 52058,70573,23273 359 + 53029,6909,81325 360 + 70130,97117,92346 361 + 34387,130,81536 362 + 98775,27831,8667 363 + 28039,29759,30410 364 + 29981,94585,32020 365 + 63560,64987,2659 366 + 3485,66006,83576 367 + 25427,85220,66535 368 + 16594,55583,73973 369 + 6792,22459,64253 370 + 85854,7726,98059 371 + 33858,95758,66413 372 + 59941,32519,78772 373 + 73731,89490,56647 374 + 92128,16683,62092 375 + 14349,82118,44724 376 + 45313,44307,48469 377 + 87604,3185,1996 378 + 31398,163,8187 379 + 62594,19496,41413 380 + 52993,89647,48559 381 + 15649,62040,78256 382 + 13910,37059,35527 383 + 99576,56730,65581 384 + 67853,38855,47117 385 + 62163,39712,27499 386 + 43848,24969,44301 387 + 32169,32499,67363 388 + 16323,20428,48946 389 + 76769,61243,15287 390 + 60662,67492,23336 391 + 4186,61483,72626 392 + 14728,63075,96128 393 + 42658,48793,58032 394 + 54760,59249,63389 395 + 67502,2809,80016 396 + 80344,33076,51466 397 + 97409,64243,58561 398 + 45180,85792,16564 399 + 81951,86646,84606 400 + 60797,96156,30923 401 + 1500,44095,78644 402 + 28828,42150,44489 403 + 51543,57716,78330 404 + 36844,59428,43547 405 + 42768,31633,56769 406 + 2040,99327,68673 407 + 8516,35206,35760 408 + 72393,51088,41005 409 + 90228,69424,45379 410 + 82948,73350,35720 411 + 94369,29620,26752 412 + 95631,44554,94176 413 + 54060,94765,49338 414 + 65337,28635,31874 415 + 33358,35348,76768 416 + 71003,56778,59361 417 + 28858,86504,68086 418 + 63862,42599,82040 419 + 40862,99891,20266 420 + 96348,85061,77131 421 + 50817,78120,85368 422 + 36323,11210,8991 423 + 59342,15326,9676 424 + 45323,15777,35434 425 + 66807,68371,80957 426 + 2858,23431,99700 427 + 7123,60629,73126 428 + 89693,76170,90262 429 + 22755,95870,12947 430 + 3596,37802,73005 431 + 59625,62995,77309 432 + 26064,76816,54019 433 + 32541,71318,2131 434 + 16517,66487,91155 435 + 44612,27513,90466 436 + 98791,38366,58096 437 + 87131,83932,43161 438 + 84511,94392,37198 439 + 19029,84930,45535 440 + 36640,28755,63576 441 + 30905,74844,32674 442 + 5443,15048,49808 443 + 37733,21442,39514 444 + 91056,83972,16043 445 + 40409,37417,90538 446 + 19077,56153,81504 447 + 17151,19180,35158 448 + 94657,10508,18147 449 + 35958,4896,16029 450 + 70152,49519,18852 451 + 19157,55490,41522 452 + 19926,95426,69942 453 + 82679,91545,60842 454 + 44550,99717,72890 455 + 22560,79262,75628 456 + 60357,91399,12191 457 + 62693,91000,71679 458 + 14995,48506,42843 459 + 37725,16933,56803 460 + 34180,20315,4425 461 + 39943,11461,98289 462 + 10335,67003,59006 463 + 41324,14901,64862 464 + 8676,8119,97134 465 + 83610,52472,31364 466 + 46992,32011,84281 467 + 36097,21699,33393 468 + 364,43449,77745 469 + 52754,43232,17231 470 + 58463,27552,65305 471 + 58935,67300,28653 472 + 41582,48070,12230 473 + 85458,62900,42581 474 + 96905,26927,70580 475 + 89538,40577,34895 476 + 40907,73248,89294 477 + 40110,24517,28209 478 + 95071,47060,86010 479 + 32361,73407,79017 480 + 56637,44391,40600 481 + 37758,5507,62422 482 + 94615,66640,89224 483 + 23408,52838,54947 484 + 57098,78690,38872 485 + 84623,58922,25030 486 + 12743,77225,29003 487 + 28521,34657,73729 488 + 46407,95301,13899 489 + 67849,4697,44958 490 + 20066,4978,60743 491 + 64833,73689,64526 492 + 81886,33831,14118 493 + 19155,23034,28128 494 + 92431,36485,53657 495 + 66886,11078,78937 496 + 21456,39637,36017 497 + 7238,1287,27445 498 + 24558,90080,90309 499 + 93955,27027,23944 500 + 92788,69611,44138 501 + 25991,99425,79948 502 + 16918,52459,29061 503 + 7221,31477,33398 504 + 27053,11588,77589 505 + 90891,30354,44552 506 + 75084,5987,29353 507 + 41874,94479,23914 508 + 9789,97206,43428 509 + 87513,12618,60482 510 + 65324,85059,37796 511 + 28655,24502,6279 512 + 60584,60607,8807 513 + 54931,61580,45598 514 + 16691,48786,68501 515 + 36004,65546,99456 516 + 7102,53591,40551 517 + 52003,88050,35289 518 + 30222,44266,57587 519 + 73324,74001,30820 520 + 92790,57354,88104 521 + 88776,72176,57484 522 + 74495,60187,32497 523 + 19074,41850,86694 524 + 81099,28309,40880 525 + 99805,56564,64483 526 + 5173,58436,69637 527 + 76743,84943,83381 528 + 51604,13233,8805 529 + 55360,42125,25525 530 + 28050,94127,56410 531 + 65336,11174,65706 532 + 39402,60594,11827 533 + 13537,88684,89119 534 + 31292,37806,68337 535 + 77884,13474,61430 536 + 42200,19748,24605 537 + 97384,90470,75857 538 + 86125,41815,90562 539 + 86825,3854,52656 540 + 8289,48066,2522 541 + 71355,64241,71313 542 + 66530,13474,82293 543 + 94586,66358,95041 544 + 51293,64350,28046 545 + 98890,9778,76342 546 + 69785,87132,8969 547 + 63573,75507,71299 548 + 97101,82116,17850 549 + 50802,14682,61252 550 + 64505,11057,4264 551 + 17312,1830,43701 552 + 69541,3618,28115 553 + 75793,7805,82990 554 + 44727,25752,47726 555 + 9155,20938,58980 556 + 89459,4864,46927 557 + 83979,76612,37500 558 + 88214,58130,89447 559 + 41223,54530,19765 560 + 64038,89086,96939 561 + 40903,78071,28015 562 + 52328,62715,32855 563 + 48952,28792,19246 564 + 30902,57382,41290 565 + 11975,47160,33690 566 + 69369,82431,13194 567 + 65172,80806,58104 568 + 40995,92852,92490 569 + 60515,65805,36585 570 + 45137,49680,85216 571 + 34655,7218,62089 572 + 28724,84314,61817 573 + 27048,38704,1037 574 + 57935,89097,13546 575 + 4354,45108,24438 576 + 32472,51095,76341 577 + 77780,2134,36995 578 + 87577,45014,38241 579 + 69348,85029,37413 580 + 48875,5803,40167 581 + 57388,758,53328 582 + 17390,84879,18256 583 + 56078,61067,6942 584 + 18350,86045,41354 585 + 65405,8159,81527 586 + 52210,30868,14242 587 + 87317,69508,46603 588 + 30737,19477,46555 589 + 21372,94260,47668 590 + 40972,49192,41747 591 + 5296,47118,99694 592 + 90556,73923,31970 593 + 67835,13910,33733 594 + 97420,26992,27392 595 + 75327,71653,72774 596 + 23197,63351,29376 597 + 87067,49909,43893 598 + 66290,2325,65458 599 + 86971,21056,96894 600 + 98500,68105,14469 601 + 39072,19411,50822 602 + 69937,3058,91064 603 + 49555,27762,82031 604 + 75170,51952,55747 605 + 20113,59999,16537 606 + 54446,19676,36639 607 + 48696,22602,66971 608 + 34338,91132,79429 609 + 66438,70994,47617 610 + 79019,11833,36403 611 + 27760,18884,25029 612 + 96584,49580,61333 613 + 6199,44485,43178 614 + 1685,2187,71737 615 + 47482,31135,74132 616 + 58348,648,31362 617 + 36512,71304,68641 618 + 80617,24228,92673 619 + 94226,52090,93535 620 + 15196,45969,1003 621 + 68619,15123,3119 622 + 134,45447,43742 623 + 83786,28744,65894 624 + 40291,50537,8216 625 + 80706,18384,56505 626 + 21768,52917,88590 627 + 6714,44412,82216 628 + 63050,41391,33761 629 + 94339,19975,21513 630 + 9504,71834,51479 631 + 40220,48333,57955 632 + 56424,58494,87068 633 + 43703,88833,88916 634 + 6886,19116,14252 635 + 29360,39186,99198 636 + 32146,89066,14090 637 + 8006,77507,95363 638 + 67259,52263,43447 639 + 20749,33120,39907 640 + 57188,10584,12247 641 + 95475,71856,12198 642 + 89118,10440,97418 643 + 30877,51501,4412 644 + 16510,48567,83854 645 + 95297,9427,1884 646 + 60480,10677,30866 647 + 99422,87128,67139 648 + 36879,69622,46697 649 + 92455,90753,32589 650 + 11205,31066,82017 651 + 28037,30627,15510 652 + 63478,60570,93391 653 + 84521,51058,29246 654 + 43643,7248,83357 655 + 35020,8869,27436 656 + 9419,34339,36624 657 + 61839,60241,64596 658 + 10959,84136,72619 659 + 75204,44524,55287 660 + 21915,82017,49256 661 + 49750,97063,31189 662 + 31975,95967,18704 663 + 27251,47392,40782 664 + 76410,98325,52915 665 + 48350,99154,45519 666 + 31653,12017,93893 667 + 43388,93261,45430 668 + 99398,21140,89310 669 + 90,28676,90243 670 + 29807,48880,75576 671 + 81248,1204,67781 672 + 65225,81737,30811 673 + 25009,48667,7012 674 + 36993,52547,8688 675 + 96801,44164,79301 676 + 24135,84236,23458 677 + 67772,66369,79511 678 + 67528,32674,94977 679 + 10091,96314,65889 680 + 15692,54488,71538 681 + 28509,36103,48177 682 + 24258,48789,42369 683 + 61376,51916,31147 684 + 50379,90292,50272 685 + 2829,99043,39990 686 + 19256,13686,32276 687 + 39955,29729,43262 688 + 4266,37350,96303 689 + 35795,73728,80140 690 + 57387,76074,74442 691 + 87942,81677,80696 692 + 48628,25661,66142 693 + 23961,57266,39363 694 + 56281,54557,77330 695 + 89220,49213,17587 696 + 14139,56950,54071 697 + 51225,90598,9442 698 + 4409,23288,81221 699 + 43006,92371,50606 700 + 83632,98998,24260 701 + 64020,24024,48960 702 + 58588,49887,75107 703 + 71493,58974,91616 704 + 88788,42046,79955 705 + 23453,63618,96825 706 + 60555,85327,45468 707 + 12062,60881,69495 708 + 4481,16536,75882 709 + 84131,11680,68283 710 + 58453,29183,13532 711 + 22967,94147,8442 712 + 44823,81798,80863 713 + 57702,41393,69096 714 + 69772,90611,90380 715 + 74332,35786,85552 716 + 51586,29470,35783 717 + 13029,78458,41054 718 + 26126,33214,78990 719 + 76931,94565,47623 720 + 67734,21896,89140 721 + 32614,41279,74714 722 + 23055,1233,46240 723 + 3618,1545,64772 724 + 25323,8905,57622 725 + 97567,11783,43123 726 + 2464,30255,68387 727 + 71325,51477,73569 728 + 71119,46232,58668 729 + 12128,84037,18246 730 + 67619,10724,13825 731 + 60396,79248,83229 732 + 26633,69182,80938 733 + 92728,25144,35827 734 + 90453,87466,97937 735 + 68038,32690,29917 736 + 51472,58402,93704 737 + 37641,2857,70409 738 + 8707,88320,42363 739 + 13820,40220,19400 740 + 8898,80488,35258 741 + 8103,14748,1721 742 + 73327,45549,90563 743 + 83271,33044,95175 744 + 50544,80889,5749 745 + 82013,73979,3638 746 + 51557,11698,26489 747 + 94279,75035,59998 748 + 53457,38779,48695 749 + 52897,53696,58133 750 + 52455,63415,94369 751 + 88006,34784,81714 752 + 21248,28234,59140 753 + 99868,90640,63581 754 + 39460,79896,41473 755 + 8024,16605,14067 756 + 18805,38463,92672 757 + 12729,38981,43996 758 + 84016,53645,47435 759 + 43332,88246,21453 760 + 57091,56350,12573 761 + 94650,80014,59801 762 + 5724,74670,61762 763 + 43771,2614,92057 764 + 41034,41960,5920 765 + 48180,67061,48295 766 + 59802,96719,91668 767 + 82350,63241,90078 768 + 13297,36984,61190 769 + 7586,18302,43043 770 + 23736,89593,55066 771 + 53943,54312,58012 772 + 11217,74922,56027 773 + 57104,98807,2160 774 + 73751,85487,99503 775 + 61169,32506,61992 776 + 77636,34540,19030 777 + 14276,36863,89733 778 + 32546,53962,12669 779 + 78925,37411,98550 780 + 52204,6602,29527 781 + 75581,12110,95415 782 + 20501,44750,88808 783 + 26724,9079,59085 784 + 2017,65960,54512 785 + 56245,56320,82717 786 + 67262,88827,66007 787 + 46002,60637,20815 788 + 10934,72795,54271 789 + 2284,95037,65832 790 + 24170,92018,60890 791 + 28849,61756,97149 792 + 13003,55368,38859 793 + 99221,66749,63207 794 + 80231,86432,57873 795 + 68911,68316,75250 796 + 31330,73067,19275 797 + 30317,41551,28447 798 + 37433,55769,31202 799 + 98208,84114,27259 800 + 20368,11562,46405 801 + 12464,66037,79359 802 + 79788,50931,66537 803 + 82868,86698,27768 804 + 60856,6657,32277 805 + 77524,77176,98128 806 + 68053,94965,63859 807 + 99440,63447,4920 808 + 66905,3239,15512 809 + 70937,92111,55957 810 + 76870,64259,38353 811 + 52990,70023,3119 812 + 5225,3407,29003 813 + 35535,47349,60468 814 + 64419,24598,66841 815 + 23124,99377,97306 816 + 41445,75960,87312 817 + 29,79614,96488 818 + 40757,24706,65304 819 + 72871,66262,9428 820 + 8394,28591,85564 821 + 99624,94585,87333 822 + 98579,76963,38444 823 + 58722,8508,12293 824 + 81151,18126,33208 825 + 87470,50769,59442 826 + 96916,14421,66709 827 + 43954,60341,84693 828 + 35019,59265,60115 829 + 30657,49485,56286 830 + 96809,12172,1939 831 + 97949,17093,47327 832 + 40195,1945,37915 833 + 37707,75241,8103 834 + 37706,48368,20374 835 + 4197,10480,76888 836 + 26822,96992,12337 837 + 80447,23191,41378 838 + 71437,33537,56879 839 + 46330,94668,51855 840 + 43250,79419,76879 841 + 86245,91089,26584 842 + 61134,62077,1966 843 + 28531,67265,6522 844 + 6519,59360,40573 845 + 26669,38116,72146 846 + 65382,26810,34544 847 + 84589,89836,36848 848 + 52902,53791,52146 849 + 45450,28077,20204 850 + 25505,22489,68073 851 + 28347,83143,83558 852 + 72191,36483,58030 853 + 4292,63221,53866 854 + 48323,69907,20127 855 + 25932,22001,33483 856 + 81436,72789,57465 857 + 19012,5056,61362 858 + 34218,8154,31347 859 + 7344,54825,84905 860 + 12109,99815,39856 861 + 24152,67907,72880 862 + 27793,18546,94859 863 + 7984,26267,65461 864 + 4363,95039,76444 865 + 30253,85781,56038 866 + 93793,64059,93430 867 + 1886,53564,60321 868 + 81174,51044,73504 869 + 62489,17019,50553 870 + 67975,90669,77617 871 + 40710,39406,67989 872 + 88338,99227,91857 873 + 11793,52390,21732 874 + 51394,86298,57668 875 + 82827,31001,85106 876 + 68945,7310,72003 877 + 32832,92145,81580 878 + 72561,47918,14264 879 + 77209,55782,38313 880 + 81882,74282,21704 881 + 51882,97992,4609 882 + 58414,62933,77634 883 + 74312,98169,34240 884 + 69635,51471,73543 885 + 95490,36491,4990 886 + 90933,43892,84379 887 + 22518,87577,618 888 + 48743,73323,65582 889 + 12912,87770,30423 890 + 7951,89917,16955 891 + 62338,48454,3983 892 + 78985,30506,48876 893 + 10980,79184,48083 894 + 19751,70704,11165 895 + 42018,41812,30011 896 + 48224,18037,19033 897 + 36265,81404,30697 898 + 52144,47177,13700 899 + 1202,24527,75444 900 + 61926,18825,39119 901 + 44256,66959,29756 902 + 88510,28243,67263 903 + 79817,52728,46347 904 + 74769,26651,74914 905 + 34106,4273,3111 906 + 5405,75942,55939 907 + 63583,27417,70584 908 + 63589,4017,29898 909 + 89537,84721,4102 910 + 23895,13525,818 911 + 55790,53172,84029 912 + 38866,83363,11556 913 + 24202,29687,55082 914 + 8936,70989,9152 915 + 66113,18369,22573 916 + 99947,59441,18839 917 + 15584,40548,56886 918 + 90436,50356,40214 919 + 12949,5437,99903 920 + 6281,32050,95178 921 + 41699,7694,41378 922 + 91671,76830,19559 923 + 9037,703,91104 924 + 95575,20178,12207 925 + 16587,15919,39864 926 + 25887,57324,68406 927 + 38003,72567,94216 928 + 98374,14196,16610 929 + 96037,96469,15450 930 + 42172,21383,25053 931 + 65489,43459,58549 932 + 55167,93789,18431 933 + 24299,58888,96156 934 + 11592,53658,82665 935 + 94871,87397,12483 936 + 29741,67002,26247 937 + 97997,29261,86131 938 + 26280,68495,77815 939 + 81429,33879,21139 940 + 9883,94136,48573 941 + 35894,24232,32571 942 + 99011,22571,71267 943 + 83721,35405,11897 944 + 84549,38496,29522 945 + 95788,96526,4885 946 + 79482,4993,18558 947 + 90375,35563,80001 948 + 45078,23672,61548 949 + 42661,94039,93503 950 + 29443,67800,55104 951 + 16420,83111,26200 952 + 44472,8892,57488 953 + 77004,34773,14770 954 + 96651,91718,98062 955 + 92585,73388,18170 956 + 26637,31499,21405 957 + 99116,91302,71556 958 + 89067,61107,71902 959 + 4349,4714,49333 960 + 33985,82952,40223 961 + 37507,78245,64234 962 + 86585,19801,57907 963 + 38675,70025,20078 964 + 90999,63531,51959 965 + 6182,74516,38729 966 + 70705,73562,81522 967 + 37903,61353,35923 968 + 78917,9437,92655 969 + 44521,19185,18798 970 + 8870,20454,27947 971 + 1907,32815,13936 972 + 89352,42076,73494 973 + 81867,13827,89586 974 + 77616,30916,54473 975 + 65459,84941,71773 976 + 20495,75046,34869 977 + 30221,8259,56414 978 + 19924,41498,37072 979 + 89553,61208,41061 980 + 80420,39421,63422 981 + 52007,31570,25760 982 + 91218,47639,31055 983 + 40456,44680,47531 984 + 23147,36507,26039 985 + 42863,48030,16989 986 + 10813,68148,29634 987 + 66041,19018,63221 988 + 43483,8560,53867 989 + 3912,5046,83997 990 + 29896,44185,92195 991 + 54491,66018,47133 992 + 185,69933,7673 993 + 63693,69748,72610 994 + 71856,61515,94293 995 + 63352,24925,15005 996 + 77188,6522,39837 997 + 25301,59078,13114 998 + 59801,92038,55033 999 + 31242,179,85583 1000 + 49267,82002,72084
+20
day8/smallinput.txt
···
··· 1 + 162,817,812 2 + 57,618,57 3 + 906,360,560 4 + 592,479,940 5 + 352,342,300 6 + 466,668,158 7 + 542,29,236 8 + 431,825,988 9 + 739,650,466 10 + 52,470,668 11 + 216,146,977 12 + 819,987,18 13 + 117,168,530 14 + 805,96,715 15 + 346,949,466 16 + 970,615,88 17 + 941,993,340 18 + 862,61,35 19 + 984,92,344 20 + 425,690,689
+23
day8/src/circuit.rs
···
··· 1 + use crate::Point; 2 + use std::fmt::Debug; 3 + 4 + #[derive(Clone, Hash, PartialEq, Eq)] 5 + pub struct Circuit { 6 + pub nodes: Vec<Point>, 7 + pub size: usize, 8 + } 9 + 10 + impl Circuit { 11 + pub fn contains_point(&self, point: &Point) -> bool { 12 + self.nodes.contains(point) 13 + } 14 + } 15 + impl Debug for Circuit { 16 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 17 + writeln!(f, "Circuit {{ "); 18 + for node in &self.nodes { 19 + writeln!(f, "{:?}, ", node)?; 20 + } 21 + writeln!(f, "size: {} }} ", self.size) 22 + } 23 + }
+164
day8/src/main.rs
···
··· 1 + use itertools::Itertools; 2 + use memoize::memoize; 3 + use std::{collections::HashMap, fmt::Debug}; 4 + mod circuit; 5 + use circuit::Circuit; 6 + 7 + #[derive(Debug, Clone, Hash, PartialEq, Eq, Copy, PartialOrd)] 8 + struct Point { 9 + x: u64, 10 + y: u64, 11 + z: u64, 12 + } 13 + 14 + impl Point { 15 + fn new(x: u64, y: u64, z: u64) -> Self { 16 + Point { x, y, z } 17 + } 18 + 19 + fn distance_to(&self, other: &Point) -> u32 { 20 + distance(*self, *other) 21 + } 22 + 23 + fn closest_neighbours(&self, points: &[Point]) -> Vec<u32> { 24 + points 25 + .iter() 26 + .map(|p| { 27 + if p != self { 28 + self.distance_to(p) 29 + } else { 30 + u32::MAX 31 + } 32 + }) 33 + .collect() 34 + } 35 + 36 + fn find_closest(&self, points: &[Point]) -> Option<Point> { 37 + points 38 + .iter() 39 + .min_by_key(|p| { 40 + if **p == *self { 41 + u32::MAX 42 + } else { 43 + self.distance_to(p) 44 + } 45 + }) 46 + .copied() 47 + } 48 + } 49 + 50 + #[memoize] 51 + fn distance(a: Point, b: Point) -> u32 { 52 + ((a.x as i64 - b.x as i64).pow(2) 53 + + (a.y as i64 - b.y as i64).pow(2) 54 + + (a.z as i64 - b.z as i64).pow(2)) 55 + .isqrt() as u32 56 + } 57 + 58 + fn main() { 59 + let input_file = std::fs::read_to_string("smallinput.txt").expect("Failed to read input file"); 60 + let points = input_file 61 + .lines() 62 + .map(|line| { 63 + let parts: Vec<&str> = line.split(',').collect(); 64 + Point::new( 65 + parts[0].parse().expect("Failed to parse x coordinate"), 66 + parts[1].parse().expect("Failed to parse y coordinate"), 67 + parts[2].parse().expect("Failed to parse z coordinate"), 68 + ) 69 + }) 70 + .collect::<Vec<Point>>(); 71 + 72 + // let mut circuits = Vec::new(); 73 + let mut jmap: HashMap<Point, usize> = HashMap::new(); 74 + for (id, p) in points.iter().enumerate() { 75 + jmap.insert(*p, id); 76 + } 77 + 78 + let point_pairs = points 79 + .iter() 80 + .enumerate() 81 + .flat_map(|(i, &p1)| { 82 + points.iter().enumerate().filter_map(move |(j, &p2)| { 83 + if i != j { 84 + let dist = p1.distance_to(&p2); 85 + Some((p1, p2)) 86 + } else { 87 + None 88 + } 89 + }) 90 + }) 91 + .collect::<Vec<(Point, Point)>>(); 92 + 93 + // deduplicate connections 94 + let mut closest_connections: Vec<(Point, Point)> = point_pairs 95 + .iter() 96 + .unique_by(|&&(p1, p2)| if p1 < p2 { (p1, p2) } else { (p2, p1) }) 97 + .copied() 98 + .collect(); 99 + 100 + // sort connections by distance 101 + closest_connections.sort_by(|a, b| distance(a.0, a.1).cmp(&distance(b.0, b.1))); 102 + // println!("Closest connections: {:?}", closest_connections); 103 + 104 + let mut n_connections = 10; 105 + 106 + // okay so basically my idea is we track how many times each size appears 107 + // will also save us the annoying calculation at the end in theory 108 + // if both circuits have sizes, 109 + let mut circuit_sizes: HashMap<usize, usize> = HashMap::new(); 110 + 111 + for (index, point_pair) in closest_connections.iter().enumerate() { 112 + if index >= n_connections { 113 + break; 114 + } 115 + 116 + // initialize circuit sizes for both points if they don't exist 117 + if circuit_sizes.contains_key(&jmap[&point_pair.0]) { 118 + circuit_sizes.insert(jmap[&point_pair.0], 1); 119 + } 120 + if circuit_sizes.contains_key(&jmap[&point_pair.1]) { 121 + circuit_sizes.insert(jmap[&point_pair.1], 1); 122 + } 123 + 124 + if jmap[&point_pair.0] == jmap[&point_pair.1] { 125 + println!( 126 + "Skipping connection between {:?} and {:?} as they are already connected in circuit {}", 127 + point_pair.0, point_pair.1, jmap[&point_pair.0] 128 + ); 129 + n_connections += 1; 130 + continue; 131 + } 132 + let size_0: usize = *circuit_sizes.get(&jmap[&point_pair.0]).unwrap_or(&0); 133 + let size_1: usize = *circuit_sizes.get(&jmap[&point_pair.1]).unwrap_or(&0); 134 + 135 + println!( 136 + "Connecting {:?} from circuit {} and {:?} in circuit {}", 137 + point_pair.1, jmap[&point_pair.1], point_pair.0, jmap[&point_pair.0] 138 + ); 139 + 140 + if size_0 > size_1 { 141 + jmap.insert(point_pair.0, jmap[&point_pair.1]); 142 + circuit_sizes.insert(size_0, circuit_sizes.get(&size_0).unwrap_or(&0) + 1); 143 + } else { 144 + jmap.insert(point_pair.1, jmap[&point_pair.0]); 145 + circuit_sizes.insert(size_1, circuit_sizes.get(&size_1).unwrap_or(&0) + 1); 146 + } 147 + 148 + println!("Circuit sizes: {:?}", circuit_sizes); 149 + } 150 + 151 + let mut circuit_groups = jmap 152 + .values() 153 + .fold(std::collections::HashMap::new(), |mut acc, &val| { 154 + *acc.entry(val).or_insert(0) += 1; 155 + acc 156 + }) 157 + .into_values() 158 + .sorted() 159 + .collect::<Vec<usize>>(); 160 + 161 + circuit_groups.reverse(); 162 + println!("Junction map: {:?}", jmap); 163 + println!("Circuit groups: {:?}", circuit_groups); 164 + }
+6
day8/toyinput.txt
···
··· 1 + 1,1,1 2 + 2,2,2 3 + 100,100,100 4 + 101,101,101 5 + 500,500,500 6 + 501,501,501
+202
day9/Cargo.lock
···
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.21" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.13" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.5" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.11" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.53" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.53" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.49" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.6" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "day9" 103 + version = "0.1.0" 104 + dependencies = [ 105 + "clap", 106 + "itertools", 107 + ] 108 + 109 + [[package]] 110 + name = "either" 111 + version = "1.15.0" 112 + source = "registry+https://github.com/rust-lang/crates.io-index" 113 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 114 + 115 + [[package]] 116 + name = "heck" 117 + version = "0.5.0" 118 + source = "registry+https://github.com/rust-lang/crates.io-index" 119 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 120 + 121 + [[package]] 122 + name = "is_terminal_polyfill" 123 + version = "1.70.2" 124 + source = "registry+https://github.com/rust-lang/crates.io-index" 125 + checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" 126 + 127 + [[package]] 128 + name = "itertools" 129 + version = "0.14.0" 130 + source = "registry+https://github.com/rust-lang/crates.io-index" 131 + checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 132 + dependencies = [ 133 + "either", 134 + ] 135 + 136 + [[package]] 137 + name = "once_cell_polyfill" 138 + version = "1.70.2" 139 + source = "registry+https://github.com/rust-lang/crates.io-index" 140 + checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" 141 + 142 + [[package]] 143 + name = "proc-macro2" 144 + version = "1.0.103" 145 + source = "registry+https://github.com/rust-lang/crates.io-index" 146 + checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" 147 + dependencies = [ 148 + "unicode-ident", 149 + ] 150 + 151 + [[package]] 152 + name = "quote" 153 + version = "1.0.42" 154 + source = "registry+https://github.com/rust-lang/crates.io-index" 155 + checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" 156 + dependencies = [ 157 + "proc-macro2", 158 + ] 159 + 160 + [[package]] 161 + name = "strsim" 162 + version = "0.11.1" 163 + source = "registry+https://github.com/rust-lang/crates.io-index" 164 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 165 + 166 + [[package]] 167 + name = "syn" 168 + version = "2.0.111" 169 + source = "registry+https://github.com/rust-lang/crates.io-index" 170 + checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" 171 + dependencies = [ 172 + "proc-macro2", 173 + "quote", 174 + "unicode-ident", 175 + ] 176 + 177 + [[package]] 178 + name = "unicode-ident" 179 + version = "1.0.22" 180 + source = "registry+https://github.com/rust-lang/crates.io-index" 181 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 182 + 183 + [[package]] 184 + name = "utf8parse" 185 + version = "0.2.2" 186 + source = "registry+https://github.com/rust-lang/crates.io-index" 187 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 188 + 189 + [[package]] 190 + name = "windows-link" 191 + version = "0.2.1" 192 + source = "registry+https://github.com/rust-lang/crates.io-index" 193 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 194 + 195 + [[package]] 196 + name = "windows-sys" 197 + version = "0.61.2" 198 + source = "registry+https://github.com/rust-lang/crates.io-index" 199 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 200 + dependencies = [ 201 + "windows-link", 202 + ]
+8
day9/Cargo.toml
···
··· 1 + [package] 2 + name = "day9" 3 + version = "0.1.0" 4 + edition = "2024" 5 + 6 + [dependencies] 7 + clap = { version = "4.5.53", features = ["derive"] } 8 + itertools = "0.14.0"
+496
day9/input.txt
···
··· 1 + 97819,50153 2 + 97819,51361 3 + 97695,51361 4 + 97695,52560 5 + 97478,52560 6 + 97478,53816 7 + 98081,53816 8 + 98081,54975 9 + 97418,54975 10 + 97418,56200 11 + 97473,56200 12 + 97473,57459 13 + 97673,57459 14 + 97673,58694 15 + 97628,58694 16 + 97628,59810 17 + 96976,59810 18 + 96976,60944 19 + 96485,60944 20 + 96485,62061 21 + 95974,62061 22 + 95974,63248 23 + 95748,63248 24 + 95748,64662 25 + 96214,64662 26 + 96214,65764 27 + 95642,65764 28 + 95642,66755 29 + 94801,66755 30 + 94801,67896 31 + 94390,67896 32 + 94390,69110 33 + 94141,69110 34 + 94141,70168 35 + 93526,70168 36 + 93526,71446 37 + 93369,71446 38 + 93369,72267 39 + 92298,72267 40 + 92298,73226 41 + 91531,73226 42 + 91531,74355 43 + 91073,74355 44 + 91073,75528 45 + 90666,75528 46 + 90666,76633 47 + 90131,76633 48 + 90131,77691 49 + 89515,77691 50 + 89515,78771 51 + 88919,78771 52 + 88919,79538 53 + 87908,79538 54 + 87908,80478 55 + 87135,80478 56 + 87135,81550 57 + 86514,81550 58 + 86514,81966 59 + 85154,81966 60 + 85154,83369 61 + 84879,83369 62 + 84879,84065 63 + 83848,84065 64 + 83848,84550 65 + 82633,84550 66 + 82633,85553 67 + 81914,85553 68 + 81914,86608 69 + 81224,86608 70 + 81224,87400 71 + 80297,87400 72 + 80297,87882 73 + 79129,87882 74 + 79129,89069 75 + 78496,89069 76 + 78496,89747 77 + 77476,89747 78 + 77476,89792 79 + 76042,89792 80 + 76042,90412 81 + 75009,90412 82 + 75009,91317 83 + 74144,91317 84 + 74144,91746 85 + 72996,91746 86 + 72996,92544 87 + 72050,92544 88 + 72050,93038 89 + 70940,93038 90 + 70940,93570 91 + 69850,93570 92 + 69850,93848 93 + 68650,93848 94 + 68650,94995 95 + 67806,94995 96 + 67806,95319 97 + 66619,95319 98 + 66619,95177 99 + 65280,95177 100 + 65280,95556 101 + 64133,95556 102 + 64133,96445 103 + 63128,96445 104 + 63128,96494 105 + 61879,96494 106 + 61879,96939 107 + 60734,96939 108 + 60734,97073 109 + 59516,97073 110 + 59516,97437 111 + 58345,97437 112 + 58345,97884 113 + 57178,97884 114 + 57178,97310 115 + 55871,97310 116 + 55871,97628 117 + 54689,97628 118 + 54689,97534 119 + 53466,97534 120 + 53466,97639 121 + 52263,97639 122 + 52263,98179 123 + 51066,98179 124 + 51066,98009 125 + 49846,98009 126 + 49846,97587 127 + 48641,97587 128 + 48641,97442 129 + 47441,97442 130 + 47441,97554 131 + 46225,97554 132 + 46225,97865 133 + 44977,97865 134 + 44977,97399 135 + 43808,97399 136 + 43808,97907 137 + 42503,97907 138 + 42503,96814 139 + 41454,96814 140 + 41454,97405 141 + 40099,97405 142 + 40099,96388 143 + 39078,96388 144 + 39078,96382 145 + 37832,96382 146 + 37832,96415 147 + 36557,96415 148 + 36557,95283 149 + 35632,95283 150 + 35632,95832 151 + 34169,95832 152 + 34169,94609 153 + 33315,94609 154 + 33315,94140 155 + 32203,94140 156 + 32203,93620 157 + 31115,93620 158 + 31115,93612 159 + 29791,93612 160 + 29791,92816 161 + 28827,92816 162 + 28827,92854 163 + 27439,92854 164 + 27439,92120 165 + 26444,92120 166 + 26444,91350 167 + 25479,91350 168 + 25479,91029 169 + 24243,91029 170 + 24243,90150 171 + 23354,90150 172 + 23354,88965 173 + 22693,88965 174 + 22693,88616 175 + 21452,88616 176 + 21452,87622 177 + 20684,87622 178 + 20684,87088 179 + 19560,87088 180 + 19560,86108 181 + 18800,86108 182 + 18800,85166 183 + 18022,85166 184 + 18022,84526 185 + 16968,84526 186 + 16968,83798 187 + 15983,83798 188 + 15983,83275 189 + 14768,83275 190 + 14768,82119 191 + 14219,82119 192 + 14219,81229 193 + 13385,81229 194 + 13385,80353 195 + 12529,80353 196 + 12529,78959 197 + 12338,78959 198 + 12338,78258 199 + 11257,78258 200 + 11257,77432 201 + 10316,77432 202 + 10316,76306 203 + 9804,76306 204 + 9804,75257 205 + 9186,75257 206 + 9186,74070 207 + 8808,74070 208 + 8808,73346 209 + 7617,73346 210 + 7617,72112 211 + 7336,72112 212 + 7336,71130 213 + 6571,71130 214 + 6571,69839 215 + 6453,69839 216 + 6453,68884 217 + 5601,68884 218 + 5601,67730 219 + 5195,67730 220 + 5195,66371 221 + 5358,66371 222 + 5358,65433 223 + 4369,65433 224 + 4369,64085 225 + 4595,64085 226 + 4595,62951 227 + 4183,62951 228 + 4183,61942 229 + 3257,61942 230 + 3257,60761 231 + 2939,60761 232 + 2939,59474 233 + 3133,59474 234 + 3133,58235 235 + 3186,58235 236 + 3186,57057 237 + 2924,57057 238 + 2924,55964 239 + 1943,55964 240 + 1943,54727 241 + 1983,54727 242 + 1983,53526 243 + 1643,53526 244 + 1643,52258 245 + 2454,52258 246 + 2454,51063 247 + 1936,51063 248 + 1936,50143 249 + 94800,50143 250 + 94800,48628 251 + 1967,48628 252 + 1967,47420 253 + 2174,47420 254 + 2174,46235 255 + 2572,46235 256 + 2572,45009 257 + 2439,45009 258 + 2439,43789 259 + 2455,43789 260 + 2455,42617 261 + 2817,42617 262 + 2817,41320 263 + 2452,41320 264 + 2452,40171 265 + 2941,40171 266 + 2941,39071 267 + 3579,39071 268 + 3579,37926 269 + 3978,37926 270 + 3978,36593 271 + 3706,36593 272 + 3706,35458 273 + 4168,35458 274 + 4168,34184 275 + 4208,34184 276 + 4208,33283 277 + 5303,33283 278 + 5303,32050 279 + 5479,32050 280 + 5479,31124 281 + 6400,31124 282 + 6400,29843 283 + 6498,29843 284 + 6498,28596 285 + 6717,28596 286 + 6717,27511 287 + 7282,27511 288 + 7282,26340 289 + 7694,26340 290 + 7694,25288 291 + 8327,25288 292 + 8327,24719 293 + 9728,24719 294 + 9728,23535 295 + 10122,23535 296 + 10122,22481 297 + 10731,22481 298 + 10731,21219 299 + 11068,21219 300 + 11068,20260 301 + 11832,20260 302 + 11832,19402 303 + 12719,19402 304 + 12719,18681 305 + 13753,18681 306 + 13753,17399 307 + 14147,17399 308 + 14147,16842 309 + 15341,16842 310 + 15341,15813 311 + 16031,15813 312 + 16031,15227 313 + 17157,15227 314 + 17157,14012 315 + 17695,14012 316 + 17695,13399 317 + 18782,13399 318 + 18782,12438 319 + 19572,12438 320 + 19572,12015 321 + 20791,12015 322 + 20791,11392 323 + 21840,11392 324 + 21840,10247 325 + 22519,10247 326 + 22519,10010 327 + 23828,10010 328 + 23828,9084 329 + 24678,9084 330 + 24678,8491 331 + 25744,8491 332 + 25744,7863 333 + 26788,7863 334 + 26788,6987 335 + 27707,6987 336 + 27707,6573 337 + 28870,6573 338 + 28870,5960 339 + 29935,5960 340 + 29935,5408 341 + 31033,5408 342 + 31033,4964 343 + 32177,4964 344 + 32177,4548 345 + 33332,4548 346 + 33332,4435 347 + 34588,4435 348 + 34588,4188 349 + 35787,4188 350 + 35787,4063 351 + 37014,4063 352 + 37014,3490 353 + 38116,3490 354 + 38116,3175 355 + 39292,3175 356 + 39292,3040 357 + 40506,3040 358 + 40506,2347 359 + 41616,2347 360 + 41616,2950 361 + 42946,2950 362 + 42946,2088 363 + 44053,2088 364 + 44053,2542 365 + 45327,2542 366 + 45327,2293 367 + 46520,2293 368 + 46520,2372 369 + 47737,2372 370 + 47737,1604 371 + 48928,1604 372 + 48928,1823 373 + 50154,1823 374 + 50154,2178 375 + 51365,2178 376 + 51365,1738 377 + 52602,1738 378 + 52602,1788 379 + 53826,1788 380 + 53826,2273 381 + 55007,2273 382 + 55007,2068 383 + 56260,2068 384 + 56260,2614 385 + 57414,2614 386 + 57414,3231 387 + 58537,3231 388 + 58537,2920 389 + 59832,2920 390 + 59832,3681 391 + 60904,3681 392 + 60904,3946 393 + 62081,3946 394 + 62081,4131 395 + 63283,4131 396 + 63283,4652 397 + 64387,4652 398 + 64387,4844 399 + 65596,4844 400 + 65596,5340 401 + 66703,5340 402 + 66703,5487 403 + 67945,5487 404 + 67945,5728 405 + 69166,5728 406 + 69166,6794 407 + 70019,6794 408 + 70019,7116 409 + 71206,7116 410 + 71206,7226 411 + 72517,7226 412 + 72517,7707 413 + 73651,7707 414 + 73651,8446 415 + 74640,8446 416 + 74640,9118 417 + 75664,9118 418 + 75664,10000 419 + 76545,10000 420 + 76545,10362 421 + 77777,10362 422 + 77777,11195 423 + 78686,11195 424 + 78686,12344 425 + 79340,12344 426 + 79340,12818 427 + 80515,12818 428 + 80515,13383 429 + 81638,13383 430 + 81638,14591 431 + 82196,14591 432 + 82196,14977 433 + 83505,14977 434 + 83505,16181 435 + 84036,16181 436 + 84036,16826 437 + 85122,16826 438 + 85122,17980 439 + 85670,17980 440 + 85670,19070 441 + 86263,19070 442 + 86263,19578 443 + 87553,19578 444 + 87553,20767 445 + 88016,20767 446 + 88016,21839 447 + 88608,21839 448 + 88608,22815 449 + 89324,22815 450 + 89324,23773 451 + 90072,23773 452 + 90072,24865 453 + 90613,24865 454 + 90613,25784 455 + 91439,25784 456 + 91439,26819 457 + 92080,26819 458 + 92080,27995 459 + 92456,27995 460 + 92456,28855 461 + 93456,28855 462 + 93456,30075 463 + 93733,30075 464 + 93733,31143 465 + 94332,31143 466 + 94332,32193 467 + 94995,32193 468 + 94995,33560 469 + 94829,33560 470 + 94829,34660 471 + 95352,34660 472 + 95352,35816 473 + 95717,35816 474 + 95717,36836 475 + 96569,36836 476 + 96569,38156 477 + 96354,38156 478 + 96354,39394 479 + 96376,39394 480 + 96376,40441 481 + 97281,40441 482 + 97281,41617 483 + 97650,41617 484 + 97650,42900 485 + 97353,42900 486 + 97353,44047 487 + 97963,44047 488 + 97963,45312 489 + 97609,45312 490 + 97609,46476 491 + 98312,46476 492 + 98312,47743 493 + 97494,47743 494 + 97494,48929 495 + 98347,48929 496 + 98347,50153
+8
day9/smallinput.txt
···
··· 1 + 7,1 2 + 11,1 3 + 11,7 4 + 9,7 5 + 9,5 6 + 2,5 7 + 2,3 8 + 7,3
+55
day9/src/floortiles.rs
···
··· 1 + use itertools::Itertools; 2 + use std::fmt::Display; 3 + 4 + #[derive(Debug)] 5 + pub struct FloorTiles { 6 + pub red_tiles: Vec<(usize, usize)>, 7 + pub rows: usize, 8 + pub cols: usize, 9 + } 10 + 11 + impl FloorTiles { 12 + pub fn load(filename: &str) -> Self { 13 + println!("trying to read {}", filename); 14 + let contents = std::fs::read_to_string(filename).expect("unable to read file as string"); 15 + let red_tiles: Vec<(usize, usize)> = contents 16 + .lines() 17 + .map(|line| { 18 + line.split(',') 19 + .map(|num| num.parse().expect("Could not parse {num}")) 20 + .collect_tuple() 21 + .expect("Unable to parse tuple") 22 + }) 23 + .collect(); 24 + FloorTiles { 25 + rows: red_tiles.iter().fold(0, |a, b| a.max(b.0)) + 1, 26 + cols: red_tiles.iter().fold(0, |a, b| a.max(b.1)) + 1, 27 + red_tiles, 28 + } 29 + } 30 + 31 + fn build_grid(&self) -> Vec<Vec<char>> { 32 + let mut grid = vec![vec!['.'; self.rows + 1]; self.cols + 1]; 33 + for &(row, col) in &self.red_tiles { 34 + if row < self.rows && col < self.cols { 35 + grid[col][row] = '#'; 36 + } 37 + } 38 + grid 39 + } 40 + 41 + fn is_inside(&self, tile: (usize, usize)) -> bool { 42 + tile.0 < self.rows && tile.1 < self.cols 43 + } 44 + } 45 + 46 + impl Display for FloorTiles { 47 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 48 + let grid = self.build_grid(); 49 + writeln!(f)?; 50 + for row in grid { 51 + writeln!(f, "{}", row.iter().collect::<String>())?; 52 + } 53 + Ok(()) 54 + } 55 + }
+46
day9/src/main.rs
···
··· 1 + use clap::Parser; 2 + mod floortiles; 3 + mod rectangle; 4 + 5 + #[derive(Parser, Debug)] 6 + struct Args { 7 + #[clap(short, long)] 8 + file: String, 9 + #[clap(short, long)] 10 + debug: bool, 11 + } 12 + 13 + fn main() { 14 + let args = Args::parse(); 15 + 16 + let tiles = floortiles::FloorTiles::load(&args.file); 17 + 18 + let mut max_area = 0; 19 + for tilea in 0..tiles.red_tiles.len() { 20 + for tileb in tilea..tiles.red_tiles.len() { 21 + if tiles.red_tiles[tilea].0 == tiles.red_tiles[tileb].0 22 + || tiles.red_tiles[tilea].1 == tiles.red_tiles[tileb].1 23 + { 24 + continue; 25 + } 26 + let rect = rectangle::Rectangle::new(tiles.red_tiles[tilea], tiles.red_tiles[tileb]); 27 + if args.debug { 28 + println!( 29 + "Rectangle from {:?} to {:?} has area: {}", 30 + rect.corn_a, 31 + rect.corn_b, 32 + rect.area() 33 + ); 34 + } 35 + 36 + if rect.area() > max_area { 37 + max_area = rect.area(); 38 + } 39 + } 40 + } 41 + 42 + if args.debug { 43 + println!("Red Tile Locations: {}", tiles); 44 + } 45 + println!("Maximum Area: {}", max_area); 46 + }
+32
day9/src/rectangle.rs
···
··· 1 + pub struct Rectangle { 2 + pub corn_a: (usize, usize), 3 + pub corn_b: (usize, usize), 4 + pub width: usize, 5 + pub height: usize, 6 + } 7 + 8 + impl Rectangle { 9 + pub fn new(corn_a: (usize, usize), corn_b: (usize, usize)) -> Self { 10 + let width = corn_a 11 + .0 12 + .max(corn_b.0) 13 + .saturating_sub(corn_a.0.min(corn_b.0)) 14 + + 1; 15 + let height = corn_a 16 + .1 17 + .max(corn_b.1) 18 + .saturating_sub(corn_a.1.min(corn_b.1)) 19 + + 1; 20 + 21 + Self { 22 + corn_a, 23 + corn_b, 24 + width, 25 + height, 26 + } 27 + } 28 + 29 + pub fn area(&self) -> usize { 30 + self.width * self.height 31 + } 32 + }