# Grin

From Esolang

**Grin** is an esoteric programming language by User:Madk based on brainfuck and named for the frequent occurrence of smiling emoticons. Its intention is to provide the fun of BrainFuck with more powerful maths. Despite some differences in the language, any BrainFuck program can be converted into a Grin program by replacing the "+"s with "}" and the "-"s with "{".

## Contents

## Commands

A "#" denotes the beginning and end of a comment.

> shift memory cell right < shift memory cell left . output the content of this memory cell as an ASCII character : output the content of this cell as a number. , set this memory cell's value to the ASCII value of input ; set this memory cell's value to a number inputted ' output the register as an ASCII character " output the register as a number + add this memory cell to the value in the register and put the answer in this memory cell - subtract the value in the register from the value in this memory cell * multiply this memory cell by the value in the register / divide this memory cell by the value in the register ^ raise this memory cell to the exponent in the register $ store the current memory cell in the register \ store the value that's in the register in the current memory cell ~ swap the value in the register and the current memory cell = set the register to 0 _ set the memory cell under the pointer to 0 % current memory cell is modulo'd by the value in the register r round the memory cell to the nearest integer & perform a logical NAND on the memory cell and the register | perform a logical OR on the memory cell and the register ! perform a logical NOT on the memory cell @ Negate the memory cell under the pointer [ jump past the matching ] if the current memory cell is 0 ] jump back to the matching [ if the current memory cell is not 0 ? If the cell under the pointer is >0 it becomes 1 and if it's <0 it becomes -1 } increment the memory cell under the pointer by 1 { decrement the memory cell under the pointer by 1 ( print all characters up to the next ) to the console ) print a newline s put the sine of the number in the current memory cell in the current memory cell c calculate the cosine of the current memory cell t calculate the tangent of the current memory cell S calculate the arcsine of the current memory cell C calculate arccos T calculate arctan 1 divides 1 by the current memory cell and places it there 2 performs modulo 2 on the current memory cell e sets the current cell's value to e p sets the current cell's value to pi l takes the natural log of the current cell and stores it there m stores the arithmatic mean of the current cell and the register in this cell q takes the square root of the current memory cell and places it there L takes the log of the current cell using the register as the base and puts it in the cell j if the register is >0 the program skips the number of instructions specified by the register, if a decimal is specified the number is rounded down D toggles following trigonometric functions to operate on degrees or radians; degrees is the default ` end the program

## Examples

### Hello, world!

(Hello, world!)

### 99 bottles of beer

}}$^^*$++}}}[}}:( bottles of beer on the wall,)):( bottles of beer.)) (Take one down, pass it around.)){:( bottles of beer on the wall.)){{]} :( bottle of beer on the wall,)):( bottle of beer.)) (Take it down, pass it around.))(No more bottles of beer on the wall.)) (No more bottles of beer on the wall,))(No more bottles of beer.)) }$^^*$++}}}(Go to the store and buy some more.)):( bottles of beer on the wall.))

### Cat

.,

### Fibonacci sequence

(Calculate how many numbers of the Fibonacci sequence?));) >:)>}:)<<[{>$>>\<$>+:)<$<\>>$<\<<]

### Collatz sequence

<}[>(Calculate a Collatz sequence of what number?));)<} [<}>>$:)>\2$>\![_}}$<</>>_]<[_}}}$<*}>_]<$<\{])<(Steps: ):))>(Again? [1/0] ))<;)]

### Juggler sequence

<}[>(Calculate the Juggler sequence of what number?));)<} [<}>>$:)>\2$>\![_}}1$<<^>>_]<[_}}$}/$<^>_]<:( -> )$<<<<<< \<\<\r$>-$[>-$<_]@[>-{$<_][@]@![>$<_]>>>>>}>>\>\<{]_}:)<< (Steps: ):))>>(Again? [1/0] ))<;)]

### Factorial

}[>(What number would you like to determine the factorial of?)); >_}<[$>*<{]>>(Answer: ):))(Again? [1/0]))<;)]`

### Round a decimal

}[>(Round up [0] or down [1]? );$>\!>(Input the number you want to round. );) $>\>\r$<-$[<-<[>}<_]>$>_]@[<-<<[>>{<<_]>>$>_][@]@![<$>_](Answer: )"))<<(Again? [0/1] );))]

### Area of a circle

}[(Input the radius of the circle you wish to find the area of. );) >_}}$p<^$>*(Answer: ):( sq. units)))<(Again? [0/1] );)]

### Distance calculation

(This program will find the distance between two coordinates in 3D space.))) (Please input [X1].y1..z1..x2..y2..z2.));>) (Please input .x1.[y1].z1..x2..y2..z2.));>) (Please input .x1..y1.[z1].x2..y2..z2.));>) (Please input .x1..y1..z1.[x2].y2..z2.));>) (Please input .x1..y1..z1..x2.[y2].z2.));>) (Please input .x1..y1..z1..x2..y2.[z2]));) <<<$<<<-$*>$>>>-$*>$<<<-$*$<<+$>>>>+>_}}1$<^ (Distance: ):)