# Convert 8 Bit brainfuck to 1 bit Brainfuck / Boolfuck

## Goal

Input is a Brainfuck program for 8 bit cells, output it for 1 bit cells.

## Explanation

We all know Brainfuck, normally it uses 8 bit cells. But there are implementations where a cell is just 1 bit, sometimes called Boolfuck. A Brainfuck program that is written for 8 bit cells most likely does not work when cells are just 1 bit. The goal is to write a conversation program that converts a Brainfuck program that works with 8 bit cells to one that works with 1 bit cells.

You can convert it with this Table:

+-----------------+---------------------------------------------------------+
| 8 Bit Brainfuck | Boolfuck                                                |
+-----------------+---------------------------------------------------------+
| +               | >[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<                         |
| -               | >>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+]<<<<<<<<<        |
| <               | <<<<<<<<<                                               |
| >               | >>>>>>>>>                                               |
| ,               | >,>,>,>,>,>,>,>,<<<<<<<<                                |
| .               | >;>;>;>;>;>;>;>;<<<<<<<<                                |
| [               | >>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<<<<[>]+<[+<] |
| ]               | >>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>]<[+<]              |
+-----------------+---------------------------------------------------------+


Standard Boolfuck uses ; instead of . for output.

## Rules

• Input is a 0 to 255 long valid Brainfuck programs with only []-+,.<>.
• Output a valid 1 bit Brainfuck or Boolfuck program that does exactly the same as the Brainfuck program.
• The table above is only a suggestion, you can use a different conversion as long as it works and doesn't use more than 16 times the amount of cells 64 times the amount of code length compared to 8 bit Brainfuck.
• The endianness of the input and output can be chosen, but they have to be the same.
• Both ; and . are valid for output a cell.
• Both + and - are valid for inverting a cell.

Every [],.+-;<> in your source code counts 1, every other byte counts 8. The sum gives your score.

Smallest score wins.

### Ungolfed Example

#!/usr/bin/env python3

import sys

for line in sys.stdin:
for c in line:
if c=='+' : print(">[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<")
if c=='-' : print(">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+]<<<<<<<<<")
if c=='<' : print("<<<<<<<<<")
if c=='>' : print(">>>>>>>>>")
if c==',' : print(">,>,>,>,>,>,>,>,<<<<<<<<")
if c=='.' : print(">;>;>;>;>;>;>;>;<<<<<<<<")
if c=='[' : print(">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<<<<[>]+<[+<]")
if c==']' : print(">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>]<[+<]")

• Here's a scoring program Commented Sep 3 at 20:31

# Vyxal, 156 bytes, score 247

kT;>+-+[>+]<[<];>[+-[>]+<[+<]++;>+-+[>+]<[<];>]<[+<]++-<++;>++;>+-+[>+]<[<];>[+]-<++>[>]+<[+<];>[+]-<++>.>.>.>.>.>.>.>.-++>,>,>,>,>,>,>,>,-‛-;‛<>f8*Ŀ‛++/Ŀ


Try it Online!

There's not much room for optimisation here, because any trick has to save eight times the cost of the program encoding it. So, all this does is replace long runs of > and < with - and ;, and separate builtins with ++, then replace the corresponding commands.

For a shorter but worse-scoring solution:

# Vyxal, 76 bytes, score 601

kT«Wėm¦n½LøsJƒ›WǎQøḢi‹WK⇩f↑¼,uṪ∑¥↳₁ṡ²₈>⊍₌?-₀O∷×Ḟ•ṫ¼i8#S⇧⌐«n8ẎkTĿn∷9Ẏ(n/ṫj)⌈Ŀ


Try it Online!

A more compressed approach that doesn't really work with the custom scoring. This uses various regpack-based compression tricks and it's a bit of a mess.

# JavaScript (ES7), Score:  492  485

The scoring scheme makes most compression attempts counter-productive. So what we really want to do is just use as few expensive characters as possible... ¯\_(ツ)_/¯

Expects an array of ASCII codes.

