Hacker News new | ask | show | jobs
by father_of_two 4080 days ago
I'm not surprised with Singapore's kids being smart, but Albert and Bernard really impressed me :) Here's a solver in python (just an hack, don't unleash hate on me).

  import collections

  dates = '''may 15 may 16 may 19
             jun 17 jun 18
             jul 14 jul 16
             aug 14 aug 15 aug 17 '''

  def dups(xs,pos):
      return [k for k,v in collections.Counter(x[pos] for x in xs).items() if v>1]

  days = dates.split()[1::2]
  months = dates.split()[0::2]
  dts = [(d,m) for d,m in zip(days, months)]
  # A doesn't know, and knows B doesn't know-- cut days occurring once
  dts = [dt for dt in dts if all(not(dt[0]==d or dt[1]==m)
           for d,m in zip(days, months) if days.count(d)==1)]
  # now B knows-- cut dup days
  dts = [dt for dt in dts if dt[0] not in dups(dts,0)]
  # A also knows-- cut months with more than 1 day
  dts = [dt for dt in dts if dt[1] not in dups(dts,1)]
  print dts
1 comments

I might have missed something here, but I think your explanation for the second "instruction" isn't exactly valid.

# now B knows-- cut dup days

You're not removing duplicate days. You're removing months that contained "days occurring once".

Because A knows: B doesn't know. Which means A knows it's not on May and June -the only months containing "days occurring once.

I solved it this way (in my head).

#MONTH doesn't know and knows DAY doesn't know

Remove "all days occurring once"

Remove "months that contained single occurrence days"

#DAY didn't know, but knows now.

Remove "duplicate days"

#MONTH knows now.

Remove "Months with more than 1 day"

Leaving July 16. :-)