Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Mad-Libs/Scala/mad-libs.scala
Normal file
14
Task/Mad-Libs/Scala/mad-libs.scala
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
object MadLibs extends App{
|
||||
val input = "<name> went for a walk in the park. <he or she>\nfound a <noun>. <name> decided to take it home."
|
||||
println(input)
|
||||
println
|
||||
|
||||
val todo = "(<[^>]+>)".r
|
||||
val replacements = todo.findAllIn(input).toSet.map{found: String =>
|
||||
found -> readLine(s"Enter a $found ")
|
||||
}.toMap
|
||||
|
||||
val output = todo.replaceAllIn(input, found => replacements(found.matched))
|
||||
println
|
||||
println(output)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue