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

Username:   Password: 
 RegisterRegister   
 Larger Integers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
drij




PostPosted: Sun Oct 12, 2008 2:18 pm   Post subject: Larger Integers

I was working my way through the problems on Project Euler when I encountered an issue with problem 3.

The problem is: "What is the largest prime factor of 600851475143?"

I wrote a nice little prime-checking function:
Turing:
fcn isPrime (maybePrime : int) : boolean
    var hasNoFactors : boolean := true

    if maybePrime = 1 or maybePrime = 2 then
        result true
    end if

    for maybeFactor : 2 .. floor (sqrt (maybePrime))
        if maybePrime mod maybeFactor = 0 then
            hasNoFactors := false
        end if
    end for

    result hasNoFactors
end isPrime

After I wrote this, I couldn't figure out how to deal with the size of the number 600851475143.

My question is, is it possible to work with large numbers such as this in turing?
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Sun Oct 12, 2008 4:52 pm   Post subject: Re: Larger Integers

Yes, the double-precision floating point can represent at least this, and all the integers >= 0 below it exactly.
Saad




PostPosted: Sun Oct 12, 2008 4:58 pm   Post subject: RE:Larger Integers

But it should be known that it can not represent accurately be represented. Unfortunately Turing has no default way of handling them with full accuray. You could make your own though.
Insectoid




PostPosted: Sun Oct 12, 2008 9:02 pm   Post subject: RE:Larger Integers

does Turing not support 'long' variables?
Saad




PostPosted: Sun Oct 12, 2008 9:46 pm   Post subject: RE:Larger Integers

None to my knowledge
[Gandalf]




PostPosted: Sun Oct 12, 2008 9:48 pm   Post subject: RE:Larger Integers

Nope, it doesn't. float is as much precision as you can get.
drij




PostPosted: Mon Oct 13, 2008 10:27 am   Post subject: Re: Larger Integers

Ok then. Thanks for all your replies. Smile
[Gandalf]




PostPosted: Mon Oct 13, 2008 7:20 pm   Post subject: RE:Larger Integers

If you're looking to get further ahead in Euler, and are willing to learn a new language that's not too difficult, I'd recommend Ruby or Python. Both, AFAIK, support arbitrarily long integers by default.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: