@@ -2,7 +2,7 @@ use crate::utils;
|
||||
|
||||
pub fn both() {
|
||||
let input: Vec<usize> = utils::read_file("input/day08.txt")
|
||||
.split(" ")
|
||||
.split(' ')
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
|
||||
@@ -23,13 +23,13 @@ impl Node {
|
||||
let num_meta: usize = input[1];
|
||||
let mut children = Vec::new();
|
||||
while num_children > 0 {
|
||||
let (node, rest) = Node::extract_from(&rest_input);
|
||||
let (node, rest) = Node::extract_from(rest_input);
|
||||
children.push(node);
|
||||
rest_input = rest;
|
||||
num_children -= 1;
|
||||
}
|
||||
|
||||
let metadata = rest_input[..num_meta].iter().map(|x| *x).collect();
|
||||
let metadata = rest_input[..num_meta].to_vec();
|
||||
(Node { metadata, children }, &rest_input[num_meta..])
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ impl Node {
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| {
|
||||
let s: usize = child.metadata_sum().clone();
|
||||
let s: usize = child.metadata_sum();
|
||||
s
|
||||
})
|
||||
.sum::<usize>()
|
||||
}
|
||||
|
||||
fn task2(&self) -> usize {
|
||||
if self.children.len() > 0 {
|
||||
if !self.children.is_empty() {
|
||||
self.metadata
|
||||
.iter()
|
||||
.map(|meta| match self.children.get(*meta - 1) {
|
||||
|
||||
Reference in New Issue
Block a user