Essays/99 Bottles of Beer

From J Wiki
Jump to navigation Jump to search

A solution to the 99 Bottles of Beer problem.

bob =: ": , ' bottle' , (1 = ]) }. 's of beer'"_
bobw=: bob , ' on the wall'"_
beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:

For example:

   beer"0 >:i.-5
5 bottles of beer on the wall, 5 bottles of beer; take one down and pass it around, 4 bottles of beer on the wall
4 bottles of beer on the wall, 4 bottles of beer; take one down and pass it around, 3 bottles of beer on the wall
3 bottles of beer on the wall, 3 bottles of beer; take one down and pass it around, 2 bottles of beer on the wall
2 bottles of beer on the wall, 2 bottles of beer; take one down and pass it around, 1 bottle of beer on the wall
1 bottle of beer on the wall, 1 bottle of beer; take one down and pass it around, 0 bottles of beer on the wall



See also

Wikipedia


Contributed by Roger Hui. Substantially the same text previously appeared in a J Forum message on 2001-03-08.