Skip to content

Commit

Permalink
Krotki, day 7 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krotki authored Dec 7, 2024
1 parent 1c5b290 commit 7c4c87b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 2024/07/calibration.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20
33 changes: 33 additions & 0 deletions 2024/07/krotki/part1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module main

import os

fn main() {
input := os.get_lines()

ops := ['+', '*']

mut sum := u64(0)
for line in input {
numbers := line.split(' ').map(it.u64())
mut acc := [numbers[1]]
for n2 in numbers[2..] {
mut nacc := []u64{}
for n1 in acc {
for op in ops {
match op {
'+' { nacc << n1 + n2 }
'*' { nacc << n1 * n2 }
else {}
}
}
}
acc = nacc.clone()
}
if acc.contains(numbers[0]) {
sum += numbers[0]
}
}

println(sum)
}
34 changes: 34 additions & 0 deletions 2024/07/krotki/part2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module main

import os

fn main() {
input := os.get_lines()

ops := ['+', '*', '||']

mut sum := u64(0)
for line in input {
numbers := line.split(' ').map(it.u64())
mut acc := [numbers[1]]
for n2 in numbers[2..] {
mut nacc := []u64{}
for n1 in acc {
for op in ops {
match op {
'+' { nacc << n1 + n2 }
'*' { nacc << n1 * n2 }
'||' { nacc << '${n1}${n2}'.u64() }
else {}
}
}
}
acc = nacc.clone()
}
if acc.contains(numbers[0]) {
sum += numbers[0]
}
}

println(sum)
}
1 change: 1 addition & 0 deletions known/2024/07/krotki/part1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3749
1 change: 1 addition & 0 deletions known/2024/07/krotki/part2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11387

0 comments on commit 7c4c87b

Please sign in to comment.