Language sed
(ten thousand bottles)
| Date: | 03/12/06 |
| Author: | anonymous |
| URL: | n/a |
| Comments: | 0 |
| Info: | n/a |
| Score: |
#!/usr/bin/sed -f
# fans of Tao Te Chug may wish to try 'echo 10000 | sed -f bofb.sed'
s/^$/99/;h
/^0$/!{
:loop
##################################################################
# N bottle(s) of beer on the wall, N bottles of beer
##################################################################
s/$/ bottles of beer/;s/^1 bottles/1 bottle/;s/^0/no more/
s/.*/& on the wall, &/p
##################################################################
# greg ubben magic lookup table subtraction: N := N - 1
##################################################################
s/[^0-9]*\([0-9][0-9]*\).*/\1;987654321000009999000999009909/
s/\([^0]\)\(0*\);[^0]*\1\(.\).*\2\(9*\).*/\3\4/
##################################################################
# Take one down and pass it around, N bottles of beer on the wall
##################################################################
s/0*\([0-9][0-9]*\)/\1 bottles of beer/;s/^1 bottles/1 bottle/;s/^0/no more/
s/.*/Take one down and pass it around, & on the wall\
/p
##################################################################
# if we still have "N bottle(s)", reiterate
##################################################################
:clear
tclear
s/[^0-9]*\([0-9][0-9]*\).*/\1/
tloop
};i\
No more bottles of beer on the wall, no more bottles of beer
##################################################################
# Go to the store to buy some more, N0 bottles of beer on the wall
##################################################################
g;s/$/ bottles of beer/;s/^1 bottles/1 bottle/;s/^0/no more/
s/.*/Go to the store to buy some more, & on the wall/
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