100 Balls, etc.: The Exciting Conclusion!
Posted by Mr. ANSI Pants | Filed under Challenge of the Month
[When we last visited our intrepid hero, he was engaged in a battle of wits atop the tallest turret of Fallacy Fortress. The fate of the world is again in his hands. We join him now...]
Dr. Destructor: Wait till I get going! Where was I?
Capt. Constructor: Australia. Oh wait. I mean, you were just telling me about spheroids, buckets, and a scale.
Dr. Destructor: Right! I, like many non-virtual Destructors out there, suffer from occasional memory leaks. Don’t tell me you Constructors are immune. Australia? Ha!
Tags: thought puzzles
100 Balls, 10 Buckets, 1 Single-Use Scale
Posted by Mr. ANSI Pants | Filed under Challenge of the Month
[We join our hero, Captain Constructor, atop the tallest turret of Doctor Destructor's hidden hideout: Fallacy Fortress...]
Dr. Destructor: You’re too late, Constructor! Before the next clock cycle, all of those mortals you call friends will be destroyed! And your little dog, too! [Maniacal laughter...]
Cptn. Constructor: Close your handle, Destructor. Just tell me how to interrupt the detonation kernel … er … process … sequence … thing.
Dr. Destructor: The sequence is perfectly synchronized and it cannot be pre-empted! Unless, of course, you are able to correctly identify the set of slightly-heavier-than-the-rest spheroids. But it is a task that is surely intractable to your puny single-core mind.
Cptn. Constructor: YOUR FACE IS SINGLE-CORE! [Our hero clears his throat, embarrassed. He is not generally given to such base language. Quickly he recovers his composure.] Tell me more about these spheroids.
Dr. Destructor: Over here you will find I have sorted 100 spheroids into 10 buckets. Each bucket holds 10 spheroids, as you can plainly see. 90 of these spheroids all weigh 1 gram each. The other 10 weigh 1.01 grams each and they have been placed all together in the same bucket. You should also have noticed by now that all 100 spheroids are visually indistinguishable from one another. Shall I go on? Your stack is beginning to look overflowed.
Cptn. Constructor: I have stack space you could never even dream of. continue;
Dr. Destructor: Immediately next to the buckets I have placed a scale. The scale has been badly damaged from overuse. I keep telling that furry PHP elephant he’s too big! Never mind that, though. I assure you that the scale is still perfectly accurate. However, it only has one good measurement left in it.
Cptn. Constructor: What does all of this have to do with the spheroids?
Dr. Destructor: It should be quite clear that to interrupt the sequence of destruction, you must identify which bucket contains the heavier spheroids. You may take any combination of spheroids you like from these 10 buckets, place your selection in this empty bucket labelled “this.EmtpyBucket”, and place “this.EmptyBucket” (which at that point will no longer be empty) on the scale. The scale will tell you the weight and you must then tell me which of the 10 buckets contains the heavier spheroids.
Cptn. Constructor: Truly, you have a dizzying intellect.
Dr. Destructor: Wait till I get going! Where was I?
[Join us next time for the exciting conclusion...]
Tags: thought puzzles
Programming Challenge: Time Parser
Posted by The Code Lisperer | Filed under Challenge of the Month
OK, this challenge is shamelessly borrowed from a challenge issued by Sasha on the Provo Linux Users Group mailing list, but I remember enjoying it so I figured I’d share. Make a solution in any language. The more, the merrier! Post solutions in the comments.
Input: A string containing an arithmetic expression consisting of times. The times could be in seconds, but they could also be in colon form: 3:12 is 192 seconds, 1:45:03 is 1 hour, 45 minutes, 3 seconds. There also may be fractions of seconds: 2:28.42 is 2 minutes, 28.42 seconds.
Output: Leave the arithmetic expression intact, but convert all times into seconds. So:
1:45.2 + 83 - 2:34 becomes 105.2 + 83 - 154
Enjoy, and good luck!
-The Code Lisperer
Tags: challenge, coding, conversion, programming, time