Mad Libs: Difference between revisions
Content deleted Content added
m Remove a pointless comment that was accidentally left in C solution |
Made more functional |
||
Line 1,080: | Line 1,080: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
Like some other examples, this prompts the user for a filename for a story template rather than reading the story in from user input. |
Like some other examples, this prompts the user for a filename for a story template rather than reading the story in from user input. |
||
<lang Mathematica> |
<lang Mathematica>text = Import[ |
||
InputString["Enter the filename of the story template:"]]; |
|||
text = Import[filename]; |
|||
answers = |
|||
⚫ | |||
InputString[ |
|||
listofanswers = {}; |
|||
"Enter a" <> |
|||
Do[ |
|||
If[StringMatchQ[#, Alternatives @@ Characters["aeiou"] ~~ ___], |
|||
answer = InputString["Enter a/an: " <> listofblanks[[i]]]; |
|||
"n", ""] <> " " <> # <> ":"] & /@ |
|||
AppendTo[listofanswers, answer]; |
|||
⚫ | |||
, {i, 1, Length[listofblanks]} |
|||
"<" | ">"]; |
|||
] |
|||
Print[ToString[ |
|||
Do[ |
|||
StringForm @@ |
|||
text = StringReplace[text, listofblanks[[i]] -> listofanswers[[i]]] |
|||
Prepend[answers, |
|||
, {i, 1, Length[listofblanks]} |
|||
StringReplace[text, RegularExpression["<[^>]+>"] -> "``"]]]];</lang> |
|||
] |
|||
text</lang> |
|||
{{out}} |
{{out}} |
||
<pre>George went for a walk in the park. he |
<pre>George went for a walk in the park. he |