Willkommen, Gast ( Anmelden | Registrierung )

 
Reply to this topicStart new topic
99 Bottles Of Beer, interpretiert in Programmiersprachen
Demo
Beitrag 10th February 2007 - 19:19:38
Beitrag #1


Rubyist
Gruppensymbol

Gruppe: Admin
Beiträge: 9.235
Beigetreten: 4-July 04
Mitglieds-Nr.: 1



Letztens wurde ich im Internet eines recht witzigen,nun ja - nicht unbedingt, Wettstreites fuendig. Und zwar geht es darum den Song 99 Bottles Of Beer in einer beliebigen Programmiersprache zu schreiben.

Mittlerweile hat dieser Wettstreit ein Umfang von 1058 Interpretationen, aufgelistet nach der jeweiligen Sprache. Da ich vermute, dass der ein oder andere Geek hier im Forum rumflitzt oder zumindest es welche gibt, die interessiert sind, stosse ich den Wettstreit auch mal im Forum an.

Vorraussetzung ist, die Seite (leicht zu finden) nicht zu besuchen und dort zu "illern". Programmiersprache ist egal. Der Quelltext muss komplett gepostet werden, wenn noetig mit "Installationsanleitung".

Wie das umgesetzt wird ist egal - ich moechte hier keinen Flamewar sehen.

Die Lyrics des Songs:

CODE

99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

94 bottles of beer on the wall, 94 bottles of beer.
Take one down and pass it around, 93 bottles of beer on the wall.

93 bottles of beer on the wall, 93 bottles of beer.
Take one down and pass it around, 92 bottles of beer on the wall.

92 bottles of beer on the wall, 92 bottles of beer.
Take one down and pass it around, 91 bottles of beer on the wall.

91 bottles of beer on the wall, 91 bottles of beer.
Take one down and pass it around, 90 bottles of beer on the wall.

90 bottles of beer on the wall, 90 bottles of beer.
Take one down and pass it around, 89 bottles of beer on the wall.

89 bottles of beer on the wall, 89 bottles of beer.
Take one down and pass it around, 88 bottles of beer on the wall.

88 bottles of beer on the wall, 88 bottles of beer.
Take one down and pass it around, 87 bottles of beer on the wall.

87 bottles of beer on the wall, 87 bottles of beer.
Take one down and pass it around, 86 bottles of beer on the wall.

86 bottles of beer on the wall, 86 bottles of beer.
Take one down and pass it around, 85 bottles of beer on the wall.

85 bottles of beer on the wall, 85 bottles of beer.
Take one down and pass it around, 84 bottles of beer on the wall.

84 bottles of beer on the wall, 84 bottles of beer.
Take one down and pass it around, 83 bottles of beer on the wall.

83 bottles of beer on the wall, 83 bottles of beer.
Take one down and pass it around, 82 bottles of beer on the wall.

82 bottles of beer on the wall, 82 bottles of beer.
Take one down and pass it around, 81 bottles of beer on the wall.

81 bottles of beer on the wall, 81 bottles of beer.
Take one down and pass it around, 80 bottles of beer on the wall.

80 bottles of beer on the wall, 80 bottles of beer.
Take one down and pass it around, 79 bottles of beer on the wall.

79 bottles of beer on the wall, 79 bottles of beer.
Take one down and pass it around, 78 bottles of beer on the wall.

78 bottles of beer on the wall, 78 bottles of beer.
Take one down and pass it around, 77 bottles of beer on the wall.

77 bottles of beer on the wall, 77 bottles of beer.
Take one down and pass it around, 76 bottles of beer on the wall.

76 bottles of beer on the wall, 76 bottles of beer.
Take one down and pass it around, 75 bottles of beer on the wall.

75 bottles of beer on the wall, 75 bottles of beer.
Take one down and pass it around, 74 bottles of beer on the wall.

74 bottles of beer on the wall, 74 bottles of beer.
Take one down and pass it around, 73 bottles of beer on the wall.

73 bottles of beer on the wall, 73 bottles of beer.
Take one down and pass it around, 72 bottles of beer on the wall.

72 bottles of beer on the wall, 72 bottles of beer.
Take one down and pass it around, 71 bottles of beer on the wall.

71 bottles of beer on the wall, 71 bottles of beer.
Take one down and pass it around, 70 bottles of beer on the wall.

70 bottles of beer on the wall, 70 bottles of beer.
Take one down and pass it around, 69 bottles of beer on the wall.

