RosettaCodeData/Task/Execute-HQ9+/Phix/execute-hq9+-1.phix
2016-12-05 23:44:36 +01:00

32 lines
970 B
Text

constant ninetynine = 99 -- (set this to 9 for testing)
function bottles(integer count)
if count=0 then return "no more bottles"
elsif count=1 then return "1 bottle" end if
if count=-1 then count = ninetynine end if
return sprintf("%d bottles",count)
end function
function bob(integer count)
return bottles(count)&" of beer"
end function
function up1(string bob)
-- Capitalise sentence start (needed just the once, "no more"=>"No more")
bob[1] = upper(bob[1])
return bob
end function
procedure ninetyninebottles()
string this = bob(ninetynine)
string that = "Take one down, pass it around,\n"
for i=ninetynine to 0 by -1 do
puts(1,up1(this)&" on the wall,\n")
puts(1,this&".\n")
if i=0 then that = "Go to the store, buy some more,\n"
elsif i=1 then that[6..8] = "it" end if
this = bob(i-1)
puts(1,that&this&" on the wall.\n\n")
end for
-- if getc(0) then end if
end procedure