Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -1,19 +1,20 @@
object HailstoneSequence extends App { // Show it all, default number is 27.
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 hailstone(n: Int): LazyList[Int] =
n #:: (if (n == 1) LazyList.empty else hailstone(if (n % 2 == 0) n / 2 else n * 3 + 1))
Hailstone.details(args.headOption.map(_.toInt).getOrElse(27))
HailTest.main(Array())
}
object Hailstone extends App { // Compute a given or default number to Hailstone sequence
def details(nr: Int) = {
def details(nr: Int): Unit = {
val collatz = HailstoneSequence.hailstone(nr)
println(s"Use the routine to show that the hailstone sequence for the number: $nr.")
println(collatz.toList)
println(s"It has ${collatz.length} elements.")
}
details(args.headOption.map(_.toInt).getOrElse(27))
}