Created
December 5, 2020 23:52
-
-
Save norcalli/b07edddf9a01a36e84413e0d13d09131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{stdin, Read}; | |
fn main() { | |
let mut stdin = stdin(); | |
let mut buf = [0u8; 7 + 3 + 1]; | |
let mut max_id = 0; | |
let mut min_id = 1 << buf.len(); | |
let mut sum = 0; | |
while let Ok(()) = stdin.read_exact(&mut buf) { | |
let mut row = 0; | |
let mut col = 0; | |
for (i, c) in buf[..10].iter().enumerate() { | |
match c { | |
b'B' => row |= 1 << (6 - i), | |
b'R' => col |= 1 << (9 - i), | |
_ => (), | |
} | |
} | |
let id = (row << 3) + col; | |
max_id = max_id.max(id); | |
min_id = min_id.min(id); | |
sum += id; | |
} | |
fn list_length(a: i32, b: i32) -> i32 { | |
(b - a + 1) * (b + a) / 2 | |
} | |
println!("Part 1: {}", max_id); | |
println!("Part 2: {}", list_length(min_id, max_id) - sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment