Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created March 13, 2024 06:47
Show Gist options
  • Save pingbird/00ebaf893d676aac1ba57149873e1f3f to your computer and use it in GitHub Desktop.
Save pingbird/00ebaf893d676aac1ba57149873e1f3f to your computer and use it in GitHub Desktop.
pub fn step_inner(l: bool, m: u64, r: bool) -> u64 {
let l = (m >> 1) | ((l as u64) << 63);
let r = (m << 1) | r as u64;
(l & m & !r) | (l & !m & r) | (!l & m & r) | (!l & m & !r) | (!l & !m & r)
}
pub fn step(input: &mut Vec<u64>, output: &mut Vec<u64>) {
output.clear();
let mut r: bool = true;
let mut input = input.iter().cloned();
let mut m = input.next().unwrap_or(0);
while r || m != 0 {
let next = input.next().unwrap_or(0);
let o = step_inner(next & 1 != 0, m, r);
output.push(o);
r = (m >> 63) != 0;
m = next;
}
}
fn main() {
let mut a: Vec<u64> = vec![];
let mut b: Vec<u64> = vec![];
let mut state = false;
for _ in 0..64 {
let (input, output) = if state { (&mut a, &mut b) } else { (&mut b, &mut a) };
step(input, output);
for i in output.iter() {
for b in 0..64 {
if i & (1 << b) != 0 {
print!("██");
} else {
print!(" ");
}
}
}
println!();
state = !state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment