Day 16 part 1.
This commit is contained in:
55
src/day16.rs
Normal file
55
src/day16.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
#[aoc_generator(day16)]
|
||||
fn parse(input: &str) -> Vec<Sue> {
|
||||
input.lines()
|
||||
.map(|line| {
|
||||
let (_, hints) = line.split_once(": ").unwrap();
|
||||
let hints: Vec<_> = hints.split(", ").collect();
|
||||
hints.into_iter().map(|thing| {
|
||||
let (name, count) = thing.split_once(": ").unwrap();
|
||||
(name.to_string(), count.parse().unwrap())
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[aoc(day16, part1)]
|
||||
fn part1(input: &[Sue]) -> usize {
|
||||
let known = "children: 3
|
||||
cats: 7
|
||||
samoyeds: 2
|
||||
pomeranians: 3
|
||||
akitas: 0
|
||||
vizslas: 0
|
||||
goldfish: 5
|
||||
trees: 3
|
||||
cars: 2
|
||||
perfumes: 1";
|
||||
let known: Sue = known.split("\n")
|
||||
.map(|line| {
|
||||
let (name, count) = line.split_once(": ").unwrap();
|
||||
(name.to_string(), count.parse().unwrap())
|
||||
}).collect();
|
||||
|
||||
let sue = input.iter()
|
||||
.enumerate()
|
||||
.filter(|(_index, sue)| {
|
||||
known.iter()
|
||||
.all(|(property, _)| {
|
||||
!sue.contains_key(property) || known.get(property) == sue.get(property)
|
||||
})
|
||||
})
|
||||
.next().unwrap();
|
||||
sue.0 + 1
|
||||
}
|
||||
|
||||
// #[aoc(day16, part2)]
|
||||
// fn part2(input: &[Ingredient]) -> i32 {
|
||||
// 0
|
||||
// }
|
||||
|
||||
type Sue = HashMap<String, u8>;
|
||||
|
||||
@@ -8,5 +8,6 @@ mod day12;
|
||||
mod day13;
|
||||
mod day14;
|
||||
mod day15;
|
||||
mod day16;
|
||||
|
||||
aoc_lib! { year = 2015 }
|
||||
|
||||
Reference in New Issue
Block a user