use index assignment in existing code

This commit is contained in:
2026-03-11 15:40:05 +01:00
parent 930d7b56cc
commit 88915bbc8a
6 changed files with 67 additions and 74 deletions

View File

@@ -44,11 +44,11 @@ func part2[lines: array] : void
for y in 1..str.len(array.nth(lines, x))-1
if array.nth(lines, x)[y] == 'A'
let s: str = mem.alloc(5)
str.set(s, 0, array.nth(lines, x - 1)[y - 1])
str.set(s, 1, array.nth(lines, x + 1)[y - 1])
str.set(s, 2, array.nth(lines, x + 1)[y + 1])
str.set(s, 3, array.nth(lines, x - 1)[y + 1])
str.set(s, 4, 0)
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]
s[3] = array.nth(lines, x - 1)[y + 1]
s[4] = 0
if str.equal(s, "MSSM") || str.equal(s, "SMMS") || str.equal(s, "MMSS") || str.equal(s, "SSMM")
out = out + 1

View File

@@ -8,9 +8,9 @@ func part1[lines: array] : void
for j in 0..str.len(line)
for k in (j+1)..str.len(line)
let s: str = mem.alloc(3)
str.set(s, 0, line[j])
str.set(s, 1, line[k])
str.set(s, 2, 0)
s[0] = line[j]
s[1] = line[k]
s[2] = 0
let n: i64 = str.parse_i64(s)
if n > largest
largest = n