# [Community Puzzle] [Solved] How time flies: Not all tests passed

https://media.tenor.com/images/aafdfdcf15681b0c81a43b8dce787f45/tenor.gif

make it a disco light!!! hahahaha

Hi!

Iâve trying to solve this puzzle and I always get the test cases correct but when I submit the code I get a 50% score saying that I failed on validator 3, 4 and 6.

I donât see where my code could fail. Can somebody have a look a help me maybe finding out what could be causing the fail? I did it in Python 3.

``````import sys
import calendar
from datetime import date

begin = input()
end = input()

y1=(int)(begin[6:])
m1=(int)(begin[3:5])
d1=(int)(begin[0:2])

y2=(int)(end[6:])
m2=(int)(end[3:5])
d2=(int)(end[0:2])

D1 = date(y1, m1, d1)
D2 = date(y2, m2, d2)
total = (D2 - D1).days

s=''

m=(int)(end[3:5])-(int)(begin[3:5])
y=(int)(end[6:])-(int)(begin[6:])

D1=date(y2, m1, d1)
F=(D2 - D1).days
if F>30 and F<60:
m-=1

d=(int)(end[0:2])-(int)(begin[0:2])

if y>0:
s+=(str)(y)
if y>1:
s+=' years'
else:
s+=' year'

if m>0:
if y>0:
s+=', '
s+=(str)(m)
if m>1:
s+=' months'
else:
s+=' month'

if m>0 or y>0:
s+=', '
s+='total '
s+=(str)(total)
if total==1:
s+=' day'
else:
s+=' days'

print(s)``````

I must have wasted about 4 hours on this puzzle. Iâd rather embrace my condition of hopless n00b who canât even wrap his head around leap years than waste another hour on it.

There is nothing I dislike more than punishing puzzles that slam the validators in your face after a bunch of useless tests lulling you into a false sense of accomplishment.

I would gladly fail the month difference validation since that notion has no clear definition and the OP didnât bother to explain what he meant by that or provide meaningful tests that could have helped guessing.
I did try a few different methods. 30 days average, count of elapsed months, taking the day of the month into account or notâŚ 4 methods passed the tests, none passed the validation.

Why a validator that supposedly checks only the number of days between two dates would turn down my code will remain forever a sweet mystery to me, but I guess i can live with that.

2 Likes

Is this puzzle really an easy one? Its success rate is currently 49%. Quite a number of Codingamers expressed that all unit tests passed, whereas some evaluation tests failed. Plus, the specification is quite ambiguous (should you write 1 day or 1 days?)

It would be nice that someone audits some submissions that pass all unit tests and fail some evaluation tests. This could let add some unit tests and/or clarifiy the specification.

1 Like

Same problem here - validators 3,4,6. Is there any example of dates that they may be checking?

Yep, you got it wrong but the tests are not telling it.
You measure year difference by substracting the year which is very wrong.
Between the 31.12.2015 and the 01.0.2016 thereâs one day for instance, but you would output 1 year, 1 day.

I added test cases and validators and update existing ones.

Hello guys !
One more poor noobâŚ Iâm passing all the tests in the editor, all the ones proposed in this thread but still doesnât validate the Full Month in the official tests
Hereâs my code (C#)

beg and end are just a simple class (with day/month/year fields and < overloaded operator)
Month duration takes leap year into account (hence the second parameter)

CODE REMOVED (because itâs an algorithm that actually worksâŚ the problem was elsewhere)

Iâm not asking for a fix, just test cases

Thanks !

I can only guess whatâs wrong with your code, but Iâm preeeeeeeeeetty sure your âMonthDurationâ function is wrong. I think youâre doing something alike this:
if (month == 2) return 28 + leapYear ? 1 : 0;

But your months start at 0, so month == 1 would be February.
Why not use the DateTime-struct, though?

Edit:
Also wondering how your code passes the other tests. Your leapYear-Boolean seems to be static, but what if I begin to count the days in 2015 (no leap year) and pass through 2016, which is a leap year? You should update your leapYear-Boolean when switching years. (Or just use DateTime-struct )

Itâs the month count that begin at 0, not the month value (which is beg.month and is just decremented)

``````beg.year++;
leapYear = IsLeapYear(beg.year);
``````

And for your last comment, youâre also right, I could use the DateTime object but I believe itâs much more fun to code it from scratch

I found the bugâŚ Itâs on the code displaying the result, for 2 months I was displaying â2 monthâ instead of â2 monthsâ âŚ shame on me.

I fail to solve â03 - Years and monthsâ and â08 - One yearâ when I submit my code, and I suspect it has something to do with leap years. Can somebody who have solved this puzzle provide the output given the following input:

Case 1)
29.02.2016
01.03.2017

Case 2)
29.02.2016
28.02.2017

Case 1) 1 year, 366 days
Case 2) 11 months, 365 days

I have a problem with the same tests as @PhilipHassel. Both cases he gave are good for me. May someone have other tests for us to try ? Iâm kinda lost on what is missing nowâŚ

If they are good for you, why do you say you have a problem with the same tests ?

@Kirbiby I donât have problem with the Tests HE gave

(Case 1 : 29.02.2016/01.03.2017 && Case 2 : 29.02.2016/28.02.2017)

but I have a problem with â03 - Years and monthsâ and â08 - One yearâ tests from the submit ones.

As we canât see the tests cases, Iâm asking here if someone has others to try debugging what could be wrong in my code.

Tell us here what was blocking you; maybe we can improve the test cases.

I added testcases two months ago, but I donât remember if I touched 03 and 08

I found the problem.

For exemple if I was the 20.03.2024 to go to the 20.03.2025 I wasnât taking care of the fact that I already was in march. I wasnât removing all days from 01.01.2024 to the 20.03.2024 and add those of 2025.

With the leap years it changes everything ! ^^.

Thx for you help !

Thank you, I found the problem This puzzle was unexpectedly hard!

I think too ^^. In my opinion itâs at least a medium one and not an easy one !