-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.rs
More file actions
21 lines (19 loc) · 585 Bytes
/
main.rs
File metadata and controls
21 lines (19 loc) · 585 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const WIDTH: usize = 12;
const COUNT: usize = 1000;
pub fn main() {
let gamma = include_str!("../input.txt")
.lines()
.map(|l| usize::from_str_radix(l, 2).unwrap())
.fold(vec![0; WIDTH], |count, bits| {
count
.into_iter()
.enumerate()
.map(|(i, n)| n + ((bits & 1 << i) >> i))
.collect()
})
.into_iter()
.enumerate()
.map(|(i, b)| ((b >= COUNT / 2) as u32) << i)
.sum::<u32>();
println!("{}", gamma * (!gamma & ((1 << WIDTH) - 1)));
}