Language Maple 11
| Date: | 06/21/07 |
| Author: | Stefan Vorkoetter |
| URL: | http://www.stefanv.com |
| Comments: | 0 |
| Info: | http://www.maplesoft.com |
| Score: |
module Sing()
local initialSize, what, where, bottles, action, ModuleApply;
bottles := proc( n::integer, { lowercase::truefalse := false } )
option remember;
if n < 0 then
bottles(initialSize)
elif n = 0 then
if lowercase then
StringTools:-LowerCase(procname(n))
else
"No more bottles"
fi
elif n = 1 then
"1 bottle"
else
"" || n || " bottles"
fi
end;
action := proc( n::integer )
if n = 0 then
"Go to the store and buy some more"
else
"Take one down and pass it around"
fi
end;
what := " of beer";
where := " on the wall";
ModuleApply := proc( packSize::integer := 99 )
local n;
initialSize := packSize;
for n from initialSize to 0 by -1 do
printf("%s%s%s, %s%s.\n",
bottles(n),what,where,bottles(n,lowercase),what);
printf("%s, %s%s%s.\n",action(n),bottles(n-1,lowercase),what,where);
if n > 0 then
printf("\n")
fi
od
end
end;
Sing();
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments