Language Python
(functional, w/o variables or procedures)
| Date: | 07/14/05 |
| Author: | Ivan Tkatchev |
| URL: | n/a |
| Comments: | 2 |
| Info: | n/a |
| Score: |
## Functional Python:
## Fully-features '99 bottles' with proper English grammar and English numerals.
## Written without procedures or side-effects; no assignment was used except
## that which is inherent in generator expressions and lambda calls.
##
## Nicely fits on one (long) line. :)
print ''.join('%(pre)s%(num)s %(bot)s on the wall, %(nul)s %(bot)s,\n%(tak)s\n' % (lambda c,b:
{'pre':['','%s %s on the wall.\n\n' % (c,b)][abs(cmp(c,'Ninety-nine'))],
'num':c, 'nul':c.lower(), 'bot':b,
'tak':['Go to the store and buy some more... Ninety-nine %s.' % b,'Take one down, pass it
around,'][abs(cmp(x,0))]
})((lambda x,o: [(['Twenty','Thirty','Forty','Fifty',
'Sixty','Seventy','Eighty','Ninety'][x/10-2]+'-'+o.lower()).replace('-no more',''),
o][int(x<20)])(x, ['No more','One','Two',
'Three','Four','Five','Six','Seven','Eight',
'Nine','Ten','Eleven','Twelve','Thirteen','Fourteen',
'Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'][[x,x%10][int(x>=20)]]),'bottle%s of beer' %
['','s'][abs(cmp(x,1))])
for x in xrange(99,-1,-1))
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| This example demonstrates the simplicity | Gerold Penz | 07/23/05 | 15 | |
| Creative version | Schizo | 11/06/05 | 16 | |
| Advanced, extensible beer/wall framework | Jamie Turner | 05/17/06 | 7 | |
| using lambda in LISP style | J Adrian Zimmer | 11/14/06 | 2 | |
| minimal version | Oliver Xymoron | 04/20/05 | 5 | |
| Fully compliant version | Ricardo Garcia Gonzalez | 01/15/06 | 7 | |
| minimal version with singular | Emlyn Jones | 06/13/05 | 3 | |
| Exception based | Michael Galpin | 02/08/08 | 0 | |
| Using a iterator class | Eric Moritz | 01/20/06 | 2 | |
| New conditional expressions in 2.5 | Ezequiel Pochiero | 12/18/06 | 1 |
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