Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language ReXplace

Date:04/20/05
Author:Simon Bünzli
URL:n/a
Comments:0
Info:n/a
Score: (2.50 in 2 votes)
# ReXplace version of "99 Bottles of Beer"
# (C) 2003 by Simon Bünzli
#
# Converts any file's content into the song's lyrics.

Options: REX1.2, timeout: 750, test, nosummary

# Initialize the number of bottles
/^(?![1-9]\d*$).*/s
	99

Repeat:

# Copy the last number to the next line, followed by "9876543210!"
/\d+$/
	$0\n$0 9876543210!

# Subtract 1 from the number on the last line
/(\d) \d*\1([\d!])[\d!]*$/
	$2

# Check whether we've just passed a multiple of 10
/.*/s
-/!$/
->Proceed

# Prepare for an extended decrement by 1
/(\n\d*?)(0*)!$/
	$1 9876543210 $20

# Decrement by 1
/0+$/
>/0/g
	9
/(\d) \d*\1([\d])[\d]* (?=9*$)/
	$2

Proceed:

# Copy the number to the preceding line
/\n(\d+)$/
	\ $1\n$1

# Continue until we reach 0
/\d+$/
-/^0+$/
->Repeat

# Empty the last line
/.*$/
	

# Remove all leading zeros
/\b0+(\d)/g
	$1

# Insert the lyrics
/(\d+) (\d+)/g
	$1 bottles of beer on the wall, $1 bottles of beer, take one down, pass it around, $2 bottles of
beer on the wall.

# Remove the plural "s" when only one bottle is left
/(\b1\b.*?)s/g
	$1

# Adjust the ending
/\b0\b/g
	no more

Download Source | Write Comment

Alternative Versions

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: