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 Matlab

(vectorized version)

Date:04/20/05
Author:Rich Stein
URL:n/a
Comments:0
Info:n/a
Score: (3.00 in 115 votes)
% MATLAB *vectorized* version of "99 bottles of beer"
% Rich Stein (rich@cs.umbc.edu)

bottles = [98:-1:3]; % bottles 98 to 3 (99, 2 & 1 are treated as special case)
lines = 3; % need the number of bottles at the beginning of 3 lines

num_array = ones(lines,1) * bottles; % bottles is a (1x96) array

format_plural1 = '%d bottles of beer on the wall,\n%d bottles of beer,\n';
format_plural2 = 'Take one down, pass it around,\n%d bottles of beer on the wall.\n\n';
format_sing1 = '%d bottle of beer on the wall,\n%d bottle of beer,\n';
format_sing2 = 'Take one down, pass it around,\n%d bottle of beer on the wall.\n\n';
format_none2 = 'Take it down, pass it around,\nNo bottles of beer on the wall.\n';

% bottles 99, 2 & 1 are treated as special cases
fprintf([format_plural1 format_plural2], 99,99,num_array,2)
fprintf([format_plural1 format_sing2], 2,2,1)
fprintf([format_sing1 format_none2], 1,1)

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
RecursiveWilliam Rossi11/24/080
standard versionBill Becker04/20/051

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: