Decrypt the extended Wechsler format
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
14
down vote
favorite
This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge.
apgsearch, the distributed soup search program for Conway's Game of Life and the search results database, Catagolue use apgcodes to classify and denote patterns. apgcodes themselves use the extended Wechsler format, an extension of a pattern notation developed by Allan Wechsler in 1992.
The following examples and the images are taken from LifeWiki.
A string of n characters in the set matching the regex
[0-9a-v]
denotes a strip of five rows, n columns wide. Each character denotes five cells in a vertical column corresponding to the bitstrings [00000
,10000
,01000
...00010
,10010
,01010
,11010
...11111
].For instance,
27deee6
corresponds to a heavyweight spaceship:
$$ beginbmatrix
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & 1 & colorGray0 & 1 & 1 & 1 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & 1 \
colorGray0 & colorGray0 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The character
z
separates contiguous five-row strips.For example,
0ca178b96z69d1d96
corresponds to a 31-bit still life:
$$ beginbmatrix
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & 1 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 \
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The characters
w
andx
are used to abbreviate00
and000
, respectively.So
w33z8kqrqk8zzzx33
corresponds to a trans-queen bee shuttle:
(10 blank rows omitted)
$$ beginbmatrix
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 \
1 & colorGray0 & 1 & 1 & 1 & colorGray0 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
Finally, the symbols matching the regex
y[0-9a-z]
correspond to runs of between 4 and 39 consecutive0
s.A good example is
31a08zy0123cko
, corresponding to a ship on quadpole:
$$ beginbmatrix
1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1
endbmatrix $$
The Challenge
Write a program or a function to parse a string of the extended Wechsler format, defined above, and print (or return) the pattern corresponding to this string.
You may assume that the string is nonempty, and does not start or end with z
.
You may use any reasonable output format, e.g., a string, a matrix, a 2d array. You may use any two values to represent 0
and 1
, given that you declare them in the answer.
You may omit the trailing zeroes lines in the output, or add extra trailing zeroes lines. You may also add/omit trailing zeroes on each line, as long as all lines have the same length in the output.
You may return the transpose of the array, if that is more convenient.
This is code-golf, so the shortest code wins.
Test cases
153 => [[1, 1, 1], [0, 0, 1], [0, 1, 0], [0, 0, 0], [0, 0, 0]]
27deee6 => [[0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]
0ca178b96z69d1d96 => [[0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 1, 0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0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
code-golf parsing game-of-life
 |Â
show 1 more comment
up vote
14
down vote
favorite
This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge.
apgsearch, the distributed soup search program for Conway's Game of Life and the search results database, Catagolue use apgcodes to classify and denote patterns. apgcodes themselves use the extended Wechsler format, an extension of a pattern notation developed by Allan Wechsler in 1992.
The following examples and the images are taken from LifeWiki.
A string of n characters in the set matching the regex
[0-9a-v]
denotes a strip of five rows, n columns wide. Each character denotes five cells in a vertical column corresponding to the bitstrings [00000
,10000
,01000
...00010
,10010
,01010
,11010
...11111
].For instance,
27deee6
corresponds to a heavyweight spaceship:
$$ beginbmatrix
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & 1 & colorGray0 & 1 & 1 & 1 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & 1 \
colorGray0 & colorGray0 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The character
z
separates contiguous five-row strips.For example,
0ca178b96z69d1d96
corresponds to a 31-bit still life:
$$ beginbmatrix
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & 1 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 \
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The characters
w
andx
are used to abbreviate00
and000
, respectively.So
w33z8kqrqk8zzzx33
corresponds to a trans-queen bee shuttle:
(10 blank rows omitted)
$$ beginbmatrix
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 \
1 & colorGray0 & 1 & 1 & 1 & colorGray0 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
Finally, the symbols matching the regex
y[0-9a-z]
correspond to runs of between 4 and 39 consecutive0
s.A good example is
31a08zy0123cko
, corresponding to a ship on quadpole:
$$ beginbmatrix
1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1
endbmatrix $$
The Challenge
Write a program or a function to parse a string of the extended Wechsler format, defined above, and print (or return) the pattern corresponding to this string.
You may assume that the string is nonempty, and does not start or end with z
.
You may use any reasonable output format, e.g., a string, a matrix, a 2d array. You may use any two values to represent 0
and 1
, given that you declare them in the answer.
You may omit the trailing zeroes lines in the output, or add extra trailing zeroes lines. You may also add/omit trailing zeroes on each line, as long as all lines have the same length in the output.
You may return the transpose of the array, if that is more convenient.
This is code-golf, so the shortest code wins.
Test cases
153 => [[1, 1, 1], [0, 0, 1], [0, 1, 0], [0, 0, 0], [0, 0, 0]]
27deee6 => [[0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]
0ca178b96z69d1d96 => [[0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
w33z8kqrqk8zzzx33 => [[0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0,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page does not say anything about that. But you can assume here that the string does not start or end withz
.
â alephalpha
yesterday
3
Not really a Game of Life pattern, but just for fun:vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
1
Two of the first three answers fail for some of these:1yx1
,1yy1
,1yw1
and1yz1
. Maybe they should be tests.
â Jonathan Allan
19 hours ago
 |Â
show 1 more comment
up vote
14
down vote
favorite
up vote
14
down vote
favorite
This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge.
apgsearch, the distributed soup search program for Conway's Game of Life and the search results database, Catagolue use apgcodes to classify and denote patterns. apgcodes themselves use the extended Wechsler format, an extension of a pattern notation developed by Allan Wechsler in 1992.
The following examples and the images are taken from LifeWiki.
A string of n characters in the set matching the regex
[0-9a-v]
denotes a strip of five rows, n columns wide. Each character denotes five cells in a vertical column corresponding to the bitstrings [00000
,10000
,01000
...00010
,10010
,01010
,11010
...11111
].For instance,
27deee6
corresponds to a heavyweight spaceship:
$$ beginbmatrix
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & 1 & colorGray0 & 1 & 1 & 1 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & 1 \
colorGray0 & colorGray0 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The character
z
separates contiguous five-row strips.For example,
0ca178b96z69d1d96
corresponds to a 31-bit still life:
$$ beginbmatrix
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & 1 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 \
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The characters
w
andx
are used to abbreviate00
and000
, respectively.So
w33z8kqrqk8zzzx33
corresponds to a trans-queen bee shuttle:
(10 blank rows omitted)
$$ beginbmatrix
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 \
1 & colorGray0 & 1 & 1 & 1 & colorGray0 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
Finally, the symbols matching the regex
y[0-9a-z]
correspond to runs of between 4 and 39 consecutive0
s.A good example is
31a08zy0123cko
, corresponding to a ship on quadpole:
$$ beginbmatrix
1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1
endbmatrix $$
The Challenge
Write a program or a function to parse a string of the extended Wechsler format, defined above, and print (or return) the pattern corresponding to this string.
You may assume that the string is nonempty, and does not start or end with z
.
You may use any reasonable output format, e.g., a string, a matrix, a 2d array. You may use any two values to represent 0
and 1
, given that you declare them in the answer.
You may omit the trailing zeroes lines in the output, or add extra trailing zeroes lines. You may also add/omit trailing zeroes on each line, as long as all lines have the same length in the output.
You may return the transpose of the array, if that is more convenient.
This is code-golf, so the shortest code wins.
Test cases
153 => [[1, 1, 1], [0, 0, 1], [0, 1, 0], [0, 0, 0], [0, 0, 0]]
27deee6 => [[0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]
0ca178b96z69d1d96 => [[0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
w33z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golf parsing game-of-life
This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge.
apgsearch, the distributed soup search program for Conway's Game of Life and the search results database, Catagolue use apgcodes to classify and denote patterns. apgcodes themselves use the extended Wechsler format, an extension of a pattern notation developed by Allan Wechsler in 1992.
The following examples and the images are taken from LifeWiki.
A string of n characters in the set matching the regex
[0-9a-v]
denotes a strip of five rows, n columns wide. Each character denotes five cells in a vertical column corresponding to the bitstrings [00000
,10000
,01000
...00010
,10010
,01010
,11010
...11111
].For instance,
27deee6
corresponds to a heavyweight spaceship:
$$ beginbmatrix
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & 1 & colorGray0 & 1 & 1 & 1 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & 1 \
colorGray0 & colorGray0 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The character
z
separates contiguous five-row strips.For example,
0ca178b96z69d1d96
corresponds to a 31-bit still life:
$$ beginbmatrix
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & 1 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 \
colorGray0 & 1 & 1 & colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & 1 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
The characters
w
andx
are used to abbreviate00
and000
, respectively.So
w33z8kqrqk8zzzx33
corresponds to a trans-queen bee shuttle:
(10 blank rows omitted)
$$ beginbmatrix
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 \
1 & colorGray0 & 1 & 1 & 1 & colorGray0 & 1 \
colorGray0 & 1 & 1 & 1 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0
endbmatrix $$
Finally, the symbols matching the regex
y[0-9a-z]
correspond to runs of between 4 and 39 consecutive0
s.A good example is
31a08zy0123cko
, corresponding to a ship on quadpole:
$$ beginbmatrix
1 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 & colorGray0 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1 & colorGray0 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & colorGray0 & 1 \
colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & colorGray0 & 1 & 1
endbmatrix $$
The Challenge
Write a program or a function to parse a string of the extended Wechsler format, defined above, and print (or return) the pattern corresponding to this string.
You may assume that the string is nonempty, and does not start or end with z
.
You may use any reasonable output format, e.g., a string, a matrix, a 2d array. You may use any two values to represent 0
and 1
, given that you declare them in the answer.
You may omit the trailing zeroes lines in the output, or add extra trailing zeroes lines. You may also add/omit trailing zeroes on each line, as long as all lines have the same length in the output.
You may return the transpose of the array, if that is more convenient.
This is code-golf, so the shortest code wins.
Test cases
153 => [[1, 1, 1], [0, 0, 1], [0, 1, 0], [0, 0, 0], [0, 0, 0]]
27deee6 => [[0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]
0ca178b96z69d1d96 => [[0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
w33z8kqrqk8zzzx33 => [[0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 1, 1, 1, 0, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
31a08zy0123cko => [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]]
o5995ozes88sezw33 => [[0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1], [1, 1, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
y3343x6bacy6cab6x343zkk8yy8kkzgo8gywg8ogz0123yw321zzgo4syws4ogzgh1yy1hgz221yy122zy3c2cx6d53y635d6xc2c => [[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
code-golf parsing game-of-life
edited yesterday
asked yesterday
alephalpha
20.4k32685
20.4k32685
Willz
ever occur at the very beginning?
â Mr. Xcoder
yesterday
@Mr.Xcoder The LifeWiki page does not say anything about that. But you can assume here that the string does not start or end withz
.
â alephalpha
yesterday
3
Not really a Game of Life pattern, but just for fun:vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
1
Two of the first three answers fail for some of these:1yx1
,1yy1
,1yw1
and1yz1
. Maybe they should be tests.
â Jonathan Allan
19 hours ago
 |Â
show 1 more comment
Willz
ever occur at the very beginning?
â Mr. Xcoder
yesterday
@Mr.Xcoder The LifeWiki page does not say anything about that. But you can assume here that the string does not start or end withz
.
â alephalpha
yesterday
3
Not really a Game of Life pattern, but just for fun:vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
1
Two of the first three answers fail for some of these:1yx1
,1yy1
,1yw1
and1yz1
. Maybe they should be tests.
â Jonathan Allan
19 hours ago
Will
z
ever occur at the very beginning?â Mr. Xcoder
yesterday
Will
z
ever occur at the very beginning?â Mr. Xcoder
yesterday
@Mr.Xcoder The LifeWiki page does not say anything about that. But you can assume here that the string does not start or end with
z
.â alephalpha
yesterday
@Mr.Xcoder The LifeWiki page does not say anything about that. But you can assume here that the string does not start or end with
z
.â alephalpha
yesterday
3
3
Not really a Game of Life pattern, but just for fun:
vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
Not really a Game of Life pattern, but just for fun:
vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
1
1
Two of the first three answers fail for some of these:
1yx1
, 1yy1
, 1yw1
and 1yz1
. Maybe they should be tests.â Jonathan Allan
19 hours ago
Two of the first three answers fail for some of these:
1yx1
, 1yy1
, 1yw1
and 1yz1
. Maybe they should be tests.â Jonathan Allan
19 hours ago
 |Â
show 1 more comment
6 Answers
6
active
oldest
votes
up vote
6
down vote
JavaScript (ES8), 197 bytes
Takes input as a string. Returns an array of strings with '#' and spaces. The output may include extra (but consistent) trailing spaces on each line.
s=>[x='x',...s.replace(/w|x|y./g,s=>''.padEnd(s<x?2:s>x?P(s[1],36)+4:3),P=parseInt)].map(c=>[!++w,1,2,3,4].map(i=>c<x?o[y+i-5]+=' #'[P(c,36)>>i&1]:o=[...++y&&o,'']),w=y=o=)&&o.map(r=>r.padEnd(w))
Try it online! (prettified output)
How?
Global variables
- The character
"x"
is used several times, so it's worth storing it into the variable x. - The function
parseInt
is used twice, so it's worth storing it into the variable P.
y is the row index, initialized to 0.
w keeps track of an upper bound of the width which is used to pad the final output.
o[Â ] is the output array, initially empty.
Pre-processing of repeated zeros
We first replace all patterns "w"
, "x"
and "yX"
in the input string with the appropriate number of spaces. These spaces will later be interpreted as "0"
.
s.replace(
/w|x|y./g,
s => ''.padEnd(
// w --> 2
s < x ? 2 :
// yX --> value of X + 4
s > x ? P(s[1], 36) + 4 :
// x --> 3
3
)
)
Decoding
We split the resulting string, prepend an initial "x"
and iterate 5 times (with i = 0 to 4) on each character c:
If c is lower than
"x"
, we append the corresponding pattern to the next 5 rows.o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
If c is greater than or equal to
"x"
, we allocate 5 new empty strings in o[Â ] and add 5 to y. This is triggered by the initial"x"
that was added at the beginning of the string, or by any"z"
in the original content.o = [...++y && o, '']
Padding
Finally, we pad each string in o[Â ] with spaces so that they all have w characters.
o.map(r => r.padEnd(w))
add a comment |Â
up vote
5
down vote
05AB1E, 148 132 bytes
I'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
"yy"þ38ÃÂ:'yð:Ã
¾hAëDUsðë#õN>â iDýXsk4+sæs0sÃÂì}}'wþ2ÃÂ:'xþ3ÃÂ:J'zð:ðë#DéøgUõDgXs-0sÃÂë}vNUyvNâÂÂ+âÂÂ*X+VDykD32â¹ibDg5s-0sÃÂìRX0Qiöì}YðëìÃÂ]ïõ#øJ
Try it online!
Try it online!
Outputs the transposed matrix as multiple output lines of 1s and 0s. If you want pretty-printed output, add J'1'âÂÂ:'0'.:
at the end.
Will add extra zeros.
Explanation
(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)
The basic algorithm is:
- Replace "yy" with 38 0s
- Split on "y" and and expand the 0-runs.
- Replace "w" and "x"
- Figure out the longest column (that is, the longest string between z's) and pad all the other columns so they are that length. (This is necessary because of how the algorithm below works)
- Split on z
- At this point, the input string is an array of columns where each column is a string of [0-9a-v], where each column is the same length.
- The algorithm to get it into the output format is to
- Convert the characters to numbers by using indexOf in a lookup string
- Convert the characters to binary and then pad to length 5
- If it is the first column, add a linebreak before the binary number
- Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
- Push the binary string with prefix to 05AB1E's "global array" register/variable
- Sort the global array. The prefix string, which determines the sort order, will make sure everything ends up in the right order and the linebreaks are in the right places.
- Remove the prefix string from each element of the global array
- Join the array with "" and print it.
There are some other minor details you can see below in the expanded code. Everything after the tabs at the end of a line is a comment and can be ignored. (This comment scheme is not part of 05AB1E, by the way. I did it this way because it looked nice.) Lines that have comments starting with "@" are for debugging purposes and can be omitted without changing the final output.
"yy"þ38ÃÂ: Replace "yy" with 38 0's. (y is the 34th character in the index, so need to add 34+4 = 38). þ is initialized to zero, which saves one byte from typing '038
'yð: Replace "y" with " "
"Replaced input Stage1 = "?D, @DEBUG
Ã
¾hAë Pushes [0-9a-z]
DU Set X to [0-9a-z] and leave [0-9a-z] on the stack.
s Swap top two elements. Now the stack is [0-9a-z],input
ðë Append a space so the below splitter works even if there are no other spaces.
# Split input on " ", which "y" has been replaced with
õ Map. This map replaces the y runs
"Element = "?D, @DEBUG
"N = "?N, @DEBUG
N>â i If N != 0
"Replacing!", @DEBUG
Dý Get the first letter
X Push X
s Swap
k X (which is [0-9a-z]) .indexOf(firstLetter)
"indexOf run token = "?D, @DEBUG
4+ Add 4 to the index, now becoming the number of zeros to add
s Swap. Now top is the string between runs
æ Remove the first character
s Swap again. Now the top is the number of zeros to add.
0sÃÂì Add that many zeros to the start of the element.
"Element Replaced = "?D, @DEBUG
}
}
'wþ2ÃÂ: Need to do this replacement after the y replacement so stuff like yw gets parsed properly. Again, þ is zero.
'xþ3ÃÂ:
J Join with ""
"Replaced input Stage2 = "?D, @DEBUG
'zð: Replace "z" with " "
ðë Append a space so the below splitter works even if there are no other spaces.
# Split on space. (Can't do split on z because it splits on z+)
DéøgU Get max length and store it in X
"Max length = "?X, @DEBUG
õ Map
DgXs- max column length - this column length
"Zeros to add = "?D, @DEBUG
0sÃÂë Add 0s to the end of the column so it is the same length as the longest one.
}
"Replaced input Stage3 = "?D, @DEBUG
"0 Stack top = "?D, @SDEBUG
"0 Stack top-1 = "?sD,s @SDEBUG
v pop and loop over top element, which is array of column code
NU Store the column number in X
yv Loop over each character in the column
NâÂÂ+âÂÂ*X+V Set Y to (rowNumber+1000)*1000+X, where X is the column number. This result is used for sorting.
"1 Stack top = "?D, @SDEBUG
"1 Stack top = "?D, @SDEBUG
D Duplicate top element (which is now [0-9a-z])
y Push y (special loop variable)
"Character = "?D, @DEBUG
k Push indexOf y in [0-9a-z]
"Index = "?D, @DEBUG
"2.1 Stack top = "?D, @SDEBUG
"2.1 Stack top-1 = "?sD,s @SDEBUG
D Duplicate index.
32â¹i index < 32. This uses up one copy of index
b Push the index in binary. This uses the second copy of index.
Dg Get the length of the binary number
5s- 5 - length
0sÃÂì Add 5-length 0s to the start of the binary number
"Binary = "?D, @SDEBUG
R Reverse the binary string. This gives the proper transposed output.
X0Qi If X (which is set to the column number) == 0
öì Stick a linebreak at the beginning of the binary string
}
Y Push Y (the sort prefix).
ð Push a space character
ëì This gives "<row prefix> <binary representation of row>"
"2.5 Stack top = "?D, @SDEBUG
"2.5 Stack top-1 = "?sD,s @SDEBUG
"Pushing '"?D?"'", @DEBUG
ÃÂ Push "<row prefix>|<binary representation of row>" to global array
"2.6 Stack top = "?D, @SDEBUG
"2.6 Stack top-1 = "?sD,s @SDEBUG
] Close all blocks
ï Push global array to stack and sort it.
"Sorted Data = "?D, @DEBUG
õ Map. This block removes the row numbers
# Split on spaces
ø Get the last element
J Join with ""
'1'âÂÂ:'0'.: @DEBUG pretty print
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last,
.
â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:"yy"
can beâÂÂyy
(05AB1E has both a 2-char and 3-char string builtin).>âÂÂ
can beÃÂ
(truthified, basically0
remains0
and everything else becomes1
).}}
can be]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.
â Kevin Cruijssen
2 hours ago
 |Â
show 1 more comment
up vote
3
down vote
APL (Dyalog Unicode), 87 80 bytes
thangs to H.PWiz for saving 7 bytes
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµè'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
Try it online!
NB: Takes the input as an upper case string.
With pretty printed output
Explanation
aâÂÂâÂÂD,âÂÂA
a is the string '0123...89ABCD...XYZ'
('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)
replaces X W and Yx with the corresponding number of '0'
s'Z'(â âÂÂâ¢)
splits the string at each 'Z'
âÂÂ(5/2)â¤aâ³âµè
decodes each substring (explained below),âÂÂâÂÂ
reshapes and pads the result, returning a nested boolean array
âÂÂ(5/2)â¤aâ³âµè
è â apply to each substring
aâ³âµ â return indecies of each charactor in a (i.e. '0'=>0, '9'=>9, 'B'=>11
(5/2)⤠â turn each of these into a 5-bit binary column
â â reverse each column
Here is a 7 byte saving:aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfy
â H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
add a comment |Â
up vote
2
down vote
Perl 6, 156 142 bytes
14 bytes saved thanks to Jo King. (Also fixed a little bug with parsing the y
and added a prettifier.)
Fixed the buggy parsing of y[wxy]
.
s:g/y(.)/0000 x:36(~$0)/;s:g/x/w0/;s:g/w/00/;s/$/z/;map
.flatmap::32($_).fmt("%05b").flip.comb,[Z] .split("z").map: (*~0 x.chars).comb
Try it online!
The line break is there just to make the text fit on the screen. It is not a part of the program.
How does it work
It is an anonymous function that takes a mutable string. (This makes using the function a little bit peculiar, because you can give it only variables, not literals.) After some work, it returns a list of lists containing 0's and 1's, with the same meaning as in the original post.
The input string comes in in the variable $_
. We start by using a series of substitution statements on it in order to get rid of all of those shorthands for various numbers of zeroes. First, we need to sort out the y
, because in the case of yx
or yw
, the w
(or x
) does not constitute a shorthand by itself. We search for y(.)
(y
and one character, which it remembers) and replace it by 000"0"x:36(~$0)
: the three zeroes are copied verbatim, then we convert the next character from base 36 to base 10 (:36(~$0)
) and add that many more zeroes. Then, we replace the w
's using s:g/w/00/
, and the x
's using s:g/x/000/
. Finally, with s/$/z/
, we add a z
onto the end, adding a whole lot of empty lines to the bottom. (We'll see the reason later.)
The rest is just a big map statement. We're mapping over .split("z").map: (*~0 x.chars).comb})
, which is the input string (without zero shorthands), splitted into lines at z
, with each line being first padded with 0 x.chars
(tons of zeroes, namely as many as is the total length of the input string) on the right and then broken down into a list of individual characters (.comb
). Finally, we transpose it with [Z]
(reduce with zip). Zipping ends as soon as the shortest list is depleted, which results in all lines having the same length. (The number of useless trailing zeroes on the right is equal to the length of the shortest line. Also, this transposition trick fails for a "matrix" with only one row. That's why we forcibly added another row at the end before.)
Now, we just map over the rows (columns of the original matrix) and replace each character encountered with the corresponding 5 bits. That is done using :32($_)
(base 32 to base 10) .fmt("%05b")
(format as a bitstring of width 5, padded with zeroes) .flip
(reverse the string, because the LSB is in the top row, not the bottom) .comb
(break the string into a list of characters). We have used .flatmap
, which flattens the resulting list (otherwise we would get a list of lists in each column). The transpose of the result is then implicitly returned.
(I feel a little bit bad because of abusing the possibility of trailing zeroes so hard. But it reduced the bytecount quite considerably :âÂÂ).)
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for1yx1
and1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be onlyy[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)
â Ramillies
19 hours ago
You can replace the000
in the y substitution withx
â Jo King
9 hours ago
add a comment |Â
up vote
2
down vote
Jelly, 66 bytes
Yowza!
ÃÂBiâ±®+
Ã
ÂuÃ
Âá¹£â¾YYj38Ã
»á¹£âÂÂYõḢç3;)Fá¹£âÂÂWj2á¹£âÂÂXj3âÂÂ0áºÂ$ùOÃÂ?â¬Fá¹£âÂÂZõïâÂÂ0ç31Bá¸Ââ¬UZ)áºÂz0
A monadic link which yields a transposed version as a list of lists (add Z
to the end to transpose back).
Try it online! Or see the test-suite (with pretty printed output).
add a comment |Â
up vote
0
down vote
Python 2, 249 bytes
def f(s,Z='0'):
while 'y'in s:i=s.find('y');s=s[:i]+4*Z+Z*int(s[i+1],36)+s[i+2:]
t=s.replace('w',2*Z).replace('x',3*Z).split('z')
return map(''.join,zip(*[[(Z*5+bin(int(c,32))[2:])[-5:][::-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))
Try it online!
There is a superfluous space inwhile 'y'in
. I think the subscript[-5:][::-1]
can be golfed to[:-6:-1]
. The return statement can be put on the previous line.
â Jonathan Frech
7 hours ago
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
JavaScript (ES8), 197 bytes
Takes input as a string. Returns an array of strings with '#' and spaces. The output may include extra (but consistent) trailing spaces on each line.
s=>[x='x',...s.replace(/w|x|y./g,s=>''.padEnd(s<x?2:s>x?P(s[1],36)+4:3),P=parseInt)].map(c=>[!++w,1,2,3,4].map(i=>c<x?o[y+i-5]+=' #'[P(c,36)>>i&1]:o=[...++y&&o,'']),w=y=o=)&&o.map(r=>r.padEnd(w))
Try it online! (prettified output)
How?
Global variables
- The character
"x"
is used several times, so it's worth storing it into the variable x. - The function
parseInt
is used twice, so it's worth storing it into the variable P.
y is the row index, initialized to 0.
w keeps track of an upper bound of the width which is used to pad the final output.
o[Â ] is the output array, initially empty.
Pre-processing of repeated zeros
We first replace all patterns "w"
, "x"
and "yX"
in the input string with the appropriate number of spaces. These spaces will later be interpreted as "0"
.
s.replace(
/w|x|y./g,
s => ''.padEnd(
// w --> 2
s < x ? 2 :
// yX --> value of X + 4
s > x ? P(s[1], 36) + 4 :
// x --> 3
3
)
)
Decoding
We split the resulting string, prepend an initial "x"
and iterate 5 times (with i = 0 to 4) on each character c:
If c is lower than
"x"
, we append the corresponding pattern to the next 5 rows.o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
If c is greater than or equal to
"x"
, we allocate 5 new empty strings in o[Â ] and add 5 to y. This is triggered by the initial"x"
that was added at the beginning of the string, or by any"z"
in the original content.o = [...++y && o, '']
Padding
Finally, we pad each string in o[Â ] with spaces so that they all have w characters.
o.map(r => r.padEnd(w))
add a comment |Â
up vote
6
down vote
JavaScript (ES8), 197 bytes
Takes input as a string. Returns an array of strings with '#' and spaces. The output may include extra (but consistent) trailing spaces on each line.
s=>[x='x',...s.replace(/w|x|y./g,s=>''.padEnd(s<x?2:s>x?P(s[1],36)+4:3),P=parseInt)].map(c=>[!++w,1,2,3,4].map(i=>c<x?o[y+i-5]+=' #'[P(c,36)>>i&1]:o=[...++y&&o,'']),w=y=o=)&&o.map(r=>r.padEnd(w))
Try it online! (prettified output)
How?
Global variables
- The character
"x"
is used several times, so it's worth storing it into the variable x. - The function
parseInt
is used twice, so it's worth storing it into the variable P.
y is the row index, initialized to 0.
w keeps track of an upper bound of the width which is used to pad the final output.
o[Â ] is the output array, initially empty.
Pre-processing of repeated zeros
We first replace all patterns "w"
, "x"
and "yX"
in the input string with the appropriate number of spaces. These spaces will later be interpreted as "0"
.
s.replace(
/w|x|y./g,
s => ''.padEnd(
// w --> 2
s < x ? 2 :
// yX --> value of X + 4
s > x ? P(s[1], 36) + 4 :
// x --> 3
3
)
)
Decoding
We split the resulting string, prepend an initial "x"
and iterate 5 times (with i = 0 to 4) on each character c:
If c is lower than
"x"
, we append the corresponding pattern to the next 5 rows.o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
If c is greater than or equal to
"x"
, we allocate 5 new empty strings in o[Â ] and add 5 to y. This is triggered by the initial"x"
that was added at the beginning of the string, or by any"z"
in the original content.o = [...++y && o, '']
Padding
Finally, we pad each string in o[Â ] with spaces so that they all have w characters.
o.map(r => r.padEnd(w))
add a comment |Â
up vote
6
down vote
up vote
6
down vote
JavaScript (ES8), 197 bytes
Takes input as a string. Returns an array of strings with '#' and spaces. The output may include extra (but consistent) trailing spaces on each line.
s=>[x='x',...s.replace(/w|x|y./g,s=>''.padEnd(s<x?2:s>x?P(s[1],36)+4:3),P=parseInt)].map(c=>[!++w,1,2,3,4].map(i=>c<x?o[y+i-5]+=' #'[P(c,36)>>i&1]:o=[...++y&&o,'']),w=y=o=)&&o.map(r=>r.padEnd(w))
Try it online! (prettified output)
How?
Global variables
- The character
"x"
is used several times, so it's worth storing it into the variable x. - The function
parseInt
is used twice, so it's worth storing it into the variable P.
y is the row index, initialized to 0.
w keeps track of an upper bound of the width which is used to pad the final output.
o[Â ] is the output array, initially empty.
Pre-processing of repeated zeros
We first replace all patterns "w"
, "x"
and "yX"
in the input string with the appropriate number of spaces. These spaces will later be interpreted as "0"
.
s.replace(
/w|x|y./g,
s => ''.padEnd(
// w --> 2
s < x ? 2 :
// yX --> value of X + 4
s > x ? P(s[1], 36) + 4 :
// x --> 3
3
)
)
Decoding
We split the resulting string, prepend an initial "x"
and iterate 5 times (with i = 0 to 4) on each character c:
If c is lower than
"x"
, we append the corresponding pattern to the next 5 rows.o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
If c is greater than or equal to
"x"
, we allocate 5 new empty strings in o[Â ] and add 5 to y. This is triggered by the initial"x"
that was added at the beginning of the string, or by any"z"
in the original content.o = [...++y && o, '']
Padding
Finally, we pad each string in o[Â ] with spaces so that they all have w characters.
o.map(r => r.padEnd(w))
JavaScript (ES8), 197 bytes
Takes input as a string. Returns an array of strings with '#' and spaces. The output may include extra (but consistent) trailing spaces on each line.
s=>[x='x',...s.replace(/w|x|y./g,s=>''.padEnd(s<x?2:s>x?P(s[1],36)+4:3),P=parseInt)].map(c=>[!++w,1,2,3,4].map(i=>c<x?o[y+i-5]+=' #'[P(c,36)>>i&1]:o=[...++y&&o,'']),w=y=o=)&&o.map(r=>r.padEnd(w))
Try it online! (prettified output)
How?
Global variables
- The character
"x"
is used several times, so it's worth storing it into the variable x. - The function
parseInt
is used twice, so it's worth storing it into the variable P.
y is the row index, initialized to 0.
w keeps track of an upper bound of the width which is used to pad the final output.
o[Â ] is the output array, initially empty.
Pre-processing of repeated zeros
We first replace all patterns "w"
, "x"
and "yX"
in the input string with the appropriate number of spaces. These spaces will later be interpreted as "0"
.
s.replace(
/w|x|y./g,
s => ''.padEnd(
// w --> 2
s < x ? 2 :
// yX --> value of X + 4
s > x ? P(s[1], 36) + 4 :
// x --> 3
3
)
)
Decoding
We split the resulting string, prepend an initial "x"
and iterate 5 times (with i = 0 to 4) on each character c:
If c is lower than
"x"
, we append the corresponding pattern to the next 5 rows.o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
If c is greater than or equal to
"x"
, we allocate 5 new empty strings in o[Â ] and add 5 to y. This is triggered by the initial"x"
that was added at the beginning of the string, or by any"z"
in the original content.o = [...++y && o, '']
Padding
Finally, we pad each string in o[Â ] with spaces so that they all have w characters.
o.map(r => r.padEnd(w))
edited 18 hours ago
answered yesterday
![](https://i.stack.imgur.com/j259a.jpg?s=32&g=1)
![](https://i.stack.imgur.com/j259a.jpg?s=32&g=1)
Arnauld
60k472252
60k472252
add a comment |Â
add a comment |Â
up vote
5
down vote
05AB1E, 148 132 bytes
I'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
"yy"þ38ÃÂ:'yð:Ã
¾hAëDUsðë#õN>â iDýXsk4+sæs0sÃÂì}}'wþ2ÃÂ:'xþ3ÃÂ:J'zð:ðë#DéøgUõDgXs-0sÃÂë}vNUyvNâÂÂ+âÂÂ*X+VDykD32â¹ibDg5s-0sÃÂìRX0Qiöì}YðëìÃÂ]ïõ#øJ
Try it online!
Try it online!
Outputs the transposed matrix as multiple output lines of 1s and 0s. If you want pretty-printed output, add J'1'âÂÂ:'0'.:
at the end.
Will add extra zeros.
Explanation
(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)
The basic algorithm is:
- Replace "yy" with 38 0s
- Split on "y" and and expand the 0-runs.
- Replace "w" and "x"
- Figure out the longest column (that is, the longest string between z's) and pad all the other columns so they are that length. (This is necessary because of how the algorithm below works)
- Split on z
- At this point, the input string is an array of columns where each column is a string of [0-9a-v], where each column is the same length.
- The algorithm to get it into the output format is to
- Convert the characters to numbers by using indexOf in a lookup string
- Convert the characters to binary and then pad to length 5
- If it is the first column, add a linebreak before the binary number
- Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
- Push the binary string with prefix to 05AB1E's "global array" register/variable
- Sort the global array. The prefix string, which determines the sort order, will make sure everything ends up in the right order and the linebreaks are in the right places.
- Remove the prefix string from each element of the global array
- Join the array with "" and print it.
There are some other minor details you can see below in the expanded code. Everything after the tabs at the end of a line is a comment and can be ignored. (This comment scheme is not part of 05AB1E, by the way. I did it this way because it looked nice.) Lines that have comments starting with "@" are for debugging purposes and can be omitted without changing the final output.
"yy"þ38ÃÂ: Replace "yy" with 38 0's. (y is the 34th character in the index, so need to add 34+4 = 38). þ is initialized to zero, which saves one byte from typing '038
'yð: Replace "y" with " "
"Replaced input Stage1 = "?D, @DEBUG
Ã
¾hAë Pushes [0-9a-z]
DU Set X to [0-9a-z] and leave [0-9a-z] on the stack.
s Swap top two elements. Now the stack is [0-9a-z],input
ðë Append a space so the below splitter works even if there are no other spaces.
# Split input on " ", which "y" has been replaced with
õ Map. This map replaces the y runs
"Element = "?D, @DEBUG
"N = "?N, @DEBUG
N>â i If N != 0
"Replacing!", @DEBUG
Dý Get the first letter
X Push X
s Swap
k X (which is [0-9a-z]) .indexOf(firstLetter)
"indexOf run token = "?D, @DEBUG
4+ Add 4 to the index, now becoming the number of zeros to add
s Swap. Now top is the string between runs
æ Remove the first character
s Swap again. Now the top is the number of zeros to add.
0sÃÂì Add that many zeros to the start of the element.
"Element Replaced = "?D, @DEBUG
}
}
'wþ2ÃÂ: Need to do this replacement after the y replacement so stuff like yw gets parsed properly. Again, þ is zero.
'xþ3ÃÂ:
J Join with ""
"Replaced input Stage2 = "?D, @DEBUG
'zð: Replace "z" with " "
ðë Append a space so the below splitter works even if there are no other spaces.
# Split on space. (Can't do split on z because it splits on z+)
DéøgU Get max length and store it in X
"Max length = "?X, @DEBUG
õ Map
DgXs- max column length - this column length
"Zeros to add = "?D, @DEBUG
0sÃÂë Add 0s to the end of the column so it is the same length as the longest one.
}
"Replaced input Stage3 = "?D, @DEBUG
"0 Stack top = "?D, @SDEBUG
"0 Stack top-1 = "?sD,s @SDEBUG
v pop and loop over top element, which is array of column code
NU Store the column number in X
yv Loop over each character in the column
NâÂÂ+âÂÂ*X+V Set Y to (rowNumber+1000)*1000+X, where X is the column number. This result is used for sorting.
"1 Stack top = "?D, @SDEBUG
"1 Stack top = "?D, @SDEBUG
D Duplicate top element (which is now [0-9a-z])
y Push y (special loop variable)
"Character = "?D, @DEBUG
k Push indexOf y in [0-9a-z]
"Index = "?D, @DEBUG
"2.1 Stack top = "?D, @SDEBUG
"2.1 Stack top-1 = "?sD,s @SDEBUG
D Duplicate index.
32â¹i index < 32. This uses up one copy of index
b Push the index in binary. This uses the second copy of index.
Dg Get the length of the binary number
5s- 5 - length
0sÃÂì Add 5-length 0s to the start of the binary number
"Binary = "?D, @SDEBUG
R Reverse the binary string. This gives the proper transposed output.
X0Qi If X (which is set to the column number) == 0
öì Stick a linebreak at the beginning of the binary string
}
Y Push Y (the sort prefix).
ð Push a space character
ëì This gives "<row prefix> <binary representation of row>"
"2.5 Stack top = "?D, @SDEBUG
"2.5 Stack top-1 = "?sD,s @SDEBUG
"Pushing '"?D?"'", @DEBUG
ÃÂ Push "<row prefix>|<binary representation of row>" to global array
"2.6 Stack top = "?D, @SDEBUG
"2.6 Stack top-1 = "?sD,s @SDEBUG
] Close all blocks
ï Push global array to stack and sort it.
"Sorted Data = "?D, @DEBUG
õ Map. This block removes the row numbers
# Split on spaces
ø Get the last element
J Join with ""
'1'âÂÂ:'0'.: @DEBUG pretty print
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last,
.
â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:"yy"
can beâÂÂyy
(05AB1E has both a 2-char and 3-char string builtin).>âÂÂ
can beÃÂ
(truthified, basically0
remains0
and everything else becomes1
).}}
can be]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.
â Kevin Cruijssen
2 hours ago
 |Â
show 1 more comment
up vote
5
down vote
05AB1E, 148 132 bytes
I'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
"yy"þ38ÃÂ:'yð:Ã
¾hAëDUsðë#õN>â iDýXsk4+sæs0sÃÂì}}'wþ2ÃÂ:'xþ3ÃÂ:J'zð:ðë#DéøgUõDgXs-0sÃÂë}vNUyvNâÂÂ+âÂÂ*X+VDykD32â¹ibDg5s-0sÃÂìRX0Qiöì}YðëìÃÂ]ïõ#øJ
Try it online!
Try it online!
Outputs the transposed matrix as multiple output lines of 1s and 0s. If you want pretty-printed output, add J'1'âÂÂ:'0'.:
at the end.
Will add extra zeros.
Explanation
(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)
The basic algorithm is:
- Replace "yy" with 38 0s
- Split on "y" and and expand the 0-runs.
- Replace "w" and "x"
- Figure out the longest column (that is, the longest string between z's) and pad all the other columns so they are that length. (This is necessary because of how the algorithm below works)
- Split on z
- At this point, the input string is an array of columns where each column is a string of [0-9a-v], where each column is the same length.
- The algorithm to get it into the output format is to
- Convert the characters to numbers by using indexOf in a lookup string
- Convert the characters to binary and then pad to length 5
- If it is the first column, add a linebreak before the binary number
- Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
- Push the binary string with prefix to 05AB1E's "global array" register/variable
- Sort the global array. The prefix string, which determines the sort order, will make sure everything ends up in the right order and the linebreaks are in the right places.
- Remove the prefix string from each element of the global array
- Join the array with "" and print it.
There are some other minor details you can see below in the expanded code. Everything after the tabs at the end of a line is a comment and can be ignored. (This comment scheme is not part of 05AB1E, by the way. I did it this way because it looked nice.) Lines that have comments starting with "@" are for debugging purposes and can be omitted without changing the final output.
"yy"þ38ÃÂ: Replace "yy" with 38 0's. (y is the 34th character in the index, so need to add 34+4 = 38). þ is initialized to zero, which saves one byte from typing '038
'yð: Replace "y" with " "
"Replaced input Stage1 = "?D, @DEBUG
Ã
¾hAë Pushes [0-9a-z]
DU Set X to [0-9a-z] and leave [0-9a-z] on the stack.
s Swap top two elements. Now the stack is [0-9a-z],input
ðë Append a space so the below splitter works even if there are no other spaces.
# Split input on " ", which "y" has been replaced with
õ Map. This map replaces the y runs
"Element = "?D, @DEBUG
"N = "?N, @DEBUG
N>â i If N != 0
"Replacing!", @DEBUG
Dý Get the first letter
X Push X
s Swap
k X (which is [0-9a-z]) .indexOf(firstLetter)
"indexOf run token = "?D, @DEBUG
4+ Add 4 to the index, now becoming the number of zeros to add
s Swap. Now top is the string between runs
æ Remove the first character
s Swap again. Now the top is the number of zeros to add.
0sÃÂì Add that many zeros to the start of the element.
"Element Replaced = "?D, @DEBUG
}
}
'wþ2ÃÂ: Need to do this replacement after the y replacement so stuff like yw gets parsed properly. Again, þ is zero.
'xþ3ÃÂ:
J Join with ""
"Replaced input Stage2 = "?D, @DEBUG
'zð: Replace "z" with " "
ðë Append a space so the below splitter works even if there are no other spaces.
# Split on space. (Can't do split on z because it splits on z+)
DéøgU Get max length and store it in X
"Max length = "?X, @DEBUG
õ Map
DgXs- max column length - this column length
"Zeros to add = "?D, @DEBUG
0sÃÂë Add 0s to the end of the column so it is the same length as the longest one.
}
"Replaced input Stage3 = "?D, @DEBUG
"0 Stack top = "?D, @SDEBUG
"0 Stack top-1 = "?sD,s @SDEBUG
v pop and loop over top element, which is array of column code
NU Store the column number in X
yv Loop over each character in the column
NâÂÂ+âÂÂ*X+V Set Y to (rowNumber+1000)*1000+X, where X is the column number. This result is used for sorting.
"1 Stack top = "?D, @SDEBUG
"1 Stack top = "?D, @SDEBUG
D Duplicate top element (which is now [0-9a-z])
y Push y (special loop variable)
"Character = "?D, @DEBUG
k Push indexOf y in [0-9a-z]
"Index = "?D, @DEBUG
"2.1 Stack top = "?D, @SDEBUG
"2.1 Stack top-1 = "?sD,s @SDEBUG
D Duplicate index.
32â¹i index < 32. This uses up one copy of index
b Push the index in binary. This uses the second copy of index.
Dg Get the length of the binary number
5s- 5 - length
0sÃÂì Add 5-length 0s to the start of the binary number
"Binary = "?D, @SDEBUG
R Reverse the binary string. This gives the proper transposed output.
X0Qi If X (which is set to the column number) == 0
öì Stick a linebreak at the beginning of the binary string
}
Y Push Y (the sort prefix).
ð Push a space character
ëì This gives "<row prefix> <binary representation of row>"
"2.5 Stack top = "?D, @SDEBUG
"2.5 Stack top-1 = "?sD,s @SDEBUG
"Pushing '"?D?"'", @DEBUG
ÃÂ Push "<row prefix>|<binary representation of row>" to global array
"2.6 Stack top = "?D, @SDEBUG
"2.6 Stack top-1 = "?sD,s @SDEBUG
] Close all blocks
ï Push global array to stack and sort it.
"Sorted Data = "?D, @DEBUG
õ Map. This block removes the row numbers
# Split on spaces
ø Get the last element
J Join with ""
'1'âÂÂ:'0'.: @DEBUG pretty print
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last,
.
â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:"yy"
can beâÂÂyy
(05AB1E has both a 2-char and 3-char string builtin).>âÂÂ
can beÃÂ
(truthified, basically0
remains0
and everything else becomes1
).}}
can be]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.
â Kevin Cruijssen
2 hours ago
 |Â
show 1 more comment
up vote
5
down vote
up vote
5
down vote
05AB1E, 148 132 bytes
I'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
"yy"þ38ÃÂ:'yð:Ã
¾hAëDUsðë#õN>â iDýXsk4+sæs0sÃÂì}}'wþ2ÃÂ:'xþ3ÃÂ:J'zð:ðë#DéøgUõDgXs-0sÃÂë}vNUyvNâÂÂ+âÂÂ*X+VDykD32â¹ibDg5s-0sÃÂìRX0Qiöì}YðëìÃÂ]ïõ#øJ
Try it online!
Try it online!
Outputs the transposed matrix as multiple output lines of 1s and 0s. If you want pretty-printed output, add J'1'âÂÂ:'0'.:
at the end.
Will add extra zeros.
Explanation
(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)
The basic algorithm is:
- Replace "yy" with 38 0s
- Split on "y" and and expand the 0-runs.
- Replace "w" and "x"
- Figure out the longest column (that is, the longest string between z's) and pad all the other columns so they are that length. (This is necessary because of how the algorithm below works)
- Split on z
- At this point, the input string is an array of columns where each column is a string of [0-9a-v], where each column is the same length.
- The algorithm to get it into the output format is to
- Convert the characters to numbers by using indexOf in a lookup string
- Convert the characters to binary and then pad to length 5
- If it is the first column, add a linebreak before the binary number
- Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
- Push the binary string with prefix to 05AB1E's "global array" register/variable
- Sort the global array. The prefix string, which determines the sort order, will make sure everything ends up in the right order and the linebreaks are in the right places.
- Remove the prefix string from each element of the global array
- Join the array with "" and print it.
There are some other minor details you can see below in the expanded code. Everything after the tabs at the end of a line is a comment and can be ignored. (This comment scheme is not part of 05AB1E, by the way. I did it this way because it looked nice.) Lines that have comments starting with "@" are for debugging purposes and can be omitted without changing the final output.
"yy"þ38ÃÂ: Replace "yy" with 38 0's. (y is the 34th character in the index, so need to add 34+4 = 38). þ is initialized to zero, which saves one byte from typing '038
'yð: Replace "y" with " "
"Replaced input Stage1 = "?D, @DEBUG
Ã
¾hAë Pushes [0-9a-z]
DU Set X to [0-9a-z] and leave [0-9a-z] on the stack.
s Swap top two elements. Now the stack is [0-9a-z],input
ðë Append a space so the below splitter works even if there are no other spaces.
# Split input on " ", which "y" has been replaced with
õ Map. This map replaces the y runs
"Element = "?D, @DEBUG
"N = "?N, @DEBUG
N>â i If N != 0
"Replacing!", @DEBUG
Dý Get the first letter
X Push X
s Swap
k X (which is [0-9a-z]) .indexOf(firstLetter)
"indexOf run token = "?D, @DEBUG
4+ Add 4 to the index, now becoming the number of zeros to add
s Swap. Now top is the string between runs
æ Remove the first character
s Swap again. Now the top is the number of zeros to add.
0sÃÂì Add that many zeros to the start of the element.
"Element Replaced = "?D, @DEBUG
}
}
'wþ2ÃÂ: Need to do this replacement after the y replacement so stuff like yw gets parsed properly. Again, þ is zero.
'xþ3ÃÂ:
J Join with ""
"Replaced input Stage2 = "?D, @DEBUG
'zð: Replace "z" with " "
ðë Append a space so the below splitter works even if there are no other spaces.
# Split on space. (Can't do split on z because it splits on z+)
DéøgU Get max length and store it in X
"Max length = "?X, @DEBUG
õ Map
DgXs- max column length - this column length
"Zeros to add = "?D, @DEBUG
0sÃÂë Add 0s to the end of the column so it is the same length as the longest one.
}
"Replaced input Stage3 = "?D, @DEBUG
"0 Stack top = "?D, @SDEBUG
"0 Stack top-1 = "?sD,s @SDEBUG
v pop and loop over top element, which is array of column code
NU Store the column number in X
yv Loop over each character in the column
NâÂÂ+âÂÂ*X+V Set Y to (rowNumber+1000)*1000+X, where X is the column number. This result is used for sorting.
"1 Stack top = "?D, @SDEBUG
"1 Stack top = "?D, @SDEBUG
D Duplicate top element (which is now [0-9a-z])
y Push y (special loop variable)
"Character = "?D, @DEBUG
k Push indexOf y in [0-9a-z]
"Index = "?D, @DEBUG
"2.1 Stack top = "?D, @SDEBUG
"2.1 Stack top-1 = "?sD,s @SDEBUG
D Duplicate index.
32â¹i index < 32. This uses up one copy of index
b Push the index in binary. This uses the second copy of index.
Dg Get the length of the binary number
5s- 5 - length
0sÃÂì Add 5-length 0s to the start of the binary number
"Binary = "?D, @SDEBUG
R Reverse the binary string. This gives the proper transposed output.
X0Qi If X (which is set to the column number) == 0
öì Stick a linebreak at the beginning of the binary string
}
Y Push Y (the sort prefix).
ð Push a space character
ëì This gives "<row prefix> <binary representation of row>"
"2.5 Stack top = "?D, @SDEBUG
"2.5 Stack top-1 = "?sD,s @SDEBUG
"Pushing '"?D?"'", @DEBUG
ÃÂ Push "<row prefix>|<binary representation of row>" to global array
"2.6 Stack top = "?D, @SDEBUG
"2.6 Stack top-1 = "?sD,s @SDEBUG
] Close all blocks
ï Push global array to stack and sort it.
"Sorted Data = "?D, @DEBUG
õ Map. This block removes the row numbers
# Split on spaces
ø Get the last element
J Join with ""
'1'âÂÂ:'0'.: @DEBUG pretty print
05AB1E, 148 132 bytes
I'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
"yy"þ38ÃÂ:'yð:Ã
¾hAëDUsðë#õN>â iDýXsk4+sæs0sÃÂì}}'wþ2ÃÂ:'xþ3ÃÂ:J'zð:ðë#DéøgUõDgXs-0sÃÂë}vNUyvNâÂÂ+âÂÂ*X+VDykD32â¹ibDg5s-0sÃÂìRX0Qiöì}YðëìÃÂ]ïõ#øJ
Try it online!
Try it online!
Outputs the transposed matrix as multiple output lines of 1s and 0s. If you want pretty-printed output, add J'1'âÂÂ:'0'.:
at the end.
Will add extra zeros.
Explanation
(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)
The basic algorithm is:
- Replace "yy" with 38 0s
- Split on "y" and and expand the 0-runs.
- Replace "w" and "x"
- Figure out the longest column (that is, the longest string between z's) and pad all the other columns so they are that length. (This is necessary because of how the algorithm below works)
- Split on z
- At this point, the input string is an array of columns where each column is a string of [0-9a-v], where each column is the same length.
- The algorithm to get it into the output format is to
- Convert the characters to numbers by using indexOf in a lookup string
- Convert the characters to binary and then pad to length 5
- If it is the first column, add a linebreak before the binary number
- Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
- Push the binary string with prefix to 05AB1E's "global array" register/variable
- Sort the global array. The prefix string, which determines the sort order, will make sure everything ends up in the right order and the linebreaks are in the right places.
- Remove the prefix string from each element of the global array
- Join the array with "" and print it.
There are some other minor details you can see below in the expanded code. Everything after the tabs at the end of a line is a comment and can be ignored. (This comment scheme is not part of 05AB1E, by the way. I did it this way because it looked nice.) Lines that have comments starting with "@" are for debugging purposes and can be omitted without changing the final output.
"yy"þ38ÃÂ: Replace "yy" with 38 0's. (y is the 34th character in the index, so need to add 34+4 = 38). þ is initialized to zero, which saves one byte from typing '038
'yð: Replace "y" with " "
"Replaced input Stage1 = "?D, @DEBUG
Ã
¾hAë Pushes [0-9a-z]
DU Set X to [0-9a-z] and leave [0-9a-z] on the stack.
s Swap top two elements. Now the stack is [0-9a-z],input
ðë Append a space so the below splitter works even if there are no other spaces.
# Split input on " ", which "y" has been replaced with
õ Map. This map replaces the y runs
"Element = "?D, @DEBUG
"N = "?N, @DEBUG
N>â i If N != 0
"Replacing!", @DEBUG
Dý Get the first letter
X Push X
s Swap
k X (which is [0-9a-z]) .indexOf(firstLetter)
"indexOf run token = "?D, @DEBUG
4+ Add 4 to the index, now becoming the number of zeros to add
s Swap. Now top is the string between runs
æ Remove the first character
s Swap again. Now the top is the number of zeros to add.
0sÃÂì Add that many zeros to the start of the element.
"Element Replaced = "?D, @DEBUG
}
}
'wþ2ÃÂ: Need to do this replacement after the y replacement so stuff like yw gets parsed properly. Again, þ is zero.
'xþ3ÃÂ:
J Join with ""
"Replaced input Stage2 = "?D, @DEBUG
'zð: Replace "z" with " "
ðë Append a space so the below splitter works even if there are no other spaces.
# Split on space. (Can't do split on z because it splits on z+)
DéøgU Get max length and store it in X
"Max length = "?X, @DEBUG
õ Map
DgXs- max column length - this column length
"Zeros to add = "?D, @DEBUG
0sÃÂë Add 0s to the end of the column so it is the same length as the longest one.
}
"Replaced input Stage3 = "?D, @DEBUG
"0 Stack top = "?D, @SDEBUG
"0 Stack top-1 = "?sD,s @SDEBUG
v pop and loop over top element, which is array of column code
NU Store the column number in X
yv Loop over each character in the column
NâÂÂ+âÂÂ*X+V Set Y to (rowNumber+1000)*1000+X, where X is the column number. This result is used for sorting.
"1 Stack top = "?D, @SDEBUG
"1 Stack top = "?D, @SDEBUG
D Duplicate top element (which is now [0-9a-z])
y Push y (special loop variable)
"Character = "?D, @DEBUG
k Push indexOf y in [0-9a-z]
"Index = "?D, @DEBUG
"2.1 Stack top = "?D, @SDEBUG
"2.1 Stack top-1 = "?sD,s @SDEBUG
D Duplicate index.
32â¹i index < 32. This uses up one copy of index
b Push the index in binary. This uses the second copy of index.
Dg Get the length of the binary number
5s- 5 - length
0sÃÂì Add 5-length 0s to the start of the binary number
"Binary = "?D, @SDEBUG
R Reverse the binary string. This gives the proper transposed output.
X0Qi If X (which is set to the column number) == 0
öì Stick a linebreak at the beginning of the binary string
}
Y Push Y (the sort prefix).
ð Push a space character
ëì This gives "<row prefix> <binary representation of row>"
"2.5 Stack top = "?D, @SDEBUG
"2.5 Stack top-1 = "?sD,s @SDEBUG
"Pushing '"?D?"'", @DEBUG
ÃÂ Push "<row prefix>|<binary representation of row>" to global array
"2.6 Stack top = "?D, @SDEBUG
"2.6 Stack top-1 = "?sD,s @SDEBUG
] Close all blocks
ï Push global array to stack and sort it.
"Sorted Data = "?D, @DEBUG
õ Map. This block removes the row numbers
# Split on spaces
ø Get the last element
J Join with ""
'1'âÂÂ:'0'.: @DEBUG pretty print
edited 6 hours ago
answered 8 hours ago
kerwizzy
513
513
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last,
.
â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:"yy"
can beâÂÂyy
(05AB1E has both a 2-char and 3-char string builtin).>âÂÂ
can beÃÂ
(truthified, basically0
remains0
and everything else becomes1
).}}
can be]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.
â Kevin Cruijssen
2 hours ago
 |Â
