bitch

From Esolang
Jump to: navigation, search

bitch (non-capitalised) is a minimalistic language created by User:Helen inspired by Arphimigon's BITCHWISE[1].
It has a total of 15 instructions[2] (one of which is no-op[3]) and a (technically) infinite number of instruction characters, as all unrecognised characters are no-ops[3].

Storage

bitch has a single place to store values, the accumulator.
The value of the accumulator is accessible by every function, but certain functions don't use them.
Some instructions in bitch allow a constant integer to be input as a second (or sometimes only) parameter.

Instruction Set

There are 3 types of instructions, which I will call flow, I/O[4] and bitwise instructions[5].

Flow Instructions


There are 5 flow instructions, 2 of which are conditional instructions[6].
Basic flow instructions do not use the accumulator value, however, the conditional flow instructions do.

Basic Flow Instructions

> - marks the beginning of a code block
< - jumps to the nearest >
. - ends the program

>code< is a loop that will run the code code indefinitely.

Conditional Flow Instructions

: - only executes the next instruction if the value in the accumulator is equal to 0
; - only executes the next instruction if the value in the accumulator is NOT equal to 0

This makes clever usage of conditionals essential for short code, as a conditional block is completely impossible.
Each instruction would have to be preceded by a conditional symbol, doubling the length of the conditional code.

I/O Instructions


There are only two actual I/O instructions, since bitch is a relatively restricted language.
However, there is a number literal form which is also included here.
It is impossible to have non-integer input or output.

\ - stores one integer of input in the accumulator
/ - outputs the accumulator value
#number - stores the specified constant in the accumulator

Bitwise Instructions


There are 6 bitwise instructions, less than the normal set of bitwise instructions.
This is because most other instructions can be formed from a combination of these.

&number - AND bitwise instruction, equivalent to accumulator AND number
|number - OR bitwise instruction, equivalent to accumulator OR number
~ - NOT bitwise instruction, equivalent to finding the 1's complement of a number
^number - XOR bitwise instruction, equivalent to accumulator XOR number
[number - left shift instruction, equivalent to accumulator left shift by number
]number - right shift instruction, equivalent to accumulator right shift by number

Turing-completeness

bitch is most likely not Turing-complete[7].
However, this has not been proven and therefore it is possible that it could be.

Popular Problem solutions in bitch

These are solutions (written in bitch) to problems on the Popular Problems page.

Possible

Cat program (limited to integers)

>\/<

Truth-machine

Will print nothing if input doesn't equal 0 or 1 (behaviour here not defined by the article).

\:/:.&-2;.#1>/<

Possible with adjustments

Hello, world!

This becomes trivial as long as we allow output to be integer values representing the actual output string.

#72/#101/#108/#108/#111/#44/#32/#119/#111/#114/#108/#100/#33/

Impossible

There are a lot of trivially impossible programs, as a lot of them involve printing characters or taking in characters as input.
These include: Hello, world!, 99 bottles of beer, Quine (unfortunately), Mandelbrot set, ROT13 encoder/decoder, FizzBuzz.
However, all of these, except for ROT13 encoder/decoder, can (probably) be made possible if we allow for usage of ASCII character values, and convert output into text manually.

It is probably impossible to do a ROT13 encoder/decoder, since bitch cannot take in text input.
A suitable solution would be to convert everything to integers, and collate each binary ASCII value.
This would give us a big integer which is really comprised of n-bit segments, each of them a character.
We could then operate on the integer as a whole, but not in bits, since the second parameter of a bitwise operation is always a constant in bitch.
With nowhere else to store other digits, it is impossible to keep the whole string if you split it up.
This makes it pretty unlikely that ROT13 encoder/decoder is possible.

It is impossible to do a true Bootstrap since bitch has specific characters for each operation and therefore text would have to be involved, which is impossible in bitch.
It is probably impossible to do it with adjustments anyways, since a Bootstrap would involve operations with an arbitrarily sized integer (as for ROT13 encoder/decoder), which bitch cannot really handle well.

