# 乘以受限操作

44

1. 加成 `x,y -> x+y`
2. 倒数`x -> 1/x`除法`x,y -> x/y`
3. 求反`x -> -x`不是减法`x,y -> x-y`，尽管您可以通过两个操作来完成`x + (-y)`
4. 常数`1`（不允许其他常数，除非由的操作产生`1`
5. 变量分配 `[variable] = [expression]`

``````<statement>: <variable> = <expr>
<variable>: a | b | c | [string of letters of your choice]
<expr>: <arith_expr> | <variable> | <constant>
<arith_expr>: <addition_expr> | <reciprocal_expr> | <negation_expr>
<addition_expr>: <expr> + <expr>
<reciprocal_expr>: 1/(<expr>)
<negation_expr>: -<expr>
<constant>: 1
``````

（之前有一个问题“ 不带乘”的“乘”，但是它允许一组更宽松的操作。）

4

Ypnypn 2014年

1
@Ypnypn是的，我已经写了一个例子来确保。
xnor 2014年

2

Martin Ender 2014年

1

xnor 2014年

2

34

## 22次行动

``````itx = 1/(1+a+b)     #4
nx = -1/(itx+itx)   #4
c = -( 1/(itx + itx + 1/(1+nx)) + 1/(1/(a+nx) + 1/(b+nx)) ) #14``````

`c = 1/(1/x + 1/y) + 1/(1/z + 1/w)`

`c = (x+z)*(y+z)/(x+y)`

`````` p = x+y
-p = z+w
q = x+z
-q = y+w
r = x+w
-r = y+z``````

``````x = ( p + q + r)/2
y = ( p - q - r)/2
z = (-p + q - r)/2
w = (-p - q + r)/2``````

``````p = -4
q = 2*a
r = 2*b``````

``````x = -2 + a + b
y = -2 - a - b
z =  2 + a - b
w =  2 - a + b``````

``````#24 ops
t = 1+1   #2
c = 1/(1/(-t+a+b) + 1/-(t+a+b))  +  1/(1/(-b+t+a) + 1/(-a+b+t)) #1, 10, 1, 10``````

``````y = -x + p
z = -x + q
w = -x + r``````

``````p = 1
q = a
r = b``````

``````x = (1+a+b)/2
y = -x + 1
z = -x + a
w = -x + b``````

``````#23 ops
itx = 1/(1+a+b)     #4
nx = -1/(itx+itx)   #4
c = -( 1/(1/(-nx) + 1/(1+nx))  +  1/(1/(a+nx) + 1/(b+nx)) ) #15``````

`itx`是1 /（2 * x）并且`nx``-x`。最终优化表达`1/x`为，`itx+itx`而不是模板化，这会`1/(-nx)`削减字符，并将解决方案降低到22个操作。

Peter Taylor

3

MooseOnTheRocks

1
@MooseOnTheRocks很好，请参见代码中零度量子集可能失败的挑战中的“津贴”。我认为，否则挑战是不可能的。
xnor

26

# 23次

``````z = 1/(1/(1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1))-(1/a+1/b))
res = z+z
``````

``````z = 1/(1/(1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1))-(1/a+1/b))
1/(a+1)+1/(b+1)                            == (a+b+2) / (ab+a+b+1)
1/(1/(a+1)+1/(b+1))                           == (ab+a+b+1) / (a+b+2)
1/(1/(a+1)+1/(b+1))-1                         == (ab - 1) / (a+b+2)
1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1)             == ab / (a+b+2)
1/(1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1))            == (a+b+2) / ab
1/a+1/b   == (a+b) / ab
1/(1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1))-(1/a+1/b)  == 2 / ab
1/(1/(1/(1/(a+1)+1/(b+1))-1+1/(a+b+1+1))-(1/a+1/b)) == ab / 2

z = ab / 2 and therefore z+z = ab
``````

``````z = ////++/++-+/++++-/+/
res = +
``````

xnor 2014年

@xnor感谢您给我我的第一个被接受的答案和我的第一个赏金！

tfitzger 2015年

@tfitzger我认为这样比较容易。问题确实说没关系。请注意，我确实正确计算了分数（每个负值为2）

Wolfram Alpha有7天的免费试用期。
ghosts_in_the_code

13

# 29次行动

``````sum = a+b
nb = -b
diff = a+nb
rfc = 1/(1/(1/sum + -1/(sum+1)) + -1/(1/diff + -1/(diff+1)) + nb + nb)  # rfc = 1/4c
c = 1/(rfc + rfc + rfc + rfc)

# sum  is  2: =+
# nb   is  2: =-
# diff is  2: =+
# rfc  is 18: =///+-/++-//+-/+++
# c    is  5: =/+++
# total = 29 operations
``````

`rfc`如果我们定义一个宏，则（Reciprocal-Four-C）的结构会更加明显：

``````s(x) = 1/(1/x + -1/(x+1))              # //+-/+ (no = in count, macros don't exist)
rfc = 1/(s(sum) + - s(diff) + nb + nb) # =/s+-s++ (6+2*s = 18)
``````

• `s(x)`，在数学上是is `1/(1/x - 1/(x+1))`，是在代数is `x*(x+1)`或之后`x*x + x`
• 当您将所有内容细分为时`rfc`，实际上`1/((a+b)*(a+b) + a + b - (a-b)*(a-b) - a + b + (-b) + (-b))`就是`1/((a+b)^2 - (a-b)^2)`
• 正方形，或只是简单的扩张差异后，你得到的`rfc``1/(4*a*b)`
• 最终，`c`是4的倒数`rfc`，因此`1/(4/(4*a*b))`变为`a*b`

2
+1，我正在完成这个相同的计算
Eric Tressler 2014年

1

xnor 2014年

1
@flawr我`s(x)`从微积分中回顾了适合该问题要求的属性，因此这意味着我具有平方函数。经过一番忙碌之后，我发现我可以`a*b`用平方差技巧来形容。一旦有了这些，就可以尝试确定哪些分配可以节省操作。
algorithmhark

isaacg 2014年

9

# 27次

``````tmp = 1/(1/(1+(-1/(1/(1+(-a))+1/(1+b))))+1/(1/(1/b+(-1/a))+1/(a+(-b))))
res = tmp+tmp+(-1)

# tmp is 23: =//+-//+-+/++///+-/+/+-
# res is 4: =++-
``````

`tmp`实际上是23岁，因此得分为27岁。
algorithmhark
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.