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 não possui built-in de conversão UTF-8, por isso tenho que fazer tudo manualmente .
Experimente on-line ou verifique se é um problema .
Explicação:
quine -part:
O quine mais curto para 05AB1E é este: 0"D34çý"D34çý( 14 bytes ) fornecido por @OliverNi . Minha resposta utiliza uma versão modificada do que Quine, adicionando ao ...aqui: 0"D34çý..."D34çý.... Uma breve explicação sobre esse quine:
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)
Parte do desafio:
Agora, para a parte do desafio do código. Como mencionei na parte superior, o 05AB1E não possui built-in de conversão UTF-8, por isso tenho que fazer essas coisas manualmente. Eu usei esta fonte como referência sobre como fazer isso: Converter manualmente pontos de código unicode em UTF-8 e UTF-16 . Aqui está um breve resumo sobre a conversão de caracteres Unicode em UTF-8:
- Converta os caracteres unicode em seus valores unicode (ou seja,
"dЖ丽"torna-se [100,1046,20029])
- Converta esses valores unicode em binários (ou seja,
[100,1046,20029]torna-se ["1100100","10000010110","100111000111101"])
- Verifique em qual dos seguintes intervalos os caracteres são:
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
Também existem intervalos para 5 ou 6 bytes, mas vamos deixá-los de fora por enquanto.
O personagem destará no primeiro intervalo, portanto, 1 byte em UTF-8; caractere Жestá no segundo intervalo, portanto, 2 bytes em UTF-8; e caractere 丽está no terceiro intervalo, portanto, 3 bytes em UTF-8.
O xpadrão por trás dele é preenchido com o binário desses caracteres, da direita para a esquerda. Então o d( 1100100) com padrão 0xxxxxxxse torna 01100100; o Ж( 10000010110) com padrão 110xxxxx 10xxxxxxse torna 11010000 10010110; e o 丽( 100111000111101) com o padrão 1110xxxx 10xxxxxx 10xxxxxxse torna 1110x100 10111000 10111101, após o que os restantes xsão substituídas por 0: 11100100 10111000 10111101.
Então, essa abordagem também usei no meu código. Em vez de verificar os intervalos reais, basta olhar para o comprimento do binário e compará-lo com a quantidade de xpadrões no entanto, pois isso economiza alguns bytes.
Ç # 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)
Veja este 05AB1E resposta meu (seções Como comprimir grandes inteiros? E Como listas inteiras compressa? ) Para entender por que •Xó•18вé [1,8,12,17].