1 # a solution for N=1000 to
2 # https://projecteuler.net/problem=14
3 # we use a fast local array to
4 # memoize small collatz numbers
11 %n =w phi @start 1, @newm %n9, @oldm %n9
12 %cmax =w phi @start 0, @newm %c, @oldm %cmax
13 %fin =w csltw %n, 1000
14 jnz %fin, @cloop, @end
16 %n0 =w phi @loop %n, @odd %n2, @even %n3
17 %c0 =w phi @loop 0, @odd %c1, @even %c1
19 jnz %no1, @iter0, @endcl
22 jnz %ism, @getmemo, @iter1
34 @getmemo # get the count for n0 in mem
37 %loc0 =l add %idx0, %mem
40 @endcl # store the count for n in mem
41 %c =w phi @getmemo %c2, @cloop %c0
44 %loc1 =l add %idx1, %mem
47 %big =w cslew %cmax, %c
48 jnz %big, @newm, @oldm
59 # extern void test(void);
61 # int main() { test(); return !(a == 178); }