• Welcome to Dark Bit Factory & Gravity.
 

Prime Numbers

Started by bikemadness, January 08, 2018

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

bikemadness

Couldn't find any samples of working out prime numbers
So here's mine.


open window 640,512
setrgb 1,200,200,200
space=12
spaces=int(490/space)
lines=0
gap=0
z=3500
repeat
lines=0
gap=0
number=0
for y=1 to z
num=0
for x=1 to y
if frac(y/x)=0 num=num+1
next x
if num<3 then
lines=lines+1
number=number+1
text 10+gap,lines*space,str$(y)
endif
if lines>spaces then
   gap=gap+50
   lines=0
   endif
next y
text 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

#1
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.
You are our 9001st visitor.
Challenge Trophies Won:

bikemadness

Thanks. I've now added the numerical count
and a start off for larger numbers so the whole
screen doesn't get filled.


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

bikemadness

After a little thought, I sped it up a little, simplified it
and added clear screen carry on. It has room for 6 digits.


open window 640,512
setrgb 1,256,256,256
for y=1 to 1000000
num=0
for x=1 to y
if frac(y/x)=0 num=num+1
if num>4 goto skip
next x
if num<3 then
lines=lines+1
number=number+1
nos=nos+1
text 5+gap,lines*11,str$(y)
endif
label skip
if lines>45 then
   gap=gap+70
   lines=0
   endif
if nos=414 then
inkey$
clear window
nos=0
gap=0
lines=0
endif
next y
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

bikemadness

And a little faster.
If it only showed text for the last few,
it would take half the time. Use rem notes.


open window 640,512
setrgb 1,256,256,256
for y=1 to 100000
num=0
for x=1 to sqrt(y)
if frac(y/x)=0 num=num+1
if num>3 goto skip
next x
if num<2 then
lines=lines+1
number=number+1
nos=nos+1
text 5+gap,lines*11,str$(y)  rem place with this: if y>99950 text 5+gap,lines*11,str$(y)
endif
label skip
if lines>45 then
   gap=gap+70
   lines=0
   endif
if nos=414 then
inkey$ rem take out this
clear window
nos=0
gap=0
lines=0
endif
next y
text 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

On the topic of primes, I hear some asymmetric encryption algorithms are based on the product of two large prime numbers.

I wonder if it's possible to make an asymmetric encryption algorithm using the product of three or more prime numbers? That could (and maybe should) be a topic of its own, but it's interesting to consider at the very least.
You are our 9001st visitor.
Challenge Trophies Won: