aoc-rs-2021/src/day_17/mod.rs
Jan Christian Grünhage 580f6259bc implement day 17
this is horrible, I'm not proud of it. There surely is some mathematical
feature that allows a smarter solution, but after I've not been able to
find that for a while, I've decided to just brute force it. Due to that,
I've not had any motivation to finish this solution on time or to remove
the loads of redundant code I've written here..
2021-12-18 18:10:16 +01:00

54 lines
1.2 KiB
Rust

mod model;
mod parsing;
use aoc_runner_derive::{aoc, aoc_generator};
pub use model::{Probe, TargetArea};
pub use parsing::parse_target_area;
use yap::IntoTokens;
#[aoc_generator(day17)]
pub fn parse_input(input: &str) -> TargetArea {
parse_target_area(&mut input.into_tokens()).unwrap()
}
#[aoc(day17, part1)]
pub fn part1(input: &TargetArea) -> usize {
let y = input.get_highest_possible_y_velocity().unwrap();
let mut ret_val = 0;
for i in 1..=y {
ret_val += i
}
ret_val as usize
}
#[aoc(day17, part2)]
pub fn part2(input: &TargetArea) -> usize {
input.get_all_possible_velocities().len()
}
#[cfg(test)]
mod test {
const EXAMPLE_INPUT: &str = "target area: x=20..30, y=-10..-5";
const RESULT_PART_1: usize = 45;
const RESULT_PART_2: usize = 112;
#[test]
fn part1_example() {
let result = super::part1(&super::parse_input(EXAMPLE_INPUT));
assert_eq!(result, RESULT_PART_1);
}
#[test]
fn part2_example() {
let result = super::part2(&super::parse_input(EXAMPLE_INPUT));
assert_eq!(result, RESULT_PART_2);
}
#[test]
fn parse_example() {
super::parse_input(EXAMPLE_INPUT);
}
}