Multiply

From Esolang
Jump to: navigation, search

This esoteric programming language is inspired by my 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.

Implementation

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