Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
16
Task/Mad-Libs/Nim/mad-libs.nim
Normal file
16
Task/Mad-Libs/Nim/mad-libs.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import rdstdin, re, algorithm, sequtils, strutils
|
||||
|
||||
#let templ = readLineFromStdin "Enter your story: "
|
||||
const templ = """<name> went for a walk in the park. <he or she>
|
||||
found a <noun>. <name> decided to take it home."""
|
||||
|
||||
echo "The story template is:\n", templ
|
||||
var fields = templ.findAll re"<[^>]+>"
|
||||
fields.sort(cmp)
|
||||
fields = deduplicate fields
|
||||
let values = readLineFromStdin("\nInput a comma-separated list of words to replace the following items\n " & fields.join(",") & ": ").split(",")
|
||||
|
||||
var story = templ
|
||||
for f,v in zip(fields, values).items:
|
||||
story = story.replace(f, v)
|
||||
echo "\nThe story becomes:\n\n", story
|
||||
Loading…
Add table
Add a link
Reference in a new issue