A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
11
Task/Hailstone-sequence/Scala/hailstone-sequence.scala
Normal file
11
Task/Hailstone-sequence/Scala/hailstone-sequence.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def hailstone(n: Int): Stream[Int] =
|
||||
n #:: {
|
||||
if (n == 1) Stream.empty
|
||||
else hailstone(if (n % 2 == 0) n / 2 else n * 3 + 1)
|
||||
}
|
||||
|
||||
def main(args: Array[String]) {
|
||||
println(hailstone(27).toList)
|
||||
val (n, len) = (1 to 100000).map(n => (n, hailstone(n).length)).maxBy(_._2)
|
||||
println("value=" + n + " len=" + len)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue