x404.co.uk http://www.x404.co.uk/forum/ |
|
Linked list arithmetic http://www.x404.co.uk/forum/viewtopic.php?f=4&t=13343 |
Page 1 of 1 |
Author: | Fogmeister [ Wed Apr 13, 2011 9:37 am ] |
Post subject: | Linked list arithmetic |
I'm guessing Fin has but have any of you used linked lists for maths with large numebrs before? I kind of invented the idea before I knew what linked lists were and now I've realised that it's actually fairly easy (ish) to do. Purely as an exercise I'm going to try create a largeNumber class that eclusively uses linked lists and has methods for operating on them. Will also be very useful for keeping for future code as I have been stuck in the past whenever it comes to very large numbers. I realise there are libraries out there for this already but I'm doing it as a learning exercise also. |
Author: | finlay666 [ Wed Apr 13, 2011 2:40 pm ] | |||||||||
Post subject: | Re: Linked list arithmetic | |||||||||
What language? I'd look at the BigInt class as an example, I'm not sure if a linked list is the most effective way depending on the calculations |
Author: | Fogmeister [ Wed Apr 13, 2011 2:42 pm ] | ||||||||||||||||||
Post subject: | Re: Linked list arithmetic | ||||||||||||||||||
c++ but any really. I just thought of the concept of even using a string or something and processing it char by char. I'll have a look at BigInt. Thanks ... Genius! That's exactly what I was looking for! |
Author: | finlay666 [ Wed Apr 13, 2011 7:29 pm ] | |||||||||
Post subject: | Re: Linked list arithmetic | |||||||||
![]() I used it for a few of the tasks on Project Euler as it's a really useful library to have around for things like that |
Author: | Fogmeister [ Thu Apr 14, 2011 8:50 am ] |
Post subject: | Re: Linked list arithmetic |
I had a quick play with this last night and it's soooo easy to use! Brilliant! |
Author: | Fogmeister [ Thu Apr 14, 2011 9:36 am ] |
Post subject: | Re: Linked list arithmetic |
LOL! Just messing around with it to find it's limits. 700! took 1.5 seconds to calculate. 1000! took 4.7 seconds to calculate and didn't crash. It is just sitting calculating 10000! ![]() LOL! I gave up in the end. It seems that the time is taken in outputting the value not in calculating it in the first place. i.e. 10000! / 10000! doesn't take long at all. |
Author: | finlay666 [ Thu Apr 14, 2011 10:38 am ] | |||||||||
Post subject: | Re: Linked list arithmetic | |||||||||
If it was a little smarter it could quickly evaluate 1000!/999! = 1000 based on evaluation |
Author: | Fogmeister [ Thu Apr 14, 2011 2:36 pm ] |
Post subject: | Re: Linked list arithmetic |
YAY! BigInt saved my Google Code Jam sample. I knew it was working properly. But the numbers being used in the large version of (minimum scalar product) were too big and it was messing up the result. BigInt fixed it ![]() |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |