templates1/collatz.scala
author Christian Urban <urbanc@in.tum.de>
Wed, 24 Jul 2019 15:18:44 +0100
changeset 267 10a2ef26a92c
parent 266 31e5218f43de
child 281 32dfd2ca577b
permissions -rw-r--r--
updated myassert workaround
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     1
// Basic Part about the 3n+1 conjecture
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
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.
127
01d522ba48d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 39
diff changeset
     8
//    If needed, you can use an auxiliary function that
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
     9
//    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
    10
//    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
    11
129
1b0f1573c27c updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    12
//def collatz(n: Long) : Long = ...
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
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    15
//(2) Complete the collatz_max function below. It should
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    16
//    calculate how many steps are needed for each number 
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    17
//    from 1 up to a bound and then calculate the maximum number of
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    18
//    steps and the corresponding number that needs that many 
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    19
//    steps. Again, you should expect bounds in the range of 1
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    20
//    up to 1 Million. The first component of the pair is
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    21
//    the maximum number of steps and the second is the 
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    22
//    corresponding number.
15
52713e632ac0 updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    23
129
1b0f1573c27c updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
    24
//def collatz_max(bnd: Long) : (Long, Long) = ...
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
199
2e13dedd922e updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    27