【发布时间】:2015-12-28 22:48:26
【问题描述】:
我有一个非常具体的 Mathematica 问题。我正在尝试围绕某些“锁定”位生成所有二进制数。我正在使用字符串值列表来表示哪些位被锁定,例如{"U","U,"L","U"},其中 U 是“未锁定”的可变位,L 是“锁定”的不可变位。我从已格式化的随机二进制数的临时列表开始到上一个列表,例如 {0, 1, 1, 0},其中 1 是锁定位. 我需要找到 1 位为常数的所有剩余二进制数。我已经递归、迭代地处理了这个问题,并且将两者结合起来没有结果. 这是我在大学里做的研究。
我正在构建一个以 10 为基数的二进制数列表。我意识到这段代码是完全错误的。这只是一种尝试。
Do[
If[bits[[pos]] == "U",
AppendTo[returnList, myFunction[bits, temp, pos, returnList]]; ],
{pos, 8, 1}]
myFunction[bits_, bin_, pos_, rList_] :=
Module[{binary = bin, current = Length[bin], returnList = rList},
If[pos == current,
Return[returnList],
If[bits[[current]] == "U",
(*If true*)
If[! MemberQ[returnList, FromDigits[binary, 2]],
(*If true*)
AppendTo[returnList, FromDigits[binary, 2]];
binary[[current]] = Abs[binary[[current]] - 1],
(*If false*)
binary[[current]] = 0;
current = current - 1]; ,
(*If false*)
current = current - 1];
returnList = myFunction[bits, binary, pos, returnList];
Return[returnList]]]
【问题讨论】:
-
如果您在这里没有得到好的答案,还有专门的mathematica.stackexchange.com。
标签: algorithm binary wolfram-mathematica