0"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J"D34çýÇbεDg•Xó•18в@ƶà©i7j0ìëR6ôRíć7®-jšTìJ1®<×ì]ð0:J
05AB1E tidak memiliki bawaan konversi UTF-8, jadi saya harus melakukan semuanya secara manual ..
Cobalah secara online atau verifikasi bahwa itu quine .
Penjelasan:
Quine :
Quine terpendek untuk 05AB1E adalah ini: 0"D34çý"D34çý( 14 byte ) disediakan oleh @OliverNi . Jawaban saya menggunakan versi modifikasi dari Quine bahwa dengan menambahkan di ...sini: 0"D34çý..."D34çý.... Penjelasan singkat tentang quine ini:
0 # Push a 0 to the stack (can be any digit)
"D34çý" # Push the string "D34çý" to the stack
D # Duplicate this string
34ç # Push 34 converted to an ASCII character to the stack: '"'
ý # Join everything on the stack (the 0 and both strings) by '"'
# (output the result implicitly)
Bagian tantangan:
Sekarang untuk bagian tantangan dari kode. Seperti yang saya sebutkan di atas, 05AB1E tidak memiliki builtin konversi UTF-8, jadi saya harus melakukan hal-hal ini secara manual. Saya telah menggunakan sumber ini sebagai referensi tentang cara melakukan itu: Mengubah secara otomatis unicode codepoint menjadi UTF-8 dan UTF-16 . Berikut ringkasan singkat tentang konversi karakter Unicode ke UTF-8:
- Ubah karakter unicode menjadi nilai unicode mereka (yaitu
"dЖ丽"menjadi [100,1046,20029])
- Ubah nilai unicode ini menjadi biner (yaitu
[100,1046,20029]menjadi ["1100100","10000010110","100111000111101"])
- Periksa di mana dari rentang berikut karakternya adalah:
0x00000000 - 0x0000007F (0-127): 0xxxxxxx
0x00000080 - 0x000007FF (128-2047): 110xxxxx 10xxxxxx
0x00000800 - 0x0000FFFF (2048-65535): 1110xxxx 10xxxxxx 10xxxxxx
0x00010000 - 0x001FFFFF (65536-2097151): 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Ada juga rentang untuk 5 atau 6 byte, tetapi mari kita tinggalkan untuk saat ini.
Karakter dakan berada di kisaran pertama, jadi 1 byte di UTF-8; karakter Жberada di kisaran kedua, jadi 2 byte di UTF-8; dan karakter 丽berada di kisaran ketiga, jadi 3 byte di UTF-8.
The xdalam pola di balik itu diisi dengan biner dari karakter ini, dari kanan ke kiri. Jadi d( 1100100) dengan pola 0xxxxxxxmenjadi 01100100; yang Ж( 10000010110) dengan pola 110xxxxx 10xxxxxxmenjadi 11010000 10010110; dan 丽( 100111000111101) dengan pola 1110xxxx 10xxxxxx 10xxxxxxmenjadi 1110x100 10111000 10111101, setelah itu sisanya xdiganti dengan 0: 11100100 10111000 10111101.
Jadi, pendekatan itu saya juga gunakan dalam kode saya. Alih-alih memeriksa rentang sebenarnya, saya hanya melihat panjang biner dan membandingkannya dengan jumlah xdalam pola, karena itu menghemat beberapa byte.
Ç # Convert each character in the string to its unicode value
b # Convert each value to binary
ε # Map over these binary strings:
Dg # Duplicate the string, and get its length
•Xó• # Push compressed integer 8657
18в # Converted to Base-18 as list: [1,8,12,17]
@ # Check for each if the length is >= to this value
# (1 if truthy; 0 if falsey)
ƶ # Multiply each by their 1-based index
à # Pop and get its maximum
© # Store it in the register (without popping)
i # If it is exactly 1 (first range):
7j # Add leading spaces to the binary to make it of length 7
0ì # And prepend a "0"
ë # Else (any of the other ranges):
R # Reverse the binary
6ô # Split it into parts of size 6
Rí # Reverse it (and each individual part) back
ć # Pop, and push the remainder and the head separated to the stack
7®- # Calculate 7 minus the value from the register
j # Add leading spaces to the head binary to make it of that length
š # Add it at the start of the remainder-list again
Tì # Prepend "10" before each part
J # Join the list together
1®<× # Repeat "1" the value from the register - 1 amount of times
ì # Prepend that at the front
] # Close both the if-else statement and map
ð0: # Replace all spaces with "0"
J # And join all modified binary strings together
# (which is output implicitly - with trailing newline)
Lihat ini 05AB1E jawaban saya (bagian Cara kompres bilangan bulat besar? Dan Cara daftar bilangan bulat kompres? ) Untuk memahami mengapa •Xó•18вadalah [1,8,12,17].