Tag Info

Hot answers tagged

1

x is just your starting value for the iteration. The function to apply, and the stopping condition, should both be applied to the current value obtained by the iteration, and are probably best expressed using pure functions: collatz[x_] := NestWhileList[If[Mod[#, 2] == 0, #/2, #*3 + 1] &, x, # != 1 &] collatz[5] (* Out: {5, 16, 8, 4, 2, 1} *) ...



Only top voted, non community-wiki answers of a minimum length are eligible