18
\$\begingroup\$

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.

  1. 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:

27deee6

$$ \begin{bmatrix} {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ 1 & 1 & {\color{Gray}0} & 1 & 1 & 1 & 1 \\ {\color{Gray}0} & 1 & 1 & 1 & 1 & 1 & 1 \\ {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & 1 & 1 & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \end{bmatrix} $$

  1. The character z separates contiguous five-row strips.

    For example, 0ca178b96z69d1d96 corresponds to a 31-bit still life:

enter image description here

enter image description here

$$ \begin{bmatrix} {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 \\ {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 \\ {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & 1 & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & 1 & 1 & 1 & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} \\ 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \end{bmatrix} $$

  1. The characters w and x are used to abbreviate 00 and 000, respectively.

    So w33z8kqrqk8zzzx33 corresponds to a trans-queen bee shuttle:

enter image description here

enter image description here

(10 blank rows omitted)

enter image description here

$$ \begin{bmatrix} {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} \\ 1 & {\color{Gray}0} & 1 & 1 & 1 & {\color{Gray}0} & 1 \\ {\color{Gray}0} & 1 & 1 & 1 & 1 & 1 & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \end{bmatrix} $$

  1. Finally, the symbols matching the regex y[0-9a-z] correspond to runs of between 4 and 39 consecutive 0s.

    A good example is 31a08zy0123cko, corresponding to a ship on quadpole:

enter image description here

enter image description here

$$ \begin{bmatrix} 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 & {\color{Gray}0} \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & {\color{Gray}0} & 1 \\ {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & {\color{Gray}0} & 1 & 1 \end{bmatrix} $$

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 , 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, 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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]]
\$\endgroup\$
  • \$\begingroup\$ Will z ever occur at the very beginning? \$\endgroup\$ – Mr. Xcoder Aug 4 '18 at 15:45
  • \$\begingroup\$ @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. \$\endgroup\$ – alephalpha Aug 4 '18 at 16:03
  • 3
    \$\begingroup\$ Not really a Game of Life pattern, but just for fun: vv99f60vv99f60uv11320uv19rqz33y133y11322310132231 \$\endgroup\$ – Arnauld Aug 4 '18 at 17:28
  • 1
    \$\begingroup\$ "You may return the transpose of the array" - if that's OK, what about other symmetries like upside-down etc...? \$\endgroup\$ – Jonathan Allan Aug 5 '18 at 13:38
  • 1
    \$\begingroup\$ Two of the first three answers fail for some of these: 1yx1, 1yy1, 1yw1 and 1yz1. Maybe they should be tests. \$\endgroup\$ – Jonathan Allan Aug 5 '18 at 14:20

10 Answers 10

2
\$\begingroup\$

Charcoal, 50 bytes

UB0≔⁺⭆χιββFS¿υ×0⁺⊟υ⌕βι≡ιz×⸿⁵y⊞υ⁴x×0³w¦00«P↓⮌⍘⌕βι²→

Try it online! Link is to verbose version of code. Uses 1 and 0. Explanation:

UB0

Set the background, i.e. any unprinted cells of the rectangle enclosing the output, to 0.

≔⁺⭆χιββ

Prefix the digits to the predefined lower case alphabet.

FS

Loop over the input string.

¿υ

If the predefined empty list is not empty...

×0⁺⊟υ⌕βι

... then print a number of 0s given by the sum of the number popped from the list and the index of the current character in the digits and letters. See below for what that number always is.

≡ι

Switch over the current character.

z×⸿⁵

If it's a z then output 5 carriage returns, taking us to the next output strip.

y⊞υ⁴

If it's a y, then push 4 to the predefined empty list, causing 4+n 0s to be output next time.

x×0³

If it's an x then output 3 0s. (This is done via repetition to avoid the literal 0 touching the x or the following literal.)

w¦00

If it's a w then output 2 0s. (The ¦ is needed to separate the two string literals.)

«P↓⮌⍘⌕βι²→

Otherwise, index the current character in the digits and letters, convert to binary, and print the result downwards least significant bit first; then move the cursor right for the next column.

\$\endgroup\$
6
\$\begingroup\$

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))
\$\endgroup\$
6
\$\begingroup\$

05AB1E, 148 132 98 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ð:žLRDUsð«#εNĀiDнXsk4+s¦sú]'W¾2×:'X¾3×:J'Z¶:.Bð¾:vNUyvDykDNX‚Š32VY‹iY+b¦RX_i¶ì}‚ˆ]¯{€¦˜J

Try it online!

Try it online!

Try it online!

Takes input as uppercase and outputs the transposed matrix as multiple output lines of 1s and 0s. May add extra zeros.

If you want to test with lowercase strings, add u in the TIO header.

If you want pretty-printed output, add '1'█:'0'.: in the TIO footer.

Explanation

(I'm calling "rows" and "columns" opposite of what you might expect because it generates the transposed matrix)

The basic algorithm is:

  1. Replace "yy" with 38 0s
  2. Split on "y" and and expand the 0-runs.
  3. Replace "w" and "x"
  4. 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)
  5. Split on z
  6. 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.
  7. The algorithm to get it into the output format is to
    1. Convert the characters to numbers by using indexOf in a lookup string
    2. Convert the characters to binary and then pad to length 5
    3. If it is the first column, add a linebreak before the binary number
    4. Add a prefix to the beginning of the binary string that stores the row and then the column of the character.
    5. Push the binary string with prefix to 05AB1E's "global array" register/variable
  8. 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.
  9. Remove the prefix string from each element of the global array
  10. 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

žLR                                             Pushes [0-9A-Za-z]
DU                                              Set X to [0-9A-Za-z] and leave [0-9A-Za-z] on the stack.
s                                               Swap top two elements. Now the stack is [0-9A-Za-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-Za-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.
        ú                                       Add that many spaces (will be replaced with zeros later) 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 "¶".
.B                                              "Squarify" command. Splits on \n and appends spaces to the end of each element so each is the same length. In this case, that is equivalent to adding zeros to the end of each column, which is what we want.
ð¾:                                             Replace spaces (which we used for padding above) with zeros.
"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              
        "1 Stack top = "?D,                     @SDEBUG
        "1 Stack top = "?D,                     @SDEBUG
        D                                       Duplicate top element (which is now [0-9A-Za-z])
        y                                       Push y (special loop variable)
        "Character = "?D,                       @DEBUG
        k                                       Push indexOf y in [0-9A-Za-z]
        "Index = "?D,                           @DEBUG
        "2.1 Stack top = "?D,                   @SDEBUG
        "2.1 Stack top-1 = "?sD,s               @SDEBUG
        D                                       Duplicate index.
        NX‚                                     Push [rowNumber,columnNumber]. This result is used for sorting.
        Š                                       Triple swap. The top of the stack is now sortPrefix, index, index
        32V                                     Set Y to 32
        Y‹i                                     index < 32. This uses up one copy of index
            Y+                                  Add 32 to the index
            b                                   Push the index in binary. This uses the second copy of index. 
            ¦                                   Remove the first character, which will be a 1 because we added 32. The result is now a padded binary string of length 5
            "Binary = "?D,                      @SDEBUG
            R                                   Reverse the binary string. This gives the proper transposed output. 
            X_i                                 This will only run if X (which is set to the column number) == 0. (Runs !X)
                ¶ì                              Stick a linebreak at the beginning of the binary string
            }
            "2.5 Stack top = "?D,               @SDEBUG
            "2.5 Stack top-1 = "?sD,s           @SDEBUG         
            ‚                                   At this point the top of the stack is sortPrefix,binaryString. This will combine the two into a list.
            "Pushing '"?D?"'",                  @DEBUG
            ˆ                                   Push [[rowNumber,columnNumber],binaryString] to global array
            "2.6 Stack top = "?D,               @SDEBUG
            "2.6 Stack top-1 = "?sD,s           @SDEBUG
        ]                                       Close all blocks
