Skip to content

Commit eb857e5

Browse files
author
mflinn-broad
committed
part 1
1 parent cb018af commit eb857e5

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/days/day6.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::thread::current;
2+
3+
use crate::util;
4+
5+
pub fn run() {
6+
let raw_input = util::read_input("inputs/day6.txt").unwrap();
7+
let starting_statte = process(&raw_input);
8+
println!("{:?}", starting_statte);
9+
println!("Part 1: {:?}", part_1(starting_statte));
10+
11+
}
12+
13+
fn process(input: &str) -> [u64; 9] {
14+
let mut tracker: [u64; 9] = [0; 9];
15+
input.trim().split(',')
16+
.map(|day_str| day_str.parse::<u64>().unwrap())
17+
.for_each(|day| tracker[day as usize] += 1);
18+
tracker
19+
}
20+
21+
fn part_1(state: [u64; 9]) -> usize {
22+
let final_state: [u64; 9] = (1..=80)
23+
.fold(state, |mut curr_state, _| {
24+
let mut temp_state: [u64; 9] = [0; 9];
25+
temp_state.copy_from_slice(&curr_state);
26+
27+
for bucket in 1..9 {
28+
curr_state[bucket-1] = temp_state[bucket];
29+
}
30+
31+
curr_state[6] += temp_state[0];
32+
curr_state[8] = temp_state[0];
33+
println!("{:?}", curr_state);
34+
curr_state
35+
});
36+
final_state.iter().map(|count| *count as usize).sum()
37+
}

src/days/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod day2;
33
pub mod day3;
44
pub mod day4;
55
pub mod day5;
6+
pub mod day6;

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ fn main() {
1111
day4::run();
1212
println!("Day 5 --------");
1313
day5::run();
14+
println!("Day 6 --------");
15+
day6::run();
1416
}

0 commit comments

Comments
 (0)