2019-12-08 14:18:41 +01:00
mod counter ;
use counter ::Counter ;
2019-12-08 15:32:02 +01:00
use itertools ::Itertools ;
2019-12-08 14:18:41 +01:00
use std ::io ::BufRead ;
const WIDTH : usize = 25 ;
const HEIGHT : usize = 6 ;
fn main ( ) {
2019-12-08 15:32:02 +01:00
let input = std ::io ::stdin ( ) . lock ( ) . lines ( ) . next ( ) . unwrap ( ) . unwrap ( ) ;
let chunked = input . chars ( ) . chunks ( HEIGHT * WIDTH ) ;
let layers = chunked . into_iter ( ) ;
2019-12-08 14:43:26 +01:00
let mut img = vec! [ '2' ; WIDTH * HEIGHT ] ;
2019-12-08 15:32:02 +01:00
let counters = layers . map ( | layer | {
Counter ::of ( layer . enumerate ( ) . map ( | ( i , p ) | {
if let Some ( & '2' ) = img . get ( i ) {
img [ i ] = p
2019-12-08 14:43:26 +01:00
}
2019-12-08 15:32:02 +01:00
p
} ) )
} ) ;
2019-12-08 14:43:26 +01:00
2019-12-08 15:32:02 +01:00
let fewest_zeros = counters . min_by_key ( | c | c [ '0' ] ) . unwrap ( ) ;
2019-12-08 14:43:26 +01:00
println! ( " Part 1: {} " , fewest_zeros [ '1' ] * fewest_zeros [ '2' ] ) ;
for line in img . chunks ( WIDTH ) {
2019-12-08 15:32:02 +01:00
println! ( " {} " , line . iter ( ) . collect ::< String > ( ) . replace ( '0' , " " ) ) ;
2019-12-08 14:43:26 +01:00
}
2019-12-08 14:18:41 +01:00
}