Skip to content

Instantly share code, notes, and snippets.

@aoi0308
Created March 24, 2012 16:25
Show Gist options
  • Save aoi0308/2184835 to your computer and use it in GitHub Desktop.
Save aoi0308/2184835 to your computer and use it in GitHub Desktop.
コップ本第2版のP.76のプログラムを少しいじったもの
import scala.io.Source
def widthOfLength(s: String): Int = s.length.toString.length
if (args.length == 0) {
Console.err.println("Please enter filename")
sys.exit(-1)
}
val lines = Source.fromFile(args(0)).getLines().toList
val maxWidth = lines.map(widthOfLength).max
val output = lines.map {line =>
val padding = " " * (maxWidth - widthOfLength(line))
padding + line.length + " | " + line
}
println(output.mkString("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment