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,5 +1,5 @@
func part1[l1: Array, l2: Array] : void
let out = 0
out := 0
for i in 0..l1->size
out = out + math.abs(array.nth(l1, i) - array.nth(l2, i))
@@ -7,7 +7,7 @@ func part1[l1: Array, l2: Array] : void
io.println_i64(out)
func part2[l1: Array, l2: Array] : void
let out = 0
out := 0
for i in 0..l1->size
out = out + array.nth(l1, i) * alg.count(l2, array.nth(l1, i))
@@ -15,15 +15,15 @@ func part2[l1: Array, l2: Array] : void
io.println_i64(out)
func main[] : i64
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
lines : Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let l1 = []
let l2 = []
l1 := []
l2 := []
for i in 0..lines->size
let line: str = array.nth(lines, i)
line : str = array.nth(lines, i)
let parts = str.split(line, " ")
parts := str.split(line, " ")
array.push(l1, str.parse_i64(array.nth(parts, 0)))
array.push(l2, str.parse_i64(array.nth(parts, 1)))

View File

@@ -1,5 +1,5 @@
func check[report: Array] : bool
let increasing = array.nth(report, 0) < array.nth(report, 1)
increasing := array.nth(report, 0) < array.nth(report, 1)
for i in 0..report->size-1
if array.nth(report, i) > array.nth(report, i + 1) && increasing
@@ -7,14 +7,14 @@ func check[report: Array] : bool
if array.nth(report, i) < array.nth(report, i + 1) && !increasing
return false
let diff = math.abs(array.nth(report, i) - array.nth(report, i + 1))
diff := math.abs(array.nth(report, i) - array.nth(report, i + 1))
if diff < 1 || diff > 3
return false
return true
func part1[data: Array] : void
let out = 0
out := 0
for i in 0..data->size
if check(array.nth(data, i))
@@ -23,15 +23,15 @@ func part1[data: Array] : void
io.println_i64(out)
func part2[data: Array] : void
let out = 0
out := 0
for i in 0..data->size
if check(array.nth(data, i))
out = out + 1
else
let arr: Array = array.nth(data, i)
arr : Array = array.nth(data, i)
for j in 0..arr->size
let sliced = array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
sliced := array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
if check(sliced)
out = out + 1
@@ -40,13 +40,13 @@ func part2[data: Array] : void
io.println_i64(out)
func main[] : i64
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
let data = []
data := []
for i in 0..lines->size
let line: str = array.nth(lines, i)
line : str = array.nth(lines, i)
let report = str.split(line, " ")
report := str.split(line, " ")
for i in 0..report->size
array.set(report, i, str.parse_i64(array.nth(report, i)))
array.push(data, report)

View File

@@ -14,7 +14,7 @@ func check[lines: Array, x: i64, y: i64, dx: i64, dy: i64] : bool
return true
func part1[lines: Array] : void
let out = 0
out := 0
for x in 0..lines->size
for y in 0..str.len(array.nth(lines, x))
@@ -38,12 +38,12 @@ func part1[lines: Array] : void
io.println_i64(out)
func part2[lines: Array] : void
let out = 0
out := 0
for x in 1..lines->size-1
for y in 1..str.len(array.nth(lines, x))-1
if array.nth(lines, x)[y] == 'A'
let s = mem.alloc(5) as str
s := mem.alloc(5) as str
s[0] = array.nth(lines, x - 1)[y - 1]
s[1] = array.nth(lines, x + 1)[y - 1]
s[2] = array.nth(lines, x + 1)[y + 1]
@@ -56,7 +56,7 @@ func part2[lines: Array] : void
io.println_i64(out)
func main[] : i64
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
lines : Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
part1(lines)
part2(lines)

View File

@@ -12,34 +12,34 @@ func check[update: Array, rules_left: Array, rules_right: Array] : bool
return true
func sort_by_rules[update: Array, rules_left: Array, rules_right: Array] : void
let swapped = true
swapped := true
while swapped
swapped = false
for i in 0..update->size-1
let a: i64 = array.nth(update, i)
let b: i64 = array.nth(update, i+1)
a : i64 = array.nth(update, i)
b : i64 = array.nth(update, i+1)
if rule_exists(rules_left, rules_right, b, a)
let tmp = a
tmp := a
array.set(update, i, b)
array.set(update, i+1, tmp)
swapped = true
func part1[updates: Array, rules_left: Array, rules_right: Array] : void
let out = 0
out := 0
for i in 0..updates->size
let update: Array = array.nth(updates, i)
update : Array = array.nth(updates, i)
if check(update, rules_left, rules_right)
out = out + array.nth(update, update->size / 2)
io.println_i64(out)
func part2[updates: Array, rules_left: Array, rules_right: Array] : void
let out = 0
out := 0
for i in 0..updates->size
let update: Array = array.nth(updates, i)
update : Array = array.nth(updates, i)
if !check(update, rules_left, rules_right)
sort_by_rules(update, rules_left, rules_right)
out = out + array.nth(update, update->size / 2)
@@ -47,23 +47,23 @@ func part2[updates: Array, rules_left: Array, rules_right: Array] : void
io.println_i64(out)
func main[] : i64
let data = must(io.read_text_file?("input.txt")) |> str.split("\n\n")
data := must(io.read_text_file?("input.txt")) |> str.split("\n\n")
let rules_left = []
let rules_right = []
let rules_lines = str.split(array.nth(data, 0), "\n")
rules_left := []
rules_right := []
rules_lines := str.split(array.nth(data, 0), "\n")
for i in 0..rules_lines->size
let line: str = array.nth(rules_lines, i)
let parts = str.split(line, "|")
line : str = array.nth(rules_lines, i)
parts := str.split(line, "|")
array.push(rules_left, str.parse_i64(array.nth(parts, 0)))
array.push(rules_right, str.parse_i64(array.nth(parts, 1)))
let updates = []
let updates_lines = str.split(array.nth(data, 1), "\n")
updates := []
updates_lines := str.split(array.nth(data, 1), "\n")
for i in 0..updates_lines->size
let line: str = array.nth(updates_lines, i)
let xs = str.split(line, ",")
line : str = array.nth(updates_lines, i)
xs := str.split(line, ",")
for i in 0..xs->size
array.set(xs, i, str.parse_i64(array.nth(xs, i)))

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)))

View File

@@ -1,11 +1,11 @@
func part1[lines: Array] : void
let password = 0
let dial = 50
password := 0
dial := 50
for i in 0..lines->size
let line: str = array.nth(lines, i)
let dir = line[0]
let n = str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
line : str = array.nth(lines, i)
dir := line[0]
n := str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
if dir == 'L'
dial = dial - n
@@ -22,13 +22,13 @@ func part1[lines: Array] : void
io.println_i64(password)
func part2[lines: Array] : void
let password = 0
let dial = 50
password := 0
dial := 50
for i in 0..lines->size
let line: str = array.nth(lines, i)
let dir = line[0]
let n = str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
line : str = array.nth(lines, i)
dir := line[0]
n := str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
if dir == 'L'
for i in 0..n
@@ -47,7 +47,7 @@ func part2[lines: Array] : void
io.println_i64(password)
func main[] : i64
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
part1(lines)
part2(lines)

View File

