Day 17 part 1.
This commit is contained in:
43
src/day17.rs
Normal file
43
src/day17.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
#[aoc_generator(day17)]
|
||||
fn parse(input: &str) -> Vec<u32> {
|
||||
input.lines().map(|line| line.parse().unwrap()).collect()
|
||||
}
|
||||
|
||||
#[aoc(day17, part1)]
|
||||
fn part1(input: &[u32]) -> usize {
|
||||
bar(input, 150)
|
||||
}
|
||||
|
||||
fn bar(containers: &[u32], target: u32) -> usize {
|
||||
baz(containers, target, 0)
|
||||
}
|
||||
|
||||
fn baz(containers: &[u32], target: u32, filled: u32) -> usize {
|
||||
if filled > target {
|
||||
return 0;
|
||||
} else if filled == target {
|
||||
return 1;
|
||||
} else if containers.len() == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
baz(&containers[1..], target, filled + containers[0])
|
||||
+ baz(&containers[1..], target, filled)
|
||||
}
|
||||
|
||||
#[aoc(day17, part2)]
|
||||
fn part2(_input: &[u32]) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::day17::bar;
|
||||
|
||||
#[test]
|
||||
fn part1() {
|
||||
assert_eq!(bar(&[20, 15, 10, 5, 5], 25), 4)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user