Wrote a quick program which searches for the highest prime number and writes it to a file. You can close the program and open it again and it will start from where it left off.

Don't ask me why! I remember reading somewhere that they are awarding $150,000 to whoever can find the highest prime number, but I think the highest is like 10 million digits long. If you leave it running you might win some money in 50 years time haha was fun making it though.

Heres the code if you wanna try it. It's only short.

rem
rem AGK Application
rem
rem change this to make program start searching at a higher number
start=1
rem Landscape App
SetDisplayAspect( 8.0/6.0 )
setorientationallowed(0,0,1,0)
settransitionmode(1)
deviceH=getdeviceheight()
deviceW=getdevicewidth()
updatedevicesize(deviceH,deviceW)
sync()
rem create prime numbers text file
writepath$=getwritepath()
if getfileexists("Prime Numbers.mo")=0
setrawwritepath(writepath$)
opentowrite(1,"Prime Numbers.mo",0)
writeinteger(1,0)
closefile(1)
endif
rem set variables
number=1
result#=0
rem current number check text
createtext(1,"Checking Number: "+str(number))
settextsize(1,6)
settextposition(1,0,8)
rem performing tasks text
createtext(2,"Dividing "+str(number)+" by "+str(z))
settextposition(2,0,16)
settextsize(2,6)
rem highest prime found text
setrawwritepath(writepath$)
opentoread(1,"Prime Numbers.mo")
highestprime=readinteger(1)
closefile(1)
createtext(3,"Highest Prime: "+str(highestprime))
settextposition(3,0,0)
settextsize(3,6)
rem set number to highest prime found
number=highestprime
if highestprime=0 then number=1
rem MAIN LOOP ***************************************************
rem inc number
for x=start to number
rem show which number is being checked.
settextstring(1,"Checking Number: "+str(number))
count=number
rem test if number ends in 1,3,7 or 9 (like all prime numbers after 5)
yes=0
if number>9
xno$=str(number)
xno2$=right(xno$,1)
xno=val(xno2$)
yes=0
if xno=1 then yes=1
if xno=3 then yes=1
if xno=7 then yes=1
if xno=9 then yes=1
else
yes=1
endif
if yes=1
rem check 1 to number if division creates integer
for z=1 to count/2
rem dividing text
settextstring(2,"Dividing "+str(number)+" by "+str(z)+"...")
check#=z
rem do division
number#=number
result#=number#/check#
if round(result#)<>result#
else
rem integer
inc factors,1
endif
sync()
next z
endif
rem if there are only 2 factors then save prime number to file
if factors=1
rem save prime number to file
writepath$=getwritepath()
setrawwritepath(writepath$)
opentowrite(1,"Prime Numbers.mo",0)
writeinteger(1,number)
closefile(1)
setrawwritepath(writepath$)
opentoread(1,"Prime Numbers.mo")
highestprime=readinteger(1)
closefile(1)
settextstring(3,"Highest Prime: "+str(highestprime))
endif
inc number,1
factors=0
sync()
next x

audiosparx.com/liambradburymusic - professional music for your games.