45 lines
944 B
Scala
45 lines
944 B
Scala
import scala.io.Source
|
|
|
|
def getTotalSize(strings: List[String]): Int = {
|
|
(0 /: strings) {(sum, string) => sum + string.size}
|
|
}
|
|
|
|
val list = List("123", "345", "ABN")
|
|
|
|
val bla = getTotalSize(list)
|
|
println(bla)
|
|
|
|
trait Censor {
|
|
var corrections = Map("Shoot" -> "Pucky", "Darn" -> "Beans")
|
|
|
|
|
|
def readCorrections() = {
|
|
val filename = "corrections.txt"
|
|
|
|
for (line <- Source.fromFile(filename).getLines) {
|
|
val splitted = line.split("#")
|
|
corrections = corrections + (splitted(0) -> splitted(1))
|
|
}
|
|
}
|
|
|
|
def correct(input: String): String = {
|
|
var output = input;
|
|
|
|
corrections.foreach((e: (String, String)) => output = e._1.r.replaceAllIn(output, e._2))
|
|
|
|
return output
|
|
}
|
|
}
|
|
|
|
class Corrector extends Censor {
|
|
def say(input: String) = {
|
|
val output = correct(input)
|
|
println(output)
|
|
}
|
|
}
|
|
|
|
val hering = new Corrector()
|
|
hering.readCorrections()
|
|
hering.say("I'm a fish, blub blub")
|
|
hering.say("Shoot Darn")
|