Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 computation speed
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iamcow




PostPosted: Thu Aug 03, 2006 1:02 pm   Post subject: computation speed

just something i did while fooling around with a piece of code

code:

var primes : array 2 .. 99999999 of boolean

proc findprime (num : int)
    var counter := 0
    var n : real
    for decreasing i : num-1 .. 2
        n := num / i
        if round (n) = n then
            counter += 1
        else
            counter := counter
        end if
    end for
    if counter = 0 then
        primes (num) := true
    else
        primes (num) := false
    end if
end findprime

for i : 2 .. 99999999
    findprime (i)
end for

for i : 2 .. 99999999
    if primes (i) = true then
        put i, " is a prime"
    else
        put i, " is not a prime"
    end if

end for


out of curiousity, how long does it take for you guys to run this program?
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Thu Aug 03, 2006 1:19 pm   Post subject: (No subject)

Umm... I'd imagine extremely long, even on an amazing computer. Why do you ask?

And just from a glance, you're findPrime function doesn't look quite right, and neither does your code.
pj_ladd12




PostPosted: Thu Aug 03, 2006 1:31 pm   Post subject: (No subject)

yeah...nothing came up lol
BenLi




PostPosted: Thu Aug 03, 2006 4:39 pm   Post subject: (No subject)

changed all "99999999"'s to 100s
the code works actually, i imagine its just quite slow.

Interesting, this is the subject of another discussion in general forum. The one about largest primes?
[Gandalf]




PostPosted: Thu Aug 03, 2006 11:31 pm   Post subject: (No subject)

pj_ladd12 wrote:
yeah...nothing came up lol

Yeah, that's because it's taking a very long time to calculate what it's going to display.

Quote:
Interesting, this is the subject of another discussion in general forum. The one about largest primes?

I doubt you'd get very far using this algorithm and Turing.
Clayton




PostPosted: Fri Aug 04, 2006 9:03 am   Post subject: (No subject)

I'm sure theres a much better way to do this, it just had to be extremely well organized and optimized Very Happy, the only problem is, Turing can't deal with big enough numbers to find the worlds next largest prime with over 10,000,000 digits
MysticVegeta




PostPosted: Fri Aug 04, 2006 10:51 am   Post subject: (No subject)

Why not just try the Sieve of Eratosthenes to find it quicker than that algorithm but still it takes time to find that many...

http://compsci.ca/v2/viewtopic.php?t=11966
CodeMonkey2000




PostPosted: Sun Aug 06, 2006 9:43 pm   Post subject: (No subject)

var primes : array 2 .. 99999999 of boolean


wow soo much time was spent on just declareing the all elements of primes.
turing really isnt that powerful.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Wed Aug 09, 2006 2:15 am   Post subject: (No subject)

spearmonkey2000 wrote:
var primes : array 2 .. 99999999 of boolean


wow soo much time was spent on just declareing the all elements of primes.
turing really isnt that powerful.


what? you clearly have no knowledge of the computer memory interface. when declaring 99999998 boolean variables, 99999998bytes of contiguous memory (either on RAM, or on disk through an TLB) is allocated, it's all done by the processor, and has nothing to do with turing's efficiency
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: