cwtests/cw02/collatz.while
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 04 Sep 2021 14:08:00 +0100
changeset 833 aad5957eb7e4
child 856 23273e3a120f
permissions -rw-r--r--
cwupdates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
833
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
write "Input a number ";
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
read n;
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
while n > 1 do {
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
  if n % 2 == 0 
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
  then n := n/2 
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  else n := 3*n+1
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
};
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
write "Yes"