type inference for variables

This commit is contained in:
2026-05-13 14:01:44 +02:00
parent 5f2082ef57
commit 027245684d
37 changed files with 304 additions and 302 deletions

View File

@@ -1,15 +1,15 @@
func main[] : i64
// https://brainfuck.org/sierpinski.b
let src: str = "++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<]>.>+[>>]>+]"
let src_len: i64 = str.len(src)
let src = "++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<]>.>+[>>]>+]"
let src_len = str.len(src)
let i = 0
let memory: ptr = mem.alloc(30000)
let memory = mem.alloc(30000)
mem.zero(memory, 30000)
let p = 0
while i < src_len
let op: u8 = src[i]
let op = src[i]
if op == '>'
p = p + 1

View File

@@ -22,7 +22,7 @@ struct CHIP8
keyboard_map: Array
func chip8_create[] : CHIP8
let c: CHIP8 = new CHIP8
let c = new CHIP8
c->memory = mem.alloc(4096)
mem.zero(c->memory, 4096)
c->display = mem.alloc(64*32)
@@ -33,7 +33,7 @@ func chip8_create[] : CHIP8
c->stack = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
c->keyboard = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let fonts: Array = [0xf0, 0x90, 0x90, 0x90, 0xf0, 0x20, 0x60, 0x20, 0x20, 0x70, 0xf0, 0x10, 0xf0, 0x80, 0xf0, 0xf0, 0x10, 0xf0, 0x10, 0xf0, 0x90, 0x90, 0xf0, 0x10, 0x10, 0xf0, 0x80, 0xf0, 0x10, 0xf0, 0xf0, 0x80, 0xf0, 0x90, 0xf0, 0xf0, 0x10, 0x20, 0x40, 0x40, 0xf0, 0x90, 0xf0, 0x90, 0xf0, 0xf0, 0x90, 0xf0, 0x10, 0xf0, 0xf0, 0x90, 0xf0, 0x90, 0x90, 0xe0, 0x90, 0xe0, 0x90, 0xe0, 0xf0, 0x80, 0x80, 0x80, 0xf0, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0xf0, 0x80, 0xf0, 0x80, 0xf0, 0xf0, 0x80, 0xf0, 0x80, 0x80]
let fonts = [0xf0, 0x90, 0x90, 0x90, 0xf0, 0x20, 0x60, 0x20, 0x20, 0x70, 0xf0, 0x10, 0xf0, 0x80, 0xf0, 0xf0, 0x10, 0xf0, 0x10, 0xf0, 0x90, 0x90, 0xf0, 0x10, 0x10, 0xf0, 0x80, 0xf0, 0x10, 0xf0, 0xf0, 0x80, 0xf0, 0x90, 0xf0, 0xf0, 0x10, 0x20, 0x40, 0x40, 0xf0, 0x90, 0xf0, 0x90, 0xf0, 0xf0, 0x90, 0xf0, 0x10, 0xf0, 0xf0, 0x90, 0xf0, 0x90, 0x90, 0xe0, 0x90, 0xe0, 0x90, 0xe0, 0xf0, 0x80, 0x80, 0x80, 0xf0, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0xf0, 0x80, 0xf0, 0x80, 0xf0, 0xf0, 0x80, 0xf0, 0x80, 0x80]
for i in 0..80
c->memory[i] = array.nth(fonts, i)
mem.free(fonts)
@@ -58,18 +58,18 @@ func chip8_disassemble[c: CHIP8, ins_count: i64] : void
for i in 0..ins_count
io.printf("0x%x: ", c->pc)
let high: i64 = c->memory[c->pc] as i64
let low: i64 = c->memory[c->pc + 1] as i64
let high = c->memory[c->pc] as i64
let low = c->memory[c->pc + 1] as i64
c->pc = c->pc + 2
let ins: i64 = (high << 8) | low
let nnn: i64 = ins & 0x0fff
let kk: i64 = ins & 0x00ff
let n: i64 = ins & 0x000f
let x: i64 = (ins >> 8) & 0x0f
let y: i64 = (ins >> 4) & 0x0f
let ins = (high << 8) | low
let nnn = ins & 0x0fff
let kk = ins & 0x00ff
let n = ins & 0x000f
let x = (ins >> 8) & 0x0f
let y = (ins >> 4) & 0x0f
let op: i64 = (ins >> 12) & 0x0f
let op = (ins >> 12) & 0x0f
if op == 0x0
if nnn == 0x0e0
io.println("CLS")
@@ -154,18 +154,18 @@ func chip8_disassemble[c: CHIP8, ins_count: i64] : void
io.printf("??? (%x)\n", ins)
func chip8_step[c: CHIP8] : void
let high: i64 = c->memory[c->pc] as i64
let low: i64 = c->memory[c->pc + 1] as i64
let high = c->memory[c->pc] as i64
let low = c->memory[c->pc + 1] as i64
c->pc = c->pc + 2
let ins: i64 = (high << 8) | low
let nnn: i64 = ins & 0x0fff
let kk: i64 = ins & 0x00ff
let n: i64 = ins & 0x000f
let x: i64 = (ins >> 8) & 0x0f
let y: i64 = (ins >> 4) & 0x0f
let ins = (high << 8) | low
let nnn = ins & 0x0fff
let kk = ins & 0x00ff
let n = ins & 0x000f
let x = (ins >> 8) & 0x0f
let y = (ins >> 4) & 0x0f
let op: i64 = (ins >> 12) & 0x0f
let op = (ins >> 12) & 0x0f
if op == 0x0
if nnn == 0x0e0
mem.zero(c->display, 64 * 32)
@@ -232,7 +232,7 @@ func chip8_step[c: CHIP8] : void
if (c->memory[c->I + row] & (0x80 >> col)) != 0
let pixel_x: u8 = (c->reg[x] + col) % 64
let pixel_y: u8 = (c->reg[y] + row) % 32
let offset: i64 = pixel_x as i64 + (pixel_y * 64)
let offset = pixel_x as i64 + (pixel_y * 64)
if c->display[offset] == 1
c->reg[0xf] = 1
@@ -248,7 +248,7 @@ func chip8_step[c: CHIP8] : void
if kk == 0x07
c->reg[x] = c->delay_timer
else if kk == 0x0A
let key_pressed: bool = false
let key_pressed = false
while !key_pressed && !WindowShouldClose()
for i in 0..16
if IsKeyDown(array.nth(c->keyboard_map, i))
@@ -274,11 +274,11 @@ func chip8_step[c: CHIP8] : void
c->reg[i] = c->memory[c->I + i]
func main[argc: i64, argv: ptr] : i64
let path: str = 0 as str
let disassemble: bool = false
let path = 0 as str
let disassemble = false
for i in 1..argc
let arg: str = mem.read64(argv + i * 8) as str
let arg = mem.read64(argv + i * 8) as str
if str.equal(arg, "-d")
disassemble = true
else
@@ -288,7 +288,7 @@ func main[argc: i64, argv: ptr] : i64
io.println("Usage: chip8 -d <path>")
return 1
let c: CHIP8 = chip8_create()
let c = chip8_create()
let buffer: io.Buffer = must(io.read_binary_file?(path))

View File

@@ -3,7 +3,7 @@ func main[argc: i64, argv: ptr] : i64
io.println("ERROR: url is missing")
return 1
let url: str = mem.read64(argv + 8) as str
let url = mem.read64(argv + 8) as str
if str.len(url) <= 7
io.println("ERROR: invalid url (Did you forget \"http://\"?)")
@@ -13,16 +13,16 @@ func main[argc: i64, argv: ptr] : i64
io.println("ERROR: only http scheme is supported")
return 1
let url_len: i64 = str.len(url)
let url_len = str.len(url)
let host_start = 7
let i: i64 = host_start
let i = host_start
while i < url_len
if url[i] == '/'
break
i = i + 1
let host: str = str.substr(url, host_start, i - host_start)
let path: str = "/"
let host = str.substr(url, host_start, i - host_start)
let path = "/"
if i < url_len
path = str.substr(url, i, url_len - i)
@@ -31,7 +31,7 @@ func main[argc: i64, argv: ptr] : i64
let s: i64 = must(net.connect?(addr, 80))
// TODO: add string builder to std
let req: str = "GET "
let req = "GET "
req = str.concat(req, path)
req = str.concat(req, " HTTP/1.0\r\nHost: ")
req = str.concat(req, host)
@@ -39,16 +39,16 @@ func main[argc: i64, argv: ptr] : i64
net.send(s, req as ptr, str.len(req))
mem.free(req)
let header_buf: str = mem.alloc(8192) as str
let header_buf = mem.alloc(8192) as str
let header_size = 0
let found: bool = false
let end_index: i64 = -1
let found = false
let end_index = -1
while !found && header_size < 8192
let n: i64 = net.read(s, header_buf as ptr + header_size, 8192 - header_size)
let n = net.read(s, header_buf as ptr + header_size, 8192 - header_size)
if n <= 0
break
let current_size: i64 = header_size + n
let current_size = header_size + n
i = 0
while i <= current_size - 4
if header_buf[i] == '\r' && header_buf[i + 1] == '\n' && header_buf[i + 2] == '\r' && header_buf[i + 3] == '\n'
@@ -62,9 +62,9 @@ func main[argc: i64, argv: ptr] : i64
io.print_sized(header_buf as ptr + end_index, header_size as i64 - end_index)
mem.free(header_buf)
let buffer: ptr = mem.alloc(4096)
let buffer = mem.alloc(4096)
while true
let n: i64 = net.read(s, buffer, 4096)
let n = net.read(s, buffer, 4096)
if n <= 0
break
io.print_sized(buffer, n)

