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没有内置的UTF-8转换,因此我必须手动完成所有操作。
在线尝试或验证它是奎奴亚藜。
说明:
quine -part:
05AB1E 的最短quine是这个:0"D34çý"D34çý
(14个字节)由@OliverNi提供。我的答案通过在...
此处添加来使用该quine的修改版本0"D34çý..."D34çý...
。对这个方法的简短解释:
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)
挑战部分:
现在是代码的挑战部分。如我在顶部所述,05AB1E没有内置的UTF-8转换,因此我必须手动执行这些操作。我已将此源用作如何执行此操作的参考:手动将Unicode代码点转换为UTF-8和UTF-16。以下是有关将Unicode字符转换为UTF-8的简短摘要:
- 将unicode字符转换为其unicode值(即
"dЖ丽"
成为[100,1046,20029]
)
- 将这些unicode值转换为二进制(即
[100,1046,20029]
成为["1100100","10000010110","100111000111101"]
)
- 检查字符在以下哪个范围内:
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
也有5或6个字节的范围,但让我们暂时忽略它们。
字符d
将在第一个范围内,因此UTF-8中为1个字节;字符Ж
在第二个范围内,因此UTF-8中为2个字节;并且字符丽
在第三个范围内,因此UTF-8中为3个字节。
将x
在模式背后都充满了这些字符的二进制,从右到左。因此带有模式的d
(1100100
)0xxxxxxx
变为01100100
; 具有模式的Ж
(10000010110
)110xxxxx 10xxxxxx
变为11010000 10010110
; 并且带有模式的丽
(100111000111101
)1110xxxx 10xxxxxx 10xxxxxx
变为1110x100 10111000 10111101
,之后将其余x
的替换为0
:11100100 10111000 10111101
。
因此,我在代码中也使用了这种方法。我只查看二进制文件的长度,然后将其x
与模式中的数量进行比较,而不是检查实际范围,因为这样可以节省一些字节。
Ç # 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)
看到这个05AB1E回答我的(部分如何压缩大的整数?以及如何压缩整数列表?)理解为什么•Xó•18в
是[1,8,12,17]
。