aboutsummaryrefslogtreecommitdiff
path: root/2022/10/b.rs
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-06-27 09:53:33 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-06-27 09:53:33 +0200
commit0e6bebb63d5795ca9143b9713d1d82ebec8d7e03 (patch)
tree3ca39b2e485247609168d0a1b3e986f1e824a6d6 /2022/10/b.rs
parentfa26f694d8cf98272763952a698301ee9935c19e (diff)
downloadaoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.tar.gz
aoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.zip
Day 10
Diffstat (limited to '2022/10/b.rs')
-rw-r--r--2022/10/b.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/2022/10/b.rs b/2022/10/b.rs
new file mode 100644
index 0000000..ab0091f
--- /dev/null
+++ b/2022/10/b.rs
@@ -0,0 +1,29 @@
1mod common;
2use common::*;
3
4fn 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
10fn 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}

Generated with cgit - Back to sebastiano.tronto.net