Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The Collatz conjecture in Nim
import strutils as su
echo "Enter a number greater than 1: "
var input: string = readLine(stdin)
if (not su.isDigit(input)):
echo "ERROR: You must enter a number."
let num: int = parseInt(input)
var count = 0
var n: int = num
if (n > 1):
while (n != 1):
if (n mod 2 == 0):
n = n div 2
n = (n * 3) + 1
count += 1
echo "You started with the number ", num, " and it took ", count, " steps to get to 1."
echo "ERROR: You must enter a number that is greater than 1."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment