# HackerRank Day of the Programmer Solution

Hello Programmers, In this post, you will learn how to solve HackerRank Day of the Programmer Solution. This problem is a part of the HackerRank Algorithms Series.

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions. We are going to solve the HackerRank Algorithms problems using C, CPP, JAVA, PYTHON, JavaScript & SCALA Programming Languages.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology, Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

## HackerRank Day of the Programmer

Marie invented a Time Machine and wants to test it by time-traveling to visit Russia on the Day of the Programmer (the 256th day of the year) during a year in the inclusive range from 1700 to 2700.

From 1700 to 1917, Russia’s official calendar was the Julian calendar; since 1919 they used the Gregorian calendar system. The transition from the Julian to Gregorian calendar system occurred in 1918, when the next day after January 31st was February 14th. This means that in 1918, February 14th was the 32nd day of the year in Russia.

In both calendar systems, February is the only month with a variable amount of days; it has 29 days during a leap year, and 28 days during all other years. In the Julian calendar, leap years are divisible by 4; in the Gregorian calendar, leap years are either of the following:

• Divisible by 400.
• Divisible by 4 and not divisible by 100.

Given a year, y, find the date of the 256th day of that year according to the official Russian calendar during that year. Then print it in the format `dd.mm.yyyy`, where `dd` is the two-digit day, `mm` is the two-digit month, and `yyyy` is y.

For example, the given year = 1984. 1984 is divisible by 4, so it is a leap year. The 256th day of a leap year after 1918 is September 12, so the answer is 12.09.1984

Function Description

Complete the dayOfProgrammer function in the editor below. It should return a string representing the date of the 256th day of the year given.

dayOfProgrammer has the following parameter(s):

• year: an integer

Input Format

A single integer denoting year y.

Sample Input 0

```2017
```

Sample Output 0

```13.09.2017
```

Explanation 0

In the year y = 2017, January has 31 days, February has 28 days, March has 31 days, April has 30 days, May has 31 days, June has 30 days, July has 31 days, and August has 31 days. When we sum the total number of days in the first eight months, we get 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 = 243. Day of the Programmer is the 256th day, so then calculate 256 – 243 = 13 to determine that it falls on day 13 of the 9th month (September). We then print the full date in the specified format, which is `13.09.2017`.

Sample Input 1

```2016
```

Sample Output 1

```12.09.2016
```

Explanation 1

Year y = 2016 is a leap year, so February has 29 days but all the other months have the same number of days as in 2017. When we sum the total number of days in the first eight months, we get 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 = 244. Day of the Programmer is the 256th day, so then calculate 256 244 = 12 to determine that it falls on day 12 of the 9th month (September). We then print the full date in the specified format, which is `12.09.2016`.

Sample Input 2

```1800
```

Sample Output 2

```12.09.1800
```

Explanation 2

Since 1800 is leap year as per Julian calendar. Day lies on 12 September.

## HackerRank Day of the Programmer Solution

### Day of the Programmer Solution in C

```#include <stdio.h>

int main(){
int y;
scanf("%d",&y);
if(y<1918){
if(y%4){
printf("13.09.%4d\n",y);
}
else{
printf("12.09.%4d\n",y);
}
}
else if(y== 1918){
printf("26.09.1918\n");
}
else{
if((y%400 == 0) || (y%4 == 0 && y%100)){
printf("12.09.%4d\n",y);
}
else{
printf("13.09.%4d\n",y);
}
}
return 0;
}```

### Day of the Programmer Solution in Cpp

```#include <bits/stdc++.h>

using namespace std;

int main(){
int y;
cin >> y;
if(y<1918){
if(y%4==0)cout<<"12.09."<<y<<endl;
else cout<<"13.09."<<y<<endl;
}
else if(y==1918){
cout<<"26.09."<<y<<endl;
}
else{
if(y%400==0){
cout<<"12.09."<<y<<endl;
}
else if(y%4==0&&y%100!=0){
cout<<"12.09."<<y<<endl;
}
else cout<<"13.09."<<y<<endl;
}
return 0;
}```

### Day of the Programmer Solution in Java

```import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int y = in.nextInt();

if(y>=1700 && y<=1917){

if(y%4==0){
System.out.println("12.09."+y);
}
else{
System.out.println("13.09."+y);
}
}

else{

if(y==1918){
System.out.println("26.09."+y);
}
else{
if(y%400==0){
System.out.println("12.09."+y);
}
else if(y%4==0 && y%100!=0){
System.out.println("12.09."+y);
}
else{
System.out.println("13.09."+y);
}
}
}
}
}```

