theyugin

Untitled

Dec 3rd, 2021
731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data