Sort by

recency

|

1522 Discussions

|

  • + 0 comments

    python 3

    def julian_year(year):
        if year % 4 == 0:
            return f"12.09.{year}"
        else:
            return f"13.09.{year}"
    
    def transition_year():
        return "26.09.1918"
    
    def gregorian_year(year):
        if year % 400 == 0:
            return f"12.09.{year}"
        elif year % 100 == 0: 
            return f"13.09.{year}"
        elif year % 4 == 0: 
            return f"12.09.{year}"
        else:
            return f"13.09.{year}"
    
    
    def dayOfProgrammer(year):
        
        if 1700 <= year <= 1917:
            return julian_year(year)
        elif year == 1918:
            return transition_year()
        elif 1919 <= year <= 2700:
            return gregorian_year(year)
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/U1u7Zz4ngVg

    string dayOfProgrammer(int year) {
        if(year == 1918) return "26.09.1918";
        if( (year <= 1917 && year % 4 == 0) or (year > 1918) && (year%400 == 0 or ((year%4 == 0) & (year%100 != 0)))) return "12.09."+to_string(year);
        return "13.09." + to_string(year);
    }
    
  • + 0 comments
    def dayOfProgrammer(year):
        # Write your code here
        cabisat = False
        if year < 1918:
            # Julian Leap Year rule: Divisible by 4
            if year % 4 == 0:
                cabisat = True
            else:
                cabisat = False
        else:
            # Gregorian Leap Year rule: Divisible by 4, except divisible by 100 unless divisible by 400
            cabisat = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
        totalMonth = 0
        totalTemp= 0
        currentDate =''
        for i in range(1, 13):
            if i == 2:
                if cabisat is True:
                    totalTemp+=29
                else:
                    totalTemp +=28
                totalMonth+=1
            else:
                if i in [1, 3, 5, 7, 8, 10, 12]:
                    totalTemp+=31
                    totalMonth+=1
                else:
                    totalTemp+=30
                    totalMonth+=1                
            if totalTemp >= 256:
                # Calculate the exact day of the 256th day
                day_of_programmer = 256 - (totalTemp - (31 if i in [1, 3, 5, 7, 8, 10, 12] else 30))
                
                # Ensure the month is two digits
                totalMonthStr = f'{i:02d}'
                currentDate = f'{day_of_programmer}.{totalMonthStr}.{year}'
                return currentDate
    
  • + 1 comment

    I don't understand the case for year: 1918? If none of the Calendars apply, then the date should be Sept 13. Could someone explain why it's 26.9.1918?

  • + 0 comments
    def dayOfProgrammer(year):
        # Write your code here
        
        if year == 1918:
            return f"26.09.{year}"
        
        elif year < 1918:
            if year % 4 == 0:
                return f"12.09.{year}"
            else:
                return f"13.09.{year}"
                
        else:
            if (year % 400 == 0) or (year % 4 ==0 and year % 100 !=0):
                return f"12.09.{year}"
            else:
                return f"13.09.{year}"