@@ -1,20 +1,20 @@
func part1_is_invalid_id[s: str] : bool
let len = str.len(s)
len := str.len(s)
if len % 2 != 0
return false
let first = str.substr(s, 0, len / 2)
let second = str.substr(s, len / 2, len / 2)
first := str.substr(s, 0, len / 2)
second := str.substr(s, len / 2, len / 2)
return str.equal(first, second)
func part1[ranges: Array] : void
let sum = 0
sum := 0
for i in 0..ranges->size
let parts = array.nth(ranges, i) |> str.split("-")
let start = array.nth(parts, 0) |> str.parse_i64()
let end = array.nth(parts, 1) |> str.parse_i64()
parts := array.nth(ranges, i) |> str.split("-")
start := array.nth(parts, 0) |> str.parse_i64()
end := array.nth(parts, 1) |> str.parse_i64()
for n in (start)..end+1
if part1_is_invalid_id(str.from_i64(n))
@@ -24,15 +24,15 @@ func part1[ranges: Array] : void
// had to cheat this one
func part2_is_invalid_id[s: str] : bool
let len = str.len(s)
len := str.len(s)
if len < 2
return false
for div in 1..(len / 2 + 1)
if len % div == 0
let u = str.substr(s, 0, div)
let is_repeat = true
u := str.substr(s, 0, div)
is_repeat := true
for k in 1..(len / div)
let segment = str.substr(s, k * div, div)
segment := str.substr(s, k * div, div)
if !str.equal(segment, u)
is_repeat = false
if is_repeat
@@ -40,12 +40,12 @@ func part2_is_invalid_id[s: str] : bool
return false
func part2[ranges: Array] : void
let sum = 0
sum := 0
for i in 0..ranges->size
let parts = array.nth(ranges, i) |> str.split("-")
let start = array.nth(parts, 0) |> str.parse_i64()
let end = array.nth(parts, 1) |> str.parse_i64()
parts := array.nth(ranges, i) |> str.split("-")
start := array.nth(parts, 0) |> str.parse_i64()
end := array.nth(parts, 1) |> str.parse_i64()
for n in (start)..end+1
if part2_is_invalid_id(str.from_i64(n))
@@ -54,7 +54,7 @@ func part2[ranges: Array] : void
io.println_i64(sum)
func main[] : i64
let ranges = must(io.read_text_file?("input.txt")) |> str.split(",")
ranges := must(io.read_text_file?("input.txt")) |> str.split(",")
part1(ranges)
part2(ranges)

View File

@@ -1,17 +1,17 @@
func part1[lines: Array] : void
let sum = 0
sum := 0
for i in 0..lines->size
let line: str = array.nth(lines, i)
line : str = array.nth(lines, i)
let largest = 0
largest := 0
for j in 0..str.len(line)
for k in (j+1)..str.len(line)
let s = mem.alloc(3) as str
s := mem.alloc(3) as str
s[0] = line[j]
s[1] = line[k]
s[2] = 0
let n = str.parse_i64(s)
n := str.parse_i64(s)
if n > largest
largest = n
@@ -20,12 +20,12 @@ func part1[lines: Array] : void
// had to cheat this one
func part2_rec[bank: str, start: i64, remaining: i64] : i64
let largest = 0
let largest_idx = start
let len = str.len(bank)
largest := 0
largest_idx := start
len := str.len(bank)
for i in (start)..(len-remaining+1)
let v = (bank[i] - '0') as i64
v := (bank[i] - '0') as i64
if v > largest
largest = v
largest_idx = i
@@ -36,16 +36,16 @@ func part2_rec[bank: str, start: i64, remaining: i64] : i64
return largest
func part2[lines: Array] : void
let sum = 0
sum := 0
for i in 0..lines->size
let line: str = array.nth(lines, i)
line : str = array.nth(lines, i)
sum = sum + part2_rec(line, 0, 12)
io.println_i64(sum)
func main[] : i64
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
part1(lines)
part2(lines)

View File

@@ -1,5 +1,5 @@
func main[] : i64
let sum = 0
sum := 0
for i in 0..266000
if i % 2 != 0

View File

@@ -1,5 +1,5 @@
func main[] : i64
let sum = 0
sum := 0
for i in 0..1000
if i % 5 == 0 || i % 3 == 0

View File

@@ -1,12 +1,12 @@
func main[] : i64
let sum = 0
let a = 0
let b = 1
sum := 0
a := 0
b := 1
while a < 4000000
if a % 2 == 0
sum = sum + a
let temp = b
temp := b
b = a + b
a = temp

View File

@@ -1,6 +1,6 @@
func main[] : i64
let n = 600851475143
let f = 2
n := 600851475143
f := 2
while f * f <= n
if n % f == 0

