aboutsummaryrefslogtreecommitdiff
path: root/2022/10/a.rs
diff options
context:
space:
mode:
Diffstat (limited to '2022/10/a.rs')
-rw-r--r--2022/10/a.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/2022/10/a.rs b/2022/10/a.rs
new file mode 100644
index 0000000..cdab283
--- /dev/null
+++ b/2022/10/a.rs
@@ -0,0 +1,23 @@
1mod common;
2use common::*;
3
4fn main() {
5 let mut x: i64 = 1;
6 let mut cycles: usize = 0;
7 let mut step: usize = 20;
8 let mut score: i64 = 0;
9 let mut line = String::new();
10 while std::io::stdin().read_line(&mut line).unwrap() > 0 {
11 let oldx = x;
12 match read_instruction(&line) {
13 Instruction::Add(n) => { x += n; cycles += 2; },
14 Instruction::Noop => { cycles += 1; }
15 }
16 if cycles >= step {
17 score += oldx * (step as i64);
18 step += 40;
19 }
20 line.clear();
21 }
22 println!("{score}");
23}

Generated with cgit - Back to sebastiano.tronto.net