Bucket

From Esolang
Jump to navigation Jump to search

Bucket is a set of languages involving 3 basic operations invented by User:A. The language variant is described by the tuple (a,b), where a<=b.

What you can do is:

  • Empty the bucket a or b
  • Fill the bucket a or b
  • Pour units of liquid from a to b or vice versa, until the former is empty or the latter is full (whichever one happens first)

"a" or "b" means the maximum amount of that bucket is a or b.

Commands

Where a is less than or equal to b in the tuple (a,b):
f: fills a
F: fills b
e: empties a
E: empties b
p: pours from a to b
P: pours from b to a

Examples in (3,4)

All values are stored in the "4" bucket.

0

No code is necessary. It was set to 0.

1

FP

2

FPePFP

3

fp

4

F

Increment bucket 4

PFP

Decrement bucket 4

fpEp

Hello World! program in Bucket for debugging in integers (derivative (1,119))

fpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfp
fpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpOfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpOfpfpfpfpfpfpfpOOfpfp
fpOPePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePeP
ePePePePePePePePePePePePeOPePePePePePePePePePePePeOfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpf
pfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpfpf
pOPePePePePePePePeOfpfpfpOPePePePePePeOPePePePePePePePeOPePePePePePePePePePePePePePePePePePePePePePePePePePePePe
PePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePePeO

Implementation in C (provided output instructions just for debugging)

#include <stdio.h>
int main(int argc, char *argv[]) {
	FILE *fp=fopen(argv[1],"r");
	char *code,c;
	for(int i=0;(c=fgetc(fp))!=EOF;i++)
		code[i]=c;
	int a,b;
	printf("Enter the tuple (a,b): ");
	scanf("%d %d",&a,&b);
	int x=0, y=0;
	for(int i=0;code[i]!='\0';i++) {
		while(x>a) {
			x--;
			y++;
		}
		while(y>b) {
			y--;
			x++;
		}
		while(x<0) {
			x++;
			y--;
		}
		while(y<0) {
			y++;
			x--;
		}
		if(code[i]=='f')
			x=a;
		else if(code[i]=='F')
			y=b;
		else if(code[i]=='e')
			x=0;
		else if(code[i]=='E')
			y=0;
		else if(code[i]=='p')
			while(x>0||y<b) {
				x--;
				y++;
			}
		else if(code[i]=='P')
			while(x<a||y>0) {
				y--;
				x++;
			}
		else if(code[i]=='o')
			printf("%d\n",x);
		else if(code[i]=='O')
			printf("%d\n",y);
	}
	return 0;
}

Here is an implementation competition.