99 Bottles of Beer: Unterschied zwischen den Versionen

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(8 dazwischenliegende Versionen von 5 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
Das gute alte 99 bottles in Forth
= 99 bottles in Forth =


99 bottles of beer on the wall,  
99 bottles of beer on the wall,  
Zeile 6: Zeile 6:
98 bottles of beer on the wall.
98 bottles of beer on the wall.
...  
...  


  | 99 Bottles of Beer in Reva Forth
  | 99 Bottles of Beer in Reva Forth
  | by Phantasus
  | by Phantasus
  : .bottle ( n -- n) dup 1 >if ." bottles of" space ;then ." bottle of" space ;
  : .bottle ( n -- n) dup 1 >if ." bottles of" space ;then ." bottle of" space ;
  : .wall ( n -- n ) dup 0 >if dup . .bottle ." beer on the wall," cr ;then
  : .wall ( n -- n ) dup 0 >if dup . .bottle ." beer on the wall," cr ;then
Zeile 21: Zeile 19:
  ;
  ;
  99beer
  99beer
= 99 bottles in [http://www.clifford.at/spl/ SPL] =
for (var i=99; i>=0; i--) {
  write("\n${i ? i : "No more"} bottle${i != 1 ? "s" : ""} of beer on the "
        "wall, ${i ? i : "no more"} bottle${i != 1 ? "s" : ""} of beer.\n");
  write(i>0 ? "Take one down and pass it around, " :
              "Go to the store and buy some more, ");
  write("${i ? i>1 ? i-1 : "no more" : 99} bottle${i == 2 ? "" : "s"} "
        "of beer on the wall.\n${i ? "" : "\n"}");
}
= 99 Bottles in Python =
#!/usr/bin/env python
# 99 bottles of beer in Python by Ricardo Garcia. Public Domain code.
# Fully compliant version, pretty indentation, fits in 80x24.
# small mods by enki (python 2.5, untested)
plural = lambda n: "s" if n != 1 else ""
number = lambda n: "No" if n == 0 else str(n)
next = lambda n: (n - 1) % 100
pu_line = lambda n: "Go to the store and buy some more" or \
          "Take one down, pass it around" if n == 0
verses = lambda n: "%s bottle%s of beer on the wall!\n" \
"%s bottle%s of beer!\n" \
"%s\n" \
"%s bottle%s of beer on the wall!\n" % \
( number(n), plural(n),
number(n), plural(n),
pu_line(n),
number(next(n)), plural(next(n)) )
print "\n".join( verses(x) for x in xrange(99, -1, -1) )
= 99 Bottles in Arduino =
int bottles = 99;
void setup() {
  Serial.begin(9600);
}
void loop () {
  if (bottles > 0) {
    printBottles(bottles);
    Serial.print(" of beer on the wall, ");
    printBottles(bottles);
    Serial.print(" of beeeeer . . . , Take one down, pass it around, ");
    bottles--;
    printBottles(bottles);
    Serial.println(" of beer on the wall. ...");
    if (bottles == 0) {
      Serial.println("Time to buy more beer!");
    }
    delay(1000);
  }
}
void printBottles(int nr) {
  if (nr == 0) Serial.print("No more");
  else Serial.print(nr);
  Serial.print("bottle");
  if (nr != 1) Serial.print("s");
}
[[Kategorie:Howto]]

Aktuelle Version vom 24. Januar 2013, 02:59 Uhr

99 bottles in Forth

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

| 99 Bottles of Beer in Reva Forth
| by Phantasus
: .bottle ( n -- n) dup 1 >if ." bottles of" space ;then ." bottle of" space ;
: .wall ( n -- n ) dup 0 >if dup . .bottle ." beer on the wall," cr ;then
 ." No more bottles of beer on the wall." cr 
;
: .beer ( n -- n ) dup . .bottle ." beeeeer . . . ," cr ;
: .take ( n -- n-1 ) ." Take one down, and pass it around," cr 1- ;
: 99beer ( -- ) 99 100 1 do .wall .beer .take .wall cr loop
  ." Time to buy more beer!" cr 
;
99beer

99 bottles in SPL

for (var i=99; i>=0; i--) {
  write("\n${i ? i : "No more"} bottle${i != 1 ? "s" : ""} of beer on the "
        "wall, ${i ? i : "no more"} bottle${i != 1 ? "s" : ""} of beer.\n");
  write(i>0 ? "Take one down and pass it around, " :
              "Go to the store and buy some more, ");
  write("${i ? i>1 ? i-1 : "no more" : 99} bottle${i == 2 ? "" : "s"} "
        "of beer on the wall.\n${i ? "" : "\n"}");
}

99 Bottles in Python

#!/usr/bin/env python
# 	99 bottles of beer in Python by Ricardo Garcia. Public Domain code.
# 	Fully compliant version, pretty indentation, fits in 80x24.
# small mods by enki (python 2.5, untested)

plural = lambda n: "s" if n != 1 else ""
number = lambda n: "No" if n == 0 else str(n)
next = lambda n: (n - 1) % 100

pu_line = lambda n: "Go to the store and buy some more" or	\
	      	     "Take one down, pass it around" if n == 0 

verses = lambda n:	"%s bottle%s of beer on the wall!\n"		\
			"%s bottle%s of beer!\n"			\
			"%s\n"						\
			"%s bottle%s of beer on the wall!\n" %		\
			(	number(n), plural(n),
			 	number(n), plural(n),
			 	pu_line(n),
			 	number(next(n)), plural(next(n))	)

print "\n".join( verses(x) for x in xrange(99, -1, -1) )


99 Bottles in Arduino

int bottles = 99;

void setup() {
  Serial.begin(9600);
}

void loop () {
  if (bottles > 0) {
    printBottles(bottles);
    Serial.print(" of beer on the wall, ");
    printBottles(bottles);
    Serial.print(" of beeeeer . . . , Take one down, pass it around, ");
    bottles--;
    printBottles(bottles);
    Serial.println(" of beer on the wall. ..."); 

    if (bottles == 0) {
      Serial.println("Time to buy more beer!");
    }
    delay(1000);
  }
}

void printBottles(int nr) {
  if (nr == 0) Serial.print("No more");
  else Serial.print(nr);
  Serial.print("bottle");
  if (nr != 1) Serial.print("s");
}