Beta

Twice Their Age

Description
Loading description...
Puzzles
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    Reference solution and fixed tests also ignore any situation where both person have 0yo in age (which would be twice the age of the other, since 0 * 2 = 0):

    Abraham Lincoln and Charles Darwin
    
    how_many_days(02/12/1809, 02/12/1809)
    365 should equal 0
    
  • Voile Avatar

    Reference solution is demonstrably wrong:

    Testing for 04/20/1993 and 06/02/1772
    365 should equal 366
    
    04/20/2213 - 06/01/2213
    04/20/1993: 220yo
    06/02/1772: 440yo
    
    06/02/2214 - 04/19/2215
    04/20/1993: 221yo
    06/02/1772: 442yo
    

    These two range will sum up to 365 as none of the ranges hit leap years.

  • bidouille Avatar

    Well, I spent some times on this, and I'm sorry to agree with gopherati, the reference code is buggy. After guessing a lot, I assumed my code is OK and so I passed the tests in force (trying until random being in my favor). The problem with your code is that when oldest birthday is before youngest in the year (see spoiler comment below).

    Also, while trying another way to do this, I got this error: ValueError: day is out of range for month To me, this can happen only with one of birthday being "02/29/Y".

    Finally, the fact I passed the test in force means there isn't enough edge cases tests. There should be at least every combinations of: oldest_birthday < or == or > youngest_birthday, "02/28" equal to one of, or before, or between, or after birthdays, more or less than 365 days between births.

  • gopheratl Avatar

    ... tentatively niling this as subsequent poking makes me think it is just my code after all.

    • tachyonlabs Avatar

      Thanks! I'm off at a conference right now, but will look into this this weekend after I ger back. I certainly used date objects myself.

    • gopheratl Avatar

      you responded just as I was nil'ing that comment, after poking at some other fail cases I'm thinking the problem might be my code after all. By the time you get back I'll know for sure :)

      :edit: aand I can't un-nil it now because it has responses, lol

      original comment seems correct.

      random test gave:

      Testing for 01/09/1999 and 11/04/2101
        365 should equal 366
      

      Test case so simulate in python:

      test.describe("Example tests")
      test.it("Testing for 01/09/1999 and 11/04/2101")
      test.assert_equals(how_many_days("01/09/1999","11/04/2101"),366)
      

      age difference is 102 stepping through:

      A = 1/9/1999 --older
      B = 11/4/2101  --younger
      age_dif = 102 (measured as age of A at time of birth of B)
      A turns 204 on 1/9/2203
      B turns 102 on 11/4/2203 -- begin first double period
      A turns 205 on 1/9/2204 -- end first double, wouldn't include leap day regardless
      B turns 103 on 11/4/2204
      A turns 206 on 1/9/2205 -- begin second double period
      B turns 104 on 11/4/2205 -- end second double period, 2205 is not a leap year
      

      In testing a second cases, I made a math mistake and had to go back and re-check the first to make sure I hadn't done the same there.

      Here's another case, with the opposite problem (expects 365 when shoudl be 366)

      random test gave:

      Testing for 08/14/1765 and 08/08/1844
        366 should equal 365
      

      Test case to simulate in python:

      test.describe("Example tests")
      test.it("Testing for 08/08/1844 and 08/14/1765")
      test.assert_equals(how_many_days("08/08/1844","08/14/1765"),365)
      

      stepping through:

      A = 08/14/1765 --older
      B = 08/08/1844 --younger
      age_dif = 78 (measured as age of A at time of birth of B)
      A turns 156 on 8/14/1921
      B turns 78 on 8/8/1922 -- begin first double period
      A turns 157 on 8/14/1922 -- end first double, wouldn't include leap day regardless
      B turns 79 on 8/8/1923
      A turns 158 on 8/14/1923 -- begin second double period
      B turns 80 on 8/8/1924 -- end second double period, includes feb. 1924, 1924 is a leap year