How to resolve the algorithm 99 bottles of beer step by step in the Ra programming language

Published on 12 May 2024 09:40 PM
#Ra

How to resolve the algorithm 99 bottles of beer step by step in the Ra programming language

Table of Contents

Problem Statement

Display the complete lyrics for the song:     99 Bottles of Beer on the Wall.

The lyrics follow this form: ... and so on, until reaching   0     (zero). Grammatical support for   1 bottle of beer   is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm 99 bottles of beer step by step in the Ra programming language

Source code in the ra programming language

class BottlesOfBeer
	**Prints the "99 Bottles of Beer" song"**
	
	on start
		
		args := program arguments
		
		# If no arguments given, print the song once
		if args empty
			.printSong
		
		# Otherwise, print the song the given number of times
		else
			.printSong(integer.parse(args[0]))
	
	shared
		
		define printSong(times := 1)
			**Print the song the given number of times**
			
			for times, _printSong
		
		define _printSong
			**Print the song**
			
			# Print for bottles 99 to 1
			for bottle in 99 to 0 by -1
			
				print "[_bottles(bottle)] of beer on the wall
				[_bottles(bottle)] of beer
				Take one down, pass it around
				[_bottles(bottle - 1)] of beer on the wall
				"
			
			print "No more bottles of beer on the wall
			No more bottles of beer
			Go to the store, buy some more
			99 bottles of beer on the wall"
		
		define _bottles(bottle as integer) as String
			**
			If bottle is 0, returns "No more bottles"
			If bottle is 1, returns "1 bottle"
			Otherwise, returns "[bottle] bottles"
			**
			
			if bottle = 0, return "No more bottles"
			if bottle = 1, return "1 bottle"
			return "[bottle] bottles"

  

You may also check:How to resolve the algorithm Leap year step by step in the Neko programming language
You may also check:How to resolve the algorithm Average loop length step by step in the VBScript programming language
You may also check:How to resolve the algorithm Literals/String step by step in the GAP programming language
You may also check:How to resolve the algorithm String length step by step in the SQL PL programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Golfscript programming language