八度,53 52字节
进行完整的重写有助于我将代码打成5字节,但是我不得不添加更多无操作,从而使其净节省只有1个字节。
@(_)~diff(sum(de2bi(+_)))%RRPPPVVVW?????????________
我无法添加TIO链接,因为没有一个在线解释器实现了所需的通信工具箱de2bi
。更改为dec2bin
相反,将将花费4个字节(工作代码为2个字节,两个无操作)。
我发现没有办法避免27次无操作中的任何一个。所有函数名称和括号都在64以下或96之间,这意味着所有“必需”字符在第6个位置(从右侧2 ^ 5)都具有1。我只有23个无操作的解决方案,但是代码本身更长。实际代码为25个字节,并且在计算二进制等价位数时具有以下列总和:
15 22 6 15 10 9 13
右边(2 ^ 5)的第6位只有22位,右边(2 ^ 3)的第4位只有6位。这意味着,我们必须至少添加16个字节,才能使6个字节最多达到22个字节。现在,注释字符%
在第6个位置添加一个位,将其增加到23个。所有可打印的ASCII字符至少需要两个字节之一最高位1
。因此,添加17个字节将使我们在两个“顶部”(2 ^ 6和2 ^ 5)中的每个位置至少具有27位。现在,我们在前两个位置有27位,在其余两个位置有22位。为了达到平衡,我们必须添加10个字节,以使每个位置的偶数位达到32位。
新代码的说明(52个字节):
@(_)~diff(sum(de2bi(+_)))
@(_) % An anonymous function that take a variable _ as input
% We use underscore, instead of a character, since it has the
% most suitable binary represetation
de2bi(+_) % Convert the input string to a binary matrix
sum(de2bi(+_)) % Take the sum of each column
diff(sum(de2bi(+_))) % And calculate the difference between each sum
~diff(sum(de2bi(+_))) % Negate the result, meaning 0 becomes true,
% and everything else becomes false
在Octave中,将仅包含1(真)的向量评估为true,在Octave中,将将至少包含0的向量评估为false。
旧代码的解释(53字节):
@(_)!((_=sum(de2bi(+_)))-_(1))%RRRFVVVVVVVVV_____????
@(_) % An anonymous function that take a variable _ as input
% We use underscore, instead of a character, since it has the
% most suitable binary represetation
! % Negate the result, meaning 0 becomes true, and everything else becomes false
de2bi(+_) % Convert the input string to a binary matrix
sum(de2bi(+_)) % Take the sum of each column
(_=sum(de2bi(+_))) % Assign the result to a new variable, also called _
% It's not a problem that we use the same variable name, due
% to the order of evaluation
((_=sum(de2bi(+_)))-_(1)) % Subtract the first element of the new variable _
% If all elements of the new variable _ are identical, then this
% should give us a vector containing only zeros,
% otherwise, at least one element should be non-zero
!((_=sum(de2bi(+_)))-_(1)) % And finally, we negate this.
在Octave中,将仅包含1(真)的向量评估为true,在Octave中,将将至少包含0 的向量评估为false。