Last active
October 29, 2021 05:25
-
-
Save RandoPerso/8c12f67dd29437b09d7a24a5eb7d41ec to your computer and use it in GitHub Desktop.
NDBall code designed to be a 4-function calculator. This first input is the operation of choice. The other inputs are the numbers to be used. Since NDBall can only handle integers from 0-255, division rounds down.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Ask for operation and send the ball to the proper coordinate on the (0-indexed) 2nd dimension. | |
/First, move the ball out of the way into a safe place. | |
(0) >4 | |
{4,1} >0 | |
{0,1|4,1} $ | |
/Checks if the input is "*" or anything with a lower ASCII value (which is an invalid input). If it is, send the ball to the multiplication calculator, else send the ball to the next check. | |
{0,2|4,1} Y[43,>2,>0] | |
(2,0,3,0,1) <0 | |
(0,0,3,0,1) <4 | |
{2,3} >3 | |
/Does the same as the previous part, but it checks for "+" and sends the ball to the addition calculator if it is. | |
{0,3|4,1} Y[44,>2,>0] | |
(3,0,1,0,1) <0 | |
{2,1|4,1} <4 | |
/Does the same as the previous part, but it checks for "-" and sends the ball to the subtraction calculator if it is. | |
{0,4|4,1} Y[46,>2,>1] | |
(4,0,2,0,1) <0 | |
{2,2|4,1} <4 | |
/This check is technically unneccesary, but this does the same as the previous part, but it checks for "/" and sends the ball to the division calculator if it is. | |
(4,1,0,0,1) Y[48,>2,>1] | |
(4,1,4,0,1) <0 | |
(0,1,4,0,1) <1 | |
(0,0,4,0,1) <4 | |
/Start of the addition calculator. | |
/Ask for 2 inputs. It stores one of the inputs in the apioform hive and stores the other in the ball. | |
(0,0,1) >0 | |
(1,0,1) % | |
(2,0,1) n | |
(3,0,1) % | |
(4,0,1) >1 | |
/Main loop. | |
(4,1,1) >1 | |
/Check if the ball's value is less than 1. | |
(4,2,1) Y[1,>1,<0] | |
/False, the ball has a value of 1 or more: | |
/Subtract one from the ball and add an apioform to the hive. After that, send the ball back to the check. | |
(3,2,1) - | |
(2,2,1) a | |
(1,2,1) <1 | |
(1,1,1) >0 | |
/True, the ball's value is less than 0: | |
/Print the number of apioforms in the hive by storing the number of apioforms into the ball and printing the balls value. | |
(4,3,1) H | |
(4,4,1) <0 | |
(3,4,1) P | |
(2,4,1) E | |
/Start of the subtraction calculator. This is the same as the addition calculator, but it removes apioforms from the hive rather than adding them. | |
(0,0,2) >0 | |
(1,0,2) % | |
(2,0,2) n | |
(3,0,2) % | |
(4,0,2) >1 | |
(4,1,2) >1 | |
(4,2,2) Y[1,>1,<0] | |
(3,2,2) - | |
(2,2,2) f | |
(1,2,2) <1 | |
(1,1,2) >0 | |
(4,3,2) H | |
(4,4,2) <0 | |
(3,4,2) P | |
(2,4,2) E | |
/Start of the multiplication calculator. | |
/NOTE: The ball is moving in the direction >3 at the start of the program. | |
/Ask for the first input and store that in the #<3 at (1,1,3,2). This will be called #A. | |
(0,0,3,2) % | |
(0,0,3,3) >1 | |
(0,1,3,3) >0 | |
(1,1,3,3) <3 | |
(1,1,3,2) #<3 | |
(1,1,3,1) <1 | |
(1,0,3,1) >3 | |
(1,0,3,2) >0 | |
/Ask for the second input and store that in the #<0 at (3,1,3,2). This will be called #B. | |
(3,0,3,2) % | |
(4,0,3,2) >1 | |
(4,1,3,2) <0 | |
(3,1,3,2) #<0 | |
/Main loop. | |
/Check if the ball's value (#B) is less than 1. | |
(2,1,3,2) Y[1,>1,<0] | |
/False, the ball's value (#B) is 1 or more. | |
/Take the value from #A and store it into the ball. | |
(0,1,3,2) >1 | |
/Check if the ball's value is less than 1. | |
(0,2,3,2) Y[1,<3,>1] | |
/False, the ball's value is 1 or more: | |
/Add an apioform to the apioform hive and subtract 1 from the ball's value. Go back to the previous check after that. | |
(0,3,3,2) a | |
(0,4,3,2) >0 | |
(1,4,3,2) <1 | |
(1,3,3,2) - | |
(1,2,3,2) <0 | |
/True, the ball's value is less than 1: | |
/Send the ball back to #B and take its value. Subtract 1 from that and set that value into #B. Go back to the check at (2,1,3,2) | |
(0,2,3,1) >0 | |
(3,2,3,1) <1 | |
(3,1,3,1) >3 | |
(3,1,3,3) >1 | |
(3,2,3,3) - | |
(3,3,3,3) >0 | |
(4,3,3,3) <1 | |
(4,1,3,3) <3 | |
/True, the ball's value (#B) is less than 1: | |
/Take the number of apioforms in the hive and print that value. | |
(2,2,3,2) H | |
(2,3,3,2) P | |
(2,4,3,2) E | |
/Start of the division calculator. | |
/Ask for the first input and temporaily store that in the swap cell at (2,2,4,3). This will be called the s-cell. | |
(0,0,4) >3 | |
(0,0,4,3) >0 | |
(1,0,4,3) % | |
(2,0,4,3) >1 | |
(2,2,4,3) s | |
/Ask for the second input and store that into the #<1 at (4,3,4,3). This will be called #. | |
(2,4,4,3) >0 | |
(3,4,4,3) % | |
(4,4,4,3) <1 | |
(4,3,4,3) #<1 | |
/Check if the ball's value is less than 1. | |
(4,2,4,3) Y[1,<1,<0] | |
/False, the ball's value is 1 or more: | |
/Subtract one from the balls value and take the value of the s-cell. | |
(3,2,4,3) - | |
/Note: The s-cell would be right here. | |
/Check if the value of the ball (s-cell) is less than 1. | |
(1,2,4,3) Y[1,<3,<0] | |
/False, the value of the ball (s-cell) is 1 or more: | |
/Subtract 1 from the ball's value (s-cell) and swap values with the s-cell. Go back to the check on (4,2,4,3). | |
(0,2,4,3) >3 | |
(0,2,4,4) >0 | |
(1,2,4,4) - | |
(2,2,4,4) <3 | |
/Note: The s-cell would be right here. | |
(2,2,4,2) >0 | |
(4,2,4,2) >3 | |
/True, the ball's value (s-cell) is less than 1: | |
/Take the number of apioforms in the hive and print that number. | |
(1,2,4,2) H | |
(1,2,4,1) P | |
(1,2,4,0) E | |
/True, the ball's value is less than 1: | |
/Add an apioform to the hive, take the value of #, and return back to the check on (4,2,4,3). | |
(4,1,4,3) a | |
(4,0,4,3) >3 | |
(4,0,4,4) >1 | |
(4,3,4,4) <3 | |
(4,3,4,2) <1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment