Cut

From Esolang
Jump to: navigation, search

Cut is a joke language. Writing the shortest number in Cut is an interesting programming puzzle.

Syntax

After the program is processed, the accumulator will be outputted. On the 1st instruction, the operations count by 1. On the 2nd instruction, the operations count by 2, and so on...

+: Count up by the current instruction number. -: Count down by the current instruction number.

Example programs

1: +

2: +-+

3: +-+-+

4: ++-+

5: +--++

C Implementation

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