Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
bottles :: Int -> String
bottles n
|n == 0 = "no more bottles"
|n == 1 = "1 bottle"
|n > 1 = show n ++ " bottles"
verse :: Int -> String
verse n
|n == 0 = "No more bottles of beer on the wall, no more bottles of beer.\n"
++ "Go to the store and buy some more, 99 bottles of beer on the wall."
|n>0 = bottles n ++ " of beer on the wall, " ++ bottles n ++ " of beer.\n"
++ "Take one down and pass it around, " ++ bottles (n-1)
++ " of beer on the wall.\n"
main = mapM (putStrLn . verse) [99,98..0]
let rec ninetyNineBottlesOfBeer = function
0 -> print_string "no more bottles of beer\n"
| 1 -> print_string "1 bottle of beer on the wall. Take it down, pass
it around\n" ; ninetyNineBottlesOfBeer 0
| n -> print_int n ; print_string " bottles of beer on the wall. Take
one down, pass it around\n" ; ninetyNineBottlesOfBeer (n - 1)
in ninetyNineBottlesOfBeer 99 ;
#light
open System
open System.Text
open System.Drawing
open System.Windows.Forms
let theBottleSong =
let strSong = new StringBuilder()
let append (s:string) = strSong.Append(s) |> ignore
for i = 99 downto 0 do
if (i = 0) then
append("\nNo more bottles of beer on the wall, no more bottles of beer." +
"\nGo to the store and buy some more, 99 bottles of beer on the wall.")
else
let x = i - 1
let plural = if (i = 1) then "" else "s"
append (sprintf "\n%d bottle%s of beer on the wall, %d bottle%s" i plural i plural);
append "\nTake one down and pass it around, ";
match x with
| 1 -> append "1 bottle "
| 0 -> append " no more bottles "
| _ -> append (sprintf "%d bottles of beer on the wall.\n" x)
strSong.ToString()
let form = new Form(Width=500, Height=420,
Visible=true, TopMost=true,
FormBorderStyle=FormBorderStyle.FixedSingle,
Text="99 bottles of beer presented in F#")
let textBox = new RichTextBox(Size=new Size(480, 350),
Location=new Point(5, 5),
Text=theBottleSong)
form.Controls.Add(textBox)
let btnClose = new Button(Location=new Point(408, 360), Text="Close")
btnClose.Click.Add (fun _ -> form.Close())
form.Controls.Add(btnClose)
[<STAThread>]
do Application.Run(form)
<pre>
Perl (минимальная версия):
http://99-bottles-of-beer.net/language-perl-727.html
<pre>
sub b{$n=99-@_-$_||No;"$n bottle"."s"x!!--$n." of beer"};$w=" on the wall";
die map{b."$w,\n".b.",\nTake one down, pass it around,\n".b(0)."$w.\n\n"}0..98
''=~( '(?{' .('`' |'%') .('[' ^'-')
.('`' |'!') .('`' |',') .'"'. '\\$'
.'==' .('[' ^'+') .('`' |'/') .('['
^'+') .'||' .(';' &'=') .(';' &'=')
.';-' .'-'. '\\$' .'=;' .('[' ^'(')
.('[' ^'.') .('`' |'"') .('!' ^'+')
.'_\\{' .'(\\$' .';=('. '\\$=|' ."\|".( '`'^'.'
).(('`')| '/').').' .'\\"'.+( '{'^'['). ('`'|'"') .('`'|'/'
).('['^'/') .('['^'/'). ('`'|',').( '`'|('%')). '\\".\\"'.( '['^('(')).
'\\"'.('['^ '#').'!!--' .'\\$=.\\"' .('{'^'['). ('`'|'/').( '`'|"\&").(
'{'^"\[").( '`'|"\"").( '`'|"\%").( '`'|"\%").( '['^(')')). '\\").\\"'.
('{'^'[').( '`'|"\/").( '`'|"\.").( '{'^"\[").( '['^"\/").( '`'|"\(").(
'`'|"\%").( '{'^"\[").( '['^"\,").( '`'|"\!").( '`'|"\,").( '`'|(',')).
'\\"\\}'.+( '['^"\+").( '['^"\)").( '`'|"\)").( '`'|"\.").( '['^('/')).
'+_,\\",'.( '{'^('[')). ('\\$;!').( '!'^"\+").( '{'^"\/").( '`'|"\!").(
'`'|"\+").( '`'|"\%").( '{'^"\[").( '`'|"\/").( '`'|"\.").( '`'|"\%").(
'{'^"\[").( '`'|"\$").( '`'|"\/").( '['^"\,").( '`'|('.')). ','.(('{')^
'[').("\["^ '+').("\`"| '!').("\["^ '(').("\["^ '(').("\{"^ '[').("\`"|
')').("\["^ '/').("\{"^ '[').("\`"| '!').("\["^ ')').("\`"| '/').("\["^
'.').("\`"| '.').("\`"| '$')."\,".( '!'^('+')). '\\",_,\\"' .'!'.("\!"^
'+').("\!"^ '+').'\\"'. ('['^',').( '`'|"\(").( '`'|"\)").( '`'|"\,").(
'`'|('%')). '++\\$="})' );$:=('.')^ '~';$~='@'| '(';$^=')'^ '[';$/='`';
Влюбляемся в F#: Доза 0: Зачем нужен ещё один язык программирования?