The goal is to output the number of the months given as input in a compact concatenated form which is still parsable if one knows the construction rules:
If either:
- January is followed by January, February, November or December; or
- November is followed by January or February
There must be a separator placed between.
Otherwise there should be no separator.
As such the output may be parsed. For example:
- March, April and September ->
349
- January, January and February ->
1-1-2
- January, January and December ->
1-1-12
- January, November and February ->
1-11-2
- November, January and February ->
11-1-2
- November and December ->
1112
Thus any run of ones is either a run of Novembers, a run of Novembers followed by a December, a run of Novembers followed by an October, or a January followed by an October. This may be parsed by looking to the right of such runs as the resulting string is read from left to right.
Input
A list of months numbers ([1-12]
) in any format you want (list, JSON, separated by one or more characters, entered one by one by user, …).
the same month can be present more than once.
Output
The compact concatenated form described above. If a separator is needed, you can freely choose one.
Output examples for January, February and March (1-2-3):
1-23
(chosen for the test cases below)1 23
1/23
1,23
- ...
Test cases
[1] => 1
[1, 2] => 1-2
[2, 1] => 21
[12] => 12
[1, 11] => 1-11
[11, 1] => 11-1
[1, 1, 1] => 1-1-1
[2, 11] => 211
[11, 2] => 11-2
[1, 2, 3] => 1-23
[11, 11] => 1111
[1,1,11,1,12,1,11,11,12] => 1-1-11-1-121-111112
[10,11,12,11,11,10,1,10,1,1] => 1011121111101101-1
[2,12,12,2,1,12,12,1,1,2,12,12,2,11,2,12,1] => 2121221-12121-1-21212211-2121
Rules
- As usual, this is code-golf, shortest answer in bytes wins.
- Standard loopholes are forbidden.
1111
is extra-ambiguous. Do you mean1-1-1-1
,1-1-11
,1-11-1
,11-1-1
or11-11
? \$\endgroup\$1
's, it's hard to know at first, so1111
should be11-11
if you mean Nov-Nov. That has been shown in the test case11-2
(not112
) and added as an extra test case. \$\endgroup\$