99 Bottles of Beer/Scala: Difference between revisions
Content added Content deleted
(ParRange) |
(Previous version failed with line spacing) |
||
Line 2: | Line 2: | ||
The trivial solution to it would be this: |
The trivial solution to it would be this: |
||
<lang scala>99 to 1 by -1 foreach {n => |
<lang scala>99 to 1 by -1 foreach { n => |
||
println( |
println( |
||
f"$n%d bottles of beer on the wall\n" + |
|||
f"$n%d bottles of beer\n" + |
|||
f"Take one down, pass it around\n" + |
|||
f"${n - 1}%d bottles of beer on the wall\n") |
|||
}</lang> |
|||
The above running in |
The above running in parallel using a ParRange, fast but shuffles the output. |
||
<lang scala>(99 to 1 by -1).par foreach {n => |
<lang scala>(99 to 1 by -1).par foreach { n => |
||
println( |
println( |
||
f"$n%d bottles of beer on the wall\n" + |
|||
f"$n%d bottles of beer\n" + |
|||
f"Take one down, pass it around\n" + |
|||
f"${n - 1}%d bottles of beer on the wall\n") |
|||
}</lang> |
|||
A Regex solution: |
A Regex solution: |