a=>a.map(c=>[[">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>"][8>>c**7]]+[+<<<<<<<<[>]+<[+<]--]<[+<]-->[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<->,>,>,>,>,>,>,>,<<<<<<<<-[+]<<<<<<<<<->;>;>;>;>;>;>;>;<<<<<<<<-<<<<<<<<<-->>>>>>>>>.split-[c%13]).join


Try it online!

• Having some >>><<< would save some score
– l4m2
Commented Sep 4 at 8:20
• this
– l4m2
Commented Sep 4 at 8:25
• "The scoring scheme makes any compression attempt counter-productive" That was to engurage solutions in Brainfuck and Boolfuck, i didn't think about that side effect. Commented Sep 4 at 11:05
• @12431234123412341234123 I once created question about Brainfuck and just say "While other languages allowed, I'll accept shortest Brainfuck answer"
– l4m2
Commented Sep 4 at 11:31
• <<<<<<<<< at last can be omitted as it won't affect output, just move pointer back
– l4m2
Commented Sep 4 at 18:19

=switch(A1,"+",">[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<","-",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+]<<<<<<<<<","<","<<<<<<<<<",">",">>>>>>>>>",",",">,>,>,>,>,>,>,>,<<<<<<<<",".",">;>;>;>;>;>;>;>;<<<<<<<<","[",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<<<<[>]+<[+<]","]",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>]<[+<]")


Dumb solution, compression doesn't seem to pay because of the scoring system.

# Charcoal, 160 bytes, score 265

⭆Ｓ§⪪⪫⪪⪫⪪-+.+[>+]<[<]-[+.[>]+<[+<]++++-+.+[>+]<[<]-]<[+<]++++>[>]+<[+<]-[+].<++>,>,>,>,>,>,>,>,.++-+.+[>+]<[<]-[+].<++>;>;>;>;>;>;>;>;.++.<++++-++++¦-×>⁹.×<⁸++℅ι


Attempt This Online! Link is to verbose version of code. Explanation: Port of @Arnauld's JavaScript answer, but modified using @Ausername's compression.

 Ｓ                      Input string
⭆                       Map over characters and join
...             Translation string
⪫⪪   -×>⁹         Replace - with nine >s
⪫⪪         .×<⁸     Replace . with eight <s
⪪               ++   Split on literal string ++
§                     Indexed by
ι Current character
℅  Ordinal
Implicitly print


# C (clang), Score 678675 669 (312 bytes)

*a[]={">[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<",">,>,>,>,>,>,>,>,<<<<<<<<",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+]<<<<<<<<<",">;>;>;>;>;>;>;>;<<<<<<<<","<<<<<<<<<",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<<<<[>]+<[+<]",">>>>>>>>>",">>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>]<[+<]"};f(s[]){for(;*s;)printf(a[*s++%43%13]);}


Try it online!

Changed the index calculation to n % 43 % 13 to avoid empty strings in the dictionary thus saving a whopping 3 points from the score =)

# 05AB1E, score 292 (166 bytes)

“>-+.+[>+]<[<]>-[+.[>]+<[+<]-->-+.+[>+]<[<]>-]<[+<]-->[>]+<[+<]>-[+].<->,>,>,>,>,>,>,>,.->-+.+[>+]<[<]>-[+].<->;>;>;>;>;>;>;>;.-.<-->-“„>-¬9×:'.“<<<<<<<<“:'-¡IT>>>%èJ


Port of @Arnauld's first JavaScript answer, with some additional score improvements by using replaces.

Input as a list of code-point integers.

Try it online.

Explanation:

“>-+…>-“               # Push this string
„>-            # Push ">-"
¬           # Push its first character without popping: ">"
9×         # Repeat it 9 times: ">>>>>>>>>"
:        # Replace all ">-" with ">>>>>>>>>" in the big string
'.            '# Push "."
“<<<<<<<<“   # Push "<<<<<<<<"
:  # Replace all "." with "<<<<<<<<" in the big string
'-¡           '# Then split on "-"
I           # Push the input-list of codepoint-integers
T          # Push 10
>>>       # Increase it three times to 13
%      # Modulo
è     # 0-based index each into the list of strings
J    # Join this list to a single string
# (which is output implicitly as result)


# Funge-98, score 972

~:'+-!#[_>:'--!>#]_>:'<-!>#[_>:'>-!#[_>:',-!#[_>:'.-!>>#]_>:'[-!>>>>>>>#]_']-!#]_>
]].....[$"<<<<<<<<<]+[>>>>>>>>>]<+[<+]>[>";..[$"<<<<<<<<,>,>,>,>,>,>,>,>"#;
[<...............]$"<<<<<<<<<]++-[>>+->>>>>>>]<[<]+>[+<<<<<<<<+>>>>>>>>>"> [<<<<<<<<<<<<<<<;+;<<<<<<<<<:k7<<<<<]...................]$"<<<<<<<<;>;>;>;>;>;>;>;>"
>,:1j2_]<<">>>>>>+->>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<+-<<<[>]+<[+<]"\$[
<<<<<<<]<<<<<<<<;+;<<<<<<<<<<<<">>>>>>>>>+<<<<<<<<+[>+]<+-[<]>>>>>>+->>>]<[+<]"<.]


Try it online!

The program never halts, so if you run it using TIO, you have to manually cancel execution in order to view the output.

# JavaScript (Node.js), 503 score

f=([c,...a])=>c?;+>[>]+<[+<]>>>>>>>>>[+]<<<<<<<<<;+;->>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+]<<<<<<<<<;-;<<<<<<<<<<;<;>>>>>>>>>>;>;,>,>,>,>,>,>,>,>,<<<<<<<<;,;.>.>.>.>.>.>.>.>.<<<<<<<<;.;[>>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>[+<<<<<<<<[>]+<[+<];[;]>>>>>>>>>+<<<<<<<<+[>+]<[<]>>>>>>>>>]<[+<].split(';'+c)[1]+f(a):[]


Try it online!

Each map is surrounded by ;<char><mapped>;<char> to allow low-cost indicing