Post Reply 
Mini-challenge: MAX(factors of 2 or 5)
01-19-2018, 11:48 PM (This post was last modified: 01-19-2018 11:50 PM by pier4r.)
Post: #16
RE: Mini-challenge: MAX(factors of 2 or 5)
(01-19-2018 07:39 PM)Joe Horn Wrote:  Yes, plus the fact that it's the obvious brute-force way of doing it. It doesn't use any number theory tricks, or clever shortcuts, or anything which represents thinking outside the box... something that you see in somebody else's code and you say "Wow, that's cool!" ... you know, something elegant, as it were.

I am unconvinced that "elegant", as in "short and to the point" for how I understood your analogy, is always valid. Or better could be that the elegant procedure is perceived elegant only because it hides complexity.

Whatever elegant procedure in mathematics mostly ends up being addition, subtractions, multiplications and division (the last two are already a composition of the first two). So better than a division is hard to get. (aside from optimizations in this or that language)

Sure you may have the function F(z) that is all fancy, but behind F(z) mostly there are the four functions arranged somehow.

Once again, this looks to me like a fizzbuzz problem. The most that I can see is accelerated division (still division).
Like:

- given a number
- compute what could be a number made out of power of two with similar magnitude of the given number. Divide the given number by this number. If the result is not a whole, half the exponent of the power of two and try again (like binary search).
- Same for power of 5.

At the end it may be an (apparent) faster search of the exponents, but the straight division would be faster I would bet.

Another way is to apply the simple division but for increasing power.

- Given X
- divide X by 2. If the reminder is 0, divide it by 4. If the reminder is 0, divide it by 8. Etc.. If it fails, try again with 2 and so on.
- Same by 5.

Still, at the end is the same procedure, just with "hidden" divisions.


It is a bit like: what is more elegant: 1.414213.... or the continued fraction [1; 2, 2, 2, 2, 2, 2 ...] to identify square root of 2?

Some would say the square fraction, because it looks powerful and complicated.
Some others would say the decimal expansion, because it is the result of the complicated continued fraction that therefore is not needed.

It depends on what one wants to optimize.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mini-challenge: MAX(factors of 2 or 5) - pier4r - 01-19-2018 11:48 PM



User(s) browsing this thread: 1 Guest(s)