compute for's end only once

This commit is contained in:
2026-06-06 19:36:28 +02:00
parent 22874181cd
commit c41c22e936
4 changed files with 10 additions and 8 deletions

View File

@@ -39,11 +39,11 @@ func part1[lines: Array] : void
func part2[lines: Array] : void
out := 0
s := _stackalloc(5) as str
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'
s := _stackalloc(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

@@ -1,5 +1,6 @@
func part1[lines: Array] : void
sum := 0
s := _stackalloc(3) as str
for i in 0..lines->size
line : str = array.nth(lines, i)
@@ -7,7 +8,6 @@ func part1[lines: Array] : void
largest := 0
for j in 0..str.len(line)
for k in (j+1)..str.len(line)
s := _stackalloc(3) as str
s[0] = line[j]
s[1] = line[k]
s[2] = 0