Jump to content

Execute HQ9+: Difference between revisions

1,037 bytes added ,  13 years ago
GP
(→‎Icon and Unicon: yes it could be shorter without line length limits or correct grammar :))
(GP)
Line 401:
echo("Unknown command: ", token)
</lang>
 
=={{header|PARI/GP}}==
Unlike many other implementations, this version will not overflow when the accumulator hits 2<sup>64</sup> (or as low as 2<sup>31</sup> in some versions).
 
The lyrics are based on the reference implementation. The endline and case-insensitivity are from an example in the spec.
<lang parigp>beer(n)={
if(n == 1,
print("1 bottle of beer on the wall");
print("1 bottle of beer");
print("Take one down and pass it around");
print("No bottles of beer on the wall")
,
print(n" bottles of beer on the wall");
print(n" bottles of beer");
print("Take one down and pass it around");
print(n-1," bottles of beer on the wall\n");
beer(n-1)
)
};
HQ9p(s)={
my(accum=0,v=Vec(s));
for(i=1,#s,
if(v[i] == "H" || v[i] == "h", print("Hello, world!"); next);
if(v[i] == "Q" || v[i] == "q", print(s); next);
if(v[i] == "9", beer(99); next);
if(v[i] == "+", accum++, error("Nasal demons"))
)
};</lang>
 
Sample input/output:
<pre>>HQ9p("qqqq")
qqqq
qqqq
qqqq
qqqq</pre>
 
=={{header|Perl 6}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.