aboutsummaryrefslogtreecommitdiff
path: root/2022/10/b.rs
diff options
context:
space:
mode:
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