progs/collatz.scala
author Christian Urban <urbanc@in.tum.de>
Tue, 08 Nov 2016 10:30:42 +0000
changeset 15 52713e632ac0
parent 11 417869f65585
child 18 87e55eb309ed
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     1
// Part 1 about the 3n+1 conceture
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     2
//=================================
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     5
//(1) Complete the collatz function below. It should
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     6
//    recursively calculate the number of steps needed 
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     7
//    until the collatz series reaches the number 1.
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     8
//    If needed you can use an auxilary function that
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     9
//    performs the recursion. The function should expect
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    10
//    arguments in the range of 1 to 10 Million.
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    12
def collatz(n: Long): Int = ...
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    15
//(2)  Complete the collatz bound function below. It should
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    16
//     calculuate how many steps are needed for each number 
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    17
//     from 1 upto a bound and return the maximum number of
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    18
//     steps. You should expect bounds in the range of 1
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    19
//     upto 10 million. 
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    20
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    21
def collatz_max(bnd: Int): Int = ...
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23