Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

The Collatz conjecture

The Collatz conjecture

The Collatz conjecture, named after Lothar Collatz who introduced the idea is a perfect example of a mathematical problem that cannot be solved by mathematics and the tools available within the domain and scope of mathematics of today.

It goes a little like this:

$${\displaystyle f(n)={\begin{cases}{\frac {n}{2}}&{\text{if }}n\equiv 0{\pmod {2}}\\[4px]3n+1&{\text{if }}n\equiv 1{\pmod {2}}.\end{cases}}}$$

it's a nice little conjecture to turn into a program, so I decided to write it in YASS to try and demonstrate this based on the above syntax:

YASS
function f ($n)

  if($n % 2 == 0)
    $n = $n / 2
  else
    $n = ($n * 3) + 1
  end if

  return $n

end function

$n = input("Please insert a start number")

$iterations = 0
print($n)
while($n != 0 and $iterations < 5)
  
  $n = f($n)

  print($n)
  if($n == 1)
    $iterations++
  end if
end while
Posted by jamiebalfour04 in Tech talk
Comments
Powered by DASH 2.0