XOṘ Mạchịne

From Esolang
Jump to navigation Jump to search

XOṘ Mạchịne is an OISC based on the XOR operation invented by User:A. It is an open question on whether this machine can simulate every logic gate with two parameters.

Exclusive-Or reference

A B Result
1 1 0
1 0 1
0 1 1
0 0 0

The Program Execution Process

Input two bits, where the first bit represents a, and the second bit represents b. After processing the program, output whether a is larger than b. If that is true, output 1. Otherwise, output 0.

There is only 1 constant available. That is the constant 1, which represents the bit 1.

a represents the bit a, and b represents the bit b.

For every two commands, e.g. ab, a XOR b is done and is stored in a.

Example programs

a AND (NOT b)

(NOT a) AND b

abbabb

NOT (a XOR b)

aba1bb

Output 0

aa

Output 1

bbaaa1

a XOR b

abbb

a

bb

NOT a

bba1

NOT b

aa1

b

b1aa1

a AND b

b1

a NOR b

a1

C Implementation

#include <stdio.h>
int main(int argc, char*argv[]) {
	FILE *fp=fopen(argv[1],"r");
	char code[99999];
	int c;
	for(int i=0;(c=fgetc(fp))!=EOF;i++)
		code[i]=c;
	char a,b;
	char s[3];
	scanf("%s",&s);
	a=s[0]-48;
	b=s[1]-48;
	//debug
	for(int i=0;code[i]!='\0';i+=2) {
		if(code[i]=='a'&&code[i+1]=='a')
			a ^= a;
		else if(code[i]=='a'&&code[i+1]=='b')
			a ^= b;
		else if(code[i]=='a'&&code[i+1]=='1')
			a ^= 1;
		else if(code[i]=='b'&&code[i+1]=='a')
			b ^= a;
		else if(code[i]=='b'&&code[i+1]=='b')
			b ^= b;
		else if(code[i]=='b'&&code[i+1]=='1')
			b ^= 1;
		
	}
	printf("%d",a>b);
	return 0;
}