Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
name := "Abbreviations-automatic"
|
||||
scalaVersion := "2.13.0"
|
||||
version := "0.1"
|
||||
|
||||
homepage := Some(url("http://rosettacode.org/wiki/Abbreviations,_automatic#Scala"))
|
||||
|
||||
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.3.0"
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
object AbbreviationsAuto extends App {
|
||||
private val wd = os.pwd
|
||||
|
||||
def processLine(line: String): String = {
|
||||
if (line.nonEmpty) {
|
||||
val days = line.split(' ')
|
||||
val maxL = days.map(_.length).max
|
||||
val paddedNames = days.map(s => s.padTo(maxL, ' '))
|
||||
|
||||
def uniqueN = (1 to maxL) // distinct filters uniques
|
||||
.map(n => paddedNames.map(_.substring(0, n)).distinct)
|
||||
.filter(_.size == paddedNames.length) // `.distinct` filters uniques
|
||||
.head.head.length
|
||||
|
||||
f"$uniqueN%3d $line" // Return by means of String Interpolation
|
||||
} else " \"\""
|
||||
}
|
||||
|
||||
os.read.lines(wd / "days_of_week.txt")
|
||||
.distinct
|
||||
.foreach(line => println(processLine(line)))
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue