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.

Advertisement

Hello, visitor! These forums are run off of the revenue generated from these ads. If you'd like to support us, please whitelist us or consider donating:

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

Anatoly
Member
From: Unknown location
Joined: 2015-07-31
Posts: 4,548
Website

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.

Offline

Wooted by:

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

LukeM
Dev Team
From: England
Joined: 2016-06-03
Posts: 2,435
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

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,382
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))

Last edited by BuzzerBee (2018-06-01 12:17:45)


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

Offline

#29 2018-05-31 18:24:04

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

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

How about 1.000.000..?

Long text wall on mobile

Last edited by BuzzerBee (2018-06-01 11:50:18)


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

Offline

Wooted by:

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

John
Guest

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

2, are primes.

Console.WriteLine("2, are primes.");
Wooted by:

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

Different55
Forum Admin
Joined: 2015-02-07
Posts: 15,566

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: 281

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
Forum Admin
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,797

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

Anatoly
Member
From: Unknown location
Joined: 2015-07-31
Posts: 4,548
Website

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

Last edited by Anatoly (2018-06-01 08:33:29)

Offline

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

Anatoly
Member
From: Unknown location
Joined: 2015-07-31
Posts: 4,548
Website

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

So it would be

Hidden text

on Swift in XCode

Offline

#36 2018-06-17 09:42:50

LukeM
Dev Team
From: England
Joined: 2016-06-03
Posts: 2,435
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

Last edited by LukeM (2018-06-17 10:00:26)

Offline

Wooted by:

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

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

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 1540202206.839 - Generated in 1.731 seconds, 12 queries executed - Memory usage: 2.73 MiB (Peak: 5.52 MiB) ]