RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
I wrote a cool function :]

0 Members and 1 Guest are viewing this topic.

**
I didn't really think about it
Rep:
Level 85
Okay so anybody that has done any research into finding prime numbers has probably gone to the wikipedia page and seen this:

It is the Sieve of Eratosthenes algorithm which finds all primes to a specified integer. Basically a prime is a number which is 1,2,3,5,7 or indivisible by 2,3,5 and 7. This comes useful at programming competitions. ;] Now before today I had given very little thought to the existence of a pattern in the spacing of primes on the number line but yesterday I started playing with python again and thought I'd give it a go. And I found it. The pattern between the first 6 is 1,1,1,2,2,4 and the patern which is repeated to infinity is 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2, 10, 2, 10. 48 numbers which are continuously added to a sum to find the nth prime. Now I tested this up the the 1,000,000th prime and it works. Here was my original function for finding the nth prime number (in Python)
Code: [Select]
def nth_prime(n):
    y = [1, 1, 1, 2, 2, 4]
    x = [2, 4, 2, 10, 2, 10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4]
    a,b=0,0
    while a<n:
        if b<11:
            b+=y[a%6]
        else:
            b+=x[a%48]
        a+=1
    return b


This gets pretty inefficient and time consuming when dealing with numbers bigger than 10^6 so I wrote this
Code: [Select]
def nth_prime(n):
    y = [1, 1, 1, 2, 2, 4]
    x = [2, 4, 2, 10, 2, 10, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4]
    a,b=0,0
    while a<n:
        if b<11:
            b+=y[a%6]
        elif n-a>48:
            b,a=b+((n//48)*210),a+(n//48)
        else:
            b+=x[a%48]
        a+=1
    return b
which basically just takes the time and throws it in a blender. I was able to verify the 10^14th prime in a split second.
So yeah, if you ever need to find the nth prime and are familiar with Python you can feel to implement this. Just please if it's anything official comment my name into the function def (Logan Blackburn).

Let me know what you think!

*
Rep:
Level 102
2014 Biggest Narcissist Award2014 Biggest Forum Potato2014 Best Non-RM Creator2013 Best Game Creator (Non-RM)2013 Best IRC ChatterboxParticipant - GIAW 112012 Most Successful Troll2012 Funniest Member2012 Best Use Of Avatar and Signature space2012 Best IRC ChatterboxSecret Santa 2012 ParticipantProject of the Month winner for November 2009For being a noted contributor to the RMRK Wiki2010 Most Successful Troll2010 Biggest Forum Couch Potato2010 Best IRC Chatterbox
I think I need an aspirin.

*
( ´ิ(ꈊ) ´ิ) ((≡^⚲͜^≡)) (ી(΄◞ิ౪◟ิ‵)ʃ)
Rep:
Level 102
(っ˘ڡ˘ς) ʕ•̼͛͡•ʕ-̺͛͡•ʔ•̮͛͡•ʔ (*ꆤ.̫ꆤ*)
2014 Avast Ye Merry Pirate!2013 Avast Ye Merry Pirate Award2012 Avast Ye Merry Pirate AwardFor frequently finding and reporting spam and spam bots2011 Most Unsung Member2011 Avast Ye Merry Pirate2010 Avast Ye Merry Pirate Award
Irock dum dum
bringing sexy back

****
Rep:
Level 83
Did you write that in Python?

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
I might swap that into C++ and use it if I ever need a prime number.
though it's hard to figure out when I'd ever need it.

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
It's nice to see you experimenting ^_^

Unfortunately your method is not sound. Putting n = 32 gives you 121 which is 11 squared.

*hugs*

*
( ´ิ(ꈊ) ´ิ) ((≡^⚲͜^≡)) (ી(΄◞ิ౪◟ิ‵)ʃ)
Rep:
Level 102
(っ˘ڡ˘ς) ʕ•̼͛͡•ʕ-̺͛͡•ʔ•̮͛͡•ʔ (*ꆤ.̫ꆤ*)
2014 Avast Ye Merry Pirate!2013 Avast Ye Merry Pirate Award2012 Avast Ye Merry Pirate AwardFor frequently finding and reporting spam and spam bots2011 Most Unsung Member2011 Avast Ye Merry Pirate2010 Avast Ye Merry Pirate Award
You got Zeriabowned ._.
bringing sexy back

*
Resident Cloud
Rep:
Level 91
I did this for some of my course they had an optional activity to make a list of prime numbers, It worked but no one else did it and it didnt count towards my mark :(

*
A Random Custom Title
Rep:
Level 96
wah
Nice try, though. I could never try something like this. :P