math - Ruby while loop only executes once -
This code is not working. I am trying to code the codeet, but the code is only for input Runs 1 time It prints from 4, 1, 1 and it shows that it only moves for one step. The second block is never executed Can someone tell me what is wrong with this Ruby Code? I do not know how this is not working. You have a Try which gives 3 and prints And if you want to make your code a bit cleaner and more idioms, then you can reflection it as follows: return statement that is executing the executable after the loop first runs.
Square Collatz def collatz (number) 0 if number == 1 step = 0 while the number> 1 if the number% 2 puts the points == 0 / = 2 puts the step + = 1 and the number = (number * 3) + 1 puts the step + step = end end of the end phase phase end = collatz Returns the .new.collatz (8) step
4 1 2 2 1 3 [Finished 0.4]]
class Collatz def collatz (number) 0 if the number = = 1 step = 0 while the number & gt; 1 number = number as well? ? Number / 2: (number * 3) + 1 points, phase + = 1 end end of end phase end = Collatz.new.collatz (8) # 4 # 1 # 2 # 2 # 1 # 3 # = & gt; ; 3
Comments
Post a Comment