Tantangan ini didasarkan pada pos kotak pasir oleh user48538 . Karena dia tidak lagi aktif di situs ini, saya mengambil alih tantangan ini.
apgsearch , program pencarian sup yang didistribusikan untuk Conway's Game of Life dan database hasil pencarian, Catagolue menggunakan apgcodes untuk mengklasifikasikan dan menunjukkan pola. apgcodes sendiri menggunakan format Wechsler yang diperluas , perpanjangan dari notasi pola yang dikembangkan oleh Allan Wechsler pada tahun 1992.
Contoh berikut dan gambar diambil dari LifeWiki .
String n karakter dalam set yang cocok dengan regex
[0-9a-v]
menunjukkan strip dengan lima baris, lebar n kolom. Setiap karakter menunjukkan lima sel dalam kolom vertikal sesuai dengan bitstrings [00000
,10000
,01000
...00010
,10010
,01010
,11010
...11111
].Misalnya,
27deee6
berkorespondensi dengan pesawat ruang angkasa kelas berat :
Karakter
z
memisahkan strip lima baris yang berdekatan.Misalnya,
0ca178b96z69d1d96
berkorespondensi dengan still life 31-bit:
Karakter
w
danx
digunakan untuk menyingkat00
dan000
, masing-masing.Jadi
w33z8kqrqk8zzzx33
sesuai dengan antar-jemput lebah ratu :
(10 baris kosong dihilangkan)
Akhirnya, simbol-simbol yang cocok dengan regex
y[0-9a-z]
berhubungan dengan berjalan antara 4 dan 39 berturut-turut0
.Contoh yang baik adalah
31a08zy0123cko
, terkait dengan kapal di quadpole :
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, 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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]]
sumber
z
ever occur at the very beginning?z
.vv99f60vv99f60uv11320uv19rqz33y133y11322310132231
1yx1
,1yy1
,1yw1
and1yz1
. Maybe they should be tests.Jawaban:
Charcoal, 50 bytes
Try it online! Link is to verbose version of code. Uses
1
and0
. Explanation: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.
Loop over the input string.
If the predefined empty list is not empty...
... then print a number of
0
s 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.
If it's a
z
then output 5 carriage returns, taking us to the next output strip.If it's a
y
, then push4
to the predefined empty list, causing4+n
0
s to be output next time.If it's an
x
then output 30
s. (This is done via repetition to avoid the literal0
touching thex
or the following literal.)If it's a
w
then output 20
s. (The¦
is needed to separate the two string literals.)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.
sumber
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.
Try it online! (prettified output)
How?
Global variables
"x"
is used several times, so it's worth storing it into the variable x.parseInt
is used twice, so it's worth storing it into the variable P.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"
.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.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.Padding
Finally, we pad each string in o[ ] with spaces so that they all have w characters.
sumber
05AB1E,
14813298 bytesI'm a highschool student and this was my first time for both golfing and using 05AB1E, so comments are appreciated!
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:
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.
sumber
,
."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.APL (Dyalog Unicode),
8780776763 bytesthanks to H.PWiz for saving 7 bytes and ngn for another
1317.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 ina
and splits on35
(i.e.)'Z'
creating a nested vector↑
converts the nested vector into a matrix padding ends with0
s(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 outputsumber
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⎕R
and its operands are unnecessary2+'WX'⍳⍵
->2+'X'=⍵
{0::2+'X'=⍵⋄4+a⍳1⊃⍵}⍵.Match
->30 36|a⍳2↑⍵.Match
Perl 6,
156142 bytes14 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]
.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 they
, because in the case ofyx
oryw
, thew
(orx
) does not constitute a shorthand by itself. We search fory(.)
(y
and one character, which it remembers) and replace it by000{"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 thew
's usings:g/w/00/
, and thex
's usings:g/x/000/
. Finally, withs/$/z/
, we add az
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 atz
, with each line being first padded with0 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.)Sekarang, kita hanya memetakan di atas baris (kolom dari matriks asli) dan mengganti setiap karakter yang ditemui dengan 5 bit yang sesuai. Itu dilakukan menggunakan
:32($_)
(basis 32 ke basis 10).fmt("%05b")
(format sebagai bitstring lebar 5, diisi dengan nol).flip
(membalikkan string, karena LSB berada di baris atas, bukan bagian bawah).comb
(pisahkan string ke daftar karakter). Kami telah menggunakan.flatmap
, yang meratakan daftar hasil (jika tidak kami akan mendapatkan daftar daftar di setiap kolom). Transpos hasilnya kemudian secara implisit dikembalikan.(Aku merasa agak buruk karena menyalahgunakan kemungkinan membuntuti nol begitu keras. Tapi itu mengurangi jumlah yang cukup besar :—).)
sumber
1yx1
and1yw1
y[0-9a-v]
and when I found that it's not the case, I just added a quick (and wrong) fix.)000
substitusi dalam y denganx
Jelly , 66 byte
Yowza!
Tautan monadik yang menghasilkan versi yang dialihkan sebagai daftar daftar (tambahkan
Z
pada bagian akhir untuk ditransposisikan kembali).Cobalah online! Atau lihat test-suite (dengan hasil cetak yang cantik).
sumber
Retina , 203 byte
Cobalah online! Tautan termasuk kasus uji. Solusi alternatif, juga 203 byte:
Cobalah online! Tautan termasuk kasus uji. Penjelasan:
Pertama-tama tangani kasus canggung dari
y
perintah. Sayangnya surat setelah ini diizinkan menjadiy
atau bahkan az
, jadi kita harus berhati-hati di sini. Semua sihiry
pertama kali diubah menjadi#
.Sebuah loop kemudian memproses
#
s. Pertama, a0
didahulukan dengan#
. Jika ini adalah#0
maka yang diubah untuk000
menyelesaikan operasi, jika tidak karakter setelah#
dikurangi dan loop berulang sampai semua#
s telah diproses.Perbaiki
w
s danx
s.Berpisah di baris baru. (
S`z
juga berfungsi untuk jumlah byte yang sama.)Buat 5 salinan dari setiap baris, lalu lakukan konversi biner dengan memetakan huruf dengan bit yang sesuai untuk
#
dan menghapus bit itu, sementara huruf lain menjadi spasi. Bit diproses dalam urutan 16, 8, 4, 2, dan kemudian terjemahan terakhir menangani membersihkan2
bit dan mengonversi1
bit pada saat yang sama. (Versi alternatif membuat setiap salinan secara individual yang biaya byte lebih banyak tetapi ini disimpan karena penanganan bit disederhanakan.)Pad semua garis dengan panjang yang sama.
sumber
Python 2 ,
249244 byteCobalah online!
5 byte disimpan oleh Jonathan Frech .
sumber
while 'y'in
. Saya pikir subskrip[-5:][::-1]
dapat di-golf-kan[:-6:-1]
. Pernyataan pengembalian dapat diletakkan di baris sebelumnya.JavaScript (ES8), 192 byte
Mengembalikan transpos ... yang kemudian direfleksikan melintasi sumbu vertikal; beri tahu saya jika itu membatalkan entri ini. Output adalah larik string yang mengandung
0
s dan1
s.Cobalah online!
Penjelasan
Untuk setiap karakter
c
,k+1
evaluasi terhadap jumlah baris yang akan dimodifikasi.k = "wxy".search(c) + 1;
, di manasearch
metode mengembalikan indeks atau-1
.k
kemudian dikurangi hingga mencapai-1
dengan memeriksa~k--
nilai kebenaran.Jika karakter saat ini adalah "y", atur tanda sehingga nilai base-36 dari karakter berikutnya - 1 menjadi nilai untuk
k
.Setelah menemukan "z", pad string ke kiri, menambah jumlah pad dengan
5
, dan reset indeks array ke0
.sumber
Haskell, 399 byte
Instal
split
paket:cabal install split
sumber