Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#26 2018-05-30 18:24:55

Anatoly
Guest

Re: I generated all primes up to 50,000.

LukeM wrote:
Anatoly wrote:
hummerz5 wrote:

I'm surprised this actually spurned conversation

are you guys limiting your loops to the square root of the number you're testing for primality? After all, one only needs find one of a factor pairing... and the factor pairs straddle the square root of the number....

But why? You could create an array, where all primes are kept, and then only going trough the primes, and only through the primes that are below the square root of the number.

That is, if we would check 100 for primality, we would only go trough 2, 3, 5 and 7 (and obviously stop at 2).

Thats what Hummerz5 was saying wasn't it? (That you only check divisors up to the square root of the number)

Yes, but with his logic you should check for 100 the number 2, 3, 4, 5, 6, 7, 8 and 9. I’m saying you only need to check 2, 3, 5 and 7.

Wooted by:

#27 2018-05-30 20:00:41

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: I generated all primes up to 50,000.

Anatoly wrote:
LukeM wrote:

Yes, but with his logic you should check for 100 the number 2, 3, 4, 5, 6, 7, 8 and 9. I’m saying you only need to check 2, 3, 5 and 7.

He never said anything about which numbers to skip, just that you only need to go up to the square root. Just because using only his logic wouldn't be optimal doesn't mean the logic is bad...

Offline

#28 2018-05-31 18:18:21, last edited by BuzzerBee (2018-06-01 12:17:45)

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: I generated all primes up to 50,000.

This is Lua

Long wall of text on mobile
local primes = ""

function abc()
	for i = 2, 150000 do
		local prime = true
		
		for j = 2, math.huge do
			if j * j > i then break end
				
			if i % j == 0 then
				prime = false
				break
			end
		end
		
		if prime then
			primes = primes.. tostring(i).. ", "
		end
	end
	
	print(primes)
end

local t = tick()
abc()
print("Elapsed time: ".. tostring(tick() - t))

http://i.imgur.com/bjvgH5L.png?1

Offline

#29 2018-05-31 18:24:04, last edited by BuzzerBee (2018-06-01 11:50:18)

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: I generated all primes up to 50,000.

How about 1.000.000..?

Long text wall on mobile

http://i.imgur.com/bjvgH5L.png?1

Offline

Wooted by:

#30 2018-05-31 18:31:43

John
Member
Joined: 2019-01-11
Posts: 1,972

Re: I generated all primes up to 50,000.

2, are primes.

Console.WriteLine("2, are primes.");

PW?scale=2

Offline

Wooted by:

#31 2018-05-31 19:01:26

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,572

Re: I generated all primes up to 50,000.

Merged all the prime topics, we don't need 50,000


"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto

Offline

Wooted by: (2)

#32 2018-05-31 23:11:31

Kkay
Formerly Kaydog99
From: Canda eh
Joined: 2015-08-20
Posts: 495

Re: I generated all primes up to 50,000.

literally feels like an excuse to fill the topic with numbers

Offline

#33 2018-06-01 03:56:45

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: I generated all primes up to 50,000.

Kkay wrote:

literally feels like an excuse to fill the topic with numbers

trust me, it's not. If we hadn't suddenly started comparing algorithms and such, this would be locked.

tl;dr: don't do that.

Offline

#34 2018-06-01 05:53:06, last edited by Anatoly (2018-06-01 08:33:29)

Anatoly
Guest

Re: I generated all primes up to 50,000.

hummerz5 wrote:
Kkay wrote:

literally feels like an excuse to fill the topic with numbers

trust me, it's not. If we hadn't suddenly started comparing algorithms and such, this would be locked.

tl;dr: don't do that.

You misunderstood me. I actually wanted to make a discussion out of this.


So what is the most fast algorithm? Ninjasupeatsninja definiely not. He’s been going trough all existent numbers...

Also, this is useless:

if prime then
			primes = primes.. tostring(i).. ", "
		end

Lua can automatically convert string to number so it should be

if prime then
			primes = primes..i.. ", "
		end

But I’m not faster then you //forums.everybodyedits.com/img/smilies/sad

rTY0qoH.jpg7QOPJxA.jpgOESgf5M.jpg

#35 2018-06-17 06:36:36

Anatoly
Guest

Re: I generated all primes up to 50,000.

So it would be

Hidden text

on Swift in XCode

#36 2018-06-17 09:42:50, last edited by LukeM (2018-06-17 10:00:26)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: I generated all primes up to 50,000.

Anatoly wrote:

So it would be

Hidden text

on Swift in XCode

Shouldn't the loop start at 2 if you are checking 2i - 1 (2 * 3 - 1 = 5)? Unless I'm missing something about loops in swift...
And the square root check currently isn't doing anything, it should be in a seperate if that breaks from the loop if k > sqrt(i) (or k * k > i which is slightly faster as sqrt is quite slow)

Other than that, yes looks good //forums.everybodyedits.com/img/smilies/smile

Sidenote: This also happened to be the first programming question in my computer science exam XD

Offline

Wooted by:

#37 2018-06-24 11:01:36

HeyNK
Member
Joined: 2017-04-07
Posts: 1,318

Re: I generated all primes up to 50,000.

You're too late, someone has already beat you to it.

Offline

HeyNK1529834496711084

Board footer

Powered by FluxBB

[ Started around 1711668310.8708 - Generated in 2.827 seconds, 12 queries executed - Memory usage: 2.97 MiB (Peak: 5.75 MiB) ]