Sha256: 1a82b971526ee25799e19506fb2f1d0209189572c51cc6b5334e1a452c00aa78

Contents?: true

Size: 233 Bytes

Versions: 124

Compression:

Stored size: 233 Bytes

Contents

return function(n)
  assert(n > 0, 'Only positive numbers are allowed')

  local steps = 0

  while n > 1 do
    if n % 2 == 0 then
      n = n / 2
    else
      n = 3 * n + 1
    end
    steps = steps + 1
  end

  return steps
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.179 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.178 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.177 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.176 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.175 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.174 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.173 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.172 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.171 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.170 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.169 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.167 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.166 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.165 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.164 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.163 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.162 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.161 tracks/lua/exercises/collatz-conjecture/example.lua
trackler-2.2.1.160 tracks/lua/exercises/collatz-conjecture/example.lua