generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: I made a prime number generator.

Previous Thread :: Next Thread 
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 04:44 PM
I think it's good. In practical uses I'd return a table, but I'm starting off with printing them directly to make it more visual.

local isPrime = function(number)
local prime = true
for i = 2, number - 1 do
if number % i == 0 then
prime = false
break
end
end
return prime
end

local getPrimeNumbersUpTo = function(number)
for i = 1, number do
if isPrime(i) then
print(i)
end
end
end

getPrimeNumbersUpTo(100)

--[[Output:
1
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
--]]
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
31 May 2015 04:46 PM
function isPrime(n)
return n == 2 or (n%2 ~= 0 and n%3 ~= 0 and n%5 ~= 0 and n%7 ~= 0)
end
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 May 2015 04:47 PM
Terribly inefficient.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 04:48 PM
What would be a better way to do it besides storing already known prime numbers?
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
31 May 2015 04:48 PM
You should do some research; there are plenty of algorithms you could use to generate them faster.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 04:49 PM
Hmp. Didn't know, I just thought I'd try a shot at it. Didn't do any research at all. I suppose you could consider this a first step though.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 May 2015 04:49 PM
Google Sieve of Eratosthenes.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 04:51 PM
*feels more stupid the more i read about what i could of done better*

could of skipped all the even numbers

doh
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
31 May 2015 04:54 PM
This may interest you: http://www.wikiwand.com/en/Sieve_of_Atkin
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
31 May 2015 04:55 PM
My computer can't handle trying to get the prime of 100,000. Took about 5 minutes for studio to respond after calculating up to 100k. Lol
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
31 May 2015 04:56 PM
You shouldn't be using roblox studio for this kind of computational work. Lol

Try the Lua for Windows interpreter, it should be on Google Code somewhere.
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
31 May 2015 04:57 PM
ZeroBaneStudio is also good.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 May 2015 04:58 PM
http : / / en . wikipedia . org / wiki / Primality _ test
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
31 May 2015 05:01 PM
Oh. I don't plan to try to find a really big prime number or anything, that's not the point of this. I'm just messing around.
Report Abuse
AhtnamasStudio is not online. AhtnamasStudio
Joined: 15 Jan 2014
Total Posts: 1104
31 May 2015 05:03 PM
Their are better ways of doing but this is a first time and I bet your learning scripting. So its all good.

Now how about get a random number and try to figure out if its odd or even and must bee under 10 lines :)
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 May 2015 05:04 PM
^
omg that sounds rlly difficlt :(
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
31 May 2015 05:09 PM
I bet your learning scripting [2]
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
31 May 2015 05:10 PM
I bet your learning scripting [3]
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
31 May 2015 05:11 PM
We're all learning scripting
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 May 2015 05:11 PM
function IsPrime(n)
for i = 1, n, 2 do
if i > math/sqrt(n) then
return true
end
if n%i==0 then
return false
else
table.insert(Repeats, i)
end
end
end




If I made an error in my above logic please feel free to correct me :)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 May 2015 05:13 PM
print((function IsEven(n) return n%2==0 end)(math.random(1, 100000)))


Legit 1 line.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 May 2015 05:14 PM
print((function(n) return n%2==0 end)(math.random(1, 100000)))


Legit 1 line.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 May 2015 05:15 PM
I don't know why I left the IsEven function, I meant to take that out altogether.

print(math.random(10000)%2==0)
Report Abuse
adandee is not online. adandee
Joined: 20 Feb 2014
Total Posts: 231
31 May 2015 05:16 PM
Wonder if it is possible to make the prime numbers generate something if it is that number.


Like this


if Num.Value = 17 then
m = Instance.new('Message', workspace)
m.Text = 'Mynamejeff'
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image