The Fry King is a small criminal mastermind from the western european nation of Belgium, more specifically Flanders. He has acquired every single fastfood restaurant in a large part of Belgium and set them out on a 101X49 grid (102 intersections horizontally, 50 vertically, including the borders), 5100 restaurants in total located on the intersections. The next step in his diabolical plan is to orchestrate the closing hours of these restaurants so that on any one day of the year (bar 2 explained later), only 1 corner of each square will have an open restaurant.

Example with a 6X2 grid:

|   |   |   |   |   |

A year has 365 days. On the first Monday of the year, only the restaurants with number 1 will be open. On the next day, Tuesday, only those with the number 2. On the next day, Wednesday, only those with number 3. On the next day, Thursday, only those with number 4. after that, it starts again at 1. The days before the first Monday count back. For example, if the first Monday falls on January 3rd, the Sunday before the 4s will be open. This might mean that when the year changes, a store might be open twice or might be skipped in the rotation.

There are 2 exceptions: the 21st of July is the national holiday. All restaurants are open. Another is the 29th of February. Because this is the Fry King's birthday, all restaurants are also open. These exceptions replace a normal day, so if the 20th is for the restaurant with number 1, the 22nd is for the joints with number 3.


You are a vigilante coder who has setup a toll-free texting number. It accepts 3 values, delimited by an *: A number between 1 and 101 denoting the column value you're in, a number between 1 and 49 to denote the row number you're in (these 2 determine which joints are eligible) and a date in the format of DD/MM/YYYY (day/month/year). The number returns 2 letters indicating which corner of your square contains today's open restaurant (NW-NE-SE-SW). If there are multiple options, it returns the first eligible one from the previous series.










Calculation is code golf. Shortest code in bytes wins. There are no special bonuses to win or limitations involved, apart from 1: no external resources.

  • 1
    \$\begingroup\$ Note: some of you might have seen this topic posted for a moment or 2. I mistook the Beta tag for Meta and thought I posted it on PCG Meta, so I deleted it before I realized that, yes, I posted this in the right place. \$\endgroup\$
    – Nzall
    Apr 21, 2014 at 17:56
  • \$\begingroup\$ Note that we usually do not impose deadlines for code-golf. It might also discourage people to consider solving your challenge. Anyways you can change the accepted answer when a new best answer is posted. \$\endgroup\$
    – Howard
    Apr 22, 2014 at 6:46
  • \$\begingroup\$ @Howard I see. I've removed the deadline. \$\endgroup\$
    – Nzall
    Apr 22, 2014 at 7:19

2 Answers 2


Python 2 (228 209 208 207)

(not counting the last newline)

import time
if t[1:3]in[(2,29),(7,21)]:t=s("%s%s"%(t[0],t[7]-1),"%Y%j")


  • substituted variables that were used only once, further golfed the print statement.
  • Removed the space after print as isaacg suggested.
  • Changed from time import*;s=strptime to import time;s=time.strptime to shave off one extra byte
  • 1
    \$\begingroup\$ Get rid of the space following the print. \$\endgroup\$
    – isaacg
    Apr 22, 2014 at 17:52
  • \$\begingroup\$ I think import time s=time.strptime shaves off 1 more character. \$\endgroup\$
    – MrLemon
    Apr 28, 2014 at 9:12
  • \$\begingroup\$ Thanks for the suggestions, they've been added (Or rather, removed?) \$\endgroup\$
    – 14mRh4X0r
    Apr 28, 2014 at 9:23

Mathematica: 272


Assumes that the input string is in a variable named i like so (perhaps add 4 chars for i=""?):

i = "2*1*20/01/2014"

Also I leave the following out of the character count (perhaps add 18 for that):


And the trailing ; on each of the non-output lines (perhaps add 9 for those). Below is a slightly ungolfed version of the code for testing/editing:

i = "2*1*20/01/2014";
R = Mod[#, 4] &;
S = ToExpression;
T = StringSplit;
{a, b, c} = T[i, "*"];
{d, m, y} = S@T[c, "/"];
{{e}} = Position[DayOfWeek[{y, m, #}] & /@ Table[i, {i, 7}], Monday];
{o, p, q} = DateDifference[Join[{y}, #], {y, m, d}] & /@ {{1, e}, {7, 21}, {2, 29}};
{"NW", "SE", "SW", "NE"}[[1 + If[p == 0 || q == 0, 0, Mod[2*Mod[S@b - 1, 2] + Mod[S@a - 1, 4] + o, 4]]]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.