### Day of the Programmer Solution in Python

```#!/bin/python
import sys
y = int(raw_input().strip())
months = {0:31,1:28,2:31,3:30,4:31,5:30,6:31,7:31,8:30,9:31,10:30,11:31}
if y <= 1917:
tot = 0
for i in range(12):
if tot + months[i] > 256:
break
if y % 4 == 0 and i == 1:
tot = tot + 29
else:
tot = tot + months[i]
ans = ""
day = 256 - tot
month = i + 1
ans = ans + str(day) + ".0" + str(month) + "." + str(y)
print ans
elif y == 1918:
tot = 0
for i in range(12):
if tot + months[i] > 256:
break
if i == 1:
tot = tot + 15
else:
tot = tot + months[i]
ans = ""
day = 256 - tot
month = i + 1
ans = ans + str(day) + ".0" + str(month) + "." + str(y)
print ans
else:
tot = 0
for i in range(12):
if tot + months[i] > 256:
break
if (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0)) and i == 1:
tot = tot + 29
else:
tot = tot + months[i]
ans = ""
day = 256 - tot
month = i + 1
ans = ans + str(day) + ".0" + str(month) + "." + str(y)
print ans```

### Day of the Programmer Solution using JavaScript

```process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
input_stdin += data;
});

process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});

return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {

if(y == 1918){
console.log('26.09.' + y)
}else{

var leapYear = false;

if(y < 1918 && y % 4 == 0){
leapYear = true;
}else if(y > 1918 && y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)){
leapYear = true;
}

if(leapYear){
console.log('12.09.' + y);
}else{
console.log('13.09.' + y);
}

}

}```

### Day of the Programmer Solution in Scala

```object Solution {

def main(args: Array[String]) {

val leapYearDate = s"12.09.\$year"
val nonLeapYearDate = s"13.09.\$year"

println {year match {
case _ if year < 1918 => if (year % 4 == 0) leapYearDate else nonLeapYearDate
case 1918 => "26.09.1918"
case _ => if (year % 400 == 0 || (year % 4 == 0 && !(year % 100 == 0))) leapYearDate else nonLeapYearDate
}}
}
}```

### Day of the Programmer Solution in Pascal

```{\$mode objfpc}
program A;
const
JMonth: array [1..12] of Integer =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
{Thirty days hath September,
April, June, and November.
All the rest have thirty-one,}
GMonth: array [1..12] of Integer =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

var
y: Integer;
is_leap_year: Boolean;

begin

if y = 1918 then
WriteLn('26.09.1918')
else if y < 1918 then
begin
is_leap_year := (y mod 4 = 0);
if is_leap_year then
WriteLn('12.09.', y)
else
WriteLn('13.09.', y);
end
else
begin
is_leap_year := (y mod 400 = 0) or ((y mod 100 <> 0) and (y mod 4 = 0));
if is_leap_year then
WriteLn('12.09.', y)
else
WriteLn('13.09.', y);
end;
end.```

Disclaimer: This problem (Day of the Programmer) is generated by HackerRank but the solution is provided by Chase2learn. This tutorial is only for Educational and Learning purposes.

## FAQ:

1. How do you solve the first question in HackerRank?

If you want to solve the first question of Hackerrank then you have to decide which programing language you want to practice i.e C programming, Cpp Programing, or Java programming then you have to start with the first program HELLO WORLD.

2. How do I find my HackerRank ID?

You will receive an email from HackerRank to confirm your access to the ID. Once you have confirmed your email, the entry will show up as verified on the settings page. You will also have an option to “Make primary”. Click on that option. Read more

3. Does HackerRank detect cheating?

yes, HackerRank uses a powerful tool to detect plagiarism in the candidates’ submitted code. The Test report of a candidate highlights any plagiarized portions in the submitted code and helps evaluators to verify the integrity of answers provided in the Test.

4. Does HackerRank use camera?

No for coding practice Hackerrank does not use camera but for companies’ interviews code submission time Hackerrank uses the camera.

5. Should I put HackerRank certificate on resume?

These certificates are useless, and you should not put them on your resume. The experience you gained from getting them is not useless. Use it to build a portfolio, and link to it on your resume.

6. Can I retake HackerRank test?

The company which sent you the HackerRank Test invite owns your Test submissions and results. It’s their discretion to permit a reattempt for a particular Test. If you wish to retake the test, we recommend that you contact the concerned recruiter who invited you to the Test and request a re-invite.

7. What is HackerRank?

HackerRank is a tech company that focuses on competitive programming challenges for both consumers and businesses. Developers compete by writing programs according to provided specifications. Wikipedi

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.