Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Mad-Libs/Wren/mad-libs.wren
Normal file
23
Task/Mad-Libs/Wren/mad-libs.wren
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import "io" for Stdin, Stdout
|
||||
import "/pattern" for Pattern
|
||||
import "/seq" for Lst
|
||||
|
||||
System.print("Please enter a multi-line story template terminated by a blank line:\n")
|
||||
Stdout.flush()
|
||||
var story = ""
|
||||
while (true) {
|
||||
var line = Stdin.readLine()
|
||||
if (line.isEmpty) break
|
||||
story = story + line + "\n" // preserve line breaks
|
||||
}
|
||||
// identify blanks
|
||||
var p = Pattern.new("<+0^>>")
|
||||
var blanks = Lst.distinct(p.findAll(story).map { |m| m.text }.toList)
|
||||
System.print("Please enter your replacements for the following 'blanks' in the story:")
|
||||
for (blank in blanks) {
|
||||
System.write(" %(blank[1..-2]) : ")
|
||||
Stdout.flush()
|
||||
var repl = Stdin.readLine()
|
||||
story = story.replace(blank, repl)
|
||||
}
|
||||
System.print("\n%(story)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue