Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 减量功能能否从这四个有限功能中实现?_Algorithm_Math_Assembly - Fatal编程技术网

Algorithm 减量功能能否从这四个有限功能中实现?

Algorithm 减量功能能否从这四个有限功能中实现?,algorithm,math,assembly,Algorithm,Math,Assembly,如何实现(如果可能)减量函数dec(x){x--}仅使用: 增量(x)[x++] 赋值(x,y)[x=y] 零(x)[x=0] 循环(x)[运行循环内的任何内容x次] 我不能使用for/while循环或基本运算符,如+,-,/--仅使用上述四个函数。是的:只需编写一个带有off by 1“error”的循环即可。 从1到x进行计数,但保存以前从零开始的循环索引值 dec(x): zero(y) loop(x) { assign(z, y) in

如何实现(如果可能)减量函数
dec(x){x--}
仅使用:

  • 增量(x)[x++]
  • 赋值(x,y)[x=y]
  • 零(x)[x=0]
  • 循环(x)[运行循环内的任何内容x次]

我不能使用for/while循环或基本运算符,如
+,-,/
--仅使用上述四个函数。

是的:只需编写一个带有off by 1“error”的循环即可。 从1到x进行计数,但保存以前从零开始的循环索引值

dec(x):
    zero(y)
    loop(x) {
        assign(z, y)
        increment(y)
    }
很多事情在别人发现后看起来都很琐碎。我错过的一些面试问题…:-)