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 J

Date:04/20/05
Author:Roger Hui
URL:n/a
Comments:6
Info:http://www.cs.trinity.edu/About/The_Courses/cs2322/
Score: (3.02 in 175 votes)
See http://www.cs.trinity.edu/About/The_Courses/cs2322/

Date: Thu, 8 Mar 2001 09:23:02 -0500
From: Roger Hui 
Reply-To: forum@jsoftware.com
To: APL Mailing List , J Forum , TimTroyR@ionet.net
Subject: Jforum: Re: New Scientist Puzzle and Oddball Languages

NB. a solution in J (http://www.jsoftware.com) 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@<:

NB. 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

Download Source | Write Comment

Alternative Versions

Comments

>>  Raul Miller said on 10/02/05 07:05:41

Raul Miller NB. a slightly more concise of Hui's implementation

bob =: ": , ' bottles of beer'"_ -. 1&= # 's'"_
bobw=: bob , ' on the wall'"_
beer=: bobw , ', '"_ , bob , '; take one down and pass it around, '"_ , bobw@<:

beer"0 (- i.) 99

>>  Raul Miller said on 10/02/05 07:25:26

Raul Miller A slightly quirkier implementation:

c=: "_
n=: 'No more'c`":@.*@(100&|)
bob=: n, ' bottles of beer'c -. 1&= # 's'c
L1=: bob, ' on the wall'c
L2=: bob, '!'c
L3=: 2&<. { ([;._2 noun define)c
Go to the store and buy some more
if one of those bottles should happen to fall
Take one down, pass it around
)
L4=: L1@<:, '!'c
lyrics=: (L1, L2, L3,: L4)"0 i.-100

Here's how the last four verses appear with this version.

_4 {. lyrics

3 bottles of beer on the wall
3 bottles of beer!
Take one down, pass it around
2 bottles of beer on the wall!

2 bottles of beer on the wall
2 bottles of beer!
Take one down, pass it around
1 bottle of beer on the wall!

1 bottle of beer on the wall
1 bottle of beer!
if one of those bottles should happen to fall
No more bottles of beer on the wall!

No more bottles of beer on the wall
No more bottles of beer!
Go to the store and buy some more
99 bottles of beer on the wall!

>>  Futureboy said on 04/12/07 14:15:05

Futureboy This doesn't appear to produce the canonical form of the song, e.g. "no more bottles of beer".

>>  PoodleNoodle said on 12/19/08 17:54:52

PoodleNoodle @Futureboy: Oh noes!
It seems to integrate the 10 green bottles song into it, I prefer it, as a small twist and a bit of a surprise from the same old script.

>>  Johanna22OBRIEN said on 08/07/10 01:34:59

Johanna22OBRIEN Make your own life time easier take the <a href="http://bestfinance-blog.com/topics/credit-loans">credit loans</a> and all you require.

>>  Konsolen said on 09/02/10 05:11:46

Konsolen Vielen Dank! Super Artikel! Wenn Sie Elektronik möchten,Können Sie im unser efox-shop suchen.wir bieten Navigation ,GPS Gerät ,DVD Spieler ,Auto Werkzeuge ,Auto Schmuck ,Kfz Zubehör AND China GPS , Navigation Gerät AND Auto DVD Spieler kaufen , Auto GPS Gerät kaufen AND Auto Rückfahrsystem Konsolen usw.
welcome you to : http://www.efox-shop.com/pc-videospiele-china-spiel-konsole-c-236_395.html Die besten Dual SIM Handys, <a href=" www.efox-shop.com/pc-videospiele-china-spiel-konsole-c-236_395.html "> Konsolen </a.>,

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: