Skip to content

Instantly share code, notes, and snippets.

@liesen
Created October 25, 2009 19:21
Show Gist options
  • Save liesen/218202 to your computer and use it in GitHub Desktop.
Save liesen/218202 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/questions/1376077/code-golf-the-wave
object Wave {
def main(args: Array[String]) {
val s = if (!args.isEmpty) args(0) else "31415926535897932384626433832795028841971693993751058209749445923078164062862"
val (ls, _) = ((Map() + 0 -> s.substring(0, 1), 0) /: s.toList.zipWithIndex.tail) {
case ((ls, y), (c, i)) =>
val d = y + (c compare s(i - 1))
((ls + d -> (ls.getOrElse(d, "") match { case z => z + (" " * (i - z.length)) + c })), d)
}
println(ls.keys.toList sort { _ > _ } map ls mkString "\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment