good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^5: OT: Finding Factor Closest To Square Rootby talexb (Chancellor) |
on Feb 21, 2005 at 11:46 UTC ( [id://433022]=note: print w/replies, xml ) | Need Help?? |
Needless to say, but I'll say it anyway, a fascinating problem. Exactly the kind of thing that my Dad eats for breakfast (retired actuary and all that). After some thought, it seems clear that this is a tough nut to crack. If you start with a sorted list of factors, largest to smallest, and multiply values together, the solution is 25. If you drop the first value, you end up with 20. I can't prove it (not at 0630, anyway), but I expect there are cases where the solution is the product of the first, second and last factors. In the end, I think the best way to find out the answer is to figure out the integer that's closest to the square root, then go backwards to find the largest number made up of the factors. Assuming you don't want to actually calculate the suqare root, the first part of that can be a straightforward binary search. The second part is where it gets interesting .. you have to find the combination of factors whose product is closest to the approximate square root value you've determined. And that sounds an awful lot like re-starting the original problem. Ugh. Alex / talexb / Toronto "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
In Section
Seekers of Perl Wisdom
|
|