parent
999f34d71f
commit
f73f01f616
@ -0,0 +1,2 @@
|
|||||||
|
stupid=jolly
|
||||||
|
vermin=furball
|
@ -0,0 +1,43 @@
|
|||||||
|
package day2
|
||||||
|
import java.util.Properties
|
||||||
|
import scala.collection.JavaConverters._
|
||||||
|
import scala.io.Source
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
|
trait Censor {
|
||||||
|
val substitutions : Map[String, String]
|
||||||
|
val source : String
|
||||||
|
override def toString(): String = {
|
||||||
|
source
|
||||||
|
.split(" ")
|
||||||
|
.map((word) => substitutions.getOrElse(word, word))
|
||||||
|
.mkString(" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object CensorRun extends App {
|
||||||
|
val chars = new Censor {
|
||||||
|
val substitutions = Map(
|
||||||
|
"shoot" -> "pucky",
|
||||||
|
"darn" -> "beans",
|
||||||
|
)
|
||||||
|
val source = "shoot that darn truck"
|
||||||
|
}
|
||||||
|
println(chars)
|
||||||
|
}
|
||||||
|
|
||||||
|
object CensorFromFile extends App {
|
||||||
|
val loadedSubstitutions = Using.Manager {use =>
|
||||||
|
val props = new Properties()
|
||||||
|
val input = use(Source.fromResource("alternatives.properties").reader())
|
||||||
|
props.load(input)
|
||||||
|
|
||||||
|
props.asScala.toMap
|
||||||
|
}.getOrElse(Map())
|
||||||
|
|
||||||
|
val chars = new Censor {
|
||||||
|
val substitutions = loadedSubstitutions
|
||||||
|
val source = "That stupid vermin did it again"
|
||||||
|
}
|
||||||
|
println(chars)
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package day2
|
||||||
|
|
||||||
|
object FullList extends App {
|
||||||
|
|
||||||
|
val strings = List(
|
||||||
|
"Earth",
|
||||||
|
"Fire",
|
||||||
|
"Wind",
|
||||||
|
"Water",
|
||||||
|
"Heart"
|
||||||
|
)
|
||||||
|
|
||||||
|
val total = strings.map(_.length()).foldLeft(0)((acc, len) => acc + len)
|
||||||
|
|
||||||
|
println(total)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue