From ea3ef158053013a2c460efcc3d0bc8de200c5766 Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Sun, 11 Dec 2022 01:57:10 +0100 Subject: [PATCH] add day 10, part 2 --- day10/part2.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 day10/part2.rs diff --git a/day10/part2.rs b/day10/part2.rs new file mode 100644 index 0000000..ec9f11b --- /dev/null +++ b/day10/part2.rs @@ -0,0 +1,37 @@ +// Copyright 2022 Christian Ulrich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// usage: ./part2 < input + +pub mod common; + +use common::Processor; + +fn main() -> Result<(), &'static str> { + let mut processor = Processor::new(); + let mut line = String::from("#"); + for (count, register_x) in processor.cycles().enumerate() { + let sprite = register_x? - 1..=register_x? + 1; + match (count + 1) % 40 { + pos if { sprite.contains(&(pos as i64)) } => line.push('#'), + _ => line.push('.'), + } + if line.len() == 40 { + println!("{line}"); + line.clear(); + } + } + Ok(()) +}