[Odin] Deep search, account for order, print when found[Odin] Deep search, account for order, print when found
🟩➕🟦
Square Sum
Week 36, 2026
package main
import "core:fmt"
List :: [dynamic; 25] int // 25 is the longest sequence (100/4)
SQUARES := [?] int { 4, 9, 16, 25, 36, 49, 64, 81 }
main :: proc () {
for n in 2*SQUARES[0]..=100 {
list: List
find(&list, n, n)
}
}
find :: proc (list: ^List, n, reminder: int, _i_start := 0) {
for i := _i_start; i < len(SQUARES); i += 1 {
s := SQUARES[i]
r := reminder - s
if r < 0 do break
append(list, s)
if r == 0 && len(list) > 1 do print(list^, n)
if r >= SQUARES[i] do find(list, n, r, i)
pop(list)
}
}
print :: proc (list: List, n: int) {
for s, i in list {
if i == 0 do fmt.print(n, "=")
if i > 0 do fmt.print(" +")
fmt.printf(" %i", s)
}
fmt.println()
}