aboutsummaryrefslogtreecommitdiff
path: root/2022/10/a.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/a.rs
parentfa26f694d8cf98272763952a698301ee9935c19e (diff)
downloadaoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.tar.gz
aoc-0e6bebb63d5795ca9143b9713d1d82ebec8d7e03.zip
Day 10
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