49
5
In his xkcd about the ISO 8601 standard date format Randall snuck in a rather curious alternative notation:
The large numbers are all the digits that appear in the current date in their usual order, and the small numbers are 1-based indices of the occurrences of that digit. So the above example represents 2013-02-27
.
Let's define an ASCII representation for such a date. The first line contains the indices 1 to 4. The second line contains the "large" digits. The third line contains the indices 5 to 8. If there are multiple indices in a single slot, they are listed next to each other from smallest to largest. If there are at most m
indices in a single slot (i.e. on the same digit, and in the same row), then each column should have be m+1
characters wide and left-aligned:
2 3 1 4
0 1 2 3 7
5 67 8
See also the companion challenge for the opposite conversion.
The Challenge
Given a date in xkcd-notation, output the corresponding ISO 8601 date (YYYY-MM-DD
).
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
You may assume that the input is any valid date between years 0000
and 9999
, inclusive.
There won't be any leading spaces in the input, but you may assume that the lines are padded with spaces to a rectangle, which contains at most one trailing column of spaces.
Standard code-golf rules apply.
Test Cases
2 3 1 4
0 1 2 3 7
5 67 8
2013-02-27
2 3 1 4
0 1 2 4 5
5 67 8
2015-12-24
1234
1 2
5678
2222-11-11
1 3 24
0 1 2 7 8
57 6 8
1878-02-08
2 4 1 3
0 1 2 6
5 678
2061-02-22
1 4 2 3
0 1 2 3 4 5 6 8
6 5 7 8
3564-10-28
1234
1
5678
1111-11-11
1 2 3 4
0 1 2 3
8 5 6 7
0123-12-30
11People who write the date in the "black cat" format are the bane of my existence. – Carcigenicate – 2015-12-19T20:02:17.203
1Forgive my ignorance, but how exactly does the weird format correspond with the date? Can't for the life of me work out the pattern. – Tom Carpenter – 2015-12-20T20:37:53.293
2@TomCarpenter The bottom and top line indicate where the numbers in the middle line appear in the date. E.g.
1
is above2
, so the first digit is2
.2
is above0
, so the second digit is0
.3
is above1
,4
is above3
, so we get2013
as the first four digits. Now5
is below0
, so the fifth digit is0
,6
and7
are both below2
, so both of those digits are2
. And finally,8
is below7
, so the last digit is8
, and we end up with2013-02-27
. (The hyphens are implicit in xkcd notation because we know at what positions they appear.) – Martin Ender – 2015-12-20T20:40:16.443