Rule110 in Rust
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
[profile.release] | |
opt-level = "z" | |
lto = true | |
codegen-units = 1 | |
panic = "abort" |
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::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