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


#21

:flashlight:


#22

make it a disco light!!!! hahahaha


#23

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)

#24

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.


#25

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.


#26

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


#27

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.


#28

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 :frowning:
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 :wink:

Thanks !


#29

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 :wink: )


#30

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

About the leapYear, the code already does what you suggest :

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 :smiley:

:sunny: 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.


#31

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


#32

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


#33

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…


#34

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


#35

@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.


#36

I’ve sent you the validators in DM. Should help you find the issue in your code.

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


#37

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


#38

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 !


#39

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


#40

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