Rust
use std::hint::unreachable_unchecked;
use std::io::{stdin, stdout, Read, Write};
pub fn main() {
let key = b"draw!";
let temp = stdin();
let mut stdin = temp.lock();
let tmp = stdout();
let mut out = tmp.lock();
let mut i = 0;
let mut buf = [0];
loop {
stdin
.read(&mut buf)
.unwrap_or_else(|_| unsafe { unreachable_unchecked() });
let read = *unsafe { buf.get_unchecked(0) };
if unsafe { read == *key.get_unchecked(i) } {
i += 1;
} else {
i = (read == b'd') as usize;
}
if i == 5 {
out.write(b"bang!")
.unwrap_or_else(|_| unsafe { unreachable_unchecked() });
out.flush()
.unwrap_or_else(|_| unsafe { unreachable_unchecked() });
break;
}
}
}
A solution in rust. It is pretty similar to @hyper-neutrino's solution, but it makes sure to flush the output buffer after writing and also asserts that io errors can't happen (it will be undefined behavior if they do, probably causing a sigill). Build rustc -Copt-level=3 -Clto=fat -Ctarget-cpu=native -o main
and run ./main