¯                                               Push global array

{                                               Sort global array. 
"Sorted Data = "?D,                             @DEBUG
€¦                                              Remove the sort prefix              
˜                                               Flatten. Before doing this, the array is in the format [[<binary string>],[<binary string>],[<binary string>],...]
J                                               Join with ""
'1'█:'0'.:                                      @DEBUG pretty print 
\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Frech Aug 6 '18 at 2:26
  • \$\begingroup\$ One small note: Most golfing languages implement implicit printing; I think you can ommit your last ,. \$\endgroup\$ – Jonathan Frech Aug 6 '18 at 2:30
  • \$\begingroup\$ 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. \$\endgroup\$ – kerwizzy Aug 6 '18 at 3:40
  • \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Allan Aug 6 '18 at 7:03
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Kevin Cruijssen Aug 6 '18 at 7:40
4
\$\begingroup\$

APL (Dyalog Unicode), 87 80 77 67 63 bytes

thanks to H.PWiz for saving 7 bytes and ngn for another 13 17.

a←⎕D,⎕A⋄,⍉↓⊖(5/2)⊤↑35(≠⊆⊢)a⍳'Y.|W|X'⎕R{'0'/⍨30 36|a⍳2↑⍵.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'/⍨+/30 36|a⍳2↑⍵.Match} replaces X W and Yx with the corresponding number of '0's (explained more below) 35(≠⊆⊢)a⍳ converts the string into vector of indecies in a and splits on 35 (i.e.) 'Z' creating a nested vector
converts the nested vector into a matrix padding ends with 0s
(5/2)⊤ converts each number into a binary vector resulting in a 3-dimensional matrix with binary vectors along the primary axis
reverses along the primary axis
reduces the rank of the matrix so it is 2-dimensional
,⍉ reshapes the result to the appropriate output

'Y.|W|X'⎕R{'0'/⍨30 36|a⍳2↑⍵.Match}
'Y.|W|X'⎕R                         ⍝ Regular expression replace. mathing the string.
                        2↑⍵.Match  ⍝ Takes matching string (either 'X' 'W' or 'Y.') and pads with spaces to length 2
                      a⍳           ⍝ Returns the indecies of each charactor in a. on the spaces this is 36 (length of a)
                30 36|             ⍝ Takes the remainders of the indecies when divided by 30 and 36 respectively. Overall 'W' -> 'W ' -> 32 36 -> 2 0, 'Y2' -> 'Y2' -> 34 2 -> 4 2.
           '0'/⍨                   ⍝ Make vector of repeating '0's with length equal to the sum of the result. '0'/⍨4 2 ≡ '000000'
\$\endgroup\$
  • \$\begingroup\$ 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 \$\endgroup\$ – H.PWiz Aug 5 '18 at 21:58
  • \$\begingroup\$ Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces. \$\endgroup\$ – jslip Aug 5 '18 at 22:15
  • \$\begingroup\$ @jslip the parentheses around ⎕R and its operands are unnecessary \$\endgroup\$ – ngn Aug 9 '18 at 15:16
  • \$\begingroup\$ 2+'WX'⍳⍵ -> 2+'X'=⍵ \$\endgroup\$ – ngn Aug 9 '18 at 15:38
  • \$\begingroup\$ {0::2+'X'=⍵⋄4+a⍳1⊃⍵}⍵.Match -> 30 36|a⍳2↑⍵.Match \$\endgroup\$ – ngn Aug 9 '18 at 15:58
3
\$\begingroup\$

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(.)/000{0 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 :—).)

\$\endgroup\$
  • \$\begingroup\$ 142 bytes \$\endgroup\$ – Jo King Aug 5 '18 at 1:50
  • \$\begingroup\$ @JoKing — Oh yes, thank you very much! \$\endgroup\$ – Ramillies Aug 5 '18 at 8:07
  • \$\begingroup\$ Fails for 1yx1 and 1yw1 \$\endgroup\$ – Jonathan Allan Aug 5 '18 at 14:16
  • \$\begingroup\$ @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.) \$\endgroup\$ – Ramillies Aug 5 '18 at 14:23
  • \$\begingroup\$ You can replace the 000 in the y substitution with x \$\endgroup\$ – Jo King Aug 6 '18 at 1:11
2
\$\begingroup\$

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).

\$\endgroup\$
2
\$\begingroup\$

Retina, 203 bytes

y(.)
#$1
{`#
0#
#0
000
)T`dl`_dl`#.
w
000
x
00
z
¶
%(`.+
$&¶$&¶$&¶$&¶$&
T`g-v`#`.+$
T`dl` `.+$
T`g-v`dl
T`89l`#`.+¶.+$
T`d` `.+¶.+$
T`89l`d
T`d`    #`.+¶.+¶.+$
T`4-7`d
T`d`  #`.+¶.+¶.+¶.+$
)T`d` # #
P`.+

Try it online! Link includes test cases. Alternative solution, also 203 bytes:

y(.)
#$1
{`#
0#
#0
000
)T`dl`_dl`#.
w
000
x
00
z
¶
%(`.+
$&¶$&
T`g-v`#`¶.+
T`dl` `¶.+
T`g-v`dl
^.+
$&¶$&
T`89l`#`¶.+
T`d` `¶.+
T`89l`d
^.+
$&¶$&
T`d`    #`¶.+
T`4-7`d
^.+
$&¶$&
T`d`  #`¶.+
)T`d` # #
P`.+

Try it online! Link includes test cases. Explanation:

y(.)
#$1

First handle the awkward case of the y command. Sadly the letter after this is allowed to be a y or even a z, so we have to be careful here. All the magic ys are first turned into #s.

{`#
0#
#0
000
)T`dl`_dl`#.

A loop then processes the #s. First, a 0 is prepended to the #. If this is a #0 then that is changed to 000 which completes the operation, otherwise the character after the # is decremented and the loop repeats until all of the #s have been processed.

w
000
x
00

Fix up the ws and xs.

z
¶

Split on new lines. (S`z also works for the same byte count.)