View File

@@ -4,6 +4,6 @@ func main[] : i64
while a < 100000
io.println_i64(a)
let temp: i64 = b
let temp = b
b = a + b
a = temp

View File

@@ -1,9 +1,9 @@
func main[] : i64
let answer: i64 = math.abs(os.urandom_i64()) % 100
let answer = math.abs(os.urandom_i64()) % 100
while true
io.println("Guess a number: ")
let guess: i64 = io.read_line() |> str.trim() |> str.parse_i64()
let guess = io.read_line() |> str.trim() |> str.parse_i64()
if guess == answer
io.println("You win!")

View File

@@ -17,13 +17,13 @@ func part2[l1: Array, l2: Array] : void
func main[] : i64
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let l1: Array = []
let l2: Array = []
let l1 = []
let l2 = []
for i in 0..lines->size
let line: str = array.nth(lines, i)
let parts: Array = str.split(line, " ")
let 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: bool = array.nth(report, 0) < array.nth(report, 1)
let 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,7 +7,7 @@ func check[report: Array] : bool
if array.nth(report, i) < array.nth(report, i + 1) && !increasing
return false
let diff: i64 = math.abs(array.nth(report, i) - array.nth(report, i + 1))
let diff = math.abs(array.nth(report, i) - array.nth(report, i + 1))
if diff < 1 || diff > 3
return false
@@ -31,7 +31,7 @@ func part2[data: Array] : void
else
let arr: Array = array.nth(data, i)
for j in 0..arr->size
let sliced: Array = array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
let 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: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
let data: Array = []
let data = []
for i in 0..lines->size
let line: str = array.nth(lines, i)
let report: Array = str.split(line, " ")
let 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

@@ -43,7 +43,7 @@ func part2[lines: Array] : void
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: str = mem.alloc(5) as str
let 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]

View File

@@ -12,7 +12,7 @@ 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: bool = true
let swapped = true
while swapped
swapped = false
@@ -20,7 +20,7 @@ func sort_by_rules[update: Array, rules_left: Array, rules_right: Array] : void
let a: i64 = array.nth(update, i)
let b: i64 = array.nth(update, i+1)
if rule_exists(rules_left, rules_right, b, a)
let tmp: i64 = a
let tmp = a
array.set(update, i, b)
array.set(update, i+1, tmp)
swapped = true
@@ -47,23 +47,23 @@ func part2[updates: Array, rules_left: Array, rules_right: Array] : void
io.println_i64(out)
func main[] : i64
let data: Array = must(io.read_text_file?("input.txt")) |> str.split("\n\n")
let data = must(io.read_text_file?("input.txt")) |> str.split("\n\n")
let rules_left: Array = []
let rules_right: Array = []
let rules_lines: Array = str.split(array.nth(data, 0), "\n")
let rules_left = []
let rules_right = []
let 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: Array = str.split(line, "|")
let 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: Array = []
let updates_lines: Array = str.split(array.nth(data, 1), "\n")
let updates = []
let 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: Array = str.split(line, ",")
let 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 = str.from_i64(a)
let b_str: str = str.from_i64(b)
let ab_str: str = str.concat(a_str, b_str)
let out: i64 = str.parse_i64(ab_str)
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)
// without freeing the program works but leaks 2GB of memory :p
mem.free(a_str)
mem.free(b_str)
@@ -11,8 +11,8 @@ func concat[a: i64, b: i64] : i64
func solve[ops: Array, e: Array] : i64
let e_1: Array = array.nth(e, 1)
let n: i64 = e_1->size - 1
let indices: Array = []
let n = e_1->size - 1
let indices = []
for i in 0..n
array.push(indices, 0)
@@ -30,8 +30,8 @@ func solve[ops: Array, e: Array] : i64
if res == array.nth(e, 0)
return res
let done: bool = true
let i: i64 = n - 1
let done = true
let i = n - 1
while i >= 0
array.set(indices, i, array.nth(indices, i) + 1)
@@ -61,14 +61,14 @@ func part2[equations: Array] : void
io.println_i64(out)
func main[] : i64
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let equations: Array = []
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
let equations = []
for i in 0..lines->size
let line: str = array.nth(lines, i)
let parts: Array = str.split(line, ": ")
let parts = str.split(line, ": ")
let xs: Array = str.split(array.nth(parts, 1), " ")
let 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

