Skip to content

Instantly share code, notes, and snippets.

@fryguy1013
Created December 16, 2018 11:00
Show Gist options
  • Save fryguy1013/fb7c2e507c6ca9f534e50928cb183251 to your computer and use it in GitHub Desktop.
Save fryguy1013/fb7c2e507c6ca9f534e50928cb183251 to your computer and use it in GitHub Desktop.
const LOOKUP : [u32; 64] = [38195, 38195, 38195, 38195, 4403, 13107, 54743, 48059, 5393, 39219, 21847, 39355, 37137, 47411, 21973, 39355, 4403, 13107, 22391, 48059, 46899, 46899, 46899, 46899, 5427, 47411, 22391, 48059, 37171, 47923, 22007, 48059, 5427, 13107, 22391, 39867, 5939, 14195, 55287, 48059, 38773, 38773, 38773, 38773, 38193, 47923, 21973, 39867, 37171, 47923, 22519, 48059, 45875, 47923, 57343, 48059, 38193, 47547, 22519, 48059, 46521, 46521, 46521, 46521];
pub fn solve_part1_faster(input: &str) -> usize {
let input = input.as_bytes();
let mut ret = 0;
let mut index = 0;
while index < input.len() {
if input[index] != b'B' { break; }
let a_start = 23 + (input[index+22] != b' ') as usize;
let a = (input[index+a_start] & 3) as usize;
let b = (input[index+a_start+2] & 3) as usize;
let o = (input[index+a_start+4] & 3) as usize;
let afo = (input[a_start + 15 + (o<<1) + o] & 3) as usize;
let rea = (input[index + 9 + (a<<1) + a] & 3) as usize;
let reb = (input[index + 9 + (b<<1) + b] & 3) as usize;
ret += ((LOOKUP[(a<<4) | (b<<2) | rea] >> ((reb<<2) | afo)) & 0x01) as usize;
index += a_start + 28;
}
ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment