Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,143,503 members, 7,781,535 topics. Date: Friday, 29 March 2024 at 04:25 PM |
Nairaland Forum / Science/Technology / Programming / Simple Factorial Challenge (4205 Views)
Factorial Design Of Experiments (d.o.e) (2) (3) (4)
Re: Simple Factorial Challenge by olyjosh(m): 2:48pm On May 27, 2016 |
jacob05: I begin to love dis python of a thing oo. Your solution is quite brilliant n fast but your answer only converges upto d 15th decimal values. Unnecessary rounding in d system I guess. 1 Like |
Re: Simple Factorial Challenge by jacob05(m): 7:19pm On May 27, 2016 |
olyjosh:Hmmm. Thanks |
Re: Simple Factorial Challenge by slysoft: 6:46pm On May 31, 2016 |
jacob05: Hi @jacob05, I designed the php script @slyrox uploaded for the problem... as @Lyphiard rightly mentioned that the problem @OP posted came from a competition in USA which we solved in our team before sharing it nairaland to develop other programmers on this platform. The accepted solution/result on the competition portal was "5.08845978368001251890" which is the same as the result of our script/algorithm and different from the solution/result of your script/algorithm "5.088459783680012467179075225". However, this is how we solved it or how we got the algorithm; Looking at the equation posted; x^2 + (5/3)x^3 + (23/12)x^4 + (119/60)x^5 ... + (2*[5000!-1]/[5000!])x^5000 it can easily be translated into a summation equation which is to sum the result of ((2 * ([a+1]! – 1) / [a+1]! ) * x^(a+1) from a = 1 till 5000 where x is a constant so for a = 1 we have x^2 a = 2 we have (5/3)x^3 sum the results till a = 5000 All we did was to translate the deduced summation equation into a script/algorithm. there was no reason behind using php, I could have used several other lang java, C#, VB, C, ruby, python The result of the problem was also requested in the nearest 20 decimal places. why i added bcscale(25) is to control the number of trailing digits after the decimal and not affect the integrity of the 20th digit after the decimal. then i took off the trailing 5 digits after the 20th decimal I will be willing to learn if you comeup with a much quicker or less-lame solution with regards to the posted problem. Thanks BTW, My understanding of your script is that 5000 = 5000!; correct me if i am wrong.
|
Re: Simple Factorial Challenge by jacob05(m): 5:07am On Jun 01, 2016 |
slysoft: And that is still naive and the wrong way of solving the problem (Although it gives you the correct answer ). The organizers of code competitions knows the easy, and mostly expensive, way of solving the problem and they most times set that trap for you. (Learnt the Hard way in the Google Code Jam 2016). Always avoid factorial loops that move towards 1000 ... It's a trap !!!... Finding factorial is an expensive runtime operation.(Especially one that tends towards 1000) Quote me if I'm wrong. 2:
Funny enough, It's relatively the same script I posted!!!. The issue with previous was with my use of float for x.. (floats are mostly not accurate) and this beginH = Decimal(1.0). The issue with the above is that 1.0 is a floating point value .. which is not exactly 1.0 when converted into decimal...(don't blame me.. ). Just had to put single quotes... beginH = Decimal('1.0')... Did the same for the rest... lobatan... 3. Yes but I did not use the expensive factorial method to calculate the result. |
Re: Simple Factorial Challenge by slysoft: 11:16am On Jun 01, 2016 |
@jacob05 Impressive script, i just learned something. The loop in your script started from 2 till 5001... can you explain why? |
Re: Simple Factorial Challenge by jacob05(m): 11:23am On Jun 01, 2016 |
slysoft: x^2 + (5/3)x^3 + (23/12)x^4 + (119/60)x^5 ... + (2*[5000!-1]/[5000!])x^5000 The power starts from 2 to 5000... range( 2, 5001 ) generates a sequence from 2 to 5001 - 1 (5000).. |
Re: Simple Factorial Challenge by jacob05(m): 11:25am On Jun 01, 2016 |
xrange would be better though... performance wise. ... But It won't kill for now.. |
Vb vs Java: Which Is Better For Mobile Applications? / Were Can I Download Free Video Tutorials On Javascript Or Ruby / Can I Call Myself A Good Programmer If I Only Know Visual Basic
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 62 |