Multiply

From Esolang
Jump to navigation Jump to search

The Multiply esoteric programming language is inspired by User:A's math homework. The math homework requires me to represent values using -3, -2, and -1 by multiplying them or dividing them. (I did not use division, though.)

Syntax

This programming language only implements multiplication.
It uses only 3 values: x as -3, y as -2, and z as -1.
Whitespace means multiplication.

Examples

x y y z <-- -3*-2*-2*-1=12.

Or in a condensed form:

xyyz

In a readable form:

x*y*y*z

Another program that prints -24:

x y y y z <-- -3*-2*-2*-2*-1=-24.

XKCD Random Number

Chosen by fair dice roll
Guaranteed to be random!
why.

Implementation

This is an interpreter made in C:

#include <stdio.h>
int main(int argc, char *argv[])
{
	int ac=1;
	char c;
	FILE *fp=fopen(argv[1],"r");
	for(;(c=fgetc(fp))!=EOF;)
	{
		if(c=='x')
			ac*=-3;
		else if(c=='y')
			ac*=-2;
		else if(c=='z')
			ac*=-1;
	}
	printf("%d\n",ac);
	return 0;
}

See also