templates/collatz.scala
author Christian Urban <urbanc@in.tum.de>
Tue, 07 Nov 2017 13:08:18 +0000
changeset 127 b4def82f3f9f
parent 39 progs/collatz.scala@c6fe374a5fca
child 129 b1a51285de7e
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
     1
// Part 1 about the 3n+1 conjecture
15
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
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
     4
object CW6a {
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     6
//(1) Complete the collatz function below. It should
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     7
//    recursively calculate the number of steps needed 
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     8
//    until the collatz series reaches the number 1.
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
     9
//    If needed, you can use an auxiliary function that
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    10
//    performs the recursion. The function should expect
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 18
diff changeset
    11
//    arguments in the range of 1 to 1 Million.
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    13
//def collatz(n: Long): ... = ...
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    16
//(2)  Complete the collatz bound function below. It should
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    17
//     calculate how many steps are needed for each number 
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    18
//     from 1 up to a bound and then calculate the maximum number of
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 15
diff changeset
    19
//     steps and the corresponding number that needs that many 
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    20
//     steps. Again, you should expect bounds in the range of 1
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    21
//     up to 1 Million. The first component of the pair is
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 15
diff changeset
    22
//     the maximum number of steps and the second is the 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 15
diff changeset
    23
//     corresponding number.
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    24
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    25
//def collatz_max(bnd: Long): (Long, Long) = ...
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
    28
}