new var declaration syntax

This commit is contained in:
2026-05-27 20:25:58 +02:00
parent 284bc61f24
commit 4fda79f0bc
48 changed files with 450 additions and 449 deletions

View File

@@ -1,8 +1,8 @@
func concat[a: i64, b: i64] : i64
let a_str = str.from_i64(a)
let b_str = str.from_i64(b)
let ab_str = str.concat(a_str, b_str)
let out = str.parse_i64(ab_str)
a_str := str.from_i64(a)
b_str := str.from_i64(b)
ab_str := str.concat(a_str, b_str)
out := str.parse_i64(ab_str)
// without freeing the program works but leaks 2GB of memory :p
mem.free(a_str)
mem.free(b_str)
@@ -10,16 +10,16 @@ func concat[a: i64, b: i64] : i64
return out
func solve[ops: Array, e: Array] : i64
let e_1: Array = array.nth(e, 1)
let n = e_1->size - 1
let indices = []
e_1 : Array = array.nth(e, 1)
n := e_1->size - 1
indices := []
for i in 0..n
array.push(indices, 0)
while true
let res: i64 = array.nth(e_1, 0)
res : i64 = array.nth(e_1, 0)
for i in 0..n
let op: str = array.nth(ops, array.nth(indices, i))
op : str = array.nth(ops, array.nth(indices, i))
if str.equal(op, "add")
res = res + array.nth(e_1, i + 1)
@@ -30,8 +30,8 @@ func solve[ops: Array, e: Array] : i64
if res == array.nth(e, 0)
return res
let done = true
let i = n - 1
done := true
i := n - 1
while i >= 0
array.set(indices, i, array.nth(indices, i) + 1)
@@ -45,7 +45,7 @@ func solve[ops: Array, e: Array] : i64
return 0
func part1[equations: Array] : void
let out = 0
out := 0
for i in 0..equations->size
out = out + solve(["add", "mul"], array.nth(equations, i))
@@ -53,7 +53,7 @@ func part1[equations: Array] : void
io.println_i64(out)
func part2[equations: Array] : void
let out = 0
out := 0
for i in 0..equations->size
out = out + solve(["add", "mul", "concat"], array.nth(equations, i))
@@ -61,14 +61,14 @@ func part2[equations: Array] : void
io.println_i64(out)
func main[] : i64
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
let equations = []
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
equations := []
for i in 0..lines->size
let line: str = array.nth(lines, i)
let parts = str.split(line, ": ")
line : str = array.nth(lines, i)
parts := str.split(line, ": ")
let xs = str.split(array.nth(parts, 1), " ")
xs := str.split(array.nth(parts, 1), " ")
for j in 0..xs->size
array.set(xs, j, str.parse_i64(array.nth(xs, j)))