solved some AoC

This commit is contained in:
mark 2023-06-07 21:14:22 +02:00
parent 46dbb13e0f
commit 217a527c01
4 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,24 @@
input := fs_read("/tmp/pin.txt").assume_no_enum().bytes_to_string().assume_no_enum()
fn prio(s string) {
switch! "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".index_of(s) {
[] [] 0
int n n + 1
}
}
sum := 0
for line input.regex(".*").assume_no_enum() {
left := line.substring(0, line.len() / 2)
right := line.substring(line.len() / 2)
for ch right.regex(".").assume_no_enum() {
if left.contains(ch) {
&sum = sum + prio(ch)
true
}
}
[]
}
println("sum: " + sum.to_string())

View File

@ -0,0 +1,32 @@
input := fs_read("/tmp/pin.txt").assume_no_enum().bytes_to_string().assume_no_enum()
fn prio(s string) {
switch! "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".index_of(s) {
[] [] 0
int n n + 1
}
}
sum := 0
for group input.regex(".*\\n.*\\n.*\\n?").assume_no_enum() {
rucksacks := group.regex(".*").assume_no_enum()
a := rucksacks.get(0).assume1()
b := rucksacks.get(1).assume1()
c := rucksacks.get(2).assume1()
println(a)
println(b)
println(c)
println("---")
badge_type := for ch "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".regex(".").assume_no_enum() {
if a.contains(ch) && b.contains(ch) && c.contains(ch) {
ch
}
}
switch! badge_type {
string s &sum = sum + prio(s)
[] [] []
}
}
println("sum: " + sum.to_string())

View File

@ -0,0 +1,21 @@
input := fs_read("/tmp/pin.txt").assume_no_enum().bytes_to_string().assume_no_enum()
fn get_pair(s string) {
list := s.regex("[^-]+").assume_no_enum()
[
list.get(0).assume1("A").parse_int().assume1("a")
list.get(1).assume1("B").parse_int().assume1("b")
]
}
count := 0
for pair input.regex(".+").assume_no_enum() {
s := pair.regex("[^,]*").assume_no_enum()
s1 := get_pair(s.get(0).assume1("bb"))
s2 := get_pair(s.get(1).assume1("aa"))
if { s1.0 <= s2.0 && s1.1 >= s2.1 } || { s1.0 >= s2.0 && s1.1 <= s2.1 } {
&count = count + 1
}
}
println("count: " + count.to_string())

View File

@ -0,0 +1,29 @@
input := fs_read("/tmp/pin.txt").assume_no_enum().bytes_to_string().assume_no_enum()
fn get_pair(s string) {
list := s.regex("[^-]+").assume_no_enum()
[
list.get(0).assume1().parse_int().assume1()
list.get(1).assume1().parse_int().assume1()
]
}
count := 0
for pair input.regex(".+").assume_no_enum() {
s := pair.regex("[^,]*").assume_no_enum()
s1 := get_pair(s.get(0).assume1())
s2 := get_pair(s.get(1).assume1())
if {
s1.0 <= s2.0 && s2.0 <= s1.1
} || {
s1.0 <= s2.1 && s2.1 <= s1.1
} || {
s2.0 <= s1.0 && s1.0 <= s2.1
} || {
s2.0 <= s1.1 && s1.1 <= s2.1
} {
&count = count + 1
}
}
println("count: " + count.to_string())