Skip to main content
deleted 197 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Retina, 7171 70 bytes

Thanks to Sp3000 for saving 1 byte.

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

(..)(..)$
$2$*¶$1
^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXDECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
+`...¶

R-6`.

Try it online!Try it online!

Explanation

Taking 201604 as an example:

(..)(..)$
$2$*¶$1DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, and prepending the list of months in reverse so we'd get:

20¶¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16

Where the represent linefeeds (0x0A).

^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX

This prepends the list of all months in reverse, as well as an X (which could be anything, really):

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
+`...¶

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶1620DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
DECNOVOCTSEPAUGJULJUNMAYAPR1620DECNOVOCTSEPAUGJULJUNMAYAPR16

This is why we've inserted that XXXX: since the months start counting from 1, we'll always remove at least three characters, even for January. Two of those characters are provided by the left over part from the year, but we need to insert that X to get to three.

R-6`.

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.

Retina, 71 bytes

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

(..)(..)$
$2$*¶$1
^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX
+`...¶

R-6`.

Try it online!

Explanation

Taking 201604 as an example:

(..)(..)$
$2$*¶$1

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, so we'd get:

20¶¶¶¶16

Where the represent linefeeds (0x0A).

^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX

This prepends the list of all months in reverse, as well as an X (which could be anything, really):

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
+`...¶

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
DECNOVOCTSEPAUGJULJUNMAYAPR16

This is why we've inserted that X: since the months start counting from 1, we'll always remove at least three characters, even for January. Two of those characters are provided by the left over part from the year, but we need to insert that X to get to three.

R-6`.

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.

Retina, 71 70 bytes

Thanks to Sp3000 for saving 1 byte.

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
+`...¶

R-6`.

Try it online!

Explanation

Taking 201604 as an example:

(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, and prepending the list of months in reverse so we'd get:

20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16

Where the represent linefeeds (0x0A).

+`...¶

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
20DECNOVOCTSEPAUGJULJUNMAYAPR16

This is why we've inserted that XXX: since the months start counting from 1, we'll always remove at least three characters, even for January.

R-6`.

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.

Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Retina, 71 bytes

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

(..)(..)$
$2$*¶$1
^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX
+`...¶

R-6`.

Try it online!

Explanation

Taking 201604 as an example:

(..)(..)$
$2$*¶$1

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, so we'd get:

20¶¶¶¶16

Where the represent linefeeds (0x0A).

^
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX

This prepends the list of all months in reverse, as well as an X (which could be anything, really):

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
+`...¶

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANX20¶¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
DECNOVOCTSEPAUGJULJUNMAYAPR16

This is why we've inserted that X: since the months start counting from 1, we'll always remove at least three characters, even for January. Two of those characters are provided by the left over part from the year, but we need to insert that X to get to three.

R-6`.

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.