### Author Topic: Prime Numbers  (Read 466 times)

0 Members and 1 Guest are viewing this topic.

• Amiga 1200
• Posts: 260
• Karma: 24
• Hard players don't go home.
##### Prime Numbers
« on: January 08, 2018 »
Couldn't find any samples of working out prime numbers
So here's mine.

Code: [Select]
`open window 640,512setrgb 1,200,200,200space=12spaces=int(490/space)lines=0gap=0z=3500repeatlines=0gap=0number=0for y=1 to znum=0for x=1 to yif frac(y/x)=0 num=num+1next xif num<3 thenlines=lines+1number=number+1text 10+gap,lines*space,str\$(y) endifif lines>spaces then   gap=gap+50   lines=0   endifnext ytext gap,(lines+1)*space,"("+str\$(number)+")"until (1=0)`
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

#### combatking0

• JavaScript lives!
• Senior Member
• Posts: 4569
• Karma: 235
• Retroman!
##### Re: Prime Numbers
« Reply #1 on: January 08, 2018 »
Interesting. If I were coming up with my own algorithm I'd have to seed it with the first 2 primes and set it going from there. Though I don't imagine mine would be very elegant.

I'll definitely have to give this one a try.
« Last Edit: January 09, 2018 by combatking0 »
You are our 9001st visitor.
Challenge Trophies Won:

• Amiga 1200
• Posts: 260
• Karma: 24
• Hard players don't go home.
##### Re: Prime Numbers
« Reply #2 on: January 09, 2018 »
Thanks. I've now added the numerical count
and a start off for larger numbers so the whole
screen doesn't get filled.

Code: [Select]
`open window 640,512space=12spaces=int(500/space)lines=0gap=0z=int(spaces*87)repeatlines=0gap=0number=0for y=1 to 10000num=0for x=1 to yif frac(y/x)=0 num=num+1next xif num<3 number=number+1if num<3 and y>9000 then 'won't start texting until after 9000'delay until then, since still has to countlines=lines+1setrgb 1,0,256,0text gap,lines*space,str\$(number)setrgb 1,256,256,256text 50+gap,lines*space,str\$(y)endif if lines>spaces then   gap=gap+90   lines=0   endifnext yuntil (1=0)`
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

• Amiga 1200
• Posts: 260
• Karma: 24
• Hard players don't go home.
##### Re: Prime Numbers
« Reply #3 on: January 10, 2018 »
After a little thought, I sped it up a little, simplified it
and added clear screen carry on. It has room for 6 digits.

Code: [Select]
`open window 640,512setrgb 1,256,256,256for y=1 to 1000000num=0for x=1 to yif frac(y/x)=0 num=num+1if num>4 goto skipnext xif num<3 thenlines=lines+1number=number+1nos=nos+1text 5+gap,lines*11,str\$(y) endiflabel skipif lines>45 then   gap=gap+70   lines=0   endifif nos=414 theninkey\$clear windownos=0gap=0lines=0endifnext y`
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

• Amiga 1200
• Posts: 260
• Karma: 24
• Hard players don't go home.
##### Re: Prime Numbers
« Reply #4 on: January 12, 2018 »
And a little faster.
If it only showed text for the last few,
it would take half the time. Use rem notes.

Code: [Select]
`open window 640,512setrgb 1,256,256,256for y=1 to 100000num=0for x=1 to sqrt(y)if frac(y/x)=0 num=num+1if num>3 goto skipnext xif num<2 thenlines=lines+1number=number+1nos=nos+1text 5+gap,lines*11,str\$(y)  rem place with this: if y>99950 text 5+gap,lines*11,str\$(y)endiflabel skipif lines>45 then   gap=gap+70   lines=0   endifif nos=414 theninkey\$ rem take out thisclear windownos=0gap=0lines=0endifnext ytext gap,(lines+1)*11,"("+str\$(number)+")"`
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

#### combatking0

• JavaScript lives!
• Senior Member