Skip to content

Instantly share code, notes, and snippets.

@fnky
Created September 22, 2021 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnky/286f0cfbaaf203be706d7d3e1ea1ff88 to your computer and use it in GitHub Desktop.
Save fnky/286f0cfbaaf203be706d7d3e1ea1ff88 to your computer and use it in GitHub Desktop.
Rule110 in Rust
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
use std::error::Error;
use std::io::{self, Write};
const BOARD_CAP: usize = 100;
fn main() -> Result<(), Box<dyn Error>> {
let mut board = [0; BOARD_CAP];
board[BOARD_CAP - 2] = 1;
let stdout = io::stdout();
let lock = stdout.lock();
let mut buf = io::BufWriter::new(lock);
for _i in 0..BOARD_CAP - 2 {
for j in 0..BOARD_CAP {
write!(buf, "{}", " *".chars().nth(board[j]).unwrap())?;
}
write!(buf, "\n")?;
buf.flush()?;
let mut pattern = (board[0] << 1) | board[1];
for j in 1..BOARD_CAP - 1 {
pattern = ((pattern << 1) & 7) | board[j + 1];
board[j] = (110 >> pattern) & 1;
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment