Skinny pig

From Esolang
Jump to navigation Jump to search

Skinny pig is an esoteric programming language specifically designed to be used by skinny pigs or guinea pigs. The guinea pig will "write" the program by doing the things it normally does, but the observer must take note of the actions taken by the guinea pig and convert each action into code.

Explanation

To create programs in Skinny pig, you need a guinea pig or a video of one. You can record actions from multiple guinea pigs at a time. Whenever the guinea pig does something that matches with a command, you write it into the program. For example, every time the guinea pig drinks, you would type "drink" into the program for each time you hear the sound that the water bottle makes when the guinea pig drinks from it. You would type "eat" for every time the guinea pig eats hay, and whenever the guinea pig eats a pellet you would type "pellet". The next time the guinea pig eats a pellet you would type "pellets" to close the loop, but the guinea pig needs to do something other than eat a pellet first before "pellets" can be used to close the loop.

Description

Skinny pig is similar to a turning tarpit because it uses a "wheel" that turns to execute commands.

These are the commands on the wheel.

#0 [ Increment the value at the top of the stack by 1. ]
#1 [ Push 97 onto the stack. ]
#2 [ Increment the value at the top of the stack by 10. ]
#3 [ Increment the value at the top of the stack by 100. ]
#4 [ Decrement the value at the top of the stack by 1. ]
#5 [ Print the ASCII character associated with the value at the top of the stack. ]
#6 [ Pop the value at the top of the stack off of the stack. ]

Whenever the wheel is turned, it moves to the next command. When the wheel turns after it is already on command 6, it goes back to command 0.

Commands

Command Outcome
drink Turn the wheel once.
eat Execute current command on the wheel.
stand Print the ASCII character associated with the value at the top of the stack.
poop Print the ASCII character associated with the value at the top of the stack.
scratch Sets the value at the top of the stack to equal one byte of input.
pellet Goes past the next "pellets" if the value of the cell the pointer is on is equal to 0.
pellets Goes to last "pellet" if the value of the cell the pointer is on is higher than 0.


Interpreter

Source code (Ruby)

eval '$m=Hash.new($p=0);b=0;'+ARGF.read.gsub(/[a-z][a-z0-9]*|./,
     'drink' => 'b+=1; b=0 if b>6;',
     'eat' => '$m[$p]+=1 if b==0; $p+=1 if b==1; $m[$p]=97 if b==1; $m[$p]+=10 if b==2; $m[$p]+=100 if b==3; $m[$p]-=1 if b==4; putc $m[$p] if b==5; $m[$p]=0 if b==6; $p-=1 if b==6;',
     'stand' => 'putc $m[$p];',
     'poop' => 'putc $m[$p];',
     'scratch' => '$m[$p]=STDIN.getbyte if !STDIN.eof;',
     'pellet' => '(',
     'pellets' => ')while(($m[$p]&=255)!=0);')
puts
p $m

(This interpreter prints the contents of the stack after the program terminates.)

Example programs

drink drink drink drink drink eat scratch scratch scratch eat eat eat eat eat

This program was generated by a video of real skinny pigs and a guinea pig. The program will print the third byte of input 5 times. For example, the input "12345" would output "33333".

eat eat eat drink drink eat drink eat drink drink eat eat scratch eat eat eat eat stand drink stand eat stand eat

This program was generated by two skinny pigs that were observed. The program first prints out "qq" then takes user input. After that, it outputs the first byte of input 6 times. This program is very similar to the first example program.

External Resources

The YouTube video used to generate the first example program