%(`.+
$&¶$&¶$&¶$&¶$&
T`g-v`#`.+$
T`dl` `.+$
T`g-v`dl
T`89l`#`.+¶.+$
T`d` `.+¶.+$
T`89l`d
T`d`    #`.+¶.+¶.+$
T`4-7`d
T`d`  #`.+¶.+¶.+¶.+$
)T`d` # #

Make 5 copies of each line, then perform binary conversion by mapping letters with the appropriate bit to # and clearing that bit, while other letters become spaces. The bits are processed in the order 16, 8, 4, 2, and then the last translation handles clearing the 2 bit and converting the 1 bit at the same time. (The alternative version makes each copy individually which costs more bytes but these are saved because the bit handling is simplified.)

P`.+

Pad all the lines to the same length.

\$\endgroup\$
1
\$\begingroup\$

Python 2, 249 244 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:])[:-6:-1]for c in r]+[Z*5]*(max(map(len,t))-len(r))for r in t]))

Try it online!

5 bytes saved by Jonathan Frech.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Frech Aug 6 '18 at 2:38
1
\$\begingroup\$

JavaScript (ES8), 192 bytes

s=>[...s,"z"].map(c=>{h=parseInt(c,36);k="wxy".search(c)+1;y?k=h-y--:h-35?y=h>33:m=m.map(P,z+=5,i=k--);for(h=k?0:h;~k--;m[i]=h.toString(2)+P(m[i++]||""));},P=d=>d.padStart(z,0),m=[i=z=y=0])&&m

Returns the transpose... which is then reflected across the vertical axis; let me know if that invalidates this entry. Output is an array of strings containing 0s and 1s.

Try it online!

Explanation

For each character c, k+1 evaluates to the number of rows to modify. k = "wxy".search(c) + 1;, where the search method returns the index or -1. k is then decremented until it reaches -1 by checking ~k-- for a truthy value.

If the current character is "y", set a flag so that the base-36 value of the next character - 1 becomes the value for k.

Upon encountering a "z", pad strings to the left, increment the pad amount by 5, and reset the array index to 0.

s =>
    [...s, "z"].map(c => {                  // append a "z" to ensure final output is properly padded
        h = parseInt(c, 36);
        k = "wxy".search(c) + 1;            // note that "y" -> 4 zeroes
        y                                   // if previous char is "y"...
            ? k = h - y--                   //      decrement y after subtracting y=1 since k is decremented to -1 and the previous y already pushed 4 zeroes
        : h - 35                            // else if current char is not "z"...
            ? y = h > 33                    //      set y if current char = "y"
        : m = m.map(P, z += 5, i = k--);    // else if current char is "z", pad
        for (
            h = k ? 0 : h;                  // if k is truthy, push zeroes
            ~k--;
            m[i] = h.toString(2)            // convert to boolean representation
                + P(m[i++] || "")           // prepend to row or to a newly padded row
        );
    },
        P = d => d.padStart(z, 0),
        m = [i = z = y = 0]                 // the logical OR 4 lines above replaces this value with ""
    ) &&
    m
\$\endgroup\$
  • \$\begingroup\$ I think it would make more sense not to return the transpose of the input. \$\endgroup\$ – mbomb007 Aug 9 '18 at 16:05
1
\$\begingroup\$

Haskell, 399 bytes

Install split package: cabal install split

import Data.Char
import Data.List.Split
import Data.List
p=map
r=replicate
a c|47<c&&c<58=c-48|96<c&&c<123=c-87
o=a.ord
m l n|l==0=[]|True=(mod n 2):m(l-1)(div n 2)
t a=p(\l->l++r((maximum$p length a)-length l)'0')a
y s|length s==0=""|h=='y'=(r(4+(o$s!!1))'0')++y(drop 2 s)|h=='w'="00"++y t|h=='x'="000"++y t|True=h:y t where h=head s;t=tail s
w=(p concat).transpose.(p$p$(m 5).o).t.(splitOn "z").y
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.