esolang

Broken Calculator

An assembly language that may crash on any line, so every program halts.

PixelatedStarfish, 2021 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: HELLO WORLD

The idea

PixelatedStarfish made Broken Calculator in 2021. Every line it runs has a chance of crashing the program with the message "Broken Calculator!", an error code and the odds. The chance is never 0, so every program halts sooner or later. That makes the halting problem decidable for it, and the specification calls it not Turing complete for that reason.

Read the story

The specification gives the odds for a program of L instructions. Take X at random from 1 to 150 + L and R = X / 4. The chance in percent is 10 L / R, rounded, so for the 11 lines of Hello World it runs from 3 to 100 percent, as the specification says. The specification does not say on which line the crash comes or how the message is laid out, so this implementation leaves the crash out and the calculator never breaks.

The machine

A program is one instruction per line. @3 is cell 3 of an unbounded tape of whole numbers, A is the accumulator and a plain number is itself.

InstructionDoes
INP CRead a number into a cell
SET C $Set a cell
ADD SUB MUL DIV MOD POW RFL C $ $Store the left value with the right, RFL being the whole root
LBL V GOTO VMark a label; jump to it
CBEQ V $ $Jump if the two are equal
CBLE V $ $ CBGR V $ $Jump if the right is less, or greater, than the left
PCR $ PIN $Print a character; print a number
ACZ ACISet the accumulator to 0; add 1
HLT NOPHalt; do nothing
CMT NOTEComment

Example

The Hello World program prints in capitals.

The Hello World program prints in capitals.

The truth machine jumps to label 0 when the input is 0. On 1 it prints 1 for ever, which in the specification means until the calculator breaks.

Expected: 0
Expected: 10

A loop counts while 6 is greater than the cell. 2 to the 10th is 1024, and its fifth root is 4.

Expected: 12345
Expected: 1024 4

Patterns it teaches

Further

Probabilistic

Cell-based

Write your own in Run Convert a program from Broken Calculator

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: broken-calculator.

Command line

shib run broken-calculator -e 'ACI
PIN A
ACZ
PIN A
NOTE Should print '\''10'\'''
shib manual broken-calculator

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/broken-calculator.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org