Advertisement
theyugin

Untitled

Dec 3rd, 2021
1,345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.45 KB | None | 0 0
  1. pub fn aoc3_1() -> u32 {
  2.     (|num| num * (!num & 0b111111111111))(read_file(&Path::new("inputs/aoc3/input.txt")).fold(
  3.         vec![0; 12],
  4.         |acc, line| acc.into_iter()
  5.             .zip(line.chars())
  6.             .map(|(acc, ch)| if ch == '0' { acc as i32 - 1 } else { acc as i32 + 1 })
  7.             .collect())
  8.         .into_iter()
  9.         .zip(0..)
  10.         .map(|(a, pow)| ((a.signum() + 1) / 2) as u32 * 2_u32.pow(pow))
  11.         .sum())
  12. }
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement