How is it possible to write the snail program without conditionals or loops?!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How is it possible to write the snail program without conditionals or loops?!?

Coding without loops and conditionals...is that possible?

26th Mar 2018, 1:49 PM
Gregory Triplett
Gregory Triplett - avatar
5 Answers
+ 3
Loops can be replaced by recursion. Conditionals aren't easy to get rid of. I'd need to see the program to give any further advice.
26th Mar 2018, 1:56 PM
John Wells
John Wells - avatar
+ 2
Finally got around to finding out what snail program is. Simple equation is all you need. ceiling((height-climb)/(climb-fall)+1) given all positive data (force float math.) negative or divide by zero for impossible.
28th Mar 2018, 9:09 PM
John Wells
John Wells - avatar
+ 1
With the given prohibitions, I wrote no code...I did not know where to start. On paper, I played with the idea if a function that would create a variable which would be named according to how many times the function had been called...plus one. When the function returned 0, display the variable name stripped of all non-numeric characters. But somewhere inside there the total height minus the daily height must be compared to 0 and an action taken based on the result. I don't see another way. I will try recursion and get post the code here. Give me a day, please.
26th Mar 2018, 2:07 PM
Gregory Triplett
Gregory Triplett - avatar
+ 1
Use an equation to mathematically calculate the distance
26th Mar 2018, 10:29 PM
Ariela
Ariela - avatar
0
Ok...if by distance you mean 'net distance per day, that is part of it. You have to use that value and the 'height of the tree' value, supplied by the user, to find the 'days'.
28th Mar 2018, 12:24 PM
Gregory Triplett
Gregory Triplett - avatar