विस्तारित वीचस्लर प्रारूप को डिक्रिप्ट करें


18

यह चुनौती user48538 द्वारा सैंडबॉक्स पोस्ट पर आधारित है । चूंकि वह अब इस साइट पर सक्रिय नहीं है, इसलिए मैंने यह चुनौती ली।


apgsearch , और जीवन के कोनवे के खेल के लिए वितरित सूप खोज कार्यक्रम खोज परिणामों डेटाबेस, Catagolue उपयोग apgcodes वर्गीकृत AND दर्शा पैटर्न के लिए। एप्गकोड्स स्वयं विस्तारित वीचस्लर प्रारूप का उपयोग करते हैं , 1992 में एलन वेक्स्लर द्वारा विकसित एक पैटर्न नोटेशन का विस्तार।

निम्न उदाहरण और चित्र LifeWiki से लिए गए हैं

  1. रेगेक्स से मेल खाने वाले सेट में n वर्णों की एक स्ट्रिंग [0-9a-v]पांच पंक्तियों की एक पट्टी को दर्शाती है, जो n चौड़े हैं। प्रत्येक चरित्र bitstrings करने के लिए इसी एक ऊर्ध्वाधर कॉलम में पाँच कोशिकाओं को दर्शाता है [ 00000, 10000, 01000... 00010, 10010, 01010, 11010... 11111]।

    उदाहरण के लिए, हैवीवेट स्पेसशिप से27deee6 मेल खाती है :

27deee6

[01100001101111011111100111100000000]
  1. चरित्र zसन्निहित पांच-पंक्ति स्ट्रिप्स को अलग करता है।

    उदाहरण के लिए, 0ca178b96z69d1d9631-बिट स्टिल लाइफ से मेल खाता है:

यहाँ छवि विवरण दर्ज करें

यहाँ छवि विवरण दर्ज करें

[000110110001010101010010001011001110000000000011111000100000100101010100011011000000000000]
  1. अक्षर wऔर क्रमशः xसंक्षिप्त 00और उपयोग किए जाते 000हैं।

    तो w33z8kqrqk8zzzx33एक ट्रांस-रानी मधुमक्खी शटल से मेल खाती है :

यहाँ छवि विवरण दर्ज करें

यहाँ छवि विवरण दर्ज करें

(10 खाली पंक्तियां छोड़ी गईं)

यहाँ छवि विवरण दर्ज करें

[0011000001100000000000000000000000000010000011100010001010111010111110000000000000000000000000000000000000000000000000000000000000000000000000011000001100000000000000000000000]
  1. अंत में, रेगेक्स से y[0-9a-z]मेल खाने वाले प्रतीक 4 और 39 के बीच लगातार चलते हैं 0

    एक अच्छा उदाहरण क्वाडपोल पर31a08zy0123cko एक जहाज के लिए है :

यहाँ छवि विवरण दर्ज करें

यहाँ छवि विवरण दर्ज करें

[1100000000101000000000000000000010100000000000000000001010000000011000000000011000000001010000000011]

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, 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]]
y3343x6bacy6cab6x343zkk8yy8kkzgo8gywg8ogz0123yw321zzgo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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, 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]]

Will z ever occur at the very beginning?
Mr. Xcoder

@ Mr.Xcoder LifeWiki पेज उस बारे में कुछ नहीं कहता है। लेकिन आप यहां मान सकते हैं कि स्ट्रिंग शुरू या समाप्त नहीं होती है z
alephalpha

3
Not really a Game of Life pattern, but just for fun: vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
Arnauld

1
"आप सरणी के हस्तांतरण को वापस कर सकते हैं" - यदि यह ठीक है, तो अन्य समरूपता जैसे उल्टा-पुल्टा आदि के बारे में क्या ...?
जोनाथन एलन

1
Two of the first three answers fail for some of these: 1yx1, 1yy1, 1yw1 and 1yz1. Maybe they should be tests.
जोनाथन एलन

जवाबों:


2

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.


6

जावास्क्रिप्ट (ईएस 8), 197 बाइट्स

एक स्ट्रिंग के रूप में इनपुट लेता है। '#' और रिक्त स्थान के साथ स्ट्रिंग की एक सरणी देता है। आउटपुट में प्रत्येक पंक्ति पर अतिरिक्त (लेकिन सुसंगत) स्थान शामिल हो सकते हैं।

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

इसे ऑनलाइन आज़माएं! (पहले से तैयार आउटपुट)

कैसे?

सार्वत्रिक चर

  • चरित्र "x"का उपयोग कई बार किया जाता है, इसलिए इसे चर x में संग्रहीत करने के लायक है ।
  • फ़ंक्शन parseIntका उपयोग दो बार किया जाता है, इसलिए इसे चर P में संग्रहीत करने के लायक है ।
  • y पंक्ति सूचकांक है, जिसे 0 से आरंभ किया गया है ।
  • w अंतिम आउटपुट को पैड करने के लिए उपयोग की जाने वाली चौड़ाई के ऊपरी बाउंड का ट्रैक रखता है।
  • ओ [] आउटपुट सरणी है, शुरू में खाली।

दोहराया शून्य के पूर्व प्रसंस्करण

हम पहले सभी पैटर्न को बदलते हैं "w", "x"और "yX"इनपुट स्ट्रिंग में उचित संख्या में रिक्त स्थान होते हैं। इन स्थानों की बाद में व्याख्या की जाएगी "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
  )
)

डिकोडिंग

हम परिणामी स्ट्रिंग को विभाजित करते हैं, प्रत्येक वर्ण पर एक प्रारंभिक "x"और पुनरावृति 5 बार ( i = 0 से 4 के साथ ) prepend करते हैं c :

  • यदि c से कम है "x", तो हम अगले 5 पंक्तियों के अनुरूप पैटर्न को जोड़ते हैं।

    o[y + i - 5] += ' #'[P(c, 36) >> i & 1]
  • यदि c से अधिक या इसके बराबर है "x", तो हम o [] में 5 नए खाली तार आवंटित करते हैं और 5 से y जोड़ते हैं । यह आरंभिक द्वारा ट्रिगर किया "x"गया है जो स्ट्रिंग की शुरुआत में, या "z"मूल सामग्री में किसी भी द्वारा जोड़ा गया था ।

    o = [...++y && o, '']

गद्दी

अंत में, हम पैड में प्रत्येक स्ट्रिंग ओ [] रिक्तियों के साथ इतना है कि वे सभी डब्ल्यू अक्षर।

o.map(r => r.padEnd(w))

6

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 

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.
जोनाथन फ्रीच

One small note: Most golfing languages implement implicit printing; I think you can ommit your last ,.
Jonathan Frech

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

शुरू करने के लिए सबसे आसान चुनौती नहीं! अच्छा काम है, मुझे लगता है कि जब वे आते हैं तो कुछ 05AB1E स्टालवार्ट कुछ आसान संकेत देंगे।
जोनाथन एलन

1
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

4

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|a2↑⍵.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|a2↑⍵.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'

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

Thanks @H.PWiz. Yeah I don't like the error catch either but otherwise I was using two regex replaces.
जसलिप

@js को कोष्ठक के चारों ओर ⎕Rऔर उसके ऑपरेंड अनावश्यक हैं
nn

2+'WX'⍳⍵ -> 2+'X'=⍵
ngn

{0::2+'X'=⍵⋄4+a⍳1⊃⍵}⍵.Match -> 30 36|a⍳2↑⍵.Match
ngn

3

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



@JoKing — Oh yes, thank you very much!
Ramillies

Fails for 1yx1 and 1yw1
Jonathan Allan

@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

You can replace the 000 in the y substitution with x
Jo King

2

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


2

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.


1

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.


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

1

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

I think it would make more sense not to return the transpose of the input.
mbomb007

1

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
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.