Scroll to see replies
Block[{a = 4, b = 1, c = 2}, Length /@
Select[Split[
IntegerDigits[BitXor[2^a - 1, (2^c - 1) 2^b], 2] // Reverse],
First[#] == 1 &]]
Options[plus1] = {"Output" -> "Standard"};
plus1[a_, b_, c_, OptionsPattern[]] :=
If[OptionValue["Output"] == "Standard", Identity, toEncoded]@
BitXor[a, c 2^b]
fromEncoded[a_] :=
FromDigits[
Reverse[Flatten[
ConstantArray @@@
Transpose[{PadRight[{}, Length[a], {1, 0}], a}]]], 2]
toEncoded[n_] :=
Length /@ Select[Split[Reverse@IntegerDigits[n, 2]], First[#] == 1 &]
toEncoded[5] (*outputs {1,1}*)
fromEncoded[{1,1}] (*outputs 5*)
plus1[fromEncoded[{4, 2, 3, 2, 2}], 5, fromEncoded[{3, 2, 5}],
"Output" -> "Nonstandard"]
Options[plus] = {"Output" -> "Standard", "Operation" -> 1};
plus[a_, b_, c_, OptionsPattern[]] :=
With[{ans = BitXor[a, c 2^b]}, Switch[OptionValue["Operation"],
1, If[OptionValue["Output"] == "Standard", Identity, toEncoded]@ans,
2, If[Mod[ans, 2] == 0, Rest, Identity]@
runlength[IntegerDigits[ans, 2] // Reverse]
]
]
runlength[bitlist_] := Length /@ Split[bitlist]
toEncoded[n_] := runlength[Reverse@IntegerDigits[n, 2]][[1 ;; -1 ;; 2]]
fromEncoded[a_] :=
FromDigits[
Reverse[Flatten[
ConstantArray @@@
Transpose[{PadRight[{}, Length[a], {1, 0}], a}]]], 2]
toEncoded[n_] :=
Length /@ Select[Split[Reverse@IntegerDigits[n, 2]], First[#] == 1 &]
In[120]:= plus[fromEncoded[{4, 2, 3, 2, 2}], 13,
fromEncoded[{3, 2, 5}], "Operation" -> 2]
Out[120]= {4, 2, 3, 2, 5, 2, 5}
Last reply 3 days ago
Did Cambridge maths students find maths and further maths a level very easy?Last reply 2 weeks ago
Edexcel A Level Mathematics Paper 2 unofficial mark scheme correct me if wrong71
Last reply 3 days ago
Did Cambridge maths students find maths and further maths a level very easy?Last reply 2 weeks ago
Edexcel A Level Mathematics Paper 2 unofficial mark scheme correct me if wrong71