[PyAR2] Car Talk Puzzler
jhjaggars at gmail.com
Mon Jun 20 00:53:35 CEST 2011
Here is my solution that disregards leading zeros in the hour spot.
Feel free to point out the bugs.
from collections import defaultdict
return "%02d" % bit
def test(hour, minute):
counter = defaultdict(int)
for pos in str(hour) + fmt(minute):
counter[pos] += 1
for key,value in counter.iteritems():
if value >= 3:
if __name__ == "__main__":
times = 0
for half in ('am', 'pm'):
for hour in range(1,13):
for minute in range(0, 60):
print "%s:%s %s" % (str(hour), fmt(minute), half)
times += 1
On Mon, May 2, 2011 at 11:45 AM, Greg Lindstrom <gslindstrom at gmail.com>wrote:
> Each week, the radio program "Car Talk" (NPR) offers up a puzzler; a quirky
> problem that usually requires some sort of "aha" to solve. Sometimes
> they're mathematical, sometimes not. This week, the puzzler asks "How many
> times in a day does a digital clock (in 12-hour mode) display a time with 3
> of the same digits (1:11, 2:22, etc.). It's a "trick" question, of course,
> but it took less than 5 minutes for me to write a python program to solve it
> (my boss will be happy to know that because I should be working).
> Can you write a routine to solve it?
> PyAR2 mailing list
> PyAR2 at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyAR2