34
\$\begingroup\$

My dog ate my calendar, and now my days are all mixed up. I tried putting it back together, but I keep mixing up the days of the week! I need some help putting my calendar back together, with the days in the correct order.

And since I need my calendar put together as fast as possible, don't waste my time by sending me superfluous bytes. The fewer bytes I have to read, the better!

Input

The days of the week, in any order. Input can be taken as a list of strings, or a space separated string, or any reasonable way of representing 7 strings (one for each day of the week).

The strings themselves are all capitalized, as weekdays should be, so the exact strings are:

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

Output

The days of the week, in sorted order (Monday - Sunday, because of course we adhere to ISO 8601). Output can be as a list of strings, or printed with some delimiter.

Disclaimer

Note that this is a challenge, with the added benefit of being able to use the input to shorten your code. You are not required to use the input if you don't want to. You are also free to use any approach, from a builtin datetime library to hard-coding the output.

Examples

To see example input and output, you can consult this python script.

\$\endgroup\$
6
  • 8
    \$\begingroup\$ I hope you've learnt your lesson from this: never leave dogs with calendars. \$\endgroup\$
    – lyxal
    Commented Apr 28, 2020 at 6:50
  • \$\begingroup\$ any delimiter allowed? \$\endgroup\$
    – Helena
    Commented Apr 28, 2020 at 18:00
  • \$\begingroup\$ @Helena I'd say any delimiter within reason. I'd prefer space, comma, or newline, but if the language you're using has another default separator, or you'll be able to knock off a few bytes, go for it. Though I will specify that it has to be the same separator between all output words. \$\endgroup\$
    – maxb
    Commented Apr 29, 2020 at 6:08
  • 2
    \$\begingroup\$ I hope you have learnt your lesson from this: it is a dog-eat-calendar world. \$\endgroup\$ Commented Apr 29, 2020 at 20:16
  • 1
    \$\begingroup\$ @ASCII-only The program should work for any of the \$7!\$ different ways to order the days of the week. I used a random shuffle in my example code just to show that the output order is independent of the input order. \$\endgroup\$
    – maxb
    Commented May 8, 2020 at 17:09

37 Answers 37

1
2
2
\$\begingroup\$

Japt, 8 bytes

n á g#4

Try it here

\$\endgroup\$
2
\$\begingroup\$

Python 3, 64 62 59 chars

Takes input as a list of strings, sorts it inplace:

lambda l:l.sort(key=lambda x:'uehrau'.find(x[1],x[0]=='S'))

Try it: https://ideone.com/rYxtff

\$\endgroup\$
2
\$\begingroup\$

R (English locale), 36 bytes

weekdays(.leap.seconds[c(8:12,6:7)])

Not quite as short as the other answer, but I posted it because it makes use of one of the strangest objects kicking around in base R — a list of all the leap seconds. It so happens that leap seconds frequently occur in increasing sequences of days so we only have to take two "chunks" from the list.

Luckily, the leap seconds object has the oldest leap second first, so I don't have to qualify this program with "will only work for the next 2–3 years"!

TIO link here.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This is certainly one of the most interesting approaches. I've never coded in R, but you could add a TIO link, something like this. \$\endgroup\$
    – maxb
    Commented Apr 29, 2020 at 13:47
  • 1
    \$\begingroup\$ Thanks — I used your link to edit my answer — hope that's alright! \$\endgroup\$
    – JDL
    Commented Apr 29, 2020 at 14:16
  • \$\begingroup\$ Well I used your code in my link, so I guess we're even. \$\endgroup\$
    – maxb
    Commented Apr 29, 2020 at 14:40
2
\$\begingroup\$

Uiua, 6 bytes

↻1Days

Boring builtin answer (Days starts with "Sunday", so it needs to be ↻ rotated). You can append ◌ pop for +1 byte if taking input is required.

(Slightly) more interesting 13-byte answer:

⊏∵⋕"1564023"⍆

Selects the correct indices from the sorted input using an array of digits.

Try all three!

\$\endgroup\$
1
\$\begingroup\$

Python

Input: Space separated strings

Once the input is sorted then the output should be ordered using indices [1, 5, 6, 4, 0, 2, 3] of the sorted array

inp=sorted(input().split())
for i in [1, 5, 6, 4, 0, 2, 3]:
  print(inp[i])

Try it here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What language is this? \$\endgroup\$
    – Wheat Wizard
    Commented Apr 29, 2020 at 14:55
  • 2
    \$\begingroup\$ Welcome to Code Golf! While it is a good answer, I'll suggest some general code golf optimizations: make all variables 1 byte, and remove all unnecessary whitespace. With those optimizations, your code becomes 14 bytes shorter. \$\endgroup\$
    – maxb
    Commented Apr 30, 2020 at 6:13
1
\$\begingroup\$

Deadfish~, 464 bytes

{{i}dd}dddc{i}{i}{i}iiiicdc{d}cdddc{i}{i}iiiic{{d}}{d}dc{{i}ddd}iiiic{i}{i}{i}iiic{d}ddddddc{i}iiiic{d}dddddcdddc{i}{i}iiiic{{d}}{d}dc{{i}dd}dddc{i}iiiicdc{i}c{d}ic{i}iiiic{d}dddddcdddc{i}{i}iiiic{{d}}{d}dc{{i}ddd}iiiic{i}{i}c{i}iiicdddcic{d}dddddcdddc{i}{i}iiiic{{d}}{d}dc{{i}dddd}c{{i}dddddd}iiiic{d}icdddddcdddc{i}{i}iiiic{{d}}{d}dc{{i}ddd}iiic{i}iiiic{i}{i}dcicdddc{d}ddddcdddc{i}{i}iiiic{{d}}{d}dc{{i}ddd}iiic{i}{i}{i}iiiic{d}iiic{d}cdddc{i}{i}iiiic{{d}}{d}dc

Try it online!

Deadfish - the worst compression algorithm.

\$\endgroup\$
0
\$\begingroup\$

AWK, 63 bytes

$0=gensub(/X/,"day ","g","MonXTueXWednesXThursXFriXSaturXSunX")

Attempt This Online!

\$\endgroup\$
1
2

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.