mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
solved some AoC
This commit is contained in:
parent
46dbb13e0f
commit
217a527c01
24
examples/advent_of_code/2022/day3a.mers
Normal file
24
examples/advent_of_code/2022/day3a.mers
Normal 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())
|
||||||
|
|
32
examples/advent_of_code/2022/day3b.mers
Normal file
32
examples/advent_of_code/2022/day3b.mers
Normal 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())
|
||||||
|
|
21
examples/advent_of_code/2022/day4a.mers
Normal file
21
examples/advent_of_code/2022/day4a.mers
Normal 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())
|
29
examples/advent_of_code/2022/day4b.mers
Normal file
29
examples/advent_of_code/2022/day4b.mers
Normal 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())
|
Loading…
Reference in New Issue
Block a user