File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ pub mod day2;
3
3
pub mod day3;
4
4
pub mod day4;
5
5
pub mod day5;
6
+ pub mod day6;
Original file line number Diff line number Diff line change @@ -11,4 +11,6 @@ fn main() {
11
11
day4:: run ( ) ;
12
12
println ! ( "Day 5 --------" ) ;
13
13
day5:: run ( ) ;
14
+ println ! ( "Day 6 --------" ) ;
15
+ day6:: run ( ) ;
14
16
}
You can’t perform that action at this time.
0 commit comments