January 15, 2021, 05:29:15 PM

### Author Topic: [bb] Prime Finder by Nathaniel [ 1+ years ago ]  (Read 401 times)

#### BlitzBot

• Jr. Member
•  • Posts: 1 ##### [bb] Prime Finder by Nathaniel [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Prime Finder
Author : Nathaniel
Posted : 1+ years ago

Description : The program first asks which number to start calculating to see if it is prime. It then continues with the next  consecutive number. (It does this until you press the esc. key.) I don't suggest putting in a number that's over 5000.

Have Fun!

Code :
Code: BlitzBasic
1. ;Prime Finder
2. ;Created by: Bubble Boy
3.
4. Graphics 800,600,16,2
5. SetBuffer BackBuffer()
6.
7. AppTitle "Prime Finder"
8.
9. number#=1
10. divisor#=1
11. quotient#=0
12. rounded=0
13. prime=0
14. go=0
15.
16.
17. Color 250,250,86
18. Print "PRIME FINDER"
19.
21.
22.
23. While Not KeyHit(1)
24.
25. Color 250,250,86
26. Print number#
27. Flip
28.
29. While go = 0
30.
31.    quotient# = number# / divisor#
32.    rounded=Int( quotient# )
33.
34.    Color 50,255,50
35.    Print quotient# + " = " + number# + " / " + divisor#
36.
37.
38.    If divisor# > 1
39.    If quotient# = rounded
40.       prime = 0
41.       go = 1
42.    Else
43.       prime = 1
44.
45.    End If
46.    End If
47.
48.
49. Delay 20
50.
51. If KeyDown(1)
52.    End
53. End If
54.
55. If divisor# = number#
56.    prime = 1
57.    go = 1
58. End If
59.
60. If number# = 1
61.    prime = 0
62.    go = 1
63. End If
64.
65. divisor# = divisor# + 1
66.
67.
68.
69.
70. Wend
71.
72. If prime = 1
73.    Color 250,250,86
74.    Print number#
75.    Color 255,50,50
76.    Print "PRIME"
77.
78.    Flip()
79.
80.
81. Else If prime = 0
82.    Color 250,250,86
83.    Print number#
84.    Color 50,50,255
85.    Print "NOT PRIME"
86.    Flip()
87. End If
88. Print " "
89.
90. Delay 2000
91.
92. go=0
93. prime=0
94. number#=number# + 1
95. divisor#=1
96. quotient#=0
97.
98. Wend
99.
100. End

erbbysam(Posted 1+ years ago)

Code: [Select]
`;Prime Finder;Created by: Bubble Boy;edited by: erbbysamSetBuffer BackBuffer()AppTitle "Prime Finder"fileout = WriteFile("primes.txt") number#=1divisor#=1quotient#=0rounded=0prime=0go=0Color 250,250,86Print "PRIME FINDER"number#=0While Not KeyHit(1)While go = 0   quotient# = number# / divisor#   rounded=Int( quotient# )   If divisor# > 1   If quotient# = rounded      prime = 0      go = 1   Else       prime = 1   End If      End IfIf divisor# = number#   prime = 1   go = 1End IfIf number# = 1   prime = 0   go = 1End Ifdivisor# = divisor# + 1WendIf prime = 1 WriteLine( fileout, number# ) End Ifgo=0prime=0number#=number# + 1divisor#=1quotient#=0WendCloseFile( fileout ) End`this uses the code above to output every prime number that it can find starting at 0 to a file. After about a minute it will find the first 10,000 primes (or every prime between 2 and 100000 )

Subirenihil(Posted 1+ years ago)

Zzzz I've had MUCH better code for finding prime numbers for years.  I can calculate the first ten million prime numbers in half an hour using my code.Tip #1: A number is prime if it is not divisible by a prime number less than or equal to it's square root.Tip #2: If number Mod divisor=0 then prime=FalseI will now post my code to the archives.<a href="codearcsf16a.html?code=1888" target="_blank">Calculating Primes[/url]And here is code that trumps mine <a href="codearcs5b52.html?code=1872" target="_blank">FAST Sieve of Eratosthenes[/url] [/i]