aboutsummaryrefslogtreecommitdiff
path: root/2022/21/a.rs
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-07 11:47:29 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-07 11:47:29 +0200
commit2641a35d5473beb6889b299b54de294fbf782b1f (patch)
tree7fc7dcdb3f8750c19385cb3d9de87029d2fadb1b /2022/21/a.rs
parent2f0e522317972711b5e03ad25b38bf03af17e8d5 (diff)
downloadaoc-2641a35d5473beb6889b299b54de294fbf782b1f.tar.gz
aoc-2641a35d5473beb6889b299b54de294fbf782b1f.zip
Day 21 2022
Diffstat (limited to '2022/21/a.rs')
-rw-r--r--2022/21/a.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/2022/21/a.rs b/2022/21/a.rs
new file mode 100644
index 0000000..297f97a
--- /dev/null
+++ b/2022/21/a.rs
@@ -0,0 +1,19 @@
1mod common;
2use common::*;
3
4pub fn calculate(name: &str, monkeys: &Vec<Monkey>) -> i64 {
5 let i = monkeys.iter().position(|m| m.name == name).unwrap();
6 match &monkeys[i].kind {
7 MonkeyType::Num(n) => *n,
8 MonkeyType::Op(op) => {
9 let n1 = calculate(&op.m1, &monkeys);
10 let n2 = calculate(&op.m2, &monkeys);
11 apply_op(n1, n2, op)
12 }
13 }
14}
15
16fn main() {
17 let monkeys = read_monkeys_from_stdin();
18 println!("{}", calculate(&"root", &monkeys));
19}

Generated with cgit - Back to sebastiano.tronto.net