changed regex builtin and added binaries to git repo

This commit is contained in:
Mark
2023-06-29 15:16:31 -04:00
parent f0314817a2
commit b6d01c7c25
17 changed files with 245 additions and 228 deletions

View File

@@ -1,24 +0,0 @@
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

@@ -1,32 +0,0 @@
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

@@ -1,21 +0,0 @@
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

@@ -1,29 +0,0 @@
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())

View File

@@ -16,7 +16,7 @@ fn rnd() {
}
words := rnd()
for word text.regex("\\S+").assume_no_enum()
for word regex("\\S+").assume_no_enum().run(text)
if words > 0 {
print(word + " ")
&words = words - 1