show 1 more comment
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last,
.
â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:"yy"
can beâÂÂyy
(05AB1E has both a 2-char and 3-char string builtin).>âÂÂ
can beÃÂ
(truthified, basically0
remains0
and everything else becomes1
).}}
can be]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.
â Kevin Cruijssen
2 hours ago
1
1
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
Hello and welcome to PPCG; very nice first post! Regarding your byte count: you are right. TIO even handily displays that the 148 characters are represented by 148 bytes using the 05AB1E code page.
â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last
,
.â Jonathan Frech
7 hours ago
One small note: Most golfing languages implement implicit printing; I think you can ommit your last
,
.â Jonathan Frech
7 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
I looked it over and made some improvements. The behavior will only be different (theoretically) for things with more than 1000 rows or columns, at which point the smaller program will do something unexpected.
â kerwizzy
6 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Not the easiest challenge to start on! Nice job, I imagine some of the 05AB1E stalwart will give some handy pointers when they come by.
â Jonathan Allan
3 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:
"yy"
can be âÂÂyy
(05AB1E has both a 2-char and 3-char string builtin). >âÂÂ
can be ÃÂ
(truthified, basically 0
remains 0
and everything else becomes 1
). }}
can be ]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.â Kevin Cruijssen
2 hours ago
Welcome to PPCG and the world of 05AB1E. I don't have that much time right now, and I've only started using 05AB1E a few months ago, so I'm not that much of a pro yet either, but here some small things to golf:
"yy"
can be âÂÂyy
(05AB1E has both a 2-char and 3-char string builtin). >âÂÂ
can be ÃÂ
(truthified, basically 0
remains 0
and everything else becomes 1
). }}
can be ]
(close all loops and if-elses). I'm sure some of the pro 05AB1E golfers are able to golf more substantial things than me, possibly even halving the byte-count.â Kevin Cruijssen
2 hours ago
 |Â