View File

@@ -1,11 +1,11 @@
func main[] : i64
let out = 0
out := 0
for a in 500..1000
for b in 500..1000
if a * b > out
let s = str.from_i64(a * b)
let s_rev = str.reverse(s)
s := str.from_i64(a * b)
s_rev := str.reverse(s)
if str.equal(s, s_rev)
out = a * b
mem.free(s)

View File

@@ -1,5 +1,5 @@
func main[] : i64
let out = 1
out := 1
for i in 1..21
out = math.lcm(out, i)

View File

@@ -1,9 +1,9 @@
func main[] : i64
let sum_of_squares = 0
sum_of_squares := 0
for i in 1..101
sum_of_squares = sum_of_squares + i * i
let square_of_sum = 0
square_of_sum := 0
for i in 1..101
square_of_sum = square_of_sum + i
square_of_sum = square_of_sum * square_of_sum

View File

@@ -1,7 +1,7 @@
func main[] : i64
let found = 0
found := 0
let i = 1
i := 1
while true
if math.is_prime(i)
found = found + 1

View File

@@ -1,11 +1,11 @@
func main[] : i64
let n = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
n := "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
let out = 0
let max = str.len(n) - 13
out := 0
max := str.len(n) - 13
for i in 0..max
let s = 1
let j = 0
s := 1
j := 0
while j < 13
s = s * (n[i + j] - '0')
j = j + 1

View File

@@ -1,7 +1,7 @@
func main[] : i64
for a in 1..1000
for b in 1..1000
let c = 1000 - b - a
c := 1000 - b - a
if a * a + b * b == c * c
io.println_i64(a * b * c)
return 0

View File

@@ -1,5 +1,5 @@
func main[] : i64
let sum = 0
sum := 0
for i in 0..2000000
if math.is_prime(i)

View File

@@ -1,7 +1,7 @@
func main[] : i64
let N = 20
N := 20
let grid = []
grid := []
array.push(grid, [8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8])
array.push(grid, [49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0])
array.push(grid, [81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65])
@@ -23,14 +23,14 @@ func main[] : i64
array.push(grid, [20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54])
array.push(grid, [1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48])
let out = 0
out := 0
for i in 0..N-3
for j in 0..N-3
let h: i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i), j+1) * array.nth(array.nth(grid, i), j+2) * array.nth(array.nth(grid, i), j+3)
let v: i64 = array.nth(array.nth(grid, j), i) * array.nth(array.nth(grid, j+1), i) * array.nth(array.nth(grid, j+2), i) * array.nth(array.nth(grid, j+3), i)
let d1: i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i+1), j+1) * array.nth(array.nth(grid, i+2), j+2) * array.nth(array.nth(grid, i+3), j+3)
let d2: i64 = array.nth(array.nth(grid, i), N-j-1) * array.nth(array.nth(grid, i+1), N-j-2) * array.nth(array.nth(grid, i+2), N-j-3) * array.nth(array.nth(grid, i+3), N-j-4)
h : i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i), j+1) * array.nth(array.nth(grid, i), j+2) * array.nth(array.nth(grid, i), j+3)
v : i64 = array.nth(array.nth(grid, j), i) * array.nth(array.nth(grid, j+1), i) * array.nth(array.nth(grid, j+2), i) * array.nth(array.nth(grid, j+3), i)
d1 : i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i+1), j+1) * array.nth(array.nth(grid, i+2), j+2) * array.nth(array.nth(grid, i+3), j+3)
d2 : i64 = array.nth(array.nth(grid, i), N-j-1) * array.nth(array.nth(grid, i+1), N-j-2) * array.nth(array.nth(grid, i+2), N-j-3) * array.nth(array.nth(grid, i+3), N-j-4)
out = math.max(out, math.max(h, math.max(v, math.max(d1, d2))))
io.println_i64(out)

View File

@@ -1,7 +1,7 @@
func num_divisors[n: i64] : i64
let end = math.isqrt(n)
end := math.isqrt(n)
let out = 0
out := 0
for i in 1..end+1
if n % i == 0
out = out + 2
@@ -11,8 +11,8 @@ func num_divisors[n: i64] : i64
return out
func main[] : i64
let n = 0
let i = 1
n := 0
i := 1
while true
n = n + i
if num_divisors(n) > 500

View File

@@ -4,18 +4,18 @@ func collatz_num[n: i64] : i64
return n * 3 + 1
func collatz_seq[n: i64]: i64
let i = 1
i := 1
while n != 1
n = collatz_num(n)
i = i + 1
return i
func main[] : i64
let max = 0
let max_index = 0
max := 0
max_index := 0
for i in 1..1000000
let seq = collatz_seq(i)
seq := collatz_seq(i)
if seq > max
max = seq
max_index = i

View File

@@ -1,7 +1,7 @@
func main[] : i64
let n = 40
let r = 20
let out = 1
n := 40
r := 20
out := 1
for i in 1..r+1
out = out * (n - (r - i)) / i

View File

@@ -1,18 +1,18 @@
func main[] : i64
let n = []
n := []
array.push(n, 1)
for j in 0..1000
let carry = 0
carry := 0
for i in 0..n->size
let tmp: i64 = array.nth(n, i) * 2 + carry
tmp : i64 = array.nth(n, i) * 2 + carry
array.set(n, i, tmp % 10)
carry = tmp / 10
while carry > 0
array.push(n, carry % 10)
carry = carry / 10
let sum = 0
sum := 0
for i in 0..n->size
sum = sum + array.nth(n, i)

View File

@@ -1,9 +1,9 @@
func main[] : i64
let s1 = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4]
let s2 = [3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
let s3 = [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]
s1 := [0, 3, 3, 5, 4, 4, 3, 5, 5, 4]
s2 := [3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
s3 := [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]
let sum = 0
sum := 0
for i in 1..10
sum = sum + array.nth(s1, i)

View File

@@ -2,13 +2,13 @@ func findmax[triangle: Array, row: i64, col: i64] : i64
if row == 14
return array.nth(array.nth(triangle, row), col)
let left = findmax(triangle, row + 1, col)
let right = findmax(triangle, row + 1, col + 1)
left := findmax(triangle, row + 1, col)
right := findmax(triangle, row + 1, col + 1)
return array.nth(array.nth(triangle, row), col) + math.max(left, right)
func main[] : i64
let triangle = []
triangle := []
array.push(triangle, [75])
array.push(triangle, [95, 64])
array.push(triangle, [17, 47, 82])

View File

@@ -10,8 +10,8 @@ func days[y: i64, m: i64] : i64
return 31
func main[] : i64
let wday = 0
let sun = 0
wday := 0
sun := 0
for year in 1901..2001
for mon in 1..13

View File

@@ -1,7 +1,7 @@
func multiply[n: Array, x: i64] : void
let carry = 0
carry := 0
for i in 0..n->size
let prod: i64 = array.nth(n, i) * x + carry
prod : i64 = array.nth(n, i) * x + carry
array.set(n, i, prod % 10)
carry = prod / 10
while carry > 0
@@ -9,12 +9,12 @@ func multiply[n: Array, x: i64] : void
carry = carry / 10
func main[] : i64
let n = [1]
n := [1]
for i in 2..101
multiply(n, i)
let sum = 0
sum := 0
for i in 0..n->size
sum = sum + array.nth(n, i)

View File

@@ -1,9 +1,9 @@
func divisors_sum[n: i64] : i64
let k = n
let sum = 1
k := n
sum := 1
for i in 2..k+1
let p = 1
p := 1
while k % i == 0
p = p * i
k = k / i
@@ -11,10 +11,10 @@ func divisors_sum[n: i64] : i64
return sum - n
func main[] : i64
let sum = 0
sum := 0
for i in 2..10000
let d = divisors_sum(i)
d := divisors_sum(i)
if i < d && i == divisors_sum(d)
sum = sum + i + d