Day 14 part 1.
This commit is contained in:
35
src/day14.rs
Normal file
35
src/day14.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
|
|
||||||
|
#[aoc_generator(day14)]
|
||||||
|
fn parse(input: &str) -> Vec<(usize, usize, usize)> {
|
||||||
|
input.lines()
|
||||||
|
.map(|line| {
|
||||||
|
// Rudolph can fly 22 km/s for 8 seconds, but then must rest for 165 seconds.
|
||||||
|
let parts: Vec<&str> = line.split(" ").collect();
|
||||||
|
let speed = parts[3].parse::<usize>().unwrap();
|
||||||
|
let fly = parts[6].parse::<usize>().unwrap();
|
||||||
|
let rest = parts[13].parse::<usize>().unwrap();
|
||||||
|
(speed, fly, rest)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[aoc(day14, part1)]
|
||||||
|
fn part1(input: &Vec<(usize, usize, usize)>) -> usize {
|
||||||
|
let seconds = 2503;
|
||||||
|
input.into_iter()
|
||||||
|
.map(|&(speed, fly, rest)| {
|
||||||
|
let cycle = fly + rest;
|
||||||
|
let full = seconds / cycle;
|
||||||
|
let rem = seconds % cycle;
|
||||||
|
let partial = if rem < fly { rem } else { fly };
|
||||||
|
(full * fly + partial) * speed
|
||||||
|
})
|
||||||
|
.max()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[aoc(day14, part2)]
|
||||||
|
// fn part2(input: &str) -> String {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
@@ -6,5 +6,6 @@ mod day10;
|
|||||||
mod day11;
|
mod day11;
|
||||||
mod day12;
|
mod day12;
|
||||||
mod day13;
|
mod day13;
|
||||||
|
mod day14;
|
||||||
|
|
||||||
aoc_lib! { year = 2015 }
|
aoc_lib! { year = 2015 }
|
||||||
|
|||||||
Reference in New Issue
Block a user