점수 (현재) : 12038 837 /-
프로그램은 숫자가 지정된 셀에 의해 ,
또는 이와 유사하게 로드된다고 가정합니다 . 또한 모든 셀이 필요에 따라 줄 바꿈으로 8 비트 부호없는 것으로 가정합니다. 각 스 니펫의 시작에서 숫자는 셀 0에로드됩니다 (필요한 경우 1).
비트 연산-799
비트 연산은 동일한 일반적인 구조를 따릅니다.
Firstly, we define a divmod 2 (DM2) function.
CELLS: A B C D
INPUT: *A 0 0 0
OUTPUT: *0 A/2 A%2 0
dp@A; while{
dec A,2; inc B,1; dp@A; inc A,1
while{ #Check if A was 1 at the start
dec D,1; pour A,C; dp@A;
}
dec C,1; pour C,A; inc D,1; dp@D
#If A was 1 at the start, D will be 1 here
while{
dec D,1; inc C,1; dec B,1; dp@D
}
dp@A
}
Translated into BF, we have
[->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]
I'm not that good at BF, so my algorithm may not be the smallest.
Next, we define the program.
In this, we assume that the numbers are loaded in $2 (cell 2) and $3.
inc $1,8; dp@1 {
dec $1
pour $3,$6
DM2 $2 # result in $3,$4
DM2 $6 # result in $7,$8
pour $7, $2
pour $8,$5
bop $4,$5 # result in $6
pour $1,$5
pour $5,$4,$1
down $4,$5 # decrease $4 till 0, decrease $5 by same amount
inc $5,#7
shl $6,$5
pour $6,$0 # $0 is result
dp@ 1
}
#Now, the result is in $0
Translated to BF (with linebreaks for readability):
>++++++++[
->>[->>>+<<<]<
[->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]>>>> #DM2 $2
[->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]> #DM2 $6
[-<<<<<+>>>>>]>
[-<<<+>>>]<<<<
(bop)<<<
[->>>>+<<<<]>>>>
[<+<<<+>>>>-]<
[->-<]>
+++++++
[->[-<<++>>]<<[->>+<<]>]
[-<<<<<<+>>>>>>]
<<<<<
]
Replace (bop) by the appropriate expression.
XOR works like this: (252-5+15=262)
[->-<]>[[-]>+<]
AND works like this: (252-5+11=258)
[>[>+<-]<-]
OR works like this: (252-5+32=279)
[->>>+<<<]>[->>+<<]>>[[-]<+>]<<<
So, combining these, we have a total of 262+258+279=799 D:
왼쪽 A 회전, 1-31 /-
숫자 A
는 셀 0에로드됩니다.
Pseudocode
$0 := A
$1 := $0 << 1 # this has the effect of discarding the top bit of A
$2 := $0
$3 := $0 << 1
$2 -= $1 >> 1 # $2 now contains the top bit of A
if $2 then $3++ # $3 now contains A rotated left 1
res:= $3 # the result is in cell 3 now
Real code
[->++>+>++<<<]>[-->-<]>[>+<[-]]
If you don't always need the pointer in the same position,
substitute [>+>] for the last loop (3 less chars).
However, the pointer will then sometimes end up in position 2, sometimes in position 4.
아님-7
숫자 A
는 셀 0에로드됩니다.
Pseudocode
$0 := A
$0 += 1
$1 := 256-$0 #since ~A=255-A
res := $1
+[->-<]