...I'm still lost with #110 and #118 (and some other problems), so I'll started with 154:
Code: Select all
Procedure Problem_154(n)
#size=2000
#mid=#size>>1
minx=#mid
miny=#mid
maxx=#mid
maxy=#mid
#modulo=1000000000000
Dim A.q(#size,#size); (x+y+z)^n | n=0, 3, 6, ...
Dim B.q(#size,#size); (x+y+z)^n | n=1, 4, 7, ...
Dim C.q(#size,#size); (x+y+z)^n | n=2, 5, 8, ...
#maxwerte=#size*#mid
Dim werte.q(#maxwerte)
Dim anzahl(#maxwerte)
level=1
B(#mid,#mid)=1
Repeat
level+1
Select level%3
Case 0
maxx+1
miny-1
For x=minx To maxx
For y=miny To maxy
A(x,y)=(C(x-1,y+1)+C(x,y)+C(x,y+1));%#modulo
Next y
Next x
Case 1
minx-1
miny+1
maxy+2
For x=minx To maxx
For y=miny To maxy
B(x,y)=(A(x,y-1)+A(x+1,y-2)+A(x+1,y-1));%#modulo
Next y
Next x
Case 2
maxx+1
miny-1
For x=minx To maxx
For y=miny To maxy
C(x,y)=(B(x,y+1)+B(x,y)+B(x-1,y+1));%#modulo
Next y
Next x
EndSelect
Until level=n
found=0
For i=0 To #maxwerte
werte(i)=0
anzahl(i)=0
Next i
l=level%3
For x=minx To maxx
For y=miny To maxy
Select l
Case 0
d=A(x,y)
Case 1
d=B(x,y)
Case 2
d=C(x,y)
EndSelect
If d
i=found
While i
If werte(i)=d
Break
Else
i-1
EndIf
Wend
If i
anzahl(i)+1
Else
found+1
werte(found)=d
anzahl(found)+1
EndIf
EndIf
Next y
Next x
For i=1 To found
Debug StrQ(werte(i))+" x "+Str(anzahl(i))
Next i
EndProcedure
Problem_154(5)
But also here I've some problems as well:
1) the modulo function return negative numbers (to check that, just remove the semicolon before the %#modulo statements)
2) the dim does not allow to build up such a huge array needed to calc the results
Does anyone know, what is the workaround for 1)?
Thanks,
Michael