Skip to content

Instantly share code, notes, and snippets.

@norcalli
Last active December 6, 2020 00:05
Show Gist options
  • Save norcalli/af2105865473019f6015ed7a1a3903d7 to your computer and use it in GitHub Desktop.
Save norcalli/af2105865473019f6015ed7a1a3903d7 to your computer and use it in GitHub Desktop.
use std::io::{stdin, Read};
fn main() {
let mut stdin = stdin();
let mut buf = [0u8; 7 + 3 + 1];
let mut max_id = 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),
_ => (),
}
}
max_id = max_id.max((row << 3) + col);
}
println!("{}", max_id);
}
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 id = 0;
for (i, c) in buf[..10].iter().enumerate() {
match c {
b'R' | b'B' => id |= 1 << (9 - i),
_ => (),
}
}
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);
}
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);
}
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 id = 0;
for (i, c) in buf[..10].iter().enumerate() {
match c {
b'R' | b'B' => id |= 1 << (9 - i),
_ => (),
}
}
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