View difference between Paste ID: SL3VFGJ3 and JxDZcGUh
SHOW: | | - or go back to the newest paste.
1
        def collatz(n:Int):Array[Int] = {
2
            val result = if (n!=1){
3
                n match{
4-
                    case i if i%2==0 => n::collatz(i/2).toList
4+
                    case n if n%2==0 => n::collatz(n/2).toList
5-
                    case i           => n::collatz(3*i+1).toList
5+
                    case n           => n::collatz(3*n+1).toList
6
                }
7
            } else {
8
                List(1)
9
            }
10
11
            result.toArray
12
        }