Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def collatz(n:Int):Array[Int] = {
- val result = if (n!=1){
- n match{
- case i if i%2==0 => n::collatz(i/2).toList
- case i => n::collatz(3*i+1).toList
- }
- } else {
- List(1)
- }
- result.toArray
- }
Advertisement
Add Comment
Please, Sign In to add comment