aoc

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

b.rs (732B)


      1 mod common;
      2 use common::*;
      3 
      4 fn draw(cycles: usize, x: i64) {
      5     let c = cycles % 40;
      6     if cycles > 0 && c == 0 { println!(); }
      7     print!("{}", if (x - (c as i64)).abs() <= 1 { '#' } else { '.' });
      8 }
      9 
     10 fn main() {
     11     let mut x: i64 = 1;
     12     let mut cycles: usize = 0;
     13     let mut line = String::new();
     14     while std::io::stdin().read_line(&mut line).unwrap() > 0 {
     15         match read_instruction(&line) {
     16             Instruction::Add(n) => {
     17                 draw(cycles, x);
     18                 draw(cycles+1, x);
     19                 cycles += 2;
     20                 x += n;
     21             },
     22             Instruction::Noop => {
     23                 draw(cycles, x);
     24                 cycles += 1;
     25             }
     26         }
     27         line.clear();
     28     }
     29 }