Post Reply 
Mini-challenge: MAX(factors of 2 or 5)
01-19-2018, 07:39 PM
Post: #12
RE: Mini-challenge: MAX(factors of 2 or 5)
(01-19-2018 02:40 PM)Thomas Okken Wrote:  
(01-19-2018 02:10 PM)pier4r Wrote:  Then I don't see why checking through division it is "unelegant".

I think Joe meant "slow."

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.

Brilliant Analogy: Imagine that I have a HUGE barrel containing a zillion American coins. I want to know how many pennies and nickels are in the barrel. My original FACTORS method above is analogous to pouring the entire barrel's contents into a very fast coin counting machine, which would count ALL the types of coins. That's fast and easy, but it's functional overkill, because it also counts the dimes, quarters, half dollars, and dollars.

On the other hand, the brute-force division methods above is analogous to spreading all the pennies out on the floor, looking for pennies, and counting as you remove them from the floor. Then, when that's done, do the same for the nickels. That has the benefit of not spending time counting the unwanted coins. But it's totally not elegant; it's just brute-force counting.

My suggested trick (GCD with 2^10 and 5^10) is analogous to grabbing handfuls of ten pennies at a time... and then counting the last handful which is less than 10. It's better than counting them all 1 at a time. But how much more elegant is counting handfuls instead of counting coins? Ah, my quest for a number theory trick continues....

<0|ΙΈ|0>
-Joe-
Visit this user's website 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) - Joe Horn - 01-19-2018 07:39 PM



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