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 dow...
#Chef
Chef
  execute() {   // this class provides synchronization // to get unique number of the bottle   class monitor giver { int number = 100; .get() { return --number; } } var g = new giver();   // start 99 concurrently worked threads // each thread gets own number of the...
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. T...
#Nit
Nit
redef class Char fun is_op: Bool do return "-+/*".has(self) end   # Get `numbers` and `operands` from string `operation` collect with `gets` in `main` function # Fill `numbers` and `operands` array with previous extraction fun exportation(operation: String, numbers: Array[Int], operands: Array[Char]) do var previous_...
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 ≤...
#Fantom
Fantom
class APlusB { public static Void main () { echo ("Enter two numbers: ") Str input := Env.cur.in.readLine Int sum := 0 input.split.each |n| { sum += n.toInt } echo (sum) } }
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 sid...
#Phix
Phix
sequence blocks, words, used function ABC_Solve(sequence word, integer idx) integer ch, res = 0 if idx>length(word) then res = 1 -- or: res = length(word)>0 -- (if "" -> false desired) else ch = word[idx] for k=1 to length(blocks) do if used[k]=0 and find(ch,bl...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#PureBasic
PureBasic
#PRISONERS=100 #DRAWERS =100 #LOOPS = 50 #MAXPROBE = 10000 OpenConsole()   Dim p1(#PRISONERS,#DRAWERS) Dim p2(#PRISONERS,#DRAWERS) Dim d(#DRAWERS)   For i=1 To #DRAWERS : d(i)=i : Next Start: For probe=1 To #MAXPROBE RandomizeArray(d(),1,100) c1=0 : c2=0 For m=1 To #PRISONERS p2(m,1)=d(m) : If d(m)=m : p...
http://rosettacode.org/wiki/24_game/Solve
24 game/Solve
task Write a program that takes four digits, either from user input or by random generation, and computes arithmetic expressions following the rules of the 24 game. Show examples of solutions generated by the program. Related task   Arithmetic Evaluator
#Wren
Wren
import "random" for Random import "/dynamic" for Tuple, Enum, Struct   var N_CARDS = 4 var SOLVE_GOAL = 24 var MAX_DIGIT = 9   var Frac = Tuple.create("Frac", ["num", "den"])   var OpType = Enum.create("OpType", ["NUM", "ADD", "SUB", "MUL", "DIV"])   var Expr = Struct.create("Expr", ["op", "left", "right", "value"])   ...
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
#Nim
Nim
import random, terminal   type Tile = uint8 Board = array[16, Tile]   type Operation = enum opInvalid opUp opDown opLeft opRight opQuit opRestart   func charToOperation(c: char): Operation = case c of 'w', 'W': opUp of 'a', 'A': opLeft of 's', 'S': opDown of 'd', 'D': opRight...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Pony
Pony
  use "term" use "random" use "time"   interface EdgeRow fun val row() : Iterator[U32] ref fun val inc() : I32   primitive TopRow is EdgeRow fun row() : Iterator[U32] ref => let r : Array[U32] box = [0,1,2,3] r.values() fun inc() : I32 => 4   primitive LeftRow is EdgeRow fun row() : Iterator[U32] ref => l...
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 dow...
#Cind
Cind
  execute() {   // this class provides synchronization // to get unique number of the bottle   class monitor giver { int number = 100; .get() { return --number; } } var g = new giver();   // start 99 concurrently worked threads // each thread gets own number of the...
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. T...
#Objeck
Objeck
use Collection.Generic; use System.Matrix;   class RPNParser { @stk : Stack<IntHolder>; @digits : List<IntHolder>;   function : Main(args : String[]) ~ Nil { digits := List->New()<IntHolder>; "Make 24 with the digits: "->Print(); for(i := 0; i < 4; i += 1;) { n : Int := Int->Random(1, 9); ...
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 ≤...
#FBSL
FBSL
#APPTYPE CONSOLE   DIM %a, %b SCANF("%d%d", @a, @b) PRINT a, "+", b, "=", a + b   PAUSE
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 sid...
#PHP
PHP
  <?php $words = array("A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "Confuse");   function canMakeWord($word) { $word = strtoupper($word); $blocks = array( "BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", "JW", "HU", "VI", "AN", "OB", "ER", "FS", "L...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Python
Python
import random   def play_random(n): # using 0-99 instead of ranges 1-100 pardoned = 0 in_drawer = list(range(100)) sampler = list(range(100)) for _round in range(n): random.shuffle(in_drawer) found = False for prisoner in range(100): found = False for ...
http://rosettacode.org/wiki/24_game/Solve
24 game/Solve
task Write a program that takes four digits, either from user input or by random generation, and computes arithmetic expressions following the rules of the 24 game. Show examples of solutions generated by the program. Related task   Arithmetic Evaluator
#Yabasic
Yabasic
operators$ = "*+-/" space$ = " "   sub present() clear screen print "24 Game" print "============\n" print "Computer provide 4 numbers (1 to 9). With operators +, -, * and / you try to\nobtain 24." print "Use Reverse Polish Notation (fi...
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
#OCaml
OCaml
module Puzzle = struct type t = int array let make () = [| 15; (* 0: the empty space *) 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; |]   let move p n = let hole, i = p.(0), p.(n) in p.(0) <- i; p.(n) <- hole   let print p = let out = Array.make 16...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Prolog
Prolog
/* ------------------------------------------------------------- Entry point, just create a blank grid and enter a 'game loop' -------------------------------------------------------------*/ play_2048 :- welcome_msg, length(Grid, 16), maplist(=(' '), Grid), % create a blank grid play(Grid, yes), !. % don't ha...
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 dow...
#Clay
Clay
/* A few options here: I could give n type Int; or specify that n is of any numeric type; but here I just let it go -- that way it'll work with anything that compares with 1 and that printTo knows how to convert to a string. And all checked at compile time, remember. */ getRound(n) { var s = String();...
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. T...
#OCaml
OCaml
ocamlopt -pp camlp4o g24.ml -o g24.opt
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 ≤...
#Fhidwfe
Fhidwfe
  function listint scanint (num:ptr) {// as of writing, fhidwfe has no builtin int scanning reset negative read = num num1 = 0 num2 = 0 while ~ = deref_ubyte$ read ' ' { char = deref_ubyte$ read if = char '-' { set negative } { num1 = + * 10 num1 as - char '0' int } read = + read 1u } if negative...
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 sid...
#Picat
Picat
go => test_it(check_word), test_it(check_word2), nl.   % Get all possible solutions (via fail) go2 ?=> test_version(check_word2), fail, nl. go2 => true.   % % Test a version. % test_it(Pred) => println(testing=Pred), Blocks = findall([A,B], block(A,B)), Words = findall(W,word(W)), foreach(Word in Wo...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#R
R
t = 100000 #number of trials success.r = rep(0,t) #this will keep track of how many prisoners find their ticket on each trial for the random method success.o = rep(0,t) #this will keep track of how many prisoners find their ticket on each trial for the optimal method   #random method for(i in 1:t){ escape = rep(F,100...
http://rosettacode.org/wiki/24_game/Solve
24 game/Solve
task Write a program that takes four digits, either from user input or by random generation, and computes arithmetic expressions following the rules of the 24 game. Show examples of solutions generated by the program. Related task   Arithmetic Evaluator
#zkl
zkl
var [const] H=Utils.Helpers; fcn u(xs){ xs.reduce(fcn(us,s){us.holds(s) and us or us.append(s) },L()) } var ops=u(H.combosK(3,"+-*/".split("")).apply(H.permute).flatten()); var fs=T( fcn f0(a,b,c,d,x,y,z){ Op(z)(Op(y)(Op(x)(a,b),c),d) }, // ((AxB)yC)zD fcn f1(a,b,c,d,x,y,z){ Op(y)(Op(x)(a,b),Op(z)(c,d)) }, // (Ax...
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
#Pascal
Pascal
  program fifteen; {$mode objfpc} {$modeswitch advancedrecords} {$coperators on} uses SysUtils, crt; type TPuzzle = record private const ROW_COUNT = 4; COL_COUNT = 4; CELL_COUNT = ROW_COUNT * COL_COUNT; RAND_RANGE = 101; type TTile = 0..Pred(CELL_COUNT); TAdjacentCell = (ac...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Python
Python
#!/usr/bin/env python3   import curses from random import randrange, choice # generate and place new tile from collections import defaultdict   letter_codes = [ord(ch) for ch in 'WASDRQwasdrq'] actions = ['Up', 'Left', 'Down', 'Right', 'Restart', 'Exit'] actions_dict = dict(zip(letter_codes, actions * 2))   def get_use...
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 dow...
#Clio
Clio
fn bottle n: n -> if = 0: 'no more bottles' elif = 1: n + ' bottle' else: n + ' bottles'   [99:0] -> * (@eager) fn i: i -> bottle -> print (transform i: sentence-case) 'of beer on the wall,' @ 'of beer.' if i = 0: 'Go to the store, buy some more, 99 bottles of beer on the wall.' -> print ...
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. T...
#Oforth
Oforth
import: mapping   : game | l expr w n i | 4 #[ 9 rand ] Array init ->l   System.Out "Digits : " << l << " --> RPN Expression for 24 : " << drop System.Console accept ->expr   expr words forEach: w [ w "+" == ifTrue: [ + continue ] w "-" == ifTrue: [ - continue ] w "*" == ifTrue: [ * conti...
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 ≤...
#Fish
Fish
i:o:"-"=?v1$68*-v v >~01-0 > >i:o:" "=?v68*-$a*+ >~*i:o:"-"=?v1$68*-v v >~01-0 > >i:o:d=?v68*-$a*+ >~*+aonao;
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 sid...
#PicoLisp
PicoLisp
(setq *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) ) ) (setq *Words '("" "1" "A" "BARK" "BOOK" "TREAT" "Bbb" "COMMON" "SQUAD" "Confuse" "abba" "ANBOCPDQERSFTGUVWXLZ") )   (de abc (W B) (let M...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#QB64
QB64
  Const Found = -1, Searching = 0, Status = 1, Tries = 2 Const Attempt = 1, Victories = 2, RandomW = 1, ChainW = 2 Randomize Timer   Dim Shared Prisoners(1 To 100, Status To Tries) As Integer, Drawers(1 To 100) As Integer, Results(1 To 2, 1 To 2) As Integer Print "100 prisoners" Print "Random way to search..." For a = ...
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
#Perl
Perl
    use strict; use warnings;   use Getopt::Long; use List::Util 1.29 qw(shuffle pairmap first all); use Tk; # 5 options 1 label text my ($verbose,@fixed,$nocolor,$charsize,$extreme,$solvability);   unless (GetOptions ( 'verbose!' => \$verbose, ...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#QB64
QB64
  _DEFINE A-Z AS _INTEGER64 DIM SHARED Grid(0 TO 5, 0 TO 5) AS INTEGER CONST Left = 19200 CONST Right = 19712 CONST Down = 20480 CONST Up = 18432 CONST ESC = 27 CONST LCtrl = 100306 CONST RCtrl = 100305   Init MakeNewGame DO _LIMIT 30 ShowGrid CheckInput flag IF flag THEN GetNextNumber _DISPLAY LOOP...
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 dow...
#CLIPS
CLIPS
(deffacts beer-bottles (bottles 99))   (deffunction bottle-count (?count) (switch ?count (case 0 then "No more bottles of beer") (case 1 then "1 more bottle of beer") (default (str-cat ?count " bottles of beer"))))   (defrule stanza  ?bottles <- (bottles ?count) => (retract ?bottles) (printout ...
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. T...
#ooRexx
ooRexx
DEFINE TEMP-TABLE tt NO-UNDO FIELD ii AS INTEGER.   DEFINE VARIABLE p_deanswer AS DECIMAL NO-UNDO. DEFINE VARIABLE idigits AS INTEGER NO-UNDO EXTENT 4. DEFINE VARIABLE ii AS INTEGER NO-UNDO. DEFINE VARIABLE Digits AS CHARACTER NO-UNDO FORMAT "x(7)". DEFINE VARIABLE Answer ...
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 ≤...
#Forth
Forth
pad dup 80 accept evaluate + .
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 sid...
#PL.2FI
PL/I
ABC: procedure options (main); /* 12 January 2014 */   declare word character (20) varying, blocks character (200) varying initial ('((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))'); declare tblocks character (200) varying;...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Quackery
Quackery
[ this ] is 100prisoners.qky   [ dup size 2 / split ] is halve ( [ --> [ [ )   [ stack ] is successes ( --> s )   [ [] swap times [ i join ] shuffle ] is drawers ( n --> [ )   [ false unrot temp put dup shuffl...
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
#Phix
Phix
constant ESC=27, UP=328, LEFT=331, RIGHT=333, DOWN=336 sequence board = tagset(15)&0, solve = board integer pos = 16 procedure print_board() for i=1 to length(board) do puts(1,iff(i=pos?" ":sprintf("%3d",{board[i]}))) if mod(i,4)=0 then puts(1,"\n") end if end for puts(1,"\n") end proced...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#R
R
  GD <- function(vec) { c(vec[vec != 0], vec[vec == 0]) } DG <- function(vec) { c(vec[vec == 0], vec[vec != 0]) }   DG_ <- function(vec, v = TRUE) { if (v) print(vec) rev(GD_(rev(vec), v = FALSE)) }   GD_ <- function(vec, v = TRUE) { if (v) { print(vec) } vec2 <- GD(vec) ...
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 dow...
#Clojure
Clojure
(defn paragraph [num] (str num " bottles of beer on the wall\n" num " bottles of beer\n" "Take one down, pass it around\n" (dec num) " bottles of beer on the wall.\n"))   (defn lyrics [] (let [numbers (range 99 0 -1) paragraphs (map paragraph numbers)] (clojure.string/join "\n" pa...
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. T...
#OpenEdge.2FProgress
OpenEdge/Progress
DEFINE TEMP-TABLE tt NO-UNDO FIELD ii AS INTEGER.   DEFINE VARIABLE p_deanswer AS DECIMAL NO-UNDO. DEFINE VARIABLE idigits AS INTEGER NO-UNDO EXTENT 4. DEFINE VARIABLE ii AS INTEGER NO-UNDO. DEFINE VARIABLE Digits AS CHARACTER NO-UNDO FORMAT "x(7)". DEFINE VARIABLE Answer ...
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 ≤...
#Fortran
Fortran
program a_plus_b implicit none integer :: a,b read (*, *) a, b write (*, '(i0)') a + b end program a_plus_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 sid...
#PL.2FM
PL/M
100H:   /* ABC PROBLEM ON $-TERMINATED STRING */ CAN$MAKE$WORD: PROCEDURE (STRING) BYTE; DECLARE STRING ADDRESS, CHAR BASED STRING BYTE; DECLARE CONST$BLOCKS DATA ('BOKXDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM'); DECLARE I BYTE, BLOCKS (40) BYTE;   DO I=0 TO 39; /* MAKE COPY OF BLOCKS */ ...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Racket
Racket
#lang racket (require srfi/1)   (define current-samples (make-parameter 10000)) (define *prisoners* 100) (define *max-guesses* 50)   (define (evaluate-strategy instance-solved? strategy (s (current-samples))) (/ (for/sum ((_ s) #:when (instance-solved? strategy)) 1) s))   (define (build-drawers) (list->vector (shuf...
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
#PHP
PHP
<?php // Puzzle 15 Game - Rosseta Code - PHP 7 as the server-side script language.   // This program DOES NOT use cookies.   session_start([ "use_only_cookies" => 0, "use_cookies" => 0, "use_trans_sid" => 1, ]);   class Location { protected $column, $row;   function __construct($column, $row){ $this->colu...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Racket
Racket
  ;; LICENSE: See License file LICENSE (MIT license) ;; ;; Repository: https://github.com/danprager/2048 ;; ;; Copyright 2014: Daniel Prager ;; daniel.a.prager@gmail.com ;; ;; This is a largely clean-room, functional implementation in Racket ;; of the game 2048 by Gabriele Cirulli, based on 1024 by Vee...
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 dow...
#CLU
CLU
bottles = proc (n: int) returns (string) if n<0 then return("99 bottles") elseif n=0 then return("No more bottles") elseif n=1 then return("1 bottle") else return(int$unparse(n) || " bottles") end end bottles   thirdline = proc (n: int) returns (string) if n=0 then return("Go to the stor...
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. T...
#PARI.2FGP
PARI/GP
game()={ my(v=vecsort(vector(4,i,random(8)+1))); print("Form 24 using */+-() and: "v); while(1, my(ans=input); if (!valid(s,v), next); trap(, print("Arithmetic error"); next , if(eval(s)==24, break, print("Bad sum")) ) ); print("You win!") }; valid(s,v)={ my(op=vecsort(...
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 ≤...
#Free_Pascal
Free Pascal
program SUMA; uses SysUtils; var s1, s2:integer; begin ReadLn(s1); Readln(s2); WriteLn(IntToStr(s1 + s2)); end.  
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 sid...
#PowerBASIC
PowerBASIC
#COMPILE EXE #DIM ALL ' ' A B C p r o b l e m . b a s ' ' by Geary Chopoff ' for Chopoff Consulting and RosettaCode.org ' on 2014Jul23 ' '2014Jul23 ' 'You are given a collection of ABC blocks. Just like the ones you had when you were a kid. 'There are twenty blocks with two letters on each block. You are guaranteed t...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Raku
Raku
unit sub MAIN (:$prisoners = 100, :$simulations = 10000); my @prisoners = ^$prisoners; my $half = floor +@prisoners / 2;   sub random ($n) { ^$n .race.map( { my @drawers = @prisoners.pick: *; @prisoners.map( -> $prisoner { my $found = 0; for @drawers.pick($half) -> $card { ...
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
#Picat
Picat
  import util.   main => Board = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,0}}, Goal = copy_term(Board), shuffle(Board), play(Board,Goal).   shuffle(Board) => foreach (_ in 1..1000) R1 = random() mod 4 + 1, C1 = random() mod 4 + 1, ...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Raku
Raku
use Term::termios;   constant $saved = Term::termios.new(fd => 1).getattr; constant $termios = Term::termios.new(fd => 1).getattr; # raw mode interferes with carriage returns, so # set flags needed to emulate it manually $termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>); $termios.unset_lflags(< ECHO ICANON IEXTEN ISI...
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 dow...
#COBOL
COBOL
identification division. program-id. ninety-nine. environment division. data division. working-storage section. 01 counter pic 99. 88 no-bottles-left value 0. 88 one-bottle-left value 1.   01 parts-of-counter redefines counter. 05 tens pic 9. 05 digits pic 9.   01 after-ten-words. 05 filler pic x(7) value spaces...
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. T...
#Perl
Perl
#!/usr/bin/env perl use warnings; use strict; use feature 'say';   print <<'EOF'; 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 parentheses, (), show how to make an answer of 24.   An answer of "q" or EOF will quit t...
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 ≤...
#Frink
Frink
  sum[eval[split[%r/\s+/, 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 sid...
#PowerShell
PowerShell
<# .Synopsis ABC Problem .DESCRIPTION You are given a collection of ABC blocks. Just like the ones you had when you were a kid. There are twenty blocks with two letters on each block. You are guaranteed to have a complete alphabet amongst all sides of the blocks blocks = "BO","XK","DQ","CP","NA","GT","R...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Red
Red
  Red []   K_runs: 100000 repeat n 100 [append rand_arr: [] n] ;; define array/series with numbers 1..100   ;;------------------------------- strat_optimal: function [pris ][ ;;------------------------------- locker: pris ;; start with locker equal to prisoner number ...
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
#Powershell
Powershell
  #15 Puzzle Game $Script:Neighbours = @{ "1" = @("2","5") "2" = @("1","3","6") "3" = @("2","4","7") "4" = @("3","8") "5" = @("1","6","9") "6" = @("2","5","7","10") "7" = @("3","6","8","11") "8" = @("4","7","12") "9" = @("5","10","13") "10" = @("6","9","11","14") "11" = @("7"...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Red
Red
Red [Needs: 'View]   random/seed now board: random [2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0]   ; ----------- move engine ----------- tasse: function [b] [ forall b [while [b/1 = 0] [remove b]] head append/dup b 0 4 - length? b ] somme: function [b] [ tasse b repeat n 3 [ m: n + 1 if all [b/:n <>...
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 dow...
#CoffeeScript
CoffeeScript
  bottlesOfBeer = (n) -> "#{n} bottle#{if n is 1 then '' else 's'} of beer"   console.log """ #{bottlesOfBeer n} on the wall #{bottlesOfBeer n} Take one down, pass it around #{bottlesOfBeer n - 1} on the wall \n""" for n in [99..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. T...
#Phix
Phix
-- Note this uses simple/strict left association, so for example: -- 1+2*1*8 is ((1+2)*1)*8 not 1+((2*1)*8) [or 1+(2*(1*8))], and -- 7-(2*2)*8 is (7-(2*2))*8 not 7-((2*2)*8) -- Does not allow unary minus on the first digit. -- Uses solve24() from the next task, when it can. -- (you may want to comment out the last ...
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 ≤...
#FunL
FunL
println( sum(map(int, readLine().split(' +'))) )
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 sid...
#Prolog
Prolog
abc_problem :- maplist(abc_problem, ['', 'A', bark, bOOk, treAT, 'COmmon', sQuaD, 'CONFUSE']).     abc_problem(Word) :- L = [[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]],   ( abc_problem(L, Word) -> format('~w OK~n', [Word]) ; ...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#REXX
REXX
/*REXX program to simulate the problem of 100 prisoners: random, and optimal strategy.*/ parse arg men trials seed . /*obtain optional arguments from the CL*/ if men=='' | men=="," then men= 100 /*number of prisoners for this run.*/ if trials=='' | trials=="," then trials= 10000...
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
#Processing
Processing
  int number_of_grid_cells = 16; // Set the number of cells of the board here 9, 16, 25 etc color piece_color = color(255, 175, 0); color background_color = color(235, 231, 178); color piece_shadow_dark = color(206, 141, 0); color piece_shadow_light = color(255, 214, 126); int z, t, p, piece_number, row_length, pi...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#REXX
REXX
/*REXX program lets a user play the 2048 game on an NxN grid (default is 4x4 grid).*/ parse arg N win seed . /*obtain optional arguments from the CL*/ if N=='' | N=="," then N= 4 /*Not specified? Then use the default.*/ if win=='' | win=="," then win= 2**11 ...
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 dow...
#ColdFusion
ColdFusion
<cfoutput> <cfloop index="x" from="99" to="0" step="-1"> <cfset plur = iif(x is 1,"",DE("s"))> #x# bottle#plur# of beer on the wall<br> #x# bottle#plur# of beer<br> Take one down, pass it around<br> #iif(x is 1,DE("No more"),"x-1")# bottle#iif(x is 2,"",DE("s"))# of beer on the wall<br><br> </cf...
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. T...
#PHP
PHP
#!/usr/bin/env php 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. Otherwi...
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 ≤...
#Furor
Furor
  cin sto mystring #s dec mystring @mystring sprintnl #g ."The length of the input is: " @mystring~ print ." characters.\n" mylist @mystring 32 strtolist ."Quantity of the items: " mylist~ printnl mylist~ mem sto nums mylist 10 ![ ."Item #" [:] #g print ." = " [|] sprintnl @nums [:] [|] #s (#g) [^] ] ."Sum = " 0 #g myl...
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 sid...
#PureBasic
PureBasic
EnableExplicit #LETTERS = "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM "   Procedure.s can_make_word(word.s) Define letters.s = #LETTERS, buffer.s Define index1.i, index2.i Define match.b For index1=1 To Len(word) index2=1 : match=#False Repeat buffer=StringField(letters,index2...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Ruby
Ruby
prisoners = [*1..100] N = 10_000 generate_rooms = ->{ [nil]+[*1..100].shuffle }   res = N.times.count do rooms = generate_rooms[] prisoners.all? {|pr| rooms[1,100].sample(50).include?(pr)} end puts "Random strategy : %11.4f %%" % (res.fdiv(N) * 100)   res = N.times.count do rooms = generate_rooms[] prisoners.al...
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
#PureBasic
PureBasic
  #difficulty=10 ;higher is harder #up="u" #down="d" #left="l" #right="r" OpenConsole("15 game"):EnableGraphicalConsole(1) Global Dim Game.i(3,3) Global hole.point   Procedure NewBoard() num.i=0 For j=0 To 3 For i=0 To 3 Game(i,j)=num num+1 Next i Next j EndProcedure ...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Ring
Ring
  # Project : 2048 Game   load "stdlib.ring" load "guilib.ring"   C_GAMETITLE = '2048 Game' C_WINDOWBACKGROUND = "background-color: gray;" if isMobile() C_LABELFONTSIZE = "font-size:120px;" C_BUTTONFONTSIZE = "font-size:160px;" else C_LABELFONTSIZE = "font-size:50px;" C_BUTTONFONTSIZE = "font-size:80px;" ok ...
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 dow...
#Comal
Comal
0010 DIM itone$(0:1) 0020 itone$(0):="one";itone$(1):="it" 0030 FOR b#:=99 TO 1 STEP -1 DO 0040 bottles(b#) 0050 PRINT "of beer on the wall," 0060 bottles(b#) 0070 PRINT "of beer," 0080 PRINT "Take ",itone$(b#=1)," down and pass it around," 0090 bottles(b#-1) 0100 PRINT "of beer on the wall!" 0110 PRINT...
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. T...
#Picat
Picat
import util.   main => play.   play => nl, Digits = [random() mod 9 + 1 : _ in 1..4].sort(), println("Enter \"q\" to quit"), println("Enter \"!\" to request a new set of four digits."), printf("Or enter expression using %w => ", Digits), Exp = read_line().strip(), evaluate(Digits,Exp).  ...
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 ≤...
#Gambas
Gambas
Public Sub Main() Dim sInput As String = InputBox("Input 2 numbers seperated by a space", "A + B")   Print Split(sInput, " ")[0] & " + " & Split(sInput, " ")[1] & " = " & Str(Val(Split(sInput, " ")[0]) + Val(Split(sInput, " ")[1]))   End
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 sid...
#Python
Python
  ''' Note that this code is broken, e.g., it won't work when blocks = [("A", "B"), ("A","C")] and the word is "AB", where the answer should be True, but the code returns False. ''' blocks = [("B", "O"), ("X", "K"), ("D", "Q"), ("C", "P"), ("N", "A"), ("G", "T"), ...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Rust
Rust
[dependencies] rand = '0.7.2'
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
#Python
Python
  ''' Structural Game for 15 - Puzzle with different difficulty levels''' from random import randint     class Puzzle: def __init__(self): self.items = {} self.position = None   def main_frame(self): d = self.items print('+-----+-----+-----+-----+') print('|%s|%s|%s|%s|' ...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Ruby
Ruby
  #!/usr/bin/ruby   require 'io/console'   class Board def initialize size=4, win_limit=2048, cell_width = 6 @size = size; @cw = cell_width; @win_limit = win_limit @board = Array.new(size) {Array.new(size, 0)} @moved = true; @score = 0; @no_more_moves = false spawn end   def draw print "\n\n" ...
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 dow...
#Comefrom0x10
Comefrom0x10
bottles = ' bottles ' remaining = 99 one_less_bottle = remaining depluralize comefrom drinking if one_less_bottle is 1 bottles = ' bottle '   drinking comefrom if remaining is one_less_bottle remaining bottles 'of beer on the wall' remaining bottles 'of beer' 'Take one down, pass it around' one_less_bottl...
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. T...
#PicoLisp
PicoLisp
  (load "@lib/frac.l")   (de random4digits () (setq Numbers (make (do 4 (link (rand 1 9))))) Numbers )   (de prompt () (prinl "^JPlease enter a 'Lisp' expression (integer or fractional math) that equals 24,^J" "using (, ), frac, + or f+, - or f-, * or f*, / or f/, and " Numbers "^J" "(use eac...
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 ≤...
#Gastona
Gastona
#listix#   <main> "@<p1> + @<p2> = " =, p1 + p2  
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 sid...
#q
q
BLOCKS:string`BO`XK`DQ`CP`NA`GT`RE`TG`QD`FS`JW`HU`VI`AN`OB`ER`FS`LY`PC`ZM WORDS:string`A`BARK`BOOK`TREAT`COMMON`SQUAD`CONFUSE   cmw:{[s;b] / [str;blocks] $[0=count s; 1b; / empty string not any found:any each b=s 0; 0b; ...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Sather
Sather
class MAIN is shuffle (a: ARRAY{INT}) is ARR_PERMUTE_ALG{INT, ARRAY{INT}}::shuffle(a); end;   try_random (n: INT, drawers: ARRAY{INT}, tries: INT): BOOL is my_tries ::= drawers.inds; shuffle(my_tries); loop tries.times!; if drawers[my_tries.elt!] = n then return true; 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
#QB64
QB64
  _TITLE "GUI Sliding Blocks Game " RANDOMIZE TIMER   ' get from user the desired board size = s DO LOCATE CSRLIN, 3: INPUT "(0 quits) Enter your number of blocks per side 3 - 9 you want > ", s IF s = 0 THEN END LOOP UNTIL s > 2 AND s < 10   ' screen setup: based on the square blocks q pixels a sides q = 540 / ...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Rust
Rust
  use std::io::{self,BufRead}; extern crate rand;   enum Usermove { Up, Down, Left, Right, }   fn print_game(field :& [[u32;4];4] ){ println!("{:?}",&field[0] ); println!("{:?}",&field[1] ); println!("{:?}",&field[2] ); println!("{:?}",&field[3] ); }   fn get_usermove()-> Usermove { ...
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 dow...
#Common_Lisp
Common Lisp
include "cowgol.coh";   sub Bottles(n: uint8) is if n == 0 then print("No more"); else print_i8(n); end if;   print(" bottle"); if n != 1 then print("s"); end if; end sub;   sub Verse(n: uint8) is Bottles(n); print(" of beer on the wall,\n"); Bottles(n); p...
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. T...
#PL.2FI
PL/I
  /* Plays the game of 24. */   TWENTYFOUR: procedure options (main); /* 14 August 2010 */   CTP: procedure (E) returns (character(50) varying); declare E character (*) varying; declare OUT character (length(E)) varying; declare S character (length(E)) varying controlled; declare c character (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 ≤...
#Gema
Gema
<D> <D>=@add{$1;$2}
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 sid...
#Quackery
Quackery
[ $ "BOXKDQCPNAGTRETGQDFS" $ "JWHUVIANOBERFSLYPCZM" join ] constant is blocks ( --> $ )   [ -2 & tuck pluck drop swap pluck drop ] is remove2 ( $ n --> $ )   [ iff [ say "True" ] else [ say "False" ] ] is echotruth ( b --> )   [ true blocks rot witheach [ upper...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Scala
Scala
import scala.util.Random import scala.util.control.Breaks._   object Main { def playOptimal(n: Int): Boolean = { val secretList = Random.shuffle((0 until n).toBuffer)   for (i <- secretList.indices) { var prev = i breakable { for (_ <- 0 until secretList.size / 2) { if (secretLis...
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
#Quackery
Quackery
  ( moves: 0 - up, 1 - down, 2 - left, 3 - right )   [ stack ] is 15.solver ( --> [ )   [ 0 swap find ] is find-empty ( board --> n )   [ over + dup -1 > over 4 < and iff [ nip true ] else [ drop false ] ] is try-nudge ( coord delta --> coord ? )   [ dip [ dup find-...
http://rosettacode.org/wiki/2048
2048
Task Implement a 2D sliding block puzzle game where blocks with numbers are combined to add their values. Rules of the game   The rules are that on each turn the player must choose a direction   (up, down, left or right).   All tiles move as far as possible in that direction, some move more than others.   Two ...
#Scala
Scala
import java.awt.event.{KeyAdapter, KeyEvent, MouseAdapter, MouseEvent} import java.awt.{BorderLayout, Color, Dimension, Font, Graphics2D, Graphics, RenderingHints} import java.util.Random   import javax.swing.{JFrame, JPanel, SwingUtilities}   object Game2048 { val target = 2048 var highest = 0   def main(args: A...
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 dow...
#Component_Pascal
Component Pascal
include "cowgol.coh";   sub Bottles(n: uint8) is if n == 0 then print("No more"); else print_i8(n); end if;   print(" bottle"); if n != 1 then print("s"); end if; end sub;   sub Verse(n: uint8) is Bottles(n); print(" of beer on the wall,\n"); Bottles(n); p...
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. T...
#Potion
Potion
is_num = (s): x = s ord(0) if (x >= "0"ord && x <= "9"ord): true. else: false. .   nums = (s): res = () 0 to (s length, (b): c = s(b) if (is_num(c)): res push(c). .) res.   try = 1 while (true): r = rand string digits = (r(0),r(1),r(2),r(3)) "\nMy next four digits: " print digits j...
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 ≤...
#Genie
Genie
[indent=4] /* A+B in Genie valac aplusb-genie.gs ./aplusb-genie */ init a:int64 = 0 b:int64 = 0 leftover:string = ""   print "Enter A and B, two numbers separated by space" line:string = stdin.read_line() res:bool = int64.try_parse(line, out a, out leftover) res = int64.try_parse(lefto...
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 sid...
#R
R
blocks <- rbind(c("B","O"), c("X","K"), c("D","Q"), c("C","P"), c("N","A"), c("G","T"), c("R","E"), c("T","G"), c("Q","D"), c("F","S"), c("J","W"), c("H","U"), c("V","I"), c("A","N"), c("O","B"), c("E","R"), c("F","S"), c("L","Y"), c("P","C"), c("Z","M"))   canMake <- function(x) { ...
http://rosettacode.org/wiki/100_prisoners
100 prisoners
The Problem 100 prisoners are individually numbered 1 to 100 A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. Prisoners start outside the room They can decid...
#Swift
Swift
import Foundation   struct PrisonersGame { let strategy: Strategy let numPrisoners: Int let drawers: [Int]   init(numPrisoners: Int, strategy: Strategy) { self.numPrisoners = numPrisoners self.strategy = strategy self.drawers = (1...numPrisoners).shuffled() }   @discardableResult func play() -...
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
#R
R
  puz15<-function(scramble.length=100){ m=matrix(c(1:15,0),byrow=T,ncol=4) scramble=sample(c("w","a","s","d"),scramble.length,replace=T) for(i in 1:scramble.length){ m=move(m,scramble[i]) } win=F turn=0 while(!win){ print.puz(m) newmove=getmove() if(newmove=="w"|newmove=="a"|newmove=="s"|n...