69 bottles of beer on the wall, 69 bottles of beer.
Take one down and pass it around, 68 bottles of beer on the wall.

68 bottles of beer on the wall, 68 bottles of beer.
Take one down and pass it around, 67 bottles of beer on the wall.

67 bottles of beer on the wall, 67 bottles of beer.
Take one down and pass it around, 66 bottles of beer on the wall.

66 bottles of beer on the wall, 66 bottles of beer.
Take one down and pass it around, 65 bottles of beer on the wall.

65 bottles of beer on the wall, 65 bottles of beer.
Take one down and pass it around, 64 bottles of beer on the wall.

64 bottles of beer on the wall, 64 bottles of beer.
Take one down and pass it around, 63 bottles of beer on the wall.

63 bottles of beer on the wall, 63 bottles of beer.
Take one down and pass it around, 62 bottles of beer on the wall.

62 bottles of beer on the wall, 62 bottles of beer.
Take one down and pass it around, 61 bottles of beer on the wall.

61 bottles of beer on the wall, 61 bottles of beer.
Take one down and pass it around, 60 bottles of beer on the wall.

60 bottles of beer on the wall, 60 bottles of beer.
Take one down and pass it around, 59 bottles of beer on the wall.

59 bottles of beer on the wall, 59 bottles of beer.
Take one down and pass it around, 58 bottles of beer on the wall.

58 bottles of beer on the wall, 58 bottles of beer.
Take one down and pass it around, 57 bottles of beer on the wall.

57 bottles of beer on the wall, 57 bottles of beer.
Take one down and pass it around, 56 bottles of beer on the wall.

56 bottles of beer on the wall, 56 bottles of beer.
Take one down and pass it around, 55 bottles of beer on the wall.

55 bottles of beer on the wall, 55 bottles of beer.
Take one down and pass it around, 54 bottles of beer on the wall.

54 bottles of beer on the wall, 54 bottles of beer.
Take one down and pass it around, 53 bottles of beer on the wall.

53 bottles of beer on the wall, 53 bottles of beer.
Take one down and pass it around, 52 bottles of beer on the wall.

52 bottles of beer on the wall, 52 bottles of beer.
Take one down and pass it around, 51 bottles of beer on the wall.

51 bottles of beer on the wall, 51 bottles of beer.
Take one down and pass it around, 50 bottles of beer on the wall.

50 bottles of beer on the wall, 50 bottles of beer.
Take one down and pass it around, 49 bottles of beer on the wall.

49 bottles of beer on the wall, 49 bottles of beer.
Take one down and pass it around, 48 bottles of beer on the wall.

48 bottles of beer on the wall, 48 bottles of beer.
Take one down and pass it around, 47 bottles of beer on the wall.

47 bottles of beer on the wall, 47 bottles of beer.
Take one down and pass it around, 46 bottles of beer on the wall.

46 bottles of beer on the wall, 46 bottles of beer.
Take one down and pass it around, 45 bottles of beer on the wall.

45 bottles of beer on the wall, 45 bottles of beer.
Take one down and pass it around, 44 bottles of beer on the wall.

44 bottles of beer on the wall, 44 bottles of beer.
Take one down and pass it around, 43 bottles of beer on the wall.

43 bottles of beer on the wall, 43 bottles of beer.
Take one down and pass it around, 42 bottles of beer on the wall.

42 bottles of beer on the wall, 42 bottles of beer.
Take one down and pass it around, 41 bottles of beer on the wall.

41 bottles of beer on the wall, 41 bottles of beer.
Take one down and pass it around, 40 bottles of beer on the wall.

40 bottles of beer on the wall, 40 bottles of beer.
Take one down and pass it around, 39 bottles of beer on the wall.

39 bottles of beer on the wall, 39 bottles of beer.
Take one down and pass it around, 38 bottles of beer on the wall.

38 bottles of beer on the wall, 38 bottles of beer.
Take one down and pass it around, 37 bottles of beer on the wall.

37 bottles of beer on the wall, 37 bottles of beer.
Take one down and pass it around, 36 bottles of beer on the wall.

36 bottles of beer on the wall, 36 bottles of beer.
Take one down and pass it around, 35 bottles of beer on the wall.

35 bottles of beer on the wall, 35 bottles of beer.
Take one down and pass it around, 34 bottles of beer on the wall.

34 bottles of beer on the wall, 34 bottles of beer.
Take one down and pass it around, 33 bottles of beer on the wall.

