-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::collections::LinkedList; | ||
|
||
use itertools::Itertools; | ||
use regex::Regex; | ||
|
||
use crate::day_6::{self, Dir, Map, Pos}; | ||
|
||
pub mod part_1; | ||
pub mod part_2; | ||
|
||
pub fn parse(input: &str) -> (Map, Vec<isize>) { | ||
let (map, moves) = input.split_once("\r\n\r\n").unwrap(); | ||
let map = day_6::parse(map); | ||
let moves = moves.chars().filter_map(|c| match c { | ||
'^' => Some(3), | ||
'>' => Some(4), | ||
'v' => Some(1), | ||
'<' => Some(2), | ||
_ => None, | ||
}).collect_vec(); | ||
(map, moves) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
######## | ||
#..O.O.# | ||
##@.O..# | ||
#...O..# | ||
#.#.O..# | ||
#...O..# | ||
#......# | ||
######## | ||
|
||
<^^>>>vv<v>>v<<^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
########## | ||
#..O..O.O# | ||
#......O.# | ||
#.OO..O.O# | ||
#[email protected].# | ||
#O#..O...# | ||
#O..O..O.# | ||
#.OO.O.OO# | ||
#....O...# | ||
########## | ||
|
||
<vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><<><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^ | ||
vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v | ||
><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv< | ||
<<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^<vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^ | ||
^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>>^v><>^v><<<<v>>v<v<v>vvv>^<><<>^>< | ||
^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><<<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^ | ||
>^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^ | ||
<><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<> | ||
^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v> | ||
v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v><^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use itertools::Itertools; | ||
|
||
use crate::{ | ||
day_6::{self, get_dir, Dir, Map, Pos}, | ||
day_8::setoff, | ||
}; | ||
|
||
use super::parse; | ||
|
||
#[cfg(test)] | ||
mod test; | ||
|
||
pub fn solve(input: &str) -> usize { | ||
let (mut map, moves) = parse(input); | ||
let mut curr = map.find(|&ch| ch == '@').unwrap(); | ||
for m in moves { | ||
let m = get_dir(m); | ||
if move_stuff(&mut map, curr, m) { | ||
curr = setoff(curr, m); | ||
} | ||
} | ||
|
||
map.find_all(|&ch| ch == 'O') | ||
.map(|(l, t)| t * 100 + l) | ||
.sum() | ||
} | ||
|
||
fn move_stuff(map: &mut Map, curr: Pos, m: Dir) -> bool { | ||
match map.get(curr) { | ||
Some('@' | 'O') => { | ||
let next = setoff(curr, m); | ||
let can_move = move_stuff(map, next, m); | ||
if can_move { | ||
let curr_chr = map.get(curr).unwrap(); | ||
map.set(curr, '.'); | ||
map.set(next, curr_chr); | ||
} | ||
can_move | ||
} | ||
Some('#') | None => false, | ||
Some('.') => true, | ||
c => panic!("Invalid char: {:?}", c), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::solve; | ||
use crate::include_using_path; | ||
|
||
#[test] | ||
fn dummy_input_0() { | ||
let input = include_using_path!("dummy_input_0.txt"); | ||
let result = solve(input); | ||
assert_eq!(result, 2028); | ||
} | ||
|
||
#[test] | ||
fn dummy_input_1() { | ||
let input = include_using_path!("dummy_input_1.txt"); | ||
let result = solve(input); | ||
assert_eq!(result, 10092); | ||
} | ||
|
||
#[test] | ||
fn solve_puzzle() { | ||
let input = include_using_path!("input.txt"); | ||
let result = solve(input); | ||
println!("Result: {}", result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters