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 hat keine integrierten UTF-8-Konvertierungsfunktionen, daher muss ich alles manuell ausführen .
Probieren Sie es online aus oder stellen Sie sicher, dass es sich um eine Quine handelt .
Erläuterung:
Quine-Teil :
Das kürzeste Quine für 05AB1E ist dieses: 0"D34çý"D34çý( 14 Bytes ) bereitgestellt von @OliverNi . Meine Antwort verwendet eine modifizierte Version dieses Quines, indem ich ...hier Folgendes hinzufüge : 0"D34çý..."D34çý.... Eine kurze Erklärung dieser 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)
Herausforderungsteil:
Nun zum Herausforderungsteil des Codes. Wie oben erwähnt, verfügt 05AB1E über keine integrierten UTF-8-Konvertierungsfunktionen, daher muss ich diese Dinge manuell ausführen. Ich habe diese Quelle als Referenz verwendet, um dies zu tun: Manuelles Konvertieren von Unicode-Codepunkten in UTF-8 und UTF-16 . Hier eine kurze Zusammenfassung der Konvertierung von Unicode-Zeichen in UTF-8:
- Konvertieren Sie die Unicode-Zeichen in ihre Unicode-Werte (dh
"dЖ丽"wird [100,1046,20029])
- Konvertieren Sie diese Unicode-Werte in Binärwerte (dh
[100,1046,20029]wird ["1100100","10000010110","100111000111101"])
- Überprüfen Sie, in welchem der folgenden Bereiche die Zeichen sind:
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
Es gibt auch Bereiche für 5 oder 6 Bytes, aber lassen wir sie vorerst weg.
Das Zeichen dbefindet sich im ersten Bereich, also 1 Byte in UTF-8; Zeichen Жliegt im zweiten Bereich, also 2 Bytes in UTF-8; und Zeichen 丽liegt im dritten Bereich, also 3 Bytes in UTF-8.
Die xim Muster dahinter sind mit der Binärdatei dieser Zeichen von rechts nach links gefüllt. So ist die d( 1100100) mit Muster 0xxxxxxxwird 01100100; das Ж( 10000010110) mit Muster 110xxxxx 10xxxxxxwird 11010000 10010110; und das 丽( 100111000111101) mit Muster 1110xxxx 10xxxxxx 10xxxxxxwird 1110x100 10111000 10111101, wonach die verbleibenden xersetzt werden durch 0: 11100100 10111000 10111101.
Also, diesen Ansatz habe ich auch in meinem Code verwendet. Anstatt die tatsächlichen Bereiche zu überprüfen, schaue ich mir nur die Länge der Binärdatei an und vergleiche sie mit der Menge xin den Mustern, da dies einige Bytes spart.
Ç # 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)
Sehen Sie diese 05AB1E Antwort von mir (Abschnitte Wie große natürliche Zahlen zu komprimieren? Und Wie zu komprimieren integer Listen? ) Zu verstehen , warum •Xó•18вist [1,8,12,17].