33 bottles of beer on the wall, 33 bottles of beer.
Take one down and pass it around, 32 bottles of beer on the wall.

32 bottles of beer on the wall, 32 bottles of beer.
Take one down and pass it around, 31 bottles of beer on the wall.

31 bottles of beer on the wall, 31 bottles of beer.
Take one down and pass it around, 30 bottles of beer on the wall.

30 bottles of beer on the wall, 30 bottles of beer.
Take one down and pass it around, 29 bottles of beer on the wall.

29 bottles of beer on the wall, 29 bottles of beer.
Take one down and pass it around, 28 bottles of beer on the wall.

28 bottles of beer on the wall, 28 bottles of beer.
Take one down and pass it around, 27 bottles of beer on the wall.

27 bottles of beer on the wall, 27 bottles of beer.
Take one down and pass it around, 26 bottles of beer on the wall.

26 bottles of beer on the wall, 26 bottles of beer.
Take one down and pass it around, 25 bottles of beer on the wall.

25 bottles of beer on the wall, 25 bottles of beer.
Take one down and pass it around, 24 bottles of beer on the wall.

24 bottles of beer on the wall, 24 bottles of beer.
Take one down and pass it around, 23 bottles of beer on the wall.

23 bottles of beer on the wall, 23 bottles of beer.
Take one down and pass it around, 22 bottles of beer on the wall.

22 bottles of beer on the wall, 22 bottles of beer.
Take one down and pass it around, 21 bottles of beer on the wall.

21 bottles of beer on the wall, 21 bottles of beer.
Take one down and pass it around, 20 bottles of beer on the wall.

20 bottles of beer on the wall, 20 bottles of beer.
Take one down and pass it around, 19 bottles of beer on the wall.

19 bottles of beer on the wall, 19 bottles of beer.
Take one down and pass it around, 18 bottles of beer on the wall.

18 bottles of beer on the wall, 18 bottles of beer.
Take one down and pass it around, 17 bottles of beer on the wall.

17 bottles of beer on the wall, 17 bottles of beer.
Take one down and pass it around, 16 bottles of beer on the wall.

16 bottles of beer on the wall, 16 bottles of beer.
Take one down and pass it around, 15 bottles of beer on the wall.

15 bottles of beer on the wall, 15 bottles of beer.
Take one down and pass it around, 14 bottles of beer on the wall.

14 bottles of beer on the wall, 14 bottles of beer.
Take one down and pass it around, 13 bottles of beer on the wall.

13 bottles of beer on the wall, 13 bottles of beer.
Take one down and pass it around, 12 bottles of beer on the wall.

12 bottles of beer on the wall, 12 bottles of beer.
Take one down and pass it around, 11 bottles of beer on the wall.

11 bottles of beer on the wall, 11 bottles of beer.
Take one down and pass it around, 10 bottles of beer on the wall.

10 bottles of beer on the wall, 10 bottles of beer.
Take one down and pass it around, 9 bottles of beer on the wall.

9 bottles of beer on the wall, 9 bottles of beer.
Take one down and pass it around, 8 bottles of beer on the wall.

8 bottles of beer on the wall, 8 bottles of beer.
Take one down and pass it around, 7 bottles of beer on the wall.

7 bottles of beer on the wall, 7 bottles of beer.
Take one down and pass it around, 6 bottles of beer on the wall.

6 bottles of beer on the wall, 6 bottles of beer.
Take one down and pass it around, 5 bottles of beer on the wall.

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


Ich fang mal mit PHP an (passend zum Forum):

