September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,26 @@
const N: usize = 41;
const K: usize = 3;
const M: usize = 3;
const POSITION: usize = 5;
fn main() {
let mut prisoners: Vec<usize> = Vec::new();
let mut executed: Vec<usize> = Vec::new();
for pos in 0..N {
prisoners.push(pos);
}
let mut to_kill: usize = 0;
let mut len: usize = prisoners.len();
while len > M {
to_kill = (to_kill + K - 1) % len;
executed.push(prisoners.remove(to_kill));
len -= 1;
}
println!("JOSEPHUS n={}, k={}, m={}", N, K, M);
println!("Executed: {:?}", executed);
println!("Executed position number {}: {}", POSITION, executed[POSITION - 1]);
println!("Survivors: {:?}", prisoners);
}