use std::collections::{BTreeMap, HashMap}; use core::read_data; struct EncryptedRoom { encrypted_name: String, sector_id: u32, checksum: String, } fn main() { let binding = read_data("2016_04_data.txt"); let inputs = binding.lines(); for line in inputs { let (balance, checksum) = line.split_once('[').unwrap(); let (checksum, _) = checksum.split_at(5); let parts = balance.split("-"); let num_parts = parts.clone().count(); let mut working_enc = String::new(); let mut sector_id = 0; // walk through the parts to find the sector id for (index, part) in parts.enumerate() { if index < ( num_parts - 1 ) { working_enc += part; } else { sector_id = part.parse::().unwrap(); } } // count the characters in the string let mut hash: HashMap = HashMap::new(); for current_char in working_enc.chars() { hash.entry(current_char).and_modify(|mut x| *x += 1).or_insert(1); } // sort the hash into a flipped btreemap println!("[{line}] / ENCRYPTED = [{working_enc}] / Sector ID : [{sector_id}] / checksum [{checksum}]"); println!("HASH: {hash:?}"); // now find the 5 most frequently occurring characters in alphabetical order // once we have the new value, compare it to the checksum } }