This file contains hidden or 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
fn main() { | |
let part1 = count_valid_passports(INPUT, part1_filter); | |
let part2 = count_valid_passports(INPUT, part2_filter); | |
println!("Part 1: {}", part1); | |
println!("Part 2: {}", part2); | |
} | |
fn count_valid_passports(batch: &str, filter: fn(&str, &str) -> bool) -> usize { | |
batch |
This file contains hidden or 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
struct Map { | |
trees: Vec<Vec<bool>>, | |
width: usize, | |
height: usize, | |
} | |
impl From<&str> for Map { | |
fn from(grid: &str) -> Self { | |
let width = grid.lines().next().unwrap().len(); | |
let height = grid.lines().count(); |
This file contains hidden or 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
struct Line<'a> { | |
lower: usize, | |
upper: usize, | |
letter: char, | |
password: &'a str, | |
} | |
impl<'a> From<&'a str> for Line<'a> { | |
fn from(l: &'a str) -> Self { | |
let (policy, password) = l.split_once(": ").unwrap(); |
This file contains hidden or 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
fn part_1(values: &HashSet<i64>) -> i64 { | |
values | |
.iter() | |
.find_map(|&v| { | |
if values.contains(&(2020 - v)) { | |
Some(v * (2020 - v)) | |
} else { | |
None | |
} | |
}) |
This file contains hidden or 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
fn main() { | |
let mut sea_floor = SeaFloor::from(INPUT); | |
let mut step = 0; | |
loop { | |
step += 1; | |
if !sea_floor.step() { | |
println!("The sea cucumbers stop moving after step: {}", step); |
This file contains hidden or 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
fn main() { | |
let program = Program::from(MONAD); | |
let (largest, smallest) = find_max_and_min_model_numbers(&program); | |
println!("The largest model number is: {}", largest); | |
println!("The smallest model number is: {}", smallest); | |
} | |
fn find_max_and_min_model_numbers(program: &Program) -> (i64, i64) { |
This file contains hidden or 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
fn main() { | |
let burrow = Burrow::<8>::from(PART1); | |
let result = burrow.energy_to_organise().unwrap(); | |
println!("Energy required to organise partial map: {:?}", result); | |
let burrow = Burrow::<16>::from(PART2); | |
let result = burrow.energy_to_organise().unwrap(); | |
println!("Energy required to organise full map: {:?}", result); | |
} |
This file contains hidden or 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
fn main() { | |
let steps = parse_steps(INPUT); | |
let regions = execute_steps(&steps); | |
let total = regions.iter().map(|c| c.count_cubes()).sum::<i64>(); | |
let inner_region = Cuboid::new(Vector::new(-50, -50, -50), Vector::new(50, 50, 50)); | |
let steps = once((true, inner_region)) | |
.chain(regions.iter().map(|&r| (false, r))) | |
.collect::<Vec<_>>(); |
This file contains hidden or 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
fn part1() { | |
let mut player_a = Player { | |
position: 1, | |
score: 0, | |
}; | |
let mut player_b = Player { | |
position: 5, | |
score: 0, | |
}; |
This file contains hidden or 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
fn main() { | |
let (algorithm, mut image) = parse_input(INPUT); | |
let mut infinite_pixels = false; | |
for _ in 0..50 { | |
image = step(&algorithm, &image, &mut infinite_pixels); | |
} | |
println!("Pixels lit: {}", image.len()); | |
} |
NewerOlder