[Community Puzzle] How time flies

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

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.

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 :slight_smile: This puzzle was unexpectedly hard!

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

My solution turned out really ugly, but at least it works hahah

Hi everyone,
I’m trying to solve this puzzle. It seem’s i have a fine solution to me.
But after submitting my code, the ‘06 COMPLEX’ test doesn’t pass, so I’m stuck at 88%.
I havn’t hardcoded anything but i clearly miss something (enonciate doesn’t help me, it’s not really precise). Without knowing what kind of validator i need to pass, i can’t deduce what the problem is :woman_shrugging:.
That’s really frustrating, do you have a sample to try another complex by my self before submitting a new proposal?

Thank’s a lot.

1 Like

can u send me a code in c++ for this game

Your program must print formatted string with the number of full years and full months (if there are any greater than 0) and the total number of days between BEGIN and END dates in dd.mm.yyyy format.

Example 1:

Input:
01.01.2000
01.01.2016

Output:
16 years, total 5844 days

Example 2:

Input:
15.12.2014
14.02.2016

Output:
1 year, 1 month, total 426 days

Example 3:

Input:
01.01.2016
18.08.2016

Output:
7 months, total 230 days

Input

Line 1: A date BEGIN in dd.mm.yyyy format.
Line 2: A date END in dd.mm.yyyy format.

Output

Line 1 : Formatted string presenting date difference as “YY day[s], MM month[s], total NN days”

Constraints

BEGIN ≤ END

Example

Input

01.01.2000 01.01.2016

Output

16 years, total 5844 days

WHICH IS THE SOLUTIOOOOON PLEAAAAASE! I´m a begginer programmer

if we tell you the solution, then you’ll remain a beginner forever.

You need to learn how to ask for help and explain what issue do you encounter while solving this puzzle.

EDIT: link to puzzle: Coding Games and Programming Challenges to Code Better

1 Like

The standard approach to problems s like this is:
Solve it with pen&paper.

What is the input, what is the solution, what kind of steps would you have to perform to arrive from input to solution, and finally, how would you implement it.
The penultimate part being the important one.
Which can be only unsuccessful, if you meticulously documented the parts before.

That is, how you learn how to think like a programmer. :wink:

HTH and have fun here!

1 Like

Hi,

i just noticed an error in the goal examples for the “How time flies” puzzle.

The Output Description says

Output

Line 1 : Formatted string presenting date difference as “YY day[s], MM month[s], total NN days”

The Output description should read
YY year[s] instead of YY day[s]

thanks for reporting. I’ve just edited it.

Hey, here is my ugly python code:
I’m passing all the first tests, but it seems like i have hardcoded something ?

I tried something about the 29.02.2016 => 28.02.2017.
I know there is a better way to write, but i’m beginning with python :frowning:

Could someone give me a hint on what’s wrong ?

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

begin = input().split('.')
end = input().split('.')
def bissextile(year):
    if (not year%4 and year%100) or not year%400:
        return True
    return False
m31=[1,3,5,7,8,10,12]
m30=[4,6,9,11]


d1 = int(begin[0])
d2 = int(end[0])
m1 = int(begin[1])
m2 = int(end[1])
y1 = int(begin[2])
y2 = int(end[2])
d=0
m=0
y=0
if d1==29 and m1==2 and d2==28 and m2==2:
    d1=28
    y1+=1
    m=+11
    d+=365
i=0
if m1 in m31:
    i=31
elif m1 in m30:
    i=30
else:
    if bissextile(y1):
        i=29
    else:
        i=28
while(d1!= d2):
    d1+=1
    d+=1
    if d1 > i:
        d1%=i
        m1+=1
        if m1>12:
            m1%=12
            y1+=1
while(m1!=m2):
    j=0
    if m1 in m31:
        j=31
    elif m1 in m30:
        j=30
    else:
        if bissextile(y1):
            j=29
        else:
            j=28
    m1+=1
    m+=1
    d+=j
    if m1==13:
        m1%=12
        y1+=1
while(y1!=y2):
    if bissextile(y1):
        d+=366
    else:
        d+=365
    y1+=1
    y+=1

if y>1:
    print(f'{y} years, ', end='')
elif y==1:
    print(f'{y} year, ', end='')
if m>1:
    print(f'{m} months, ', end='')
elif m==1:
    print(f'{m} month, ', end='')
print(f'total {d} days')

Try this testcase:

01.04.2000
01.04.2001
01.04.2000
01.04.2001
1 year, total 366 days

ah. Right
Thx

I can’t pass the 06-Complex validator, and I don’t know why…
Any clues or other test ?

Try:

11.05.2000
04.02.2016

Answer:

15 years, 8 months, total 5747 days
1 Like

Thanks, I manage to get 100% with this one :+1: