# BrainSoothe

Jump to navigation Jump to search

BrainSoothe (abbreviated BS in a G-rated context) is an esolang devised by User:arseniiv in 2020 entirely not for mocking the abbreviation BF.

## Syntax

The program is a nonempty finite sequence of (unbounded) nonnegative integer literals delimited by spaces or other non-numeric characters which are ignored. There should be no literals at different positions which denote the same number.

## Semantics

At runtime, there is an unbounded integer register initialized to the program input, or to zero if there’s no input. There is a literal pointer which can point to any literal in the code; initially it points to the leftmost one. We denote the value of the literal currently in focus by ${\displaystyle n}$ and the current value of the register by ${\displaystyle x}$.

Each execution step, we assign ${\displaystyle x:=x+1}$ and test if ${\displaystyle x\equiv 0{\pmod {n}}}$. If that’s the case, we make ${\displaystyle x:=x-n}$, then jump ${\displaystyle n}$ literals to the right, and in case of overshoot, halt. If that’s not the case, we just shift focus to the literal to the right of the current, and if that’s not possible, jump to the first literal.

The output is the final value of the register when the execution halts.

### Pseudocode

That literary description above might be misleading against all my wishes, so here is a more formal one in Python 3 (you may ignore the import and erase type annotations if you wish).

from typing import Sequence

def run(instructions: Sequence[int], value: int) -> int:
instr_count = len(instructions)
assert instr_count != 0
assert all(instr >= 0 for instr in instructions)
assert instr_count == len(set(instructions))
instr_index = 0
while True:
value += 1
instr = instructions[instr_index]
test = value % instr if instr != 0 else value
if test == 0:
value -= instr
instr_index += instr
if instr_index >= instr_count:
return value
else:
instr_index += 1
if instr_index == instr_count:
instr_index = 0


## Examples

A single-instruction program ${\displaystyle n}$ implements floor division ${\displaystyle x\mapsto \lfloor x/n\rfloor }$, including the case of ${\displaystyle n=0}$ for which it doesn’t halt.

## Commentary

If this ends up being a language simple to write in, or a non-TC one, well, that was worth a try, as I admit this joke language was fleshed out in less than half an hour.

Update: Yes that’s not TC as the register effectively has ${\displaystyle \operatorname {LCM} (\mathrm {instructions} )}$ values. Meh.