diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-27 09:53:33 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-27 09:53:33 +0200 |
| commit | 0e6bebb63d5795ca9143b9713d1d82ebec8d7e03 (patch) | |
| tree | 3ca39b2e485247609168d0a1b3e986f1e824a6d6 /2022/10/b.rs | |
| parent | fa26f694d8cf98272763952a698301ee9935c19e (diff) | |
| download | aoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.tar.gz aoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.zip | |
Day 10
Diffstat (limited to '2022/10/b.rs')
| -rw-r--r-- | 2022/10/b.rs | 29 |
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 @@ | |||
| 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 | } | ||