@@ -4,8 +4,8 @@ func part1[lines: Array] : void
for i in 0..lines->size
let line: str = array.nth(lines, i)
let dir: u8 = line[0]
let n: i64 = str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
let dir = line[0]
let n = str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
if dir == 'L'
dial = dial - n
@@ -27,8 +27,8 @@ func part2[lines: Array] : void
for i in 0..lines->size
let line: str = array.nth(lines, i)
let dir: u8 = line[0]
let n: i64 = str.substr(line, 1, str.len(line) - 1) |> str.parse_i64()
let dir = line[0]
let 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: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
part1(lines)
part2(lines)

View File

@@ -1,10 +1,10 @@
func part1_is_invalid_id[s: str] : bool
let len: i64 = str.len(s)
let len = str.len(s)
if len % 2 != 0
return false
let first: str = str.substr(s, 0, len / 2)
let second: str = str.substr(s, len / 2, len / 2)
let first = str.substr(s, 0, len / 2)
let second = str.substr(s, len / 2, len / 2)
return str.equal(first, second)
@@ -12,9 +12,9 @@ func part1[ranges: Array] : void
let sum = 0
for i in 0..ranges->size
let parts: Array = array.nth(ranges, i) |> str.split("-")
let start: i64 = array.nth(parts, 0) |> str.parse_i64()
let end: i64 = array.nth(parts, 1) |> str.parse_i64()
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()
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: i64 = str.len(s)
let len = str.len(s)
if len < 2
return false
for div in 1..(len / 2 + 1)
if len % div == 0
let u: str = str.substr(s, 0, div)
let is_repeat: bool = true
let u = str.substr(s, 0, div)
let is_repeat = true
for k in 1..(len / div)
let segment: str = str.substr(s, k * div, div)
let segment = str.substr(s, k * div, div)
if !str.equal(segment, u)
is_repeat = false
if is_repeat
@@ -43,9 +43,9 @@ func part2[ranges: Array] : void
let sum = 0
for i in 0..ranges->size
let parts: Array = array.nth(ranges, i) |> str.split("-")
let start: i64 = array.nth(parts, 0) |> str.parse_i64()
let end: i64 = array.nth(parts, 1) |> str.parse_i64()
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()
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: Array = must(io.read_text_file?("input.txt")) |> str.split(",")
let ranges = must(io.read_text_file?("input.txt")) |> str.split(",")
part1(ranges)
part2(ranges)

View File

@@ -7,11 +7,11 @@ func part1[lines: Array] : void
let largest = 0
for j in 0..str.len(line)
for k in (j+1)..str.len(line)
let s: str = mem.alloc(3) as str
let s = mem.alloc(3) as str
s[0] = line[j]
s[1] = line[k]
s[2] = 0
let n: i64 = str.parse_i64(s)
let n = str.parse_i64(s)
if n > largest
largest = n
@@ -21,11 +21,11 @@ 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: i64 = start
let len: i64 = str.len(bank)
let largest_idx = start
let len = str.len(bank)
for i in (start)..(len-remaining+1)
let v: i64 = (bank[i] - '0') as i64
let v = (bank[i] - '0') as i64
if v > largest
largest = v
largest_idx = i
@@ -45,7 +45,7 @@ func part2[lines: Array] : void
io.println_i64(sum)
func main[] : i64
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
part1(lines)
part2(lines)

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
func main[] : i64
let N = 20
let grid: Array = []
let 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])

View File

@@ -1,5 +1,5 @@
func num_divisors[n: i64] : i64
let end: i64 = math.isqrt(n)
let end = math.isqrt(n)
let out = 0
for i in 1..end+1

View File

@@ -15,7 +15,7 @@ func main[] : i64
let max_index = 0
for i in 1..1000000
let seq: i64 = collatz_seq(i)
let seq = collatz_seq(i)
if seq > max
max = seq
max_index = i

View File

@@ -1,5 +1,5 @@
func main[] : i64
let n: Array = []
let n = []
array.push(n, 1)
for j in 0..1000

View File

