├── .gitignore ├── 02 ├── example.txt ├── rock-paper-scissors.rs └── rock-paper-scissors2.rs ├── day_06 ├── example1.txt ├── example2.txt ├── example3.txt ├── example4.txt ├── Cargo.toml ├── src │ └── main.rs ├── input.txt └── Cargo.lock ├── day_08 ├── example.txt ├── Cargo.lock ├── Cargo.toml ├── example2.txt ├── src │ └── main.rs └── input.txt ├── day_09 ├── example.txt ├── example2.txt ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── day_16 ├── src │ └── main.rs ├── Cargo.toml ├── example.txt └── input.txt ├── day_12 ├── example.txt ├── Cargo.toml ├── src │ └── main.rs └── input.txt ├── 01 ├── Justfile ├── hello.rs ├── elf-count-top-three.rs └── elf-count.rs ├── day_05 ├── example.txt ├── Cargo.lock ├── Cargo.toml ├── src │ └── main.rs └── input.txt ├── 03 ├── Cargo.lock ├── Cargo.toml ├── src │ └── main.rs └── input.txt ├── day_04 ├── Cargo.lock ├── Cargo.toml ├── src │ └── main.rs └── input.txt ├── day_07 ├── Cargo.lock ├── Cargo.toml ├── example.txt ├── src │ └── main.rs └── input.txt ├── day_10 ├── Cargo.lock ├── Cargo.toml ├── input.txt ├── example.txt └── src │ └── main.rs ├── day_14 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── day_03_part_2 ├── Cargo.lock ├── Cargo.toml ├── src │ └── main.rs └── input.txt ├── day_04_part_2 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── day_10_part_2 ├── Cargo.lock ├── Cargo.toml └── src │ └── main.rs ├── day_11 ├── Cargo.toml ├── example.txt ├── Cargo.lock ├── input.txt └── src │ └── main.rs ├── day_15 ├── Cargo.toml ├── example.txt ├── input.txt └── src │ └── main.rs ├── day_13 ├── Cargo.toml ├── example.txt ├── Cargo.lock └── src │ └── main.rs ├── README.md └── run-all.sh /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /02/example.txt: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z -------------------------------------------------------------------------------- /day_06/example1.txt: -------------------------------------------------------------------------------- 1 | bvwbjplbgvbhsrlpgdmjqwftvncz 2 | -------------------------------------------------------------------------------- /day_06/example2.txt: -------------------------------------------------------------------------------- 1 | nppdvjthqldpwncqszvftbrmjlhg 2 | -------------------------------------------------------------------------------- /day_06/example3.txt: -------------------------------------------------------------------------------- 1 | nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg 2 | -------------------------------------------------------------------------------- /day_06/example4.txt: -------------------------------------------------------------------------------- 1 | zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw 2 | -------------------------------------------------------------------------------- /day_08/example.txt: -------------------------------------------------------------------------------- 1 | 30373 2 | 25512 3 | 65332 4 | 33549 5 | 35390 -------------------------------------------------------------------------------- /day_09/example.txt: -------------------------------------------------------------------------------- 1 | R 4 2 | U 4 3 | L 3 4 | D 1 5 | R 4 6 | D 1 7 | L 5 8 | R 2 -------------------------------------------------------------------------------- /day_16/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /day_09/example2.txt: -------------------------------------------------------------------------------- 1 | R 5 2 | U 8 3 | L 8 4 | D 3 5 | R 17 6 | D 10 7 | L 25 8 | U 20 -------------------------------------------------------------------------------- /day_12/example.txt: -------------------------------------------------------------------------------- 1 | Sabqponm 2 | abcryxxl 3 | accszExk 4 | acctuvwj 5 | abdefghi 6 | -------------------------------------------------------------------------------- /01/Justfile: -------------------------------------------------------------------------------- 1 | run: build 2 | ./elf-count 3 | ./elf-count-top-three 4 | 5 | build: 6 | rustc elf-count.rs 7 | rustc elf-count-top-three.rs 8 | -------------------------------------------------------------------------------- /01/hello.rs: -------------------------------------------------------------------------------- 1 | // Hello world in Rust 2 | fn main() { 3 | println!("Hello, world!"); 4 | } 5 | /* To compile and run: 6 | rustc hello.rs 7 | ./hello 8 | */ 9 | -------------------------------------------------------------------------------- /day_05/example.txt: -------------------------------------------------------------------------------- 1 | [D] 2 | [N] [C] 3 | [Z] [M] [P] 4 | 1 2 3 5 | 6 | move 1 from 2 to 1 7 | move 3 from 1 to 3 8 | move 2 from 2 to 1 9 | move 1 from 1 to 2 -------------------------------------------------------------------------------- /03/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day3" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_04/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_04" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_05/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_05" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_07/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_07" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_08/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_08" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_09/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_09" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_10/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_10" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_14/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_14" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_03_part_2/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_03_part_2" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_04_part_2/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_04_part_2" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /day_10_part_2/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "day_10_part_2" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /03/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day3" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_04/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_04" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_05/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_05" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_07/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_07" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_08/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_08" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_09/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_09" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_10/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_10" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_14/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_14" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_16/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_16" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_03_part_2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_03_part_2" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_04_part_2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_04_part_2" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_10_part_2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_10_part_2" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /day_08/example2.txt: -------------------------------------------------------------------------------- 1 | 21000134031120241101 2 | 00103034425403355252 3 | 12300435123441545650 4 | 24344430101013050350 5 | 30133305443534264655 6 | 31333311503403303246 7 | 43444132424004411013 8 | 02001304302526160460 9 | 22540540153003664663 -------------------------------------------------------------------------------- /day_11/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_11" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | regex = "1.7.0" 10 | -------------------------------------------------------------------------------- /day_15/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_15" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | regex = "1.7.0" 10 | -------------------------------------------------------------------------------- /day_13/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_13" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | parameterized = "1.0.1" 10 | -------------------------------------------------------------------------------- /day_12/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_12" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | graphalgs = "0.1.0" 10 | petgraph = "0.6.2" 11 | -------------------------------------------------------------------------------- /day_06/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "day_06" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | clap = { version = "4.0.29", features = ["derive"] } 10 | -------------------------------------------------------------------------------- /day_13/example.txt: -------------------------------------------------------------------------------- 1 | [1,1,3,1,1] 2 | [1,1,5,1,1] 3 | 4 | [[1],[2,3,4]] 5 | [[1],4] 6 | 7 | [9] 8 | [[8,7,6]] 9 | 10 | [[4,4],4,4] 11 | [[4,4],4,4,4] 12 | 13 | [7,7,7,7] 14 | [7,7,7] 15 | 16 | [] 17 | [3] 18 | 19 | [[[]]] 20 | [[]] 21 | 22 | [1,[2,[3,[4,[5,6,7]]]],8,9] 23 | [1,[2,[3,[4,[5,6,0]]]],8,9] -------------------------------------------------------------------------------- /day_07/example.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # advent-of-code-2022-in-rust 2 | 3 | See [Learning Rust with ChatGPT, Copilot and Advent of Code](https://simonwillison.net/2022/Dec/5/rust-chatgpt-copilot/) 4 | 5 | Copilot and ChatGPT assisted [Advent of Code 2022](https://adventofcode.com/2022) to learn Rust. 6 | 7 | See the [closed issues](https://github.com/simonw/advent-of-code-2022-in-rust/issues?q=is%3Aissue+is%3Aclosed) in this repo for detailed threads showing what I've learned so far. 8 | -------------------------------------------------------------------------------- /day_16/example.txt: -------------------------------------------------------------------------------- 1 | Valve AA has flow rate=0; tunnels lead to valves DD, II, BB 2 | Valve BB has flow rate=13; tunnels lead to valves CC, AA 3 | Valve CC has flow rate=2; tunnels lead to valves DD, BB 4 | Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE 5 | Valve EE has flow rate=3; tunnels lead to valves FF, DD 6 | Valve FF has flow rate=0; tunnels lead to valves EE, GG 7 | Valve GG has flow rate=0; tunnels lead to valves FF, HH 8 | Valve HH has flow rate=22; tunnel leads to valve GG 9 | Valve II has flow rate=0; tunnels lead to valves AA, JJ 10 | Valve JJ has flow rate=21; tunnel leads to valve II 11 | 12 | -------------------------------------------------------------------------------- /day_11/example.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 28 | -------------------------------------------------------------------------------- /day_15/example.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 14 | Sensor at x=20, y=1: closest beacon is at x=15, y=3 15 | -------------------------------------------------------------------------------- /run-all.sh: -------------------------------------------------------------------------------- 1 | # Recursively search for Justfiles and run just against each one 2 | 3 | # Use the find command to search for Justfiles in the current directory and its subdirectories 4 | justfiles=$(find . -name "Justfile") 5 | cargos=$(find . -name "Cargo.toml") 6 | 7 | # Save the current directory so we can change back to it later 8 | orig_dir=$(pwd) 9 | 10 | # Loop through each Justfile 11 | for justfile in $justfiles; do 12 | # Get the directory containing the Justfile 13 | dir=$(dirname $justfile) 14 | 15 | # Change to the directory containing the Justfile 16 | pushd $dir 17 | 18 | # Run just without any arguments 19 | just 20 | 21 | # Change back to the original directory 22 | popd 23 | done 24 | 25 | # Loop through each Cargo.toml 26 | for cargo in $cargos; do 27 | # Get the directory containing the Cargo.toml 28 | dir=$(dirname $cargo) 29 | 30 | # Change to the directory containing the Cargo.toml 31 | pushd $dir 32 | 33 | # Run cargo 34 | cargo run 35 | 36 | # Change back to the original directory 37 | popd 38 | done 39 | 40 | # Change back to the original directory 41 | cd $orig_dir 42 | -------------------------------------------------------------------------------- /day_11/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.20" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "day_11" 16 | version = "0.1.0" 17 | dependencies = [ 18 | "regex", 19 | ] 20 | 21 | [[package]] 22 | name = "memchr" 23 | version = "2.5.0" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 26 | 27 | [[package]] 28 | name = "regex" 29 | version = "1.7.0" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" 32 | dependencies = [ 33 | "aho-corasick", 34 | "memchr", 35 | "regex-syntax", 36 | ] 37 | 38 | [[package]] 39 | name = "regex-syntax" 40 | version = "0.6.28" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 43 | -------------------------------------------------------------------------------- /day_04/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | fn range_contains_range(range: (u32, u32), other: (u32, u32)) -> bool { 6 | range.0 <= other.0 && range.1 >= other.1 7 | } 8 | 9 | fn main() -> Result<(), std::io::Error> { 10 | // Read file line by line 11 | let file = fs::File::open("input.txt")?; 12 | let reader = io::BufReader::new(file); 13 | let mut score = 0; 14 | for line in reader.lines() { 15 | let line = line?; 16 | // Line is e.g. 41-47,40-80 - parse into a-b,c-d 17 | // first use split_once('-') 18 | let (one, two) = line.split_once(',').unwrap(); 19 | let (a, b) = one.split_once('-').unwrap(); 20 | let (c, d) = two.split_once('-').unwrap(); 21 | // Parse those into numbers 22 | let a = a.parse::().unwrap(); 23 | let b = b.parse::().unwrap(); 24 | let c = c.parse::().unwrap(); 25 | let d = d.parse::().unwrap(); 26 | 27 | let range1 = (a, b); 28 | let range2 = (c, d); 29 | 30 | if range_contains_range(range1, range2) || range_contains_range(range2, range1) { 31 | score += 1; 32 | } 33 | } 34 | println!("Score: {}", score); 35 | Ok(()) 36 | } 37 | -------------------------------------------------------------------------------- /03/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | fn find_duplicate_character(s1: &str, s2: &str) -> Option { 6 | for c1 in s1.chars() { 7 | for c2 in s2.chars() { 8 | if c1 == c2 { 9 | return Some(c1); 10 | } 11 | } 12 | } 13 | None 14 | } 15 | 16 | fn main() -> io::Result<()> { 17 | let file = fs::File::open("input.txt")?; 18 | let reader = io::BufReader::new(file); 19 | let mut score: i32 = 0; 20 | 21 | for line in reader.lines() { 22 | let line = line?; 23 | // Split the line exactly in half into two strings 24 | let (left, right) = line.split_at(line.len() / 2); 25 | 26 | let duplicate = find_duplicate_character(left, right).unwrap(); 27 | 28 | /* 29 | Lowercase item types a through z have priorities 1 through 26. 30 | Uppercase item types A through Z have priorities 27 through 52. 31 | */ 32 | let priority = match duplicate { 33 | 'a'..='z' => duplicate as u8 - 'a' as u8 + 1, 34 | 'A'..='Z' => duplicate as u8 - 'A' as u8 + 27, 35 | _ => 0, 36 | } as i32; 37 | println!("{}: {}", line, priority); 38 | score += priority; 39 | } 40 | println!("{}", score); 41 | Ok(()) 42 | } 43 | -------------------------------------------------------------------------------- /01/elf-count-top-three.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | fn main() -> io::Result<()> { 6 | let file = fs::File::open("input.txt")?; 7 | let reader = io::BufReader::new(file); 8 | 9 | // Create a new, empty vector of integers. 10 | let mut elves = Vec::new(); 11 | 12 | let mut current = 0; 13 | 14 | for line in reader.lines() { 15 | let line = line?; 16 | 17 | // If line is empty, save the elf 18 | if line.is_empty() { 19 | elves.push(current); 20 | current = 0; 21 | continue; 22 | } 23 | 24 | match line.parse::() { 25 | Ok(n) => { 26 | current += n; 27 | }, 28 | Err(e) => { 29 | println!("Error: {}", e); 30 | continue; 31 | } 32 | }; 33 | } 34 | 35 | // Sort the elves vector in descending order 36 | elves.sort_by(|a, b| b.cmp(a)); 37 | 38 | // New vector with just the top three: 39 | let top_three = &elves[0..3]; 40 | 41 | // Print out the top three 42 | let mut sum = 0; 43 | for elf in top_three { 44 | println!("{}", elf); 45 | sum += elf; 46 | } 47 | 48 | // Print out the sum of the top three 49 | println!("Sum: {}", sum); 50 | 51 | Ok(()) 52 | } 53 | -------------------------------------------------------------------------------- /day_04_part_2/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | fn range_overlaps_range(range: (u32, u32), other: (u32, u32)) -> bool { 6 | range.0 <= other.0 && other.0 <= range.1 7 | || range.0 <= other.1 && other.1 <= range.1 8 | || other.0 <= range.0 && range.0 <= other.1 9 | || other.0 <= range.1 && range.1 <= other.1 10 | } 11 | 12 | fn main() -> Result<(), std::io::Error> { 13 | // Read file line by line 14 | let file = fs::File::open("input.txt")?; 15 | let reader = io::BufReader::new(file); 16 | let mut score = 0; 17 | for line in reader.lines() { 18 | let line = line?; 19 | // Line is e.g. 41-47,40-80 - parse into a-b,c-d 20 | // first use split_once('-') 21 | let (one, two) = line.split_once(',').unwrap(); 22 | let (a, b) = one.split_once('-').unwrap(); 23 | let (c, d) = two.split_once('-').unwrap(); 24 | // Parse those into numbers 25 | let a = a.parse::().unwrap(); 26 | let b = b.parse::().unwrap(); 27 | let c = c.parse::().unwrap(); 28 | let d = d.parse::().unwrap(); 29 | 30 | let range1 = (a, b); 31 | let range2 = (c, d); 32 | 33 | if range_overlaps_range(range1, range2) { 34 | score += 1; 35 | } 36 | } 37 | println!("Score: {}", score); 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /02/rock-paper-scissors.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | fn main() -> io::Result<()> { 5 | let file = fs::File::open("input.txt")?; 6 | let reader = io::BufReader::new(file); 7 | 8 | let mut score = 0; 9 | 10 | for line in reader.lines() { 11 | let line = line?; 12 | 13 | // Line is of form "opponent me" - split on the space 14 | let mut parts = line.split(" "); 15 | let opponent = parts.next().unwrap(); 16 | let me = parts.next().unwrap(); 17 | 18 | /* 19 | A/X = rock 20 | B/Y = paper 21 | C/Z = scissors 22 | */ 23 | 24 | // Who won? Opponent A beats me Z, B beats me X, C beats me Y 25 | let win_score = match (opponent, me) { 26 | ("A", "Z") | ("B", "X") | ("C", "Y") => 0, 27 | ("A", "Y") | ("B", "Z") | ("C", "X") => 6, 28 | _ => 3, 29 | }; 30 | score += win_score; 31 | // And an extra score based on what I picked 32 | // X = 1, Y = 2, Z = 3 - use match for that too: 33 | let extra_score = match me { 34 | "X" => 1, 35 | "Y" => 2, 36 | "Z" => 3, 37 | _ => 0, 38 | }; 39 | println!("{} {} {} {}", opponent, me, win_score, extra_score); 40 | score += extra_score; 41 | } 42 | println!("{}", score); 43 | Ok(()) 44 | } 45 | -------------------------------------------------------------------------------- /day_11/input.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 83, 88, 96, 79, 86, 88, 70 3 | Operation: new = old * 5 4 | Test: divisible by 11 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 59, 63, 98, 85, 68, 72 10 | Operation: new = old * 11 11 | Test: divisible by 5 12 | If true: throw to monkey 4 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 90, 79, 97, 52, 90, 94, 71, 70 17 | Operation: new = old + 2 18 | Test: divisible by 19 19 | If true: throw to monkey 5 20 | If false: throw to monkey 6 21 | 22 | Monkey 3: 23 | Starting items: 97, 55, 62 24 | Operation: new = old + 5 25 | Test: divisible by 13 26 | If true: throw to monkey 2 27 | If false: throw to monkey 6 28 | 29 | Monkey 4: 30 | Starting items: 74, 54, 94, 76 31 | Operation: new = old * old 32 | Test: divisible by 7 33 | If true: throw to monkey 0 34 | If false: throw to monkey 3 35 | 36 | Monkey 5: 37 | Starting items: 58 38 | Operation: new = old + 4 39 | Test: divisible by 17 40 | If true: throw to monkey 7 41 | If false: throw to monkey 1 42 | 43 | Monkey 6: 44 | Starting items: 66, 63 45 | Operation: new = old + 6 46 | Test: divisible by 2 47 | If true: throw to monkey 7 48 | If false: throw to monkey 5 49 | 50 | Monkey 7: 51 | Starting items: 56, 56, 90, 96, 68 52 | Operation: new = old + 7 53 | Test: divisible by 3 54 | If true: throw to monkey 4 55 | If false: throw to monkey 1 56 | -------------------------------------------------------------------------------- /day_06/src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | use std::fs; 3 | use std::io; 4 | use std::io::BufRead; 5 | 6 | #[derive(Parser, Debug)] 7 | #[command(author, version, about, long_about = None)] 8 | struct Args { 9 | /// File to read 10 | filename: String, 11 | 12 | /// Length of characters to seek 13 | #[arg(short, long, default_value_t = 4)] 14 | length: u16, 15 | } 16 | 17 | fn main() -> Result<(), std::io::Error> { 18 | let args = Args::parse(); 19 | 20 | let length = args.length; 21 | 22 | // Read the first line of the file as a string 23 | let file = fs::File::open(args.filename)?; 24 | let reader = io::BufReader::new(file); 25 | let mut lines = reader.lines(); 26 | let line = lines.next().unwrap()?; 27 | // Turn that into a vector of chars 28 | let chars: Vec = line.chars().collect(); 29 | 30 | for i in args.length..(chars.len() as u16) { 31 | // Put previous X characters in a set 32 | let mut set = std::collections::HashSet::new(); 33 | for j in i - args.length..i { 34 | set.insert(chars[j as usize]); 35 | } 36 | // If the set has X characters, print last X 37 | if set.len() == args.length.into() { 38 | println!("Found it"); 39 | let x_chars = chars 40 | .iter() 41 | .skip((i - (length - 1)).into()) 42 | .take(length.into()); 43 | println!("{}", x_chars.collect::()); 44 | println!("Index: {}", i); 45 | break; 46 | } 47 | } 48 | Ok(()) 49 | } 50 | -------------------------------------------------------------------------------- /day_10/input.txt: -------------------------------------------------------------------------------- 1 | noop 2 | addx 24 3 | addx -19 4 | noop 5 | noop 6 | noop 7 | addx 5 8 | noop 9 | addx 1 10 | addx 5 11 | addx -1 12 | addx 5 13 | addx 1 14 | addx 14 15 | addx -9 16 | addx -1 17 | addx 5 18 | noop 19 | addx 2 20 | addx -20 21 | addx 24 22 | addx -36 23 | addx -2 24 | noop 25 | addx 3 26 | addx 2 27 | addx 5 28 | addx 21 29 | addx -16 30 | noop 31 | addx 2 32 | addx 15 33 | addx -14 34 | addx 2 35 | addx 5 36 | addx 2 37 | addx -4 38 | addx 5 39 | addx -8 40 | addx 15 41 | addx 2 42 | addx 3 43 | addx -2 44 | addx -38 45 | noop 46 | addx 3 47 | addx 4 48 | noop 49 | addx 7 50 | noop 51 | noop 52 | addx -2 53 | addx 5 54 | addx -16 55 | addx 21 56 | noop 57 | addx -10 58 | addx 11 59 | addx 2 60 | addx 5 61 | addx 4 62 | noop 63 | noop 64 | addx -6 65 | addx 7 66 | noop 67 | addx 3 68 | addx -36 69 | noop 70 | addx 5 71 | noop 72 | addx 20 73 | addx -19 74 | addx 5 75 | addx 4 76 | noop 77 | addx -2 78 | addx 3 79 | noop 80 | addx 4 81 | noop 82 | addx -1 83 | addx 5 84 | addx 3 85 | addx -28 86 | addx 30 87 | noop 88 | addx 6 89 | noop 90 | noop 91 | addx 1 92 | addx -38 93 | addx 40 94 | addx -33 95 | addx 20 96 | addx -19 97 | addx 2 98 | noop 99 | addx 28 100 | addx -23 101 | addx 5 102 | addx 2 103 | addx 2 104 | addx 3 105 | addx -2 106 | addx 5 107 | addx 2 108 | addx -7 109 | addx 12 110 | addx -2 111 | noop 112 | addx 3 113 | addx -38 114 | noop 115 | addx 24 116 | addx -17 117 | noop 118 | addx 5 119 | noop 120 | noop 121 | addx 1 122 | addx -8 123 | addx 13 124 | noop 125 | noop 126 | addx 2 127 | addx 5 128 | addx 2 129 | addx 6 130 | addx -5 131 | addx 4 132 | noop 133 | addx 1 134 | addx 2 135 | noop 136 | addx 3 137 | noop 138 | noop 139 | -------------------------------------------------------------------------------- /day_03_part_2/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | 5 | 6 | fn main() -> io::Result<()> { 7 | let file = fs::File::open("input.txt")?; 8 | let reader = io::BufReader::new(file); 9 | let mut score: i32 = 0; 10 | 11 | // Read the file three lines at a time 12 | let mut lines = reader.lines(); 13 | let mut found_char = 'X'; 14 | 15 | loop { 16 | // Try this but break if it is an error: 17 | let line1 = match lines.next() { 18 | Some(Ok(line)) => line, 19 | _ => break, 20 | }; 21 | let line2 = lines.next().unwrap()?; 22 | let line3 = lines.next().unwrap()?; 23 | 24 | // What character is present in all three lines? 25 | let mut found = false; 26 | for c1 in line1.chars() { 27 | for c2 in line2.chars() { 28 | for c3 in line3.chars() { 29 | if c1 == c2 && c2 == c3 { 30 | found = true; 31 | found_char = c1; 32 | } 33 | } 34 | if found { 35 | break; 36 | } 37 | } 38 | if found { 39 | break; 40 | } 41 | } 42 | if found { 43 | let priority = match found_char { 44 | 'a'..='z' => found_char as u8 - 'a' as u8 + 1, 45 | 'A'..='Z' => found_char as u8 - 'A' as u8 + 27, 46 | _ => 0, 47 | } as i32; 48 | score += priority; 49 | } else { 50 | // Quit with error 51 | panic!("No character found that was in all 3 lines"); 52 | } 53 | } 54 | println!("{}", score); 55 | Ok(()) 56 | } 57 | -------------------------------------------------------------------------------- /day_10/example.txt: -------------------------------------------------------------------------------- 1 | addx 15 2 | addx -11 3 | addx 6 4 | addx -3 5 | addx 5 6 | addx -1 7 | addx -8 8 | addx 13 9 | addx 4 10 | noop 11 | addx -1 12 | addx 5 13 | addx -1 14 | addx 5 15 | addx -1 16 | addx 5 17 | addx -1 18 | addx 5 19 | addx -1 20 | addx -35 21 | addx 1 22 | addx 24 23 | addx -19 24 | addx 1 25 | addx 16 26 | addx -11 27 | noop 28 | noop 29 | addx 21 30 | addx -15 31 | noop 32 | noop 33 | addx -3 34 | addx 9 35 | addx 1 36 | addx -3 37 | addx 8 38 | addx 1 39 | addx 5 40 | noop 41 | noop 42 | noop 43 | noop 44 | noop 45 | addx -36 46 | noop 47 | addx 1 48 | addx 7 49 | noop 50 | noop 51 | noop 52 | addx 2 53 | addx 6 54 | noop 55 | noop 56 | noop 57 | noop 58 | noop 59 | addx 1 60 | noop 61 | noop 62 | addx 7 63 | addx 1 64 | noop 65 | addx -13 66 | addx 13 67 | addx 7 68 | noop 69 | addx 1 70 | addx -33 71 | noop 72 | noop 73 | noop 74 | addx 2 75 | noop 76 | noop 77 | noop 78 | addx 8 79 | noop 80 | addx -1 81 | addx 2 82 | addx 1 83 | noop 84 | addx 17 85 | addx -9 86 | addx 1 87 | addx 1 88 | addx -3 89 | addx 11 90 | noop 91 | noop 92 | addx 1 93 | noop 94 | addx 1 95 | noop 96 | noop 97 | addx -13 98 | addx -19 99 | addx 1 100 | addx 3 101 | addx 26 102 | addx -30 103 | addx 12 104 | addx -1 105 | addx 3 106 | addx 1 107 | noop 108 | noop 109 | noop 110 | addx -9 111 | addx 18 112 | addx 1 113 | addx 2 114 | noop 115 | noop 116 | addx 9 117 | noop 118 | noop 119 | noop 120 | addx -1 121 | addx 2 122 | addx -37 123 | addx 1 124 | addx 3 125 | noop 126 | addx 15 127 | addx -21 128 | addx 22 129 | addx -6 130 | addx 1 131 | noop 132 | addx 2 133 | addx 1 134 | noop 135 | addx -10 136 | noop 137 | noop 138 | addx 20 139 | addx 1 140 | addx 2 141 | addx 2 142 | addx -6 143 | addx -11 144 | noop 145 | noop 146 | noop -------------------------------------------------------------------------------- /day_10/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | fn main() { 4 | let file_contents = fs::read_to_string("input.txt").unwrap(); 5 | 6 | /* 7 | File format: 8 | addx 4 9 | noop 10 | addx -1 11 | */ 12 | let mut register_x = 1; 13 | let mut cycle = 0; 14 | 15 | const CAPTURE_AT: [i32; 6] = [20, 60, 100, 140, 180, 220]; 16 | let mut captured = Vec::new(); 17 | 18 | for line in file_contents.lines() { 19 | let mut parts = line.split_whitespace(); 20 | let command = parts.next().unwrap(); 21 | match command { 22 | "addx" => { 23 | // addx V takes two cycles to complete. After two cycles, the 24 | // X register is increased by the value V. (V can be negative.) 25 | let value = parts.next().unwrap().parse::().unwrap(); 26 | println!("Adding {} to x", value); 27 | cycle += 1; 28 | if CAPTURE_AT.contains(&cycle) { 29 | captured.push((cycle, register_x, cycle * register_x)); 30 | } 31 | cycle += 1; 32 | if CAPTURE_AT.contains(&cycle) { 33 | captured.push((cycle, register_x, cycle * register_x)); 34 | } 35 | register_x += value; 36 | } 37 | "noop" => { 38 | // takes one cycle to complete 39 | cycle += 1; 40 | if CAPTURE_AT.contains(&cycle) { 41 | captured.push((cycle, register_x, cycle * register_x)); 42 | } 43 | println!("Doing nothing"); 44 | } 45 | _ => { 46 | println!("Unknown command: {}", command); 47 | } 48 | } 49 | } 50 | println!( 51 | "Final register_x: {}, captured: {:#?}", 52 | register_x, captured 53 | ); 54 | // Sum of signal strengths (3rd items) 55 | let sum: i32 = captured.iter().map(|(_, _, s)| s).sum(); 56 | println!("Sum of signal strengths: {}", sum); 57 | } 58 | -------------------------------------------------------------------------------- /day_10_part_2/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | fn main() { 4 | let file_contents = fs::read_to_string("../day_10/input.txt").unwrap(); 5 | 6 | /* 7 | File format: 8 | addx 4 9 | noop 10 | addx -1 11 | */ 12 | let mut register_x = 1; 13 | let mut cycle = 0; 14 | 15 | const CAPTURE_AT: [i32; 6] = [20, 60, 100, 140, 180, 220]; 16 | let mut captured = Vec::new(); 17 | 18 | for line in file_contents.lines() { 19 | let mut parts = line.split_whitespace(); 20 | let command = parts.next().unwrap(); 21 | match command { 22 | "addx" => { 23 | // addx V takes two cycles to complete. After two cycles, the 24 | // X register is increased by the value V. (V can be negative.) 25 | let value = parts.next().unwrap().parse::().unwrap(); 26 | cycle += 1; 27 | draw(cycle, register_x); 28 | if CAPTURE_AT.contains(&cycle) { 29 | captured.push((cycle, register_x, cycle * register_x)); 30 | } 31 | cycle += 1; 32 | draw(cycle, register_x); 33 | if CAPTURE_AT.contains(&cycle) { 34 | captured.push((cycle, register_x, cycle * register_x)); 35 | } 36 | register_x += value; 37 | } 38 | "noop" => { 39 | // takes one cycle to complete 40 | cycle += 1; 41 | draw(cycle, register_x); 42 | if CAPTURE_AT.contains(&cycle) { 43 | captured.push((cycle, register_x, cycle * register_x)); 44 | } 45 | } 46 | _ => { 47 | println!("Unknown command: {}", command); 48 | } 49 | } 50 | } 51 | } 52 | 53 | fn draw(cycle: i32, register_x: i32) { 54 | let pos = (cycle - 1) % 40; 55 | // If register X within -1/0/1 of pos 56 | if (register_x - pos).abs() <= 1 { 57 | print!("#"); 58 | } else { 59 | print!("."); 60 | } 61 | if cycle % 40 == 0 { 62 | println!(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /02/rock-paper-scissors2.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::io::BufRead; 4 | fn main() -> io::Result<()> { 5 | let file = fs::File::open("input.txt")?; 6 | let reader = io::BufReader::new(file); 7 | 8 | let mut score = 0; 9 | 10 | for line in reader.lines() { 11 | let line = line?; 12 | 13 | let mut parts = line.split(" "); 14 | let opponent_code = parts.next().unwrap(); 15 | let outcome_code = parts.next().unwrap(); 16 | 17 | /* 18 | A = rock 19 | B = paper 20 | C = scissors 21 | 22 | X = I lose 23 | Y = draw 24 | Z = I win 25 | */ 26 | let opponent = match opponent_code { 27 | "A" => "rock", 28 | "B" => "paper", 29 | "C" => "scissors", 30 | _ => "unknown", 31 | }; 32 | let outcome = match outcome_code { 33 | "X" => "lose", 34 | "Y" => "draw", 35 | "Z" => "win", 36 | _ => "unknown", 37 | }; 38 | 39 | // Need to figure out what I picked, based on opponent + outcome 40 | let me = match (opponent, outcome) { 41 | ("rock", "win") => "paper", 42 | ("rock", "draw") => "rock", 43 | ("rock", "lose") => "scissors", 44 | ("paper", "win") => "scissors", 45 | ("paper", "draw") => "paper", 46 | ("paper", "lose") => "rock", 47 | ("scissors", "win") => "rock", 48 | ("scissors", "draw") => "scissors", 49 | ("scissors", "lose") => "paper", 50 | _ => "unknown", 51 | }; 52 | 53 | let win_score = match outcome { 54 | "win" => 6, 55 | "draw" => 3, 56 | "lose" => 0, 57 | _ => 0, 58 | }; 59 | 60 | // And an extra score based on what I picked 61 | let extra_score = match me { 62 | "rock" => 1, 63 | "paper" => 2, 64 | "scissors" => 3, 65 | _ => 0, 66 | }; 67 | println!("{} {} {} {}", opponent, me, win_score, extra_score); 68 | score += extra_score; 69 | score += win_score; 70 | } 71 | println!("{}", score); 72 | Ok(()) 73 | } 74 | -------------------------------------------------------------------------------- /day_13/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "autocfg" 7 | version = "1.1.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 10 | 11 | [[package]] 12 | name = "day_13" 13 | version = "0.1.0" 14 | dependencies = [ 15 | "parameterized", 16 | ] 17 | 18 | [[package]] 19 | name = "hashbrown" 20 | version = "0.12.3" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 23 | 24 | [[package]] 25 | name = "indexmap" 26 | version = "1.9.2" 27 | source = "registry+https://github.com/rust-lang/crates.io-index" 28 | checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" 29 | dependencies = [ 30 | "autocfg", 31 | "hashbrown", 32 | ] 33 | 34 | [[package]] 35 | name = "parameterized" 36 | version = "1.0.1" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "bae5c87ace1829bb3dcbadaf9d099c62beb05ca19ab4b26389eaa33ced9db11b" 39 | dependencies = [ 40 | "parameterized-macro", 41 | ] 42 | 43 | [[package]] 44 | name = "parameterized-macro" 45 | version = "1.0.1" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "1def6e0adb9bf9daf2d352cba8407b5eaa204f77e02de149ad690e816d7fac14" 48 | dependencies = [ 49 | "indexmap", 50 | "proc-macro2", 51 | "quote", 52 | "syn", 53 | ] 54 | 55 | [[package]] 56 | name = "proc-macro2" 57 | version = "1.0.47" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 60 | dependencies = [ 61 | "unicode-ident", 62 | ] 63 | 64 | [[package]] 65 | name = "quote" 66 | version = "1.0.21" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 69 | dependencies = [ 70 | "proc-macro2", 71 | ] 72 | 73 | [[package]] 74 | name = "syn" 75 | version = "1.0.105" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" 78 | dependencies = [ 79 | "proc-macro2", 80 | "quote", 81 | "unicode-ident", 82 | ] 83 | 84 | [[package]] 85 | name = "unicode-ident" 86 | version = "1.0.5" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 89 | -------------------------------------------------------------------------------- /day_15/input.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=3556832, y=3209801: closest beacon is at x=3520475, y=3164417 2 | Sensor at x=3068970, y=3071952: closest beacon is at x=3520475, y=3164417 3 | Sensor at x=636397, y=1899889: closest beacon is at x=338784, y=1935796 4 | Sensor at x=3856769, y=3377079: closest beacon is at x=3520475, y=3164417 5 | Sensor at x=2876227, y=2633203: closest beacon is at x=2595700, y=2684432 6 | Sensor at x=1435445, y=1194830: closest beacon is at x=925348, y=2000000 7 | Sensor at x=3764673, y=3881970: closest beacon is at x=3520475, y=3164417 8 | Sensor at x=3171272, y=1098717: closest beacon is at x=3778277, y=740547 9 | Sensor at x=3646837, y=966534: closest beacon is at x=3778277, y=740547 10 | Sensor at x=1736390, y=3309102: closest beacon is at x=1623417, y=4114070 11 | Sensor at x=1086601, y=2272573: closest beacon is at x=925348, y=2000000 12 | Sensor at x=3793954, y=2346914: closest beacon is at x=3520475, y=3164417 13 | Sensor at x=1896054, y=2706210: closest beacon is at x=2595700, y=2684432 14 | Sensor at x=2298950, y=3449308: closest beacon is at x=2205069, y=3958831 15 | Sensor at x=1911518, y=3848874: closest beacon is at x=2205069, y=3958831 16 | Sensor at x=2566355, y=1516144: closest beacon is at x=2595700, y=2684432 17 | Sensor at x=246553, y=343125: closest beacon is at x=338784, y=1935796 18 | Sensor at x=2197183, y=3975039: closest beacon is at x=2205069, y=3958831 19 | Sensor at x=552775, y=3494740: closest beacon is at x=-138318, y=2857049 20 | Sensor at x=128870, y=1935711: closest beacon is at x=338784, y=1935796 21 | Sensor at x=2197078, y=3999879: closest beacon is at x=2205069, y=3958831 22 | Sensor at x=2502533, y=3911039: closest beacon is at x=2205069, y=3958831 23 | Sensor at x=2289309, y=3024440: closest beacon is at x=2595700, y=2684432 24 | Sensor at x=3999523, y=551710: closest beacon is at x=3778277, y=740547 25 | Sensor at x=2246061, y=3999936: closest beacon is at x=2205069, y=3958831 26 | Sensor at x=3982782, y=1306639: closest beacon is at x=3778277, y=740547 27 | Sensor at x=1166660, y=2766482: closest beacon is at x=925348, y=2000000 28 | Sensor at x=3744391, y=440575: closest beacon is at x=3778277, y=740547 29 | Sensor at x=1480453, y=3997346: closest beacon is at x=1623417, y=4114070 30 | Sensor at x=9770, y=1844797: closest beacon is at x=338784, y=1935796 31 | Sensor at x=202829, y=2427690: closest beacon is at x=338784, y=1935796 32 | Sensor at x=3051096, y=3631595: closest beacon is at x=3147080, y=4258152 33 | Sensor at x=2111052, y=297293: closest beacon is at x=1552534, y=-431081 34 | Sensor at x=864326, y=2053355: closest beacon is at x=925348, y=2000000 35 | Sensor at x=2422495, y=2130146: closest beacon is at x=2595700, y=2684432 36 | Sensor at x=3655670, y=100751: closest beacon is at x=3778277, y=740547 37 | Sensor at x=535656, y=2133259: closest beacon is at x=338784, y=1935796 38 | Sensor at x=263229, y=2101270: closest beacon is at x=338784, y=1935796 39 | -------------------------------------------------------------------------------- /01/elf-count.rs: -------------------------------------------------------------------------------- 1 | // Import the 'fs' and 'io' modules from the standard library. 2 | // The 'fs' module provides functions for working with files and directories, 3 | // and the 'io' module provides functions for working with input and output. 4 | use std::fs; 5 | use std::io; 6 | 7 | // Import the 'BufRead' trait from the 'io' module. 8 | // The 'BufRead' trait provides methods for reading data from a source 9 | // in a buffered manner. 10 | use std::io::BufRead; 11 | 12 | // Define the 'main' function. 13 | // This is the entry point of the program. 14 | // The 'main' function returns a 'Result<(), io::Error>', which is 15 | // an enumeration that represents either a successful value of type '()' 16 | // or an error value of type 'io::Error'. 17 | fn main() -> io::Result<()> { 18 | // Open the file 'numbers.txt' in read-only mode and bind the result 19 | // to the 'file' variable. The 'File::open' method returns a 'Result' 20 | // that contains either the opened file or an error value. 21 | // The '?' operator is used to propagate any errors that occur. 22 | let file = fs::File::open("input.txt")?; 23 | 24 | // Create a 'BufReader' for the opened file and bind the result 25 | // to the 'reader' variable. The 'BufReader' type provides buffered 26 | // reading capabilities for the file. 27 | let reader = io::BufReader::new(file); 28 | 29 | // Initialize two integer variables - current and max 30 | let mut current = 0; 31 | let mut max = 0; 32 | 33 | // Iterate over each line in the 'reader'. 34 | // The 'lines' method returns an iterator over the lines in the 'reader'. 35 | for line in reader.lines() { 36 | // Bind the current line to the 'line' variable. 37 | // The 'line' variable is of type 'io::Result', which is 38 | // an enumeration that represents either a successful value of type 39 | // 'String' or an error value of type 'io::Error'. 40 | // The '?' operator is used to propagate any errors that occur. 41 | let line = line?; 42 | 43 | // If line is empty, figure out if we have a new max 44 | if line.is_empty() { 45 | if current > max { 46 | max = current; 47 | } 48 | current = 0; 49 | continue; 50 | } 51 | 52 | // Parse the line as an 'i32' (32-bit signed integer) and bind the 53 | // result to the 'number' variable. 54 | 55 | // If an error occurs, print it and continue 56 | // Start that code here: 57 | match line.parse::() { 58 | Ok(n) => { 59 | current += n; 60 | }, 61 | Err(e) => { 62 | println!("Error: {}", e); 63 | continue; 64 | } 65 | }; 66 | } 67 | // Print the parsed number to the console. 68 | // The 'println!` macro is used to print a formatted string to the 69 | // console. In this case, the format string is "{}", which means 70 | // that the value of the 'max' variable will be printed in place 71 | // of the "{}" placeholder. 72 | println!("Max: {}", max); 73 | 74 | // Return an 'Ok' value containing '()'. 75 | // This indicates that the 'main' function has completed successfully. 76 | Ok(()) 77 | } 78 | -------------------------------------------------------------------------------- /day_16/input.txt: -------------------------------------------------------------------------------- 1 | Valve TM has flow rate=3; tunnels lead to valves WB, PE, DX, TK, CH 2 | Valve ST has flow rate=21; tunnels lead to valves NS, DE, UX, XU 3 | Valve IX has flow rate=0; tunnels lead to valves DK, LR 4 | Valve OG has flow rate=0; tunnels lead to valves MN, FK 5 | Valve FR has flow rate=0; tunnels lead to valves JQ, GS 6 | Valve HU has flow rate=0; tunnels lead to valves TJ, XX 7 | Valve WC has flow rate=15; tunnel leads to valve TJ 8 | Valve JT has flow rate=0; tunnels lead to valves OV, AA 9 | Valve DW has flow rate=0; tunnels lead to valves FK, AA 10 | Valve RG has flow rate=0; tunnels lead to valves PS, DK 11 | Valve JQ has flow rate=14; tunnels lead to valves VM, FR 12 | Valve XX has flow rate=5; tunnels lead to valves GP, MN, WB, LM, HU 13 | Valve IN has flow rate=11; tunnels lead to valves OK, GS, DU 14 | Valve LR has flow rate=7; tunnels lead to valves IX, NR, YY, HZ, PR 15 | Valve TK has flow rate=0; tunnels lead to valves TM, OV 16 | Valve VM has flow rate=0; tunnels lead to valves KQ, JQ 17 | Valve IC has flow rate=0; tunnels lead to valves FK, DU 18 | Valve CH has flow rate=0; tunnels lead to valves EZ, TM 19 | Valve OV has flow rate=10; tunnels lead to valves YW, JT, NN, TK 20 | Valve KQ has flow rate=17; tunnels lead to valves VM, YW, CY 21 | Valve NR has flow rate=0; tunnels lead to valves FK, LR 22 | Valve MN has flow rate=0; tunnels lead to valves OG, XX 23 | Valve YY has flow rate=0; tunnels lead to valves LR, LM 24 | Valve OK has flow rate=0; tunnels lead to valves CY, IN 25 | Valve DK has flow rate=20; tunnels lead to valves FA, RG, IX 26 | Valve CY has flow rate=0; tunnels lead to valves KQ, OK 27 | Valve PR has flow rate=0; tunnels lead to valves DX, LR 28 | Valve DE has flow rate=0; tunnels lead to valves ST, EL 29 | Valve TJ has flow rate=0; tunnels lead to valves WC, HU 30 | Valve NS has flow rate=0; tunnels lead to valves WU, ST 31 | Valve PE has flow rate=0; tunnels lead to valves TM, XO 32 | Valve DU has flow rate=0; tunnels lead to valves IN, IC 33 | Valve DX has flow rate=0; tunnels lead to valves TM, PR 34 | Valve EQ has flow rate=0; tunnels lead to valves AA, GP 35 | Valve AA has flow rate=0; tunnels lead to valves JT, EZ, HZ, DW, EQ 36 | Valve WB has flow rate=0; tunnels lead to valves TM, XX 37 | Valve PF has flow rate=23; tunnels lead to valves BP, WU 38 | Valve FJ has flow rate=19; tunnels lead to valves DO, TY, NN, PS 39 | Valve GP has flow rate=0; tunnels lead to valves XX, EQ 40 | Valve FK has flow rate=4; tunnels lead to valves DW, XO, OG, IC, NR 41 | Valve DO has flow rate=0; tunnels lead to valves XU, FJ 42 | Valve XO has flow rate=0; tunnels lead to valves FK, PE 43 | Valve PS has flow rate=0; tunnels lead to valves RG, FJ 44 | Valve MD has flow rate=25; tunnel leads to valve BP 45 | Valve EZ has flow rate=0; tunnels lead to valves CH, AA 46 | Valve GS has flow rate=0; tunnels lead to valves IN, FR 47 | Valve XU has flow rate=0; tunnels lead to valves DO, ST 48 | Valve WU has flow rate=0; tunnels lead to valves PF, NS 49 | Valve YW has flow rate=0; tunnels lead to valves OV, KQ 50 | Valve HZ has flow rate=0; tunnels lead to valves LR, AA 51 | Valve TY has flow rate=0; tunnels lead to valves FJ, EL 52 | Valve BP has flow rate=0; tunnels lead to valves MD, PF 53 | Valve EL has flow rate=18; tunnels lead to valves DE, TY 54 | Valve UX has flow rate=0; tunnels lead to valves FA, ST 55 | Valve FA has flow rate=0; tunnels lead to valves UX, DK 56 | Valve NN has flow rate=0; tunnels lead to valves OV, FJ 57 | Valve LM has flow rate=0; tunnels lead to valves XX, YY 58 | -------------------------------------------------------------------------------- /day_06/input.txt: -------------------------------------------------------------------------------- 1 | pnnfhnhshrhmhwwmwzmznmnwmwfmfhfjfcjjtgtbggpdgdjjbjrjsjpjrrmddmgmpmddrhddnfnfzfpfvpfpprhhlffmtffqhhdtdcdsswsdwswmmfvvpdprrnnhhhtffnfbbznbznnvdnnbffjrfrbfrbrgbrrntnggrqqwtqwwgjgsswgwqwtwwsvwvbwvwrwlrlppzfzwfzzpmzzhqqzqlzlglzzmrmwrmwwvmwvvnppjfjttlffhjjjsccbggnffqgfgjjnccmdmzmllvnlnznttlvlttvnvgnvvqvmvqqzrqqcgglzzwtztwwmjmzjjnddsffqrqlrrvsvdvldvvlgvlvccdzczcqcpphggtnthhhtbhtttcjtjcjgcjcbbrhbbfrffgjgdgzddcttczzsccbpcpddcpcggmjgjddtcccthccfrccmdmhmddnwddfldffntnptnpttcptcptpfphhmfmwfwmmlblgbgvbvlltqltldttfcfcclgcllmplmlbbjnjzjnzzttnvvgddshddsqddggsqgqddsggdhghjgjhhgchhdmdjmjddgdhghrrphrrpnnqhhjwwqrrcmmslmmszzpgzpzzrmzmznzllnjnnlnbbdvdsdffbpffcmmnznqqcbbzvvjnjvvwqwgqqpnnzwnzwnzwwwlpwpzzfqzfqqwnqnbnfnqnbqqbggqnqdndrrzzlffbbgqgfgrfrqqsddnqnqjjgssqwqwcqcpcrrqppwpjjfnfpffhphwwmcwwznwznnplptlplnlsnlsldslslsffwtwftwtbtdbbjsjcczwwfllwtlwtlwlvwlwrwppsggvcvrrqcrqqvmqvmmbrrsbsfspspjpnnmpmqmcczgzffqmfmtmpppwzppzrpzrzsrrpqrpqpmpvmpvpttbqtqmtmjttqdqgggcppclcjcpcsppctpplpdpcppcmmdzmzddvhvhnhrrldllcwwbnwnssshlhrhthggtmggbjbjwwbvbttjllvrrfggngvngnmmvzzrrmddmcddztztctfccqpcpcqqvqppqcqdcdhhvhssgfgzgwwzmmnssvwwbqbhbnhnphpqqjcqcddfwfttqjtqtlttglljgjbgjgnnsqqvrvffqvqfqbffljjpffssqdsqstqqqldqqmhmsmsqqwtqwqdqgdgjjfbjffgbbrhhqghgppqgpgmpmmfzfhhfrhffgmfggpzgpzzhtzhhlbhhqbbzvvnvqnntptmmbhbdhdwwmjjcnnmsscqcbbtjtvjvwjvvmsmjmtmpmgghttcztzggpddbfbfgbbdsdrsrrqfqjjqfjjhzhtzzmdzzcgzgdzzmvmmfmjmgjmggmppbdppmzpppvfppzhhfsfwfhhpjpmmrjjpssdccjpjpwjppvdpphcpcjcfjfwjfwfjwfjjqcqcwqqqsmmmbbgdgwwpcwwdfdlflrltlgtthfhfjhhlthtddlgdggsjsrrdpdcppgttphpgpwppmpzmmrjmmvjvgvgfglfgllbqlqhllszzlwwhzzdfdcdtctptwtztfzzmjzjtjtrjrcrnrjjmwmnnbddgvgtgsstjsszmpqdmzgqflrbrspjmtzjcrmlzltmhgblghnwqvwwqwzbpnfrpdpblpjgshfccfbjfsnwvvhnjftsdnsgtzzjtzpmtfdvzrhtqpblhwgmqtgpbfvbdmsnrrrvvbstpsznvbbwgjfqjrhdvwvgptpglpfddhddmtglmjlpwlvfpbtbmgbplbzrlpdlvqzcwhbscpszgfstjpfdvfpmljlngrbgrdnnblzqrfpzsdvblpwbtnhdjclldvwvbwcwzfzbdspgwpfqjfbdbrqcshtlvcrdstnzggbwqnzbrfzbpnrtmvpbvdhcvdsdshgtvhfgdzljflppqbwclnvbhbczvrscjhlbgbfvwdjhnjsgmvwhpfgwbbmnndpnglfrmtfdzvqgfjdqfhgrhvpbqndmqnqccgwswwdsqjnbjtjbjdbqgjnmfbdvlnfwbnrdqgvgzzhmmbbdzfdvvpwhpbwbnzdcdpchrwlhfsjnhhjggvplmqggwjdsvjtpnpnqgldjjdcscrdltssjdrpcrfbgbcjfplhzgwbprfcslhpcngtszrghmwhzdqscbfrhzdwcffzvmjrmcjcstfvhplvrsglgsjnjtrpddsdfqjsndjnfmvdhfgdbzzflqhsrrwmrnlpqzmcddqbqvvzgtlztpgjnddtcnbmqsjlhmcszrmcjvwzpptlfqsmpvgnzvrjdwzpdwqgbmdgdtvjlmfczthjbcgfhbqpnmlbmrwwhfptzlbmfdhssznjcvjbmnjtnvzjhzczlrrdnttmmcbnzhqpplzqwgttwrnwfvmnptgqlfrnzvqpjfgrzwmlcwvtptvcvrlsrdwdgqfvffspmdbnnrqjttpqvhvdpbcrvzptwnhhfsqzchmncvttcdgdnlppcfzpmjpvbvqhlvplwvrmmbbggbwttwmvsqjlllsftprsmtmnzjcqfzblrllzgshfljchrjwjlpvhpbrtrsschzltrblgjnbgdnmwdggjhqggntblnhsvfgsbcblhmctbqzqwmhqnjhpzjfqpjdgwpzhczcftfcpdhvzhzccmwmrfrbqshzmtpqgpbbvfqqbjbmvnlnlwjtzrpmhdlffccrqcfgsjfszbrzrfztntchtmgmbhjgmlsqzcbtqqjzzlghtzzqmlnnvsgsvbbjfgqsqbqmqrdzwpwdgbggpdvhvnlzshhntprjdwhnwfvdjzpqgflwrvwgtmfdmfdztcbtfnjdrvgdwwczdgphnvdgrbdchprqldfjrvcsflcmlcmzqvqgsgnzcgmrhccgcmptcdzhbcdgdtppwztfstzqqzqrdzlnzthggjmpcflmbcmdrrjnnpbpqfmjbzqbtsjjgdlmgncbmgspqqvbrvzrdjscpzjsdtcdvsdwqlmwrngttswnrsbqctvhgfnnwblpcqzdmzpfchplslspmghvgcqntmlrfhgpcbpspvfhnvqvglsqzsnsdzddqpbsjhlclslngbwvvgjhwfcncqsmqwbptzvpzlzslsjjjldjpwpfrdlfbjphqcjtsgqdsdfdjhqgdhcppndwmhmmldvvmblcqcqfqhltbcbvrnghjfmtgqwtwljtczvqlnmgscjhqdhnzwhzvzzqnlsrhqvljqpgpwghfqlhjjrrhvnmnnrbnlhdcjctwtlhmhhmhjvcgzdrzmdjrvqzgnsttjdwglgwlcmbcdnjprgfsbbdzzngbqdrvwwwhbtlnnmzqdjttsrrpvlfdqnfhhtdtvmpcjgdwtbnqmwmtszdqfmbhjsjpqqddzfggwjhbtlnqfgcwbjzdtcpcpzgnrmnvwlpgmwfjlpgppdfrfvvjwsfcdqdnpcpjbqsvhttssgptqjghctrbgntlfjzdrfjccsprsjlrrwrzsmnjsqslmpdtrvhlqbnmgpjthpqdqmnvrtzlhhzzfzbrcclpmpcszhbttgrtcpgcpjwpdbfpfvgspsgtvglwthqcmcvmrfmclwlvjlsptfgmtlrnsvjrnfwzhdcsmgztpzfcvzwdztpppvqpvqfpdrsfnlhrbqwrsqjtwjmhnpwmqmpdgdhbtbpfwnmswffdqffdggrdrpmngvpzplmmwlddnhcvjjzqqfsbbtfmzdwnpvbjrshmllczhgvwwcbcbtfrfnplqjwmjlvpwwgfrtffwddwppsgtnlmpvfnhfzcsgjbqbjmbvpnqppsrvwnlzvcmjqgtbzrdsnrgwbfmrvnflgccrssfvcwgllqqbbcthzmbtnsmbzbcczhtzcvmthttpltrtdmgspctvtpvqbhmnnpnjwmhpqclmjsdrbjwvjbtzcjlqbjsvbgdwqzflnwzcfjwtrhjgfshfmwbjfwpnhjsmtpgbpwlfjjnmdlrhchmnfmgmgcrftmwbzshdwbhndgwtjbrrvbwprqppfmgfmfllpcjgrwdmtzddthsjlgjljv -------------------------------------------------------------------------------- /day_09/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | fn main() { 4 | let file_contents = fs::read_to_string("input.txt").unwrap(); 5 | 6 | let mut knots: Vec<(i32, i32)> = Vec::new(); 7 | for _ in 0..10 { 8 | knots.push((0, 0)); 9 | } 10 | let mut tail_visited: Vec<(i32, i32)> = Vec::new(); 11 | tail_visited.push((0, 0)); 12 | 13 | // print_board(&knots); 14 | 15 | for line in file_contents.lines() { 16 | // Line is "R 4" - split into move, distance (integer) 17 | let mut parts = line.split(" "); 18 | let direction = parts.next().unwrap(); 19 | let distance = parts.next().unwrap().parse::().unwrap(); 20 | println!("direction = {} distance = {}", direction, distance); 21 | // First move the head 22 | for _ in 0..distance { 23 | match direction { 24 | "R" => knots[0].0 += 1, 25 | "L" => knots[0].0 -= 1, 26 | "U" => knots[0].1 += 1, 27 | "D" => knots[0].1 -= 1, 28 | _ => panic!("Unknown direction {}", direction), 29 | } 30 | println!(" head_pos = {:?}", knots[0]); 31 | // Now move each other knot in turn, if it needs to be moved 32 | for i in 1..knots.len() { 33 | // Is knot within one of head in either direction? 34 | let mut knot = knots[i]; 35 | let prev = knots[i - 1]; 36 | if (prev.0 == knot.0 && (prev.1 - knot.1).abs() == 1) 37 | || (prev.1 == knot.1 && (prev.0 - knot.0).abs() == 1) 38 | { 39 | println!(" Touching, no need to move"); 40 | } 41 | // Are tail and head diagonally touching? 42 | else if (prev.0 - knot.0).abs() == 1 && (prev.1 - knot.1).abs() == 1 { 43 | println!(" Diagonally touching, no need to move"); 44 | } else { 45 | // Need to move the tail 46 | // If tail is not in same row AND column as head... 47 | if prev.0 != knot.0 && prev.1 != knot.1 { 48 | // Move it diagonally in the right direction 49 | knot.0 += to_one(prev.0 - knot.0); 50 | knot.1 += to_one(prev.1 - knot.1); 51 | } else { 52 | // Move it in the right direction 53 | if prev.0 == knot.0 { 54 | knot.1 += to_one(prev.1 - knot.1); 55 | } else { 56 | knot.0 += to_one(prev.0 - knot.0); 57 | } 58 | } 59 | knots[i] = knot; 60 | println!(" knot = {:?}", knot); 61 | if i == 9 { 62 | tail_visited.push(knot); 63 | } 64 | } 65 | } 66 | // print_board(&head_pos, &tail_pos); 67 | } 68 | } 69 | println!("tail_visited = {:?}", tail_visited); 70 | // Count unique tuples in that 71 | let mut unique_tuples = Vec::new(); 72 | for tuple in tail_visited { 73 | if !unique_tuples.contains(&tuple) { 74 | unique_tuples.push(tuple); 75 | } 76 | } 77 | println!("Number of unique locations = {:?}", unique_tuples.len()); 78 | } 79 | /* 80 | fn print_board(knots: &knot) { 81 | for y in 0..10 { 82 | for x in 0..10 { 83 | // If both in same spot do an X 84 | if x == head_pos.0 && y == head_pos.1 && x == tail_pos.0 && y == tail_pos.1 { 85 | print!("X"); 86 | } else if x == head_pos.0 && y == head_pos.1 { 87 | print!("H"); 88 | } else if x == tail_pos.0 && y == tail_pos.1 { 89 | print!("T"); 90 | } else { 91 | print!("."); 92 | } 93 | } 94 | println!(""); 95 | } 96 | } 97 | */ 98 | 99 | 100 | fn to_one(n: i32) -> i32 { 101 | if n > 0 { 102 | 1 103 | } else if n < 0 { 104 | -1 105 | } else { 106 | 0 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /day_05/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::fs; 3 | use std::io; 4 | use std::io::BufRead; 5 | 6 | 7 | 8 | fn main() -> Result<(), std::io::Error> { 9 | // Get the arguments as an iterator 10 | let args: Vec = env::args().collect(); 11 | 12 | // Ensure that at least one argument was passed 13 | if args.len() < 2 { 14 | println!("error: missing required argument 'filename'"); 15 | return Ok(()); 16 | } 17 | 18 | // Get the value of the filename argument 19 | let filename = &args[1]; 20 | 21 | // Check if the multistack flag was passed 22 | let multistack = args.iter().any(|arg| arg == "--multistack" || arg == "-m"); 23 | /* 24 | [V] [C] [M] 25 | [V] [J] [N] [H] [V] 26 | [R] [F] [N] [W] [Z] [N] 27 | [H] [R] [D] [Q] [M] [L] [B] 28 | [B] [C] [H] [V] [R] [C] [G] [R] 29 | [G] [G] [F] [S] [D] [H] [B] [R] [S] 30 | [D] [N] [S] [D] [H] [G] [J] [J] [G] 31 | [W] [J] [L] [J] [S] [P] [F] [S] [L] 32 | 1 2 3 4 5 6 7 8 9 33 | */ 34 | // Start by reading the file up to the blank line 35 | // and parsing it into a vector of vector-char stacks 36 | let file = fs::File::open(filename)?; 37 | let reader = io::BufReader::new(file); 38 | let mut stacks = Vec::new(); 39 | // Populate with 9 empty stacks of chars 40 | for _ in 0..9 { 41 | stacks.push(Vec::new()); 42 | } 43 | let mut line_strings: Vec = Vec::new(); 44 | 45 | for line in reader.lines() { 46 | let line = line?; 47 | line_strings.push(line); 48 | } 49 | 50 | let mut line_index = 0; 51 | loop { 52 | let line = &line_strings[line_index]; 53 | // Stop when line starts with " 1" 54 | if line.starts_with(" 1") { 55 | break; 56 | } 57 | // Add one space to the end of the line 58 | let line = format!("{} ", line); 59 | // Read it four characters at a time 60 | let mut stack_index = 0; 61 | for chunk in line.as_bytes().chunks(4) { 62 | // Look at second character in chunk 63 | let c = chunk[1] as char; 64 | if c != ' ' { 65 | stacks[stack_index].push(c); 66 | } 67 | stack_index += 1; 68 | } 69 | line_index += 1; 70 | } 71 | 72 | // Reverse the order of every stack 73 | for stack in stacks.iter_mut() { 74 | stack.reverse(); 75 | } 76 | // debug print the stacks 77 | for stack in &stacks { 78 | println!("{:?}", stack); 79 | } 80 | // Next read the remaining lines and apply each one 81 | // to the stacks - skip 2 (the stack names and the blank line) 82 | for line in line_strings.iter().skip(line_index + 2) { 83 | // Format: "move 10 from 8 to 1" 84 | // Split on spaces, convert that to a vector 85 | let parts: Vec<&str> = line.split(" ").collect(); 86 | // num_cards is 1st index, from_stack is 3rd, to_stack is 5th 87 | let num_cards: i32 = parts[1 as usize].parse().unwrap(); 88 | let from_stack: i32 = parts[3 as usize].parse().unwrap(); 89 | let to_stack: i32 = parts[5 as usize].parse().unwrap(); 90 | 91 | println!("{} cards move from {} to {}", num_cards, from_stack, to_stack); 92 | println!(" from stack before: {:?}", stacks[(from_stack - 1) as usize]); 93 | println!(" to stack before: {:?}", stacks[(to_stack - 1) as usize]); 94 | 95 | // Move the cards 96 | if multistack { 97 | // Create vector for cards to move 98 | let mut cards_to_move = Vec::new(); 99 | for _ in 0..num_cards { 100 | let card = stacks[from_stack as usize - 1].pop().unwrap(); 101 | cards_to_move.push(card); 102 | } 103 | cards_to_move.reverse(); 104 | // Move them 105 | for card in cards_to_move { 106 | stacks[to_stack as usize - 1].push(card); 107 | } 108 | } else { 109 | // Move cards one at a time 110 | for _ in 0..num_cards { 111 | let card = stacks[from_stack as usize - 1].pop().unwrap(); 112 | stacks[to_stack as usize - 1].push(card); 113 | } 114 | } 115 | 116 | println!(" from stack after: {:?}", stacks[(from_stack - 1) as usize]); 117 | println!(" to stack after: {:?}", stacks[(to_stack - 1) as usize]); 118 | 119 | } 120 | // debug print the stacks 121 | for stack in &stacks { 122 | println!("{:?}", stack); 123 | } 124 | // Create string with top card of each stack 125 | let mut result = String::new(); 126 | for stack in &stacks { 127 | if stack.len() > 0 { 128 | result.push(stack[stack.len() - 1]); 129 | } 130 | } 131 | println!("Result: {}", result); 132 | Ok(()) 133 | } 134 | -------------------------------------------------------------------------------- /day_11/src/main.rs: -------------------------------------------------------------------------------- 1 | use regex::Regex; 2 | use std::fs; 3 | 4 | #[derive(Debug)] 5 | enum Operand { 6 | // Can either be an integer or a 'Old' 7 | Int(i64), 8 | Old, 9 | } 10 | #[derive(Debug)] 11 | enum Op { 12 | Plus, 13 | Times, 14 | } 15 | 16 | #[derive(Debug)] 17 | struct Monkey { 18 | id: i32, 19 | items: Vec, 20 | operation_left: Operand, 21 | operation_right: Operand, 22 | operation_op: Op, 23 | test_divisible_by: i64, 24 | if_true_monkey: i32, 25 | if_false_monkey: i32, 26 | items_inspected: i64, 27 | } 28 | 29 | fn main() { 30 | let mut monkeys = Vec::new(); 31 | 32 | let file_contents = fs::read_to_string("input.txt").unwrap(); 33 | 34 | let re = Regex::new( 35 | r"Monkey (\d+):\s* 36 | Starting items: (\d+(?:,\s*\d+)*)\s* 37 | Operation: new = old (\*|\+) (old|\d+)\s* 38 | Test: divisible by (\d+)\s* 39 | If true: throw to monkey (\d+)\s* 40 | If false: throw to monkey (\d+)", 41 | ) 42 | .unwrap(); 43 | 44 | // Use find_iter to find all matches for that regex 45 | // and then extract the data from each match 46 | for cap in re.captures_iter(&file_contents) { 47 | println!("Found match: {:?}", cap); 48 | let monkey_id = cap[1].parse::().unwrap(); 49 | let items = cap[2] 50 | .split(", ") 51 | .map(|x| x.parse::().unwrap()) 52 | .collect::>(); 53 | let operation_op = match &cap[3] { 54 | "+" => Op::Plus, 55 | "*" => Op::Times, 56 | _ => panic!("Unknown operation"), 57 | }; 58 | let operation_left = Operand::Old; 59 | println!("Dealing with {}", &cap[4]); 60 | let operation_right = match &cap[4] == "old" { 61 | true => Operand::Old, 62 | false => Operand::Int(cap[4].parse::().unwrap()), 63 | }; 64 | let test_divisible_by = cap[5].parse::().unwrap(); 65 | let if_true_monkey = cap[6].parse::().unwrap(); 66 | let if_false_monkey = cap[7].parse::().unwrap(); 67 | 68 | let monkey = Monkey { 69 | id: monkey_id, 70 | items, 71 | operation_left, 72 | operation_right, 73 | operation_op, 74 | test_divisible_by, 75 | if_true_monkey, 76 | if_false_monkey, 77 | items_inspected: 0, 78 | }; 79 | monkeys.push(monkey); 80 | } 81 | 82 | let common_divider: i64 = monkeys 83 | .iter() 84 | .map(|monkey| monkey.test_divisible_by) 85 | .product(); 86 | 87 | println!("Common divider: {}", common_divider); 88 | 89 | for round in 1..10001 { 90 | // Loop through and process every monkey 91 | for i in 0..monkeys.len() { 92 | let monkey = &mut monkeys[i]; 93 | let mut items_to_send = Vec::new(); 94 | while monkey.items.len() > 0 { 95 | // Take left-most item from monkey.items 96 | let item = monkey.items.remove(0); 97 | monkey.items_inspected += 1; 98 | let result; 99 | // First the monkey applies the operation to the item 100 | println!( 101 | "About to attempt operation: {:?} {:?} {:?}, Old = {}", 102 | monkey.operation_left, monkey.operation_op, monkey.operation_right, item 103 | ); 104 | match monkey.operation_op { 105 | Op::Plus => { 106 | result = match monkey.operation_left { 107 | Operand::Int(i) => i, 108 | Operand::Old => item, 109 | } + match monkey.operation_right { 110 | Operand::Int(i) => i, 111 | Operand::Old => item, 112 | }; 113 | } 114 | Op::Times => { 115 | result = match monkey.operation_left { 116 | Operand::Int(i) => i, 117 | Operand::Old => item, 118 | } * match monkey.operation_right { 119 | Operand::Int(i) => i, 120 | Operand::Old => item, 121 | }; 122 | } 123 | } 124 | // Worry level no longer reduces: 125 | // result = result / 3; 126 | let target_monkey_idx = match result % monkey.test_divisible_by { 127 | 0 => monkey.if_true_monkey, 128 | _ => monkey.if_false_monkey, 129 | }; 130 | items_to_send.push((target_monkey_idx, result % common_divider)); 131 | } 132 | println!( 133 | " Monkey {}, items_to_send = {:?}", 134 | monkey.id, items_to_send 135 | ); 136 | // Now we send the items to the other monkeys 137 | for (target_monkey_idx, item) in &items_to_send { 138 | monkeys[*target_monkey_idx as usize].items.push(*item); 139 | } 140 | } 141 | println!("\nAfter {} rounds:\n\n", round); 142 | for monkey in &monkeys { 143 | println!("Monkey {:?}", monkey); 144 | } 145 | println!("\nLevel of monkey business (product of num inspected for two busiest monkeys):"); 146 | let items_inspected = monkeys 147 | .iter() 148 | .map(|x| x.items_inspected) 149 | .collect::>(); 150 | // Pick the top two 151 | let mut top_two = items_inspected.clone(); 152 | top_two.sort(); 153 | top_two.reverse(); 154 | let top_two = top_two[0..2].to_vec(); 155 | let level_of_monkey_business = top_two[0] * top_two[1]; 156 | println!(" {}", level_of_monkey_business); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /day_15/src/main.rs: -------------------------------------------------------------------------------- 1 | use regex::Regex; 2 | use std::fs; 3 | 4 | #[derive(Debug)] 5 | struct Sensor { 6 | x: i32, 7 | y: i32, 8 | beacon_x: i32, 9 | beacon_y: i32, 10 | } 11 | 12 | // A method 13 | impl Sensor { 14 | fn distance(&self) -> i32 { 15 | // Manhattan distance from sensor to beacon 16 | (self.x - self.beacon_x).abs() + (self.y - self.beacon_y).abs() 17 | } 18 | fn point_cannot_have_beacon(&self, x: i32, y: i32) -> bool { 19 | // This point cannot have a beacon if it is within distance of sensor 20 | (x - self.x).abs() + (y - self.y).abs() <= self.distance() 21 | } 22 | fn points_around_edge(&self) -> Vec<(i32, i32)> { 23 | // Find diagonal points on the border around the edge of the shape 24 | let mut points = Vec::new(); 25 | let mut x = self.x - self.distance(); 26 | let mut y = self.y - self.distance(); 27 | let mut dx = 1; 28 | let mut dy = 1; 29 | let mut d = 0; 30 | let mut i = 0; 31 | while i < 4 * self.distance() { 32 | points.push((x, y)); 33 | x += dx; 34 | y += dy; 35 | d += 1; 36 | if d == self.distance() { 37 | d = 0; 38 | if dx == 1 { 39 | dx = 0; 40 | dy = 1; 41 | } else if dy == 1 { 42 | dx = -1; 43 | dy = 0; 44 | } else if dx == -1 { 45 | dx = 0; 46 | dy = -1; 47 | } else if dy == -1 { 48 | dx = 1; 49 | dy = 0; 50 | } 51 | } 52 | i += 1; 53 | } 54 | points 55 | } 56 | } 57 | 58 | fn beacon_exists_at(sensors: &Vec, x: i32, y: i32) -> bool { 59 | for sensor in sensors { 60 | if sensor.beacon_x == x && sensor.beacon_y == y { 61 | return true; 62 | } 63 | } 64 | false 65 | } 66 | 67 | fn beacon_or_sensor_exists_at(sensors: &Vec, x: i32, y: i32) -> bool { 68 | for sensor in sensors { 69 | if (sensor.beacon_x == x && sensor.beacon_y == y) || (sensor.x == x && sensor.y == y) { 70 | return true; 71 | } 72 | } 73 | false 74 | } 75 | 76 | fn main() { 77 | let file_contents = fs::read_to_string("example.txt").unwrap(); 78 | let mut sensors = Vec::new(); 79 | // Sensor at x=10, y=20: closest beacon is at x=10, y=16 80 | let re = 81 | Regex::new(r"Sensor at x=(\d+), y=(\d+): closest beacon is at x=(\d+), y=(\d+)").unwrap(); 82 | for cap in re.captures_iter(&file_contents) { 83 | let sensor = Sensor { 84 | x: cap[1].parse().unwrap(), 85 | y: cap[2].parse().unwrap(), 86 | beacon_x: cap[3].parse().unwrap(), 87 | beacon_y: cap[4].parse().unwrap(), 88 | }; 89 | sensors.push(sensor); 90 | } 91 | // println!("{:#?}", sensors); 92 | 93 | // Figure out dimensions of possible space 94 | // For each sensor, look at how big its range could possibly be, 95 | // then find min and max x and y based on that 96 | let mut min_x = 0; 97 | let mut max_x = 0; 98 | let mut min_y = 0; 99 | let mut max_y = 0; 100 | for sensor in &sensors { 101 | let distance = sensor.distance(); 102 | if sensor.x - distance < min_x { 103 | min_x = sensor.x - distance; 104 | } 105 | if sensor.x + distance > max_x { 106 | max_x = sensor.x + distance; 107 | } 108 | if sensor.y - distance < min_y { 109 | min_y = sensor.y - distance; 110 | } 111 | if sensor.y + distance > max_y { 112 | max_y = sensor.y + distance; 113 | } 114 | } 115 | println!( 116 | "min_x: {}, max_x: {}, min_y: {}, max_y: {}", 117 | min_x, max_x, min_y, max_y 118 | ); 119 | 120 | // How many points on line y=line_to_search could NOT have a sensor? 121 | let line_to_search = 10; // 10 or 2000000 122 | let mut count = 0; 123 | for x in min_x..=max_x { 124 | let mut point_cannot_have_beacon = false; 125 | for sensor in &sensors { 126 | if sensor.point_cannot_have_beacon(x, line_to_search) { 127 | point_cannot_have_beacon = true; 128 | break; 129 | } 130 | } 131 | if point_cannot_have_beacon && !beacon_exists_at(&sensors, x, line_to_search) { 132 | count += 1; 133 | } 134 | } 135 | println!("Count: {}", count); 136 | 137 | println!("\nPart 2\n======\n"); 138 | 139 | // Search the space to find the beacon 140 | let max_search = 20; // 20 or 4000000 141 | 142 | // I'm just going to search the points that are a single square outside each sensor 143 | for sensor in &sensors { 144 | let points = sensor.points_around_edge(); 145 | println!("Sensor: {:?}", sensor); 146 | println!("Points: {:?}", points); 147 | continue; 148 | 'outer: for (x, y) in points { 149 | /* 150 | if x == 14 && y == 11 { 151 | println!("Found it! {:?}", (x, y)); 152 | // Check no sensor can see it 153 | for sensor in &sensors { 154 | if sensor.point_cannot_have_beacon(x, y) { 155 | println!("Sensor {:?} says it cannot be here", sensor); 156 | break; 157 | } 158 | } 159 | } 160 | */ 161 | if x < 0 || y < 0 { 162 | continue; 163 | } 164 | 165 | for sensor in &sensors { 166 | if sensor.point_cannot_have_beacon(x, y) { 167 | println!("Sensor {:?} says {:?} cannot be here", sensor, (x, y)); 168 | break 'outer; 169 | } 170 | } 171 | println!("Found it! {:?}", (x, y)); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /day_08/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | use std::fs; 3 | 4 | #[derive(Debug)] 5 | struct Map { 6 | lines: Vec, 7 | } 8 | 9 | struct ScenicScore { 10 | x: usize, 11 | y: usize, 12 | char: char, 13 | top: usize, 14 | bottom: usize, 15 | left: usize, 16 | right: usize, 17 | score: usize, 18 | } 19 | 20 | impl fmt::Debug for ScenicScore { 21 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 22 | write!( 23 | f, 24 | "({}, {}) char: {}, top: {}, bottom: {}, left: {}, right: {}, score: {}", 25 | self.x, self.y, self.char, self.top, self.bottom, self.left, self.right, self.score 26 | ) 27 | } 28 | } 29 | // An explanation of: 30 | // &mut fmt::Formatter<'_> 31 | // in as much detail as possible: 32 | // 33 | // &mut fmt::Formatter<'_> is a reference to a mutable Formatter object 34 | // that has a lifetime of '_. 35 | // 36 | // The lifetime of a reference is the scope in which it is valid. 37 | // _ means: 38 | // "I don't care what the lifetime is, just make it compile" 39 | 40 | // Method that returns x,y coordinate 41 | impl Map { 42 | // x is along the line, y is down the lines 43 | fn get(&self, x: usize, y: usize) -> char { 44 | self.lines[y].chars().nth(x).unwrap() 45 | } 46 | fn item_is_visible(&self, x: usize, y: usize) -> bool { 47 | // Items on the edges are always visible 48 | if x == 0 || x == self.lines[0].len() - 1 || y == 0 || y == self.lines.len() - 1 { 49 | return true; 50 | } 51 | let current_char = self.get(x, y); 52 | let mut visible_from_top = true; 53 | let mut visible_from_bottom = true; 54 | let mut visible_from_left = true; 55 | let mut visible_from_right = true; 56 | 57 | // Visible from top? 58 | for i in 0..y { 59 | let char = self.get(x, i); 60 | if char >= current_char { 61 | visible_from_top = false; 62 | break; 63 | } 64 | } 65 | // Visible from bottom? 66 | for i in y + 1..self.lines.len() { 67 | let char = self.get(x, i); 68 | if char >= current_char { 69 | visible_from_bottom = false; 70 | break; 71 | } 72 | } 73 | // Visible from left? 74 | for i in 0..x { 75 | let char = self.get(i, y); 76 | if char >= current_char { 77 | visible_from_left = false; 78 | break; 79 | } 80 | } 81 | // Visible from right? 82 | for i in x + 1..self.lines[y].len() { 83 | let char = self.get(i, y); 84 | if char >= current_char { 85 | visible_from_right = false; 86 | break; 87 | } 88 | } 89 | visible_from_top || visible_from_bottom || visible_from_left || visible_from_right 90 | } 91 | // Returns tuple of four integers 92 | fn viewing_distances(&self, x: usize, y: usize) -> (usize, usize, usize, usize) { 93 | let mut top = 0; 94 | let mut bottom = 0; 95 | let mut left = 0; 96 | let mut right = 0; 97 | let current_char = self.get(x, y); 98 | // Top: look from current position, in reverse direction 99 | for i in (0..y).rev() { 100 | let char = self.get(x, i); 101 | top += 1; 102 | if char >= current_char { 103 | break; 104 | } 105 | } 106 | // Bottom 107 | for i in y + 1..self.lines.len() { 108 | let char = self.get(x, i); 109 | bottom += 1; 110 | if char >= current_char { 111 | break; 112 | } 113 | } 114 | // Left - look from current position, in reverse direction 115 | for i in (0..x).rev() { 116 | let char = self.get(i, y); 117 | left += 1; 118 | if char >= current_char { 119 | break; 120 | } 121 | } 122 | // Right 123 | for i in x + 1..self.lines[y].len() { 124 | let char = self.get(i, y); 125 | right += 1; 126 | if char >= current_char { 127 | break; 128 | } 129 | } 130 | (top, bottom, left, right) 131 | } 132 | } 133 | 134 | fn main() { 135 | let file_contents = fs::read_to_string("input.txt").unwrap(); 136 | let mut map = Map { lines: Vec::new() }; 137 | for line in file_contents.lines() { 138 | map.lines.push(line.to_string()); 139 | } 140 | let mut visible_count = 0; 141 | for y in 0..map.lines.len() { 142 | for x in 0..map.lines[y].len() { 143 | let is_visible = map.item_is_visible(x, y); 144 | if is_visible { 145 | visible_count += 1; 146 | print!("X"); 147 | } else { 148 | print!(" "); 149 | } 150 | } 151 | // Output the line too, with extra spaces between characters 152 | let spaced_line = map.lines[y].replace("", " "); 153 | println!(" {}", spaced_line); 154 | } 155 | println!("\nVisible count: {}", visible_count); 156 | 157 | println!("\nPart 2\n======\n\n"); 158 | 159 | let mut scenic_scores = Vec::new(); 160 | for y in 0..map.lines.len() { 161 | for x in 0..map.lines[y].len() { 162 | let (top, bottom, left, right) = map.viewing_distances(x, y); 163 | let score = top * bottom * left * right; 164 | scenic_scores.push(ScenicScore { 165 | x, 166 | y, 167 | char: map.get(x, y), 168 | top, 169 | bottom, 170 | left, 171 | right, 172 | score, 173 | }); 174 | // Print centered within 8 characters 175 | print!("{:8}", score); 176 | } 177 | println!(); 178 | } 179 | let max_score = scenic_scores 180 | .iter() 181 | .max_by(|a, b| a.score.cmp(&b.score)) 182 | .unwrap(); 183 | println!("Max score: {:#?}", max_score); 184 | } 185 | -------------------------------------------------------------------------------- /day_12/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | use petgraph::algo::dijkstra; 4 | use petgraph::prelude::*; 5 | use petgraph::Graph; 6 | 7 | #[derive(Debug, Clone)] 8 | struct Node { 9 | idx: usize, 10 | char: char, 11 | x: i32, 12 | y: i32, 13 | // Vector of indexes in the `nodes` vector of connected nodes 14 | connections: Vec, 15 | } 16 | 17 | fn main() { 18 | let file_contents = fs::read_to_string("input.txt").unwrap(); 19 | // Create grid 20 | let mut grid: Vec> = Vec::new(); 21 | let mut start_coord = (0, 0); 22 | let mut end_coord = (0, 0); 23 | let mut line_number = 0; 24 | for line in file_contents.lines() { 25 | let mut chars: Vec = line.chars().collect(); 26 | // Look for S and replace it with an 'a' 27 | let index_of_capital_s = match chars.iter().position(|&c| c == 'S') { 28 | Some(i) => i as i32, 29 | None => -1, 30 | }; 31 | if index_of_capital_s != -1 { 32 | start_coord = (line_number, index_of_capital_s); 33 | chars[index_of_capital_s as usize] = 'a'; 34 | } 35 | // Look for E and replace it with a 'z' 36 | let index_of_capital_e = match chars.iter().position(|&c| c == 'E') { 37 | Some(i) => i as i32, 38 | None => -1, 39 | }; 40 | if index_of_capital_e != -1 { 41 | end_coord = (line_number, index_of_capital_e); 42 | chars[index_of_capital_e as usize] = 'z'; 43 | } 44 | grid.push(chars); 45 | line_number += 1; 46 | } 47 | println!("Start coord: {:?}", start_coord); 48 | println!("End coord: {:?}", end_coord); 49 | // Now figure out which nodes are connected to which 50 | 51 | let mut nodes: Vec = Vec::new(); 52 | let mut node_idx = 0; 53 | // Iterate through grid getting back an index each time 54 | for (y, row) in grid.iter().enumerate() { 55 | for (x, char) in row.iter().enumerate() { 56 | let node = Node { 57 | idx: node_idx as usize, 58 | char: *char, 59 | x: x as i32, 60 | y: y as i32, 61 | connections: Vec::new(), 62 | }; 63 | nodes.push(node); 64 | node_idx += 1; 65 | } 66 | } 67 | // Now populate connections for each node 68 | let mut connections_to_add = Vec::new(); 69 | let nodes_clone = nodes.clone(); 70 | for node in nodes_clone.iter() { 71 | let left_node = nodes_clone 72 | .iter() 73 | .find(|n| n.x == node.x - 1 && n.y == node.y); 74 | let right_node = nodes_clone 75 | .iter() 76 | .find(|n| n.x == node.x + 1 && n.y == node.y); 77 | let up_node = nodes_clone 78 | .iter() 79 | .find(|n| n.x == node.x && n.y == node.y - 1); 80 | let down_node = nodes_clone 81 | .iter() 82 | .find(|n| n.x == node.x && n.y == node.y + 1); 83 | for other_node in vec![left_node, right_node, up_node, down_node] { 84 | match other_node { 85 | Some(n) => { 86 | // Is other_node no more than 1 higher than node? 87 | let diff = n.char as i32 - node.char as i32; 88 | /* println!( 89 | " . node: {}, other_node: {}, diff: {}", 90 | node.char, n.char, diff 91 | ); 92 | */ 93 | if diff <= 1 { 94 | connections_to_add.push((node.idx, n.idx)); 95 | } 96 | } 97 | None => {} 98 | } 99 | } 100 | } 101 | // Add all those connections 102 | for (node_idx, other_node_idx) in connections_to_add.iter() { 103 | nodes[*node_idx].connections.push(*other_node_idx); 104 | } 105 | 106 | // println!("{:#?}", nodes); 107 | 108 | // Build a graph 109 | let mut graph: Graph<(), (), Directed> = Graph::new(); 110 | let mut graph_nodes = Vec::new(); 111 | 112 | // Add a blank node to the graph for every node 113 | for _ in nodes.iter() { 114 | let graph_node = graph.add_node(()); 115 | graph_nodes.push(graph_node); 116 | } 117 | 118 | // Populate with connections 119 | for node in nodes.iter() { 120 | for other_node_idx in node.connections.iter() { 121 | graph.add_edge(graph_nodes[node.idx], graph_nodes[*other_node_idx], ()); 122 | } 123 | } 124 | 125 | // println!("{:?}", graph); 126 | 127 | // Run dijkstra's algorithm 128 | let start_node_index = nodes 129 | .iter() 130 | .position(|n| n.x == start_coord.1 && n.y == start_coord.0) 131 | .expect("Couldn't find start node"); 132 | let end_node_index = nodes 133 | .iter() 134 | .position(|n| n.x == end_coord.1 && n.y == end_coord.0) 135 | .expect("Couldn't find end node"); 136 | 137 | let start_graph_node = graph_nodes[start_node_index]; 138 | let end_graph_node = graph_nodes[end_node_index]; 139 | 140 | let shortest_path = dijkstra(&graph, start_graph_node, Some(end_graph_node), |_e| 1); 141 | 142 | println!("\nShortest path: {:?}", shortest_path); 143 | println!(""); 144 | println!("end graph node: {:?}", end_graph_node); 145 | println!(""); 146 | println!("Shortest path length: {}", shortest_path[&end_graph_node]); 147 | 148 | // Part 2 149 | println!("\nPart 2\n======\n\n"); 150 | 151 | // Set to max int: 152 | let mut shortest_path_from_an_a = std::i32::MAX; 153 | 154 | // Loop through every `a` node and their index: 155 | for (a_node_index, a_node) in nodes.iter().enumerate() { 156 | if a_node.char == 'a' { 157 | // Run dijkstra's algorithm 158 | let a_node = graph_nodes[a_node_index]; 159 | let shortest_path = dijkstra(&graph, a_node, Some(end_graph_node), |_e| 1); 160 | 161 | if shortest_path.contains_key(&end_graph_node) { 162 | let path_length = shortest_path[&end_graph_node]; 163 | println!("Path length: {} for node: {:?}", path_length, a_node); 164 | if path_length < shortest_path_from_an_a { 165 | shortest_path_from_an_a = path_length; 166 | } 167 | } 168 | } 169 | } 170 | println!( 171 | "Shortest path from an `a` node: {}", 172 | shortest_path_from_an_a 173 | ); 174 | } 175 | -------------------------------------------------------------------------------- /day_12/input.txt: -------------------------------------------------------------------------------- 1 | abccccaaaaaaaaaaaaaccaaaaaaaacccccccccaaaaaaaaccccccccaaacaaacccccccaaaaaaccccccccccccccccccccccaaaacccccccccccacccccccccccccccccccccccccccccccccccccccccccccccaaaa 2 | abccccaaaaacaaaaaaccccaaaaaaccccccccccaaaaaaacccccccccaaaaaaacccccaaaaaaaaaacccccccccccccccccccaaaaaacccccccccaaaaaaaaccccccccccccccccccccccccccccccccccccccccaaaaa 3 | abcccaaaaaccaaaaaaccccaaaaaaccccccaacccaaaaaacccccccccaaaaaacccaaaaaaaaaaaaaaacaaccacccccccccccaaaaaaccccccccccaaaaaacccccccccccccccccccccccccccccccccccccccccaaaaa 4 | abccccccaaccaaaaaaccaaaaaaaaccccccaaacaaaacaaacccccccaaaaaaaaccaaaaaaaaaaaaaaacaaaaacccccccccccccaaccccccccccccaaaaaaccccccccccccccccccccccccccccacccccccccccaaaaaa 5 | abccccccccccaaccaaccaaaaccaacccccccaaaaaaaccccccccccaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccaaaaccccccccccccccccaaaaaaaacccccccccccccccccccccccccccaaccccccccccccccaa 6 | abcccccccaaaaacccaaaaaaaacccaaccccaaaaaaccccccccccccaaaaaaaaaaaaaaaacaaaaaaaccaaaaaaccccccaaaaaccccccccccccccaaaaaaaaaaccaccccccccccccccccccccccccaccccccccccccccca 7 | abcccccccaaaaacccaaaaaaaaccaaaaccaaaaaaaaccccccccccccccaaacaaaaaaaaacaaaaaacccccaaaacccccaaaaaaccccccccccccccaaaaaaaaaaaaacccccccccccccccllllllccccdccccccccccccccc 8 | abccccccaaaaaacccccaaaaccccaaaaacaaaaaaaaccccccccccccccaaacccccaaaccccaaaaaacccaaccccccccaaaaaacccccccccccccccccaaaaaaaaaacccccccccccccklllllllllcddddccaccaaaccccc 9 | abccccccaaaaaacccccaaaaaaaaaaaaaaaccaaccccccaacaacccccccaaccccccccccccaaacaacccccccccccccaaaaaacccccccccccccccccaaaaaaaaaacccccccccccckklllppllllcddddddddaaaaccccc 10 | abccccccaaaaaaccccaaacaaaaaaaaaaaaccaaccccccaaaaaccccccccccccccccccccccccccccccccccccccccccaaccccccaaccccccccccccaacaaaaaaaccccccccccckklpppppplllmdddddddddacccccc 11 | abccccccccaaacccccaacccaccaaaaaaccccccccccccaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccaaaaccccccccccccaaaaaaaaaaccccccccckkkkppppppplmmmmmmddddddaacccc 12 | abccccaaacaaacccccccccccccaaaaaaccccccccccccaaaaaacccccccccccccccccaaaccccccccccccccccccccccccccccaaaaccccccccccccaaaaaaaaaaccccccccckkkppppuppppmmmmmmmmddeeeacccc 13 | abccccaaaaaaacccccccccccccaaaaaacccaccccccccaaaaaacccccccccccccccccaaaacccccccccccccccccccccaaacccaaaacccccccccccaaaacaaaccccccccccckkkpppuuuuuppqqmmmmmmmmeeeacccc 14 | abcccccaaaaaaccccccccccccaaaaaaaacaaccccccccccaaaccccccccccccccccccaaaaccccccccccccccccccccaaaaccccccccccccccccccaaaaaaaacccccccccckkkkpppuuuuupqqqqqqqmmmmeeeccccc 15 | abcccccaaaaaaaacccccccccccaccccaaaaacccccccccccccccccccccccccccccccaaaccccccccccccccaaaccccaaaacccccccccccccaaccaaaaaaaaccccccccckkkkkrrpuuuxuuuqqqqqqqqmmmmeeccccc 16 | abccccaaaaaaaaaccccccccccccccaaaaaacccccccacaacccccccccccccccccccccccccccccccccccccaaaaaacccaaaccccccccccaaaaccaaaaaaacccccccccckkkkrrrrruuuxxuvvvvvvqqqqnnneeccccc 17 | abcccaaaaaaaaaaccccccccccccccaaaaaaaacccccaaaaacccccccccccccccaaaaaccccccccccccccccaaaaaaccccccccccccccccaaaaaaaaaaaaacccccccccjjjkrrrrruuuxxxxvvvvvvvqqqnnneeccccc 18 | abcaaaaacaaacccccccccccccccccaaaaaaaacccccaaaaaccaacccccccccccaaaaaccccccccccccccccaaaaaccccccccccccccccccaaaaaccaaaaaacccccccjjjrrrrruuuuuxxxyvyyyvvvqqqnneeeccccc 19 | abcaaaaacaaaccaaccccccccccccccccaacccccccaaaaaaaaaaaccccccccccaaaaaaccccccccccccccccaaaaaccccccccccccccccaaaaacccaaaaaaaacaaacjjjrrrtttuuxxxxxyyyyyvvvqqnnneeeccccc 20 | abaaaaaccaacccaaaccaacccaaccccccaccccccccaaaaaaaaaacccccccccccaaaaaaccccccccccccccccaacaacccccccccccccccccccaacccaaccccaaaaaacjjjrrrtttxxxxxxxyyyyyvvvrrnnneeeccccc 21 | SbaaaaacccccccaaaaaaaccaaaacccccccccccccccaaaaaaaaacccccccccccaaaaaaccccccccccccccccccccccccccccccccccccccccccccccaacccaaaaaacjjjrrrtttxxxEzzzzyyyvvvrrnnneeecccccc 22 | abcaaaaacccccccaaaaaaccaaaacccccccccccccccaaaaaaaaacccccccccccccaaccccccccccccccccccccccccccccaaccccccccccaaccccacaaaacaaaaaaajjjrrrtttxxxxxyyyyyvvvrrrnnnfffcccccc 23 | abcaacccccccaaaaaaaacccaaaaccccccccccccccccaaaaaaaaaaccccccccccccccccccccccccccccccccccccccaaaaaccccccccccaaccccaaaaaaaaaaaaaajjjqqqttttxxxxyyyyyyvvrrrnnnfffcccccc 24 | abccccccccccaaaaaaaaaccccccccccccccccccccaaaaaaaaaaaaacccccccccccccccccaacccccccccccccccccccaaaaaccccccaacaaaaaccaaaacaaaaaaaacjjjqqqqttttxxyywyyyywvrrnnnfffcccccc 25 | abccccccccccaaaaaaaaaacccccccccccccccccccaaaaaaaaacaaacccccccccccccaaacaacccccccccccccccccccaaaaaccccccaaaaaaaaccaaaaccccaaacccjjjjqqqqtttxwywwwyywwwrrnnnfffcccccc 26 | abcccccccccccccaaaaaaacccccccccccccccccccaaaaaaaaaaaaaaaacccccccccccaaaaaccccccccccccccccccaaaaacccaaccccaaaaccccaacaacccaaaccccjjjiqqqtttwwywwwwwwwwrrroofffcccccc 27 | abcccccccccccccaaaccccccccccccccccccccccaaaaaaaaaaaaaaaaaccccccccccccaaaaaacccccccccccccccccccaaacaaaccccaaaaaccccccccccccccccccciiiiqqqttwwwwwswwwwrrrroofffcccccc 28 | abcccccccccccccaaccccccccccccaaaacccccccaaaaaaaaccaaaaacccccccccccccaaaaaaacccccccccccccccccccaaaaaaacccaaacaacccccaaaaacccccccccciiiqqqttwwwwsssssrrrrroofffaccccc 29 | abcccccccccccccccccccccccccccaaaaccccccccacaaacccaaaaaaccccccaaccccaaaaaaccccccccaacaaccccccccaaaaaaccccaaaacacccccaaaaacccccccccciiiqqqtsswsssssssrrrrooofffaccccc 30 | abcccccccccccccccccccccccccccaaaaccccccccccaaaccaaaaaaaccccccaaaaccaacaaaccccccccaaaaacccccccccaaaaaaaaccaaacacccccaaaaaacccccccccciiqqqssssssspposrrroooofffaccccc 31 | abccccaaacccccccccccccccccccccaaacccccccccccccccaaacaaaccccaaaaaacccccaaaccccccccaaaaaacccccccaaaaaaaaaaaaaaaaaccccaaaaaaccccccaccciiiqqpsssssppppooooooogffaaccccc 32 | abccccaaaaaacccaaaccccccccccccccccccccccccccccccccccccaccccaaaaacccccccccccccccccaaaaaaccccccaaaaaaaaaaaaaaaaaaccccaaaaaacccaaaaccciiiqqppppppppppoooooogggfaaacccc 33 | abcccaaaaaaacccaaaccccccccccccccccccccccccccccccccccccccccccaaaaaccccccccccccccccaaaaaaccccccaaacaaaccccaaaaaacccccccaacccccaaaaaacciiipppppppphgggggggggggaaaacccc 34 | abccaaaaaaaacccaaacaaacccccccccccccccccccccaacccccccccccccccaacaacccccaacccccccccccaaacccccccccccaaacccccaaaaacccccccccccccccaaaaacciiihppppphhhhgggggggggaaccccccc 35 | abccaaaaaaacaaaaaaaaaacccccccccccccccccccccaaaccccccacccccccccccccccccaaccccccccccccccccccccccccaaaaccccaaaaaaccccccccccccccaaaaacccciihhhhhhhhhhgggggggccaaccccccc 36 | abccccaaaaaaaaaaaaaaacccccccccccccccccccaaaaaaaaccccaaacaaaccccccccccaaaaccaaccccccccaacaacccccaaaaaaacccaacccccccccccccccccaacaaccccchhhhhhhhhaaaacccccccccccccccc 37 | abccccaaaaaacaaaaaaaccccccccccccccccccccaaaaaaaaccccaaaaaaaccccccccccaaaaaaaacaccccccaaaaaccccccaaaaacccccccccccccccccccccccccccccccccchhhhhhacaaaaaccccccccccccccc 38 | abccccaaccccccaaaaaacccccccccccccaaccccccaaaaaacccccaaaaaaccccccaaaaaaaaaaaaaaaccccccaaaaaacccaaaaaaacccccccccccccccccccccccccccccccccccccaaaaccaaacccccccccccaaaca 39 | abccccccccccccaaaaaaaccccccccccccaaccccccaaaaaacccaaaaaaaaccccccaaaaaaaaaaaaaacccccccaaaaaacccaaaaaaaaccccccaaacccccccccccccccccccccccccccaaaaccccccccccccccccaaaaa 40 | abccaaacccccccaaacaaacccccccccaaaaaaaacccaaaaaacccaaaaaaaaacccccaaaaaaaaaaaaaacccccccaaaaaccccaaaaaaaaccccccaaaaccccccccccccccccccccccccccaaaccccccccccccccccccaaaa 41 | abcaaaacccccccaaccccccccccccccaaaaaaaacccaaccaacccaaaaaaaaaaccccccccaaaaaaacaacccccccccaaaccccccaaacaaccccccaaaacccccccccccccccccccccccccccccccccccccccccccccaaaaaa 42 | -------------------------------------------------------------------------------- /day_07/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashSet; 2 | use std::fs; 3 | 4 | #[derive(Debug)] 5 | struct File { 6 | filename: String, 7 | length: usize, 8 | } 9 | 10 | #[derive(Debug)] 11 | struct Directory { 12 | name: String, 13 | // List of references to directories 14 | directories: Vec, 15 | // List of references to files 16 | files: Vec, 17 | } 18 | 19 | fn main() { 20 | let file_contents = fs::read_to_string("input.txt").unwrap(); 21 | 22 | let mut directories = vec![Directory { 23 | name: String::from(""), 24 | directories: Vec::new(), 25 | files: Vec::new(), 26 | }]; 27 | let mut files: Vec = Vec::new(); 28 | 29 | let mut current_directory_idx: usize = 0; 30 | 31 | println!( 32 | "Current directory index: {}, current directory: {:?}", 33 | current_directory_idx, directories[current_directory_idx] 34 | ); 35 | 36 | for line in file_contents.lines() { 37 | match line { 38 | // $ cd X 39 | line if line.starts_with("$ cd") => { 40 | let path = line.split(" ").nth(2).unwrap(); 41 | println!("change directory: '{}'", path); 42 | if path == "/" { 43 | current_directory_idx = 0; 44 | } else if path == ".." { 45 | // Find directory for which current_directory_idx is in its directories 46 | for (i, directory) in directories.iter().enumerate() { 47 | if directory.directories.contains(¤t_directory_idx) { 48 | current_directory_idx = i; 49 | break; 50 | } 51 | } 52 | println!( 53 | "cd .. got us to '{}'", 54 | directories[current_directory_idx].name 55 | ); 56 | } else { 57 | // Cd to this directory 58 | let mut found = false; 59 | for dir_idx in &directories[current_directory_idx].directories { 60 | if directories[*dir_idx].name == path { 61 | current_directory_idx = *dir_idx; 62 | found = true; 63 | break; 64 | } 65 | } 66 | if !found { 67 | // Create the directory 68 | let new_dir = Directory { 69 | name: String::from(path), 70 | directories: Vec::new(), 71 | files: Vec::new(), 72 | }; 73 | directories.push(new_dir); 74 | let new_dir_idx = directories.len() - 1; 75 | directories[current_directory_idx] 76 | .directories 77 | .push(new_dir_idx); 78 | current_directory_idx = new_dir_idx; 79 | } 80 | } 81 | } 82 | // Ignore ls 83 | line if line.starts_with("$ ls") => { 84 | println!("ls"); 85 | } 86 | // integer_file_size filename 87 | line if line.split(" ").nth(0).unwrap().parse::().is_ok() => { 88 | let file_size = line.split(" ").nth(0).unwrap().parse::().unwrap(); 89 | let filename = line.split(" ").nth(1).unwrap(); 90 | println!("file: '{}', size: {}", filename, file_size); 91 | let new_file = File { 92 | filename: String::from(filename), 93 | length: file_size, 94 | }; 95 | files.push(new_file); 96 | directories[current_directory_idx] 97 | .files 98 | .push(files.len() - 1); 99 | } 100 | line => { 101 | println!("line: {}", line); 102 | let bits = line.split(" ").collect::>(); 103 | println!(" . bits: {:?}", bits); 104 | } 105 | } 106 | } 107 | // Debug print files 108 | println!("Files:"); 109 | for file in &files { 110 | println!(" . {:?}", file); 111 | } 112 | // Debug print directories 113 | println!("Directories:"); 114 | for directory in &directories { 115 | println!(" . {:?}", directory); 116 | } 117 | 118 | // Determine the total size of each directory, including nested files 119 | let mut total_sizes = vec![0; directories.len()]; 120 | 121 | // Looping through directories backwards should accumulate the total size of each directory 122 | for (i, directory) in directories.iter().enumerate().rev() { 123 | for file_idx in &directory.files { 124 | total_sizes[i] += files[*file_idx].length; 125 | } 126 | for dir_idx in &directory.directories { 127 | total_sizes[i] += total_sizes[*dir_idx]; 128 | } 129 | } 130 | println!("Total sizes: {:?}", total_sizes); 131 | // Find all of the directories with a total size of at most 100000. 132 | let mut small_directories = Vec::new(); 133 | for (i, size) in total_sizes.iter().enumerate() { 134 | if *size <= 100000 { 135 | small_directories.push(i); 136 | } 137 | } 138 | // What is the sum of the total sizes of those directories? 139 | let mut total_size_small_directories = 0; 140 | for dir_idx in &small_directories { 141 | total_size_small_directories += total_sizes[*dir_idx]; 142 | } 143 | println!( 144 | "Total size of small directories: {}", 145 | total_size_small_directories 146 | ); 147 | println!(""); 148 | println!("Part 2"); 149 | println!("======"); 150 | println!(""); 151 | 152 | let total_size_of_everything = total_size_for_directory_idx(0, &directories, &files); 153 | 154 | println!("Total size of everything: {}", total_size_of_everything); 155 | 156 | // Build list of tuples of (directory_idx, directory_name, total_size) 157 | let mut directory_sizes = Vec::new(); 158 | for (idx, directory) in directories.iter().enumerate() { 159 | directory_sizes.push(( 160 | idx, 161 | directory.name.clone(), 162 | total_size_for_directory_idx(idx, &directories, &files), 163 | )); 164 | } 165 | println!("Directory sizes: {:?}", directory_sizes); 166 | 167 | // Need 30000000 free to run update, which directories could we delete to get that? 168 | let space_needed = 70000000 - 30000000; 169 | let space_needed_to_free = total_size_of_everything - space_needed; 170 | println!("Space needed to free: {}", space_needed_to_free); 171 | 172 | let candidates = directory_sizes 173 | .iter() 174 | .filter(|(_, _, size)| *size >= space_needed_to_free) 175 | .collect::>(); 176 | 177 | println!("Candidates: {:?}", candidates); 178 | 179 | // Sort candidates by third value in tuple 180 | let mut candidates = candidates; 181 | candidates.sort_by(|(_, _, size1), (_, _, size2)| size1.cmp(size2)); 182 | println!("Sorted candidates: {:?}", candidates); 183 | 184 | if candidates.len() > 0 { 185 | println!("So the directory to delete is: {:?}", candidates[0]); 186 | } else { 187 | println!("No candidates found"); 188 | } 189 | } 190 | 191 | fn find_all_directory_children( 192 | directory_idx: usize, 193 | directories: &Vec, 194 | ) -> HashSet { 195 | let mut directory_idxs = HashSet::new(); 196 | directory_idxs.insert(directory_idx); 197 | // Children of this idx 198 | for dir_idx in &directories[directory_idx].directories { 199 | directory_idxs.insert(*dir_idx); 200 | for recursive_idx in find_all_directory_children(*dir_idx, directories) { 201 | directory_idxs.insert(recursive_idx); 202 | } 203 | } 204 | directory_idxs 205 | } 206 | 207 | fn total_size_for_directory_idx( 208 | directory_idx: usize, 209 | directories: &Vec, 210 | files: &Vec, 211 | ) -> usize { 212 | let mut total_size = 0; 213 | let directory_children = find_all_directory_children(directory_idx, &directories); 214 | for directory_idx in directory_children { 215 | for file_idx in &directories[directory_idx].files { 216 | total_size += files[*file_idx].length; 217 | } 218 | } 219 | total_size 220 | } 221 | -------------------------------------------------------------------------------- /day_13/src/main.rs: -------------------------------------------------------------------------------- 1 | use parameterized::parameterized; 2 | use std::cmp::{Ord, Ordering, PartialOrd}; 3 | use std::fs; 4 | 5 | #[derive(Debug, Clone, PartialEq, Eq)] 6 | enum NestedInteger { 7 | Value(i32), 8 | Children(Vec), 9 | } 10 | 11 | impl Ord for NestedInteger { 12 | fn cmp(&self, other: &Self) -> Ordering { 13 | println!("Comparing {:?} and {:?}", self, other); 14 | match (self, other) { 15 | (NestedInteger::Value(a), NestedInteger::Value(b)) => a.cmp(b), 16 | // If one side is a value and the other a list, compare to [value] - in both directions: 17 | (NestedInteger::Value(_), _) => NestedInteger::Children(vec![self.clone()]).cmp(other), 18 | (_, NestedInteger::Value(_)) => self.cmp(&NestedInteger::Children(vec![other.clone()])), 19 | // If both sides are lists, compare them one element at a time 20 | (NestedInteger::Children(a), NestedInteger::Children(b)) => { 21 | let mut a = a.iter(); 22 | let mut b = b.iter(); 23 | loop { 24 | println!(" a: {:?}, b: {:?}", a, b); 25 | match (a.next(), b.next()) { 26 | (Some(a), Some(b)) => match a.cmp(b) { 27 | Ordering::Equal => continue, 28 | other => return other, 29 | }, 30 | // If the right list runs out of items first, the inputs are not in the right order 31 | (Some(_), None) => return Ordering::Greater, 32 | (None, Some(_)) => return Ordering::Less, 33 | (None, None) => return Ordering::Equal, 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | 41 | impl PartialOrd for NestedInteger { 42 | fn partial_cmp(&self, other: &Self) -> Option { 43 | Some(self.cmp(other)) 44 | } 45 | } 46 | 47 | fn main() { 48 | let file_contents = fs::read_to_string("input.txt").unwrap(); 49 | for line in file_contents.lines() { 50 | let parsed = parse_line(line); 51 | println!("{:?}", line); 52 | println!("{:#?}", parsed); 53 | } 54 | // Determine which pairs of packets are already in the right order. 55 | // What is the sum of the indices of those pairs? 56 | // First, do pairs 57 | let mut left = None; 58 | let mut right; 59 | let mut indexes = Vec::new(); 60 | let mut index = 1; // Indexes are 1-based 61 | for line in file_contents.lines() { 62 | // Skip blank lines 63 | if line.is_empty() { 64 | continue; 65 | } 66 | let parsed = parse_line(line); 67 | if left.is_none() { 68 | left = Some(parsed); 69 | continue; 70 | } else { 71 | right = Some(parsed); 72 | // Is this pair in the right order? 73 | if left.unwrap() < right.unwrap() { 74 | indexes.push(index); 75 | } 76 | left = None; 77 | index += 1; 78 | } 79 | } 80 | println!("Indexes: {:?}", indexes); 81 | println!("Sum: {}", indexes.iter().sum::()); 82 | println!("Last index: {}", index); 83 | 84 | println!("\nPart 2\n======\n"); 85 | 86 | // Load all the packets into a Vec 87 | let mut packets = Vec::new(); 88 | for line in file_contents.lines() { 89 | // Skip blank lines 90 | if line.is_empty() { 91 | continue; 92 | } 93 | let parsed = parse_line(line); 94 | packets.push(parsed); 95 | } 96 | // Add the two divider packets 97 | let divider1 = parse_line("[[2]]"); 98 | packets.push(divider1); 99 | let divider2 = parse_line("[[6]]"); 100 | packets.push(divider2); 101 | 102 | // Sort the packets 103 | packets.sort(); 104 | println!("Packets: {:?}", packets); 105 | 106 | // Find index of divider1 and divider2 107 | let divider1_index = packets 108 | .iter() 109 | .position(|x| x == &parse_line("[[2]]")) 110 | .unwrap() 111 | + 1; 112 | let divider2_index = packets 113 | .iter() 114 | .position(|x| x == &parse_line("[[6]]")) 115 | .unwrap() 116 | + 1; 117 | println!("Divider 1 index: {}", divider1_index); 118 | println!("Divider 2 index: {}", divider2_index); 119 | println!("Multpiled: {}", divider1_index * divider2_index); 120 | } 121 | 122 | fn parse_line(line: &str) -> NestedInteger { 123 | // line is a JSON array e.g. [[1, 2], [3, 14]] - parse it 124 | let mut chars = line.chars(); 125 | let mut current = NestedInteger::Children(Vec::new()); 126 | let mut stack = Vec::new(); 127 | let mut current_integer = 0; 128 | let mut in_integer = false; 129 | let mut has_found_first = false; 130 | while let Some(c) = chars.next() { 131 | match c { 132 | '[' => { 133 | // Start of a new list 134 | if has_found_first { 135 | stack.push(current); 136 | } 137 | has_found_first = true; 138 | current = NestedInteger::Children(Vec::new()); 139 | current_integer = 0; 140 | in_integer = false; 141 | } 142 | ']' => { 143 | // End of a list 144 | if in_integer { 145 | // Push onto Children list in current 146 | match &mut current { 147 | NestedInteger::Children(children) => { 148 | children.push(NestedInteger::Value(current_integer)); 149 | } 150 | _ => panic!("Unexpected type"), 151 | } 152 | } 153 | if let Some(mut parent) = stack.pop() { 154 | match &mut parent { 155 | NestedInteger::Children(children) => { 156 | children.push(current.clone()); 157 | } 158 | _ => panic!("Unexpected type"), 159 | } 160 | current = parent; 161 | } 162 | current_integer = 0; 163 | in_integer = false; 164 | } 165 | ',' => { 166 | // End of an integer 167 | if in_integer { 168 | match &mut current { 169 | NestedInteger::Children(children) => { 170 | children.push(NestedInteger::Value(current_integer)); 171 | } 172 | _ => panic!("Unexpected type"), 173 | } 174 | current_integer = 0; 175 | in_integer = false; 176 | } 177 | } 178 | '0'..='9' => { 179 | // A digit 180 | current_integer = current_integer * 10 + (c as i32 - '0' as i32); 181 | in_integer = true; 182 | } 183 | _ => {} 184 | } 185 | } 186 | current 187 | } 188 | 189 | #[test] 190 | fn test_parse_line() { 191 | let line = "[[1, 2], [3, 14]]"; 192 | let parsed = parse_line(line); 193 | assert_eq!( 194 | parsed, 195 | NestedInteger::Children(vec![ 196 | NestedInteger::Children(vec![NestedInteger::Value(1), NestedInteger::Value(2)]), 197 | NestedInteger::Children(vec![NestedInteger::Value(3), NestedInteger::Value(14)]) 198 | ]) 199 | ); 200 | } 201 | 202 | #[test] 203 | fn test_two_lines_equal() { 204 | let line = "[[1, 2], [3, 14]]"; 205 | let parsed = parse_line(line); 206 | let parsed2 = parse_line(line); 207 | assert_eq!(parsed, parsed2); 208 | } 209 | 210 | #[parameterized( 211 | left = {"[1,1,3,1,1]", "[[1],[2,3,4]]", "[[8,7,6]]", "[[4,4],4,4]", "[7,7,7]", "[]", "[[]]", "[1,[2,[3,[4,[5,6,0]]]],8,9]", "[[0,7,7,[1,[3,8,10,8],[3],[2,2]],10],[[0,5,[1,2],[0],[5,7,5]],1,4,[2]],[]]", "[[0]]"}, 212 | right = {"[1,1,5,1,1]", "[[1],4]", "[9]", "[[4,4],4,4,4]", "[7,7,7,7]", "[3]", "[[[]]]", "[1,[2,[3,[4,[5,6,7]]]],8,9]", "[[[2,[]]],[],[9,1]]", "[[[2]]]"} 213 | )] 214 | fn test_order_comparison(left: &str, right: &str) { 215 | // For each example, the one on the left should be < the one on the right 216 | let parsed_left = parse_line(left); 217 | let parsed_right = parse_line(right); 218 | println!("Left: {:?}", parsed_left); 219 | println!("Right: {:?}", parsed_right); 220 | 221 | assert_eq!( 222 | parsed_left < parsed_right, 223 | true, 224 | "{} should be < {}", 225 | left, 226 | right 227 | ); 228 | } 229 | -------------------------------------------------------------------------------- /day_08/input.txt: -------------------------------------------------------------------------------- 1 | 131102031022411233124153000402524132243245422402002121234345453535321113450535302430144220243210033 2 | 210030011133442111442145434004231353202400601331445042106230540242340014332243105022302133441101011 3 | 201302044230110302341330012044051130055046354663404014033243655520410125432425532024143403330032232 4 | 210303103204034020151134514120046162664361356330261302226530654326452225134535222440444443410101130 5 | 021310332113230035544033314213544254421233042151226601345516101654005025035545035333140023212102212 6 | 220140301231432453044535532323066560244052510442522465306425021511260132313424322110345422300411332 7 | 103013240142011245425311001542145655516105003352455141424412415222100145355043202120423034202120403 8 | 314103304322445325255534650156565303510461206034672755654106425161056213552330050310445352323213402 9 | 243430113305332145305400366156126611120357766767667531265661631510215134106224240155532142014202020 10 | 344044011305120500223111213354316112154646744635155132374774442641061323024416155344101304242413014 11 | 210001340311202411013214565026366577746364242672331436164352252445110000414212215202321411504422400 12 | 001030344254033552521244445311464542617442572153467545366653342426676363026234406640015310103000111 13 | 123004351234415456501532136126535464236513321263256111263236363424471316560661104630322511135024314 14 | 243444301010130503501065440067414335615573435151661324666436573133444251763541254166141130405531401 15 | 301333054435342646553265615125271561444757162666247563564724434377461174733226461663122454115301022 16 | 313333115034033032461152521554721624436564356545874583322623147632365263427634464233444421123452114 17 | 434441324240044110131332722354256132333522657745624745724323263635746316535120231124164652542245541 18 | 020013043025261604606066777717675561448878622688884553346728286853164272251311263510330645452212040 19 | 225405401530036646635664123763243188844858643328244728344354343287813231363771264361344552214134043 20 | 444013205241103641532477643143435563484567276423226466226434857664377176552653732212146514023430325 21 | 235444033555452351644577725572733823223422438445886848336238372267477767173715122521014452405344110 22 | 022222500504231055646646534633724257646568684735488756288737857786232268232655151633323530463425151 23 | 412102254551210100735562467375656382325864659764674335534465738553284326347575542675435335613154320 24 | 202304233522424114651647265763556544532358373769578879369385574555386666783363244334360301665155255 25 | 400235422666401262236327746826382638573848989589958764697958946664233887757677777164614616200413302 26 | 413211350405512664175712772346875822558798479568486643787487763573785465875336133314155235265153544 27 | 412112650043523364626154522655787734369585968849884958638795656846722736645822544573361050432101002 28 | 040151232015244534675233447267274466883354564933934639355395374945757347634723116764261154205631025 29 | 053511566106055552733487866435428673379594867554589579573759867856436754328455243315565403452366550 30 | 402441261342655261311663778728277373873487457867467678497684746937764462833722831553364205512206541 31 | 401560462601374333165687778774966694644847875679669694796453568554383377242683474675113640166014002 32 | 245431640441276372256235534578677594558499466595957658548574676357557473852362834636123725105611001 33 | 140325466637452621767678632447835458776865576466546548894776445753494487385328422645157221103664133 34 | 253440020224216474125727543697395446885846849486744757588954688447585337348374328857266123303626032 35 | 522360463154354425644334277863647479565896696996775849896649575745746557964548536537415577142552050 36 | 402351634474624167474857559553949899894799879644496759587555549787974996993634823833353424316316042 37 | 414140006077774645384224689955449865767867876647679668857949995687773539976755288762714471242526254 38 | 032242255462211412258653836566746764685477947565799869886769647489953985859547537844111624535631156 39 | 241646435225236526565228495485878686676559956669957869665758947786478934645637286347261114426145563 40 | 512215356337536722737525437473645894558456658976958699776986594778559569864962457825216143344215016 41 | 322625244746336257345525895486859454957989669585766859958667775649875866654855238722721513671212305 42 | 044600535247217686848675385837958687859856856865869679556868995579875763985654342678317263541605554 43 | 430320424173321746345287493633447589689698796959599858768985856685945573454358785585284454656334025 44 | 232026013361136674773333583555589876467998965697988698997966777468454666855894285223681327425505166 45 | 354332536226232536453676489538955896788985786767799998876886965757444485955456462568453444425456521 46 | 016154147271566788586769489946847647867857556667888797775895768988576579978395627453672756147414326 47 | 463454162462563733454784956555887864475857986666689767978699985965647598648778424456255355723655466 48 | 021001072567511684363734454496747746785559778677966778897776558954997794766634668356686124441524525 49 | 234605435156344755776859794859864756797769876888968689787579998559856654953446748662382433262116262 50 | 030666223611312438477278595797684446757958596668696976678757986797965899875556377876865147373650335 51 | 245046541536764737224694794369857786796969878968689968797958865856864988656773724353268427134461620 52 | 265066622261247542566375373496969757789659688887789988798956868878668565665794723743572475263161166 53 | 422245453144736877586299945587888888767997586686876996879786788998867747683776448657845662361505315 54 | 210351625547722865278485967857788659769765586689699988976775596895984657648869967252632246417436621 55 | 141004614422116428487735355858968995455599988699767679796595755979678769336598642342483777532511004 56 | 533362561377622426377686383498446767487997987976886899988585956569875694463399574483265564264622314 57 | 456163507723454276868637866355647859456998677889778989889969998954684957667483346372863274465245646 58 | 030644251421316636263479555487765499846688669798677798668968599994746869757876565775844144255106462 59 | 510135336311735337436764935399965949469956999767696876898578576969547984463869253278467243311543030 60 | 466524526117724766584368696865578944888566858759789698699778689456856774865884337672615767136523254 61 | 254110631463762333865539645936466585858655857657659586556989585456479575455563845762632676471423233 62 | 562434653773762262468663566995359545869887797866957588766855659579865834576343438465353323754454240 63 | 112066240641477224475587449447989749648974898785555767886979489566644938356955638286634724441631625 64 | 330443313353347713822865768695549469777556759786896565758769775757475566378642426537546311412140051 65 | 040065350247621726448577745444446666557767548565886798996759654466566755698345662584625446342463260 66 | 330536625076531353825376746548345995946649894668956867559446757474398638639624464682343654214032311 67 | 530251120326432762683357643388548466489576697998869899549584977659746869733837538723573545213461105 68 | 255356015316555756432734833639785737748988987965669458947565666746847669548847254811135737404226043 69 | 454354550123557227257454326863468487794448666674495859497588676766356646553276336612337324063553462 70 | 144340525160235512164242786385886753536996894579865659848488534457479379684556654637432614663443613 71 | 305316054035171372138527636345993984687638579458566486795488343446895753373444445772513544116215313 72 | 543055400456632262131666826787874497775946535566897457748984377394483964377555447341647525602315351 73 | 412546632444321676125286364645444448636496473746537653585847369856994564666782226566264742530022340 74 | 044233444612165527122563533685825959374668734768758953663536843946435452847223172365277563546141540 75 | 340030454102343151253211647666557354334348799955649644348678747758347287426221514313112316663165454 76 | 011020051334501654522762446268866586389746656669789443696677886848328248582411315534364123146250501 77 | 305413453334030464614216442476475733478966457359966737766476988846463467574624373625606065562242335 78 | 034215112203016427473135421577622448726677469646375339565639944867546662453345521671403262325021214 79 | 132210543140531252452317342463454885388566728556533533877354846446665578244115675240031664244524501 80 | 201140051634662646614612354714626525722377445426842485568735384726362363654642742661135663265002510 81 | 025011353243541235316415314133578633558245363633567643474723462264656821637416273202656565602515322 82 | 121540314222665224011553176734444466578255884322834667368468238484254776573264467333645106223352155 83 | 233134314541654641520531771126551528746557387438726348653238283875537147555615754035502132555444301 84 | 424510000505066600303343337525732714723283556468834467558232644677477536766533666404266150255104242 85 | 041433452552331436330125237255465337374884372735358382327855756643676341445255435062065033314033212 86 | 141025211241314363206626056633223121353133645783244374622462256271457773212200625560321421020100213 87 | 224101010422251643133220616233621223532466525114754865347141165612135423157400060111225313054434032 88 | 004040052225144131342364656025377722754756627621767354111575442445436452322335541156250421012350243 89 | 043322120521041516241540153402233524371432721521521276133447761312616332565246332656140342120501432 90 | 200232013354533102134562014146621725413251577715376671261144475237357064044430050234040121014304202 91 | 011420212054031401033241133121106532344212712314572323662643147467661343340045361122545415103011124 92 | 102223410325432324313243446514164004156475643254444557477323147134144354265066260422110450012141414 93 | 031411112311321035125554420606413626050373327654774373667767140605036115333551650220414205214132024 94 | 210204032200320524351051665115025502044361230251377575706601164652440120455165201034431244211004301 95 | 331131223444034015143142430503454436431142412165246111316106164251614223504203533022310134023423343 96 | 120300034332102045152234220042512653414152606411234665213124345325420542210314454221024423343223220 97 | 200230420442302210441134513143532363040132120013505235035543064245636124512505054404233133430423011 98 | 000202411243122420140310501035333204626352325031215630345206242502134153000033354044334042221310101 99 | 111301302244231442013332415144033330063530643146335532313306033656410450441505505240142210004121122 -------------------------------------------------------------------------------- /day_06/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "bitflags" 7 | version = "1.3.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 10 | 11 | [[package]] 12 | name = "cc" 13 | version = "1.0.77" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" 16 | 17 | [[package]] 18 | name = "clap" 19 | version = "4.0.29" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" 22 | dependencies = [ 23 | "bitflags", 24 | "clap_derive", 25 | "clap_lex", 26 | "is-terminal", 27 | "once_cell", 28 | "strsim", 29 | "termcolor", 30 | ] 31 | 32 | [[package]] 33 | name = "clap_derive" 34 | version = "4.0.21" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" 37 | dependencies = [ 38 | "heck", 39 | "proc-macro-error", 40 | "proc-macro2", 41 | "quote", 42 | "syn", 43 | ] 44 | 45 | [[package]] 46 | name = "clap_lex" 47 | version = "0.3.0" 48 | source = "registry+https://github.com/rust-lang/crates.io-index" 49 | checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" 50 | dependencies = [ 51 | "os_str_bytes", 52 | ] 53 | 54 | [[package]] 55 | name = "day_06" 56 | version = "0.1.0" 57 | dependencies = [ 58 | "clap", 59 | ] 60 | 61 | [[package]] 62 | name = "errno" 63 | version = "0.2.8" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" 66 | dependencies = [ 67 | "errno-dragonfly", 68 | "libc", 69 | "winapi", 70 | ] 71 | 72 | [[package]] 73 | name = "errno-dragonfly" 74 | version = "0.1.2" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 77 | dependencies = [ 78 | "cc", 79 | "libc", 80 | ] 81 | 82 | [[package]] 83 | name = "heck" 84 | version = "0.4.0" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 87 | 88 | [[package]] 89 | name = "hermit-abi" 90 | version = "0.2.6" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" 93 | dependencies = [ 94 | "libc", 95 | ] 96 | 97 | [[package]] 98 | name = "io-lifetimes" 99 | version = "1.0.3" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" 102 | dependencies = [ 103 | "libc", 104 | "windows-sys", 105 | ] 106 | 107 | [[package]] 108 | name = "is-terminal" 109 | version = "0.4.1" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" 112 | dependencies = [ 113 | "hermit-abi", 114 | "io-lifetimes", 115 | "rustix", 116 | "windows-sys", 117 | ] 118 | 119 | [[package]] 120 | name = "libc" 121 | version = "0.2.138" 122 | source = "registry+https://github.com/rust-lang/crates.io-index" 123 | checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" 124 | 125 | [[package]] 126 | name = "linux-raw-sys" 127 | version = "0.1.3" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" 130 | 131 | [[package]] 132 | name = "once_cell" 133 | version = "1.16.0" 134 | source = "registry+https://github.com/rust-lang/crates.io-index" 135 | checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" 136 | 137 | [[package]] 138 | name = "os_str_bytes" 139 | version = "6.4.1" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" 142 | 143 | [[package]] 144 | name = "proc-macro-error" 145 | version = "1.0.4" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 148 | dependencies = [ 149 | "proc-macro-error-attr", 150 | "proc-macro2", 151 | "quote", 152 | "syn", 153 | "version_check", 154 | ] 155 | 156 | [[package]] 157 | name = "proc-macro-error-attr" 158 | version = "1.0.4" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 161 | dependencies = [ 162 | "proc-macro2", 163 | "quote", 164 | "version_check", 165 | ] 166 | 167 | [[package]] 168 | name = "proc-macro2" 169 | version = "1.0.47" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 172 | dependencies = [ 173 | "unicode-ident", 174 | ] 175 | 176 | [[package]] 177 | name = "quote" 178 | version = "1.0.21" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 181 | dependencies = [ 182 | "proc-macro2", 183 | ] 184 | 185 | [[package]] 186 | name = "rustix" 187 | version = "0.36.5" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" 190 | dependencies = [ 191 | "bitflags", 192 | "errno", 193 | "io-lifetimes", 194 | "libc", 195 | "linux-raw-sys", 196 | "windows-sys", 197 | ] 198 | 199 | [[package]] 200 | name = "strsim" 201 | version = "0.10.0" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 204 | 205 | [[package]] 206 | name = "syn" 207 | version = "1.0.105" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" 210 | dependencies = [ 211 | "proc-macro2", 212 | "quote", 213 | "unicode-ident", 214 | ] 215 | 216 | [[package]] 217 | name = "termcolor" 218 | version = "1.1.3" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 221 | dependencies = [ 222 | "winapi-util", 223 | ] 224 | 225 | [[package]] 226 | name = "unicode-ident" 227 | version = "1.0.5" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 230 | 231 | [[package]] 232 | name = "version_check" 233 | version = "0.9.4" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 236 | 237 | [[package]] 238 | name = "winapi" 239 | version = "0.3.9" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 242 | dependencies = [ 243 | "winapi-i686-pc-windows-gnu", 244 | "winapi-x86_64-pc-windows-gnu", 245 | ] 246 | 247 | [[package]] 248 | name = "winapi-i686-pc-windows-gnu" 249 | version = "0.4.0" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 252 | 253 | [[package]] 254 | name = "winapi-util" 255 | version = "0.1.5" 256 | source = "registry+https://github.com/rust-lang/crates.io-index" 257 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 258 | dependencies = [ 259 | "winapi", 260 | ] 261 | 262 | [[package]] 263 | name = "winapi-x86_64-pc-windows-gnu" 264 | version = "0.4.0" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 267 | 268 | [[package]] 269 | name = "windows-sys" 270 | version = "0.42.0" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 273 | dependencies = [ 274 | "windows_aarch64_gnullvm", 275 | "windows_aarch64_msvc", 276 | "windows_i686_gnu", 277 | "windows_i686_msvc", 278 | "windows_x86_64_gnu", 279 | "windows_x86_64_gnullvm", 280 | "windows_x86_64_msvc", 281 | ] 282 | 283 | [[package]] 284 | name = "windows_aarch64_gnullvm" 285 | version = "0.42.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 288 | 289 | [[package]] 290 | name = "windows_aarch64_msvc" 291 | version = "0.42.0" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 294 | 295 | [[package]] 296 | name = "windows_i686_gnu" 297 | version = "0.42.0" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 300 | 301 | [[package]] 302 | name = "windows_i686_msvc" 303 | version = "0.42.0" 304 | source = "registry+https://github.com/rust-lang/crates.io-index" 305 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 306 | 307 | [[package]] 308 | name = "windows_x86_64_gnu" 309 | version = "0.42.0" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 312 | 313 | [[package]] 314 | name = "windows_x86_64_gnullvm" 315 | version = "0.42.0" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 318 | 319 | [[package]] 320 | name = "windows_x86_64_msvc" 321 | version = "0.42.0" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 324 | -------------------------------------------------------------------------------- /day_14/src/main.rs: -------------------------------------------------------------------------------- 1 | // Coordinate system: 0,0 is top left, x increases to the right, y increases down 2 | 3 | use std::fmt; 4 | 5 | struct Grid { 6 | width: usize, 7 | height: usize, 8 | min_x: i32, 9 | max_x: i32, 10 | min_y: i32, 11 | max_y: i32, 12 | lines: Vec>, 13 | has_floor: bool, 14 | } 15 | 16 | impl fmt::Display for Grid { 17 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 18 | let mut s = String::new(); 19 | for line in &self.lines { 20 | for c in line { 21 | s.push(*c); 22 | } 23 | s.push('\n'); 24 | } 25 | write!(f, "{}", s) 26 | } 27 | } 28 | 29 | impl Grid { 30 | fn char_at(&self, coord: (i32, i32)) -> char { 31 | if self.has_floor { 32 | // an infinite horizontal line with a y coordinate equal to two 33 | // plus the highest y coordinate of any point in your scan 34 | // println!("Checking floor at: {:?}", coord); 35 | println!( 36 | "coord: {:?}, coord.0: {}, coord.1: {}, self.max_y + 2: {}", 37 | coord, 38 | coord.0, 39 | coord.1, 40 | self.max_y + 2 41 | ); 42 | if coord.1 >= self.max_y + 2 { 43 | // println!("Hit floor at {:?}", coord); 44 | return '#'; 45 | } 46 | } 47 | // Subtract min_x / min_y 48 | // println!("char_at: {} {}", coord.0, coord.1); 49 | let x = coord.0 - self.min_x; 50 | let y = coord.1 - self.min_y; 51 | let ch; 52 | // If out of bounds, return ' ' 53 | if !self.has_floor { 54 | if x < 0 || y < 0 || x >= self.width as i32 || y >= self.height as i32 { 55 | return ' '; 56 | } else { 57 | return self.lines[y as usize][x as usize]; 58 | } 59 | } else { 60 | // When there is a floor it can't go out of bounds 61 | println!("char_at: {} {}", x, y); 62 | ch = self.lines[y as usize][x as usize]; 63 | ch 64 | } 65 | } 66 | fn set_char_at(&mut self, coord: (i32, i32), ch: char) { 67 | // Add min_x / min_y 68 | // println!("Setting char {} at {:?}", ch, coord); 69 | let x = coord.0 - self.min_x; 70 | let y = coord.1 - self.min_y; 71 | // println!(" translated to: {} {}", x, y); 72 | self.lines[y as usize][x as usize] = ch; 73 | } 74 | fn simulate_sand(&mut self) -> bool { 75 | // Returns true if sand was placed, false if it fell into void 76 | // Sand is added at 500,0 77 | let mut sand_pos = (500, 0); 78 | loop { 79 | // Inspect all three spaces below the sand 80 | let below = (sand_pos.0, sand_pos.1 + 1); 81 | let below_left = (sand_pos.0 - 1, sand_pos.1 + 1); 82 | let below_right = (sand_pos.0 + 1, sand_pos.1 + 1); 83 | if self.char_at(below) == '.' || self.char_at(below) == ' ' { 84 | sand_pos = below; 85 | if self.char_at(sand_pos) == ' ' { 86 | println!("Sand fell into void at {:?}", sand_pos); 87 | return false; 88 | } 89 | if sand_pos == (500, 0) { 90 | println!("Sand got to source"); 91 | return false; 92 | } 93 | continue; 94 | } else if self.char_at(below_left) == '.' || self.char_at(below_left) == ' ' { 95 | sand_pos = below_left; 96 | if self.char_at(sand_pos) == ' ' { 97 | return false; 98 | } 99 | if sand_pos == (500, 0) { 100 | println!("Sand got to source"); 101 | return false; 102 | } 103 | continue; 104 | } else if self.char_at(below_right) == '.' || self.char_at(below_right) == ' ' { 105 | sand_pos = below_right; 106 | if self.char_at(sand_pos) == ' ' { 107 | return false; 108 | } 109 | if sand_pos == (500, 0) { 110 | println!("Sand got to source"); 111 | return false; 112 | } 113 | continue; 114 | } else { 115 | // Sand lives here now 116 | self.set_char_at(sand_pos, 'o'); 117 | break; 118 | } 119 | } 120 | true 121 | } 122 | } 123 | 124 | fn main() { 125 | let instructions = String::from(include_str!("../input.txt")); 126 | let mut grid = parse_grid(instructions, false); 127 | println!("{}", grid); 128 | // Simulate sand until it falls into the void 129 | let mut i = 0; 130 | while grid.simulate_sand() { 131 | i += 1; 132 | println!("After {} iterations:", i); 133 | println!("{}\n\n", grid); 134 | } 135 | println!("Final i: {}", i); 136 | 137 | println!("\nPart 2\n======\n"); 138 | 139 | // Now run simulation again with a floor at two plus the highest y coordinate 140 | let mut j = 0; 141 | let instructions2 = String::from(include_str!("../input.txt")); 142 | let mut grid2 = parse_grid(instructions2, true); 143 | while grid2.simulate_sand() { 144 | j += 1; 145 | } 146 | // println!("{}\n\n", grid2); 147 | println!("Final j: {}", j); 148 | } 149 | 150 | fn parse_grid(input: String, has_floor: bool) -> Grid { 151 | // Each line describes a shape of rock drawn on the grid 152 | let mut min_x = 100000; 153 | let mut max_x = -100000; 154 | let mut min_y = 0; 155 | let mut max_y = -100000; 156 | if has_floor { 157 | max_x = 10000000; 158 | } 159 | let mut grid_lines = Vec::new(); 160 | // First loop to find min/max of everything: 161 | for line in input.lines() { 162 | // Line looks like this: 163 | // 498,4 -> 498,6 -> 496,6 164 | // First update min/max coordinates 165 | let mut coords = line.split(" -> "); 166 | while let Some(coord) = coords.next() { 167 | let mut coord = coord.split(","); 168 | let x = coord.next().unwrap().parse::().unwrap(); 169 | let y = coord.next().unwrap().parse::().unwrap(); 170 | if x < min_x { 171 | min_x = x; 172 | } 173 | if x > max_x { 174 | max_x = x; 175 | } 176 | if y < min_y { 177 | min_y = y; 178 | } 179 | if y > max_y { 180 | max_y = y; 181 | } 182 | } 183 | } 184 | // Prepare the grid 185 | let width = (max_x - min_x + 1) as usize; 186 | let height = (max_y - min_y + 1) as usize; 187 | for _ in 0..height { 188 | let mut line = Vec::new(); 189 | for _ in 0..width { 190 | line.push('.'); 191 | } 192 | grid_lines.push(line); 193 | } 194 | // Second loop to fill in the grid based on instructions 195 | for line in input.lines() { 196 | // 498,4 -> 498,6 -> 496,6 197 | let mut coords = line.split(" -> "); 198 | let mut done_first = false; 199 | let mut prev_coords = (0, 0); 200 | while let Some(coord) = coords.next() { 201 | // collect as (i32, i32) tuple: 202 | let mut bits = coord.split(","); 203 | let coord = ( 204 | bits.next().unwrap().parse::().unwrap(), 205 | bits.next().unwrap().parse::().unwrap(), 206 | ); 207 | if !done_first { 208 | done_first = true; 209 | prev_coords = coord; 210 | continue; 211 | } 212 | // println!("Drawing line from {:?} to {:?}", prev_coords, coord); 213 | 214 | if prev_coords.0 == coord.0 { 215 | // Vertical line 216 | let (y1, y2) = if prev_coords.1 < coord.1 { 217 | (prev_coords.1, coord.1) 218 | } else { 219 | (coord.1, prev_coords.1) 220 | }; 221 | // println!(" Vertical line from {} to {}", y1, y2); 222 | for y in y1..=y2 { 223 | grid_lines[(y - min_y) as usize][(prev_coords.0 - min_x) as usize] = '#'; 224 | } 225 | } else { 226 | // Horizontal line 227 | let (x1, x2) = if prev_coords.0 < coord.0 { 228 | (prev_coords.0, coord.0) 229 | } else { 230 | (coord.0, prev_coords.0) 231 | }; 232 | // println!(" Horizontal line from {} to {}", x1, x2); 233 | for x in x1..=x2 { 234 | grid_lines[(prev_coords.1 - min_y) as usize][(x - min_x) as usize] = '#'; 235 | } 236 | } 237 | /* 238 | println!("{}\n\n", Grid { 239 | width, 240 | height, 241 | min_x, 242 | max_x, 243 | min_y, 244 | max_y, 245 | lines: grid_lines.clone(), 246 | }); 247 | */ 248 | prev_coords = coord; 249 | } 250 | } 251 | Grid { 252 | width, 253 | height, 254 | min_x, 255 | max_x, 256 | min_y, 257 | max_y, 258 | lines: grid_lines, 259 | has_floor, 260 | } 261 | } 262 | 263 | // Write a test 264 | // Path: src/main.rs 265 | #[test] 266 | fn test_parse_grid() { 267 | let instructions = String::from("498,4 -> 498,6 -> 496,6\n503,4 -> 502,4 -> 502,9 -> 494,9"); 268 | let mut grid = parse_grid(instructions, false); 269 | assert_eq!(grid.width, 10); 270 | assert_eq!(grid.height, 10); 271 | assert_eq!(grid.min_x, 494); 272 | assert_eq!(grid.max_x, 503); 273 | assert_eq!(grid.min_y, 0); 274 | assert_eq!(grid.max_y, 9); 275 | 276 | let as_string = format!("{}", grid); 277 | println!("{}", as_string); 278 | assert_eq!( 279 | as_string, 280 | " 281 | .......... 282 | .......... 283 | .......... 284 | .......... 285 | ....#...## 286 | ....#...#. 287 | ..###...#. 288 | ........#. 289 | ........#. 290 | #########. 291 | " 292 | .trim_start() 293 | ); 294 | grid.simulate_sand(false); 295 | println!("{}", grid); 296 | } 297 | -------------------------------------------------------------------------------- /03/input.txt: -------------------------------------------------------------------------------- 1 | GGVGlqWFgVfFqqVZGFlblJPMsDbbMrDMpDsJRn 2 | LwzHtwdLHHwDrzPZzzsJbJ 3 | wdLTBvSvHvZVGCjhfN 4 | HsSSnZVHjjssZnJpSJjBHHWgQGcgqqQLQdQFqNgWgqGNDg 5 | rmmRwrtfThtTrbCrGGGcLBDTqDBNQLdL 6 | mwPrrbzPfwvbzhwMMnnjHnBjZlnzMM 7 | gjjdMBgdqdTpJpBcjgRRRlqnvrqfnZtrtZDw 8 | zHShWLhCszCWHVbVzQWCPtQvNZRwtfftfNnrnftlfR 9 | PzPSssHbVhCLFMJFcMFJJMjdJw 10 | ZqJdtpfpjmpJjpnwWdttTCDLLTQFNTzTzrcqrQqc 11 | MsSlBGvBsSGGSlbGsCgggNTgzNLczFQNrNQVQcFzFF 12 | sGHHSGllhvMGhSRGCjtjtjnjnnmHWpWWtJ 13 | tMdjQlHPHsGjsCtsCpwwqfhfnnFMDMrpfD 14 | SbNvWvBRJRWwFSgppgSrfg 15 | RNcNbvzJRcVLRVzTRFLjdHCQttdZdPlHstPl 16 | QWqgpdBflpHNCNWNHHPm 17 | VVMbbJsLFVMhrMJMmRjFNHwHjjCTGSSRFj 18 | mbMsZzsLmVhJZrcLcJhLMtnqvBnZdggplDffvlnlvnDn 19 | prnNnsFnZpnBNdNtFrNnzNQQwTTQZqTHTQJQMwHDMDlZ 20 | jgfgcSmbLmhmcPShghRdmwJTQjTlqGlJQJHqQqGHqQ 21 | hRVhPfbCgbVggLVRSSmRhRPhrrrnCzzsvCvrnvFnNppsvBtd 22 | QJLNDWSWQdLFFFhLdt 23 | npHhHMsfsjpZjznRtmrMCdBwFBFrBdmt 24 | HsjHqRRfnnHRsgfHffZspgzqDGQSWbQTDNGhQhSqNPhDWWbT 25 | bsCmFDsGZCNsDmLDLZBSHSJTHnrZQMQSSQ 26 | jqRpwvfqnnRQrftdBMHddB 27 | phpchwpzjpvwRzwcsnlFsssPCCGzDlsD 28 | rMqzVQfrfVZWZhTdRTQL 29 | cgmtFtjFFJDDtFvSFRZdLlhpHZddmwTZWh 30 | FbcSTtctcvFTJNgtJDGNPnCqMPMfMBfznGVsrMCq 31 | wLJfGJJPZLBfwSLGHbqmhhDHHhFDzfhv 32 | FsnpFjVjplTQCspNlCDbzhMMbqvMvsgmHDqb 33 | lRdlTdTddllpRQFRltVVdFRcwrtrcWWcPrrWPrPSrZWLPc 34 | VGVZhTppGTfPnJVJrFqbsmbSSshHqWqRHF 35 | llzDCzlBLdNcCddlMMNBdCCtWHbFqFRRRsHjWtRwSWqbmjWm 36 | NbcMBBvzzMQLCDBVTQQPVrPQPPZVPp 37 | cdcgfmQdqlqhzzPjzfwpwf 38 | GLBGBDvbvRzGwtnnmPpp 39 | ZRCZBRFSRvLRLFvvbLLFQdHMTHTlQlNqNmqFlWdH 40 | vzjzvHtcHvJcDStLLGSShCbbfF 41 | MWFFTVZRMmMgdQdSQLwQrQwbGw 42 | gFTmgmVZssRsWZRNzJlBHHnnJDvzNPlP 43 | rHrvHpmHZfdGDDGGZd 44 | cTlMsNhllMhGchNPCBlhMQgVDdgDSSWVbWVwRQwRSgbV 45 | lnBjnNNTTMnCTcChPNhMvtzvFGLtJrjFtHHHzHJm 46 | lgpdZZMmGVVzVZzt 47 | HfHLrHqbPbzJJzRJJPTl 48 | HsLWWbDqFrqlqfbsbDqDBncpgFmmvpnmmgpvdvjcdM 49 | GpNVbTpJJNvMBMVvJTGvhnWQQScllnhhWlhVSznV 50 | ZjswwHHLZzGnjWjSjl 51 | sHdftLLtgLfwdtPmHtMbNpMTpNqGRbPvTqPv 52 | sHSNNhNwsllGSGGlWSGWSsFrrVbQrdmFrVrrmnrHmrHr 53 | QQMRZDDRcrcnmRcV 54 | fJfCPMJCzTMZSGsWwsWBwqQf 55 | HwQZZJsHdqqsdJQGRgCgVGgSqgpcGG 56 | ljWWbnPhjBlGpCRCnScSGg 57 | hrrztWlbPjltjMPSdJDZSsHttwsZwD 58 | VzzbmzvpvNhvBDqc 59 | QHSJSQGCwJCGrGQjjcgcBFhdgqdqFdDNNw 60 | rCGJtZrHhhtLRsth 61 | TMWwCLPpMTThrvtMRJjbjRvmJs 62 | fDzcHFfSfFQfZzZRJbdmmqqssqtbSW 63 | WWgGZglcllgPBBCBNVGPNr 64 | wrwwhpTpbqhqrshrrfrFfwfzRJGdNJHNmcFzCCzCRJGzGR 65 | vMggvjQvgPvQjVLMMPSZqWNJGCzcNGdcdzHPPzcmCzPz 66 | qDZWvBZVfDhbTtrp 67 | LpDvHdjVghnjbGrn 68 | FBBBPwwlBlwSfFTWPHPWWhmgngmmnPnmbsngngbGrb 69 | FwftBSCSfWCtwfVQDvHHCMVvdQLQ 70 | ZrQpQlSpNlqQCVnQBmdDqmWDqmWWBDBB 71 | HsZMsJvZzLMHTRwWhgDwmfDBgdhWdf 72 | RZvTzJGzRjFrVNVjlQrS 73 | mqjMwfqlSSPmSrlPhwhVpGRcppWcpcGRcGWv 74 | ssJDJJNgZNDWrRWcRpvr 75 | ZTsTnnsLJQgPnfMwmnMrfm 76 | qsVBvZqWLdfbfvLj 77 | mPNRgmHBBGQrCbSbrdfCCSbC 78 | PlQTGcTTcgGFQQGPTGllpqMzwzpVJZwBMssZ 79 | FWGcNRLRLhwJJQfV 80 | nzbzlDBHSpTDbpDpzHwCqhqwJJghQqQMCCBw 81 | JnzndzpmJFmNsrrFsc 82 | gmRwwDwfnRDJgwZLFQFFNGNQrFBmFbbm 83 | CCVHVWWThSrjVGvbNj 84 | WpdqpplppHCWzlClMMTTZJcJsdscJLLdbDDfZDgL 85 | VNtCCMDllpBqDvtdCczTSgjHlzGSHSGZTZ 86 | hPFPsQhhFhLnbsRnLFssdzcHdsSHSSHgjzHG 87 | QPWPQrPPmbdnbWLFPrrBVrVDBqqNMVwttDtBvD 88 | PPNNRggwgRRgHBhDtwhTwbDs 89 | SFGSFSMCJFMrcrCMSSsbtrTbbZhBvtHhrTHD 90 | MFfSMpflQLQflfLjnLmddsLdddqq 91 | RcgbcrrFscVrwZVCgVGGmHppNNndWnGdNqddqqNqND 92 | jTlSTBSTjLTvlvjjPtvMLlhHnftphtDFNFqDnDHWNddn 93 | QBMQvzzjzvJPjFQMmwZJrgmCCJVRVbbc 94 | CzPJsWCpvsNszsJsNsHlDhMrrJGjhrRVhRGgDDjG 95 | tFFdbqFLFdwctQdfVhjRRghTcrjVRTDW 96 | bwQtFLdLBdFmwnHnWHPBNnHCnp 97 | CNTstGNslRRRstlmNmmTZZqfFwtqgwqgfBPSwSWwqgWq 98 | hpDbcHbpSrcgqqzhhWVfqg 99 | DDcLDjbMjCSsZRNlMv 100 | MhHMCMNbzbMHlcqmGmrmWc 101 | tnPggdZPBPgdtttJpdnwVBnmqQcvlQrQlfGqmfWffBcqWD 102 | VPPwPPLPwLGFGLzCbG 103 | rqBcBmjHTGfPbcVgPG 104 | dlDpsdshzlldlDvsWlWvLQbQBbfLFLbPvbBGQBgG 105 | BlBznnRWzlphphBnhZjZtNNCNmrNqjCqHwHN 106 | mQBvmvBmmLJvvrLtttQrfhGlcRGfRhVGWJVChlRG 107 | MzPswTsbTPPsNgMNszgzMpbMfcRcGflVGRfWSpFRlWWWFhcC 108 | bcPsTbgbbTTwNZzTZzvdjdjtQQndZvdrvdmZ 109 | hQzTQJFFZJrcdcdZFFrGFSVWVRWRwRgRHVMWDCDSWc 110 | lPmpNBnnnsNBnLnfbfnCDWMvwRvDCCMPwwHWvM 111 | HpjmffNlnqqhddTddFZjGJ 112 | BwsLFFbHLbVCSCSFbsbFLsJbqnTtZrRMHTZtrTrZTcRRRRTq 113 | lGhNhpPmmhpztZTBrcpjRqpB 114 | QPzdfzBQNgFJSCwsdLbS 115 | ZsZsSBTgffSCqSSfrMnnMwjqmqmnnnqwMm 116 | bbPPbzVclcPzGNlvzVtmnDBnQmtnQLBjJVLn 117 | zPFGplGGvdPbHplcbzzvdlNBTThgRpCTCTfhfsCCsSRZhR 118 | CVLSVCLVZRsHcnzSRpdZZRCdPlmcMWDDlPNqMqtDMmqPMlDt 119 | TBnGjfQrQJjhfWlPPmPQDNlmlP 120 | fjhhGvjvvrTTBhvTBTbvGVRLzVnbSRZpHddspHRzLs 121 | DDtWjfRfftWMLzSQjzzhWjjwRVPHqFbBbZHVwZBFvFwZvZ 122 | JGllgCJlJsrCGPrCNTPdslvZVVNVbvBqNbbpbbFHpBwZ 123 | CcPdnCdmCJjfcftWhtSL 124 | pgpfddDGHWzDNGNGpRCQjCTFHZZQFQjcRT 125 | bJlhqmMvnlrRQFtTthPVhZ 126 | lvbJrlJMBwfzGNTddB 127 | wpbJGGZpsjvtdWvGWF 128 | HqqhBhBqhhNQHTSHqqNzRHVPvTvddWrjtrjFvrvdTdVP 129 | NRLCRzlqHQtNRBLzQllhhZcgbggwmLDZpsgssDpwwD 130 | pDzFzJFcVMcWJFJFzpLBsqWLZssshsGLGbsS 131 | wqHqfvnfrRwQtdQRthhBbBbZLhPLnBTGsh 132 | CfQqlqvtfHNvMVmzmmMCFDMc 133 | GcgpNHvcSNvpSLphdhsLdQTsdWThhQ 134 | wwzttPrrhQswdhnT 135 | tjJjMJRbRbjztmjtjbgcRsNlgglHpDFSlSvg 136 | VVLvLqqPVlvcqLLdwLbHpzcHSsbRJppHbHpF 137 | CfjjCNGmMWhWjhWHWb 138 | ZmGZffggrDqZvZtlbTqL 139 | TTmmhvBvvHWzHpsPpstpLVdwwsLb 140 | qflfFgNctNcCnCCNDnfFFNDwrslwZbPswwZbJLJZbrlPLL 141 | FgQDDcncStCgtqccjSDTHWMThvhTQMBQhWvWRG 142 | SqhVghPccSBhgSBqWBFNQNsHQHMjCCQQWCwQHN 143 | fLZftnlttcbbtZbZlpZtttQjwsCQjRwwRDQspMRMNNQs 144 | TfLtvbJtZmlbTTTtlJbFvVqPSgBdPqPhFSGBcd 145 | pPPNDptcqtpcDztLDhhngnnJgJTmJwNnwm 146 | HVVCsSClHGBCHslWHbSCGGVngTrJwnnJnQRRBrhQhgJhdm 147 | WTWWWsvVlvGbWCFvjDftPpjqZLLtDz 148 | wWclwtDwRvflvffB 149 | sMMsGdsSTMrJZNqczfdvhvnzCnfv 150 | rspppMjMspSTSMpgLjcPFmwPLmPHwb 151 | tCdSMHtHtRFHdWSSJQSgrrrnghTNJN 152 | BGfcvDsfvsqcvqfGvfGnNLhggBNQJNJQmpgQJm 153 | sGfQDPDZzfDZzclwDzwsDlfjtbdHClFRCMWjbMFMRFWbdj 154 | pJNCcvqCccsVvFCpqsmvWJfCBWgSzBBRrrBRDDgDrSbbgQbQ 155 | TMLnLjjffwfwGdjQjDDBjBrDtztRSb 156 | MdPLGhHnMZhlPHHTFfZvVCpmmmcFcVFC 157 | SwFMfCMRCdQDdMbmdFfdbbnlcVncVCcgLqWcNNnCcWlW 158 | hPjQzzhGzhpPrtPJPpPHrVgnqVVncVVnNHlqVnncNB 159 | ptjGrptztpthtrtJJhTsGwFDZZDQmSdfZSwsRZSwfZ 160 | rSSWWCWrdllHWpjcnFNnRCNjQp 161 | bGwwJqGVGbGJVVhgbBgttGmBQjFsMjpMcMnnMBcQFNnsssvv 162 | bfthwmfJfgwwmmwZqVJPHNHSZHWzSlDPrdDdSH 163 | nmJccvclcbwmlbbvVbvsHwJJPCPNCNPnLBhrBPPLBhLhBgBP 164 | MdRGtdDRTqWDMqtMDtQDRWSdLLBsrhLgBCgrgCgNNLPBfNMf 165 | dRZQdDdRRSQWGsjZmwzjmlzsZH 166 | PBGGMrTQTrTBpPQpLpSlwjwfjtlnfwbmGttw 167 | fCsJCWJcvRCtwwjbCl 168 | NsqcsfcvDHFVDJvdLQTrpdTTzTPpHr 169 | rltrwsBTlrfGZggGBLGGNN 170 | jhMnRQJVphMnbhvQjDZNqqZDNTNHZVHGHq 171 | MRvbhQRQQChpvbjvMSvQnMcsFsfwwmlCwFwWcTWwrmPc 172 | DDvLLLBnvrzvbvbmtv 173 | TMwRjTRMGCwGGwrjQQnmrQrrQdhZ 174 | MJPFHFTwgCGqGqgJMGDfSWcsnBSccgVDlnpW 175 | flzVzNrdLNLJzrGlfdlzjrQDgFTpDgDmmmgFmqFDQjQh 176 | CbnBcsZnPZVSnwvVsZbRhhBDpgFphgmgDgTppq 177 | ZWnsWSnncSZsntZCbsswwJMzdLzlMdNMLtMVfrllMt 178 | ZffSgNfgJgGCHZcZrpHrNJTLhqvSLTqQnvVTLvzvLTjV 179 | tWFtHMwlBlDqjjzjnqvvlV 180 | DRMPDtWHPFDBFFwWMFBmFRPgZpJfsffNGJNrGcsprrsmfg 181 | wRZRmpZmlPqZjzGrdrGq 182 | bBhQQFPQbPDVNzVNzdGWNdrf 183 | QFbcDcDbLHgHBPDFRsSSMtmvRttMpCLS 184 | MpWJVVJMcWvpRShcwpLGflmqzSfNdfNLdQzN 185 | CDBTtCgtbjgCRrBrPBTQqzflNqjGdLzzmqffzq 186 | rFgnnBbttDTPtHCDPrPMnpwVJhJvMZvpMvppRZ 187 | sWTTmpsfsWppPTTsTVZWHVVZNvVcdcJvdN 188 | DjjBzjhRHvvvSzdc 189 | rMBjjrjbjrGDlgMlMrGjBgRLPTTwHMsfnFwFQPMPMnmFFm 190 | QRRbDjjmPzNQwFDNmrQmzCbVHrMhBVrJLJJfMGGLtfJBHh 191 | dsWcsqqWSWvnWnWcWGPJLBqhLBqGhBJHHH 192 | ZWnPWgWgPnlbCDDwmmDbRZ 193 | nfPqqfLqQnfHBSqnzztQjVmjfGRWJNGRWsJWJfmJ 194 | TTMlMMlFDMGVGRsVJH 195 | CbDbFDbvgTFFwgTDlDprhlPSqBzSnPdLPtPPHgznQqBQ 196 | fJmWVfHqjfjhZCQZ 197 | NcNzBNvgszQmzjnthZQC 198 | LsLsgBNFmFgTFgGBBgcdMdvPDPDJWrlpVbGpJWqHDlHJHD 199 | SllDdvzgdFDdlPJvbFDDSzFScPTRTNcwfZRwRhcwwNnRZTtf 200 | WBpWBCLGVpLjHrHGGVhZNwcTVcNhVnRcNZ 201 | LHLQLspHWQGpWCHnBvdzDJFlqvdsqgSgqS 202 | GcTctDMjMhpMDRjLsMMsfDWFfdPCFNbnCPnvCPgW 203 | JmvwqlBwnmfdFPFP 204 | SvZqHSZqqHZZZBlllBwSwsRsMHpLjpLsMGtsMspGRT 205 | ClLnCLfClLVllfLLcQjLBCfCmSHVsttsmtsVStDNVdppdsSp 206 | PFrRMbWqMRwFRqRSqwqvMvMsGtgsdmssrgNtdmpNdDGgdt 207 | bwJbPWPwFFPFSczCZzZZCcfjBJ 208 | MwmBmzwJQTcTmfPVfZPwhhwHPH 209 | jlnrglFLvbrGRFGnvFZdNNFfPZddPThVhdPH 210 | RjbjpgbnLGvpLgzBqBpmWmmzqTMS 211 | FnsSpttPnPbNCFDtsPnFHQZTQZgcwgDDTfrfTHMZ 212 | mRjzRzlvBvhjZrQmMMwfZZNN 213 | ldzddlzLRlRWdhjdRLjhRWtJbJbNtJJpJPbCbGCWNG 214 | wBwmNZBTmzzcVcmpzZqdMgPjnLSVlPgDPdbMdg 215 | flJvGtHffHDddddbHjnb 216 | RstrhfrhhRGFQtRhtftvQhvFZpsmpWwNlWqcWTccBNWswqNp 217 | DPWhbzDlQLLlQbLDlLhPhLFNNJqCFGqnNJCCSCnGPnGN 218 | wvwjtvtdwfssvSJgFFvGGSCFcp 219 | mtdrZwwJsrtddrHRtZWbVThLlBzVTzhHQWhB 220 | TsRRWctsTJMQZllggc 221 | zDvhpbprgGvpvVlVQlZpQMJVlQ 222 | rrrvFvGCDhDSrrrvChCgSstBNTSftWBjTdfWBN 223 | JJdssBcLVGrgbBHWrH 224 | QZTptvmvmlZpRDlMMMZCQvnjjFnrjWGFbjnrnFGWgZrz 225 | TMRplDMggtwlppTlvhsJJqdcqwVPSSNcLd 226 | JjTCCrcRvccPLmMP 227 | NfGFPZlNnwBfPlbbbQZGqLHgzLghSmMBzSgvzmDMhv 228 | ZfbnNQpQnZGlGlGpWTddjdTJdpRPTrCj 229 | gWLblMMggdWsdRJlblMRMMqWDvPvcPPPccJPJVTZVZThmcDP 230 | rQFfGfrCHrjnrtNTcPShTSPvvVLtmm 231 | fQrCfLrpLHnCHwslqzqsslswzqRW 232 | zpJtGlJPMPTlTjGJCDGCDljpdnvhhWnZnZnDwwmvnWDWWvdd 233 | sHrVrSrRRRLNgLVBqSsZmWwvwcvwZjmwngmdbn 234 | QsQQBrrLHTjPpTQzzP 235 | JDlzHHzzptRDmbTMrrVQ 236 | dRRNqnCBnmrQsVQQ 237 | wFPCBNFgwjPwhgFNztftpJRPpzRvvHtZ 238 | DlBhrDBPPwMWwhWchW 239 | ntSqbbSJFJNqzVzjCfMvfSlSRWccRL 240 | mVlHtNVtqldbJVmNHmdTTBBgrQQgGsPQdrDgsP 241 | HWHNbBgvNLdcvQMnSf 242 | wqqqVPDPhqwszFwrrszFfMdWthLcMdfhthSQfJSt 243 | qVPVwTzFwFDpDrPDzDPFDPlCHjBGjTmZGjbWWGZBRTNjjH 244 | GVgdWjllSqgjdgHqqlfmhwcpwCzhvZwMcScv 245 | nsJQbLRQsNnzQDQQPPBbRBRhfZwpZcvwpvvmLCcvpcmfMM 246 | DRJtnnRbBBnPztsrPzRBPbsFFHqqVrqggjFWqrgWjTGgFq 247 | hhZJQPJFHGGlcWWslpNN 248 | VwwwJjvwMtrCnwjDNDzlfscWszWW 249 | nVStCrMqbVwqVqSqwnLPhTJFdRgJHZSFRLTP 250 | vPgMbbRhhvMvNjjLWsWQsHQmHwBrmmBzww 251 | tFctDnVFpppHVBTdzdTQwl 252 | FtSFqSptfJCqqJStZCqDpDJMhvLLgLMgQgjgGZgGgMPLZg 253 | zwsWgSGWLSVhPWhtLgLWhPVNQTmDrDQttZpdQtdpQDDQZQ 254 | fjCHcvvjMDrppCQpVV 255 | VMqRnVJMVLPzbRWhGh 256 | mjRmzQlzDzNHWwDZ 257 | FBfJBGqnnpfSVGnpJbJVfNtCsJHWZvrsNJCZrCNsvN 258 | fZPBnfPqSBqdfpFbVnVSjgdcLLgRLjmgRhLLghlR 259 | FSFnTcppdQtnnDhtzDfg 260 | ZLGVmBLBVwZCVjjGqGhVwVVgzzbMDtNNvszMmMffNDDvtM 261 | VZPJjBZVqBZZBjqwVqllpSTphhQFPShWSQcW 262 | hTRdcLrCLgplLvBFGvlL 263 | nZDZqzbDbDzRZtVNDzDWGwslsllBFpnlpGvJssFG 264 | zbqjNWQVmVPrrRjRdRhS 265 | VpNCbVHlHHZfflVfmchctqFcqQQjZmZM 266 | WDSRGgsSvgJSRrnWgqQhmjBqmhqrtLqmQm 267 | znSGTgDJnsDGzgwCwlpbCNwHzVtl 268 | sTTTrpHFFFqTnQbbvfJdDzHHDLVV 269 | CjMtgMgRvbPfjjvB 270 | mhMvlhhWClvqshNTQQqsNN 271 | tWFtFBzbwdFrpmdhdm 272 | qTqDjJjJQQqMjTDLJjNqNqPNdmpcSmhdmhhmcrWZpdPGddcc 273 | RjNQLJNTTJDDJRHHjQqnMWtlvvVvbtBvRVzgzgwgVg 274 | CGdQjwdJrbBmpmZZZlRWcb 275 | NgtMPVstgSzBLzhgzgLgDRlcmDWRmlZvcSmDSvvp 276 | LhNsgPPLFPPsNzMhhVzPsGJBFqwQGfnqfQjdGdGfwr 277 | CNbNdbzjCZpPNzjmzjsCMRJvnnMRGnsvJGRs 278 | wrtdwTLWFcFWdFgwRRsnJGnGfTGJfMsq 279 | FttcwgBtgVLgPldQSNZBzBpz 280 | DjRZrrRmttRFDvDrFTZsnWnHVSTSSJVZJH 281 | dNNhLqlLLqdCzfMMlCfSncTVVWcHdcVsVdSVnT 282 | QqppMfzMfqWCwbRQrwFrrttQ 283 | dwGjHrtjsdhfCHnPSpfMfDPpPDWS 284 | lmNzzlLbFqcqNgzpWMSvbbvDQDGWDp 285 | LBmglgmqBqmrwCGhCjVtBC 286 | tvHgWZCCprlgpWglCtjPhLmPmhVdJFSzVzdJVmmQ 287 | fBnTTnNNBnwfnNqcBbBBTbGJQQJhSSdQJJsmdJFSQGSmVV 288 | cMcDwFbRfFRlHCRCZrrp 289 | ZFWmgghzBgwgjWBzjzmRWWMmsVwnVrsdVdwNrrpnnVrPCnCP 290 | GLLbtGqllctqvGJvSlQbJGsPnVdsdpsTPLsVppBCTVss 291 | tJBStGSvctvDDfczmRgRZjzDjZmgzH 292 | FMrLmsQQSWzCZBhpQJTQQZ 293 | dPPVncVvPBJDCPhwJD 294 | fvHbbVHvqnvvvBzgLbbGGmrbMr 295 | mrZzrzqDrhZqDddSFrCGLLLPQPQBJPJJBnQq 296 | TgbpGblWlMsjgWlgMfpNRgbRHHBnHHHtLpCJPCPBnBLJtQQL 297 | sbTlblTlvRbbGblbFcdDzccVcDVvzzzd 298 | zMzfzlGwSBMMSCMzhsPgfcPcfcbhjQPt 299 | FHHqJVdJmFmdVrJdJppthscjGtqRPRcccgcQbR 300 | rvNJJpLrvvLnJvNFFvZZZBWznBWGSDCMnCwz -------------------------------------------------------------------------------- /day_03_part_2/input.txt: -------------------------------------------------------------------------------- 1 | GGVGlqWFgVfFqqVZGFlblJPMsDbbMrDMpDsJRn 2 | LwzHtwdLHHwDrzPZzzsJbJ 3 | wdLTBvSvHvZVGCjhfN 4 | HsSSnZVHjjssZnJpSJjBHHWgQGcgqqQLQdQFqNgWgqGNDg 5 | rmmRwrtfThtTrbCrGGGcLBDTqDBNQLdL 6 | mwPrrbzPfwvbzhwMMnnjHnBjZlnzMM 7 | gjjdMBgdqdTpJpBcjgRRRlqnvrqfnZtrtZDw 8 | zHShWLhCszCWHVbVzQWCPtQvNZRwtfftfNnrnftlfR 9 | PzPSssHbVhCLFMJFcMFJJMjdJw 10 | ZqJdtpfpjmpJjpnwWdttTCDLLTQFNTzTzrcqrQqc 11 | MsSlBGvBsSGGSlbGsCgggNTgzNLczFQNrNQVQcFzFF 12 | sGHHSGllhvMGhSRGCjtjtjnjnnmHWpWWtJ 13 | tMdjQlHPHsGjsCtsCpwwqfhfnnFMDMrpfD 14 | SbNvWvBRJRWwFSgppgSrfg 15 | RNcNbvzJRcVLRVzTRFLjdHCQttdZdPlHstPl 16 | QWqgpdBflpHNCNWNHHPm 17 | VVMbbJsLFVMhrMJMmRjFNHwHjjCTGSSRFj 18 | mbMsZzsLmVhJZrcLcJhLMtnqvBnZdggplDffvlnlvnDn 19 | prnNnsFnZpnBNdNtFrNnzNQQwTTQZqTHTQJQMwHDMDlZ 20 | jgfgcSmbLmhmcPShghRdmwJTQjTlqGlJQJHqQqGHqQ 21 | hRVhPfbCgbVggLVRSSmRhRPhrrrnCzzsvCvrnvFnNppsvBtd 22 | QJLNDWSWQdLFFFhLdt 23 | npHhHMsfsjpZjznRtmrMCdBwFBFrBdmt 24 | HsjHqRRfnnHRsgfHffZspgzqDGQSWbQTDNGhQhSqNPhDWWbT 25 | bsCmFDsGZCNsDmLDLZBSHSJTHnrZQMQSSQ 26 | jqRpwvfqnnRQrftdBMHddB 27 | phpchwpzjpvwRzwcsnlFsssPCCGzDlsD 28 | rMqzVQfrfVZWZhTdRTQL 29 | cgmtFtjFFJDDtFvSFRZdLlhpHZddmwTZWh 30 | FbcSTtctcvFTJNgtJDGNPnCqMPMfMBfznGVsrMCq 31 | wLJfGJJPZLBfwSLGHbqmhhDHHhFDzfhv 32 | FsnpFjVjplTQCspNlCDbzhMMbqvMvsgmHDqb 33 | lRdlTdTddllpRQFRltVVdFRcwrtrcWWcPrrWPrPSrZWLPc 34 | VGVZhTppGTfPnJVJrFqbsmbSSshHqWqRHF 35 | llzDCzlBLdNcCddlMMNBdCCtWHbFqFRRRsHjWtRwSWqbmjWm 36 | NbcMBBvzzMQLCDBVTQQPVrPQPPZVPp 37 | cdcgfmQdqlqhzzPjzfwpwf 38 | GLBGBDvbvRzGwtnnmPpp 39 | ZRCZBRFSRvLRLFvvbLLFQdHMTHTlQlNqNmqFlWdH 40 | vzjzvHtcHvJcDStLLGSShCbbfF 41 | MWFFTVZRMmMgdQdSQLwQrQwbGw 42 | gFTmgmVZssRsWZRNzJlBHHnnJDvzNPlP 43 | rHrvHpmHZfdGDDGGZd 44 | cTlMsNhllMhGchNPCBlhMQgVDdgDSSWVbWVwRQwRSgbV 45 | lnBjnNNTTMnCTcChPNhMvtzvFGLtJrjFtHHHzHJm 46 | lgpdZZMmGVVzVZzt 47 | HfHLrHqbPbzJJzRJJPTl 48 | HsLWWbDqFrqlqfbsbDqDBncpgFmmvpnmmgpvdvjcdM 49 | GpNVbTpJJNvMBMVvJTGvhnWQQScllnhhWlhVSznV 50 | ZjswwHHLZzGnjWjSjl 51 | sHdftLLtgLfwdtPmHtMbNpMTpNqGRbPvTqPv 52 | sHSNNhNwsllGSGGlWSGWSsFrrVbQrdmFrVrrmnrHmrHr 53 | QQMRZDDRcrcnmRcV 54 | fJfCPMJCzTMZSGsWwsWBwqQf 55 | HwQZZJsHdqqsdJQGRgCgVGgSqgpcGG 56 | ljWWbnPhjBlGpCRCnScSGg 57 | hrrztWlbPjltjMPSdJDZSsHttwsZwD 58 | VzzbmzvpvNhvBDqc 59 | QHSJSQGCwJCGrGQjjcgcBFhdgqdqFdDNNw 60 | rCGJtZrHhhtLRsth 61 | TMWwCLPpMTThrvtMRJjbjRvmJs 62 | fDzcHFfSfFQfZzZRJbdmmqqssqtbSW 63 | WWgGZglcllgPBBCBNVGPNr 64 | wrwwhpTpbqhqrshrrfrFfwfzRJGdNJHNmcFzCCzCRJGzGR 65 | vMggvjQvgPvQjVLMMPSZqWNJGCzcNGdcdzHPPzcmCzPz 66 | qDZWvBZVfDhbTtrp 67 | LpDvHdjVghnjbGrn 68 | FBBBPwwlBlwSfFTWPHPWWhmgngmmnPnmbsngngbGrb 69 | FwftBSCSfWCtwfVQDvHHCMVvdQLQ 70 | ZrQpQlSpNlqQCVnQBmdDqmWDqmWWBDBB 71 | HsZMsJvZzLMHTRwWhgDwmfDBgdhWdf 72 | RZvTzJGzRjFrVNVjlQrS 73 | mqjMwfqlSSPmSrlPhwhVpGRcppWcpcGRcGWv 74 | ssJDJJNgZNDWrRWcRpvr 75 | ZTsTnnsLJQgPnfMwmnMrfm 76 | qsVBvZqWLdfbfvLj 77 | mPNRgmHBBGQrCbSbrdfCCSbC 78 | PlQTGcTTcgGFQQGPTGllpqMzwzpVJZwBMssZ 79 | FWGcNRLRLhwJJQfV 80 | nzbzlDBHSpTDbpDpzHwCqhqwJJghQqQMCCBw 81 | JnzndzpmJFmNsrrFsc 82 | gmRwwDwfnRDJgwZLFQFFNGNQrFBmFbbm 83 | CCVHVWWThSrjVGvbNj 84 | WpdqpplppHCWzlClMMTTZJcJsdscJLLdbDDfZDgL 85 | VNtCCMDllpBqDvtdCczTSgjHlzGSHSGZTZ 86 | hPFPsQhhFhLnbsRnLFssdzcHdsSHSSHgjzHG 87 | QPWPQrPPmbdnbWLFPrrBVrVDBqqNMVwttDtBvD 88 | PPNNRggwgRRgHBhDtwhTwbDs 89 | SFGSFSMCJFMrcrCMSSsbtrTbbZhBvtHhrTHD 90 | MFfSMpflQLQflfLjnLmddsLdddqq 91 | RcgbcrrFscVrwZVCgVGGmHppNNndWnGdNqddqqNqND 92 | jTlSTBSTjLTvlvjjPtvMLlhHnftphtDFNFqDnDHWNddn 93 | QBMQvzzjzvJPjFQMmwZJrgmCCJVRVbbc 94 | CzPJsWCpvsNszsJsNsHlDhMrrJGjhrRVhRGgDDjG 95 | tFFdbqFLFdwctQdfVhjRRghTcrjVRTDW 96 | bwQtFLdLBdFmwnHnWHPBNnHCnp 97 | CNTstGNslRRRstlmNmmTZZqfFwtqgwqgfBPSwSWwqgWq 98 | hpDbcHbpSrcgqqzhhWVfqg 99 | DDcLDjbMjCSsZRNlMv 100 | MhHMCMNbzbMHlcqmGmrmWc 101 | tnPggdZPBPgdtttJpdnwVBnmqQcvlQrQlfGqmfWffBcqWD 102 | VPPwPPLPwLGFGLzCbG 103 | rqBcBmjHTGfPbcVgPG 104 | dlDpsdshzlldlDvsWlWvLQbQBbfLFLbPvbBGQBgG 105 | BlBznnRWzlphphBnhZjZtNNCNmrNqjCqHwHN 106 | mQBvmvBmmLJvvrLtttQrfhGlcRGfRhVGWJVChlRG 107 | MzPswTsbTPPsNgMNszgzMpbMfcRcGflVGRfWSpFRlWWWFhcC 108 | bcPsTbgbbTTwNZzTZzvdjdjtQQndZvdrvdmZ 109 | hQzTQJFFZJrcdcdZFFrGFSVWVRWRwRgRHVMWDCDSWc 110 | lPmpNBnnnsNBnLnfbfnCDWMvwRvDCCMPwwHWvM 111 | HpjmffNlnqqhddTddFZjGJ 112 | BwsLFFbHLbVCSCSFbsbFLsJbqnTtZrRMHTZtrTrZTcRRRRTq 113 | lGhNhpPmmhpztZTBrcpjRqpB 114 | QPzdfzBQNgFJSCwsdLbS 115 | ZsZsSBTgffSCqSSfrMnnMwjqmqmnnnqwMm 116 | bbPPbzVclcPzGNlvzVtmnDBnQmtnQLBjJVLn 117 | zPFGplGGvdPbHplcbzzvdlNBTThgRpCTCTfhfsCCsSRZhR 118 | CVLSVCLVZRsHcnzSRpdZZRCdPlmcMWDDlPNqMqtDMmqPMlDt 119 | TBnGjfQrQJjhfWlPPmPQDNlmlP 120 | fjhhGvjvvrTTBhvTBTbvGVRLzVnbSRZpHddspHRzLs 121 | DDtWjfRfftWMLzSQjzzhWjjwRVPHqFbBbZHVwZBFvFwZvZ 122 | JGllgCJlJsrCGPrCNTPdslvZVVNVbvBqNbbpbbFHpBwZ 123 | CcPdnCdmCJjfcftWhtSL 124 | pgpfddDGHWzDNGNGpRCQjCTFHZZQFQjcRT 125 | bJlhqmMvnlrRQFtTthPVhZ 126 | lvbJrlJMBwfzGNTddB 127 | wpbJGGZpsjvtdWvGWF 128 | HqqhBhBqhhNQHTSHqqNzRHVPvTvddWrjtrjFvrvdTdVP 129 | NRLCRzlqHQtNRBLzQllhhZcgbggwmLDZpsgssDpwwD 130 | pDzFzJFcVMcWJFJFzpLBsqWLZssshsGLGbsS 131 | wqHqfvnfrRwQtdQRthhBbBbZLhPLnBTGsh 132 | CfQqlqvtfHNvMVmzmmMCFDMc 133 | GcgpNHvcSNvpSLphdhsLdQTsdWThhQ 134 | wwzttPrrhQswdhnT 135 | tjJjMJRbRbjztmjtjbgcRsNlgglHpDFSlSvg 136 | VVLvLqqPVlvcqLLdwLbHpzcHSsbRJppHbHpF 137 | CfjjCNGmMWhWjhWHWb 138 | ZmGZffggrDqZvZtlbTqL 139 | TTmmhvBvvHWzHpsPpstpLVdwwsLb 140 | qflfFgNctNcCnCCNDnfFFNDwrslwZbPswwZbJLJZbrlPLL 141 | FgQDDcncStCgtqccjSDTHWMThvhTQMBQhWvWRG 142 | SqhVghPccSBhgSBqWBFNQNsHQHMjCCQQWCwQHN 143 | fLZftnlttcbbtZbZlpZtttQjwsCQjRwwRDQspMRMNNQs 144 | TfLtvbJtZmlbTTTtlJbFvVqPSgBdPqPhFSGBcd 145 | pPPNDptcqtpcDztLDhhngnnJgJTmJwNnwm 146 | HVVCsSClHGBCHslWHbSCGGVngTrJwnnJnQRRBrhQhgJhdm 147 | WTWWWsvVlvGbWCFvjDftPpjqZLLtDz 148 | wWclwtDwRvflvffB 149 | sMMsGdsSTMrJZNqczfdvhvnzCnfv 150 | rspppMjMspSTSMpgLjcPFmwPLmPHwb 151 | tCdSMHtHtRFHdWSSJQSgrrrnghTNJN 152 | BGfcvDsfvsqcvqfGvfGnNLhggBNQJNJQmpgQJm 153 | sGfQDPDZzfDZzclwDzwsDlfjtbdHClFRCMWjbMFMRFWbdj 154 | pJNCcvqCccsVvFCpqsmvWJfCBWgSzBBRrrBRDDgDrSbbgQbQ 155 | TMLnLjjffwfwGdjQjDDBjBrDtztRSb 156 | MdPLGhHnMZhlPHHTFfZvVCpmmmcFcVFC 157 | SwFMfCMRCdQDdMbmdFfdbbnlcVncVCcgLqWcNNnCcWlW 158 | hPjQzzhGzhpPrtPJPpPHrVgnqVVncVVnNHlqVnncNB 159 | ptjGrptztpthtrtJJhTsGwFDZZDQmSdfZSwsRZSwfZ 160 | rSSWWCWrdllHWpjcnFNnRCNjQp 161 | bGwwJqGVGbGJVVhgbBgttGmBQjFsMjpMcMnnMBcQFNnsssvv 162 | bfthwmfJfgwwmmwZqVJPHNHSZHWzSlDPrdDdSH 163 | nmJccvclcbwmlbbvVbvsHwJJPCPNCNPnLBhrBPPLBhLhBgBP 164 | MdRGtdDRTqWDMqtMDtQDRWSdLLBsrhLgBCgrgCgNNLPBfNMf 165 | dRZQdDdRRSQWGsjZmwzjmlzsZH 166 | PBGGMrTQTrTBpPQpLpSlwjwfjtlnfwbmGttw 167 | fCsJCWJcvRCtwwjbCl 168 | NsqcsfcvDHFVDJvdLQTrpdTTzTPpHr 169 | rltrwsBTlrfGZggGBLGGNN 170 | jhMnRQJVphMnbhvQjDZNqqZDNTNHZVHGHq 171 | MRvbhQRQQChpvbjvMSvQnMcsFsfwwmlCwFwWcTWwrmPc 172 | DDvLLLBnvrzvbvbmtv 173 | TMwRjTRMGCwGGwrjQQnmrQrrQdhZ 174 | MJPFHFTwgCGqGqgJMGDfSWcsnBSccgVDlnpW 175 | flzVzNrdLNLJzrGlfdlzjrQDgFTpDgDmmmgFmqFDQjQh 176 | CbnBcsZnPZVSnwvVsZbRhhBDpgFphgmgDgTppq 177 | ZWnsWSnncSZsntZCbsswwJMzdLzlMdNMLtMVfrllMt 178 | ZffSgNfgJgGCHZcZrpHrNJTLhqvSLTqQnvVTLvzvLTjV 179 | tWFtHMwlBlDqjjzjnqvvlV 180 | DRMPDtWHPFDBFFwWMFBmFRPgZpJfsffNGJNrGcsprrsmfg 181 | wRZRmpZmlPqZjzGrdrGq 182 | bBhQQFPQbPDVNzVNzdGWNdrf 183 | QFbcDcDbLHgHBPDFRsSSMtmvRttMpCLS 184 | MpWJVVJMcWvpRShcwpLGflmqzSfNdfNLdQzN 185 | CDBTtCgtbjgCRrBrPBTQqzflNqjGdLzzmqffzq 186 | rFgnnBbttDTPtHCDPrPMnpwVJhJvMZvpMvppRZ 187 | sWTTmpsfsWppPTTsTVZWHVVZNvVcdcJvdN 188 | DjjBzjhRHvvvSzdc 189 | rMBjjrjbjrGDlgMlMrGjBgRLPTTwHMsfnFwFQPMPMnmFFm 190 | QRRbDjjmPzNQwFDNmrQmzCbVHrMhBVrJLJJfMGGLtfJBHh 191 | dsWcsqqWSWvnWnWcWGPJLBqhLBqGhBJHHH 192 | ZWnPWgWgPnlbCDDwmmDbRZ 193 | nfPqqfLqQnfHBSqnzztQjVmjfGRWJNGRWsJWJfmJ 194 | TTMlMMlFDMGVGRsVJH 195 | CbDbFDbvgTFFwgTDlDprhlPSqBzSnPdLPtPPHgznQqBQ 196 | fJmWVfHqjfjhZCQZ 197 | NcNzBNvgszQmzjnthZQC 198 | LsLsgBNFmFgTFgGBBgcdMdvPDPDJWrlpVbGpJWqHDlHJHD 199 | SllDdvzgdFDdlPJvbFDDSzFScPTRTNcwfZRwRhcwwNnRZTtf 200 | WBpWBCLGVpLjHrHGGVhZNwcTVcNhVnRcNZ 201 | LHLQLspHWQGpWCHnBvdzDJFlqvdsqgSgqS 202 | GcTctDMjMhpMDRjLsMMsfDWFfdPCFNbnCPnvCPgW 203 | JmvwqlBwnmfdFPFP 204 | SvZqHSZqqHZZZBlllBwSwsRsMHpLjpLsMGtsMspGRT 205 | ClLnCLfClLVllfLLcQjLBCfCmSHVsttsmtsVStDNVdppdsSp 206 | PFrRMbWqMRwFRqRSqwqvMvMsGtgsdmssrgNtdmpNdDGgdt 207 | bwJbPWPwFFPFSczCZzZZCcfjBJ 208 | MwmBmzwJQTcTmfPVfZPwhhwHPH 209 | jlnrglFLvbrGRFGnvFZdNNFfPZddPThVhdPH 210 | RjbjpgbnLGvpLgzBqBpmWmmzqTMS 211 | FnsSpttPnPbNCFDtsPnFHQZTQZgcwgDDTfrfTHMZ 212 | mRjzRzlvBvhjZrQmMMwfZZNN 213 | ldzddlzLRlRWdhjdRLjhRWtJbJbNtJJpJPbCbGCWNG 214 | wBwmNZBTmzzcVcmpzZqdMgPjnLSVlPgDPdbMdg 215 | flJvGtHffHDddddbHjnb 216 | RstrhfrhhRGFQtRhtftvQhvFZpsmpWwNlWqcWTccBNWswqNp 217 | DPWhbzDlQLLlQbLDlLhPhLFNNJqCFGqnNJCCSCnGPnGN 218 | wvwjtvtdwfssvSJgFFvGGSCFcp 219 | mtdrZwwJsrtddrHRtZWbVThLlBzVTzhHQWhB 220 | TsRRWctsTJMQZllggc 221 | zDvhpbprgGvpvVlVQlZpQMJVlQ 222 | rrrvFvGCDhDSrrrvChCgSstBNTSftWBjTdfWBN 223 | JJdssBcLVGrgbBHWrH 224 | QZTptvmvmlZpRDlMMMZCQvnjjFnrjWGFbjnrnFGWgZrz 225 | TMRplDMggtwlppTlvhsJJqdcqwVPSSNcLd 226 | JjTCCrcRvccPLmMP 227 | NfGFPZlNnwBfPlbbbQZGqLHgzLghSmMBzSgvzmDMhv 228 | ZfbnNQpQnZGlGlGpWTddjdTJdpRPTrCj 229 | gWLblMMggdWsdRJlblMRMMqWDvPvcPPPccJPJVTZVZThmcDP 230 | rQFfGfrCHrjnrtNTcPShTSPvvVLtmm 231 | fQrCfLrpLHnCHwslqzqsslswzqRW 232 | zpJtGlJPMPTlTjGJCDGCDljpdnvhhWnZnZnDwwmvnWDWWvdd 233 | sHrVrSrRRRLNgLVBqSsZmWwvwcvwZjmwngmdbn 234 | QsQQBrrLHTjPpTQzzP 235 | JDlzHHzzptRDmbTMrrVQ 236 | dRRNqnCBnmrQsVQQ 237 | wFPCBNFgwjPwhgFNztftpJRPpzRvvHtZ 238 | DlBhrDBPPwMWwhWchW 239 | ntSqbbSJFJNqzVzjCfMvfSlSRWccRL 240 | mVlHtNVtqldbJVmNHmdTTBBgrQQgGsPQdrDgsP 241 | HWHNbBgvNLdcvQMnSf 242 | wqqqVPDPhqwszFwrrszFfMdWthLcMdfhthSQfJSt 243 | qVPVwTzFwFDpDrPDzDPFDPlCHjBGjTmZGjbWWGZBRTNjjH 244 | GVgdWjllSqgjdgHqqlfmhwcpwCzhvZwMcScv 245 | nsJQbLRQsNnzQDQQPPBbRBRhfZwpZcvwpvvmLCcvpcmfMM 246 | DRJtnnRbBBnPztsrPzRBPbsFFHqqVrqggjFWqrgWjTGgFq 247 | hhZJQPJFHGGlcWWslpNN 248 | VwwwJjvwMtrCnwjDNDzlfscWszWW 249 | nVStCrMqbVwqVqSqwnLPhTJFdRgJHZSFRLTP 250 | vPgMbbRhhvMvNjjLWsWQsHQmHwBrmmBzww 251 | tFctDnVFpppHVBTdzdTQwl 252 | FtSFqSptfJCqqJStZCqDpDJMhvLLgLMgQgjgGZgGgMPLZg 253 | zwsWgSGWLSVhPWhtLgLWhPVNQTmDrDQttZpdQtdpQDDQZQ 254 | fjCHcvvjMDrppCQpVV 255 | VMqRnVJMVLPzbRWhGh 256 | mjRmzQlzDzNHWwDZ 257 | FBfJBGqnnpfSVGnpJbJVfNtCsJHWZvrsNJCZrCNsvN 258 | fZPBnfPqSBqdfpFbVnVSjgdcLLgRLjmgRhLLghlR 259 | FSFnTcppdQtnnDhtzDfg 260 | ZLGVmBLBVwZCVjjGqGhVwVVgzzbMDtNNvszMmMffNDDvtM 261 | VZPJjBZVqBZZBjqwVqllpSTphhQFPShWSQcW 262 | hTRdcLrCLgplLvBFGvlL 263 | nZDZqzbDbDzRZtVNDzDWGwslsllBFpnlpGvJssFG 264 | zbqjNWQVmVPrrRjRdRhS 265 | VpNCbVHlHHZfflVfmchctqFcqQQjZmZM 266 | WDSRGgsSvgJSRrnWgqQhmjBqmhqrtLqmQm 267 | znSGTgDJnsDGzgwCwlpbCNwHzVtl 268 | sTTTrpHFFFqTnQbbvfJdDzHHDLVV 269 | CjMtgMgRvbPfjjvB 270 | mhMvlhhWClvqshNTQQqsNN 271 | tWFtFBzbwdFrpmdhdm 272 | qTqDjJjJQQqMjTDLJjNqNqPNdmpcSmhdmhhmcrWZpdPGddcc 273 | RjNQLJNTTJDDJRHHjQqnMWtlvvVvbtBvRVzgzgwgVg 274 | CGdQjwdJrbBmpmZZZlRWcb 275 | NgtMPVstgSzBLzhgzgLgDRlcmDWRmlZvcSmDSvvp 276 | LhNsgPPLFPPsNzMhhVzPsGJBFqwQGfnqfQjdGdGfwr 277 | CNbNdbzjCZpPNzjmzjsCMRJvnnMRGnsvJGRs 278 | wrtdwTLWFcFWdFgwRRsnJGnGfTGJfMsq 279 | FttcwgBtgVLgPldQSNZBzBpz 280 | DjRZrrRmttRFDvDrFTZsnWnHVSTSSJVZJH 281 | dNNhLqlLLqdCzfMMlCfSncTVVWcHdcVsVdSVnT 282 | QqppMfzMfqWCwbRQrwFrrttQ 283 | dwGjHrtjsdhfCHnPSpfMfDPpPDWS 284 | lmNzzlLbFqcqNgzpWMSvbbvDQDGWDp 285 | LBmglgmqBqmrwCGhCjVtBC 286 | tvHgWZCCprlgpWglCtjPhLmPmhVdJFSzVzdJVmmQ 287 | fBnTTnNNBnwfnNqcBbBBTbGJQQJhSSdQJJsmdJFSQGSmVV 288 | cMcDwFbRfFRlHCRCZrrp 289 | ZFWmgghzBgwgjWBzjzmRWWMmsVwnVrsdVdwNrrpnnVrPCnCP 290 | GLLbtGqllctqvGJvSlQbJGsPnVdsdpsTPLsVppBCTVss 291 | tJBStGSvctvDDfczmRgRZjzDjZmgzH 292 | FMrLmsQQSWzCZBhpQJTQQZ 293 | dPPVncVvPBJDCPhwJD 294 | fvHbbVHvqnvvvBzgLbbGGmrbMr 295 | mrZzrzqDrhZqDddSFrCGLLLPQPQBJPJJBnQq 296 | TgbpGblWlMsjgWlgMfpNRgbRHHBnHHHtLpCJPCPBnBLJtQQL 297 | sbTlblTlvRbbGblbFcdDzccVcDVvzzzd 298 | zMzfzlGwSBMMSCMzhsPgfcPcfcbhjQPt 299 | FHHqJVdJmFmdVrJdJppthscjGtqRPRcccgcQbR 300 | rvNJJpLrvvLnJvNFFvZZZBWznBWGSDCMnCwz -------------------------------------------------------------------------------- /day_05/input.txt: -------------------------------------------------------------------------------- 1 | [V] [C] [M] 2 | [V] [J] [N] [H] [V] 3 | [R] [F] [N] [W] [Z] [N] 4 | [H] [R] [D] [Q] [M] [L] [B] 5 | [B] [C] [H] [V] [R] [C] [G] [R] 6 | [G] [G] [F] [S] [D] [H] [B] [R] [S] 7 | [D] [N] [S] [D] [H] [G] [J] [J] [G] 8 | [W] [J] [L] [J] [S] [P] [F] [S] [L] 9 | 1 2 3 4 5 6 7 8 9 10 | 11 | move 2 from 2 to 7 12 | move 8 from 5 to 6 13 | move 2 from 4 to 5 14 | move 1 from 4 to 5 15 | move 1 from 5 to 8 16 | move 5 from 9 to 2 17 | move 7 from 1 to 6 18 | move 7 from 3 to 8 19 | move 1 from 4 to 6 20 | move 2 from 5 to 6 21 | move 6 from 7 to 5 22 | move 2 from 2 to 4 23 | move 4 from 5 to 2 24 | move 10 from 8 to 1 25 | move 2 from 7 to 4 26 | move 4 from 2 to 8 27 | move 2 from 9 to 8 28 | move 1 from 8 to 4 29 | move 2 from 4 to 9 30 | move 5 from 8 to 2 31 | move 1 from 4 to 6 32 | move 1 from 8 to 9 33 | move 1 from 7 to 2 34 | move 2 from 4 to 2 35 | move 1 from 7 to 3 36 | move 13 from 2 to 1 37 | move 1 from 2 to 4 38 | move 1 from 2 to 3 39 | move 2 from 5 to 4 40 | move 17 from 6 to 4 41 | move 3 from 4 to 9 42 | move 14 from 1 to 4 43 | move 4 from 6 to 8 44 | move 1 from 9 to 8 45 | move 23 from 4 to 8 46 | move 6 from 1 to 7 47 | move 3 from 1 to 5 48 | move 1 from 3 to 8 49 | move 5 from 7 to 8 50 | move 1 from 3 to 4 51 | move 1 from 5 to 3 52 | move 1 from 5 to 1 53 | move 1 from 3 to 2 54 | move 1 from 9 to 4 55 | move 9 from 4 to 9 56 | move 1 from 1 to 2 57 | move 11 from 8 to 2 58 | move 1 from 4 to 5 59 | move 13 from 2 to 3 60 | move 7 from 9 to 6 61 | move 1 from 5 to 6 62 | move 1 from 5 to 2 63 | move 1 from 9 to 4 64 | move 1 from 4 to 9 65 | move 2 from 8 to 9 66 | move 1 from 7 to 8 67 | move 8 from 9 to 1 68 | move 8 from 1 to 4 69 | move 4 from 6 to 7 70 | move 1 from 9 to 4 71 | move 2 from 3 to 9 72 | move 1 from 9 to 1 73 | move 6 from 4 to 1 74 | move 2 from 1 to 3 75 | move 22 from 8 to 6 76 | move 1 from 2 to 5 77 | move 3 from 7 to 8 78 | move 15 from 6 to 4 79 | move 7 from 3 to 7 80 | move 4 from 6 to 9 81 | move 2 from 9 to 2 82 | move 6 from 3 to 5 83 | move 3 from 9 to 5 84 | move 5 from 5 to 8 85 | move 1 from 2 to 1 86 | move 6 from 8 to 2 87 | move 1 from 1 to 2 88 | move 3 from 5 to 3 89 | move 1 from 7 to 2 90 | move 4 from 7 to 8 91 | move 4 from 6 to 1 92 | move 1 from 5 to 1 93 | move 4 from 8 to 7 94 | move 2 from 3 to 2 95 | move 1 from 1 to 3 96 | move 15 from 4 to 2 97 | move 3 from 7 to 3 98 | move 4 from 7 to 2 99 | move 1 from 4 to 9 100 | move 5 from 3 to 8 101 | move 29 from 2 to 1 102 | move 1 from 9 to 5 103 | move 1 from 2 to 1 104 | move 11 from 1 to 5 105 | move 1 from 4 to 5 106 | move 2 from 6 to 3 107 | move 1 from 3 to 4 108 | move 16 from 1 to 9 109 | move 4 from 8 to 4 110 | move 3 from 6 to 9 111 | move 1 from 3 to 7 112 | move 1 from 7 to 3 113 | move 6 from 1 to 6 114 | move 3 from 4 to 3 115 | move 3 from 8 to 5 116 | move 3 from 1 to 8 117 | move 3 from 1 to 4 118 | move 2 from 4 to 9 119 | move 3 from 6 to 3 120 | move 15 from 5 to 2 121 | move 3 from 2 to 3 122 | move 4 from 2 to 7 123 | move 2 from 5 to 9 124 | move 10 from 3 to 6 125 | move 11 from 9 to 5 126 | move 2 from 4 to 9 127 | move 8 from 9 to 4 128 | move 1 from 9 to 6 129 | move 7 from 4 to 6 130 | move 3 from 5 to 8 131 | move 22 from 6 to 9 132 | move 4 from 7 to 8 133 | move 8 from 5 to 8 134 | move 2 from 4 to 3 135 | move 1 from 8 to 1 136 | move 17 from 8 to 3 137 | move 3 from 3 to 4 138 | move 13 from 3 to 9 139 | move 20 from 9 to 7 140 | move 2 from 2 to 9 141 | move 19 from 9 to 5 142 | move 1 from 1 to 4 143 | move 3 from 2 to 7 144 | move 4 from 4 to 3 145 | move 1 from 9 to 8 146 | move 18 from 5 to 1 147 | move 1 from 9 to 4 148 | move 1 from 9 to 7 149 | move 2 from 4 to 8 150 | move 1 from 5 to 4 151 | move 3 from 2 to 7 152 | move 3 from 3 to 1 153 | move 2 from 1 to 3 154 | move 3 from 3 to 8 155 | move 1 from 4 to 8 156 | move 6 from 8 to 2 157 | move 1 from 3 to 9 158 | move 1 from 3 to 9 159 | move 10 from 1 to 9 160 | move 7 from 1 to 7 161 | move 4 from 7 to 4 162 | move 29 from 7 to 3 163 | move 6 from 2 to 9 164 | move 25 from 3 to 6 165 | move 5 from 3 to 9 166 | move 13 from 6 to 9 167 | move 12 from 6 to 2 168 | move 1 from 8 to 9 169 | move 10 from 2 to 6 170 | move 7 from 6 to 5 171 | move 20 from 9 to 3 172 | move 11 from 3 to 6 173 | move 1 from 7 to 9 174 | move 2 from 2 to 9 175 | move 19 from 9 to 2 176 | move 14 from 6 to 8 177 | move 4 from 5 to 2 178 | move 2 from 4 to 6 179 | move 3 from 5 to 1 180 | move 13 from 8 to 5 181 | move 1 from 6 to 1 182 | move 2 from 4 to 2 183 | move 8 from 2 to 4 184 | move 6 from 4 to 7 185 | move 1 from 9 to 8 186 | move 2 from 4 to 7 187 | move 5 from 2 to 4 188 | move 4 from 4 to 2 189 | move 10 from 5 to 6 190 | move 1 from 1 to 7 191 | move 1 from 5 to 4 192 | move 1 from 4 to 9 193 | move 4 from 7 to 8 194 | move 5 from 1 to 7 195 | move 1 from 9 to 7 196 | move 7 from 3 to 2 197 | move 2 from 5 to 2 198 | move 8 from 6 to 9 199 | move 1 from 4 to 6 200 | move 3 from 7 to 4 201 | move 5 from 9 to 7 202 | move 2 from 4 to 3 203 | move 20 from 2 to 4 204 | move 2 from 4 to 8 205 | move 14 from 4 to 2 206 | move 12 from 7 to 4 207 | move 8 from 2 to 1 208 | move 10 from 2 to 4 209 | move 6 from 8 to 5 210 | move 1 from 7 to 8 211 | move 4 from 4 to 3 212 | move 1 from 3 to 9 213 | move 1 from 2 to 7 214 | move 1 from 6 to 8 215 | move 5 from 3 to 5 216 | move 1 from 3 to 2 217 | move 7 from 4 to 5 218 | move 6 from 1 to 7 219 | move 5 from 7 to 6 220 | move 1 from 6 to 5 221 | move 2 from 7 to 8 222 | move 1 from 2 to 6 223 | move 2 from 8 to 2 224 | move 5 from 5 to 7 225 | move 6 from 6 to 8 226 | move 16 from 4 to 9 227 | move 16 from 9 to 4 228 | move 11 from 5 to 4 229 | move 5 from 8 to 3 230 | move 2 from 5 to 2 231 | move 14 from 4 to 2 232 | move 1 from 6 to 3 233 | move 1 from 6 to 9 234 | move 1 from 5 to 3 235 | move 3 from 8 to 2 236 | move 10 from 4 to 7 237 | move 5 from 9 to 2 238 | move 3 from 4 to 7 239 | move 1 from 1 to 4 240 | move 3 from 2 to 5 241 | move 2 from 3 to 7 242 | move 1 from 4 to 2 243 | move 18 from 2 to 8 244 | move 3 from 8 to 4 245 | move 5 from 3 to 1 246 | move 1 from 3 to 9 247 | move 1 from 9 to 3 248 | move 8 from 8 to 7 249 | move 2 from 5 to 4 250 | move 1 from 5 to 6 251 | move 1 from 2 to 5 252 | move 1 from 5 to 8 253 | move 1 from 6 to 9 254 | move 3 from 2 to 7 255 | move 27 from 7 to 4 256 | move 2 from 2 to 4 257 | move 4 from 8 to 4 258 | move 1 from 9 to 8 259 | move 3 from 1 to 6 260 | move 1 from 3 to 5 261 | move 3 from 8 to 3 262 | move 1 from 1 to 4 263 | move 1 from 8 to 1 264 | move 3 from 1 to 4 265 | move 2 from 8 to 2 266 | move 2 from 6 to 2 267 | move 8 from 4 to 9 268 | move 1 from 7 to 1 269 | move 1 from 5 to 4 270 | move 1 from 7 to 3 271 | move 4 from 2 to 7 272 | move 1 from 8 to 6 273 | move 8 from 9 to 7 274 | move 1 from 6 to 3 275 | move 3 from 3 to 4 276 | move 37 from 4 to 1 277 | move 1 from 4 to 5 278 | move 13 from 7 to 8 279 | move 6 from 8 to 4 280 | move 5 from 8 to 3 281 | move 1 from 7 to 6 282 | move 4 from 1 to 5 283 | move 1 from 6 to 5 284 | move 2 from 8 to 4 285 | move 32 from 1 to 5 286 | move 1 from 1 to 4 287 | move 5 from 3 to 5 288 | move 1 from 3 to 2 289 | move 1 from 2 to 9 290 | move 19 from 5 to 2 291 | move 1 from 9 to 1 292 | move 16 from 5 to 1 293 | move 7 from 5 to 6 294 | move 1 from 3 to 1 295 | move 11 from 1 to 2 296 | move 18 from 2 to 4 297 | move 1 from 5 to 9 298 | move 8 from 6 to 1 299 | move 10 from 2 to 6 300 | move 7 from 4 to 9 301 | move 2 from 2 to 1 302 | move 7 from 4 to 2 303 | move 5 from 4 to 5 304 | move 2 from 9 to 6 305 | move 9 from 6 to 3 306 | move 5 from 5 to 3 307 | move 8 from 4 to 9 308 | move 7 from 9 to 8 309 | move 4 from 2 to 9 310 | move 10 from 3 to 1 311 | move 6 from 8 to 1 312 | move 2 from 6 to 3 313 | move 5 from 3 to 8 314 | move 3 from 2 to 7 315 | move 1 from 9 to 5 316 | move 1 from 3 to 5 317 | move 2 from 7 to 8 318 | move 1 from 8 to 9 319 | move 1 from 6 to 1 320 | move 23 from 1 to 4 321 | move 2 from 5 to 3 322 | move 1 from 8 to 2 323 | move 2 from 8 to 5 324 | move 2 from 5 to 6 325 | move 1 from 2 to 7 326 | move 1 from 7 to 5 327 | move 4 from 9 to 7 328 | move 1 from 7 to 5 329 | move 1 from 3 to 6 330 | move 3 from 7 to 4 331 | move 1 from 3 to 8 332 | move 1 from 4 to 6 333 | move 6 from 1 to 8 334 | move 4 from 6 to 4 335 | move 2 from 9 to 1 336 | move 1 from 5 to 1 337 | move 19 from 4 to 2 338 | move 2 from 9 to 3 339 | move 1 from 9 to 3 340 | move 9 from 1 to 8 341 | move 1 from 5 to 8 342 | move 1 from 9 to 3 343 | move 2 from 3 to 9 344 | move 3 from 8 to 4 345 | move 1 from 4 to 9 346 | move 1 from 9 to 5 347 | move 2 from 3 to 4 348 | move 6 from 4 to 7 349 | move 3 from 9 to 5 350 | move 4 from 4 to 7 351 | move 1 from 5 to 6 352 | move 18 from 2 to 7 353 | move 13 from 7 to 9 354 | move 3 from 5 to 1 355 | move 1 from 2 to 1 356 | move 1 from 6 to 5 357 | move 3 from 1 to 7 358 | move 1 from 1 to 5 359 | move 7 from 9 to 6 360 | move 8 from 7 to 4 361 | move 11 from 7 to 6 362 | move 5 from 9 to 2 363 | move 17 from 6 to 1 364 | move 2 from 5 to 1 365 | move 11 from 8 to 1 366 | move 20 from 1 to 2 367 | move 3 from 8 to 1 368 | move 1 from 9 to 8 369 | move 1 from 6 to 1 370 | move 11 from 1 to 7 371 | move 18 from 2 to 3 372 | move 12 from 4 to 8 373 | move 11 from 7 to 3 374 | move 7 from 2 to 3 375 | move 2 from 1 to 5 376 | move 1 from 1 to 3 377 | move 1 from 8 to 1 378 | move 1 from 5 to 9 379 | move 1 from 9 to 6 380 | move 1 from 8 to 7 381 | move 1 from 5 to 3 382 | move 1 from 6 to 7 383 | move 2 from 8 to 1 384 | move 8 from 3 to 2 385 | move 7 from 2 to 9 386 | move 6 from 8 to 6 387 | move 1 from 9 to 3 388 | move 2 from 6 to 4 389 | move 5 from 9 to 6 390 | move 7 from 6 to 2 391 | move 8 from 2 to 9 392 | move 2 from 1 to 9 393 | move 2 from 7 to 2 394 | move 2 from 4 to 8 395 | move 1 from 2 to 7 396 | move 25 from 3 to 7 397 | move 7 from 9 to 7 398 | move 1 from 2 to 5 399 | move 1 from 1 to 4 400 | move 3 from 8 to 1 401 | move 3 from 1 to 8 402 | move 3 from 7 to 8 403 | move 15 from 7 to 3 404 | move 10 from 8 to 3 405 | move 1 from 5 to 7 406 | move 1 from 8 to 5 407 | move 3 from 9 to 2 408 | move 1 from 6 to 4 409 | move 2 from 2 to 7 410 | move 1 from 2 to 5 411 | move 14 from 7 to 9 412 | move 1 from 6 to 2 413 | move 1 from 7 to 1 414 | move 1 from 5 to 4 415 | move 3 from 4 to 3 416 | move 1 from 7 to 6 417 | move 1 from 2 to 7 418 | move 1 from 1 to 2 419 | move 3 from 9 to 1 420 | move 1 from 6 to 2 421 | move 2 from 2 to 6 422 | move 17 from 3 to 6 423 | move 1 from 8 to 3 424 | move 1 from 5 to 4 425 | move 2 from 7 to 2 426 | move 9 from 9 to 8 427 | move 1 from 9 to 3 428 | move 16 from 3 to 2 429 | move 1 from 7 to 5 430 | move 5 from 6 to 5 431 | move 1 from 1 to 6 432 | move 1 from 4 to 1 433 | move 1 from 9 to 3 434 | move 9 from 8 to 6 435 | move 3 from 1 to 5 436 | move 1 from 9 to 1 437 | move 16 from 2 to 1 438 | move 2 from 2 to 7 439 | move 2 from 3 to 9 440 | move 2 from 7 to 4 441 | move 2 from 9 to 3 442 | move 3 from 3 to 5 443 | move 1 from 4 to 5 444 | move 1 from 4 to 2 445 | move 1 from 1 to 7 446 | move 1 from 7 to 1 447 | move 1 from 3 to 6 448 | move 2 from 5 to 1 449 | move 3 from 6 to 2 450 | move 2 from 5 to 8 451 | move 8 from 5 to 4 452 | move 1 from 5 to 3 453 | move 1 from 3 to 2 454 | move 1 from 8 to 3 455 | move 1 from 3 to 8 456 | move 4 from 1 to 7 457 | move 9 from 1 to 7 458 | move 6 from 1 to 8 459 | move 3 from 7 to 4 460 | move 7 from 6 to 7 461 | move 11 from 4 to 3 462 | move 2 from 3 to 8 463 | move 8 from 3 to 8 464 | move 4 from 6 to 1 465 | move 1 from 7 to 4 466 | move 2 from 1 to 2 467 | move 8 from 7 to 2 468 | move 1 from 4 to 8 469 | move 10 from 8 to 2 470 | move 2 from 6 to 1 471 | move 1 from 1 to 4 472 | move 1 from 4 to 8 473 | move 2 from 1 to 4 474 | move 6 from 6 to 5 475 | move 1 from 1 to 9 476 | move 2 from 6 to 8 477 | move 1 from 4 to 5 478 | move 1 from 6 to 9 479 | move 4 from 8 to 9 480 | move 1 from 7 to 1 481 | move 6 from 8 to 6 482 | move 1 from 6 to 1 483 | move 1 from 4 to 9 484 | move 2 from 9 to 5 485 | move 5 from 5 to 9 486 | move 8 from 9 to 5 487 | move 2 from 8 to 5 488 | move 3 from 6 to 9 489 | move 8 from 5 to 7 490 | move 5 from 5 to 6 491 | move 1 from 9 to 2 492 | move 1 from 3 to 1 493 | move 1 from 6 to 7 494 | move 1 from 5 to 6 495 | move 24 from 2 to 4 496 | move 3 from 9 to 7 497 | move 16 from 4 to 5 498 | move 2 from 1 to 3 499 | move 12 from 5 to 6 500 | move 1 from 9 to 5 501 | move 4 from 5 to 9 502 | move 1 from 1 to 6 503 | move 1 from 5 to 2 504 | move 2 from 9 to 8 505 | move 1 from 8 to 1 506 | move 5 from 4 to 5 507 | move 2 from 3 to 5 508 | move 1 from 8 to 3 509 | move 1 from 1 to 6 510 | move 3 from 5 to 7 511 | move 1 from 9 to 1 512 | move 1 from 2 to 8 -------------------------------------------------------------------------------- /day_07/input.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir cmwrq 4 | dir ftrccld 5 | dir jjlbmtw 6 | dir jpncfpb 7 | dir mddr 8 | dir mthvntdd 9 | 55644 pjts.dzh 10 | dir ptzsl 11 | dir wmqc 12 | $ cd cmwrq 13 | $ ls 14 | dir dtbzzl 15 | dir pjnghbm 16 | 16144 rvs 17 | 50956 swngfrsj.pcj 18 | dir vhvn 19 | dir vrt 20 | dir zgrjmtcq 21 | $ cd dtbzzl 22 | $ ls 23 | 42503 ljhpmvd.zqf 24 | dir wwpnn 25 | $ cd wwpnn 26 | $ ls 27 | 58541 jjdgzwnq 28 | dir lwqgsbg 29 | dir nztw 30 | dir rdtjztmt 31 | 101609 sqqpcvq.llm 32 | dir ssdlqcrw 33 | $ cd lwqgsbg 34 | $ ls 35 | 207528 cpqhb.jsf 36 | 38543 cqjgspw 37 | dir dtbzzl 38 | 106337 dtbzzl.njz 39 | 302201 pdv.ppg 40 | dir pjts 41 | 175215 pvczm.cfw 42 | dir sbvljdh 43 | $ cd dtbzzl 44 | $ ls 45 | 252091 vhvn.zqv 46 | $ cd .. 47 | $ cd pjts 48 | $ ls 49 | 155681 bdbfjbgt.rwg 50 | 219192 dtcz.gqt 51 | $ cd .. 52 | $ cd sbvljdh 53 | $ ls 54 | dir rdrqc 55 | dir rtfpcswj 56 | $ cd rdrqc 57 | $ ls 58 | 242263 pjts.mbt 59 | $ cd .. 60 | $ cd rtfpcswj 61 | $ ls 62 | 228044 ssgcjt.twr 63 | $ cd .. 64 | $ cd .. 65 | $ cd .. 66 | $ cd nztw 67 | $ ls 68 | 30777 vqfsh.smp 69 | $ cd .. 70 | $ cd rdtjztmt 71 | $ ls 72 | 276602 pvczm.cfw 73 | dir rzbb 74 | 305089 ssdlqcrw.dgb 75 | $ cd rzbb 76 | $ ls 77 | 155253 pvczm.cfw 78 | $ cd .. 79 | $ cd .. 80 | $ cd ssdlqcrw 81 | $ ls 82 | 22423 vqfsh.smp 83 | $ cd .. 84 | $ cd .. 85 | $ cd .. 86 | $ cd pjnghbm 87 | $ ls 88 | 189296 ctqfg.ljd 89 | dir dtbzzl 90 | dir pjts 91 | 205394 ssdlqcrw.lgv 92 | $ cd dtbzzl 93 | $ ls 94 | 239152 fbb.gtn 95 | dir hlw 96 | 39308 hsnbffzf.qvc 97 | 211316 nhm.zhz 98 | dir nztw 99 | dir pvsjpn 100 | 230237 twjq 101 | $ cd hlw 102 | $ ls 103 | dir lfqqrp 104 | dir nztw 105 | $ cd lfqqrp 106 | $ ls 107 | dir mbmfpz 108 | dir mdhfdlw 109 | dir pjts 110 | dir qzs 111 | dir ssdlqcrw 112 | $ cd mbmfpz 113 | $ ls 114 | dir fsrbwl 115 | dir lsmpw 116 | $ cd fsrbwl 117 | $ ls 118 | 154657 ftlc.zbr 119 | dir ltsj 120 | 228929 pvczm.cfw 121 | dir ssdlqcrw 122 | 234216 tdl 123 | $ cd ltsj 124 | $ ls 125 | 51204 vmq.sjg 126 | $ cd .. 127 | $ cd ssdlqcrw 128 | $ ls 129 | 64928 nztw.gpn 130 | $ cd .. 131 | $ cd .. 132 | $ cd lsmpw 133 | $ ls 134 | 61867 dtbzzl.dgj 135 | $ cd .. 136 | $ cd .. 137 | $ cd mdhfdlw 138 | $ ls 139 | 92462 dtbzzl.jmq 140 | 239442 tczcgf.zwj 141 | $ cd .. 142 | $ cd pjts 143 | $ ls 144 | 144464 dtbzzl.lnz 145 | dir pjts 146 | 118500 swgt.smz 147 | $ cd pjts 148 | $ ls 149 | 173783 dvztnn 150 | 103088 jlv.pgh 151 | 39332 nhm.zhz 152 | 266947 pppfcg 153 | $ cd .. 154 | $ cd .. 155 | $ cd qzs 156 | $ ls 157 | 11155 cpqhb.jsf 158 | $ cd .. 159 | $ cd ssdlqcrw 160 | $ ls 161 | 192414 gcwqcwrf.vmb 162 | $ cd .. 163 | $ cd .. 164 | $ cd nztw 165 | $ ls 166 | 313009 nwt 167 | $ cd .. 168 | $ cd .. 169 | $ cd nztw 170 | $ ls 171 | 280535 dtbzzl.grj 172 | 269725 ssdlqcrw.tqs 173 | $ cd .. 174 | $ cd pvsjpn 175 | $ ls 176 | 105150 jvjb.mdd 177 | 142501 nztw.cvp 178 | $ cd .. 179 | $ cd .. 180 | $ cd pjts 181 | $ ls 182 | dir btc 183 | dir tpwcmvch 184 | 259357 vqfsh.smp 185 | $ cd btc 186 | $ ls 187 | 5264 gdjpql.wqr 188 | $ cd .. 189 | $ cd tpwcmvch 190 | $ ls 191 | 141657 jjdgzwnq 192 | 15650 nhm.zhz 193 | dir nlrq 194 | 182100 qgf.qgj 195 | 302332 qshf 196 | 244799 vhvn 197 | dir wvnqzjf 198 | $ cd nlrq 199 | $ ls 200 | dir dtbzzl 201 | 207207 gnd.vmb 202 | $ cd dtbzzl 203 | $ ls 204 | 271143 wjbzmc 205 | $ cd .. 206 | $ cd .. 207 | $ cd wvnqzjf 208 | $ ls 209 | 64128 mtzc.rqb 210 | $ cd .. 211 | $ cd .. 212 | $ cd .. 213 | $ cd .. 214 | $ cd vhvn 215 | $ ls 216 | 187526 vqfsh.smp 217 | $ cd .. 218 | $ cd vrt 219 | $ ls 220 | dir drrnm 221 | dir fqr 222 | 270995 nztw.mfg 223 | 137476 vqfsh.smp 224 | $ cd drrnm 225 | $ ls 226 | 250912 pvczm.cfw 227 | $ cd .. 228 | $ cd fqr 229 | $ ls 230 | 229272 nszfcq 231 | dir nztw 232 | 170643 phh.pdl 233 | $ cd nztw 234 | $ ls 235 | dir bqf 236 | $ cd bqf 237 | $ ls 238 | 9998 vqfsh.smp 239 | $ cd .. 240 | $ cd .. 241 | $ cd .. 242 | $ cd .. 243 | $ cd zgrjmtcq 244 | $ ls 245 | 109025 vhvn 246 | $ cd .. 247 | $ cd .. 248 | $ cd ftrccld 249 | $ ls 250 | dir dtbzzl 251 | dir fvmh 252 | dir fwztt 253 | 22306 jngjc.mpd 254 | 190320 lnr.jhn 255 | dir lsvvn 256 | 295676 nztw 257 | 135025 nztw.ssc 258 | dir pjts 259 | dir qglhlggq 260 | dir rslphgp 261 | 247764 ssdlqcrw.jnm 262 | dir vhvn 263 | $ cd dtbzzl 264 | $ ls 265 | dir fgwh 266 | $ cd fgwh 267 | $ ls 268 | dir dpdvswq 269 | $ cd dpdvswq 270 | $ ls 271 | dir jsstq 272 | 248465 vhvn 273 | $ cd jsstq 274 | $ ls 275 | 252517 nztw 276 | $ cd .. 277 | $ cd .. 278 | $ cd .. 279 | $ cd .. 280 | $ cd fvmh 281 | $ ls 282 | dir djcn 283 | dir dtbzzl 284 | 303052 fbnnfsbp.zzg 285 | 77238 mdpcghq.nls 286 | dir mvppnhr 287 | 238683 ptw 288 | dir zdqlwnc 289 | $ cd djcn 290 | $ ls 291 | 8600 jjdgzwnq 292 | $ cd .. 293 | $ cd dtbzzl 294 | $ ls 295 | dir sppdjcm 296 | dir vtnzqtvj 297 | $ cd sppdjcm 298 | $ ls 299 | 237925 dvfctpg.zbn 300 | dir fghb 301 | dir pfjdsm 302 | dir pjts 303 | 314661 zfchfq 304 | $ cd fghb 305 | $ ls 306 | 280081 cpqhb.jsf 307 | 88448 wbcpnnvs.sjc 308 | $ cd .. 309 | $ cd pfjdsm 310 | $ ls 311 | 256877 bssmgf 312 | 127978 drwttw 313 | 103674 hznr.hjg 314 | $ cd .. 315 | $ cd pjts 316 | $ ls 317 | 191709 qhwwpzn.dsc 318 | $ cd .. 319 | $ cd .. 320 | $ cd vtnzqtvj 321 | $ ls 322 | dir rrl 323 | $ cd rrl 324 | $ ls 325 | 281036 jjdgzwnq 326 | dir lzlswv 327 | dir sjsqnvq 328 | 245082 ssdlqcrw.smq 329 | $ cd lzlswv 330 | $ ls 331 | dir dmh 332 | $ cd dmh 333 | $ ls 334 | 41234 hlhgn.mvr 335 | 233542 tgv.csn 336 | $ cd .. 337 | $ cd .. 338 | $ cd sjsqnvq 339 | $ ls 340 | 221327 qjncmbn 341 | $ cd .. 342 | $ cd .. 343 | $ cd .. 344 | $ cd .. 345 | $ cd mvppnhr 346 | $ ls 347 | dir ldwv 348 | 176153 nztw 349 | dir rmdjdqvl 350 | dir tmj 351 | dir vhvn 352 | $ cd ldwv 353 | $ ls 354 | 161179 mjsm 355 | $ cd .. 356 | $ cd rmdjdqvl 357 | $ ls 358 | dir gnztqmhv 359 | dir lpmhfr 360 | dir tphjm 361 | $ cd gnztqmhv 362 | $ ls 363 | 176043 qlds.mpq 364 | $ cd .. 365 | $ cd lpmhfr 366 | $ ls 367 | dir jrrdsd 368 | $ cd jrrdsd 369 | $ ls 370 | 114477 vqfsh.smp 371 | $ cd .. 372 | $ cd .. 373 | $ cd tphjm 374 | $ ls 375 | 74809 dcfmjn 376 | $ cd .. 377 | $ cd .. 378 | $ cd tmj 379 | $ ls 380 | 252001 cpqhb.jsf 381 | 49666 pqpq 382 | 139885 qpj.wpb 383 | 116339 vqfsh.smp 384 | $ cd .. 385 | $ cd vhvn 386 | $ ls 387 | 89397 dtbzzl.hvp 388 | 105454 pvczm.cfw 389 | 280352 zdzm 390 | $ cd .. 391 | $ cd .. 392 | $ cd zdqlwnc 393 | $ ls 394 | dir fbhcv 395 | 8676 jjdgzwnq 396 | 99885 nhm.zhz 397 | 234563 pjts.gdj 398 | dir rsdltnvc 399 | $ cd fbhcv 400 | $ ls 401 | 71695 hrzzgwqt 402 | 296401 vqfsh.smp 403 | $ cd .. 404 | $ cd rsdltnvc 405 | $ ls 406 | 41623 gcvtqf 407 | 233747 wdcssvgh.vfs 408 | $ cd .. 409 | $ cd .. 410 | $ cd .. 411 | $ cd fwztt 412 | $ ls 413 | 96594 jjdgzwnq 414 | 245415 mtp.szl 415 | 129782 pjts.jjr 416 | 308104 pvczm.cfw 417 | dir ssdlqcrw 418 | 155109 vhvn.smj 419 | dir vvzsr 420 | $ cd ssdlqcrw 421 | $ ls 422 | dir bzd 423 | 292228 dtbzzl.tdb 424 | 107505 ssdlqcrw 425 | 181384 tfnrpsd 426 | $ cd bzd 427 | $ ls 428 | 84648 brdc 429 | 171457 vhvn 430 | $ cd .. 431 | $ cd .. 432 | $ cd vvzsr 433 | $ ls 434 | dir bcdqrs 435 | 147437 jjdgzwnq 436 | dir ssdlqcrw 437 | 197054 ssdlqcrw.dpz 438 | dir vhvn 439 | dir wthshgg 440 | $ cd bcdqrs 441 | $ ls 442 | 297401 pspd.dlq 443 | 136072 pvczm.cfw 444 | $ cd .. 445 | $ cd ssdlqcrw 446 | $ ls 447 | 293104 dtbzzl.pdh 448 | $ cd .. 449 | $ cd vhvn 450 | $ ls 451 | 178932 gvrht.cbm 452 | $ cd .. 453 | $ cd wthshgg 454 | $ ls 455 | dir dppwvtmp 456 | dir ljgszd 457 | 88822 pcmw.bbq 458 | 255776 pvczm.cfw 459 | 163501 ssdlqcrw 460 | dir vbjsmgp 461 | dir vzqc 462 | dir zmpdrpd 463 | $ cd dppwvtmp 464 | $ ls 465 | 45608 dtbzzl.lfq 466 | 164648 gdch.bzp 467 | 65225 nhm.zhz 468 | $ cd .. 469 | $ cd ljgszd 470 | $ ls 471 | 125627 vqfsh.smp 472 | $ cd .. 473 | $ cd vbjsmgp 474 | $ ls 475 | 236951 zpbgb.zmv 476 | $ cd .. 477 | $ cd vzqc 478 | $ ls 479 | 234565 fjfpbjjp 480 | 254986 jjdgzwnq 481 | 164495 nztw.qhz 482 | dir vhvn 483 | $ cd vhvn 484 | $ ls 485 | 199196 nztw 486 | $ cd .. 487 | $ cd .. 488 | $ cd zmpdrpd 489 | $ ls 490 | 123210 bznqq.dbv 491 | 141163 jjdgzwnq 492 | 302352 wjf.tdv 493 | 92016 wljnwsh 494 | $ cd .. 495 | $ cd .. 496 | $ cd .. 497 | $ cd .. 498 | $ cd lsvvn 499 | $ ls 500 | 282867 phv.ncc 501 | $ cd .. 502 | $ cd pjts 503 | $ ls 504 | 40866 jjdgzwnq 505 | $ cd .. 506 | $ cd qglhlggq 507 | $ ls 508 | 19577 dtbzzl.ngb 509 | 21171 jjdgzwnq 510 | 136074 pvczm.cfw 511 | 212428 rlpjjf.lvh 512 | dir vhvn 513 | 274669 wcqlws.ndv 514 | dir wpvq 515 | $ cd vhvn 516 | $ ls 517 | 183301 cbppfp.vbc 518 | 84069 cqnz 519 | dir dtbzzl 520 | dir mdng 521 | 126627 pjts.pvp 522 | dir ptqq 523 | 47594 pvczm.cfw 524 | 154978 qlnnfbvd 525 | $ cd dtbzzl 526 | $ ls 527 | 50385 ccgbrdmb.hrr 528 | 22427 rzlwl.jbt 529 | $ cd .. 530 | $ cd mdng 531 | $ ls 532 | dir gdqqtvnp 533 | 224013 gtv.tbz 534 | 121884 jjdgzwnq 535 | dir nrmhpblm 536 | 142950 nztw 537 | 9710 pvczm.cfw 538 | dir vhvn 539 | $ cd gdqqtvnp 540 | $ ls 541 | 292349 vhvn.nfr 542 | $ cd .. 543 | $ cd nrmhpblm 544 | $ ls 545 | 52703 jbvd.mlc 546 | 78268 pfns.lpr 547 | $ cd .. 548 | $ cd vhvn 549 | $ ls 550 | 274549 pjts 551 | $ cd .. 552 | $ cd .. 553 | $ cd ptqq 554 | $ ls 555 | 257967 jqppq.lgb 556 | 166450 nhm.zhz 557 | $ cd .. 558 | $ cd .. 559 | $ cd wpvq 560 | $ ls 561 | 173437 vqfsh.smp 562 | $ cd .. 563 | $ cd .. 564 | $ cd rslphgp 565 | $ ls 566 | 29192 pvczm.cfw 567 | 18984 ttpfnqvn.cdr 568 | 302301 vqfsh.smp 569 | 291211 vsvtc.wwf 570 | $ cd .. 571 | $ cd vhvn 572 | $ ls 573 | dir ssdlqcrw 574 | $ cd ssdlqcrw 575 | $ ls 576 | 76864 jpwvws.fwv 577 | 26365 nztw.css 578 | 185966 vqfsh.smp 579 | $ cd .. 580 | $ cd .. 581 | $ cd .. 582 | $ cd jjlbmtw 583 | $ ls 584 | 211239 ctfhmm.ssv 585 | 230020 nztw 586 | 109641 sqtjn 587 | $ cd .. 588 | $ cd jpncfpb 589 | $ ls 590 | dir hjgwcmh 591 | 286054 pcffhsw.bdm 592 | 260831 pvczm.cfw 593 | dir vhvn 594 | $ cd hjgwcmh 595 | $ ls 596 | 92277 bbjhc 597 | dir fmst 598 | dir gzjq 599 | $ cd fmst 600 | $ ls 601 | 105833 cpqhb.jsf 602 | 315858 nhm.zhz 603 | 233459 nztw 604 | $ cd .. 605 | $ cd gzjq 606 | $ ls 607 | dir prjqfwf 608 | dir ssdlqcrw 609 | $ cd prjqfwf 610 | $ ls 611 | 151003 jnmgdb.rhn 612 | $ cd .. 613 | $ cd ssdlqcrw 614 | $ ls 615 | 103688 cpqhb.jsf 616 | $ cd .. 617 | $ cd .. 618 | $ cd .. 619 | $ cd vhvn 620 | $ ls 621 | 14901 cpqhb.jsf 622 | 98212 tztzq 623 | $ cd .. 624 | $ cd .. 625 | $ cd mddr 626 | $ ls 627 | dir qpfjp 628 | $ cd qpfjp 629 | $ ls 630 | dir cfhv 631 | $ cd cfhv 632 | $ ls 633 | dir ssdlqcrw 634 | $ cd ssdlqcrw 635 | $ ls 636 | 134280 vvnpvrqb.hdv 637 | $ cd .. 638 | $ cd .. 639 | $ cd .. 640 | $ cd .. 641 | $ cd mthvntdd 642 | $ ls 643 | dir bcdcz 644 | dir cngbf 645 | 62389 cwtvl 646 | dir mqjjbq 647 | dir nhblb 648 | 6743 pvczm.cfw 649 | dir ssdlqcrw 650 | dir ttvgr 651 | dir vdmm 652 | dir wnhnwjm 653 | dir zdvbsb 654 | $ cd bcdcz 655 | $ ls 656 | 213688 dtbzzl.hsv 657 | dir lbvbc 658 | 100222 nndbhrf 659 | 115627 rqnsfbz.rmf 660 | dir tvgclpsc 661 | 258672 vqfsh.smp 662 | 163927 whgmd 663 | $ cd lbvbc 664 | $ ls 665 | 224836 fpfpwtf.zfz 666 | 103806 nztw 667 | $ cd .. 668 | $ cd tvgclpsc 669 | $ ls 670 | 76900 cpqhb.jsf 671 | 282820 qtffdmsg 672 | $ cd .. 673 | $ cd .. 674 | $ cd cngbf 675 | $ ls 676 | dir hstph 677 | 12089 jqvnttq.dsh 678 | 38052 nztw.sqj 679 | dir qrnpjz 680 | $ cd hstph 681 | $ ls 682 | 172788 pjts.qmt 683 | $ cd .. 684 | $ cd qrnpjz 685 | $ ls 686 | dir blzc 687 | dir rvl 688 | dir zvhtzqqc 689 | $ cd blzc 690 | $ ls 691 | 108342 nhm.zhz 692 | $ cd .. 693 | $ cd rvl 694 | $ ls 695 | dir bcrf 696 | dir sjbr 697 | $ cd bcrf 698 | $ ls 699 | 182498 cpqhb.jsf 700 | dir dcb 701 | 14228 ggsq 702 | dir gnhvtgm 703 | $ cd dcb 704 | $ ls 705 | dir zlgjzcjv 706 | $ cd zlgjzcjv 707 | $ ls 708 | 18316 cpqhb.jsf 709 | $ cd .. 710 | $ cd .. 711 | $ cd gnhvtgm 712 | $ ls 713 | 110236 nhm.zhz 714 | $ cd .. 715 | $ cd .. 716 | $ cd sjbr 717 | $ ls 718 | 133009 cscbp 719 | 315907 vtpmnwt 720 | $ cd .. 721 | $ cd .. 722 | $ cd zvhtzqqc 723 | $ ls 724 | dir fglfpn 725 | dir gtzrq 726 | dir hfgdcf 727 | 274977 ltbzhjn 728 | dir msc 729 | dir ssdlqcrw 730 | $ cd fglfpn 731 | $ ls 732 | 39153 dvhjpfc 733 | $ cd .. 734 | $ cd gtzrq 735 | $ ls 736 | 60625 sqljdlpz.wpw 737 | $ cd .. 738 | $ cd hfgdcf 739 | $ ls 740 | 36016 qdvnn.pbt 741 | $ cd .. 742 | $ cd msc 743 | $ ls 744 | 56601 cpqhb.jsf 745 | dir hrz 746 | dir vlhllqz 747 | $ cd hrz 748 | $ ls 749 | 241511 fhngt.mlb 750 | 286505 nhm.zhz 751 | $ cd .. 752 | $ cd vlhllqz 753 | $ ls 754 | 157880 nhm.zhz 755 | $ cd .. 756 | $ cd .. 757 | $ cd ssdlqcrw 758 | $ ls 759 | 121507 dssrvr 760 | 295897 lvtwlb.whn 761 | 12047 pjts.gqc 762 | $ cd .. 763 | $ cd .. 764 | $ cd .. 765 | $ cd .. 766 | $ cd mqjjbq 767 | $ ls 768 | 157818 blbmb.fcv 769 | 119103 ccppbmqb.pbt 770 | 141463 cpqhb.jsf 771 | 197900 drhmws.fdd 772 | dir fmvp 773 | dir rhldnjlt 774 | 175029 vqfsh.smp 775 | $ cd fmvp 776 | $ ls 777 | dir dhnn 778 | dir dlcvwqw 779 | 131432 hnv.tlr 780 | dir jzqt 781 | 98127 nhm.zhz 782 | dir nvsdbjj 783 | dir pjts 784 | 9179 pvczm.cfw 785 | 121310 vqfsh.smp 786 | $ cd dhnn 787 | $ ls 788 | 173921 qcjsdg.zfg 789 | 58654 vhvn.csb 790 | $ cd .. 791 | $ cd dlcvwqw 792 | $ ls 793 | 285116 zjb 794 | $ cd .. 795 | $ cd jzqt 796 | $ ls 797 | 104478 clmzwnf 798 | 299622 cpqhb.jsf 799 | 301236 jjdgzwnq 800 | dir nsvlqq 801 | 136737 vhvn 802 | dir vmp 803 | 12932 wrd.jsz 804 | $ cd nsvlqq 805 | $ ls 806 | 111712 dtbzzl.htn 807 | 213593 hvzlmtj.ztr 808 | $ cd .. 809 | $ cd vmp 810 | $ ls 811 | 104275 jjdgzwnq 812 | $ cd .. 813 | $ cd .. 814 | $ cd nvsdbjj 815 | $ ls 816 | 180999 jjdgzwnq 817 | 219819 vhvn 818 | $ cd .. 819 | $ cd pjts 820 | $ ls 821 | 111715 npzn 822 | $ cd .. 823 | $ cd .. 824 | $ cd rhldnjlt 825 | $ ls 826 | dir ffhcbvmf 827 | dir vprlq 828 | $ cd ffhcbvmf 829 | $ ls 830 | 247668 cpqhb.jsf 831 | $ cd .. 832 | $ cd vprlq 833 | $ ls 834 | 168090 jmmtz.fzt 835 | 68360 nhm.zhz 836 | 304580 vqfsh.smp 837 | $ cd .. 838 | $ cd .. 839 | $ cd .. 840 | $ cd nhblb 841 | $ ls 842 | 154794 hrgsrbnj.tch 843 | dir nfwl 844 | dir ptc 845 | dir rng 846 | 50110 swtt.tct 847 | dir vhvn 848 | dir vlj 849 | $ cd nfwl 850 | $ ls 851 | dir lqs 852 | dir mlvnlz 853 | $ cd lqs 854 | $ ls 855 | dir mbcft 856 | dir ntmvt 857 | dir nztw 858 | $ cd mbcft 859 | $ ls 860 | 78188 bdnr 861 | 194668 pjts 862 | $ cd .. 863 | $ cd ntmvt 864 | $ ls 865 | 75647 nhm.zhz 866 | 186651 scsvrqpf.jhb 867 | $ cd .. 868 | $ cd nztw 869 | $ ls 870 | 164920 vqfsh.smp 871 | $ cd .. 872 | $ cd .. 873 | $ cd mlvnlz 874 | $ ls 875 | 289891 wjf 876 | $ cd .. 877 | $ cd .. 878 | $ cd ptc 879 | $ ls 880 | 190002 pjts.vmh 881 | $ cd .. 882 | $ cd rng 883 | $ ls 884 | 39093 nhm.zhz 885 | $ cd .. 886 | $ cd vhvn 887 | $ ls 888 | 275854 hbv 889 | $ cd .. 890 | $ cd vlj 891 | $ ls 892 | dir qqqrm 893 | 203390 ssdlqcrw 894 | $ cd qqqrm 895 | $ ls 896 | dir wcpllh 897 | $ cd wcpllh 898 | $ ls 899 | dir pwg 900 | $ cd pwg 901 | $ ls 902 | 19102 dtbzzl.qvp 903 | $ cd .. 904 | $ cd .. 905 | $ cd .. 906 | $ cd .. 907 | $ cd .. 908 | $ cd ssdlqcrw 909 | $ ls 910 | 181610 vqfsh.smp 911 | $ cd .. 912 | $ cd ttvgr 913 | $ ls 914 | dir vpcpd 915 | $ cd vpcpd 916 | $ ls 917 | 28102 mbb.szv 918 | 304017 rshrzjhn 919 | $ cd .. 920 | $ cd .. 921 | $ cd vdmm 922 | $ ls 923 | 95079 tssjcd.lfg 924 | $ cd .. 925 | $ cd wnhnwjm 926 | $ ls 927 | 67931 mmhcgsc.zjf 928 | 22062 nqpzsf.ccc 929 | 219285 trr.vcn 930 | $ cd .. 931 | $ cd zdvbsb 932 | $ ls 933 | 293736 dtbzzl.ftj 934 | $ cd .. 935 | $ cd .. 936 | $ cd ptzsl 937 | $ ls 938 | 26404 jnsdzmbd 939 | $ cd .. 940 | $ cd wmqc 941 | $ ls 942 | dir dtbzzl 943 | dir hdzmzc 944 | dir nmmpwqvz 945 | dir qjnm 946 | $ cd dtbzzl 947 | $ ls 948 | dir hpzgnb 949 | $ cd hpzgnb 950 | $ ls 951 | 189696 sbmdrbm 952 | $ cd .. 953 | $ cd .. 954 | $ cd hdzmzc 955 | $ ls 956 | 143510 dtbzzl.dmp 957 | $ cd .. 958 | $ cd nmmpwqvz 959 | $ ls 960 | 276725 nhm.zhz 961 | $ cd .. 962 | $ cd qjnm 963 | $ ls 964 | 202264 cpqhb.jsf -------------------------------------------------------------------------------- /day_04/input.txt: -------------------------------------------------------------------------------- 1 | 7-96,6-95 2 | 36-41,35-40 3 | 35-84,83-91 4 | 95-96,5-95 5 | 3-3,4-99 6 | 12-21,21-22 7 | 10-28,10-28 8 | 6-11,10-12 9 | 12-91,76-98 10 | 17-69,18-69 11 | 26-81,7-27 12 | 26-42,57-80 13 | 32-38,33-38 14 | 4-83,5-83 15 | 33-85,34-86 16 | 14-95,6-78 17 | 79-84,78-87 18 | 12-61,11-62 19 | 56-92,55-92 20 | 34-63,9-34 21 | 33-44,33-85 22 | 5-17,16-26 23 | 21-43,21-32 24 | 12-60,59-60 25 | 10-48,10-49 26 | 94-94,71-94 27 | 45-46,24-46 28 | 81-97,82-98 29 | 5-27,27-57 30 | 3-96,2-22 31 | 5-92,2-97 32 | 53-87,76-90 33 | 68-83,82-82 34 | 55-67,55-73 35 | 39-79,78-78 36 | 81-86,87-97 37 | 3-25,2-67 38 | 50-63,62-62 39 | 5-96,5-97 40 | 27-88,28-88 41 | 19-53,20-53 42 | 55-89,55-90 43 | 43-46,43-99 44 | 82-95,56-96 45 | 8-57,8-8 46 | 90-95,2-90 47 | 56-78,34-81 48 | 53-81,54-81 49 | 20-30,9-62 50 | 12-83,11-16 51 | 64-65,63-69 52 | 15-95,15-94 53 | 6-94,4-93 54 | 36-93,8-92 55 | 67-74,68-74 56 | 4-89,5-89 57 | 23-24,22-23 58 | 44-53,45-80 59 | 43-60,43-83 60 | 61-69,62-78 61 | 77-77,25-77 62 | 43-65,43-66 63 | 12-65,13-84 64 | 54-56,54-97 65 | 13-34,33-60 66 | 20-55,55-56 67 | 34-93,35-92 68 | 26-85,27-96 69 | 51-97,9-97 70 | 18-41,17-40 71 | 3-14,14-80 72 | 55-66,8-56 73 | 4-89,64-98 74 | 20-98,20-63 75 | 1-16,15-22 76 | 20-93,41-92 77 | 9-86,8-10 78 | 5-27,27-28 79 | 29-51,30-48 80 | 44-64,44-44 81 | 29-96,2-96 82 | 1-98,13-97 83 | 6-84,18-84 84 | 28-81,27-72 85 | 7-95,6-95 86 | 43-84,78-84 87 | 2-62,35-98 88 | 46-88,9-88 89 | 11-19,10-18 90 | 21-81,22-89 91 | 98-99,78-98 92 | 26-57,25-57 93 | 12-31,10-30 94 | 31-84,32-85 95 | 93-93,91-93 96 | 10-89,8-76 97 | 6-36,7-36 98 | 51-96,95-99 99 | 14-32,5-17 100 | 23-37,34-38 101 | 14-15,22-82 102 | 95-96,72-95 103 | 38-52,53-53 104 | 25-94,25-96 105 | 38-74,37-74 106 | 73-94,41-73 107 | 72-85,35-84 108 | 15-98,14-16 109 | 81-94,82-94 110 | 85-89,85-87 111 | 3-87,3-83 112 | 84-93,4-91 113 | 42-57,42-50 114 | 42-80,23-42 115 | 18-26,18-27 116 | 44-58,44-99 117 | 35-68,3-67 118 | 40-97,41-53 119 | 11-99,12-12 120 | 7-51,12-59 121 | 13-71,68-71 122 | 5-12,4-97 123 | 8-20,20-79 124 | 13-91,12-14 125 | 33-62,18-32 126 | 3-94,5-94 127 | 26-98,26-93 128 | 31-38,30-85 129 | 13-83,14-82 130 | 6-74,73-74 131 | 73-73,45-62 132 | 38-38,38-38 133 | 9-21,4-20 134 | 14-60,13-83 135 | 83-90,83-89 136 | 73-73,6-74 137 | 1-3,3-94 138 | 3-84,3-85 139 | 61-90,81-97 140 | 93-93,23-94 141 | 31-81,81-81 142 | 26-76,75-75 143 | 95-96,94-94 144 | 70-72,71-89 145 | 95-95,4-95 146 | 10-70,9-11 147 | 3-99,4-98 148 | 26-99,26-92 149 | 77-95,78-90 150 | 47-82,48-83 151 | 4-83,82-88 152 | 51-51,42-50 153 | 10-86,11-96 154 | 9-46,39-49 155 | 20-78,20-79 156 | 1-62,2-61 157 | 57-59,58-75 158 | 4-90,28-90 159 | 4-4,4-52 160 | 34-81,35-96 161 | 32-68,67-83 162 | 83-87,84-88 163 | 71-96,71-71 164 | 61-96,95-99 165 | 3-99,1-4 166 | 13-94,12-95 167 | 13-86,14-95 168 | 36-89,35-88 169 | 8-12,12-96 170 | 34-55,33-55 171 | 43-55,56-95 172 | 38-39,7-38 173 | 3-48,47-98 174 | 86-86,5-86 175 | 4-64,4-4 176 | 80-97,41-98 177 | 16-16,30-54 178 | 3-94,4-94 179 | 16-90,15-91 180 | 7-19,7-84 181 | 64-79,8-79 182 | 29-94,94-95 183 | 25-86,24-85 184 | 91-95,90-93 185 | 3-54,3-96 186 | 4-92,6-95 187 | 14-14,14-70 188 | 65-82,83-83 189 | 5-80,18-35 190 | 63-88,44-52 191 | 3-65,1-21 192 | 34-87,49-49 193 | 92-94,48-93 194 | 3-96,3-95 195 | 52-70,51-75 196 | 64-64,7-64 197 | 20-53,21-63 198 | 3-9,6-10 199 | 49-93,50-94 200 | 38-97,38-94 201 | 91-95,92-96 202 | 38-43,38-45 203 | 73-74,19-73 204 | 26-83,82-83 205 | 71-72,71-71 206 | 6-97,6-98 207 | 67-93,90-94 208 | 39-97,40-97 209 | 10-33,33-40 210 | 35-84,34-93 211 | 5-72,73-73 212 | 15-98,14-66 213 | 24-66,25-84 214 | 23-49,11-50 215 | 35-79,34-36 216 | 15-78,16-94 217 | 87-89,6-88 218 | 5-8,7-39 219 | 13-82,2-5 220 | 70-70,14-70 221 | 47-86,87-94 222 | 10-98,9-94 223 | 2-63,1-62 224 | 26-67,26-26 225 | 67-68,66-68 226 | 51-58,49-57 227 | 29-44,41-45 228 | 33-95,34-95 229 | 4-18,4-17 230 | 75-89,75-75 231 | 12-87,11-87 232 | 29-60,31-61 233 | 35-37,36-44 234 | 11-62,10-73 235 | 12-36,12-30 236 | 67-67,67-77 237 | 9-96,10-98 238 | 15-71,12-72 239 | 87-90,15-86 240 | 37-76,37-77 241 | 74-75,73-74 242 | 32-71,31-72 243 | 14-29,29-60 244 | 47-94,36-79 245 | 19-89,16-84 246 | 84-85,77-84 247 | 38-80,7-80 248 | 24-36,25-52 249 | 47-48,47-48 250 | 95-96,34-95 251 | 72-80,72-76 252 | 13-75,12-75 253 | 6-89,5-88 254 | 61-90,21-90 255 | 98-98,1-99 256 | 41-84,41-52 257 | 11-44,11-43 258 | 25-97,25-96 259 | 36-99,35-89 260 | 24-53,23-56 261 | 12-12,12-91 262 | 52-88,52-87 263 | 5-10,5-9 264 | 94-96,7-95 265 | 10-94,9-93 266 | 30-32,31-60 267 | 83-83,9-83 268 | 73-97,60-72 269 | 60-81,38-81 270 | 20-59,19-21 271 | 1-93,74-93 272 | 64-86,17-85 273 | 37-40,37-70 274 | 53-87,24-54 275 | 21-81,20-81 276 | 53-93,54-94 277 | 35-73,39-74 278 | 5-74,6-73 279 | 13-97,24-98 280 | 80-87,81-90 281 | 13-41,42-42 282 | 40-40,40-61 283 | 30-53,31-52 284 | 73-97,74-95 285 | 77-93,78-94 286 | 42-81,43-98 287 | 29-49,18-57 288 | 93-99,97-99 289 | 12-64,12-99 290 | 25-99,46-98 291 | 5-70,11-88 292 | 7-65,7-99 293 | 32-89,31-88 294 | 6-92,1-61 295 | 1-9,10-56 296 | 57-96,97-98 297 | 51-97,98-99 298 | 15-81,14-81 299 | 9-28,10-51 300 | 4-99,4-98 301 | 49-55,49-49 302 | 51-77,43-78 303 | 18-55,19-54 304 | 22-22,22-85 305 | 38-83,37-82 306 | 20-89,4-13 307 | 58-89,1-90 308 | 94-95,55-94 309 | 38-83,69-93 310 | 29-53,52-52 311 | 9-99,10-99 312 | 37-67,37-66 313 | 39-97,19-49 314 | 10-96,9-63 315 | 23-98,75-98 316 | 15-96,15-93 317 | 5-10,9-56 318 | 7-84,3-8 319 | 84-86,73-85 320 | 64-84,39-75 321 | 23-41,22-23 322 | 18-20,16-18 323 | 69-82,69-97 324 | 42-76,43-74 325 | 27-29,16-29 326 | 52-63,55-64 327 | 22-91,96-99 328 | 13-74,12-75 329 | 76-81,76-80 330 | 23-54,20-53 331 | 85-87,47-86 332 | 23-33,22-30 333 | 3-19,19-19 334 | 36-43,43-53 335 | 2-89,1-99 336 | 9-31,8-15 337 | 92-94,64-94 338 | 36-88,35-70 339 | 70-73,68-72 340 | 44-70,33-38 341 | 40-91,40-99 342 | 77-77,15-76 343 | 21-37,30-77 344 | 82-86,61-82 345 | 3-77,3-92 346 | 49-60,15-60 347 | 9-85,65-86 348 | 2-13,12-65 349 | 39-48,47-49 350 | 37-77,37-37 351 | 53-54,54-81 352 | 43-72,42-71 353 | 4-4,5-85 354 | 54-85,85-85 355 | 39-79,40-80 356 | 9-83,8-84 357 | 12-79,3-80 358 | 62-92,61-90 359 | 4-64,62-63 360 | 82-82,9-82 361 | 31-85,43-86 362 | 5-51,4-52 363 | 95-98,98-99 364 | 61-89,89-90 365 | 5-57,30-69 366 | 6-46,6-50 367 | 6-43,12-42 368 | 33-58,32-57 369 | 55-55,56-91 370 | 92-94,42-93 371 | 3-98,98-98 372 | 12-68,3-13 373 | 77-77,78-78 374 | 33-92,91-91 375 | 12-13,13-44 376 | 2-93,1-3 377 | 42-49,41-47 378 | 16-86,3-16 379 | 13-26,26-32 380 | 1-95,46-95 381 | 36-58,37-38 382 | 15-17,18-98 383 | 57-83,70-84 384 | 23-85,5-23 385 | 50-99,8-96 386 | 76-76,75-82 387 | 4-97,98-98 388 | 3-24,11-30 389 | 27-27,13-28 390 | 25-55,23-24 391 | 26-48,26-86 392 | 15-42,14-42 393 | 50-61,50-62 394 | 39-96,3-39 395 | 28-52,43-56 396 | 20-90,61-91 397 | 79-99,99-99 398 | 8-23,8-29 399 | 12-78,12-77 400 | 39-41,27-40 401 | 8-90,5-7 402 | 8-32,20-33 403 | 21-89,22-90 404 | 3-36,3-99 405 | 37-60,36-63 406 | 28-42,5-42 407 | 44-57,40-56 408 | 52-69,43-69 409 | 9-10,8-9 410 | 1-98,1-99 411 | 8-21,3-12 412 | 1-82,1-56 413 | 16-16,5-15 414 | 37-56,38-75 415 | 20-53,19-31 416 | 54-97,97-97 417 | 11-93,10-38 418 | 18-60,7-41 419 | 96-99,8-97 420 | 42-63,63-92 421 | 12-51,50-51 422 | 45-45,44-87 423 | 62-63,16-63 424 | 36-81,36-36 425 | 4-45,1-4 426 | 12-14,7-13 427 | 64-64,60-64 428 | 68-68,67-68 429 | 9-95,94-98 430 | 56-72,55-74 431 | 34-57,34-46 432 | 33-69,33-70 433 | 65-78,64-66 434 | 3-64,63-65 435 | 6-79,6-69 436 | 66-93,93-94 437 | 55-56,36-55 438 | 8-96,7-95 439 | 33-83,33-93 440 | 54-96,55-96 441 | 1-73,5-90 442 | 76-78,61-77 443 | 10-90,9-94 444 | 27-81,16-57 445 | 85-96,86-96 446 | 48-48,11-49 447 | 47-63,48-48 448 | 18-27,18-48 449 | 40-93,40-46 450 | 31-44,32-43 451 | 21-41,34-40 452 | 44-53,44-54 453 | 28-95,7-95 454 | 2-97,1-97 455 | 20-97,96-99 456 | 71-82,20-72 457 | 4-32,4-98 458 | 56-56,23-55 459 | 10-74,73-73 460 | 22-78,21-77 461 | 57-65,56-65 462 | 45-95,12-87 463 | 62-67,62-77 464 | 33-78,31-79 465 | 33-51,32-50 466 | 21-99,26-87 467 | 11-94,98-99 468 | 15-49,15-50 469 | 2-9,10-83 470 | 39-39,16-40 471 | 15-73,40-74 472 | 98-99,6-98 473 | 46-84,46-81 474 | 9-97,9-96 475 | 56-66,36-55 476 | 65-81,66-93 477 | 14-97,70-96 478 | 47-92,46-92 479 | 12-46,13-19 480 | 5-57,25-86 481 | 44-84,45-83 482 | 14-39,31-39 483 | 46-68,32-69 484 | 13-90,17-80 485 | 14-64,15-78 486 | 3-5,4-57 487 | 6-7,13-57 488 | 75-75,6-75 489 | 46-92,45-64 490 | 17-45,16-45 491 | 8-94,52-99 492 | 94-95,6-94 493 | 37-76,36-75 494 | 55-56,6-65 495 | 40-64,28-50 496 | 12-20,21-95 497 | 28-50,47-51 498 | 99-99,7-98 499 | 37-63,33-89 500 | 14-99,13-13 501 | 7-80,7-19 502 | 19-47,18-18 503 | 37-46,47-47 504 | 17-73,4-86 505 | 9-43,10-43 506 | 26-71,25-26 507 | 14-91,1-10 508 | 31-58,30-31 509 | 44-44,22-45 510 | 59-59,59-60 511 | 9-9,9-64 512 | 44-65,45-46 513 | 10-96,96-96 514 | 2-52,2-84 515 | 35-36,35-35 516 | 94-95,81-94 517 | 12-89,13-90 518 | 4-86,4-93 519 | 13-96,4-96 520 | 52-54,53-72 521 | 6-90,5-91 522 | 10-34,10-75 523 | 22-31,22-30 524 | 23-97,9-96 525 | 7-91,83-95 526 | 8-12,8-18 527 | 34-39,35-38 528 | 2-22,3-87 529 | 6-15,7-54 530 | 37-84,36-62 531 | 51-93,51-94 532 | 4-4,5-97 533 | 17-55,33-56 534 | 48-53,50-89 535 | 17-90,18-99 536 | 8-8,29-60 537 | 18-40,32-87 538 | 3-88,3-89 539 | 14-14,15-53 540 | 55-62,55-61 541 | 5-96,58-97 542 | 50-59,50-98 543 | 37-86,38-86 544 | 1-56,11-68 545 | 65-75,66-69 546 | 66-84,73-92 547 | 99-99,2-99 548 | 99-99,13-99 549 | 65-88,6-93 550 | 13-89,90-90 551 | 41-64,40-63 552 | 21-66,22-66 553 | 57-92,56-93 554 | 57-78,78-92 555 | 94-98,11-94 556 | 10-53,27-54 557 | 37-42,38-42 558 | 17-97,1-17 559 | 39-86,39-85 560 | 6-6,7-43 561 | 20-55,21-55 562 | 93-93,7-94 563 | 73-74,75-95 564 | 29-88,28-72 565 | 40-90,22-86 566 | 75-75,20-76 567 | 15-72,4-74 568 | 69-82,64-81 569 | 21-23,21-59 570 | 56-70,68-73 571 | 9-94,95-95 572 | 4-6,8-53 573 | 7-20,19-45 574 | 25-41,26-40 575 | 62-72,61-74 576 | 79-95,49-79 577 | 2-96,1-95 578 | 19-33,25-59 579 | 8-90,7-91 580 | 28-91,90-92 581 | 11-20,19-88 582 | 5-30,6-10 583 | 8-99,8-8 584 | 90-99,94-99 585 | 19-77,19-94 586 | 37-58,37-63 587 | 23-44,3-45 588 | 6-98,5-98 589 | 9-42,6-9 590 | 66-75,71-76 591 | 58-87,86-88 592 | 40-48,40-49 593 | 17-24,17-48 594 | 3-97,2-32 595 | 37-88,37-89 596 | 3-89,5-25 597 | 19-61,13-20 598 | 5-67,3-6 599 | 72-73,15-72 600 | 36-78,75-79 601 | 6-92,7-91 602 | 28-97,27-98 603 | 56-56,14-56 604 | 2-92,1-92 605 | 1-7,7-82 606 | 34-71,11-72 607 | 5-96,5-83 608 | 23-71,67-73 609 | 25-93,25-94 610 | 2-99,1-2 611 | 21-73,11-73 612 | 57-63,56-62 613 | 30-33,33-34 614 | 77-77,31-77 615 | 13-78,14-96 616 | 17-80,46-93 617 | 17-46,1-17 618 | 42-50,41-87 619 | 31-84,4-31 620 | 39-80,18-79 621 | 13-31,14-84 622 | 2-96,3-94 623 | 8-98,9-67 624 | 22-60,22-22 625 | 16-97,15-99 626 | 82-93,82-82 627 | 57-77,22-70 628 | 96-97,13-96 629 | 17-41,41-85 630 | 17-72,17-98 631 | 12-96,4-96 632 | 15-18,17-19 633 | 33-53,33-59 634 | 34-41,35-64 635 | 94-98,27-93 636 | 98-98,1-98 637 | 57-69,32-70 638 | 67-89,66-67 639 | 66-72,73-73 640 | 5-43,5-73 641 | 26-98,27-68 642 | 16-80,15-81 643 | 2-65,2-55 644 | 82-92,82-93 645 | 16-16,16-21 646 | 2-19,4-48 647 | 82-82,56-81 648 | 2-97,1-97 649 | 53-54,38-53 650 | 20-87,21-88 651 | 45-60,44-56 652 | 4-4,5-92 653 | 95-95,79-95 654 | 21-71,7-72 655 | 57-83,58-83 656 | 4-66,11-67 657 | 57-57,58-92 658 | 17-91,17-76 659 | 14-15,15-56 660 | 4-4,4-98 661 | 7-98,15-68 662 | 28-94,94-94 663 | 3-47,27-47 664 | 4-33,12-69 665 | 48-56,48-57 666 | 3-26,5-65 667 | 46-71,46-72 668 | 9-98,37-99 669 | 60-76,18-75 670 | 26-26,26-27 671 | 31-56,31-57 672 | 96-96,4-96 673 | 55-82,55-83 674 | 25-26,26-48 675 | 59-71,54-56 676 | 69-70,7-69 677 | 2-98,98-98 678 | 24-74,75-92 679 | 61-96,61-86 680 | 1-73,1-1 681 | 57-86,56-67 682 | 9-94,94-94 683 | 52-52,53-98 684 | 4-7,2-8 685 | 35-63,34-60 686 | 29-94,29-71 687 | 43-89,44-90 688 | 13-17,12-15 689 | 52-58,51-79 690 | 51-94,12-93 691 | 24-52,24-26 692 | 14-53,53-54 693 | 26-91,26-64 694 | 18-78,65-79 695 | 27-64,55-87 696 | 40-67,68-68 697 | 25-70,24-70 698 | 1-82,81-94 699 | 17-19,18-89 700 | 18-18,17-18 701 | 33-60,57-72 702 | 51-73,52-99 703 | 41-98,42-98 704 | 8-25,14-34 705 | 2-17,1-62 706 | 26-40,21-40 707 | 2-21,3-16 708 | 72-85,72-98 709 | 41-86,14-58 710 | 14-16,30-60 711 | 96-97,22-96 712 | 12-57,12-58 713 | 16-74,15-75 714 | 8-61,7-36 715 | 37-56,36-67 716 | 6-99,6-87 717 | 60-75,60-60 718 | 96-98,67-97 719 | 15-26,25-27 720 | 14-88,87-87 721 | 31-95,32-96 722 | 75-91,53-76 723 | 16-49,17-38 724 | 40-82,41-77 725 | 3-59,2-59 726 | 20-44,20-45 727 | 10-76,9-76 728 | 11-13,12-91 729 | 16-18,17-95 730 | 47-62,33-61 731 | 34-69,19-70 732 | 72-92,91-99 733 | 27-34,28-29 734 | 6-86,2-5 735 | 25-75,25-40 736 | 34-68,35-68 737 | 16-95,16-94 738 | 37-96,37-93 739 | 20-62,20-61 740 | 5-86,4-85 741 | 37-49,35-36 742 | 48-59,48-60 743 | 38-42,39-49 744 | 36-89,37-97 745 | 24-26,25-69 746 | 8-93,21-93 747 | 24-83,23-83 748 | 38-68,37-39 749 | 11-70,34-86 750 | 14-88,13-93 751 | 86-86,47-87 752 | 33-67,32-34 753 | 1-80,80-80 754 | 81-82,8-81 755 | 53-97,5-98 756 | 11-30,1-18 757 | 4-99,3-98 758 | 1-99,77-98 759 | 8-14,15-56 760 | 3-70,2-87 761 | 19-34,34-62 762 | 56-57,57-91 763 | 3-64,2-4 764 | 80-83,84-89 765 | 58-59,1-58 766 | 4-77,5-86 767 | 5-97,3-97 768 | 48-94,26-95 769 | 10-96,7-95 770 | 4-4,6-41 771 | 5-23,4-6 772 | 5-91,90-93 773 | 13-88,89-89 774 | 1-97,90-97 775 | 69-80,69-91 776 | 8-11,11-72 777 | 24-45,36-44 778 | 20-20,20-46 779 | 64-73,65-94 780 | 46-90,47-77 781 | 7-61,61-74 782 | 16-25,25-26 783 | 16-16,15-22 784 | 60-89,61-89 785 | 51-99,52-84 786 | 22-85,22-93 787 | 46-71,45-72 788 | 9-65,10-66 789 | 65-69,60-66 790 | 24-43,23-75 791 | 15-30,3-31 792 | 44-93,26-65 793 | 8-35,8-34 794 | 68-82,2-79 795 | 67-71,18-67 796 | 93-97,93-98 797 | 6-83,2-2 798 | 26-84,27-50 799 | 2-50,49-52 800 | 39-80,40-65 801 | 3-3,4-68 802 | 27-84,36-85 803 | 21-86,20-39 804 | 10-82,9-71 805 | 18-86,40-60 806 | 55-80,23-46 807 | 24-30,23-23 808 | 29-68,30-45 809 | 41-48,42-59 810 | 85-94,88-93 811 | 2-99,98-99 812 | 33-94,94-95 813 | 78-80,3-79 814 | 94-94,16-94 815 | 1-4,3-97 816 | 71-96,52-72 817 | 94-96,95-98 818 | 71-72,72-81 819 | 20-33,32-33 820 | 15-55,15-15 821 | 21-33,33-65 822 | 28-33,27-33 823 | 1-93,57-92 824 | 23-64,63-93 825 | 5-89,4-89 826 | 66-71,68-78 827 | 7-80,2-7 828 | 10-86,9-71 829 | 2-99,2-98 830 | 6-15,5-14 831 | 83-88,60-84 832 | 34-37,33-36 833 | 49-82,82-83 834 | 68-75,61-69 835 | 40-87,16-41 836 | 61-67,64-67 837 | 8-67,7-68 838 | 31-61,30-88 839 | 16-77,16-16 840 | 1-62,63-63 841 | 7-67,2-6 842 | 39-67,8-57 843 | 7-94,11-95 844 | 41-93,73-85 845 | 39-54,47-98 846 | 28-90,2-83 847 | 1-6,6-57 848 | 10-11,9-16 849 | 28-82,27-81 850 | 4-95,5-96 851 | 31-95,8-94 852 | 73-91,33-84 853 | 34-92,15-35 854 | 49-94,6-50 855 | 3-99,2-98 856 | 59-60,34-59 857 | 22-76,22-86 858 | 9-11,10-93 859 | 67-78,77-86 860 | 16-83,15-47 861 | 73-81,72-73 862 | 72-88,2-73 863 | 26-62,27-72 864 | 5-81,5-89 865 | 19-69,20-69 866 | 32-97,32-96 867 | 63-86,32-75 868 | 7-97,7-96 869 | 84-92,91-93 870 | 72-96,2-96 871 | 19-22,19-19 872 | 66-82,65-81 873 | 81-96,65-82 874 | 71-83,35-88 875 | 99-99,1-99 876 | 22-97,22-96 877 | 29-97,29-83 878 | 13-85,84-84 879 | 23-67,23-34 880 | 14-81,13-81 881 | 55-98,16-97 882 | 58-78,38-78 883 | 6-16,3-16 884 | 47-78,46-77 885 | 16-53,15-25 886 | 84-90,83-91 887 | 32-32,31-47 888 | 2-21,4-57 889 | 17-56,49-55 890 | 12-67,67-67 891 | 19-71,42-97 892 | 82-82,63-83 893 | 39-46,18-46 894 | 6-97,1-97 895 | 42-88,43-89 896 | 19-19,19-95 897 | 17-95,4-95 898 | 50-96,50-90 899 | 3-81,1-2 900 | 4-47,7-18 901 | 12-17,7-95 902 | 23-92,23-58 903 | 40-91,91-92 904 | 3-69,69-70 905 | 47-50,46-50 906 | 9-92,9-97 907 | 7-71,4-16 908 | 27-38,74-96 909 | 11-30,30-89 910 | 23-46,22-46 911 | 2-6,5-98 912 | 36-93,35-93 913 | 9-19,19-99 914 | 25-33,32-34 915 | 13-36,14-35 916 | 5-97,4-5 917 | 19-99,20-95 918 | 43-79,54-83 919 | 21-99,20-47 920 | 71-74,70-72 921 | 90-90,3-90 922 | 71-99,71-71 923 | 5-6,6-98 924 | 74-84,74-83 925 | 19-95,19-94 926 | 34-81,38-83 927 | 13-34,5-14 928 | 15-80,15-79 929 | 6-23,5-90 930 | 67-76,67-70 931 | 39-91,14-90 932 | 65-96,64-95 933 | 8-88,52-89 934 | 61-94,89-94 935 | 32-66,66-66 936 | 10-28,15-55 937 | 9-93,8-90 938 | 38-97,39-98 939 | 78-84,77-79 940 | 5-85,3-29 941 | 21-80,80-80 942 | 84-89,88-90 943 | 45-85,12-66 944 | 99-99,1-98 945 | 45-49,48-74 946 | 6-98,3-68 947 | 13-95,94-95 948 | 49-52,51-53 949 | 18-43,6-18 950 | 85-85,20-85 951 | 62-65,61-65 952 | 8-92,9-92 953 | 23-83,22-83 954 | 15-77,77-77 955 | 56-74,55-78 956 | 23-78,22-79 957 | 32-80,33-34 958 | 4-99,11-96 959 | 27-91,16-91 960 | 8-82,8-81 961 | 3-39,28-39 962 | 39-47,39-46 963 | 16-21,34-70 964 | 65-98,65-97 965 | 16-86,16-85 966 | 8-99,33-73 967 | 24-94,19-93 968 | 48-57,56-58 969 | 4-96,3-40 970 | 73-83,17-82 971 | 1-3,2-55 972 | 83-96,96-97 973 | 35-83,66-91 974 | 27-44,16-34 975 | 33-82,31-60 976 | 46-88,45-88 977 | 45-78,58-78 978 | 41-47,40-80 979 | 5-95,4-95 980 | 9-65,10-67 981 | 51-82,68-82 982 | 52-98,36-94 983 | 36-38,37-41 984 | 19-33,9-33 985 | 22-98,21-23 986 | 12-96,11-97 987 | 75-77,11-76 988 | 91-92,12-91 989 | 92-93,4-93 990 | 18-18,17-18 991 | 20-45,44-55 992 | 94-95,61-94 993 | 38-99,39-73 994 | 6-11,11-84 995 | 29-49,9-29 996 | 24-91,24-44 997 | 72-72,28-72 998 | 49-53,49-51 999 | 9-85,8-85 1000 | 26-80,26-90 --------------------------------------------------------------------------------