Modulinos: Difference between revisions

(Added Coffeescript)
Line 1,629:
Test: The meaning of life is 42</lang>
 
=={{header|Scala}}==
===Unix version===
<lang bash>#!/bin/sh
exec scala "$0" "$@"
!#
def hailstone(n: Int): Stream[Int] =
n #:: (if (n == 1) Stream.empty else hailstone(if (n % 2 == 0) n / 2 else n * 3 + 1))
 
val nr = argv.headOption.map(_.toInt).getOrElse(27)
val collatz = 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.")</lang>
===Windows cmd.exe interpretation===
<lang winbatch>::#!
@echo off
call scala %0 %*
pause
goto :eof
::!#
def hailstone(n: Int): Stream[Int] =
n #:: (if (n == 1) Stream.empty else hailstone(if (n % 2 == 0) n / 2 else n * 3 + 1))
 
val nr = argv.headOption.map(_.toInt).getOrElse(27)
val collatz = 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.")
</lang>{{out}}<pre>C:\>Hailstone.cmd 42
Use the routine to show that the hailstone sequence for the number: 42.
List(42, 21, 64, 32, 16, 8, 4, 2, 1)
It has 9 elements.</pre>
=={{header|Tcl}}==
<lang tcl>proc main {args} {
Anonymous user