[Community Puzzle] How time flies

Hi @_CG_SaiksyApo,
I tried this:
Console.WriteLine(Thread.CurrentThread.CurrentCulture);
gives me: en-US. Is that your question?

Yes, I used:

using System.Globalization;
Console.WriteLine(CultureInfo.CurrentCulture);

And it shows en-US too (on CG), I don’t understand why it’s parsed like ‘day.month.year’ in your VS tho :’(

1 Like

indeed, the culture needed to be set though VS did not have a problem with that. thank you.

Hi, I think you all are cheating, using Date/Time functions of languages.
I suppose the spirit of the puzzle is solving it without them, otherwise some language could do all job for you.
But I can be wrong :wink:

You can solve with just this function and the plain old math:

function daysinmonth(m,y){
  var days=[31,28,31,30,31,30,31,31,30,31,30,31];
  return days[m-1] + ( ((m==2)&&(((y%4==0)&&(y%100!=0))||(y%400==0))) ?1:0);
}

or, if you don’t like arrays and really love math :wink: :

function daysinmonth(m,y){
 return (((Math.abs(2*m-15)+1)/2)%2) + ( (m!=2)?30: ( (((y%4==0)&&(y%100!=0))||(y%400==0)) ?29:28) );
}
1 Like

is there anyone can shed some light as to why some of the areas in the validators didn’t pass?

:flashlight:

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.

3 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 :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 !

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

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.

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 ?