The Day of the Programmer

This Hackerrank problem asks you given the year, the 256 date of that year according to the Russian Calendar.

Screen Shot 2017-11-05 at 5.35.44 PM

The Code:

import sys

def solve(year):
    months = [31,28,31,30,31,30,31,31]
    
    if year > 1918:
        if year%400 == 0 or (year%4 == 0 and year%100 != 0):
            months[1] = 29
            tmp = sum(months)
            day = 256-tmp
        else:
            tmp = sum(months)
            day = 256-tmp
    elif year == 1918:
        months[1] = 15
        tmp = sum(months)
        day = 256-tmp
    else:
        if year%4 == 0:
            months[1] = 29
            tmp = sum(months)
            day = 256-tmp
        else:
            tmp = sum(months)
            day = 256-tmp
    

   return (str(day) + '.' + "09" + '.' + str(year))
year = int(input().strip())
result = solve(year)
print(result)

For this problem, I set the number of days in the months from January through August into an array and summed them together. After which I subtracted from 256 and got the day. To get the variations in days I altered the month of February based on the calendar system.

Developer Aside:

I took the easy way out in displaying the month since in the Russian calendar system (regardless of the year) the 256 day lands in September.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s