Text animation format Code Golf
Python 3, 57 bytes
lambda s:eval(s.upper().translate({70:'+[',87:']*'})[1:])
Turns a string like
f1w0f2w10
into a expression like
[1]*0+[2]*10
that it evaluated as code. This is done by turning the string uppercase, turning each f
into +[
and each w
into ]*
, and removing the initial +
. Thanks to Dennis for saving 7 bytes in Python 3 by using translate with a dictionary.
V, 25 bytes
Óá¨ä«©á¨ä«©/²a±,
D@"hD
Try it online!
Here is a hexdump of the answer, which is encoded in latin1:
0000000: d3e1 a8e4 aba9 e1a8 e4ab a92f b261 b12c .........../.a.,
0000010: 2016 1b0a 4440 2268 44 ...D@"hD
Explanation:
<C-v>
is byte 0x16
and <esc>
is byte 0x1B
. Since they are both unprintable, I am using this notation to refer to them.
Óá¨ä«©á¨ä«©/²a±, <C-v><esc>
This is a compressed regex, that basically transforms the input into V code. Here's what the buffer looks like after running this regex:
3a10, <esc>3a11, <esc>3a10, <esc>3a12, <esc>
Here's how that works:
3 "3 times:
a <esc> "Append the following text:
10, " '10, '
Running this in V (or its parent, vim) would create:
10, 10, 10,
And then a similar command repeats for each element of the input.
So, after running this regex, we've got valid V code that will create the desired output. Thankfully, V can easily self-interpret, as long as the code is in a buffer. So, we run the following:
D "Delete this line into the unnamed register
@" "Run the text in the unnamed register as V code
This is exactly what we want, but now the output has a trailing ,
. So:
h "Move one character to the left. Now we are on the second to last character
D "Delete until the end of the current line
Pyth, 18 bytes
r_McvM:z"\d+"1 2 9
Try it online. Test suite.