show 1 more comment
up vote
3
down vote
APL (Dyalog Unicode), 87 80 bytes
thangs to H.PWiz for saving 7 bytes
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµè'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
Try it online!
NB: Takes the input as an upper case string.
With pretty printed output
Explanation
aâÂÂâÂÂD,âÂÂA
a is the string '0123...89ABCD...XYZ'
('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)
replaces X W and Yx with the corresponding number of '0'
s'Z'(â âÂÂâ¢)
splits the string at each 'Z'
âÂÂ(5/2)â¤aâ³âµè
decodes each substring (explained below),âÂÂâÂÂ
reshapes and pads the result, returning a nested boolean array
âÂÂ(5/2)â¤aâ³âµè
è â apply to each substring
aâ³âµ â return indecies of each charactor in a (i.e. '0'=>0, '9'=>9, 'B'=>11
(5/2)⤠â turn each of these into a 5-bit binary column
â â reverse each column
Here is a 7 byte saving:aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfy
â H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
add a comment |Â
up vote
3
down vote
APL (Dyalog Unicode), 87 80 bytes
thangs to H.PWiz for saving 7 bytes
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµè'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
Try it online!
NB: Takes the input as an upper case string.
With pretty printed output
Explanation
aâÂÂâÂÂD,âÂÂA
a is the string '0123...89ABCD...XYZ'
('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)
replaces X W and Yx with the corresponding number of '0'
s'Z'(â âÂÂâ¢)
splits the string at each 'Z'
âÂÂ(5/2)â¤aâ³âµè
decodes each substring (explained below),âÂÂâÂÂ
reshapes and pads the result, returning a nested boolean array
âÂÂ(5/2)â¤aâ³âµè
è â apply to each substring
aâ³âµ â return indecies of each charactor in a (i.e. '0'=>0, '9'=>9, 'B'=>11
(5/2)⤠â turn each of these into a 5-bit binary column
â â reverse each column
Here is a 7 byte saving:aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfy
â H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
APL (Dyalog Unicode), 87 80 bytes
thangs to H.PWiz for saving 7 bytes
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµè'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
Try it online!
NB: Takes the input as an upper case string.
With pretty printed output
Explanation
aâÂÂâÂÂD,âÂÂA
a is the string '0123...89ABCD...XYZ'
('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)
replaces X W and Yx with the corresponding number of '0'
s'Z'(â âÂÂâ¢)
splits the string at each 'Z'
âÂÂ(5/2)â¤aâ³âµè
decodes each substring (explained below),âÂÂâÂÂ
reshapes and pads the result, returning a nested boolean array
âÂÂ(5/2)â¤aâ³âµè
è â apply to each substring
aâ³âµ â return indecies of each charactor in a (i.e. '0'=>0, '9'=>9, 'B'=>11
(5/2)⤠â turn each of these into a 5-bit binary column
â â reverse each column
APL (Dyalog Unicode), 87 80 bytes
thangs to H.PWiz for saving 7 bytes
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµè'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
Try it online!
NB: Takes the input as an upper case string.
With pretty printed output
Explanation
aâÂÂâÂÂD,âÂÂA
a is the string '0123...89ABCD...XYZ'
('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)
replaces X W and Yx with the corresponding number of '0'
s'Z'(â âÂÂâ¢)
splits the string at each 'Z'
âÂÂ(5/2)â¤aâ³âµè
decodes each substring (explained below),âÂÂâÂÂ
reshapes and pads the result, returning a nested boolean array
âÂÂ(5/2)â¤aâ³âµè
è â apply to each substring
aâ³âµ â return indecies of each charactor in a (i.e. '0'=>0, '9'=>9, 'B'=>11
(5/2)⤠â turn each of these into a 5-bit binary column
â â reverse each column
edited 12 hours ago
answered 13 hours ago
![](https://i.stack.imgur.com/35pXC.jpg?s=32&g=1)
![](https://i.stack.imgur.com/35pXC.jpg?s=32&g=1)
jslip
4416
4416
Here is a 7 byte saving:aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfy
â H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
add a comment |Â
Here is a 7 byte saving:aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfy
â H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
Here is a 7 byte saving:
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfyâ H.PWiz
12 hours ago
Here is a 7 byte saving:
aâÂÂâÂÂD,âÂÂAâÂÂ,âÂÂâÂÂâÂÂ(5/2)â¤aâ³âµ¨'Z'(â âÂÂâ¢)('Y.|W|X'âÂÂR'0'/â¨0::2+'WX'â³âµâÂÂ4+aâ³1âÂÂâµâµ.Match)âÂÂ
. The error catch also doesn't seem very golfyâ H.PWiz
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
â jslip
12 hours ago
add a comment |Â
up vote
2
down vote
Perl 6, 156 142 bytes
14 bytes saved thanks to Jo King. (Also fixed a little bug with parsing the y
and added a prettifier.)
Fixed the buggy parsing of y[wxy]
.
s:g/y(.)/0000 x:36(~$0)/;s:g/x/w0/;s:g/w/00/;s/$/z/;map
.flatmap::32($_).fmt("%05b").flip.comb,[Z] .split("z").map: (*~0 x.chars).comb
Try it online!
The line break is there just to make the text fit on the screen. It is not a part of the program.
How does it work
It is an anonymous function that takes a mutable string. (This makes using the function a little bit peculiar, because you can give it only variables, not literals.) After some work, it returns a list of lists containing 0's and 1's, with the same meaning as in the original post.
The input string comes in in the variable $_
. We start by using a series of substitution statements on it in order to get rid of all of those shorthands for various numbers of zeroes. First, we need to sort out the y
, because in the case of yx
or yw
, the w
(or x
) does not constitute a shorthand by itself. We search for y(.)
(y
and one character, which it remembers) and replace it by 000"0"x:36(~$0)
: the three zeroes are copied verbatim, then we convert the next character from base 36 to base 10 (:36(~$0)
) and add that many more zeroes. Then, we replace the w
's using s:g/w/00/
, and the x
's using s:g/x/000/
. Finally, with s/$/z/
, we add a z
onto the end, adding a whole lot of empty lines to the bottom. (We'll see the reason later.)
The rest is just a big map statement. We're mapping over .split("z").map: (*~0 x.chars).comb})
, which is the input string (without zero shorthands), splitted into lines at z
, with each line being first padded with 0 x.chars
(tons of zeroes, namely as many as is the total length of the input string) on the right and then broken down into a list of individual characters (.comb
). Finally, we transpose it with [Z]
(reduce with zip). Zipping ends as soon as the shortest list is depleted, which results in all lines having the same length. (The number of useless trailing zeroes on the right is equal to the length of the shortest line. Also, this transposition trick fails for a "matrix" with only one row. That's why we forcibly added another row at the end before.)
Now, we just map over the rows (columns of the original matrix) and replace each character encountered with the corresponding 5 bits. That is done using :32($_)
(base 32 to base 10) .fmt("%05b")
(format as a bitstring of width 5, padded with zeroes) .flip
(reverse the string, because the LSB is in the top row, not the bottom) .comb
(break the string into a list of characters). We have used .flatmap
, which flattens the resulting list (otherwise we would get a list of lists in each column). The transpose of the result is then implicitly returned.
(I feel a little bit bad because of abusing the possibility of trailing zeroes so hard. But it reduced the bytecount quite considerably :âÂÂ).)
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for1yx1
and1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be onlyy[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)
â Ramillies
19 hours ago
You can replace the000
in the y substitution withx
â Jo King
9 hours ago
add a comment |Â
up vote
2
down vote
Perl 6, 156 142 bytes
14 bytes saved thanks to Jo King. (Also fixed a little bug with parsing the y
and added a prettifier.)
Fixed the buggy parsing of y[wxy]
.
s:g/y(.)/0000 x:36(~$0)/;s:g/x/w0/;s:g/w/00/;s/$/z/;map
.flatmap::32($_).fmt("%05b").flip.comb,[Z] .split("z").map: (*~0 x.chars).comb
Try it online!
The line break is there just to make the text fit on the screen. It is not a part of the program.
How does it work
It is an anonymous function that takes a mutable string. (This makes using the function a little bit peculiar, because you can give it only variables, not literals.) After some work, it returns a list of lists containing 0's and 1's, with the same meaning as in the original post.
The input string comes in in the variable $_
. We start by using a series of substitution statements on it in order to get rid of all of those shorthands for various numbers of zeroes. First, we need to sort out the y
, because in the case of yx
or yw
, the w
(or x
) does not constitute a shorthand by itself. We search for y(.)
(y
and one character, which it remembers) and replace it by 000"0"x:36(~$0)
: the three zeroes are copied verbatim, then we convert the next character from base 36 to base 10 (:36(~$0)
) and add that many more zeroes. Then, we replace the w
's using s:g/w/00/
, and the x
's using s:g/x/000/
. Finally, with s/$/z/
, we add a z
onto the end, adding a whole lot of empty lines to the bottom. (We'll see the reason later.)
The rest is just a big map statement. We're mapping over .split("z").map: (*~0 x.chars).comb})
, which is the input string (without zero shorthands), splitted into lines at z
, with each line being first padded with 0 x.chars
(tons of zeroes, namely as many as is the total length of the input string) on the right and then broken down into a list of individual characters (.comb
). Finally, we transpose it with [Z]
(reduce with zip). Zipping ends as soon as the shortest list is depleted, which results in all lines having the same length. (The number of useless trailing zeroes on the right is equal to the length of the shortest line. Also, this transposition trick fails for a "matrix" with only one row. That's why we forcibly added another row at the end before.)
Now, we just map over the rows (columns of the original matrix) and replace each character encountered with the corresponding 5 bits. That is done using :32($_)
(base 32 to base 10) .fmt("%05b")
(format as a bitstring of width 5, padded with zeroes) .flip
(reverse the string, because the LSB is in the top row, not the bottom) .comb
(break the string into a list of characters). We have used .flatmap
, which flattens the resulting list (otherwise we would get a list of lists in each column). The transpose of the result is then implicitly returned.
(I feel a little bit bad because of abusing the possibility of trailing zeroes so hard. But it reduced the bytecount quite considerably :âÂÂ).)
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for1yx1
and1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be onlyy[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)
â Ramillies
19 hours ago
You can replace the000
in the y substitution withx
â Jo King
9 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Perl 6, 156 142 bytes
14 bytes saved thanks to Jo King. (Also fixed a little bug with parsing the y
and added a prettifier.)
Fixed the buggy parsing of y[wxy]
.
s:g/y(.)/0000 x:36(~$0)/;s:g/x/w0/;s:g/w/00/;s/$/z/;map
.flatmap::32($_).fmt("%05b").flip.comb,[Z] .split("z").map: (*~0 x.chars).comb
Try it online!
The line break is there just to make the text fit on the screen. It is not a part of the program.
How does it work
It is an anonymous function that takes a mutable string. (This makes using the function a little bit peculiar, because you can give it only variables, not literals.) After some work, it returns a list of lists containing 0's and 1's, with the same meaning as in the original post.
The input string comes in in the variable $_
. We start by using a series of substitution statements on it in order to get rid of all of those shorthands for various numbers of zeroes. First, we need to sort out the y
, because in the case of yx
or yw
, the w
(or x
) does not constitute a shorthand by itself. We search for y(.)
(y
and one character, which it remembers) and replace it by 000"0"x:36(~$0)
: the three zeroes are copied verbatim, then we convert the next character from base 36 to base 10 (:36(~$0)
) and add that many more zeroes. Then, we replace the w
's using s:g/w/00/
, and the x
's using s:g/x/000/
. Finally, with s/$/z/
, we add a z
onto the end, adding a whole lot of empty lines to the bottom. (We'll see the reason later.)
The rest is just a big map statement. We're mapping over .split("z").map: (*~0 x.chars).comb})
, which is the input string (without zero shorthands), splitted into lines at z
, with each line being first padded with 0 x.chars
(tons of zeroes, namely as many as is the total length of the input string) on the right and then broken down into a list of individual characters (.comb
). Finally, we transpose it with [Z]
(reduce with zip). Zipping ends as soon as the shortest list is depleted, which results in all lines having the same length. (The number of useless trailing zeroes on the right is equal to the length of the shortest line. Also, this transposition trick fails for a "matrix" with only one row. That's why we forcibly added another row at the end before.)
Now, we just map over the rows (columns of the original matrix) and replace each character encountered with the corresponding 5 bits. That is done using :32($_)
(base 32 to base 10) .fmt("%05b")
(format as a bitstring of width 5, padded with zeroes) .flip
(reverse the string, because the LSB is in the top row, not the bottom) .comb
(break the string into a list of characters). We have used .flatmap
, which flattens the resulting list (otherwise we would get a list of lists in each column). The transpose of the result is then implicitly returned.
(I feel a little bit bad because of abusing the possibility of trailing zeroes so hard. But it reduced the bytecount quite considerably :âÂÂ).)
Perl 6, 156 142 bytes
14 bytes saved thanks to Jo King. (Also fixed a little bug with parsing the y
and added a prettifier.)
Fixed the buggy parsing of y[wxy]
.
s:g/y(.)/0000 x:36(~$0)/;s:g/x/w0/;s:g/w/00/;s/$/z/;map
.flatmap::32($_).fmt("%05b").flip.comb,[Z] .split("z").map: (*~0 x.chars).comb
Try it online!
The line break is there just to make the text fit on the screen. It is not a part of the program.
How does it work
It is an anonymous function that takes a mutable string. (This makes using the function a little bit peculiar, because you can give it only variables, not literals.) After some work, it returns a list of lists containing 0's and 1's, with the same meaning as in the original post.
The input string comes in in the variable $_
. We start by using a series of substitution statements on it in order to get rid of all of those shorthands for various numbers of zeroes. First, we need to sort out the y
, because in the case of yx
or yw
, the w
(or x
) does not constitute a shorthand by itself. We search for y(.)
(y
and one character, which it remembers) and replace it by 000"0"x:36(~$0)
: the three zeroes are copied verbatim, then we convert the next character from base 36 to base 10 (:36(~$0)
) and add that many more zeroes. Then, we replace the w
's using s:g/w/00/
, and the x
's using s:g/x/000/
. Finally, with s/$/z/
, we add a z
onto the end, adding a whole lot of empty lines to the bottom. (We'll see the reason later.)
The rest is just a big map statement. We're mapping over .split("z").map: (*~0 x.chars).comb})
, which is the input string (without zero shorthands), splitted into lines at z
, with each line being first padded with 0 x.chars
(tons of zeroes, namely as many as is the total length of the input string) on the right and then broken down into a list of individual characters (.comb
). Finally, we transpose it with [Z]
(reduce with zip). Zipping ends as soon as the shortest list is depleted, which results in all lines having the same length. (The number of useless trailing zeroes on the right is equal to the length of the shortest line. Also, this transposition trick fails for a "matrix" with only one row. That's why we forcibly added another row at the end before.)
Now, we just map over the rows (columns of the original matrix) and replace each character encountered with the corresponding 5 bits. That is done using :32($_)
(base 32 to base 10) .fmt("%05b")
(format as a bitstring of width 5, padded with zeroes) .flip
(reverse the string, because the LSB is in the top row, not the bottom) .comb
(break the string into a list of characters). We have used .flatmap
, which flattens the resulting list (otherwise we would get a list of lists in each column). The transpose of the result is then implicitly returned.
(I feel a little bit bad because of abusing the possibility of trailing zeroes so hard. But it reduced the bytecount quite considerably :âÂÂ).)
edited 19 hours ago
answered yesterday
Ramillies
1,291411
1,291411
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for1yx1
and1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be onlyy[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)
â Ramillies
19 hours ago
You can replace the000
in the y substitution withx
â Jo King
9 hours ago
add a comment |Â
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for1yx1
and1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be onlyy[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)
â Ramillies
19 hours ago
You can replace the000
in the y substitution withx
â Jo King
9 hours ago
142 bytes
â Jo King
yesterday
142 bytes
â Jo King
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
@JoKing â Oh yes, thank you very much!
â Ramillies
yesterday
Fails for
1yx1
and 1yw1
â Jonathan Allan
19 hours ago
Fails for
1yx1
and 1yw1
â Jonathan Allan
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be only
y[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)â Ramillies
19 hours ago
@JonathanAllan, you're right, thank you. I'll fix it in a moment. (I first thought for some reason that there could be only
y[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)â Ramillies
19 hours ago
You can replace the
000
in the y substitution with x
â Jo King
9 hours ago
You can replace the
000
in the y substitution with x
â Jo King
9 hours ago
add a comment |Â
up vote
2
down vote
Jelly, 66 bytes
Yowza!
ÃÂBiâ±®+
Ã
ÂuÃ
Âá¹£â¾YYj38Ã
»á¹£âÂÂYõḢç3;)Fá¹£âÂÂWj2á¹£âÂÂXj3âÂÂ0áºÂ$ùOÃÂ?â¬Fá¹£âÂÂZõïâÂÂ0ç31Bá¸Ââ¬UZ)áºÂz0
A monadic link which yields a transposed version as a list of lists (add Z
to the end to transpose back).
Try it online! Or see the test-suite (with pretty printed output).
add a comment |Â
up vote
2
down vote
Jelly, 66 bytes
Yowza!
ÃÂBiâ±®+
Ã
ÂuÃ
Âá¹£â¾YYj38Ã
»á¹£âÂÂYõḢç3;)Fá¹£âÂÂWj2á¹£âÂÂXj3âÂÂ0áºÂ$ùOÃÂ?â¬Fá¹£âÂÂZõïâÂÂ0ç31Bá¸Ââ¬UZ)áºÂz0
A monadic link which yields a transposed version as a list of lists (add Z
to the end to transpose back).
Try it online! Or see the test-suite (with pretty printed output).
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Jelly, 66 bytes
Yowza!
ÃÂBiâ±®+
Ã
ÂuÃ
Âá¹£â¾YYj38Ã
»á¹£âÂÂYõḢç3;)Fá¹£âÂÂWj2á¹£âÂÂXj3âÂÂ0áºÂ$ùOÃÂ?â¬Fá¹£âÂÂZõïâÂÂ0ç31Bá¸Ââ¬UZ)áºÂz0
A monadic link which yields a transposed version as a list of lists (add Z
to the end to transpose back).
Try it online! Or see the test-suite (with pretty printed output).
Jelly, 66 bytes
Yowza!
ÃÂBiâ±®+
Ã
ÂuÃ
Âá¹£â¾YYj38Ã
»á¹£âÂÂYõḢç3;)Fá¹£âÂÂWj2á¹£âÂÂXj3âÂÂ0áºÂ$ùOÃÂ?â¬Fá¹£âÂÂZõïâÂÂ0ç31Bá¸Ââ¬UZ)áºÂz0
A monadic link which yields a transposed version as a list of lists (add Z
to the end to transpose back).
Try it online! Or see the test-suite (with pretty printed output).
edited 13 hours ago
answered 13 hours ago
![](https://i.stack.imgur.com/fIyIX.jpg?s=32&g=1)
![](https://i.stack.imgur.com/fIyIX.jpg?s=32&g=1)
Jonathan Allan
46.5k433155
46.5k433155
add a comment |Â
add a comment |Â
up vote
0
down vote
Python 2, 249 bytes
def f(s,Z='0'):
while 'y'in s:i=s.find('y');s=s[:i]+4*Z+Z*int(s[i+1],36)+s[i+2:]
t=s.replace('w',2*Z).replace('x',3*Z).split('z')
return map(''.join,zip(*[[(Z*5+bin(int(c,32))[2:])[-5:][::-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))
Try it online!
There is a superfluous space inwhile 'y'in
. I think the subscript[-5:][::-1]
can be golfed to[:-6:-1]
. The return statement can be put on the previous line.
â Jonathan Frech
7 hours ago
add a comment |Â
up vote
0
down vote
Python 2, 249 bytes
def f(s,Z='0'):
while 'y'in s:i=s.find('y');s=s[:i]+4*Z+Z*int(s[i+1],36)+s[i+2:]
t=s.replace('w',2*Z).replace('x',3*Z).split('z')
return map(''.join,zip(*[[(Z*5+bin(int(c,32))[2:])[-5:][::-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))
Try it online!
There is a superfluous space inwhile 'y'in
. I think the subscript[-5:][::-1]
can be golfed to[:-6:-1]
. The return statement can be put on the previous line.
â Jonathan Frech
7 hours ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Python 2, 249 bytes
def f(s,Z='0'):
while 'y'in s:i=s.find('y');s=s[:i]+4*Z+Z*int(s[i+1],36)+s[i+2:]
t=s.replace('w',2*Z).replace('x',3*Z).split('z')
return map(''.join,zip(*[[(Z*5+bin(int(c,32))[2:])[-5:][::-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))
Try it online!
Python 2, 249 bytes
def f(s,Z='0'):
while 'y'in s:i=s.find('y');s=s[:i]+4*Z+Z*int(s[i+1],36)+s[i+2:]
t=s.replace('w',2*Z).replace('x',3*Z).split('z')
return map(''.join,zip(*[[(Z*5+bin(int(c,32))[2:])[-5:][::-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))
Try it online!
answered 15 hours ago
Chas Brown
3,510216
3,510216
There is a superfluous space inwhile 'y'in
. I think the subscript[-5:][::-1]
can be golfed to[:-6:-1]
. The return statement can be put on the previous line.
â Jonathan Frech
7 hours ago
add a comment |Â
There is a superfluous space inwhile 'y'in
. I think the subscript[-5:][::-1]
can be golfed to[:-6:-1]
. The return statement can be put on the previous line.
â Jonathan Frech
7 hours ago
There is a superfluous space in
while 'y'in
. I think the subscript [-5:][::-1]
can be golfed to [:-6:-1]
. The return statement can be put on the previous line.â Jonathan Frech
7 hours ago
There is a superfluous space in
while 'y'in
. I think the subscript [-5:][::-1]
can be golfed to [:-6:-1]
. The return statement can be put on the previous line.â Jonathan Frech
7 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f169976%2fdecrypt-the-extended-wechsler-format%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Will
z
ever occur at the very beginning?â Mr. Xcoder
yesterday
@Mr.Xcoder The LifeWiki page does not say anything about that. But you can assume here that the string does not start or end with
z
.â alephalpha
yesterday
3
Not really a Game of Life pattern, but just for fun:
vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
â Arnauld
yesterday
"You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...?
â Jonathan Allan
20 hours ago
1
Two of the first three answers fail for some of these:
1yx1
,1yy1
,1yw1
and1yz1
. Maybe they should be tests.â Jonathan Allan
19 hours ago