From ccf1a5828fc26a82545c7accf1ce7916daa08a2d Mon Sep 17 00:00:00 2001 From: alyx Date: Mon, 20 Nov 2023 17:12:15 -0500 Subject: Reorganize using workspaces --- 2015/rs/code/three/Cargo.toml | 8 ++++++++ 2015/rs/code/three/src/input.txt | 1 + 2015/rs/code/three/src/main.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 2015/rs/code/three/Cargo.toml create mode 100644 2015/rs/code/three/src/input.txt create mode 100644 2015/rs/code/three/src/main.rs (limited to '2015/rs/code/three') diff --git a/2015/rs/code/three/Cargo.toml b/2015/rs/code/three/Cargo.toml new file mode 100644 index 0000000..6c6d234 --- /dev/null +++ b/2015/rs/code/three/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "three" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2015/rs/code/three/src/input.txt b/2015/rs/code/three/src/input.txt new file mode 100644 index 0000000..55f286f --- /dev/null +++ b/2015/rs/code/three/src/input.txt @@ -0,0 +1 @@ +^><^>>>^<^v<<^<><^<^v>^vv<>v>>^^^v<<<^>^<^v<^>^v><<<^>><>v>v^<<^>^<<^^^>v>>v^^>^>vv>>^>>v^>^v>^<^^v>^>^^v^^>v^^v><^><^<<>v^<^<^vv^>>>v^v^>^<>^v<^^vv^>^<>^^<vv<>^>v<^>^v>v^>^v<>^><>>v^v<><>v^v>>>>v^^>^><^^<^>^v^v<>v<<<^<v^^^<^^^>v<^v>>>>>v<^^^^>v<^<>>>>>>v^vvvv^^^v<^v^>v><^>^v<<>>vv^>v>v^^>vv^<^vvv<>><>><><^^^^<^^^<^v>>v>^v^^^>v^^^v>>^v^^<^>>^>^<>>^^<>>^vv>v^<^>>>><><^^v<><<<<^^<>>^<>vv^<^>v^^><^v>^^>v<>^v^<>^vv^>vvv>v>^>^>>^>><>>>^^^^v^<>v^^>^<>v<^^v><^v><>^^^^^v^v>>^^v><<><^^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vv^^<^>>v>vv^v<^<>^v^<^<<><<<^vvv^>^^<<>>>vv<<^<><^v<^<><<^^>vv^v>v^^^>>>>^>vv<v>>^^v^^><>v<<^><^>^>v^v>><^v^>v<<^<^<^<^<>>v^^>><<<>vv<^^>^vv<<<^^v^^>v<<><^<>^^>^v<>v>><^^^vv^>^><>v^^>^v>^<<^v>^>>>>><^^^<>v>v^^<^v^>>v^<^>v^v>>>>^>>vv<>^<^v>v>v^v>^<>^>v<<>^<>>^<>>^<>v^><<>^v>>^^^^<<^v><>^<^>^^v><^^<^^v>v<<^>^>><<^^^vvv<<^vv<^^>v^^vv^<^^<<^^>>^^<v^>>v^^>v<^>^>vv>><v><^<^vv>^^v>^>v<<^vv><^^^^^^><<^>>>^v<>^^v<<<>><<<>^<<v^>^^^<^>^^^v<<>v^><<^^<<^v<<>^v>>vv>><<^v^^>v^v>^^v<><^^^<^^>v>^<>vvv^v^^^>v^^v<^>^^>>^v<><^><^<<^vv^<><<>v^vv^<<<^^>v<<>>>v<>v<><<^v>^^v>^^>v>^>^>v<>><>^>^>^vvvv<^^^^^v>v>><>^>^><>^^>v^^<<><^><<<<>v>^^>^v<<<>vvv>>v<^v>>v>v^<<<>^>^>^<>v<^^vv><^v<<^vv<^<<^^vv^^>vv<^>v>^^<^>v<<^^<^>^^^v^^>>v^vv^<^v>^<>^<^>>^<^v<>v><^^<><>^>v<^<^vv>><^v>^<>^^>^<><<>^<>><<>vvv^<<^^>>v<^>>vv>^v^^^v<>v<>><>^vv^>vv^ diff --git a/2015/rs/code/three/src/main.rs b/2015/rs/code/three/src/main.rs new file mode 100644 index 0000000..770fc10 --- /dev/null +++ b/2015/rs/code/three/src/main.rs @@ -0,0 +1,29 @@ +use std::collections::HashSet; + +static INPUT: &'static str = include_str!("input.txt"); + +fn main() { + let valueified = INPUT.chars().map(|c| match c { '<' => (-1, 0), '>' => (1, 0), '^' => (0, 1), 'v' => (0, -1), _ => (0, 0) }); + + let mut visited = HashSet::new(); + append_visits(valueified.clone(), &mut visited); + println!("Number visited normally: {}", visited.len()); + + let santa_iter = valueified.clone().step_by(2); + let robot_iter = valueified.skip(1).step_by(2); + + let mut visited = HashSet::new(); + append_visits(santa_iter.clone(), &mut visited); + append_visits(robot_iter.clone(), &mut visited); + println!("Number visited w/ robot: {}", visited.len()); +} + +fn append_visits>(iter: I, visited: &mut HashSet<(i32, i32)>) { + let (mut x, mut y) = (0, 0); + visited.insert((0, 0)); + for (move_x, move_y) in iter { + x += move_x; + y += move_y; + visited.insert((x, y)); + } +} -- cgit v1.2.3-70-g09d2