aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

a.rs (593B)


      1 mod common;
      2 use common::*;
      3 
      4 fn main() {
      5     let mut x: i64 = 1;
      6     let mut cycles: usize = 0;
      7     let mut step: usize = 20;
      8     let mut score: i64 = 0;
      9     let mut line = String::new();
     10     while std::io::stdin().read_line(&mut line).unwrap() > 0 {
     11         let oldx = x;
     12         match read_instruction(&line) {
     13             Instruction::Add(n) => { x += n; cycles += 2; },
     14             Instruction::Noop => { cycles += 1; }
     15         }
     16         if cycles >= step {
     17             score += oldx * (step as i64);
     18             step += 40;
     19         }
     20         line.clear();
     21     }
     22     println!("{score}");
     23 }