Day 17 part 1.

This commit is contained in:
2024-06-27 21:53:21 +02:00
parent 4056898a87
commit f18e7797ed
2 changed files with 44 additions and 0 deletions

43
src/day17.rs Normal file
View 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)
}
}