QUELLTEXT
<?php
/*
*      99bottlesofbeer.php
*
*      Copyright 2007 Daniel Schmidt <demo.code@gmail.com>
*
*      This program is free software; you can redistribute it and/or modify
*      it under the terms of the GNU General Public License as published by
*      the Free Software Foundation; either version 2 of the License, or
*      (at your option) any later version.
*
*      This program is distributed in the hope that it will be useful,
*      but WITHOUT ANY WARRANTY; without even the implied warranty of
*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*      GNU General Public License for more details.
*
*      You should have received a copy of the GNU General Public License
*      along with this program; if not, write to the Free Software
*      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

class BottleSong{
    
    private $_bottles;
    private $_song;

    function __construct() {
           $this->_song = "";
        $this->init();    
       }
    
    private function init(){
        $this->_bottles = array();
    }
    
    private function wall(){
        for($i=99;$i>=0;$i--){
            array_push($this->_bottles,$i);
        }    
        
    }
    
    private function pluralize($bottle){
        return $bottles = ($bottle>1)? "bottles":"bottle";
    }
    
    private function verse_one($num){
        $verse = "";
        switch($num){
            case 0:        $verse = "No more bottles of beer on the wall, no more bottles of beer.";    
                        break;
            default:    $verse = $num." ".$this->pluralize($num)." of beer on the wall, ".$num." ".$this->pluralize($num)." of beer.";
        }
        
        return $verse;
    }
    
    private function verse_two($num){
        $bottles = ($num-1)." ".$this->pluralize($num-1)." of beer on the wall.";
        $verse = "";
        
        switch($num){
            case 0 :    $verse = "Go to the store and buy some more, 99 bottles of beer on the wall.";
                        break;
            case 1 :    $verse = "Take one down and pass it around, no more bottles of beer on the wall.";    
                        break;
            default:    $verse = "Take one down and pass it around, ".$bottles;
        }    
        
        return $verse;
    }
    
    private function song(){
        $this->wall();
        foreach($this->_bottles as $bottle){
            $this->_song .= $this->verse_one($bottle)."<br/>";
            $this->_song .=    $this->verse_two($bottle)."<br/><br/>";
        }
        return $this->_song;
    }    
    
    public function sing(){
        return $this->song();
    }
}
?>


Aufruf dann mit
QUELLTEXT
$song = new BottleSong();
echo $song->sing();



Vielleicht mach ich noch Pascal,Ruby und Java.


--------------------
I want to know how it feels, when I die. Can you take me under?
Go to the top of the page
 
+Quote Post
Demo
Beitrag 20th February 2007 - 11:33:17
Beitrag #2


Rubyist
Gruppensymbol

Gruppe: Admin
Beiträge: 9.235
Beigetreten: 4-July 04
Mitglieds-Nr.: 1



Next one : Pascal.

QUELLTEXT
program ninetyninebottlesofbeer(input,output);
{gibt das Lied "99BottlesOfBeer" aus}
const
    BSTART = 0;
    BEND = 99;

type
    tBottles = BSTART..BEND;
    
var
    bottles : tBottles;

function pluralize(bottle: tbottles):STRING;

    var
    tempChar: STRING;
begin
    if((bottle>1) OR (bottle=0)) then
        tempChar:="bottles"
    else
        tempChar:="bottle";
    
    pluralize:=tempChar;
end;

procedure go_to_store(inBottles: tbottles);
{wird ausgegeben, wenn keine Flaschen mehr auf der Wand stehen}
begin
    writeln("Go to the store and buy some more, ",inBottles," ",pluralize(inBottles)," of beer on the wall.");
end;

procedure verse_one(inBottles : tbottles);
{gibt Strophe 1 aus}
begin
    if(inBottles>1) then
        writeln(inBottles," ",pluralize(inBottles)," of beer on the wall, ",inBottles," ",pluralize(inBottles)," of beer.")
    else
        writeln("No more bottles of beer on the wall, no more bottles of beer.");
end;

procedure verse_two(inBottles: tbottles);
{gibt Strophe 2 aus, wenn keine Flaschen mehr da sind, wird go_to_store aufgerufen.}
    var
    bottle :tbottles;

begin
    if(inBottles>1) then
    begin
        bottle:= inBottles-1;
        writeln("Take one down and pass it around, ",bottle," ",pluralize(bottle)," of beer on the wall.");
    end
    else
        go_to_store(BEND);
end;

begin
{Hauptroutine}
    for bottles:=99 downto 1 do
    begin
        verse_one(bottles);
        verse_two(bottles);    
    end;
end.


Das ganze funktioniert hervorragend mit dem GNU Pascal Compiler.

QUELLTEXT
gpc 99bottlesofbeer.pas -o 99bottlesofbeer


Die Meldung:
QUELLTEXT
warning: missing string capacity -- assuming 255
kann man getrost ignorieren, dies ist nur eine Mitteilung, dass der Datentyp STRING nur eine Laenge von 255 hat.

Ansonsten - die Sprache ist fuer mich etwas befremdlich. Warum vor dem else kein Semikolon stehen darf, ist mir etwas schleierhaft (zum Beispiel).


--------------------
I want to know how it feels, when I die. Can you take me under?
Go to the top of the page
 
+Quote Post
mulder
Beitrag 20th February 2007 - 11:48:58
Beitrag #3


daumendruecker
Gruppensymbol

Gruppe: Members
Beiträge: 3.455
Beigetreten: 30-August 04
Mitglieds-Nr.: 160



thumb_up.gif demo ... nettes "spielchen" ..

mir gehts schon die ganze zeit durch den kopf ... aber ich finde zZ keine zeit mal schnell das in die ksh zu haun! blush.gif

aber pascal ... dry.gif damit wurde ich in der 7. klasse geschlagen .. ganz schlimm ...


--------------------
" If you're going through hell, keep going" Churchill
"Wer grinst, hat schmutzige Gedanken!"
"Ich glaube nicht an den Himmel, ich glaube an den Schmerz!"

Go to the top of the page
 
+Quote Post
Demo
Beitrag 20th February 2007 - 11:54:40
Beitrag #4


Rubyist
Gruppensymbol

Gruppe: Admin
Beiträge: 9.235
Beigetreten: 4-July 04
Mitglieds-Nr.: 1



ZITAT(mulder @ 20.02.2007 - 11:48:58) *
aber pascal ... dry.gif damit wurde ich in der 7. klasse geschlagen .. ganz schlimm ...


Ich hatte es in der Uni.


--------------------
I want to know how it feels, when I die. Can you take me under?
Go to the top of the page
 
+Quote Post
Manne
Beitrag 20th February 2007 - 11:55:42
Beitrag #5


Legende
Gruppensymbol

Gruppe: Members
Beiträge: 2.596
Beigetreten: 8-July 04
Wohnort: L.E.
Mitglieds-Nr.: 6



ZITAT(mulder @ 20.02.2007 - 11:48:58) *
thumb_up.gif demo ... nettes "spielchen" ..

mir gehts schon die ganze zeit durch den kopf ... aber ich finde zZ keine zeit mal schnell das in die ksh zu haun! blush.gif

aber pascal ... dry.gif damit wurde ich in der 7. klasse geschlagen .. ganz schlimm ...


Wir hatten in der 7. Klasse nicht mal einen der Pascal hieß! rolleyes.gif


--------------------
skydive-leipzig.de


Fan der KLM-Reihe!

Anzahl Livespiele 2012/2013: 13 (Stand 20.11.12)
Go to the top of the page
 
+Quote Post
Demo
Beitrag 20th February 2007 - 17:47:35
Beitrag #6


Rubyist
Gruppensymbol

Gruppe: Admin
Beiträge: 9.235
Beigetreten: 4-July 04
Mitglieds-Nr.: 1



Weiter gehts mit meiner Lieblingssprache: Ruby.
Weitestgehend objektorientierte Variante.

QUELLTEXT
#!/usr/bin/env ruby
#
#  Created by Demo on 2007-02-20.
#  Copyright (c) 2007. All rights reserved.

class Pluralize
  def initialize
  end
  
  def pluralize(bottle)
    bottle > 1 ? "bottles" : "bottle"
  end
end

class Verse < Pluralize
  
  def initialize(lines)
    super()
      @beer = lines
  end

  def write_verse
    bottles = pluralize(@beer)
    one(bottles) + "\n" + two(bottles)
  end
  
  private
  
  def one(bottles)
    if @beer == 0
      return "No more bottles of beer on the wall, no more bottles of beer."
    else
      return "#{@beer} #{bottles} of beer on the wall,#{@beer} #{bottles} of beer."
    end
  end
  
  def two(bottles)
    if @beer == 0
      return "Go to the store and buy some more, 99 bottles of beer on the wall."
    else
      beer = @beer-1
          if beer == 0; beer = "no more"; end
      return "Take one down and pass it around, #{beer} #{bottles} of beer on the wall."
    end
  end
end
  
class Song
  
  @lines;@song
  def initialize(lines)
    @lines=lines
    @song = Array.new()
  end
  
  def write_song
    @lines.downto(0) do |line|
      @song << Verse.new(line).write_verse
    end  
  end
  
  def play
    @song.each do |verse|
      puts verse
    end
  end
end

if __FILE__ == $0
  song = Song.new(99)
  song.write_song
  song.play
end


Ich werd mal versuchen das noch zu kuerzen,da ich die Rubytypischen Dinge grossteils weggelassen habe. wink.gif


--------------------
I want to know how it feels, when I die. Can you take me under?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 Besucher lesen dieses Thema (Gäste: 1 | Anonyme Besucher: 0)
0 Mitglieder:

 



RSS Vereinfachte Darstellung Aktuelles Datum: 22nd September 2018 - 21:49:28