task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Ela
Ela
open list   beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around" beer 0 = "better go to the store and buy some more." beer v = show v ++ " bottles of beer on the wall\n" ++ show v ++" bottles of beer\nTake one down, pass it around\n"   map beer [99,98..0]
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Simula
Simula
BEGIN   CLASS EXPR; BEGIN     REAL PROCEDURE POP; BEGIN IF STACKPOS > 0 THEN BEGIN STACKPOS := STACKPOS - 1; POP := STACK(STACKPOS); END; END POP;     PROCEDURE PUSH(NEWTOP); REAL NEWTOP; BEGIN STACK(STACKPOS) := NEWTOP; STACKPOS := STACKPOS + 1; END PUSH;     REAL PROCEDURE CALC(OPERATOR, ERR); CHARACTER OPERATOR; LABEL ERR; BEGIN REAL X, Y; X := POP; Y := POP; IF OPERATOR = '+' THEN PUSH(Y + X) ELSE IF OPERATOR = '-' THEN PUSH(Y - X) ELSE IF OPERATOR = '*' THEN PUSH(Y * X) ELSE IF OPERATOR = '/' THEN BEGIN IF X = 0 THEN BEGIN EVALUATEDERR :- "DIV BY ZERO"; GOTO ERR; END; PUSH(Y / X); END ELSE BEGIN EVALUATEDERR :- "UNKNOWN OPERATOR"; GOTO ERR; END END CALC;     PROCEDURE READCHAR(CH); NAME CH; CHARACTER CH; BEGIN IF T.MORE THEN CH := T.GETCHAR ELSE CH := EOT; END READCHAR;     PROCEDURE SKIPWHITESPACE(CH); NAME CH; CHARACTER CH; BEGIN WHILE (CH = SPACE) OR (CH = TAB) OR (CH = CR) OR (CH = LF) DO READCHAR(CH); END SKIPWHITESPACE;     PROCEDURE BUSYBOX(OP, ERR); INTEGER OP; LABEL ERR; BEGIN CHARACTER OPERATOR; REAL NUMBR; BOOLEAN NEGATIVE;   SKIPWHITESPACE(CH);   IF OP = EXPRESSION THEN BEGIN   NEGATIVE := FALSE; WHILE (CH = '+') OR (CH = '-') DO BEGIN IF CH = '-' THEN NEGATIVE := NOT NEGATIVE; READCHAR(CH); END;   BUSYBOX(TERM, ERR);   IF NEGATIVE THEN BEGIN NUMBR := POP; PUSH(0 - NUMBR); END;   WHILE (CH = '+') OR (CH = '-') DO BEGIN OPERATOR := CH; READCHAR(CH); BUSYBOX(TERM, ERR); CALC(OPERATOR, ERR); END;   END ELSE IF OP = TERM THEN BEGIN   BUSYBOX(FACTOR, ERR); WHILE (CH = '*') OR (CH = '/') DO BEGIN OPERATOR := CH; READCHAR(CH); BUSYBOX(FACTOR, ERR); CALC(OPERATOR, ERR) END   END ELSE IF OP = FACTOR THEN BEGIN   IF (CH = '+') OR (CH = '-') THEN BUSYBOX(EXPRESSION, ERR) ELSE IF (CH >= '0') AND (CH <= '9') THEN BUSYBOX(NUMBER, ERR) ELSE IF CH = '(' THEN BEGIN READCHAR(CH); BUSYBOX(EXPRESSION, ERR); IF CH = ')' THEN READCHAR(CH) ELSE GOTO ERR; END ELSE GOTO ERR;   END ELSE IF OP = NUMBER THEN BEGIN   NUMBR := 0; WHILE (CH >= '0') AND (CH <= '9') DO BEGIN NUMBR := 10 * NUMBR + RANK(CH) - RANK('0'); READCHAR(CH); END; IF CH = '.' THEN BEGIN REAL FAKTOR; READCHAR(CH); FAKTOR := 10; WHILE (CH >= '0') AND (CH <= '9') DO BEGIN NUMBR := NUMBR + (RANK(CH) - RANK('0')) / FAKTOR; FAKTOR := 10 * FAKTOR; READCHAR(CH); END; END; PUSH(NUMBR);   END;   SKIPWHITESPACE(CH);   END BUSYBOX;     BOOLEAN PROCEDURE EVAL(INP); TEXT INP; BEGIN EVALUATEDERR :- NOTEXT; STACKPOS := 0; T :- COPY(INP.STRIP); READCHAR(CH); BUSYBOX(EXPRESSION, ERRORLABEL);  ! OUTTEXT("T = '");  ! OUTTEXT(T);  ! OUTTEXT("'");  ! OUTTEXT(", T.POS = ");  ! OUTINT(T.POS, 0);  ! OUTTEXT(", STACKPOS = ");  ! OUTINT(STACKPOS, 0);  ! OUTTEXT(", T.MORE = ");  ! OUTCHAR(IF T.MORE THEN 'T' ELSE 'F');  ! OUTTEXT(", CH = ");  ! OUTCHAR(CH);  ! OUTIMAGE; IF NOT T.MORE AND STACKPOS = 1 AND CH = EOT THEN BEGIN EVALUATED := POP; EVAL := TRUE; GOTO NOERRORLABEL; END; ERRORLABEL: EVAL := FALSE; IF EVALUATEDERR = NOTEXT THEN EVALUATEDERR :- "INVALID EXPRESSION: " & INP; NOERRORLABEL: END EVAL;     REAL PROCEDURE RESULT; RESULT := EVALUATED;   TEXT PROCEDURE ERR; ERR :- EVALUATEDERR;   TEXT T;   INTEGER EXPRESSION; INTEGER TERM; INTEGER FACTOR; INTEGER NUMBER;   CHARACTER TAB; CHARACTER LF; CHARACTER CR; CHARACTER SPACE; CHARACTER EOT;   CHARACTER CH; REAL ARRAY STACK(0:31); INTEGER STACKPOS;   REAL EVALUATED; TEXT EVALUATEDERR;   EXPRESSION := 1; TERM := 2; FACTOR := 3; NUMBER := 4;   TAB := CHAR(9); LF := CHAR(10); CR := CHAR(13); SPACE := CHAR(32); EOT := CHAR(0);   END EXPR;   INTEGER ARRAY DIGITS(1:4); INTEGER SEED, I; REF(EXPR) E;   E :- NEW EXPR; OUTTEXT("ENTER RANDOM SEED: "); OUTIMAGE; SEED := ININT; FOR I := 1 STEP 1 UNTIL 4 DO DIGITS(I) := RANDINT(0, 9, SEED);   L: BEGIN INTEGER ARRAY DIGITSUSED(0:9); INTEGER ARRAY DIGITSTAKEN(0:9); CHARACTER C, LASTC; TEXT INP;   LASTC := CHAR(0); OUTTEXT("MAKE 24 USING THESE DIGITS: "); FOR I := 1 STEP 1 UNTIL 4 DO BEGIN OUTINT(DIGITS(I), 2); DIGITSUSED( DIGITS(I) ) := DIGITSUSED( DIGITS(I) ) + 1; END; OUTIMAGE; INIMAGE; INP :- COPY(SYSIN.IMAGE.STRIP); OUTIMAGE; WHILE INP.MORE DO BEGIN C := INP.GETCHAR; IF (C >= '0') AND (C <= '9') THEN BEGIN INTEGER D; IF (LASTC >= '0') AND (LASTC <= '9') THEN BEGIN OUTTEXT("NUMBER HAS TOO MANY DIGITS: "); OUTCHAR(LASTC); OUTCHAR(C); OUTIMAGE; GOTO L; END; D := RANK(C) - RANK('0'); DIGITSTAKEN(D) := DIGITSTAKEN(D) + 1; END ELSE IF NOT ((C = '+') OR (C = '-') OR (C = '/') OR (C = '*') OR (C = ' ') OR (C = '(') OR (C = ')')) THEN BEGIN OUTTEXT("ILLEGAL INPUT CHARACTER: "); OUTCHAR(C); OUTIMAGE; GOTO L; END; LASTC := C; END; FOR I := 0 STEP 1 UNTIL 9 DO BEGIN IF DIGITSUSED(I) <> DIGITSTAKEN(I) THEN BEGIN OUTTEXT("NOT THE SAME DIGITS."); OUTIMAGE; GOTO L; END; END; IF E.EVAL(INP) THEN BEGIN OUTTEXT("RESULT IS "); OUTFIX(E.RESULT, 4, 10); OUTIMAGE; OUTTEXT(IF ABS(E.RESULT - 24) < 0.001 THEN "YOU WIN" ELSE "YOU LOOSE"); OUTIMAGE; END ELSE BEGIN OUTTEXT(E.ERR); OUTIMAGE; END; END;   END.  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Idris
Idris
main : IO() main = do line <- getLine print $ sum $ map cast $ words line
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#SNOBOL4
SNOBOL4
  * Program: abc.sbl, * To run: sbl -r abc.sbl * Comment: Tested using the Spitbol for Linux version of SNOBOL4   * Read in blocks to construct the blocks string in1 line = replace(input,&lcase,&ucase) :f(in1end) line ? breakx(' ') . pre ' ' rem . post :f(in1end) blocks = blocks "," pre post :(in1) in1end   * Function to determine if a word can be constructed with the given blocks define('abc(blocks,word)s,i,let') abcpat = (breakx(',') ',') . pre (*let len(1) | len(1) *let) rem . post :(abc_end) abc eq(size(word),0) :s(abc3) s = replace(word,&lcase,&ucase) i = 0 abc2 i = lt(i,size(s)) i + 1 :f(abc4) let = substr(s,i,1) blocks ? abcpat = pre post :f(abc3) :(abc2) abc3 abc = 'False' :(abc5) abc4 abc = 'True'  :(abc5) abc5 output = lpad('can_make_word("' word '"): ',26) abc abc = "" :(return) abc_end   * Check words * output = abc(blocks,"") * output = abc(blocks," ") output = abc(blocks,'A') output = abc(blocks,'bark') output = abc(blocks,'BOOK') output = abc(blocks,'TrEAT') output = abc(blocks,'COMMON') output = abc(blocks,'SQUAD') output = abc(blocks,'CONFUSE')   * The blocks are entered below, after the following END label END b o X K D Q C P N A G T R E T G Q D F S J W H U V I A N O B E R F S L Y P C Z M  
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#Visual_Basic_.NET
Visual Basic .NET
Public Class Board Inherits System.Windows.Forms.Form   Const XbyX = 4 Const XSize = 60   Private Empty As New Panel Private Tiles As New List(Of Tile) Private Moves As Integer   Public Sub New() Me.Text = XbyX ^ 2 - 1 & " Puzzle Game" Me.ClientSize = New Size(XbyX * XSize, XbyX * XSize) Me.FormBorderStyle = FormBorderStyle.FixedToolWindow Restart() End Sub   Public Sub Restart() Dim Start As List(Of Integer) = MakeCompleteable(GetRandamStartOrder())   Empty.SetBounds(((XbyX ^ 2 - 1) Mod XbyX) * XSize, ((XbyX ^ 2 - 1) \ XbyX) * XSize, XSize, XSize)   Me.Moves = 0 Me.Tiles.Clear() Me.Controls.Clear() For No = 0 To XbyX ^ 2 - 2 Dim Tile As New Tile Tile.Text = Start(No) Tile.Board = Me Tile.SetBounds((No Mod XbyX) * XSize, (No \ XbyX) * XSize, XSize, XSize) Me.Tiles.Add(Tile) Me.Controls.Add(Tile) Next   End Sub   Public Sub IsComplete() Me.Moves += 1 If Empty.Left = ((XbyX ^ 2 - 1) Mod XbyX) * XSize AndAlso Empty.Top = ((XbyX ^ 2 - 1) \ XbyX) * XSize Then Me.Tiles.Sort() For x = 1 To XbyX ^ 2 - 1 If Not Tiles(x - 1).Text = x Then Exit Sub End If Next MsgBox($"Completed in {Me.Moves} Moves!", MsgBoxStyle.Information, "Winner") Restart() End If End Sub   Public Class Tile Inherits Button Implements IComparable(Of Tile) Public Board As Board Private Sub Tile_Click(sender As Object, e As EventArgs) Handles Me.Click With Board.Empty If Me.Left = .Left AndAlso (Me.Top + Me.Height = .Top OrElse .Top + .Height = Me.Top) Then Swap() ElseIf Me.Top = .Top AndAlso (Me.Left + Me.Width = .Left OrElse .Left + .Width = Me.Left) Then Swap() End If End With End Sub Private Sub Swap() Dim p = Board.Empty.Location Board.Empty.Location = Me.Location Me.Location = p Board.IsComplete() End Sub Public Function CompareTo(other As Tile) As Integer Implements IComparable(Of Tile).CompareTo Dim Result = Me.Top.CompareTo(other.Top) If Result = 0 Then Return Me.Left.CompareTo(other.Left) End If Return Result End Function End Class   Public Function GetRandamStartOrder() As List(Of Integer) Dim List As New List(Of Integer) Dim Random As New Random() Do While List.Count < XbyX ^ 2 - 1 Dim Value As Integer = Random.Next(1, XbyX ^ 2) If Not List.Contains(Value) Then List.Add(Value) End If Loop Return List End Function   Public Function MakeCompleteable(List As List(Of Integer)) As List(Of Integer) 'ToDo Return List End Function   End Class
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Elena
Elena
import system'routines; import extensions; import extensions'routines; import extensions'text;   extension bottleOp { bottleDescription() = self.toPrintable() + (self != 1).iif(" bottles"," bottle");   bottleEnumerator() = new Variable(self).doWith:(n) { ^ new Enumerator { bool next() = n > 0;   get() = new StringWriter() .printLine(n.bottleDescription()," of beer on the wall") .printLine(n.bottleDescription()," of beer") .printLine("Take one down, pass it around") .printLine((n.reduce:1).bottleDescription()," of beer on the wall");   reset() {}   enumerable() = __target; } }; }   public program() { var bottles := 99;   bottles.bottleEnumerator().forEach:printingLn }
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Swift
Swift
import Darwin import Foundation   println("24 Game") println("Generating 4 digits...")   func randomDigits() -> Int[] { var result = Int[](); for var i = 0; i < 4; i++ { result.append(Int(arc4random_uniform(9)+1)) } return result; }   // Choose 4 digits let digits = randomDigits()   print("Make 24 using these digits : ")   for digit in digits { print("\(digit) ") } println()   // get input from operator var input = NSString(data:NSFileHandle.fileHandleWithStandardInput().availableData, encoding:NSUTF8StringEncoding)   var enteredDigits = Int[]()   var enteredOperations = Character[]()   let inputString = input as String   // store input in the appropriate table for character in inputString { switch character { case "1", "2", "3", "4", "5", "6", "7", "8", "9": let digit = String(character) enteredDigits.append(digit.toInt()!) case "+", "-", "*", "/": enteredOperations.append(character) case "\n": println() default: println("Invalid expression") } }   // check value of expression provided by the operator var value = Int()   if enteredDigits.count == 4 && enteredOperations.count == 3 { value = enteredDigits[0] for (i, operation) in enumerate(enteredOperations) { switch operation { case "+": value = value + enteredDigits[i+1] case "-": value = value - enteredDigits[i+1] case "*": value = value * enteredDigits[i+1] case "/": value = value / enteredDigits[i+1] default: println("This message should never happen!") } } }   if value != 24 { println("The value of the provided expression is \(value) instead of 24!") } else { println("Congratulations, you found a solution!") }  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#J
J
2+3 5
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#SPAD
SPAD
  blocks:List Tuple Symbol:= _ [(B,O),(X,K),(D,Q),(C,P),(N,A),(G,T),(R,E),(T,G),(Q,D),(F,S), _ (J,W),(H,U),(V,I),(A,N),(O,B),(E,R),(F,S),(L,Y),(P,C),(Z,M)]     findComb(l:List List NNI):List List NNI == #l=0 => [] #l=1 => [[s] for s in first l] r:List List NNI:=[] for y in findComb(rest l) repeat r:=concat(r,[concat(x,y) for x in first l]) return r   canMakeWord?(word,blocks) == word:=upperCase word bchr:=[map(char,map(string,s::List(Symbol))) for s in blocks] c:=[[j for j in 1..#blocks | member?(word.k,bchr.j)] for k in 1..#word] reduce(_or,[test(#removeDuplicates(l)=#word) for l in findComb(c)])     Example:=["a","bark","book","treat","common","squad","confuse"]   [canMakeWord?(s,blocks) for s in Example]    
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#Visual_Prolog
Visual Prolog
  /* ------------------------------------------------------------------------------------------------------   Copyright (c) 2004 - Gal Zsolt (CalmoSoft)   ------------------------------------------------------------------------------------------------------ */   implement playDialog open core, vpiDomains, vpiOldDomains, resourceIdentifiers   facts thisWin : vpiDomains::windowHandle := erroneous.   clauses show(Parent):- _ = vpi::winCreateDynDialog(Parent, controlList, eventHandler, gui_api::lNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates eventHandler : vpiDomains::ehandler. clauses eventHandler(Win, Event) = Result :- Result = generatedEventHandler(Win, Event).   /* ------------------------------------------------------------------------------------------------------ */     predicates onDestroy : vpiOldDomains::destroyHandler. clauses onDestroy() = vpiOldDomains::defaultHandling() :- thisWin := erroneous.   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlCancel : vpiOldDomains::controlHandler. clauses onControlCancel(_Ctrl, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull) :- file::save("game.dba",gameDB), retractall(table(_,_)), retractall(gameplay(_,_)), retractall(empty_cell(_)), retractall(cell(_,_)), retractall(cellnr(_,_)), retractall(good(_,_,_)), vpi::winDestroy(thisWin).   /* ------------------------------------------------------------------------------------------------------ */   predicates onUpdate : vpiOldDomains::updateHandler. clauses onUpdate(Rectangle) = vpiOldDomains::defaultHandling():- vpi::winClear( thisWin,Rectangle,0x808040),  !.   /* ------------------------------------------------------------------------------------------------------ */   class facts - gameDB table:(integer,string). gameplay:(integer,integer). empty_cell:(integer).   class facts cell:(integer,vpiDomains::windowHandle). cellnr:(integer,integer).   /* ------------------------------------------------------------------------------------------------------ */   class facts step_nr:integer:=0.   predicates onCreate : vpiOldDomains::createHandler. clauses onCreate(_CreationData) = vpiOldDomains::defaultHandling():- retractall(table(_,_)), retractall(gameplay(_,_)), retractall(empty_cell(_)), retractall(cell(_,_)), retractall(cellnr(_,_)), retractall(good(_,_,_)),   scrollbars_init(), cellhandle_init(), empty:=16, good_cell(0), table_save(), step_nr:=0, fail. onCreate(_CreationData) = vpiOldDomains::defaultHandling().   /* ------------------------------------------------------------------------------------------------------ */   facts vsbarr : vpiDomains::windowHandle := erroneous. vsbarl : vpiDomains::windowHandle := erroneous. hsbart : vpiDomains::windowHandle := erroneous. hsbarb : vpiDomains::windowHandle := erroneous.   predicates scrollbars_init:(). clauses scrollbars_init():- vsbarr := vpi::winGetCtlHandle(thisWin,idc_sbvr), vsbarl := vpi::winGetCtlHandle(thisWin,idc_sbvl), hsbart := vpi::winGetCtlHandle(thisWin,idc_sbht), hsbarb := vpi::winGetCtlHandle(thisWin,idc_sbhb),     vpi::winSetScrollRange(vsbarr,sb_Ctl,1,4), vpi::winSetScrollProportion(vsbarr,sb_Ctl,1), vpi::winSetScrollPos(vsbarr,sb_Ctl,4),   vpi::winSetScrollRange(vsbarl,sb_Ctl,1,4), vpi::winSetScrollProportion(vsbarl,sb_Ctl,1), vpi::winSetScrollPos(vsbarl,sb_Ctl,4),   vpi::winSetScrollRange(hsbart,sb_Ctl,1,4), vpi::winSetScrollProportion(hsbart,sb_Ctl,1), vpi::winSetScrollPos(hsbart,sb_Ctl,4),   vpi::winSetScrollRange(hsbarb,sb_Ctl,1,4), vpi::winSetScrollProportion(hsbarb,sb_Ctl,1), vpi::winSetScrollPos(hsbarb,sb_Ctl,4).   /* ------------------------------------------------------------------------------------------------------ */   class facts cell1 : vpiDomains::windowHandle := erroneous. cell2 : vpiDomains::windowHandle := erroneous. cell3 : vpiDomains::windowHandle := erroneous. cell4 : vpiDomains::windowHandle := erroneous. cell5 : vpiDomains::windowHandle := erroneous. cell6 : vpiDomains::windowHandle := erroneous. cell7 : vpiDomains::windowHandle := erroneous. cell8 : vpiDomains::windowHandle := erroneous. cell9 : vpiDomains::windowHandle := erroneous. cell10 : vpiDomains::windowHandle := erroneous. cell11 : vpiDomains::windowHandle := erroneous. cell12 : vpiDomains::windowHandle := erroneous. cell13 : vpiDomains::windowHandle := erroneous. cell14 : vpiDomains::windowHandle := erroneous. cell15 : vpiDomains::windowHandle := erroneous. cell16 : vpiDomains::windowHandle := erroneous.   predicates cell_handle:(). clauses cell_handle():- cell1:=vpi::winGetCtlHandle(thisWin,idc_cell1), cell2:=vpi::winGetCtlHandle(thisWin,idc_cell2), cell3:=vpi::winGetCtlHandle(thisWin,idc_cell3), cell4:=vpi::winGetCtlHandle(thisWin,idc_cell4), cell5:=vpi::winGetCtlHandle(thisWin,idc_cell5), cell6:=vpi::winGetCtlHandle(thisWin,idc_cell6), cell7:=vpi::winGetCtlHandle(thisWin,idc_cell7), cell8:=vpi::winGetCtlHandle(thisWin,idc_cell8), cell9:=vpi::winGetCtlHandle(thisWin,idc_cell9), cell10:=vpi::winGetCtlHandle(thisWin,idc_cell10), cell11:=vpi::winGetCtlHandle(thisWin,idc_cell11), cell12:=vpi::winGetCtlHandle(thisWin,idc_cell12), cell13:=vpi::winGetCtlHandle(thisWin,idc_cell13), cell14:=vpi::winGetCtlHandle(thisWin,idc_cell14), cell15:=vpi::winGetCtlHandle(thisWin,idc_cell15), cell16:=vpi::winGetCtlHandle(thisWin,idc_cell16).   /* ------------------------------------------------------------------------------------------------------ */   predicates cellhandle_init:(). clauses cellhandle_init():- retractall(cell(_,_)), cell_handle(),   assert(cell(1,cell1)), assert(cell(2,cell2)), assert(cell(3,cell3)), assert(cell(4,cell4)), assert(cell(5,cell5)), assert(cell(6,cell6)), assert(cell(7,cell7)), assert(cell(8,cell8)), assert(cell(9,cell9)), assert(cell(10,cell10)), assert(cell(11,cell11)), assert(cell(12,cell12)), assert(cell(13,cell13)), assert(cell(14,cell14)), assert(cell(15,cell15)), assert(cell(16,cell16)).   /* ------------------------------------------------------------------------------------------------------ */   class facts good_nr:integer:=0. good:(integer,integer,integer) nondeterm. empty:integer:=16.   predicates good_cell:(integer) multi. clauses good_cell(16):-!. good_cell(Number):- NumberNew = Number+1, good_nr:=0, good_above(NumberNew),  % movable cells above empty cell good_before(NumberNew),  % movable cells before empty cell good_after(NumberNew),  % movable cells after empty cell good_under(NumberNew),  % movable cells under empty cell assert(cellnr(NumberNew,good_nr)),  % number of movable cells around the empty cell good_cell(NumberNew).   /* ------------------------------------------------------------------------------------------------------ */   predicates good_above:(integer). clauses good_above(Number):- Number > 4,  % movable cells above empty cell good_nr:= good_nr+1, assert(good(Number,good_nr,Number-4)), fail. good_above(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates good_before:(integer). clauses good_before(Number):- (Number mod 4) <> 1,  % movable cells before empty cell good_nr:= good_nr+1, assert(good(Number,good_nr,Number-1)), fail. good_before(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates good_after:(integer). clauses good_after(Number):- (Number mod 4) > 0,  % movable cells after empty cell good_nr:= good_nr+1, assert(good(Number,good_nr,Number+1)), fail. good_after(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates good_under:(integer). clauses good_under(Number):- Number < 13,  % movable cells under empty cell good_nr:= good_nr+1, assert(good(Number,good_nr,Number+4)), fail. good_under(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates cell_click:(integer).   clauses cell_click(NrCell):- good(empty,_,NrCell), cell(empty,EmptyHandle), cell(NrCell,NrCellHandle), EmptyNr = vpi::winGetText(NrCellHandle), vpi::winSetText(EmptyHandle,EmptyNr), vpi::winSetText(NrCellHandle,""), empty:=NrCell, step_nr := step_nr + 1, Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetText( Bingo, ""), vpi::winSetState(Bingo,[wsf_Invisible]), bingo(),    % VerVal = uncheckedConvert(integer, math::floor((empty-1)/4)+1),  % HorVal = uncheckedConvert(integer, math::floor((empty-1) mod 4)+1),   VerVal = math::floor((empty-1)/4)+1, HorVal = math::floor((empty-1) mod 4)+1,   vpi::winSetScrollPos(vsbarr,sb_Ctl,VerVal), vpi::winSetScrollPos(vsbarl,sb_Ctl,VerVal), vpi::winSetScrollPos(hsbart,sb_Ctl,HorVal), vpi::winSetScrollPos(hsbarb,sb_Ctl,HorVal),   Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(step_nr)),   assert(gameplay(step_nr,NrCell)),   fail. cell_click(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates cell_click_play:(integer).   clauses cell_click_play(NrCell):- good(empty,_,NrCell), cell(empty,EmptyHandle), cell(NrCell,NrCellHandle), EmptyNr = vpi::winGetText(NrCellHandle), vpi::winSetText(EmptyHandle,EmptyNr), vpi::winSetText(NrCellHandle,""), empty:=NrCell, Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetText(Bingo, ""), vpi::winSetState(Bingo,[wsf_Invisible]), bingo(),    % VerVal = uncheckedConvert(integer,math::floor((empty-1)/4)+1),  % HorVal = uncheckedConvert(integer,math::floor((empty-1) mod 4)+1),   VerVal = math::floor((empty-1)/4)+1, HorVal = math::floor((empty-1) mod 4)+1,   vpi::winSetScrollPos(vsbarr,sb_Ctl,VerVal), vpi::winSetScrollPos(vsbarl,sb_Ctl,VerVal), vpi::winSetScrollPos(hsbart,sb_Ctl,HorVal), vpi::winSetScrollPos(hsbarb,sb_Ctl,HorVal),   programControl::sleep(1000),   fail. cell_click_play(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlmix : vpiOldDomains::controlHandler. clauses onControlmix(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- step_nr:=0, cell_reset(), mix_cells(0), Play = vpi::winGetCtlHandle(thisWin,idc_play), vpi::winSetState(Play,[wsf_Disabled]), Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetText(Bingo, ""), vpi::winSetState(Bingo,[wsf_Invisible]), step_nr:=0, Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(step_nr)), table_save(), retractall(gameplay(_,_)), fail.   onControlmix(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   class facts rand_nr:integer:=0. mix_nr:integer:=300.   predicates mix_cells:(integer) multi.   clauses mix_cells(mix_nr):-!. mix_cells(Number):- NumberNew = Number+1, cellnr(empty,CellNr), RandomNr = (math::random(1315) mod CellNr) + 1, rand_nr := RandomNr, good(empty,rand_nr, I), cell_click(I), mix_cells(NumberNew). mix_cells(_).   /* ------------------------------------------------------------------------------------------------------ */   predicates table_save:(). clauses table_save():- retractall(table(_,_)), retractall(empty_cell(_)), assert(empty_cell(empty)),   assert(table(1,vpi::winGetText(cell1))), assert(table(2,vpi::winGetText(cell2))), assert(table(3,vpi::winGetText(cell3))), assert(table(4,vpi::winGetText(cell4))), assert(table(5,vpi::winGetText(cell5))), assert(table(6,vpi::winGetText(cell6))), assert(table(7,vpi::winGetText(cell7))), assert(table(8,vpi::winGetText(cell8))), assert(table(9,vpi::winGetText(cell9))), assert(table(10,vpi::winGetText(cell10))), assert(table(11,vpi::winGetText(cell11))), assert(table(12,vpi::winGetText(cell12))), assert(table(13,vpi::winGetText(cell13))), assert(table(14,vpi::winGetText(cell14))), assert(table(15,vpi::winGetText(cell15))), assert(table(16,vpi::winGetText(cell16))).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlreset : vpiOldDomains::controlHandler. clauses onControlreset(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_reset().   /* ------------------------------------------------------------------------------------------------------ */ predicates cell_reset:(). clauses cell_reset():- vpi::winSetText(cell1,"1"), vpi::winSetText(cell2,"2"), vpi::winSetText(cell3,"3"), vpi::winSetText(cell4,"4"), vpi::winSetText(cell5,"5"), vpi::winSetText(cell6,"6"), vpi::winSetText(cell7,"7"), vpi::winSetText(cell8,"8"), vpi::winSetText(cell9,"9"), vpi::winSetText(cell10,"10"), vpi::winSetText(cell11,"11"), vpi::winSetText(cell12,"12"), vpi::winSetText(cell13,"13"), vpi::winSetText(cell14,"14"), vpi::winSetText(cell15,"15"), vpi::winSetText(cell16,""),   vpi::winSetScrollPos(vsbarr,sb_Ctl,4), vpi::winSetScrollPos(vsbarl,sb_Ctl,4), vpi::winSetScrollPos(hsbart,sb_Ctl,4), vpi::winSetScrollPos(hsbarb,sb_Ctl,4),   empty:=16, step_nr:=0, Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(step_nr)), Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetText(Bingo, ""), vpi::winSetState(Bingo,[wsf_Invisible]), Play = vpi::winGetCtlHandle(thisWin,idc_play), vpi::winSetState(Play,[wsf_Disabled]), retractall(gameplay(_,_)), table_save().   /* ------------------------------------------------------------------------------------------------------ */   predicates bingo:().   clauses bingo():- toString(1) = vpi::winGetText(cell1), toString(2) = vpi::winGetText(cell2), toString(3) = vpi::winGetText(cell3), toString(4) = vpi::winGetText(cell4), toString(5) = vpi::winGetText(cell5), toString(6) = vpi::winGetText(cell6), toString(7) = vpi::winGetText(cell7), toString(8) = vpi::winGetText(cell8), toString(9) = vpi::winGetText(cell9), toString(10) = vpi::winGetText(cell10), toString(11) = vpi::winGetText(cell11), toString(12) = vpi::winGetText(cell12), toString(13) = vpi::winGetText(cell13), toString(14) = vpi::winGetText(cell14), toString(15) = vpi::winGetText(cell15), "" = vpi::winGetText(cell16),   Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetState(Bingo,[wsf_Visible]), vpi::winSetText(Bingo, "BINGO !"),   Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(step_nr)),   fail. bingo().   /* ------------------------------------------------------------------------------------------------------ */   facts fileName:string:="".   predicates onControlsave : vpiOldDomains::controlHandler. clauses onControlsave(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- try FileName = vpiCommonDialogs::getFileName(fileName, ["All files", "*.game"], "Save game as", [dlgfn_Save], "", _) catch _ do fail end try,  !, file::save(FileName,gameDB).   onControlsave(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo)= vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlopen : vpiOldDomains::controlHandler. clauses onControlopen(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- try FileName = vpiCommonDialogs::getFileName("game_", ["All files", "*.game"], "Open game file", [], "", _) catch _ do fail end try,  !, retractall(table(_,_)), retractall(gameplay(_,_)), retractall(empty_cell(_)), file::consult(FileName,gameDB), play_display(), Play = vpi::winGetCtlHandle(thisWin,idc_play), vpi::winSetState(Play,[wsf_Enabled]), Bingo = vpi::winGetCtlHandle(thisWin,idc_bingo), vpi::winSetState(Bingo,[wsf_Invisible]), vpi::winSetText(Bingo, ""), step_nr:=0, Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(step_nr)).   onControlopen(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates play_display:(). clauses play_display():-   table(1,Cell1), table(2,Cell2), table(3,Cell3), table(4,Cell4), table(5,Cell5), table(6,Cell6), table(7,Cell7), table(8,Cell8), table(9,Cell9), table(10,Cell10), table(11,Cell11), table(12,Cell12), table(13,Cell13), table(14,Cell14), table(15,Cell15), table(16,Cell16),   vpi::winSetText(cell1,Cell1), vpi::winSetText(cell2,Cell2), vpi::winSetText(cell3,Cell3), vpi::winSetText(cell4,Cell4), vpi::winSetText(cell5,Cell5), vpi::winSetText(cell6,Cell6), vpi::winSetText(cell7,Cell7), vpi::winSetText(cell8,Cell8), vpi::winSetText(cell9,Cell9), vpi::winSetText(cell10,Cell10), vpi::winSetText(cell11,Cell11), vpi::winSetText(cell12,Cell12), vpi::winSetText(cell13,Cell13), vpi::winSetText(cell14,Cell14), vpi::winSetText(cell15,Cell15), vpi::winSetText(cell16,Cell16),   empty_cell(Empty_Cell), empty:=Empty_Cell,   fail. play_display().   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlplay : vpiOldDomains::controlHandler. clauses   onControlplay(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- Play = vpi::winGetCtlHandle(thisWin,idc_play), vpi::winSetState(Play,[wsf_Disabled]), gameplay(Nr,Nr_cell), cell_click_play(Nr_cell), Step = vpi::winGetCtlHandle(thisWin,idc_step), vpi::winSetText(Step,toString(Nr)), fail.   onControlplay(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlsbvr : vpiOldDomains::controlHandler.  % Sets the right vertical scrollbar clauses onControlsbvr(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineDown,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalr = vpi::winGetScrollPos(vsbarr,sb_Ctl)+1, Sbarvalr < 5, cell_click(empty+4), vpi::winSetScrollPos(vsbarr,sb_Ctl, Sbarvalr), vpi::winSetScrollPos(vsbarl,sb_Ctl, Sbarvalr), fail.   onControlsbvr(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineUp,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalr = vpi::winGetScrollPos(vsbarr,sb_Ctl)-1, Sbarvalr > 0, cell_click(empty-4), vpi::winSetScrollPos(vsbarr,sb_Ctl, Sbarvalr), vpi::winSetScrollPos(vsbarl,sb_Ctl, Sbarvalr), fail.   onControlsbvr(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).     /* ------------------------------------------------------------------------------------------------------ */   predicates onControlsbvl : vpiOldDomains::controlHandler.  % Sets the left vertical scrollbar clauses onControlsbvl(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineDown,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvall = vpi::winGetScrollPos(vsbarl,sb_Ctl)+1, Sbarvall < 5, cell_click(empty+4), vpi::winSetScrollPos(vsbarl,sb_Ctl, Sbarvall), vpi::winSetScrollPos(vsbarr,sb_Ctl, Sbarvall), fail.   onControlsbvl(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineUp,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvall = vpi::winGetScrollPos(vsbarl,sb_Ctl)-1, Sbarvall > 0, cell_click(empty-4), vpi::winSetScrollPos(vsbarl,sb_Ctl, Sbarvall), vpi::winSetScrollPos(vsbarr,sb_Ctl, Sbarvall), fail.   onControlsbvl(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlsbht : vpiOldDomains::controlHandler.  % Sets the top horizontal scrollbar clauses onControlsbht(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineDown,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalt = vpi::winGetScrollPos(hsbart,sb_Ctl)+1, Sbarvalt < 5, cell_click(empty+1), vpi::winSetScrollPos(hsbart,sb_Ctl, Sbarvalt), vpi::winSetScrollPos(hsbarb,sb_Ctl, Sbarvalt), fail.   onControlsbht(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineUp,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalt = vpi::winGetScrollPos(hsbart,sb_Ctl)-1, Sbarvalt > 0, cell_click(empty-1), vpi::winSetScrollPos(hsbart,sb_Ctl, Sbarvalt), vpi::winSetScrollPos(hsbarb,sb_Ctl, Sbarvalt), fail.   onControlsbht(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlsbhb : vpiOldDomains::controlHandler.  % Sets the bottom horizontal scrollbar clauses onControlsbhb(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineDown,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalb = vpi::winGetScrollPos(hsbarb,sb_Ctl)+1, Sbarvalb < 5, cell_click(empty+1), vpi::winSetScrollPos(hsbarb,sb_Ctl, Sbarvalb), vpi::winSetScrollPos(hsbart,sb_Ctl, Sbarvalb), fail.   onControlsbhb(_CtrlID, _CtrlType, _CtrlWin,scroll(sc_LineUp,_)) = vpiOldDomains::handled(gui_api::rNull):- Sbarvalb = vpi::winGetScrollPos(hsbarb,sb_Ctl)-1, Sbarvalb > 0, cell_click(empty-1), vpi::winSetScrollPos(hsbarb,sb_Ctl, Sbarvalb), vpi::winSetScrollPos(hsbart,sb_Ctl, Sbarvalb), fail.   onControlsbhb(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell1 : vpiOldDomains::controlHandler. clauses onControlcell1(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(1).   /* ------------------------------------------------------------------------------------------------------ */     predicates onControlcell2 : vpiOldDomains::controlHandler. clauses onControlcell2(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(2).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell3 : vpiOldDomains::controlHandler. clauses onControlcell3(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(3).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell4 : vpiOldDomains::controlHandler. clauses onControlcell4(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(4).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell5 : vpiOldDomains::controlHandler. clauses onControlcell5(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(5).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell6 : vpiOldDomains::controlHandler. clauses onControlcell6(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(6).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell7 : vpiOldDomains::controlHandler. clauses onControlcell7(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(7).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell8 : vpiOldDomains::controlHandler. clauses onControlcell8(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(8).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell9 : vpiOldDomains::controlHandler. clauses onControlcell9(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(9).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell10 : vpiOldDomains::controlHandler. clauses onControlcell10(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(10).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell11 : vpiOldDomains::controlHandler. clauses onControlcell11(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(11).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell12 : vpiOldDomains::controlHandler. clauses onControlcell12(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(12).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell13 : vpiOldDomains::controlHandler. clauses onControlcell13(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(13).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell14 : vpiOldDomains::controlHandler. clauses onControlcell14(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(14).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell15 : vpiOldDomains::controlHandler. clauses onControlcell15(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(15).   /* ------------------------------------------------------------------------------------------------------ */   predicates onControlcell16 : vpiOldDomains::controlHandler. clauses onControlcell16(_CtrlID, _CtrlType, _CtrlWin, _CtrlInfo) = vpiOldDomains::handled(gui_api::rNull):- cell_click(16).   /* ------------------------------------------------------------------------------------------------------ */    % This code is maintained by the VDE do not update it manually, 22:12:35-14.3.2004 constants dialogType : vpiDomains::wintype = wd_Modal. title : string = "playDialog". rectangle : vpiDomains::rct = rct(200,40,359,263). dialogFlags : vpiDomains::wsflags = [wsf_Close,wsf_TitleBar]. dialogFont = "MS Sans Serif". dialogFontSize = 8.   constants controlList : vpiDomains::windef_list = [ dlgFont(wdef(dialogType, rectangle, title, u_DlgBase), dialogFont, dialogFontSize, dialogFlags), ctl(wdef(wc_PushButton,rct(40,166,67,178),"&Mix",u_DlgBase),idc_mix,[wsf_Group,wsf_TabStop]), ctl(wdef(wc_PushButton,rct(67,166,94,178),"&Reset",u_DlgBase),idc_reset,[wsf_Group,wsf_TabStop]), ctl(wdef(wc_PushButton,rct(40,178,67,190),"&Save",u_DlgBase),idc_save,[wsf_Group,wsf_TabStop]), ctl(wdef(wc_PushButton,rct(94,178,121,190),"&Open",u_DlgBase),idc_open,[wsf_Group,wsf_TabStop]), ctl(wdef(wc_PushButton,rct(40,190,121,202),"&Play",u_DlgBase),idc_play,[wsf_Group,wsf_TabStop,wsf_Disabled]), ctl(wdef(wc_PushButton,rct(94,166,121,178),"&Exit",u_DlgBase),idc_cancel,[wsf_Group,wsf_TabStop]), ctl(wdef(wc_PushButton,rct(40,40,60,60),"1",u_DlgBase),idc_cell1,[wsf_Group]), ctl(wdef(wc_PushButton,rct(60,40,80,60),"2",u_DlgBase),idc_cell2,[wsf_Group]), ctl(wdef(wc_PushButton,rct(80,40,100,60),"3",u_DlgBase),idc_cell3,[wsf_Group]), ctl(wdef(wc_PushButton,rct(100,40,120,60),"4",u_DlgBase),idc_cell4,[wsf_Group]), ctl(wdef(wc_PushButton,rct(40,60,60,80),"5",u_DlgBase),idc_cell5,[wsf_Group]), ctl(wdef(wc_PushButton,rct(60,60,80,80),"6",u_DlgBase),idc_cell6,[wsf_Group]), ctl(wdef(wc_PushButton,rct(80,60,100,80),"7",u_DlgBase),idc_cell7,[wsf_Group]), ctl(wdef(wc_PushButton,rct(100,60,120,80),"8",u_DlgBase),idc_cell8,[wsf_Group]), ctl(wdef(wc_PushButton,rct(40,80,60,100),"9",u_DlgBase),idc_cell9,[wsf_Group]), ctl(wdef(wc_PushButton,rct(60,80,80,100),"10",u_DlgBase),idc_cell10,[wsf_Group]), ctl(wdef(wc_PushButton,rct(80,80,100,100),"11",u_DlgBase),idc_cell11,[wsf_Group]), ctl(wdef(wc_PushButton,rct(100,80,120,100),"12",u_DlgBase),idc_cell12,[wsf_Group]), ctl(wdef(wc_PushButton,rct(40,100,60,120),"13",u_DlgBase),idc_cell13,[wsf_Group]), ctl(wdef(wc_PushButton,rct(60,100,80,120),"14",u_DlgBase),idc_cell14,[wsf_Group]), ctl(wdef(wc_PushButton,rct(80,100,100,120),"15",u_DlgBase),idc_cell15,[wsf_Group]), ctl(wdef(wc_PushButton,rct(100,100,120,120),"",u_DlgBase),idc_cell16,[wsf_Group]), ctl(wdef(wc_HScroll,rct(30,18,130,30),"",u_DlgBase),idc_sbht,[]), ctl(wdef(wc_VScroll,rct(130,30,142,130),"",u_DlgBase),idc_sbvr,[]), ctl(wdef(wc_HScroll,rct(30,130,130,142),"",u_DlgBase),idc_sbhb,[]), ctl(wdef(wc_VScroll,rct(18,30,30,130),"",u_DlgBase),idc_sbvl,[]), ctl(wdef(wc_PushButton,rct(67,178,94,190),"",u_DlgBase),idc_step,[wsf_Group]), ctl(wdef(wc_PushButton,rct(40,154,121,166),"",u_DlgBase),idc_bingo,[wsf_Group,wsf_Invisible]) ].   predicates generatedEventHandler : vpiDomains::ehandler. clauses generatedEventHandler(Win, e_create(_)) = _ :- thisWin := Win, fail. generatedEventHandler(_Win, e_Create(CreationData)) = Result :- handled(Result) = onCreate(CreationData). generatedEventHandler(_Win, e_Update(Rectangle)) = Result :- handled(Result) = onUpdate(Rectangle). generatedEventHandler(_Win, e_Control(idc_cancel, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlCancel(idc_cancel, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_mix, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlmix(idc_mix, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_reset, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlreset(idc_reset, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_sbvr, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlsbvr(idc_sbvr, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_sbvl, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlsbvl(idc_sbvl, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_sbhb, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlsbhb(idc_sbhb, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_sbht, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlsbht(idc_sbht, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_save, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlsave(idc_save, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_open, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlopen(idc_open, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_play, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlplay(idc_play, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell1, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell1(idc_cell1, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell10, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell10(idc_cell10, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell11, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell11(idc_cell11, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell12, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell12(idc_cell12, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell13, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell13(idc_cell13, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell14, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell14(idc_cell14, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell15, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell15(idc_cell15, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell16, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell16(idc_cell16, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell2, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell2(idc_cell2, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell3, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell3(idc_cell3, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell4, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell4(idc_cell4, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell5, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell5(idc_cell5, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell6, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell6(idc_cell6, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell7, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell7(idc_cell7, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell8, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell8(idc_cell8, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Control(idc_cell9, CtrlType, CtrlWin, CtlInfo)) = Result :- handled(Result) = onControlcell9(idc_cell9, CtrlType, CtrlWin, CtlInfo). generatedEventHandler(_Win, e_Destroy()) = Result :- handled(Result) = onDestroy().  % end of automatic code end implement playDialog  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Elixir
Elixir
defmodule Bottles do def run do Enum.each 99..1, fn idx -> IO.puts "#{idx} bottle#{plural(idx)} of beer on the wall" IO.puts "#{idx} bottle#{plural(idx)} of beer" IO.puts "Take one down, pass it around" IO.puts "#{idx - 1} bottle#{plural(idx-1)} of beer on the wall" IO.puts "" end end   def plural(1), do: "" def plural(num), do: "s" end   Bottles.run
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Tcl
Tcl
# Four random non-zero digits proc choose4 {} { set digits {} foreach x {1 2 3 4} {lappend digits [expr {int(1+rand()*9)}]} return [lsort $digits] }   # Print out a welcome message proc welcome digits { puts [string trim " The 24 Game   Given any four digits in the range 1 to 9, which may have repetitions, Using just the +, -, *, and / operators; and the possible use of brackets, (), show how to make an answer of 24.   An answer of \"q\" will quit the game. An answer of \"!\" will generate a new set of four digits. Otherwise you are repeatedly asked for an expression until it evaluates to 24   Note: you cannot form multiple digit numbers from the supplied digits, so an answer of 12+12 when given 1, 2, 2, and 1 would not be allowed. "] puts "\nYour four digits: $digits" }   # Check whether we've got a legal answer proc check {answer digits} { if { [regexp "\[^-+*/() \t[join $digits {}]\]" $answer] || [regexp {\d\d} $answer] } then { return false } set digs [lsort [regexp -inline -all {\d} $answer]] if {$digs ne $digits} { return false } expr {![catch {expr $answer}]} }   # The main game loop proc main {} { fconfigure stdout -buffering none   set digits [choose4] welcome $digits set trial 0 while true { puts -nonewline "Expression [incr trial]: " gets stdin answer   # Check for various types of non-answer if {[eof stdin] || $answer eq "q" || $answer eq "Q"} { break } elseif {$answer eq "!"} { set digits [choose4] puts "New digits: $digits" continue } elseif {![check $answer $digits]} { puts "The input '$answer' was wonky!" continue }   # Check to see if it is the right answer set ans [expr [regsub {\d} $answer {&.0}]] puts " = [string trimright $ans .0]" if {$ans == 24.0} { puts "That's right!" break } } puts "Thank you and goodbye" } main
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Java
Java
import java.util.Scanner;   public class Sum2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Standard input System.out.println(in.nextInt() + in.nextInt()); // Standard output } }
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Standard_ML
Standard ML
  val BLOCKS = [(#"B",#"O"), (#"X",#"K"), (#"D",#"Q"), (#"C",#"P"), (#"N",#"A"), (#"G",#"T"), (#"R",#"E"), (#"T",#"G"), (#"Q",#"D"), (#"F",#"S"), (#"J",#"W"), (#"H",#"U"), (#"V",#"I"), (#"A",#"N"),(#"O",#"B"), (#"E",#"R"), (#"F",#"S"), (#"L",#"Y"), (#"P",#"C"), (#"Z",#"M")]; val words = ["A","BARK","BOOK","TREaT","COMMON","SQUAD","CONFUSE"]; open List;   local val remove = fn x => fn B => (fn (a,b) => (tl a)@b ) (partition ( fn a=> x=a) B) in fun cando ([] , Done, B ) = true | cando (h::t, Done, []) = false | cando (h::t, Done, B ) = let val S = find (fn (a,b) => a=h orelse b=h) B in if isSome S then cando (t, (h,valOf S)::Done, remove (valOf S) B) else let val T = find ( fn(_,(a,b)) => a=h orelse b=h) Done val U = if isSome T then find (fn (a,b) => a = #1 (valOf T) orelse b = #1 (valOf T) ) B else NONE in if isSome T andalso isSome U then cando ( t, (#1 (valOf T),(valOf U))::(h,#2 (valOf T))::(remove (valOf T) Done), remove (valOf U) B) else false end end end;   map (fn st => cando(map Char.toUpper (String.explode st),[],BLOCKS)) words;   val BLOCKS = [(#"U",#"S"), (#"T",#"Z"), (#"A",#"O"), (#"Q",#"A")]; val words = ["A","UTAH","AutO"]; map (fn st => cando(map Char.toUpper (String.explode st),[],BLOCKS)) words;  
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#VBScript
VBScript
  '----------------15 game------------------------------------- 'WARNING: this script uses ANSI escape codes to position items on console so 'it won't work in Windows from XP to 8.1 where Microsoft removed ANSI support... 'Windows 10, 11 or 98 are ok!!! option explicit const maxshuffle=100 'level dim ans0:ans0=chr(27)&"[" dim anscls:anscls=ans0 & "2J"   dim dirs:dirs=array(6,-1,-6,1) dim a:a=array(-1,-1,-1,-1,-1,-1,_ -1, 1, 2, 3, 4,-1,_ -1, 5, 6, 7, 8,-1,_ -1, 9,10,11,12,-1,_ -1,13,14,15, 0,-1,_ -1,-1,-1,-1,-1,-1) dim b(35) dim pos0 dim s:s=Array("W+Enter: up Z+Enter: down A+Enter: left S+Enter right ",_ "Bad move!! ",_ "You did it! Another game? [y/n]+Enter ",_ "Bye! ")     do shuffle draw toxy 10,1,s(0) do if usr(wait()) then draw toxy 10,1,s(0) else toxy 10,1,s(1) end if loop until checkend toxy 10,1,s(2) loop until wait()="n" toxy 10,1,s(3)   function wait(): toxy 11,1,"": wait=left(lcase(wscript.stdin.readline),1): end function   sub toxy(x,y,s) wscript.StdOut.Write ans0 & x & ";" & y & "H"& " "& s end sub   sub draw dim i,j wscript.stdout.write anscls for i=0 to 3 'row for j=0 to 3 'col toxy (j*2)+2,(i*3)+3,iif(b(j*6+i+7)<>0,b(j*6+i+7)," ") next next toxy 10,1,"" end sub     function checkend dim i for i=0 to ubound(a) if (b(i)<>a(i)) then checkend=false : exit function next checkend=true end function   function move(d) dim p1 p1=pos0+d if b(p1) <>-1 then b(pos0)=b(p1): b(p1)=0: pos0=p1: move=true else move=false end if end function   sub shuffle dim cnt,r,i randomize timer for i=0 to ubound(a):b(i)=a(i):next pos0=28 cnt=0 do r=int(rnd*4) if move(dirs(r))=true then cnt=cnt+1 loop until cnt=maxshuffle end sub   function iif(a,b,c): if a then iif=b else iif=c end if:end function   function usr(a) dim d select case lcase(a) case "w" :d=-6 case "z" :d=6 case "a" :d=-1 case "s" :d=1 end select usr= move(d) end function  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Elm
Elm
module Main exposing (main)   import Html     main = List.range 1 100 |> List.reverse |> List.map (\n -> let nString = String.fromInt n   n1String = String.fromInt (n - 1) in [ nString ++ " bottles of beer on the wall" , nString ++ " bottles of beer" , "Take one down, pass it around" , n1String ++ " bottles of beer on the wall" ] |> List.map Html.text |> List.intersperse (Html.br [] []) |> Html.p [] ) |> Html.div []
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#TorqueScript
TorqueScript
function startTwentyFourGame() { if($numbers !$= "") { echo("Ending current 24 game..."); endTwentyFourGame(); }   echo("Welcome to the 24 game!"); echo("Generating 4 numbers..."); for(%a = 0; %a < 4; %a++) $numbers = setWord($numbers, %a, getRandom(0, 9));   echo("Numbers generated! Here are your numbers:"); echo($numbers); echo("Use try24Equation( equation ); to try and guess the equation.");   $TwentyFourGame = 1; }   function endTwentyFourGame() { if(!$TwentyFourGame) { echo("No 24 game is active!"); return false; }   echo("Ending the 24 game."); $numbers = ""; $TwentyFourGame = 0; }   function try24Equation(%equ) { if(!$TwentyFourGame) { echo("No 24 game is active!"); return false; } %numbers = "0123456789"; %operators = "+-*x/()"; %tempchars = $numbers; %other = strReplace(%tempchars, " ", "");   //Check it and make sure it has all the stuff %equ = strReplace(%equ, " ", ""); %length = strLen(%equ);   for(%a = 0; %a < %Length; %a++) { %Char = getSubStr(%equ, %a, 1); if(%a+1 != %Length) %Next = getSubStr(%equ, %a+1, 1); else %Next = " ";   if(strPos(%numbers @ %operators, %char) < 0) { echo("The equation you entered is invalid! Try again."); return false; } if(strPos(%tempchars, %char) < 0 && strPos(%operators, %char) < 0) { echo("The equation you entered uses a number you were not given! Try again."); return false; } else if(strPos(%numbers, %next) >= 0 && strPos(%numbers, %char) >= 0) { echo("No numbers above 9 please! Try again."); echo(%next SPC %char SPC %a); return false; } else if(strPos(%operators, %char) > 0) continue;   %pos = 2*strPos(%other, %char); if(%pos < 0) return "ERROROMG";   //Remove it from the allowed numbers %tempchars = removeWord(%tempchars, %pos/2); %other = getSubStr(%other, 0, %pos) @ getSubStr(%other, %pos+1, strLen(%other)); }    %result = doEquation(%equ);   if(%result != 24) { echo("Your equation resulted to" SPC %result @ ", not 24! Try again."); return false; }   for(%a = 0; %a < 4; %a++) $numbers = setWord($numbers, %a, getRandom(0, 9));   echo("Great job!" SPC %equ SPC "Does result to 24! Here's another set for you:"); echo($numbers); }   //Evaluates an equation without using eval. function doEquation(%equ) { //Validate the input  %equ = strReplace(%equ, " ", "");%equ = strReplace(%equ, "*", "x");  %equ = strReplace(%equ, "+", " + ");%equ = strReplace(%equ, "x", " x ");  %equ = strReplace(%equ, "/", " / ");%equ = strReplace(%equ, "-", " - ");   //Parenthesis' while(strPos(%equ, "(") > -1 && strPos(%equ, ")") > 0) {  %start = strPos(%equ, "(");  %end = %start;  %level = 1; while(%level != 0 && %end != strLen(%equ)) {  %end++; if(getsubStr(%equ, %end, 1) $= "(") %level++; if(getsubStr(%equ, %end, 1) $= ")") %level--; } if(%level != 0) return "ERROR";  %inbrackets = getsubStr(%equ, %start+1, %end - strLen(getsubStr(%equ, 0, %start + 1)));  %leftofbrackets = getsubStr(%equ, 0, %start);  %rightofbrackets = getsubStr(%equ, %end + 1, strLen(%equ) - %end);  %equ = %leftofbrackets @ doEquation(%inbrackets) @ %rightofbrackets; }   if(strPos(%equ, "ERROR") >= 0) return "ERROR";   //Multiplication/Division loop for(%a = 0; %a < getWordCount(%equ); %a++) { if(getWord(%equ, %a) $= "x" || getWord(%equ, %a) $= "/" && %a != 0) {  %f = getWord(%equ, %a - 1);  %l = getWord(%equ, %a + 1);  %o = getWord(%equ, %a); switch$(%o) { case "x": %a--;  %equ = removeWord(removeWord(setWord(%equ, %a+1, %f * %l), %a+2), %a); case "/": %a--;  %equ = removeWord(removeWord(setWord(%equ, %a+1, %f / %l), %a+2), %a); } } }   //Addition/Subraction loop for(%a = 0; %a < getWordCount(%equ); %a++) { if(getWord(%equ, %a) $= "+" || getWord(%equ, %a) $= "-" && %a != 0) {  %f = getWord(%equ, %a - 1);  %l = getWord(%equ, %a + 1);  %o = getWord(%equ, %a); switch$(%o) { case "+": %a--;  %equ = removeWord(removeWord(setWord(%equ, %a+1, %f + %l), %a+2), %a); case "-": %a--;  %equ = removeWord(removeWord(setWord(%equ, %a+1, %f - %l), %a+2), %a); } } } return %equ; }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#JavaScript
JavaScript
<html> <body> <div id='input'></div> <div id='output'></div> <script type='text/javascript'> var a = window.prompt('enter A number', ''); var b = window.prompt('enter B number', ''); document.getElementById('input').innerHTML = a + ' ' + b;   var sum = Number(a) + Number(b); document.getElementById('output').innerHTML = sum; </script> </body> </html>
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Swift
Swift
import Foundation   func Blockable(str: String) -> Bool {   var blocks = [ "BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", "JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM" ]   var strUp = str.uppercaseString var final = ""   for char: Character in strUp { var CharString: String = ""; CharString.append(char) for j in 0..<blocks.count { if blocks[j].hasPrefix(CharString) || blocks[j].hasSuffix(CharString) { final.append(char) blocks[j] = "" break } } }   return final == strUp }   func CanOrNot(can: Bool) -> String { return can ? "can" : "cannot" }   for str in [ "A", "BARK", "BooK", "TrEaT", "comMON", "sQuAd", "Confuse" ] { println("'\(str)' \(CanOrNot(Blockable(str))) be spelled with blocks.") }
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#Wren
Wren
import "random" for Random import "/dynamic" for Enum import "/ioutil" for Input import "/fmt" for Fmt   var Move = Enum.create("Move", ["up", "down", "right", "left"])   var Rand = Random.new() var RandMove = Fn.new { Rand.int(4) }   var SolvedBoard = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]   var AreEqual = Fn.new { |l1, l2| if (l1.count != l2.count) return false for (i in 0...l1.count) { if (l1[i] != l2[i]) return false } return true }   class Puzzle { construct new() { _board = SolvedBoard.toList _empty = 15 // _board[empty] == 0 _moves = 0 _quit = false // Could make this configurable, 10 == easy, 50 == normal, 100 == hard shuffle(50) }   shuffle(moves) { // we use some number of random moves to "shuffle" the board var i = 0 while (i < moves || AreEqual.call(_board, SolvedBoard)) { if (doMove(RandMove.call())) i = i + 1 } }   isValidMove(m) { if (m == Move.up) return [_empty - 4, (_empty/4).floor > 0] if (m == Move.down) return [_empty + 4, (_empty/4).floor < 3] if (m == Move.right) return [_empty + 1, _empty % 4 < 3] if (m == Move.left) return [_empty - 1, _empty % 4 > 0] Fiber.abort("not reached") }   doMove(m) { var i = _empty var res = isValidMove(m) var j = res[0] var ok = res[1] if (ok) { _board.swap(i, j) _empty = j _moves = _moves + 1 } return ok }   play() { var instructions = """ Please enter "U", "D", "L", or "R" to move the empty cell up, down, left, or right. You can also enter "Q" to quit. Upper or lowercase is accepted and only the first character is important (i.e. you may enter "up" if you like). """ System.print(instructions) System.write("\nStarting board:") while (!AreEqual.call(_board, SolvedBoard) && !_quit) { System.print("\n%(this)") playOneMove() } if (AreEqual.call(_board, SolvedBoard)) { System.print("\n%(this)") System.print("You solved the puzzle in %(_moves) moves.") } }   playOneMove() { while (true) { var s = Input.option("Enter move #%(_moves + 1) (U, D, L, R or Q): ", "UuDdLlRrQq") var m if (s == "U" || s == "u") { m = Move.up } else if (s == "D" || s == "d") { m = Move.down } else if (s == "L" || s == "l") { m = Move.left } else if (s == "R" || s == "r") { m = Move.right } else if (s == "Q" || s == "q") { System.print("Quiting after %(_moves).") _quit = true return } if (!doMove(m)) { System.print("That is not a valid move at the moment.") continue } return } }   toString { var buf = "" var i = 0 for (c in _board) { if (c == 0) { buf = buf + " ." } else { buf = buf + Fmt.swrite("$3d", c) } if (i % 4 == 3) buf = buf + "\n" i = i + 1 } return buf } }   var p = Puzzle.new() p.play()
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Emacs_Lisp
Emacs Lisp
(let ((i 99)) (while (> i 0) (message "%d bottles of beer on the wall" i) (message "%d bottles of beer" i) (message "Take one down, pass it around") (message "%d bottles of beer on the wall" (1- i)) (setq i (1- i))))
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT BUILD X_TABLE blanks = ":': :"   SECTION game operators="*'/'+'-'(')",numbers=""   LOOP n=1,4 number=RANDOM_NUMBERS (1,9,1) numbers=APPEND(numbers,number) ENDLOOP   SET allowed=APPEND (numbers,operators) SET allowed=MIXED_SORT (allowed) SET allowed=REDUCE (allowed) BUILD S_TABLE ALLOWED =* DATA '{allowed}'   SET checksum=DIGIT_SORT (numbers)   printnumbers=EXCHANGE (numbers,blanks) printoperat=EXCHANGE (operators,blanks)   PRINT "Your numbers ", printnumbers PRINT "Use only these operators ", printoperat PRINT "Enter an expression that equates to 24" PRINT "Enter 'l' for new numbers" PRINT "Your 4 digits: ",printnumbers   DO play ENDSECTION   SECTION check_expr SET pos = VERIFY (expr,allowed) IF (pos!=0) THEN PRINT "wrong entry on position ",pos DO play STOP ELSE SET yourdigits = STRINGS (expr,":>/:") SET yourchecksum = DIGIT_SORT (yourdigits) IF (checksum!=yourchecksum) THEN PRINT/ERROR "wrong digits" DO play STOP ELSE CONTINUE ENDIF ENDIF ENDSECTION   SECTION play LOOP n=1,3 ASK "Expression {n}": expr="" IF (expr=="l") THEN RELEASE S_TABLE allowed PRINT "Your new numbers" DO game ELSEIF (expr!="") THEN DO check_expr sum={expr} IF (sum!=24) THEN PRINT/ERROR expr," not equates 24 but ",sum CYCLE ELSE PRINT "BINGO ", expr," equates ", sum STOP ENDIF ELSE CYCLE ENDIF ENDLOOP ENDSECTION DO game  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Joy
Joy
get get +.
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Tcl
Tcl
package require Tcl 8.6   proc abc {word {blocks {BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM}}} { set abc {{letters blocks abc} { set rest [lassign $letters ch] set i 0 foreach blk $blocks { if {$ch in $blk && (![llength $rest] || [apply $abc $rest [lreplace $blocks $i $i] $abc])} { return true } incr i } return false }} return [apply $abc [split $word ""] [lmap b $blocks {split $b ""}] $abc] }   foreach word {"" A BARK BOOK TREAT COMMON SQUAD CONFUSE} { puts [format "Can we spell %9s? %s" '$word' [abc $word]] }
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#x86-64_Assembly
x86-64 Assembly
 ; Puzzle15 by grosged (march 2019)  ; How to play ?.. Just press one of the arrow keys then [enter] to valid  ; ( press [Ctrl+C] to escape )   segment .data check: db "1 2 3 4",10," 5 6 7 8",10," 9 10 11 12",10," 13 14 1" puzzle: db 27,"c",10," 1 2 3 4",10," 5 6 7 8",10," 9 10 11 12",10," 13 14 15 ",10,10 db " Direction ?",13 db " Well done ! ",10,10 inKey: dw 0,0,0,0   segment .text global _start   _start: mov rax,100 syscall mov rcx,rax shr rcx,3 and rcx,255 and rax,31 lea rsi,[_start+rax] mov rbx,15   Mixing: push rcx mov di,word[rsi+rcx*2] mov rcx,8 quatre: mov ax,di shr di,2 and ax,3 add ax,65 call SWAPPIN loop quatre pop rcx loop Mixing cmp cx,ax   MainLp: mov rdx,80 Succes: lea rsi,[puzzle] mov rdi,1 mov rax,1 End?: syscall mov rax,60 je End? mov rdx,8 lea rsi,[inKey] mov rdi,0 mov rax,0 syscall mov al,byte [rsi+rax-2] call SWAPPIN lea rsi,[check] lea rdi,[puzzle+5] mov rcx,7 repe cmpsq jne MainLp mov rdx,95 jmp Succes   SWAPPIN:mov rdx,rbx cmp al,"A" jne NotUp add rbx,4 cmp rbx,16 cmovae rbx,rdx NotUp: cmp al,"B" jne NotDwn sub rbx,4 cmovc rbx,rdx NotDwn: cmp al,"C" jne NotLft test rbx,3 jz Endcll dec rbx NotLft: cmp al,"D" jne Endcll inc rbx test rbx,3 cmovz rbx,rdx Endcll: mov ax," " xchg ax,word[puzzle+4+rbx*4] mov word[puzzle+4+rdx*4],ax ret
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Erlang
Erlang
-module(beersong). -export([sing/0]). -define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99 bottles of beer on the wall.~n"). -define(TEMPLATE_N, "~s of beer on the wall, ~s of beer.~nTake one down and pass it around, ~s of beer on the wall.~n~n").   create_verse(0) -> {0, io_lib:format(?TEMPLATE_0, phrase(0))}; create_verse(Bottle) -> {Bottle, io_lib:format(?TEMPLATE_N, phrase(Bottle))}.   phrase(0) -> ["No more bottles", "no more bottles"]; phrase(1) -> ["1 bottle", "1 bottle", "no more bottles"]; phrase(2) -> ["2 bottles", "2 bottles", "1 bottle"]; phrase(Bottle) -> lists:duplicate(2, integer_to_list(Bottle) ++ " bottles") ++ [integer_to_list(Bottle-1) ++ " bottles"].   bottles() -> lists:reverse(lists:seq(0,99)).   sing() -> lists:foreach(fun spawn_singer/1, bottles()), sing_verse(99).   spawn_singer(Bottle) -> Pid = self(), spawn(fun() -> Pid ! create_verse(Bottle) end).   sing_verse(Bottle) -> receive {_, Verse} when Bottle == 0 -> io:format(Verse); {N, Verse} when Bottle == N -> io:format(Verse), sing_verse(Bottle-1) after 3000 -> io:format("Verse not received - re-starting singer~n"), spawn_singer(Bottle), sing_verse(Bottle) end.
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#UNIX_Shell
UNIX Shell
gen_digits() { awk 'BEGIN { srand() for(i = 1; i <= 4; i++) print 1 + int(9 * rand()) }' | sort }   same_digits() { [ "$(tr -dc 0-9 | sed 's/./&\n/g' | grep . | sort)" = "$*" ] }   guessed() { [ "$(echo "$1" | tr -dc '\n0-9()*/+-' | bc 2>/dev/null)" = 24 ] }     while : do digits=$(gen_digits) echo echo Digits: $digits read -r expr   echo " $expr" | same_digits "$digits" || \ { echo digits should be: $digits; continue; }   guessed "$expr" && message=correct \ || message=wrong   echo $message done
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#jq
jq
$ jq -s add 3 2 5
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#TUSCRIPT
TUSCRIPT
set words = "A'BARK'BOOK'TREAT'COMMON'SQUAD'CONFUSE" set result = * loop word = words set blocks = "BO'XK'DQ'CP'NA'GT'RE'TG'QD'FS'JW'HU'VI'AN'OB'ER'FS'LY'PC'ZM" set wordx = split (word, |"~</~") set cond = "true" loop char = wordx set n = filter_index (blocks, "~*{char}*~", -) if (n.eq."") then set cond = "false" exit endif set n2 = select (n, 1) set n3 = select (blocks, #n2, blocks) endloop set out = concat (word, " ", cond) set result = append (result, out) endloop
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#XBasic
XBasic
  PROGRAM "fifteenpuzzlegame" VERSION "0.0001"   IMPORT "xst"   DECLARE FUNCTION Entry() INTERNAL FUNCTION PrintPuzzle(d%[]) INTERNAL FUNCTION IntroAndLevel(shCnt%[]) INTERNAL FUNCTION BuildBoard(d%[], shCnt%[], level%) INTERNAL FUNCTION IsMoveValid(d%[], piece%, piecePos%, emptyPos%) INTERNAL FUNCTION IsPuzzleComplete(d%[]) INTERNAL FUNCTION PiecePosition(d%[], piece%)   ' Pseudo-random number generator ' Based on the rand, srand functions from Kernighan & Ritchie's book ' 'The C Programming Language' DECLARE FUNCTION Rand() DECLARE FUNCTION SRand(seed%%)   FUNCTION Entry() DIM d%[15] DIM shCnt%[2] BuildBoard(@d%[], @shCnt%[], IntroAndLevel(@shCnt%[])) PrintPuzzle(@d%[]) DO x% = SSHORT(INLINE$("To move a piece, enter its number: ")) DO WHILE IsMoveValid(@d%[], x%, @y%, @z%) = 0 PRINT "Wrong move." PrintPuzzle(@d%[]) x% = SSHORT(INLINE$("To move a piece, enter its number: ")) LOOP d%[z% - 1] = x% d%[y% - 1] = 0 PrintPuzzle(@d%[]) LOOP UNTIL IsPuzzleComplete(@d%[]) PRINT "YOU WON!" END FUNCTION   FUNCTION PrintPuzzle(d%[]) DIM ds$[15] ' Board pieces FOR p%% = 0 TO 15 IF d%[p%%] = 0 THEN ds$[p%%] = " " ELSE ds$[p%%] = FORMAT$("### ", d%[p%%]) END IF NEXT p%% PRINT "+-----+-----+-----+-----+" PRINT "|"; ds$[0]; "|"; ds$[1]; "|"; ds$[2]; "|"; ds$[3]; "|" PRINT "+-----+-----+-----+-----+" PRINT "|"; ds$[4]; "|"; ds$[5]; "|"; ds$[6]; "|"; ds$[7]; "|" PRINT "+-----+-----+-----+-----+" PRINT "|"; ds$[8]; "|"; ds$[9]; "|"; ds$[10]; "|"; ds$[11]; "|" PRINT "+-----+-----+-----+-----+" PRINT "|"; ds$[12]; "|"; ds$[13]; "|"; ds$[14]; "|"; ds$[15]; "|" PRINT "+-----+-----+-----+-----+" END FUNCTION   FUNCTION IntroAndLevel(shCnt%[]) XstClearConsole() shCnt%[0] = 10 shCnt%[1] = 50 shCnt%[2] = 100 PRINT "15 PUZZLE GAME" PRINT PRINT PRINT "Please enter level of difficulty," DO level% = SSHORT(INLINE$("1 (easy), 2 (medium) or 3 (hard): ")) LOOP UNTIL (level% >= 1) && (level% <= 3) END FUNCTION level%   FUNCTION BuildBoard(d%[], shCnt%[], level%) ' Set pieces in correct order first FOR p%% = 1 TO 15 d%[p%% - 1] = p%% NEXT p%% d%[15] = 0 ' 0 = empty piece/slot z% = 16 ' z% = empty position PRINT PRINT "Shuffling pieces"; XstGetSystemTime (@msec) SRand(INT(msec) MOD 32768) FOR n% = 1 TO shCnt%[level% - 1] PRINT "."; DO x% = INT(Rand() / 32768.0 * 4.0) + 1 PRINT x% SELECT CASE x% CASE 1: r% = z% - 4 CASE 2: r% = z% + 4 CASE 3: IF (z% - 1) MOD 4 <> 0 THEN r% = z% - 1 END IF CASE 4: IF z% MOD 4 <> 0 THEN r% = z% + 1 END IF END SELECT LOOP UNTIL (r% >= 1) && (r% <= 16) d%[z% - 1] = d%[r% - 1] z% = r% d%[z% - 1] = 0 NEXT n% XstClearConsole() END FUNCTION   FUNCTION IsMoveValid(d%[], piece%, piecePos%, emptyPos%) mv% = 0 IF (piece% >= 1) && (piece% <= 15) THEN piecePos% = PiecePosition(@d%[], piece%) emptyPos% = PiecePosition(@d%[], 0) ' Check if empty piece is above, below, left or right to piece IF (piecePos% - 4 = emptyPos%) || (piecePos% + 4 = emptyPos%) || ((piecePos% - 1 = emptyPos%) && (emptyPos% MOD 4 <> 0)) || ((piecePos% + 1 = emptyPos%) && (piecePos% MOD 4 <> 0)) THEN mv% = 1 END IF END IF END FUNCTION mv%   FUNCTION PiecePosition(d%[], piece%) p%% = 0 DO WHILE d%[p%%] <> piece% INC p%% IF p%% > 15 THEN PRINT "UH OH!" QUIT(1) END IF LOOP END FUNCTION p%% + 1   FUNCTION IsPuzzleComplete(d%[]) pc% = 0 p%% = 1 DO WHILE (p%% < 16) && (d%[p%% - 1] = p%%) INC p%% LOOP IF p%% = 16 THEN pc% = 1 END IF END FUNCTION pc%   ' Return pseudo-random integer on 0..32767 FUNCTION Rand() #next&& = #next&& * 1103515245 + 12345 END FUNCTION USHORT(#next&& / 65536) MOD 32768   ' Set seed for Rand() FUNCTION SRand(seed%%) #next&& = seed%% END FUNCTION   END PROGRAM  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Euphoria
Euphoria
constant bottles = "bottles", bottle = "bottle"   procedure beers (integer how_much) sequence word1 = bottles, word2 = bottles switch how_much do case 2 then word2 = bottle case 1 then word1 = bottle word2 = bottle end switch   printf (1, "%d %s of beer on the wall \n" & "%d %s of beer \n" & "Take one down, and pass it around \n" & "%d %s of beer on the wall \n\n", { how_much, word1, how_much, word1, how_much-1, word2 } ) end procedure   for a = 99 to 1 by -1 do beers (a) end for
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#VBA
VBA
  Sub Rosetta_24game()   Dim Digit(4) As Integer, i As Integer, iDigitCount As Integer Dim stUserExpression As String Dim stFailMessage As String, stFailDigits As String Dim bValidExpression As Boolean, bValidDigits As Boolean, bValidChars As Boolean Dim vResult As Variant, vTryAgain As Variant, vSameDigits As Variant   ' Generate 4 random digits GenerateNewDigits: For i = 1 To 4 Digit(i) = [randbetween(1,9)] Next i   ' Get user expression GetUserExpression: bValidExpression = True stFailMessage = "" stFailDigits = "" stUserExpression = InputBox("Enter a mathematical expression which results in 24, using the following digits: " & _ Digit(1) & ", " & Digit(2) & ", " & Digit(3) & " and " & Digit(4), "Rosetta Code | 24 Game")   ' Check each digit is included in user expression bValidDigits = True stFailDigits = "" For i = 1 To 4 If InStr(stUserExpression, Digit(i)) = 0 Then bValidDigits = False stFailDigits = stFailDigits & " " & Digit(i) End If Next i If bValidDigits = False Then bValidExpression = False stFailMessage = "Your expression excluded the following required digits: " & stFailDigits & vbCr & vbCr End If   ' Check each character of user expression is a valid character type bValidDigits = True stFailDigits = "" For i = 1 To Len(stUserExpression) If InStr("0123456789+-*/()", Mid(stUserExpression, i, 1)) = 0 Then bValidDigits = False stFailDigits = stFailDigits & " " & Mid(stUserExpression, i, 1) End If Next i If bValidDigits = False Then bValidExpression = False stFailMessage = stFailMessage & "Your expression contained invalid characters:" & stFailDigits & vbCr & vbCr End If   ' Check no disallowed integers entered bValidDigits = True stFailDigits = "" iDigitCount = 0 For i = 1 To Len(stUserExpression) If Not InStr("0123456789", Mid(stUserExpression, i, 1)) = 0 Then iDigitCount = iDigitCount + 1 If IsError(Application.Match(--(Mid(stUserExpression, i, 1)), Digit, False)) Then bValidDigits = False stFailDigits = stFailDigits & " " & Mid(stUserExpression, i, 1) End If End If Next i If iDigitCount > 4 Then bValidExpression = False stFailMessage = stFailMessage & "Your expression contained more than 4 digits" & vbCr & vbCr End If If iDigitCount < 4 Then bValidExpression = False stFailMessage = stFailMessage & "Your expression contained less than 4 digits" & vbCr & vbCr End If If bValidDigits = False Then bValidExpression = False stFailMessage = stFailMessage & "Your expression contained invalid digits:" & stFailDigits & vbCr & vbCr End If   ' Check no double digit numbers entered bValidDigits = True stFailDigits = "" For i = 11 To 99 If Not InStr(stUserExpression, i) = 0 Then bValidDigits = False stFailDigits = stFailDigits & " " & i End If Next i If bValidDigits = False Then bValidExpression = False stFailMessage = stFailMessage & "Your expression contained invalid numbers:" & stFailDigits & vbCr & vbCr End If   ' Check result of user expression On Error GoTo EvalFail vResult = Evaluate(stUserExpression) If Not vResult = 24 Then bValidExpression = False stFailMessage = stFailMessage & "Your expression did not result in 24. It returned: " & vResult End If   ' Return results If bValidExpression = False Then vTryAgain = MsgBox(stFailMessage & vbCr & vbCr & "Would you like to try again?", vbCritical + vbRetryCancel, "Rosetta Code | 24 Game | FAILED") If vTryAgain = vbRetry Then vSameDigits = MsgBox("Do you want to use the same numbers?", vbQuestion + vbYesNo, "Rosetta Code | 24 Game | RETRY") If vSameDigits = vbYes Then GoTo GetUserExpression Else GoTo GenerateNewDigits End If End If Else vTryAgain = MsgBox("You entered: " & stUserExpression & vbCr & vbCr & "which resulted in: " & vResult, _ vbInformation + vbRetryCancel, "Rosetta Code | 24 Game | SUCCESS") If vTryAgain = vbRetry Then GoTo GenerateNewDigits End If End If Exit Sub EvalFail: bValidExpression = False vResult = Err.Description Resume End Sub    
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Jsish
Jsish
/* A+B in Jsish */ var line = console.input(); var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/); if (nums) { var A = Number(nums[1]); var B = Number(nums[2]); if (A <= 1000 && A >= -1000 && B <= 1000 && B >= -1000) { printf("%d\n", A + B); } else { puts("error: A and B both need to be in range -1000 thru 1000 inclusive"); } } else { puts("error: A+B requires two numbers separated by space"); }
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#TXR
TXR
@(do (defvar blocks '((B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M)))    ;; Define and build hash which maps each letter that occurs in blocks  ;; to a list of the blocks in which that letter occurs.   (defvar alpha2blocks [hash-uni [group-by first blocks] [group-by second blocks] append])    ;; convert, e.g. "abc" -> (A B C)  ;; intern -- convert a string to an interned symbol "A" -> A  ;; tuples -- turn string into 1-element tuples: "ABC" -> ("A" "B" "C")  ;; square brackets around mapcar -- Lisp-1 style evaluation, allowing  ;; the intern function binding to be treated as a variable binding.   (defun string-to-syms (str) [mapcar intern (tuples 1 (upcase-str str))])    ;; Recursive part of algorithm working purely with Lisp symbols.  ;; alpha -- single symbol denoting a letter  ;; [alpha2blocks alpha] -- look up list of blocks for given letter  ;; (memq item list) -- is item a member of list, under eq equality?  ;; (remq item list) -- remove items from list which are eq to item.   (defun can-make-word-guts (letters blocks) (cond ((null letters) t) ((null blocks) nil) (t (let ((alpha (first letters))) (each ((bl [alpha2blocks alpha])) (if (and (memq bl blocks) (can-make-word-guts (rest letters) (remq bl blocks))) (return-from can-make-word-guts t)))))))   (defun can-make-word (str) (can-make-word-guts (string-to-syms str) blocks))) @(repeat) @w @(output) >>> can_make_word("@(upcase-str w)") @(if (can-make-word w) "True" "False") @(end) @(end)
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#XPL0
XPL0
int Box, Hole, I; [Box:= [^ ,^F,^E,^D, \starting configuration ^C,^B,^A,^9, \slide digits into ascending order ^8,^7,^6,^5, \with blank in lower-right corner ^4,^3,^2,^1]; Hole:= 0; \index for hole position loop [Clear; \erase screen and move to start for I:= 0 to 15 do \show puzzle [ChOut(0, Box(I)); ChOut(0, ^ ); if (I & 3) = 3 then CrLf(0)]; case ChIn(1) of \get move $1B: quit; \Esc $48: if Hole < 12 then \UpArrow scan code [Box(Hole):= Box(Hole+4); Hole:= Hole+4; Box(Hole):= ^ ]; $50: if Hole > 3 then \DnArrow [Box(Hole):= Box(Hole-4); Hole:= Hole-4; Box(Hole):= ^ ]; $4B: if (Hole & 3) < 3 then \LfArrow [Box(Hole):= Box(Hole+1); Hole:= Hole+1; Box(Hole):= ^ ]; $4D: if (Hole & 3) > 0 then \RtArrow [Box(Hole):= Box(Hole-1); Hole:= Hole-1; Box(Hole):= ^ ] other []; \ignore 0 scan code prefix etc. ]; ]
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Extended_BrainF.2A.2A.2A
Extended BrainF***
#light let rec bottles n = let (before, after) = match n with | 1 -> ("bottle", "bottles") | 2 -> ("bottles", "bottle") | n -> ("bottles", "bottles") printfn "%d %s of beer on the wall" n before printfn "%d %s of beer" n before printfn "Take one down, pass it around" printfn "%d %s of beer on the wall\n" (n - 1) after if n > 1 then bottles (n - 1)
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Vlang
Vlang
import os import rand import rand.seed import math   fn main() { rand.seed(seed.time_seed_array(2)) mut n := []int{len: 4} for i in 0.. n.len { n[i] = rand.intn(9) or {0} } println("Your numbers: $n") expr := os.input("Enter RPN: ") if expr.len != 7 { println("invalid. expression length must be 7." + " (4 numbers, 3 operators, no spaces)") return } mut stack := []f64{len: 0, cap:4} for r in expr.split('') { if r >= '0' && r <= '9' { if n.len == 0 { println("too many numbers.") return } mut i := 0 for n[i] != r.int() { i++ if i == n.len { println("wrong numbers.") return } } n.delete(n.index(r.int())) stack << f64(r[0]-'0'[0]) continue } if stack.len < 2 { println("invalid expression syntax.") return } match r { '+' { stack[stack.len-2] += stack[stack.len-1] } '-' { stack[stack.len-2] -= stack[stack.len-1] } '*' { stack[stack.len-2] *= stack[stack.len-1] } '/' { stack[stack.len-2] /= stack[stack.len-1] } else { println("$r invalid.") return } } stack = stack[..stack.len-1] } if math.abs(stack[0]-24) > 1e-6 { println("incorrect. ${stack[0]} != 24") } else { println("correct.") } }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Julia
Julia
input = parse.(Int, split(readline(stdin))) println(stdout, sum(input))
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Ultimate.2B.2B
Ultimate++
  #include <Core/Core.h> #include <stdio.h> #include <ctype.h> //C++ #include <iostream> #include <vector> #include <string> #include <set> #include <cctype>     //C++ typedef std::pair<char,char> item_t; typedef std::vector<item_t> list_t;     //C using namespace Upp;   int can_make_words(char **b, char *word) { int i, ret = 0, c = toupper(*word);   if (!c) return 1; if (!b[0]) return 0;   for (i = 0; b[i] && !ret; i++) { if (b[i][0] != c && b[i][1] != c) continue; Swap(b[i], b[0]); // It needs to be Swap and not SWAP ret = can_make_words(b + 1, word + 1); Swap(b[i], b[0]); // It needs to be Swap instead of SWAP } return ret; }     //C++   bool can_create_word(const std::string& w, const list_t& vals) { std::set<uint32_t> used; while (used.size() < w.size()) { const char c = toupper(w[used.size()]); uint32_t x = used.size(); for (uint32_t i = 0, ii = vals.size(); i < ii; ++i) { if (used.find(i) == used.end()) { if (toupper(vals[i].first) == c || toupper(vals[i].second) == c) { used.insert(i); break; } } } if (x == used.size()) break; } return used.size() == w.size(); }     // U++ CONSOLE_APP_MAIN { // C char* blocks[] = { (char*)"BO", (char*)"XK", (char*)"DQ", (char*)"CP", (char*)"NA", (char*)"GT", (char*)"RE", (char*)"TG", (char*)"QD", (char*)"FS", (char*)"JW", (char*)"HU", (char*)"VI", (char*)"AN", (char*)"OB", (char*)"ER", (char*)"FS", (char*)"LY", (char*)"PC", (char*)"ZM", 0 };   char *words[] = { (char*)"", (char*)"A", (char*)"BARK", (char*)"BOOK", (char*)"TREAT", (char*)"COMMON", (char*)"SQUAD", (char*)"Confuse", 0 };   char **w; for (w = words; *w; w++) printf("%s\t%d\n", *w, can_make_words(blocks, *w));   printf("\n");   // C++ list_t vals{ {'B', 'O'}, {'X', 'K'}, {'D', 'Q'}, {'C', 'P'}, {'N', 'A'}, {'G', 'T'}, {'R', 'E'}, {'T', 'G'}, {'Q', 'D'}, {'F', 'S'}, {'J', 'W'}, {'H', 'U'}, {'V', 'I'}, {'A', 'N'}, {'O', 'B'}, {'E', 'R'}, {'F', 'S'}, {'L', 'Y'}, {'P', 'C'}, {'Z', 'M'} }; std::vector<std::string> wordsb{"A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "Confuse"}; for (const std::string& w : wordsb) { std::cout << w << ": " << std::boolalpha << can_create_word(w, vals) << ".\n"; } std::cout << "\n";       const Vector<String>& cmdline = CommandLine(); for(int i = 0; i < cmdline.GetCount(); i++) { }   }  
http://rosettacode.org/wiki/15_puzzle_game
15 puzzle game
Task Implement the Fifteen Puzzle Game. The   15-puzzle   is also known as:   Fifteen Puzzle   Gem Puzzle   Boss Puzzle   Game of Fifteen   Mystic Square   14-15 Puzzle   and some others. Related Tasks   15 Puzzle Solver   16 Puzzle Game
#Yabasic
Yabasic
dx = 4 : dy = 4 : dxy = dx * dy dim grid(dx, dy)   dim t(dxy)   for x = 1 to dx for y = 1 to dy fin = false repeat i = int(ran(dxy) + 1) if t(i) = 0 then t(i) = 1 fin = true if i < dxy then grid(x, y) = i else ex = x : ey = y end if end if until(fin = true) next y next x   drawTable()   repeat moveTile() drawTable() until(finish())   print "\n\n\nNumber of movements: ",mov,"\nEnd\n"   sub finish() local x, y, v   for y = 1 to dy for x = 1 to dx v = v + 1 if (v < dxy) and (grid(x, y) <> v) return false next x next y return true end sub   sub moveTile() local direction$   direction$ = inkey$   switch direction$ case "up": if (ey + 1) < (dy + 1) then grid(ex, ey) = grid(ex, ey + 1) : ey = ey + 1 end if : break case "down": if (ey - 1) > 0 then grid(ex, ey) = grid(ex, ey - 1) : ey = ey - 1 end if : break case "right": if (ex - 1) > 0 then grid(ex, ey) = grid(ex - 1, ey) : ex = ex - 1 end if : break case "left": if (ex + 1) < (dx + 1) then grid(ex, ey) = grid(ex + 1, ey) : ex = ex + 1 end if : break default: return : break end switch mov = mov + 1 grid(ex, ey) = 0 end sub   sub drawTable() local x, y   clear screen   print " Use the cursor keys"   for x = 1 to dx for y = 1 to dy print at(x * 3, y * 2); if grid(x, y) then print color("yellow","magenta") grid(x, y) using "##" else print " " end if next y next x end sub
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#F.23
F#
#light let rec bottles n = let (before, after) = match n with | 1 -> ("bottle", "bottles") | 2 -> ("bottles", "bottle") | n -> ("bottles", "bottles") printfn "%d %s of beer on the wall" n before printfn "%d %s of beer" n before printfn "Take one down, pass it around" printfn "%d %s of beer on the wall\n" (n - 1) after if n > 1 then bottles (n - 1)
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Wren
Wren
import "random" for Random import "/ioutil" for Input import "/seq" for Stack   var R = Random.new()   class Game24 { static run() { var digits = List.filled(4, 0) for (i in 0..3) digits[i] = R.int(1, 10) System.print("Make 24 using these digits: %(digits)") var cin = Input.text("> ") var s = Stack.new() var total = 0 for (c in cin) { var d = c.bytes[0] if (d >= 48 && d <= 57) { d = d - 48 total = total + (1 << (d*5)) s.push(d) } else if ("+-*/".indexOf(c) != -1) s.push(applyOperator_(s.pop(), s.pop(), c)) } if (tallyDigits_(digits) != total) { System.write("Not the same digits.") } else if ((24 - s.peek()).abs < 0.001) { System.print("Correct!") } else { System.write("Not correct.") } }   static applyOperator_(a, b, c) { if (c == "+") return a + b if (c == "-") return b - a if (c == "*") return a * b if (c == "/") return b / a return 0/0 }   static tallyDigits_(a) { var total = 0 for (i in 0...a.count) total = total + (1 << (a[i]*5)) return total } }   Game24.run()
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#K
K
  split:{(a@&~&/' y=/: a:(0,&x=y)_ x) _dv\: y} ab:{+/0$split[0:`;" "]} ab[] 2 3 5  
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#UNIX_Shell
UNIX Shell
can_build_word() { if [[ $1 ]]; then can_build_word_rec "$1" BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM else return 1 fi }   can_build_word_rec() { [[ -z $1 ]] && return 0   local -u word=$1 # uppercase the first parameter shift local blocks=("$@")   # see if we have a block for the first letter local letter=${word:0:1} indices=() i for (( i=0; i<${#blocks[@]}; i++ )); do if [[ ${blocks[i]} == *$letter* ]]; then indices+=($i) fi done (( ${#indices[@]} == 0 )) && return 1   local tmp for i in ${indices[@]}; do tmp=( "${blocks[@]}" ) unset "tmp[$i]" can_build_word_rec "${word:1}" "${tmp[@]}" && return 0 done   return 1 }   words=( "" A BARK Book treat COMMON Squad confuse ) for word in "${words[@]}"; do can_build_word "$word" "${blocks[@]}" && ans=yes || ans=no printf "%s\t%s\n" "$word" $ans done
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Factor
Factor
USING: io kernel make math math.parser math.ranges sequences ;   : bottle ( -- quot ) [ [ [ [ # " bottles of beer on the wall,\n" % ] [ # " bottles of beer.\n" % ] bi ] keep "Take one down, pass it around,\n" % 1 - # " bottles of beer on the wall\n" % ] " " make print ] ; inline   : last-verse ( -- ) "Go to the store and buy some more," "no more bottles of beer on the wall!" [ print ] bi@ ;   : bottles ( n -- ) 1 [a,b] bottle each last-verse ;   ! Usage: 99 bottles
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#Yabasic
Yabasic
operadores$ = "*/+-" espacios$ = " "   clear screen print "24 Game" print "============\n" print "The player is provided with 4 numbers with which to perform operations" print "of addition (+), subtraction (-), multiplication (*) or division (/) to attempt" print "to get 24 as result." print "Use reverse Polish notation (first the operands and then the operators)." print "For example: instead of 2 + 4, type 2 4 +\n\n"   repeat print at(0,9) espacios$, espacios$, espacios$, espacios$, espacios$, espacios$ print at(0,9); serie$ = ordenaCadena$(genSerie$()) validos$ = serie$+operadores$ line input "Enter your formula in reverse Polish notation: " entrada$ entrada$ = quitaEspacios$(entrada$) entradaOrd$ = ordenaCadena$(entrada$) if (right$(entradaOrd$,4) <> serie$) or (len(entradaOrd$)<>7) then print "Error in the entered series" else resultado = evaluaEntrada(entrada$) print "The result is = ",resultado," " if resultado = 24 then print "Correct!" else print "Error!" end if end if print "Want to try again? (press N to exit, or another key to continue)" until(upper$(left$(inkey$(),1)) = "N")   sub genSerie$() local i, c$, s$   print "The numbers to be used are: "; i = ran() for i = 1 to 4 c$ = str$(int(ran(9))+1) print c$," "; s$ = s$ + c$ next i print return s$ end sub     sub evaluaEntrada(entr$) local d1, d2, c$, n(4), i   while(entr$<>"") c$ = left$(entr$,1) entr$ = mid$(entr$,2) if instr(serie$,c$) then i = i + 1 n(i) = val(c$) elseif instr(operadores$,c$) then d2 = n(i) n(i) = 0 i = i - 1 d1 = n(i) n(i) = evaluador(d1, d2, c$) else print "Invalid sign" return end if wend   return n(i)   end sub     sub evaluador(d1, d2, op$) local t   switch op$ case "+": t = d1 + d2 : break case "-": t = d1 - d2 : break case "*": t = d1 * d2 : break case "/": t = d1 / d2 : break end switch   return t end sub     sub quitaEspacios$(entr$) local n, i, s$, t$(1)   n = token(entr$,t$()," ")   for i=1 to n s$ = s$ + t$(i) next i return s$ end sub     sub ordenaCadena$(cadena$) local testigo, n, fin, c$   fin = len(cadena$)-1 repeat testigo = false for n = 1 to fin if mid$(cadena$,n,1) > mid$(cadena$,n+1,1) then testigo = true c$ = mid$(cadena$,n,1) mid$(cadena$,n,1) = mid$(cadena$,n+1,1) mid$(cadena$,n+1,1) = c$ end if next n until(testigo = false) return cadena$ end sub
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Keg
Keg
+.
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#UTFool
UTFool
  ··· http://rosettacode.org/wiki/ABC_Problem ··· ■ ABC § static blocks⦂ StringBuffer " BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM" ▶ main • args⦂ String[] for each word in ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"]⦂ String   System.out.println "⸨word⸩: ⸨canMakeWord word⸩"   ▶ canMakeWord⦂ boolean • word⦂ String solution⦂ boolean: word.isEmpty° if no solution i⦂ int: blocks.indexOf word.substring 0, 1 🔁 until solution or i < 0 i: i ÷ 3 × 3 · block index block⦂ String: blocks.substring i, i + 3 blocks.delete i, i + 3 · remove block solution: canMakeWord word.substring 1 blocks.insert i, block · restore block i: blocks.indexOf (word.substring 0, 1), i + 3 return solution  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Falcon
Falcon
for i in [99:1] > i, " bottles of beer on the wall" > i, " bottles of beer" > "Take one down, pass it around" > i-1, " bottles of beer on the wall\n" end
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#zkl
zkl
while(1){ digits := [1..4].pump(String,(0).random.fpM("11-",1,9)); exp := ask("Enter an expression using the digits ",digits, " that evals to 24: ") - " \n"; expf:=exp.apply(fcn(c){if ("1"<=c<="9") "(%s).toFloat()".fmt(c) else c}); reg r; try { Compiler.Compiler.compileText(expf).__constructor(); r=vm.regX } catch { println("bad expression"); continue; } else{ extra := (exp - "+-/*()" - digits); if (extra) { println("Extra goodies in expression: ",extra); continue; } (digits.split("").sort() != (exp - "+-/*()").split("").sort()) : if(_) { println("You can only use the digits ",digits," once each"); continue; }; if (exp.matches("*[1-9][1-9]*")) { println("no repeated digits"); continue; } if (r.closeTo(24,0.001)) "nice!".println(); else println("That evaled to ",r,", not 24"); } }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Kite
Kite
#!/usr/bin/kite   import "System.file";   in = System.file.stdin; line = in|readline; while(not (line is null)) [ arry = line|split(" "); result = (arry[0])|int + (arry[1])|int; result|print;   line = in|readline; ];
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#VBA
VBA
  Option Explicit   Sub Main_ABC() Dim Arr, i As Long   Arr = Array("A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE") For i = 0 To 6 Debug.Print ">>> can_make_word " & Arr(i) & " => " & ABC(CStr(Arr(i))) Next i End Sub   Function ABC(myWord As String) As Boolean Dim myColl As New Collection Dim NbLoop As Long, NbInit As Long Dim b As Byte, i As Byte Const BLOCKS As String = "B,O;X,K;D,Q;C,P;N,A;G,T;R,E;T,G;Q,D;F,S;J,W;H,U;V,I;A,N;O,B;E,R;F,S;L,Y;P,C;Z,M"   For b = 0 To 19 myColl.Add Split(BLOCKS, ";")(b), Split(BLOCKS, ";")(b) & b Next b NbInit = myColl.Count NbLoop = NbInit For b = 1 To Len(myWord) For i = 1 To NbLoop If i > NbLoop Then Exit For If InStr(myColl(i), Mid(myWord, b, 1)) <> 0 Then myColl.Remove (i) NbLoop = NbLoop - 1 Exit For End If Next Next b ABC = (NbInit = (myColl.Count + Len(myWord))) End Function  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#FALSE
FALSE
uses "console";   number bottles = 99; boolean looping = true; object counter = closure { if (--bottles > 0) { return true; } else { return false; } };   while (looping) { Console.println("${bottles} bottles of beer on the wall,"); Console.println("${bottles} bottles of beer,"); Console.println("Take one down, pass it around,");   looping = counter.invoke();   Console.println("${bottles} bottles of beer on the wall.");
http://rosettacode.org/wiki/24_game
24 game
The 24 Game tests one's mental arithmetic. Task Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24. Only the following operators/functions are allowed: multiplication, division, addition, subtraction Division should use floating point or rational arithmetic, etc, to preserve remainders. Brackets are allowed, if using an infix expression evaluator. Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). The order of the digits when given does not have to be preserved. Notes The type of expression evaluator used is not mandated. An RPN evaluator is equally acceptable for example. The task is not for the program to generate the expression, or test whether an expression is even possible. Related tasks 24 game/Solve Reference The 24 Game on h2g2.
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 LET n$="" 20 RANDOMIZE 30 FOR i=1 TO 4 40 LET n$=n$+STR$ (INT (RND*9)+1) 50 NEXT i 60 LET i$="": LET f$="": LET p$="" 70 CLS 80 PRINT "24 game" 90 PRINT "Allowed characters:" 100 LET i$=n$+"+-*/()" 110 PRINT AT 4,0; 120 FOR i=1 TO 10 130 PRINT i$(i);" "; 140 NEXT i 150 PRINT "(0 to end)" 160 INPUT "Enter the formula";f$ 170 IF f$="0" THEN STOP 180 PRINT AT 6,0;f$;" = "; 190 FOR i=1 TO LEN f$ 200 LET c$=f$(i) 210 IF c$=" " THEN LET f$(i)="": GO TO 250 220 IF c$="+" OR c$="-" OR c$="*" OR c$="/" THEN LET p$=p$+"o": GO TO 250 230 IF c$="(" OR c$=")" THEN LET p$=p$+c$: GO TO 250 240 LET p$=p$+"n" 250 NEXT i 260 RESTORE 270 FOR i=1 TO 11 280 READ t$ 290 IF t$=p$ THEN LET i=11 300 NEXT i 310 IF t$<>p$ THEN PRINT INVERSE 1;"Bad construction!": BEEP 1,.1: PAUSE 0: GO TO 60 320 FOR i=1 TO LEN f$ 330 FOR j=1 TO 10 340 IF (f$(i)=i$(j)) AND f$(i)>"0" AND f$(i)<="9" THEN LET i$(j)=" " 350 NEXT j 360 NEXT i 370 IF i$( TO 4)<>" " THEN PRINT FLASH 1;"Invalid arguments!": BEEP 1,.01: PAUSE 0: GO TO 60 380 LET r=VAL f$ 390 PRINT r;" "; 400 IF r<>24 THEN PRINT FLASH 1;"Wrong!": BEEP 1,1: PAUSE 0: GO TO 60 410 PRINT FLASH 1;"Correct!": PAUSE 0: GO TO 10 420 DATA "nononon" 430 DATA "(non)onon" 440 DATA "nono(non)" 450 DATA "no(no(non))" 460 DATA "((non)on)on" 470 DATA "no(non)on" 480 DATA "(non)o(non)" 485 DATA "no((non)on)" 490 DATA "(nonon)on" 495 DATA "(no(non))on" 500 DATA "no(nonon)"
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Klong
Klong
  {(1:$(*x?0c )#x)+1:$(1+*|x?0c )_x}@.rl() 2 3 5  
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Wren
Wren
import "/fmt" for Fmt   var r // recursive r = Fn.new { |word, bl| if (word == "") return true var c = word.bytes[0] | 32 for (i in 0...bl.count) { var b = bl[i] if (c == b.bytes[0] | 32 || c == b.bytes[1] | 32) { bl[i] = bl[0] bl[0] = b if (r.call(word[1..-1], bl[1..-1])) return true var t = bl[i] bl[i] = bl[0] bl[0] = t } } return false }   var newSpeller = Fn.new { |blocks| var bl = blocks.split(" ") return Fn.new { |word| r.call(word, bl) } }   var sp = newSpeller.call("BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM") for (word in ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"]) { System.print("%(Fmt.s(-7, word)) %(sp.call(word))") }
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#ferite
ferite
uses "console";   number bottles = 99; boolean looping = true; object counter = closure { if (--bottles > 0) { return true; } else { return false; } };   while (looping) { Console.println("${bottles} bottles of beer on the wall,"); Console.println("${bottles} bottles of beer,"); Console.println("Take one down, pass it around,");   looping = counter.invoke();   Console.println("${bottles} bottles of beer on the wall.");
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Kotlin
Kotlin
// version 1.0.5-2   fun main(args: Array<String>) { val r = Regex("""-?\d+[ ]+-?\d+""") while(true) { print("Enter two integers separated by space(s) or q to quit: ") val input: String = readLine()!!.trim() if (input == "q" || input == "Q") break if (!input.matches(r)) { println("Invalid input, try again") continue } val index = input.lastIndexOf(' ') val a = input.substring(0, index).trimEnd().toInt() val b = input.substring(index + 1).toInt() if (Math.abs(a) > 1000 || Math.abs(b) > 1000) { println("Both numbers must be in the interval [-1000, 1000] - try again") } else { println("Their sum is ${a + b}\n") } } }
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#XPL0
XPL0
string 0;   char Side1, Side2; def Size = 20; char Avail(Size);   func CanMakeWord(Word); \returns 'true' if blocks can make Word char Word; int I, Let; [Let:= Word(0) & $5F; \get letter and make sure it's uppercase if Let = 0 then return true; \if 0 then end of word; return successful for I:= 0 to Size-1 do \scan for block that contains letter if Avail(I) and (Side1(I) = Let or Side2(I) = Let) then [Avail(I):= false; if CanMakeWord(Word+1) then return true; ]; return false; ];   int I, J, Words; [Side1:= "BXDCNGRTQFJHVAOEFLPZ"; Side2:= "OKQPATEGDSWUINBRSYCM"; Words:= ["A", "bark", "Book", "Treat", "Common", "Squad", "conFuse"]; for J:= 0 to 6 do [Text(0, "Can make ^""); Text(0, Words(J)); Text(0, "^": "); for I:= 0 to Size-1 do Avail(I):= true; Text(0, if CanMakeWord(Words(J)) then "True" else "False"); CrLf(0); ]; ]
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Fexl
Fexl
  \suffix=(\n eq n 1 "" "s") \sing_count=(\n put [n " bottle" (suffix n) " of beer"]) \sing_line1=(\n sing_count n say " on the wall") \sing_line2=(\n sing_count n nl) \sing== (\n le n 0 (); sing_line1 n sing_line2 n say "Take one down, pass it around" \n=(- n 1) sing_line1 n nl sing n ) sing 3  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#KQL
KQL
datatable(Input:string)[ '2 2', '3 2' ] | parse Input with A:int ' ' B:int | project Input, Output = A + B
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#Yabasic
Yabasic
letters$ = "BO,XK,DQ,CP,NA,GT,RE,TG,QD,FS,JW,HU,VI,AN,OB,ER,FS,LY,PC,ZM"   sub canMake(letters$, word$) local i, j, p, n, pairs$(1)   n = token(letters$, pairs$(), ",") word$ = upper$(word$)   for i = 1 to len(word$) for j = 1 to n p = instr(pairs$(j), mid$(word$, i, 1)) if p then pairs$(j) = "" break end if next j if not p return false next i return true end sub   print "a = ", canMake(letters$, "a") // 1 = true print "bark = ", canMake(letters$, "Bark") // 1 print "book = ", canMake(letters$, "BooK") // 0 = false print "treat = ", canMake(letters$, "TREAt") // 1 print "common = ", canMake(letters$, "common") // 0 print "squad = ", canMake(letters$, "squad") // 1 print "confuse = ", canMake(letters$, "confuse") // 1
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#FOCAL
FOCAL
01.10 S N=99 01.15 D 2;T " OF BEER ON THE WALL,",! 01.20 D 2;T " OF BEER,",! 01.24 S N=N-1 01.25 T "TAKE ";I (N),1.3,1.4,1.3 01.30 T "IT";G 1.5 01.40 T "ONE" 01.50 T " DOWN AND PASS IT AROUND,",! 01.60 D 2;T " OF BEER ON THE WALL!",!! 01.70 I (N),1.8,1.15 01.80 Q   02.01 C-PRINT N BOTTLE(S) 02.10 I (N)2.2,2.2,2.3 02.20 T "NO MORE";G 2.4 02.30 D 3 02.40 T " BOTTLE";I (N-1)2.5,2.6,2.5 02.50 T "S" 02.60 R   03.01 C-PRINT 2-DIGIT NUMBER IN N 03.02 C-THIS IS NECESSARY BECAUSE T ALWAYS PREPENDS = TO NUMBERS 03.10 S A=FITR(N/10);I (A),3.3,3.2 03.20 D 4 03.30 S A=N-FITR(N/10)*10;D 4   04.01 C-PRINT DIGIT IN A 04.10 I (A-0),4.20,4.11 04.11 I (A-1),4.21,4.12 04.12 I (A-2),4.22,4.13 04.13 I (A-3),4.23,4.14 04.14 I (A-4),4.24,4.15 04.15 I (A-5),4.25,4.16 04.16 I (A-6),4.26,4.17 04.17 I (A-7),4.27,4.18 04.18 I (A-8),4.28,4.19 04.19 T "9";R 04.20 T "0";R 04.21 T "1";R 04.22 T "2";R 04.23 T "3";R 04.24 T "4";R 04.25 T "5";R 04.26 T "6";R 04.27 T "7";R 04.28 T "8";R
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#L.2B.2B
L++
(main (decl int a) (decl int b) (>> std::cin a b) (prn (+ a b)))
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#zkl
zkl
var blocks=T("BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", "JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM", );   fcn can_make_word(word){ fcn(blks,word){ if (not word) return(True); // bottom of recursion foreach b in (blks){ n:=__bWalker.idx; if(not b.holds(word[0])) continue; // letter not on this block blks.del(n); // remove this block from pile if (self.fcn(blks,word[1,*])) return(True); // try remaining blocks blks.insert(n,b); // put block back in pile: backtracking } False; // out of blocks but not out of word }(blocks.copy(),word.toUpper()) }   foreach word in (T("","A","BarK","BOOK","TREAT","COMMON","SQUAD","Confuse","abba")){ can_make_word(word).println(": ",word); }
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Forth
Forth
:noname dup . ." bottles" ; :noname ." 1 bottle"  ; :noname ." no more bottles" ; create bottles , , ,   : .bottles dup 2 min cells bottles + @ execute ; : .beer .bottles ." of beer" ; : .wall .beer ." on the wall" ; : .take ." Take one down, pass it around" ; : .verse .wall cr .beer cr 1- .take cr .wall cr ; : verses begin cr .verse ?dup 0= until ;   99 verses
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Lambdatalk
Lambdatalk
  Lambdatalk works in a wiki, lambdatank.   1) Open the wiki frame-editor and define a contenteditable box   {def box {pre {@ contenteditable style="box-shadow:0 0 8px #000; padding:5px;" ondblclick="this.innerHTML=LAMBDATALK.eval_forms(this.innerHTML)" }}} -> blockedit   2) create this box   {box}   and close the wiki frame-editor. The wiki-page displays a shadowed box, (here simulated as a space between square brackets)   [ ]   3) Enter any valid lambdatalk expression, for instance   1+2+3 is equal to {+ 1 2 3}   then double-click. The expression is evaluated and the box displays   [ 1+2+3 is equal to 6 ]   Several boxes can be created in the wiki page with any valid lambdatalk expressions.  
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#zonnon
zonnon
  module Main; type Block = record l,r: char; used: boolean; end Block;   var blocks: array 20 of Block;   procedure Exists(c: char): boolean; var i: integer; r: boolean; begin r := false;i := 0; while ~r & (i < len(blocks)) do if ~(blocks[i].used) then r := (blocks[i].l = cap(c)) or (blocks[i].r = cap(c)); blocks[i].used := r; end; inc(i) end; return r end Exists;   procedure CanMakeWord(s: string); var i: integer; made: boolean; begin made := true; for i := 0 to len(s) - 1 do made := made & Exists(s[i]) end; writeln(s:20,"?",made); Clean() end CanMakeWord;   procedure Clean(); var i: integer; begin for i := 0 to len(blocks) - 1 do blocks[i].used := false end end Clean;   procedure InitBlock(i:integer;l,r:char); begin blocks[i].l := l;blocks[i].r := r; blocks[i].used := false; end InitBlock;   procedure Init; begin InitBlock(0,'B','O'); InitBlock(1,'X','K'); InitBlock(2,'D','Q'); InitBlock(3,'C','Q'); InitBlock(4,'N','A'); InitBlock(5,'G','T'); InitBlock(6,'R','E'); InitBlock(7,'T','G'); InitBlock(8,'Q','D'); InitBlock(9,'F','S'); InitBlock(10,'J','W'); InitBlock(11,'H','U'); InitBlock(12,'V','I'); InitBlock(13,'A','N'); InitBlock(14,'O','B'); InitBlock(15,'E','R'); InitBlock(16,'F','S'); InitBlock(17,'L','Y'); InitBlock(18,'P','C'); InitBlock(19,'Z','M') end Init;   begin Init(); CanMakeWord("A"); CanMakeWord("BARK"); CanMakeWord("BOOK"); CanMakeWord("TREAT"); CanMakeWord("COMMON"); CanMakeWord("confuse"); end Main.  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Fortran
Fortran
program bottlestest   implicit none   integer :: i   character(len=*), parameter :: bwall = " on the wall", & bottles = "bottles of beer", & bottle = "bottle of beer", & take = "Take one down, pass it around", & form = "(I0, ' ', A)"   do i = 99,0,-1 if ( i /= 1 ) then write (*,form) i, bottles // bwall if ( i > 0 ) write (*,form) i, bottles else write (*,form) i, bottle // bwall write (*,form) i, bottle end if if ( i > 0 ) write (*,*) take end do   end program bottlestest
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Lang5
Lang5
read read + .   read " " split expand drop + .
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks: (B O) (X K) (D Q) (C P) (N A) (G T) (R E) (T G) (Q D) (F S) (J W) (H U) (V I) (A N) (O B) (E R) (F S) (L Y) (P C) (Z M) Task Write a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks. The rules are simple:   Once a letter on a block is used that block cannot be used again   The function should be case-insensitive   Show the output on this page for the following 7 words in the following example Example >>> can_make_word("A") True >>> can_make_word("BARK") True >>> can_make_word("BOOK") False >>> can_make_word("TREAT") True >>> can_make_word("COMMON") False >>> can_make_word("SQUAD") True >>> can_make_word("CONFUSE") True Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 LET b$="BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM" 20 READ p 30 FOR c=1 TO p 40 READ p$ 50 GO SUB 100 60 NEXT c 70 STOP 80 DATA 7,"A","BARK","BOOK","TREAT","COMMON","SQUAD","CONFUSE" 90 REM Can make? 100 LET u$=b$ 110 PRINT "Can make word ";p$;"? "; 120 FOR i=1 TO LEN p$ 130 FOR j=1 TO LEN u$ 140 IF p$(i)=u$(j) THEN GO SUB 200: GO TO 160 150 NEXT j 160 IF j>LEN u$ THEN PRINT "No": RETURN 170 NEXT i 180 PRINT "Yes": RETURN 190 REM Erase pair 200 IF j/2=INT (j/2) THEN LET u$(j-1 TO j)=" ": RETURN 210 LET u$(j TO j+1)=" ": RETURN
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Frege
Frege
module Beer where   main = mapM_ (putStrLn . beer) [99, 98 .. 0] beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around" beer 0 = "better go to the store and buy some more." beer v = show v ++ " bottles of beer on the wall\n" ++ show v ++ " bottles of beer\nTake one down, pass it around\n" ++ head (lines $ beer $ v-1) ++ "\n"
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Lasso
Lasso
[a + b]
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#friendly_interactive_shell
friendly interactive shell
  units = array[units[volume]] showApproximations[false]   for n = 99 to 0 step -1 { unit = units.removeRandom[] str = getBottleString[n, unit]   println["$str of beer on the wall, $str."]   if (n == 0) println["Go to the store and buy some more, 99 bottles of beer on the wall."] else println["Take one down and pass it around, " + getBottleString[n-1, unit] + " on the wall.\n"] }   getBottleString[n, unit] := format[n*12 floz, unit, 6] + "s"  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#LIL
LIL
# A+B, in LIL # Requires lil shell readline routine set in [readline] set A [index $in 0] set B [index $in 1] if [expr $A < -1000 || $A > 1000] { print "A out of range: $A"; exit 1 } if [expr $B < -1000 || $B > 1000] { print "B out of range: $B"; exit 1 } print [expr $A + $B]
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Frink
Frink
  units = array[units[volume]] showApproximations[false]   for n = 99 to 0 step -1 { unit = units.removeRandom[] str = getBottleString[n, unit]   println["$str of beer on the wall, $str."]   if (n == 0) println["Go to the store and buy some more, 99 bottles of beer on the wall."] else println["Take one down and pass it around, " + getBottleString[n-1, unit] + " on the wall.\n"] }   getBottleString[n, unit] := format[n*12 floz, unit, 6] + "s"  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Lisaac
Lisaac
Section Header + name := A_PLUS_B   Section Public - main <- ( (IO.read_integer; IO.last_integer) + (IO.read_integer; IO.last_integer) ).println;
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#FunL
FunL
val numbers = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve'} alt = {3:'thir', 5:'fif'}   def suffix( a, b ) = (if a.endsWith( 't' ) then a.substring( 0, a.length()-1 ) else a) + b   number( n@(13 | 15) ) = suffix( alt(n%10), 'teen' ) number( 20 ) = 'twenty' number( n@(30 | 50) ) = suffix( alt(n\10), 'ty' ) number( n ) | n <= 12 = numbers(n) | n <= 19 = suffix( numbers(n%10), 'teen' ) | 10|n = suffix( numbers(n\10), 'ty' ) | otherwise = number( n\10*10 ) + '-' + number( n%10 )   cap( s ) = s.substring( 0, 1 ).toUpperCase() + s.substring( 1, s.length() )   bottles( 0 ) = 'no more bottles' bottles( 1 ) = 'one bottle' bottles( n ) = number( n ) + ' bottles'   verse( 0 ) = ('No more bottles of beer on the wall, no more bottles of beer.\n' + 'Go to the store and buy some more, ninety-nine bottles of beer on the wall.') verse( n ) = (cap( 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')   for i <- 99..0 by -1 do println( verse(i) )
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Little
Little
void main() { string a, b; scan(gets(stdin), "%d %d", &a, &b); puts(((int)a + (int)b)); }
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#FutureBasic
FutureBasic
  include "NSLog.incl"   NSUInteger i CFStringRef a, b, c   a = @" bottles of beer on the wall,\n" b = @" bottles of beer.\n" c = @"Take one down, pass it around,\n"   for i = 99 to 1 step -1 NSLog( @"%ld%@%ld%@%@%ld%@\n", i, a, i, b, c, i -1, a ) next   HandleEvents  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Little_Man_Computer
Little Man Computer
INP STA 99 INP ADD 99 OUT HLT // Output the sum of two numbers
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Gambas
Gambas
' Gambas module file   Public Const bottlesofbeer As String = " bottles of beer." Public Const onthewall As String = " on the wall." Public Const takeonedown As String = "Take one down, pass it around." Public Const onebeer As String = "1 bottle of beer"   Public Sub Main()   Dim bottles As Byte   For bottles = 99 To 3 Step -1 Print CStr(bottles) & bottlesofbeer & onthewall Print CStr(bottles) & bottlesofbeer Print takeonedown Print CStr(bottles - 1) & bottlesofbeer & onthewall Print Next   Print "2" & bottlesofbeer & onthewall Print "2" & bottlesofbeer Print takeonedown Print onebeer & onthewall Print   Print onebeer & onthewall Print onebeer Print takeonedown Print "No more" & bottlesofbeer & onthewall Print   Print "No" & bottlesofbeer & onthewall Print "No" & bottlesofbeer Print "Go to the store, buy some more." Print "99" & bottlesofbeer & onthewall   End
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#LiveCode
LiveCode
<?lc if isNumber($0) and isNumber($1) then put $0 + $1 else put $0 && $1 end if ?>
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#GAP
GAP
Bottles := function(n) local line, i, j, u; line := function(n) s := String(n); if n < 2 then return Concatenation(String(n), " bottle of beer"); else return Concatenation(String(n), " bottles of beer"); fi; end; for i in [1 .. n] do j := n - i + 1; u := line(j); Display(Concatenation(u, " on the wall")); Display(u); Display("Take one down, pass it around"); Display(Concatenation(line(j - 1), " on the wall")); if i <> n then Display(""); fi; od; end;
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Logo
Logo
show apply "sum readlist
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Genie
Genie
[indent=4] def plural(n:uint):string return (n == 1) ? "" : "s" def no(n:uint):string return (n == 0) ? "No" : n.to_string() init bottles:uint = 99; do print "%u bottle%s of beer on the wall", bottles, plural(bottles) print "%u bottle%s of beer", bottles, plural(bottles) print "Take one down, pass it around" --bottles print "%s bottle%s of beer on the wall\n", no(bottles), plural(bottles) while bottles != 0
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Lua
Lua
a,b = io.read("*number", "*number") print(a+b)
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#gnuplot
gnuplot
if (!exists("bottles")) bottles = 99 print sprintf("%i bottles of beer on the wall", bottles) print sprintf("%i bottles of beer", bottles) print "Take one down, pass it around" bottles = bottles - 1 print sprintf("%i bottles of beer on the wall", bottles) print "" if (bottles > 0) reread
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#M2000_Interpreter
M2000 Interpreter
Def Range(X%)=Abs(X%)<=1000 Do { Input A%, B% } Until Range(A%) And Range(B%) Print A%+B%
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Go
Go
package main   import "fmt"   func main() { bottles := func(i int) string { switch i { case 0: return "No more bottles" case 1: return "1 bottle" default: return fmt.Sprintf("%d bottles", i) } }   for i := 99; i > 0; i-- { fmt.Printf("%s of beer on the wall\n", bottles(i)) fmt.Printf("%s of beer\n", bottles(i)) fmt.Printf("Take one down, pass it around\n") fmt.Printf("%s of beer on the wall\n", bottles(i-1)) } }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#M4
M4
define(`sumstr', `eval(patsubst(`$1',` ',`+'))')   sumstr(1 2) 3
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Go.21
Go!
-- -- 99 Bottles of Beer in Go! -- John Knottenbelt -- -- Go! is a multi-paradigm programming language that is oriented -- to the needs of programming secure, production quality, agent -- based applications. -- -- http://www.doc.ic.ac.uk/~klc/dalt03.html --   main .. { include "sys:go/io.gof". include "sys:go/stdlib.gof".   main() -> drink(99); stdout.outLine("Time to buy some more beer...").   drink(0) -> {}. drink(i) -> stdout.outLine( bottles(i) <> " on the wall,\n" <> bottles(i) <> ".\n" <> "take one down, pass it around,\n" <> bottles(i-1) <> " on the wall.\n"); drink(i-1).   bottles(0) => "no bottles of beer". bottles(1) => "1 bottle of beer". bottles(i) => i^0 <> " bottles of beer". }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Maple
Maple
convert( scanf( "%d %d" ), '`+`' ); 23 34 57
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Golfscript
Golfscript
[296,{3/)}%-1%["No more"]+[" bottles":b]294*[b-1<]2*+[b]+[" of beer on the wall\n".8<"\nTake one down, pass it around\n"+1$n+]99*]zip
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Input[] + Input[]
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Golo
Golo
module Bottles   augment java.lang.Integer { function bottles = |self| -> match { when self == 0 then "No bottles" when self == 1 then "One bottle" otherwise self + " bottles" } }   function main = |args| { 99: downTo(1, |i| { println(i: bottles() + " of beer on the wall,") println(i: bottles() + " of beer!") println("Take one down, pass it around,") println((i - 1): bottles() + " of beer on the wall!") println("--------------------------------------") }) }
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#MATLAB_.2F_Octave
MATLAB / Octave
function sumOfInputs = APlusB() inputStream = input('Enter two numbers, separated by a space: ', 's'); numbers = str2num(inputStream); %#ok<ST2NM> if any(numbers < -1000 | numbers > 1000) warning('APlusB:OutOfRange', 'Some numbers are outside the range'); end sumOfInputs = sum(numbers); end
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Gosu
Gosu
  for (i in 99..0) {   print("${i} bottles of beer on the wall")   if (i > 0) { print("${i} bottles of beer") print("Take one down, pass it around") } print("");   }  
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤ A , B ≤ + 1000 ) {\displaystyle (-1000\leq A,B\leq +1000)} Output data The required output is one integer:   the sum of A and B. Example input   output   2 2 4 3 2 5
#Maude
Maude
  red 3 + 4 .  
http://rosettacode.org/wiki/99_bottles_of_beer
99 bottles of beer
Task Display the complete lyrics for the song:     99 Bottles of Beer on the Wall. The beer song The lyrics follow this form: 99 bottles of beer on the wall 99 bottles of beer Take one down, pass it around 98 bottles of beer on the wall 98 bottles of beer on the wall 98 bottles of beer Take one down, pass it around 97 bottles of beer on the wall ... 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). Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioinformatics/base count Count occurrences of a substring Count how many vowels and consonants occur in a string Remove/replace XXXX redacted Conjugate a Latin verb Remove vowels from a string String interpolation (included) Strip block comments Strip comments from a string Strip a set of characters from a string Strip whitespace from a string -- top and tail Strip control codes and extended characters from a string Anagrams/Derangements/shuffling Word wheel ABC problem Sattolo cycle Knuth shuffle Ordered words Superpermutation minimisation Textonyms (using a phone text pad) Anagrams Anagrams/Deranged anagrams Permutations/Derangements Find/Search/Determine ABC words Odd words Word ladder Semordnilap Word search Wordiff  (game) String matching Tea cup rim text Alternade words Changeable words State name puzzle String comparison Unique characters Unique characters in each string Extract file extension Levenshtein distance Palindrome detection Common list elements Longest common suffix Longest common prefix Compare a list of strings Longest common substring Find common directory path Words from neighbour ones Change e letters to i in words Non-continuous subsequences Longest common subsequence Longest palindromic substrings Longest increasing subsequence Words containing "the" substring Sum of the digits of n is substring of n Determine if a string is numeric Determine if a string is collapsible Determine if a string is squeezable Determine if a string has all unique characters Determine if a string has all the same characters Longest substrings without repeating characters Find words which contains all the vowels Find words which contains most consonants Find words which contains more than 3 vowels Find words which first and last three letters are equals Find words which odd letters are consonants and even letters are vowels or vice_versa Formatting Substring Rep-string Word wrap String case Align columns Literals/String Repeat a string Brace expansion Brace expansion using ranges Reverse a string Phrase reversals Comma quibbling Special characters String concatenation Substring/Top and tail Commatizing numbers Reverse words in a string Suffixation of decimal numbers Long literals, with continuations Numerical and alphabetical suffixes Abbreviations, easy Abbreviations, simple Abbreviations, automatic Song lyrics/poems/Mad Libs/phrases Mad Libs Magic 8-ball 99 Bottles of Beer The Name Game (a song) The Old lady swallowed a fly The Twelve Days of Christmas Tokenize Text between Tokenize a string Word break problem Tokenize a string with escaping Split a character string based on change of character Sequences Show ASCII table De Bruijn sequences Self-referential sequences Generate lower case ASCII alphabet See also   http://99-bottles-of-beer.net/   Category:99_Bottles_of_Beer   Category:Programming language families   Wikipedia 99 bottles of beer
#Groovy
Groovy
def bottles = { "${it==0 ? 'No more' : it} bottle${it==1 ? '' : 's' }" }   99.downto(1) { i -> print """ ${bottles(i)} of beer on the wall ${bottles(i)} of beer Take one down, pass it around ${bottles(i-1)} of beer on the wall """ }