7
1
Background
Inspired by a now deleted question by John Burger from which I quote:
Now obviously no human made this mistake. It's a mis-decode of something - perhaps the ISBN? My question is: does anyone know of an existing algorithm that was so messed up it would invent an entirely new calendar?
It seems that the book was published on
2008-09-16
, so maybe it was somehow read as00809162
->00=dec?
,80
,9162
Task
Given a date represented as a three-element list, answer with the corresponding three-element mis-decoded list.
Mis-decoding happens as follows (example for [2008,9,16]
in parentheses):
Join the digits of the year, month, and day, inserting leading zeros as necessary (
"20080916"
)Move the first digit to the end (
"00809162"
)Split the eight digits into groups of two, two, and four (
"00","80","9162"
)Interpret them as numbers (
[0,80,9162]
)Normalise the month number by wrapping 0 around to 12, and wrapping 13 around to 1, 14 to 2, 15 to 3, …, 25 to 1 etc. (
[12,80,9162]
)Rearrange the list to get the original order (
[9162,12,80]
)You may take the original date in any order, but your answer must use the same order. Please state any non-default order.
The given year will always have four digits, but dates in October will lead to a three- or two-digit answer year.
You may take a list of strings or a character-delimited string, but it may not include leading zeros and you must answer in the same format and again without leading zeros.
Examples
[1700,1,1]
→ [1011,10,0]
[1920,4,29]
→ [4291,8,0]
[1966,11,27]
→ [1271,12,61]
[1996,12,13]
→ [2131,3,61]
[2008,9,1]
→ [9012,12,80]
[2008,9,16]
→ [9162,12,80]
[1010,10,1]
→ [11,1,1]
Can we take the input as a list of strings? – Windmill Cookies – 2019-01-07T16:42:18.380
@WindmillCookies Yes, but then they may not include leading zeros, and you must answer with a list of strings (without leading zeros) too. – Adám – 2019-01-07T16:45:12.077
Is it okay if the program prints the numbers separated by spaces to stdout? – fəˈnɛtɪk – 2019-01-07T16:55:14.143
@fəˈnɛtɪk What does your input/argument look like? – Adám – 2019-01-07T17:17:05.710
The input argument is in 3 integers from stdin. I am trying to do it using Cardinal. – fəˈnɛtɪk – 2019-01-07T18:15:47.757
@fəˈnɛtɪk Are they space or newline separated in stdin? – Adám – 2019-01-07T18:23:52.450
Newline separated – fəˈnɛtɪk – 2019-01-07T18:27:47.863
@fəˈnɛtɪk (sorry for slow responses) The printing on three lines is good. Space separated, not so much. – Adám – 2019-01-07T19:42:21.823
Is the output year guaranteed to have 4 digits (no leading zero)? – Neil A. – 2019-01-07T20:27:26.337
@NeilA. It follows from the spec that dates in October have a three-digit result year, no? – Adám – 2019-01-07T23:05:55.957
1@Adám Ah, I wasn't sure if when you said "The year will always have four digits." you were referring to input, output, or both – Neil A. – 2019-01-07T23:23:35.560
The clear reason for the date of publishing is that it was published in the 92nd century when they fixed all the months to have 100 days each and sent back with a time machine due to how good the book was. – fəˈnɛtɪk – 2019-01-07T23:53:15.480