How to resolve the algorithm Mad Libs step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mad Libs step by step in the zkl programming language

Table of Contents

Problem Statement

Mad Libs is a phrasal template word game where one player prompts another for a list of words to substitute for blanks in a story, usually with funny results.

Write a program to create a Mad Libs like story. The program should read an arbitrary multiline story from input. The story will be terminated with a blank line. Then, find each replacement to be made within the story, ask the user for a word to replace it with, and make all the replacements. Stop when there are none left and print the final story.

The input should be an arbitrary story in the form: Given this example, it should then ask for a name, a he or she and a noun ( gets replaced both times with the same value).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Mad Libs step by step in the zkl programming language

Source code in the zkl programming language

story,line,re:=Data(),"",RegExp("(<[^>]+>)");
do{ line=ask("Story: "); story.write(line,"\n") }while(line);
while(re.search(story,True)){ 
   z,ml,N:=re.matched,z[1],z[0][1]; // z=( (0,6),"" )
   s:=ask("Text to replace ",ml," with: ");
   while(Void!=(n:=story.find(ml))){ story[n,N]=s } // replace all s
}
println("-----------------");
story.text.print();

  

You may also check:How to resolve the algorithm Thue-Morse step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Documentation step by step in the Fortran programming language
You may also check:How to resolve the algorithm Intersecting number wheels step by step in the REXX programming language
You may also check:How to resolve the algorithm Totient function step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Soundex step by step in the PicoLisp programming language