@@ -1,7 +1,7 @@
func main[] : i64
let s1: Array = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4]
let s2: Array = [3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
let s3: Array = [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]
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]
let sum = 0

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: i64 = findmax(triangle, row + 1, col)
let right: i64 = findmax(triangle, row + 1, col + 1)
let left = findmax(triangle, row + 1, col)
let right = findmax(triangle, row + 1, col + 1)
return array.nth(array.nth(triangle, row), col) + math.max(left, right)
func main[] : i64
let triangle: Array = []
let triangle = []
array.push(triangle, [75])
array.push(triangle, [95, 64])
array.push(triangle, [17, 47, 82])

View File

@@ -9,7 +9,7 @@ func multiply[n: Array, x: i64] : void
carry = carry / 10
func main[] : i64
let n: Array = [1]
let n = [1]
for i in 2..101
multiply(n, i)

View File

@@ -1,5 +1,5 @@
func divisors_sum[n: i64] : i64
let k: i64 = n
let k = n
let sum = 1
for i in 2..k+1
@@ -14,7 +14,7 @@ func main[] : i64
let sum = 0
for i in 2..10000
let d: i64 = divisors_sum(i)
let d = divisors_sum(i)
if i < d && i == divisors_sum(d)
sum = sum + i + d

View File

@@ -1,5 +1,5 @@
func main[] : i64
let arr: Array = []
let arr = []
for i in 0..10
array.push(arr, math.abs(os.urandom_i64()) % 1000)

View File

@@ -1,12 +1,12 @@
func rule110_step[state: Array] : Array
let new_state: Array = []
let new_state = []
for i in 0..state->size
let left: bool = false
let left = false
if i - 1 >= 0
left = array.nth(state, i - 1)
let center: bool = array.nth(state, i)
let right: bool = false
let right = false
if i + 1 < state->size
right = array.nth(state, i + 1)
@@ -25,7 +25,7 @@ func print_state[state: Array]: void
func main[] : i64
let SIZE = 60
let state: Array = []
let state = []
for i in 0..SIZE
array.push(state, false)
array.push(state, true)

View File

@@ -30,7 +30,7 @@ func main[] : i64
io.println("0. Quit")
io.print("\n> ")
let choice: i64 = io.read_line() |> str.parse_i64()
let choice = io.read_line() |> str.parse_i64()
if choice == 0
break
@@ -39,8 +39,8 @@ func main[] : i64
sqlite3_prepare_v2(db, "SELECT * FROM todo", -1, ^stmt, 0)
while sqlite3_step(stmt) == 100
let id: i64 = sqlite3_column_int(stmt, 0)
let task: str = sqlite3_column_text(stmt, 1)
let id = sqlite3_column_int(stmt, 0)
let task = sqlite3_column_text(stmt, 1)
io.print_i64(id)
io.print(" - ")
@@ -49,7 +49,7 @@ func main[] : i64
io.println("============")
else if choice == 2
io.print("\nEnter new task: ")
let task: str = io.read_line() |> str.trim()
let task = io.read_line() |> str.trim()
sqlite3_prepare_v2(db, "INSERT INTO todo(task) VALUES (?);", -1, ^stmt, 0)
sqlite3_bind_text(stmt, 1, task, -1, 0)
@@ -59,7 +59,7 @@ func main[] : i64
io.println("\nTask added\n")
else if choice == 3
io.print("\nEnter task id: ")
let id: i64 = io.read_line() |> str.parse_i64()
let id = io.read_line() |> str.parse_i64()
sqlite3_prepare_v2(db, "DELETE FROM todo WHERE id = ?;", -1, ^stmt, 0)
sqlite3_bind_int(stmt, 1, id, -1, 0)

View File

@@ -2,12 +2,12 @@ func main[] : i64
let s: i64 = must(net.listen?(net.pack_addr(127, 0, 0, 1), 8000))
io.println("Listening on port 8000...")
let resp: ptr = mem.alloc(60000)
let resp = mem.alloc(60000)
while true
let conn: i64 = net.accept(s)
let conn = net.accept(s)
if conn < 0
continue
let n: i64 = net.read(conn, resp, 60000)
let n = net.read(conn, resp, 60000)
net.send(conn, resp, n)
net.close(conn)

View File

@@ -3,7 +3,7 @@ func main[] : i64
io.println("Listening on port 8000...")
while true
let pkt: net.UDPPacket = net.udp_receive(s, 60000)
let pkt = net.udp_receive(s, 60000)
if pkt->size <= 0
net.UDPPacket.free(pkt)
continue