Requires a 16-bit interpreter, at least 64 tape cells, integer i/o. This all is faciliated using bfi -d
bundled with asm2bf. Fairly slow, overflows at n=6. Takes n
in r4. Outputs the result due to a meta consensus.
?A=popr1/outr1
@z incr3
psh1
dup
@a movr2,r3
movr1,1
@b cltr2,2
cjn%c
mulr1,r2
decr2
jmp%b
@c pshr1
psh1
fad
incr3
cltr3,r4
cjn%a
A
A
Example usage:
mov r4, 5
jmp %z
Deobfuscated:
inc r3
push 1
push 1
@mloop
mov r2, r3
mov r1, 1
@loop
clt r2, 2
cjnz %done
mul r1, r2
dec r2
jmp %loop
@done
push r1
push 1
fadd
inc r3
clt r3, r4
cjnz %mloop
pop r1
out r1
pop r1
out r1
Bonus: optimized brainfuck code:
>>>>>>+++++<+>>>>>>>>>>>>+[<<<<+>>>>>>>[>>]>+<<<[<<]<-]<<<<[>>>>+<<<<-]>>>>>>>[>
>]+[<<]<[<<<<+>>>>>>>[>>]>+<<<[<<]<-]<<<<[>>>>+<<<<-]>>>>>>>[>>]+[<<]<<<<[-]+[<<
<<<<<<<<[-]>[<+<<+>>>-]<<<[>>>+<<<-]>[-]+>>>>>>>>>>>[-]+[<<<<<<<<<<<[<<+>>-]<<[>
>>[<+<+>>-]<<[>>+<<-]<-]>>>->>>++>>>>>>>[-]+<<<<<<<<<<[>>>>>>>+<<<<<<<-]>>>[>>>+
<<<-]>>>[<<<<<<+>>>+>>>>[-<]>]<<[>>>>-<<<<<<<<<<->>>>>>-[<<<+>>>-]<<]>>>[<<<<<<<
+>>>>>>>-]<<<<[-]>>>>>>>]<<<<<<<<<<<[>>>>>>>>>>+>>>>>>>[>>]>+<<<[<<]<<<<<<<<<<<<
<<<-]>>>>>>>>>>[<<<<<<<<<<+>>>>>>>>>>-]>>>>>>>[>>]+[<<]<[<<<<+>>>>>>>[>>]>+<<<[<
<]<-]<<<<[>>>>+<<<<-]>>>>>>>[>>]+[<<]>>[>>]<<-<[<<<<->+>>>-]<-<<-<[>[<+>>>>+<<<-
]>[<+>-]<[>>>[<<+>+>-]<[>+<-]<<-]<[>+<-]>>>>>>[<<<<<[<+>>+<-]<[>+<-]>>>>>>-]<<[<
<<[<+>>>+<<-]>>[<<+>>-]>-]]<[>>[<+>-]>>>>>[<<<<+>>>>-]<<<]<<[-]+[<<]<<<<<<<<<<<[
-]<<+>>>>>>>>>[-]<<<<<<<<<[>>>>>>+<<<<<<-]>[>>>>+<<<<-]>>>>[<<<<<+>+>>>>>[-<]>]<
<[>>>>+<<<<<<<<<->>>>>-[<<<<+>>>>-]<<]>>>[<<<<<<+>>>>>>-]>>>]>>>[-]>>>[>>]<<->[<
<<[<<]<+>>>[>>]>-]<<<[<<]<.[-]>>>[>>]<<->[<<<[<<]<+>>>[>>]>-]<<<[<<]<.
To change the output, tweak the first block of +
.
N
the results will be the same if using a finite precision floating point number. Is that behaviour acceptable or does the result have to progressively get more accurate asN
approaches infinity? \$\endgroup\$