Back
Close

BrainFuck part 6 - 16-bit integers

DPAmar
1,554 views

Inc/dec operations

Reminder : N = [ABCD] with A=B=0 and N = 256*D + C, with cursor on C

A bit more complex now : increase and decrease value

What does Increase means ? Store N+1 instead of N. In our case : N = D * 256 + C with C < 256. N + 1 = D * 256 + C+1: C+1 is the new C unless C+1 is 256 : then C is 0 and D+1 is the new D

  • Set else flag in B
  • Increase C
  • If C is not null reset else flag
  • If else flag is not null (C is null) increase D

Note: in one case it's increase C, in the other case it's store 0 instead of 255, which is "decrease C" as well

What does Decrease means ? Store N-1 instead of N. In our case : N = D * 256 + C with C >= 0. N - 1 = D * 256 + C-1: C-1 is the new C unless C is null : then C is 255 and D-1 is the new D

  • Set else flag in B
  • If C is not null reset else flag
  • If else flag is not null (C is null) decrease D
  • Decrease C

Note: in one case it's decrease C, in the other case it's store 255 instead of 0, which is "decrease C" as well

Operation8-bit version16-bit versionComments
Increase+<+>+[<-]<[->>+<<<]>>Increase C, if null increase D
Decrease-<+>[<-]<[->>-<<<]>>-If C null decrease D; decrease C

Current operation map

Operation8-bit version16-bit versionComments
Write..write C (D does not matter)
Read,,>[-]<read C and reset D
Move left<<<<<Move 4 times
Move right>>>>>Move 4 times
Increase+<+>+[<-]<[->>+<<<]>>Increase C, if null increase D
Decrease-<+>[<-]<[->>-<<<]>>-If C null decrease D; decrease C
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants