Browse Source

2016 day 19 partial

master
Terrana Ninetailed 2 years ago
parent
commit
7a4e0ffed1
  1. 1
      2016/resources/day19.input
  2. 37
      2016/src/day19.rs
  3. 6
      2016/src/main.rs

1
2016/resources/day19.input

@ -0,0 +1 @@
3018458

37
2016/src/day19.rs

@ -0,0 +1,37 @@
use std::str::FromStr;
use crate::file_input::read_input_file;
use std::collections::VecDeque;
use std::time::Instant;
pub fn part1() {
let mut n = usize::from_str(read_input_file("day19.input").as_str()).unwrap();
let mut first = 0;
let mut exponent = 1;
while n > 1 {
println!("{} left, {} is first", n, first+1);
if n & 1 == 1 {
first += 1 << exponent;
}
n /= 2;
exponent += 1;
}
println!("{} wins!", first+1);
}
pub fn part2() {
// This will work, but is hideously slow due to vector resizing
let n = usize::from_str(read_input_file("day19.input").as_str()).unwrap();
let mut table = VecDeque::new();
for i in 0..n {
table.push_back(i);
}
let mut current_player = 0;
while table.len() > 1 {
let out_index = (current_player + (table.len() / 2)) % table.len();
table.remove(out_index);
if out_index > current_player {
current_player = (current_player + 1) % table.len();
}
}
println!("{} wins!", table[0]+1);
}

6
2016/src/main.rs

@ -22,6 +22,7 @@ mod day15;
mod day16;
mod day17;
mod day18;
mod day19;
fn main() {
let mut selection= String::new();
@ -123,6 +124,11 @@ fn main() {
Some("2") => day18::part2(),
_ => ()
},
Some("19") => match choices.next() {
Some("1") => day19::part1(),
Some("2") => day19::part2(),
_ => ()
},
_ => ()
}
let run_time = Instant::now() - start;

Loading…
Cancel
Save