langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
4
Task/Mad-Libs/Perl-6/mad-libs.pl6
Normal file
4
Task/Mad-Libs/Perl-6/mad-libs.pl6
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $story = slurp(@*ARGS.shift);
|
||||
my %words;
|
||||
$story.=subst(/ '<' (.*?) '>' /, { %words{$0} //= prompt "$0? " }, :g );
|
||||
say $story;
|
||||
84
Task/Mad-Libs/Pike/mad-libs.pike
Normal file
84
Task/Mad-Libs/Pike/mad-libs.pike
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/pike
|
||||
|
||||
Stdio.Readline readln = Stdio.Readline();
|
||||
|
||||
void print_help()
|
||||
{
|
||||
write(#"Write a Story.
|
||||
|
||||
Names or objects in the story can be made variable by
|
||||
referencing them as <person> <object>, etc.
|
||||
End the story with an empty line.
|
||||
|
||||
Type show to read the story. You will be asked to fill the variables,
|
||||
and the the story will be shown.
|
||||
|
||||
Type help to see this message again.
|
||||
Type exit to quit.
|
||||
|
||||
");
|
||||
}
|
||||
|
||||
void add_line(string input)
|
||||
{
|
||||
array variables = parse_for_variables(input);
|
||||
write("Found variables: %{\"%s\" %}\n", variables);
|
||||
story += input+"\n";
|
||||
}
|
||||
|
||||
array parse_for_variables(string input)
|
||||
{
|
||||
array vars = Array.flatten(array_sscanf(input, "%*[^<>]%{<%[^<>]>%*[^<>]%}%*[^<>]"));
|
||||
return Array.uniq(vars);
|
||||
}
|
||||
|
||||
mapping fill_variables(string story)
|
||||
{
|
||||
array vars = parse_for_variables(story);
|
||||
mapping variables = ([]);
|
||||
foreach(vars;; string name)
|
||||
{
|
||||
string value = readln->read(sprintf("Please name a%s %s: ", (<'a','e','i','o','u'>)[name[1]]?"":"n", name));
|
||||
if (value != "")
|
||||
variables["<"+name+">"] = value;
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
void show_story(string story)
|
||||
{
|
||||
mapping variables = fill_variables(story);
|
||||
write("\n"+replace(story, variables));
|
||||
}
|
||||
|
||||
void do_exit()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
mapping functions = ([ "help":print_help,
|
||||
"show":show_story,
|
||||
"exit":do_exit,
|
||||
]);
|
||||
string story = "";
|
||||
|
||||
void main()
|
||||
{
|
||||
Stdio.Readline.History readline_history = Stdio.Readline.History(512);
|
||||
readln->enable_history(readline_history);
|
||||
|
||||
string prompt="> ";
|
||||
|
||||
print_help();
|
||||
while(1)
|
||||
{
|
||||
string input=readln->read(prompt);
|
||||
if(!input)
|
||||
exit(0);
|
||||
if(input == "")
|
||||
show_story(story);
|
||||
else if (functions[input])
|
||||
functions[input]();
|
||||
else add_line(input);
|
||||
}
|
||||
}
|
||||
13
Task/Mad-Libs/Run-BASIC/mad-libs.run
Normal file
13
Task/Mad-Libs/Run-BASIC/mad-libs.run
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
temp$="<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home."
|
||||
k = instr(temp$,"<")
|
||||
while k
|
||||
replace$ = mid$(temp$,k,instr(temp$,">")-k + 1)
|
||||
print "Replace:";replace$;" with:"; :input with$
|
||||
while k
|
||||
temp$ = left$(temp$,k-1) + with$ + mid$(temp$,k + len(replace$))
|
||||
k = instr(temp$,replace$,k)
|
||||
wend
|
||||
k = instr(temp$,"<")
|
||||
wend
|
||||
print temp$
|
||||
wait
|
||||
Loading…
Add table
Add a link
Reference in a new issue