'Program for finding "Number of hexagons (sides length = 1) 'that intersect the circumference of a circle of radius n 'centered at a lattice point. For n=1 To 100 sumhex=0 '-------------------------row value------------------------------ m3=math.Remainder(n,3) If m3=0 Then rowup=n*(2/3) rowdn=rowup Else If m3=1 Then rowup=n*(2/3)+(4/3) rowdn=rowup-2 Else rowup=n*(2/3)+(2/3) rowdn=rowup EndIf EndIf '--------------------------UPPER/LOWER------------------------------------- cal=1 y=-0.5 recal: hex=0 For i = 1 To rowup If Math.Remainder(i,2)=0 Then y=y+1 Else y=y+0.5 EndIf x=math.Power(n*n-y*y,0.5) j=x/(math.Power(3,0.5)/2) d=math.Abs(j-math.Round(j)) If d <0.0000001 Then j=math.Round(j) EndIf l[i]=math.Floor(j) h[i]=math.Ceiling(j) '------------------------hex defind-------------------------------------------- if math.Remainder(i,2)=0 Then bb=math.Remainder(Math.Floor(i/2),2) cc=math.Remainder(h[i],2) If h[i]=h[i-1] Or h[i]=l[i] then hex=hex+1 else If cal=1 then if bb<>cc then hex=hex+2 Else hex=hex+1 EndIf endif If cal=2 then if bb<>cc then hex=hex+1 Else hex=hex+2 EndIf endif endif EndIf EndFor sumhex=sumhex+hex If cal=1 then y=0 rowup=rowdn cal=2 Goto recal EndIf '-------------------------------Final result----------------------------------------- If m3>0 Then totalhex=3*(2*sumhex-1) Else totalhex=6*sumhex EndIf TextWindow.Write(totalhex+", ") Endfor