--- /dev/null
+use std::io::Read;
+use std::error::Error;
+use std::fs::File;
+
+use std::collections::HashMap;
+
+pub fn run(input_file: &str) -> Result<(), Box<dyn Error>> {
+ let mut f = File::open(input_file)?;
+ let mut input = String::new();
+ f.read_to_string(&mut input)?;
+
+ let res = run_part1(&input)?;
+ println!("{res}");
+
+ let res = run_part2(&input)?;
+ println!("{res}");
+
+ Ok(())
+}
+
+#[derive(Debug)]
+struct Puzzle {
+ instructions: Vec<char>,
+ nodes: HashMap<String, (String, String)>,
+}
+
+impl Puzzle {
+ pub fn new(input: &str) -> Self {
+ let (str_instructions, str_nodes) = input.split_once("\n\n").unwrap();
+
+ let instructions: Vec<char> = str_instructions.chars().collect();
+ let nodes: HashMap<String, (String, String)> = str_nodes.split('\n')
+ .filter(|l| !l.is_empty())
+ .map(|l| {
+ let (node, value) = l.split_once(" = ").unwrap();
+ let x: &[_] = &['(',')'];
+ let (left, right) = value.trim_matches(x).split_once(", ").unwrap();
+ (node.to_string(), (left.to_string(), right.to_string()))
+ })
+ .collect();
+
+ Self {
+ instructions,
+ nodes,
+ }
+ }
+}
+
+fn run_part1(input: &str) -> Result<u32, Box<dyn Error>> {
+ println!("Running day08 - part 1");
+ let puzzle = Puzzle::new(input);
+
+ let mut step = 0;
+ let mut i = 0;
+ let mut found_ZZZ = false;
+ let mut node: String = String::from("AAA");
+
+ while !found_ZZZ {
+ if i >= puzzle.instructions.len() {
+ i = 0;
+ }
+
+ let new_node = match puzzle.instructions[i] {
+ 'L' => &puzzle.nodes.get(&node).unwrap().0,
+ 'R' => &puzzle.nodes.get(&node).unwrap().1,
+ _ => unreachable!(),
+ };
+
+ node = new_node.to_string();
+ if node == "ZZZ".to_string() {
+ found_ZZZ = true;
+ }
+ i += 1;
+ step += 1;
+ }
+
+ let res = step;
+ Ok(res)
+}
+
+fn run_part2(input: &str) -> Result<u32, Box<dyn Error>> {
+ println!("Running day08 - part 2");
+ let res = 0;
+ Ok(res)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ static TEXT_INPUT: &str = "";
+
+ #[test]
+ fn day08_part1_example1() {
+ let input = "\
+RL
+
+AAA = (BBB, CCC)
+BBB = (DDD, EEE)
+CCC = (ZZZ, GGG)
+DDD = (DDD, DDD)
+EEE = (EEE, EEE)
+GGG = (GGG, GGG)
+ZZZ = (ZZZ, ZZZ)";
+ let res = run_part1(&input);
+ assert_eq!(2, res.unwrap());
+ }
+
+ #[test]
+ fn day08_part1_example2() {
+ let input = "\
+LLR
+
+AAA = (BBB, BBB)
+BBB = (AAA, ZZZ)
+ZZZ = (ZZZ, ZZZ)";
+ let res = run_part1(&input);
+ assert_eq!(6, res.unwrap());
+ }
+
+ #[test]
+ fn day08_part2() {
+ let res = run_part2(TEXT_INPUT);
+ assert_eq!(0, res.unwrap());
+ }
+}