Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 61 characters in body
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70

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)

Try it online! Try it online!

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)

Try it online!

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)

Try it online!

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
deleted 168 characters in body
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70

Wolfram Language (Mathematica), 62(削除) 62 (削除ここまで) 59 bytes

sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@ss(i=0;Pick[i,2]~Cases~(-1)^+##&@@s~Partition~UpTo@i++,{1..}]&/@s)

Try it online! Try it online!

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

sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}

Try it online!

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)

Try it online!

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
added 253 characters in body
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70

Wolfram Language (Mathematica), 62 bytes

sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}

Try it online!

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

sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}

Try it online!

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

sTr/@Mod[i=0;1+##&@@s~Partition~UpTo@i++&/@s,2]~Cases~{1..}

Try it online!

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. *)
added 253 characters in body
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70
Loading
Source Link
att
  • 22.8k
  • 2
  • 19
  • 70
Loading

AltStyle によって変換されたページ (->オリジナル) /