Created
October 25, 2009 19:21
-
-
Save liesen/218202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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