Wolfram Language (Mathematica), (削除) 62 (削除ここまで) 59(削除) 59 (削除ここまで) 58 bytes
s(i=0;Pick[i,(1##&@@Partition[1-1)^+##&@@s~Partition~UpTo@i++2s,UpTo@i++],{1..}]&/@s)
Input a list of bits.
Mathematica's Listable functions only reduceevaluate when arguments are all scalars or lists of matching lengths. IfAs a result, if the block size does not evenly divide the total length, Plus remains unevaluated, and the resulting expression Plus[Times[...] does not evaluate further and cannot be matched by {1..}.
i=0; (-1)^+##&@@s~Partition~UpTo@i++ i++ &/@s possible checksumsfor sizes 0,...,len-1:
1##&@@Partition[1-2s,UpTo@i ] checksum by multiplying with 0,1 <-> 1,-1
Pick[i, ,{1..}] output length if valid
Wolfram Language (Mathematica), (削除) 62 (削除ここまで) 59 bytes
s(i=0;Pick[i,(-1)^+##&@@s~Partition~UpTo@i++,{1..}]&/@s)
Input a list of bits.
Mathematica's Listable functions only reduce when arguments are all scalars or lists of matching lengths. If the block size does not evenly divide the total length, Plus remains unevaluated, and the resulting expression Plus[...] cannot be matched by {1..}.
i=0; (-1)^+##&@@s~Partition~UpTo@i++ &/@s possible checksums, with 0,1 <-> 1,-1
Pick[i, ,{1..}] output length if valid
Wolfram Language (Mathematica), (削除) 62 (削除ここまで) (削除) 59 (削除ここまで) 58 bytes
s(i=0;Pick[i,1##&@@Partition[1-2s,UpTo@i++],{1..}]&/@s)
Input a list of bits.
Mathematica's Listable functions only evaluate when arguments are all scalars or lists of matching lengths. As a result, if the block size does not evenly divide the total length, Times[...] does not evaluate further and cannot be matched by {1..}.
i=0; i++ &/@s for sizes 0,...,len-1:
1##&@@Partition[1-2s,UpTo@i ] checksum by multiplying with 0,1 -> 1,-1
Pick[i, ,{1..}] output length if valid
Wolfram Language (Mathematica), 62(削除) 62 (削除ここまで) 59 bytes
sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@ss(i=0;Pick[i,2]~Cases~(-1)^+##&@@s~Partition~UpTo@i++,{1..}]&/@s)
Input a list of bits.
Xor gives the same result as the sum of its arguments mod 2, but Xor is not Listable, while Plus and Mod are.
Mathematica's Listable functions only reduce when all arguments are all scalars or lists of the same length or scalarsmatching lengths. Thus ifIf the block size does not evenly divide the total length, so Plus remains unevaluated. The, and the resulting expresionexpression Plus[...] cannot be matched by {1..}.
Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2] (* calculate bitwisei=0; complements of possible checksums of the input *)
% ~Cases~{(-1..} )^+##&@@s~Partition~UpTo@i++ &/@s (* find thosepossible whichchecksums, onlywith contain0,1 1s<-> *)1,-1
Tr/@ % Pick[i, ,{1..}] (* get the lengthoutput oflength each.if *)valid
Wolfram Language (Mathematica), 62 bytes
sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}
Input a list of bits.
Xor gives the same result as the sum of its arguments mod 2, but Xor is not Listable, while Plus and Mod are.
Mathematica's Listable functions only reduce when all arguments are lists of the same length or scalars. Thus if the block size does not evenly divide the total length, so Plus remains unevaluated. The resulting expresion Plus[...] cannot be matched by {1..}.
Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2] (* calculate bitwise complements of possible checksums of the input *)
% ~Cases~{1..} (* find those which only contain 1s *)
Tr/@ % (* get the length of each. *)
Wolfram Language (Mathematica), (削除) 62 (削除ここまで) 59 bytes
s(i=0;Pick[i,(-1)^+##&@@s~Partition~UpTo@i++,{1..}]&/@s)
Input a list of bits.
Mathematica's Listable functions only reduce when arguments are all scalars or lists of matching lengths. If the block size does not evenly divide the total length, Plus remains unevaluated, and the resulting expression Plus[...] cannot be matched by {1..}.
i=0; (-1)^+##&@@s~Partition~UpTo@i++ &/@s possible checksums, with 0,1 <-> 1,-1
Pick[i, ,{1..}] output length if valid
Wolfram Language (Mathematica), 62 bytes
sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}
Input a list of bits.
IfXor gives the partition sizesame result as the sum of its arguments mod 2, but Xor is not valid (doesListable, while Plus and Mod are.
Mathematica's Listable functions only reduce when all arguments are lists of the same length or scalars. Thus if the block size does not evenly divide the total length), the final list in the partition will be shorter, so Plus cannot thread over the lists, and remains unevaluated. The resulting expresion Plus[...] cannot be matched by {1..}.
Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2] (* calculate bitwise complements of possible checksums of the input *)
% ~Cases~{1..} (* find those which only contain 1s *)
Tr/@ % (* get the length of each. *)
Wolfram Language (Mathematica), 62 bytes
sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}
Input a list of bits.
If the partition size is not valid (does not divide the total length), the final list in the partition will be shorter, so Plus cannot thread over the lists, and remains unevaluated. The resulting expresion Plus[...] cannot be matched by {1..}.
Wolfram Language (Mathematica), 62 bytes
sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}
Input a list of bits.
Xor gives the same result as the sum of its arguments mod 2, but Xor is not Listable, while Plus and Mod are.
Mathematica's Listable functions only reduce when all arguments are lists of the same length or scalars. Thus if the block size does not evenly divide the total length, so Plus remains unevaluated. The resulting expresion Plus[...] cannot be matched by {1..}.
Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2] (* calculate bitwise complements of possible checksums of the input *)
% ~Cases~{1..} (* find those which only contain 1s *)
Tr/@ % (* get the length of each. *)