混淆code:最后一个数字数字、code

2023-09-11 07:26:18 作者:与往事干杯

我必须写混淆code在brainfuck语言做如下的挑战:

  

对于给定的数n输出的最后一位。

     

输入

     

输入将包括只有一行,其中只有一个整数n(1&其中; =正&其中; = 20亿),接着用一个新行'\ N'(ASCII 10)

     

输出

     

在输出,必须找到只有一个整数,表示n的最后一位。

     

例如我   输入:32   输出:2

     

例子二:   输入:231231132   输出:2

这是我尝试过,但没有奏效:

  +>,]<> ++++++++++。
 
leetcode 只出现一次的数字

解决方案

现在的问题是,你说的是循环终止当输入为0。

输入是永远不为0,ASCII码为换行是10所以这就是你需要使用。

这code应该工作。在现实中,这code不关心人,如果你给它一个数字,它只是返回找到的第一个换行符前的最后一个字符。

  + //增量[1] 1,并进入循环
  [//读取输入[1],并进入另一个循环
     &GT + GT +其中;&所述;  -  //复制初始输入两次而递减的原始
  ]
  >>> ++++++++++ //写10(用于换行符),并进入一个循环[
    &其中 - →;  -  //递减计数器10和所复制的输入之一
  ]
<退一步到(输入 -  10)细胞
]<<&LT ;. //如果(输入 -  10 == 0),那么你刚才读一个回车!好极了!退一步三到最后存储的输入并打印到控制台。
 

I have a challenge to write obfuscated code in the brainfuck language to do the following:

For a given number n output its last digit.

input

Input will consist of only one line in which there is only one integer n ( 1 < = n < = 2,000,000,000 ) , followed by a newline ' \ n' (ASCII 10).

output

On the output, has to find exactly one integer denoting the last digit of n.

example I input: 32 output: 2

example II: input: 231231132 output: 2

This is what I tried, but it didn't work:

+[>,]<.>++++++++++.

解决方案

The problem is that you're telling the loop to terminate when the input is 0.

The input is never 0, the ASCII for newline is 10 so that's what you'll need to use.

This code should work. In reality, this code doesn't care at all if you've given it a number, it just returns the last character before the first newline it finds.

+[     // increment [1] by 1 and enter the loop
  ,[     // read input to [1] and enter another loop
     >+>+<<-     // copy the initial input twice whilst decrementing the original
  ]
  >>>++++++++++     // write 10 (for newline) and enter a loop[
    <->-     // decrement the 10 counter and one of the copied inputs
  ]
< step back to the (input - 10) cell
]<<<.     // if (input - 10 == 0) then you just read a carriage return! yay! Step back by three to the last stored input and print it out to the console.