9
0
It is December 2014, and 2015 has almost started. However, it appears not everyone has realized this.
But the people of PPCG come to the rescue!
Input
Your program is given a grid like the one one the wall, where days that are in the month December look different from those in November and January. Each week starts with Sunday and ends with Saturday.
Days within the month are represented by a #
. Days that fall outside the month are represented by a (space, ASCII code 32). Each week is on a separate line. Lines are separated by a newline character (
\n
). Your program may require either the ommission or inclusion of a newline at the end of the input.
For example, this is the input for December 2009:
#####
#######
#######
#######
#####
The calendar is always of the month December.
Task
Given the input, you must find the year associated with the calendar. Since there are multiple years for which a calendar matches, you must return the year (before 2015) that is the closest to 2015. (Excluding 2015 itself.)
Your program must produce the correct output for any year < 2015, excluding those which have a calendar layout for December that is equal to that of another year (before 2015) closer to 2015.
If the year is < 2014, you must also calculate the difference of the year to 2014. For example, for 2012 the difference is 2
.
Output
Your program's output must be:
- The text:
Your calendar is for <year>.
(Note: since this was originally spelled as “calender“, I’ll accept that spelling as well.) - Followed by a newline (
\n
or\r\n
). - Followed by the text:
It's almost 2015.
- If the year is < 2014, this must be followed by the text:
You're <difference> years behind.
This must be on a separate line. - Followed by a newline (
\n
or\r\n
). - Followed by the text:
Go buy a new calendar!
- Optionally followed by a newline (
\n
or\r\n
).
Rules
- You can choose whether you want to receive the calendar as a command-line argument (e.g.
yourprogram.exe <calendar>
) or prompt for user input. - You may assume your program won't receive invalid input. Invalid input includes calendar layout for which there exists no year.
- The shortest code (in bytes, in any language) wins.
Any non-standard command-line arguments (arguments that aren't normally required to run a script) count towards the total character count.
What your program must not do:
- Depend on any external resources.
- Depend on having a specific file name.
- Output anything other than the required output.
- Take exceptionally long to run. If your program runs over a minute on an average home user's computer, it's invalid.
- Your program must not be written in a programming language for which there did not exist a publicly available compiler / interpreter before this challenge was posted.
Examples
Input:
#####
#######
#######
#######
#####
Output:
Your calendar is for 2009.
It's almost 2015.
You're 5 years behind.
Go buy a new calendar!
Input:
######
#######
#######
#######
####
Output:
Your calendar is for 2014.
It's almost 2015.
Go buy a new calendar!
Input:
#
#######
#######
#######
#######
##
Output:
Your calendar is for 2012.
It's almost 2015.
You're 2 years behind.
Go buy a new calendar!
Phew. Managed to post it 6 seconds before 2014 was over in UTC (which is used by SE). Also, Happy new year everybody! – user2428118 – 2015-01-01T00:00:50.153
Say, hypothetically, that 2016 and 2009 have the same shape. Then which one is the closest? (i.e. do you mean closest by absolute distance, or closest but earlier than 2015?) – Sp3000 – 2015-01-01T00:06:14.413
@SP3000 The latter. I've edited the post to clarify. – user2428118 – 2015-01-01T00:07:26.100
For the second test case, Dec 1 2014 was on a Monday but your calendar shows it start from a Sunday. Is this correct? – Sp3000 – 2015-01-01T00:21:09.250
@Sp3000 That was an error. I've fixed it, thanks. – user2428118 – 2015-01-01T00:33:15.537
2Is it really necessary to spell calendar two different ways in the output? – feersum – 2015-01-01T02:54:19.757
3"You can choose whether you want to receive the fraction as a command-line argument (e.g. yourprogram.exe 2/5)"... What? – feersum – 2015-01-01T06:18:51.120
@feersum Both were errors. The second one is because I copied some of the rules from this question of mine. I'll fix them.
– user2428118 – 2015-01-01T13:04:53.273@feersum That looks like an old mistake that wasn't corrected in the examples yet. The text:
Your calendar is for <year>.
(Note: since this was originally spelled as “calender“, I’ll accept that spelling as well.) – nyuszika7h – 2015-01-02T10:08:58.003@nyuszika7h I've already corrected those errors. I added the text you cite because the change would otherwise invalidate existing answers. – user2428118 – 2015-01-02T20:23:07.720
@user2428118 I know that's why you added it. But the examples still said "calender" in a few places. – nyuszika7h – 2015-01-03T14:17:43.390
adding kolmorogov-complexity tag because over half the bytes in the best entries are dedicated to representing the static strings. – Sparr – 2018-12-29T18:28:30.310