A pi calculator might be impossible due to its involvement with decimals.
However it might be possible to emulate decimals by multiplying by 10 every time a digit is calculated, allowing us to deal with integers rather than reals.
This would involve outputting each digit at a time, which would definitely work.

Unproven

Possible? Fibonacci sequence, Factorials, Prime numbers, Disan Count, Digital root calculator, Pi calculator.
Possible with adjustments? 99 bottles of beer, Quine, Mandelbrot set, ROT13 encoder/decoder, FizzBuzz.
Impossible? Bootstrap.

Implementation

A horrific 80-line implementation of bitch is possible in Java:

import java.util.ArrayList;
import java.util.Scanner;

public class bitch {
    public static void main(String[] args) {
        @SuppressWarnings("resource") Scanner s = new Scanner(System.in);
        char[] originalProgram;

        while(true) {
            {
                String string = s.nextLine();
                originalProgram = string.toCharArray();
            }
            
            runProgram(originalProgram);

            System.out.println("---------------------------------------------------------------");
        }
    }

    public static int runProgram(char[] originalProgram) {
        Scanner s = new Scanner(System.in);

        int opCounter = 0;
        char[] program = originalProgram.clone();
        int current = 0;
        
        ArrayList<Integer> blockPoints = new ArrayList<Integer>();

        loop:
        while(program.length > 0) {
            switch(program[0]) {
                case '\\': current = s.nextInt(); break;
                case '#': current = grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case '>': blockPoints.add(opCounter); break;
                case '<': opCounter = blockPoints.get(blockPoints.size()-1)-1; program = join(new char[] { 'a' }, new String(originalProgram).substring(opCounter+1).toCharArray()); blockPoints.remove(blockPoints.size()-1); break;
                case '&': current &= grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case '|': current |= grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case '~': current = ~current; break;
                case '^': current ^= grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case '[': current <<= grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case ']': current >>>= grabInteger(new String(program).substring(1).toCharArray()); opCounter += ((Integer) current).toString().length(); program = new String(program).substring(((Integer) current).toString().length()).toCharArray(); break;
                case '.': break loop;
                case '/': System.out.println(current); break;
                case ':': if(current != 0) { program = new String(program).substring(1).toCharArray(); opCounter++; } break;
                case ';': if(current == 0) { program = new String(program).substring(1).toCharArray(); opCounter++; } break;
            }

            program = new String(program).substring(1).toCharArray();
            opCounter++;

            // if(blockPoints.size() > 0) { System.out.print("Latest block point: "); System.out.println(blockPoints.get(blockPoints.size()-1)); }
            // System.out.print("Current code: "); System.out.println(program);
            // System.out.print("Current pointer: "); System.out.println(opCounter);
        }

        return current;
    }

    public static int grabInteger(char[] c) {
        String intS = "";
        
        for(char chr : c) {
            if(!new String(new char[] {chr}).matches("-?[0-9]?")) { break; }
            intS += chr;
        }

        int intV = new Integer(intS);

        return intV;
    }

    public static char[] join(char[] a, char[] b) {
        char[] r = new char[a.length + b.length];
        for(int x = 0; x < a.length; x++) { r[x] = a[x]; }
        for(int x = a.length; x < a.length+b.length; x++) { r[x] = b[x-a.length]; }

        return r;
    }
}

A .jar might be available here.
If so, you can use it like this:

java -jar bitch.jar

This implementation has an infinite loop of getting the next line (on which a bitch program would be written) and then running the bitch program.
All bitch instructions are compatible with this implementation.

An alternate implementation is available at Try It Online or in the GitHub for bitch.

References

  1. No available webpage for BITCHWISE as of 05/01/2019.
  2. Link to Wikipedia's article on instructions and instruction set architecture.
  3. 3.0 3.1 Link to Wikipedia's article on no-ops.
  4. Link to Wikipedia's article on I/O.
  5. Link to Wikipedia's article on bitwise instructions.
  6. Link to Wikipedia's article on conditional instructions.
  7. Link to Esolang's article and Wikipedia's article on Turing-completeness.