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/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Pascal
Pascal
  program AbundantOddNumbers; {$IFDEF FPC} {$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$CODEALIGN proc=16}{$ALIGN 16} {$ELSE} {$APPTYPE CONSOLE} {$ENDIF} {geeksforgeeks * 1100 = 2^2*5^2*11^1 (2^0 + 2^1 + 2^2) * (5^0 + 5^1 + 5^2) * (11^0 + 11^1) (upto the power of factor in factorization i.e. power of 2 and 5 i...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#F.23
F#
  type Player = | Computer | Person type Play = {runningTotal:int; nextTurn:Player} type Win = | ByExact of Player | ByOtherExceeded of Player type Status = | Start | Playing of Play | Winner of Win | Exit   let rnd = System.Random () let randomFirstPlayer () = let selection = rnd.Ne...
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
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program game24Solver.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a ...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Groovy
Groovy
class FourRings { static void main(String[] args) { fourSquare(1, 7, true, true) fourSquare(3, 9, true, true) fourSquare(0, 9, false, false) }   private static void fourSquare(int low, int high, boolean unique, boolean print) { int count = 0   if (print) { ...
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...
#11l
11l
L(i) (99..1).step(-1) print(i‘ bottles of beer on the wall’) print(i‘ bottles of beer’) print(‘Take one down, pass it around’) print((i - 1)" bottles of beer on the wall\n")
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...
#Argile
Argile
use std, array, list   do generate random digits show random digits let result = parse expression (get input line) if result != ERROR if some digits are unused print "Wrong ! (you didn't use all digits)" ; failure++ else if result == 24.0 print "Correct !" ; success++ else print "W...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#PARI.2FGP
PARI/GP
row(n)=my(v=vector(n)); forpart(i=n,v[i[#i]]++); v; show(n)=for(k=1,n,print(row(k))); show(25) apply(numbpart, [23,123,1234,12345]) plot(x=1,999.9, numbpart(x\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 ≤...
#AutoHotkey
AutoHotkey
Gui, Add, Edit, vEdit ;Enter your A+B, i.e. 5+3 or 5+3+1+4+6+2 Gui, Add, Button, gAdd, Add Gui, Add, Edit, ReadOnly x+10 w80 Gui, Show return   Add: Gui, Submit, NoHide Loop, Parse, Edit, + ;its taking each substring separated by "+" and its storing it in A_LoopField var += A_LoopField ;here its adding it to var GuiCo...
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#Shen
Shen
(define ack 0 N -> (+ N 1) M 0 -> (ack (- M 1) 1) M N -> (ack (- M 1) (ack M (- N 1))))
http://rosettacode.org/wiki/Abbreviations,_automatic
Abbreviations, automatic
The use of   abbreviations   (also sometimes called synonyms, nicknames, AKAs, or aliases)   can be an easy way to add flexibility when specifying or using commands, sub─commands, options, etc. It would make a list of words easier to maintain   (as words are added, changed, and/or deleted)   if the minimum abbrevia...
#Vlang
Vlang
import os   fn distinct_strings(strs []string) []string { len := strs.len mut set := map[string]bool{} mut distinct := []string{cap: len} for str in strs { if str !in set { distinct << str set[str] = true } } return distinct }   fn take_runes(s string, n i...
http://rosettacode.org/wiki/Abbreviations,_automatic
Abbreviations, automatic
The use of   abbreviations   (also sometimes called synonyms, nicknames, AKAs, or aliases)   can be an easy way to add flexibility when specifying or using commands, sub─commands, options, etc. It would make a list of words easier to maintain   (as words are added, changed, and/or deleted)   if the minimum abbrevia...
#Wren
Wren
import "io" for File import "/pattern" for Pattern import "/seq" for Lst import "/fmt" for Fmt   var p = Pattern.new("+1/s") var lines = File.read("days_of_week.txt").split("\n").map { |l| l.trim() } var i = 1 for (line in lines) { if (line == "") { if (i != lines.count) System.print() } else { ...
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...
#CoffeeScript
CoffeeScript
blockList = [ 'BO', 'XK', 'DQ', 'CP', 'NA', 'GT', 'RE', 'TG', 'QD', 'FS', 'JW', 'HU', 'VI', 'AN', 'OB', 'ER', 'FS', 'LY', 'PC', 'ZM' ]   canMakeWord = (word="") -> # Create a shallow clone of the master blockList blocks = blockList.slice 0 # Check if blocks contains letter checkBlocks = (letter) -> ...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Perl
Perl
use strict; use warnings; use feature 'say'; use ntheory qw/divisor_sum divisors/;   sub odd_abundants { my($start,$count) = @_; my $n = int(( $start + 2 ) / 3); $n += 1 if 0 == $n % 2; $n *= 3; my @out; while (@out < $count) { $n += 6; next unless (my $ds = divisor_sum($n)) ...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#Fortran
Fortran
! game 21 - an example in modern fortran language for rosseta code.   subroutine ai common itotal, igoal if (itotal .lt. igoal) then move = 1 do i = 1, 3 if (mod(itotal + i - 1 , 4) .eq. 0) then move = i end if end do do i = 1, 3 if (itotal + i .eq. igoal) then move...
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
#AutoHotkey
AutoHotkey
#NoEnv InputBox, NNNN ; user input 4 digits NNNN := RegExReplace(NNNN, "(\d)(?=\d)", "$1,") ; separate with commas for the sort command sort NNNN, d`, ; sort in ascending order for the permutations to work StringReplace NNNN, NNNN, `,, , All ; remove comma separators after sorting   ops := "+-*/" patterns := [ "...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Haskell
Haskell
import Data.List import Control.Monad   perms :: (Eq a) => [a] -> [[a]] perms [] = [[]] perms xs = [ x:xr | x <- xs, xr <- perms (xs\\[x]) ]   combs :: (Eq a) => Int -> [a] -> [[a]] combs 0 _ = [[]] combs n xs = [ x:xr | x <- xs, xr <- combs (n-1) xs ]   ringCheck :: [Int] -> Bool ringCheck [x0, x1, x2, x3, x4, x5, x6]...
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...
#360_Assembly
360 Assembly
  \ 99 bottles of beer on the wall: : allout "no more bottles" ; : just-one "1 bottle"  ; : yeah! dup . " bottles" ;   [ ' allout , ' just-one , ' yeah! , ] var, bottles   : .bottles dup 2 n:min bottles @ swap caseof ; : .beer .bottles . " of beer" . ; : .wall .beer " on the wall" . ; : .take " Take o...
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...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program game24.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a file i...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Perl
Perl
use ntheory qw/:all/;   sub triangle_row { my($n,@row) = (shift); # Tally by first element of the unrestricted integer partitions. forpart { $row[ $_[0] - 1 ]++ } $n; @row; }   printf "%2d: %s\n", $_, join(" ",triangle_row($_)) for 1..25; print "\n"; say "P($_) = ", partitions($_) for (23, 123, 1234, 12345);
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 ≤...
#AutoIt
AutoIt
;AutoIt Version: 3.2.10.0 $num = "45 54" consolewrite ("Sum of " & $num & " is: " & sum($num)) Func sum($numbers) $numm = StringSplit($numbers," ") Return $numm[1]+$numm[$numm[0]] EndFunc
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#Sidef
Sidef
func A(m, n) { m == 0 ? (n + 1)  : (n == 0 ? (A(m - 1, 1))  : (A(m - 1, A(m, n - 1)))); }
http://rosettacode.org/wiki/Abbreviations,_automatic
Abbreviations, automatic
The use of   abbreviations   (also sometimes called synonyms, nicknames, AKAs, or aliases)   can be an easy way to add flexibility when specifying or using commands, sub─commands, options, etc. It would make a list of words easier to maintain   (as words are added, changed, and/or deleted)   if the minimum abbrevia...
#Yabasic
Yabasic
  a = open("days_of_week.txt", "r")   while(not eof(#a)) line input #a s$ print buscar(s$), " ", s$ wend   close #a   sub buscar(s$) local n, d, i, j, s, a$, b$, r$(1)   n = token(s$, r$()) d = 1   repeat s = true for i = 1 to n for j = i + 1 to n a$ =...
http://rosettacode.org/wiki/Abbreviations,_automatic
Abbreviations, automatic
The use of   abbreviations   (also sometimes called synonyms, nicknames, AKAs, or aliases)   can be an easy way to add flexibility when specifying or using commands, sub─commands, options, etc. It would make a list of words easier to maintain   (as words are added, changed, and/or deleted)   if the minimum abbrevia...
#zkl
zkl
nds:=File("daysOfWeek.txt").read().howza(11) // stripped lines .pump(List,Void.Filter,fcn(day){ d,N,m := day.split(),d.len(),(0).max(d.apply("len")); // N==7 foreach n in ([1..m]){ ds:=d.apply("get",0,n); // ("Su","Mo","Tu","We","Th","Fr","Sa") foreach a,b in (N,[a+1..N-1]){ if(ds[a]==ds[b]) contin...
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...
#Comal
Comal
0010 FUNC can'make'word#(word$) CLOSED 0020 blocks$:=" BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM" 0030 FOR i#:=1 TO LEN(word$) DO 0040 pos#:=UPPER$(word$(i#)) IN blocks$ 0050 IF NOT pos# THEN RETURN FALSE 0060 blocks$(pos#):="";blocks$(pos# BITXOR 1):="" 0070 ENDFOR i# 0080 RETURN TRUE 0090 ENDFUNC 0...
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...
#11l
11l
F play_random(n) V pardoned = 0 V in_drawer = Array(0.<100) V sampler = Array(0.<100) L 0 .< n random:shuffle(&in_drawer) V found = 0B L(prisoner) 100 found = 0B L(reveal) random:sample(sampler, 50) V card = in_drawer[reveal] I card == prisoner ...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Phix
Phix
function abundantOdd(integer n, done, lim, bool printAll) while done<lim do atom tot = sum(factors(n,-1)) if tot>n then done += 1 if printAll or done=lim then string ln = iff(printAll?sprintf("%2d. ",done):"") printf(1,"%s%,6d (proper sum:%,d)\...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#FreeBASIC
FreeBASIC
#define PLAYER 1 #define COMP 0 randomize timer   dim as uinteger sum, add = 0 dim as uinteger turn = int(rnd+0.5) dim as uinteger precomp(0 to 3) = { 1, 1, 3, 2 }   while sum < 21: turn = 1 - turn print using "The sum is ##"; sum if turn = PLAYER then print "It is your turn." while add <...
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
#BBC_BASIC
BBC BASIC
  PROCsolve24("1234") PROCsolve24("6789") PROCsolve24("1127") PROCsolve24("5566") END   DEF PROCsolve24(s$) LOCAL F%, I%, J%, K%, L%, P%, T%, X$, o$(), p$(), t$() DIM o$(4), p$(24,4), t$(11) o$() = "", "+", "-", "*", "/" RESTORE FOR T% = 1 TO 11 ...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#J
J
fspuz=:dyad define range=: x+i.1+y-x lo=. 6+3*x hi=. _3+2*y r=.i.0 0 if. lo <: hi do. for_T.lo ([+[:i.1+-~) hi do. range2=: (#~ (T-{.range)>:]) range range3=: (#~ (T-+/2{.range)>:]) range ab=: (#~ ~:/"1) (,.T-])range2 abc=: ;ab <@([ ,"1 0 -.~)"1/range3 abcd=: (#~ T = +/@}."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 dow...
#6502_Assembly
6502 Assembly
  \ 99 bottles of beer on the wall: : allout "no more bottles" ; : just-one "1 bottle"  ; : yeah! dup . " bottles" ;   [ ' allout , ' just-one , ' yeah! , ] var, bottles   : .bottles dup 2 n:min bottles @ swap caseof ; : .beer .bottles . " of beer" . ; : .wall .beer " on the wall" . ; : .take " Take o...
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...
#Arturo
Arturo
print "-----------------------------" print " Welcome to 24 Game" print "-----------------------------"   digs: map 1..4 'x -> random 1 9   print ["The numbers you can use are:" join.with:" " digs]   print ""   validExpression?: function [expr][ loop expr 'item [ if or? inline? item block? item [ ...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Phix
Phix
-- demo\rosetta\9billionnames.exw with javascript_semantics sequence cache = {{1}} function cumu(integer n) sequence r for l=length(cache) to n do r = {0} for x=1 to l do r = append(r,r[-1]+cache[l-x+1][min(x,l-x)+1]) end for cache = append(cache,r) end for retur...
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 ≤...
#AWK
AWK
{print $1 + $2}
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#Simula
Simula
BEGIN INTEGER procedure Ackermann(g, p); SHORT INTEGER g, p; Ackermann:= IF g = 0 THEN p+1 ELSE Ackermann(g-1, IF p = 0 THEN 1 ELSE Ackermann(g, p-1));   INTEGER g, p; FOR p := 0 STEP 3 UNTIL 13 DO BEGIN g := 4 - p/3; outtext("Ackermann("); outi...
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...
#Common_Lisp
Common Lisp
  (defun word-possible-p (word blocks) (cond ((= (length word) 0) t) ((null blocks) nil) (t (let* ((c (aref word 0)) (bs (remove-if-not #'(lambda (b) (find c b :test #'char-equal)) blocks))) (some #'identity ...
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...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program prisonniex64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantes...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#PicoLisp
PicoLisp
(de accud (Var Key) (if (assoc Key (val Var)) (con @ (inc (cdr @))) (push Var (cons Key 1)) ) Key ) (de **sum (L) (let S 1 (for I (cdr L) ...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#Gambas
Gambas
  ' Gambas module file   Private gameConunt As Integer = 0 Private numRound As Integer = 1 Private winPlayer As Integer = 0 Private winComputer As Integer = 0     Public Sub Main()   Dim entra As String   Print "Enter q to quit at any time\nThe computer will choose first"   While gameConunt < 21 Print "ROUND:...
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
#C
C
#include <stdio.h>   typedef struct {int val, op, left, right;} Node;   Node nodes[10000]; int iNodes;   int b; float eval(Node x){ if (x.op != -1){ float l = eval(nodes[x.left]), r = eval(nodes[x.right]); switch(x.op){ case 0: return l+r; case 1: return l-r; case...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Java
Java
import java.util.Arrays;   public class FourSquares { public static void main(String[] args) { fourSquare(1, 7, true, true); fourSquare(3, 9, true, true); fourSquare(0, 9, false, false); }   private static void fourSquare(int low, int high, boolean unique, boolean print) { in...
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...
#6800_Assembly
6800 Assembly
  \ 99 bottles of beer on the wall: : allout "no more bottles" ; : just-one "1 bottle"  ; : yeah! dup . " bottles" ;   [ ' allout , ' just-one , ' yeah! , ] var, bottles   : .bottles dup 2 n:min bottles @ swap caseof ; : .beer .bottles . " of beer" . ; : .wall .beer " on the wall" . ; : .take " Take o...
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...
#AutoHotkey
AutoHotkey
AutoExecute: Title := "24 Game" Gui, -MinimizeBox Gui, Add, Text, w230 vPuzzle Gui, Add, Edit, wp vAnswer Gui, Add, Button, w70, &Generate Gui, Add, Button, x+10 wp Default, &Submit Gui, Add, Button, x+10 wp, E&xit     ButtonGenerate: ; new set of numbers Loop, 4 Random...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Phixmonti
Phixmonti
/# Rosetta Code problem: http://rosettacode.org/wiki/9_billion_names_of_God_the_integer by Galileo, 05/2022 #/   include ..\Utilitys.pmt   cls   def nine_billion_names >ps 0 ( tps dup ) dim   1 ( 1 1 ) sset   ( 2 tps ) for var i ( 1 i ) for var j ( i 1 - j 1 - ) sget >ps ( i j - j ) sget...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Picat
Picat
import cp.   main => foreach(N in 1..25) P = integer_partition(N).reverse, G = P.map(sort_down).map(first).counts.to_list.sort.map(second), println(G=G.sum) end, println("Num partitions == sum of rows:"), println([partition1(N) : N in 1..25]).   % Get all partitions integer_partition(N) = find_al...
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 ≤...
#BASIC
BASIC
DEFINT A-Z   tryagain: backhere = CSRLIN INPUT "", i$ i$ = LTRIM$(RTRIM$(i$)) where = INSTR(i$, " ") IF where THEN a = VAL(LEFT$(i$, where - 1)) b = VAL(MID$(i$, where + 1)) c = a + b LOCATE backhere, LEN(i$) + 1 PRINT c ELSE GOTO tryagain END IF
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#Slate
Slate
m@(Integer traits) ackermann: n@(Integer traits) [ m isZero ifTrue: [n + 1] ifFalse: [n isZero ifTrue: [m - 1 ackermann: n] ifFalse: [m - 1 ackermann: (m ackermann: n - 1)]] ].
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...
#Component_Pascal
Component Pascal
  MODULE ABCProblem; IMPORT StdLog, DevCommanders, TextMappers; CONST notfound = -1; TYPE String = ARRAY 3 OF CHAR; VAR blocks : ARRAY 20 OF String;   PROCEDURE Check(s: ARRAY OF CHAR): BOOLEAN; VAR used: SET; i,blockIndex: INTEGER;   PROCEDURE GetBlockFor(c: CHAR): INTEGER; VAR i: INTEGER; BEGIN c := CAP...
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...
#Ada
Ada
  package Prisoners is   type Win_Percentage is digits 2 range 0.0 .. 100.0; type Drawers is array (1 .. 100) of Positive;   function Play_Game (Repetitions : in Positive; Strategy  : not null access function (Cupboard  : in Drawers; Max_Prisoners : Integer; Max_Attempts : ...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Processing
Processing
void setup() { println("First 25 abundant odd numbers: "); int abundant = 0; int i = 1; while (abundant < 25) { int sigma_sum = sigma(i); if (sigma_sum > 2 * i) { abundant++; println(i + " Sigma sum: " + sigma_sum); } i += 2; } println("Thousandth abundant odd number: "); whil...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#Go
Go
package main   import ( "bufio" "fmt" "log" "math/rand" "os" "strconv" "time" )   var scanner = bufio.NewScanner(os.Stdin)   var ( total = 0 quit = false )   func itob(i int) bool { if i == 0 { return false } return true }   func getChoice() { for { f...
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
#C.2B.2B
C++
  #include <iostream> #include <ratio> #include <array> #include <algorithm> #include <random>   typedef short int Digit; // Typedef for the digits data type.   constexpr Digit nDigits{4}; // Amount of digits that are taken into the game. constexpr Digit maximumDigit{9}; // Maximum digit that may be taken into th...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#JavaScript
JavaScript
(() => {   // 4-rings or 4-squares puzzle ------------------------   // rings :: noRepeatedDigits -> DigitList -> solutions // rings :: Bool -> [Int] -> [[Int]] const rings = (uniq, digits) => { return 0 < digits.length ? (() => { const ns = sortBy(flip(compare), digi...
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...
#8080_Assembly
8080 Assembly
  \ 99 bottles of beer on the wall: : allout "no more bottles" ; : just-one "1 bottle"  ; : yeah! dup . " bottles" ;   [ ' allout , ' just-one , ' yeah! , ] var, bottles   : .bottles dup 2 n:min bottles @ swap caseof ; : .beer .bottles . " of beer" . ; : .wall .beer " on the wall" . ; : .take " Take o...
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...
#AutoIt
AutoIt
  ;AutoIt Script Example ;by Daniel Barnes ;spam me at djbarnes at orcon dot net dot en zed ;13/08/2012   ;Choose four random digits (1-9) with repetitions allowed: global $digits FOR $i = 1 TO 4 $digits &= Random(1,9,1) NEXT   While 1 main() WEnd   Func main() $text = "Enter an equation (using all of, and only, th...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#PicoLisp
PicoLisp
(de row (N) (let C '((1)) (do N (push 'C (grow C)) ) (mapcon '((L) (when (cdr L) (cons (- (cadr L) (car L))) ) ) (car C) ) ) )   (de grow (Lst) (let (L (length Lst) S 0) (cons 0 (mapcar '((I X) (i...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Pike
Pike
array cumu(int n) { array(array(int)) cache = ({({1})});   for(int l = sizeof(cache); l < n + 1; l++) { array(int) r = ({0}); for(int x = 1; x < l + 1; x++) { r = Array.push(r, r[-1] + cache[l - x][min(x, l-x)]); } cache = Array.push(cache, r); } return cache[n]; }   array row(int n) { array r = cumu(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 ≤...
#Batch_File
Batch File
::aplusb.cmd @echo off setlocal set /p a="A: " set /p b="B: " set /a c=a+b echo %c% endlocal
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#Smalltalk
Smalltalk
|ackermann| ackermann := [ :n :m | (n = 0) ifTrue: [ (m + 1) ] ifFalse: [ (m = 0) ifTrue: [ ackermann value: (n-1) value: 1 ] ifFalse: [ ackermann value: (n-1) value: ( ackermann value: 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 sid...
#Cowgol
Cowgol
include "cowgol.coh"; include "strings.coh";   sub can_make_word(word: [uint8]): (r: uint8) is var blocks: [uint8] := "BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM";   # Initialize blocks array var avl: uint8[41]; CopyString(blocks, &avl[0]);   r := 1; loop var letter := [word]; 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...
#APL
APL
  ∇ R ← random Nnc; N; n; c (N n c) ← Nnc R ← ∧/{∨/⍵=c[n?N]}¨⍳N ∇   ∇ R ← follow Nnc; N; n; c; b (N n c) ← Nnc b ← n N⍴⍳N R ← ∧/∨⌿b={⍺⊢c[⍵]}⍀n N⍴c ∇   ∇ R ← M timesSimPrisoners Nn; N; n; m; c; r; s (N n) ← Nn R ← 0 0 m ← M LOOP: c←N?N r ← random N n c s ← follow N n c R ← R + r,s ...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#PureBasic
PureBasic
NewList l_sum.i()     Procedure.i sum_proper_divisors(n.i) Define.i sum, i=3, j Shared l_sum() AddElement(l_sum()) l_sum()=1 While i<Sqr(n)+1 If n%i=0 sum+i AddElement(l_sum()) l_sum()=i j=n/i If i<>j sum+j AddElement(l_sum()) l_sum()=j EndIf ...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#Haskell
Haskell
import System.Random import System.IO import System.Exit import Control.Monad import Text.Read import Data.Maybe   promptAgain :: IO Int promptAgain = do putStrLn "Invalid input - must be a number among 1,2 or 3. Try again." playerMove   playerMove :: IO Int playerMove = do putStr "Your choice(1 to 3):" number ...
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
#C.23
C#
using System; using System.Collections.Generic; using static System.Linq.Enumerable;   public static class Solve24Game { public static void Main2() { var testCases = new [] { new [] { 1,1,2,7 }, new [] { 1,2,3,4 }, new [] { 1,2,4,5 }, new [] { 1,2,7,7 }, ...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#jq
jq
# Generate a stream of all the permutations of the input array def permutations: if length == 0 then [] else range(0;length) as $i | [.[$i]] + (del(.[$i])|permutations) end ;   # Permutations of a ... n inclusive def permutations(a;n): [range(a;n+1)] | permutations;   # value of a box # Input: the table...
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...
#8th
8th
  \ 99 bottles of beer on the wall: : allout "no more bottles" ; : just-one "1 bottle"  ; : yeah! dup . " bottles" ;   [ ' allout , ' just-one , ' yeah! , ] var, bottles   : .bottles dup 2 n:min bottles @ swap caseof ; : .beer .bottles . " of beer" . ; : .wall .beer " on the wall" . ; : .take " Take o...
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...
#BBC_BASIC
BBC BASIC
REM Choose four random digits (1-9) with repetitions allowed: DIM digits%(4), check%(4) FOR choice% = 1 TO 4 digits%(choice%) = RND(9) NEXT choice%   REM Prompt the player: PRINT "Enter an equation (using all of, and only, the single digits "; FOR index% = 1 TO 4 ...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#PureBasic
PureBasic
  Define nMax.i=25, n.i, k.i Dim pfx.s(1)   Procedure.s Sigma(sx.s, sums.s) Define i.i, v1.i, v2.i, r.i Define s.s, sa.s sums=ReverseString(sums) : s=ReverseString(sx) For i=1 To Len(s)*Bool(Len(s)>Len(sums))+Len(sums)*Bool(Len(sums)>=Len(s)) v1=Val(Mid(s,i,1)) v2=Val(Mid(sums,i,1)) r+v1+v2 ...
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 ≤...
#bc
bc
read() + read()
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#SmileBASIC
SmileBASIC
DEF ACK(M,N) IF M==0 THEN RETURN N+1 ELSEIF M>0 AND N==0 THEN RETURN ACK(M-1,1) ELSE RETURN ACK(M-1,ACK(M,N-1)) ENDIF 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...
#D
D
import std.stdio, std.algorithm, std.string;   bool canMakeWord(in string word, in string[] blocks) pure /*nothrow*/ @safe { auto bs = blocks.dup; outer: foreach (immutable ch; word.toUpper) { foreach (immutable block; bs) if (block.canFind(ch)) { bs = bs.remove(bs.countUntil...
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...
#Applesoft_BASIC
Applesoft BASIC
0 GOTO 9   1 FOR X = 0 TO N:J(X) = X: NEXT: FOR I = 0 TO N:FOR X = 0 TO N:T = J(X):NP = INT ( RND (1) * H):J(X) = J(NP):J(NP) = T: NEXT :FOR G = 1 TO W:IF D(J(G)) = I THEN IP = IP + 1: NEXT I: RETURN 2 NEXT G:RETURN   3 FOR I = 0 TO N:NG = I: FOR G = 0 TO W:CD = D(NG):IF CD = I THEN IP = IP + 1: NEXT I: RETURN 4 NG...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Python
Python
#!/usr/bin/python # Abundant odd numbers - Python   oddNumber = 1 aCount = 0 dSum = 0   from math import sqrt   def divisorSum(n): sum = 1 i = int(sqrt(n)+1)   for d in range (2, i): if n % d == 0: sum += d otherD = n // d if otherD != d: sum +=...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#J
J
  g21=: summarize@play@setup ::('g21: error termination'"_)   NB. non-verb must be defined before use, otherwise are assumed verbs. Until=: 2 :'u^:(0-:v)^:_'   t=: 'score turn choice' (t)=: i. # ;: t empty erase't'   Fetch=: &{ Alter=: }   play=: move Until done done=: 21 <: score Fetch move=: [: update you`it@.(turn F...
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
#Ceylon
Ceylon
import ceylon.random { DefaultRandom }   shared sealed class Rational(numerator, denominator = 1) satisfies Numeric<Rational> {   shared Integer numerator; shared Integer denominator;   Integer gcd(Integer a, Integer b) => if (b == 0) then a else gcd(b, a % b);   shared Rational inverted => Rational(denominator, n...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Julia
Julia
  using Combinatorics   function foursquares(low, high, onlyunique=true, showsolutions=true) integers = collect(low:high) count = 0 sumsallequal(c) = c[1] + c[2] == c[2] + c[3] + c[4] == c[4] + c[5] + c[6] == c[6] + c[7] combos = onlyunique ? combinations(integers) : with_repla...
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...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program bootleBeer64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantes...
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...
#Befunge
Befunge
v > > >> v 2 2 1234 4 ^1?3^4 >8*00p10p> >?  ?5> 68*+00g10gpv v9?7v6 0 8 0 > > >> ^ g ^p00 _v# `\*49:+1 < _>"rorrE",,,,,$ >~:67*-!#v_:167*+-!#v_:95*-!#v_:295*+-!#v_:586*+\`#v_:97*2--!#v ...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Python
Python
cache = [[1]] def cumu(n): for l in range(len(cache), n+1): r = [0] for x in range(1, l+1): r.append(r[-1] + cache[l-x][min(x, l-x)]) cache.append(r) return cache[n]   def row(n): r = cumu(n) return [r[i+1] - r[i] for i in range(n)]   print "rows:" for x in range(1, 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 ≤...
#Befunge
Befunge
&&+.@
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#SNOBOL4
SNOBOL4
define('ack(m,n)') :(ack_end) ack ack = eq(m,0) n + 1 :s(return) ack = eq(n,0) ack(m - 1,1) :s(return) ack = ack(m - 1,ack(m,n - 1)) :(return) ack_end   * # Test and display ack(0,0) .. ack(3,6) L1 str = str ack(m,n) ' ' n = lt(n,6) n + 1 :s(L1) output = str; str = '' ...
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...
#Delphi
Delphi
program ABC; {$APPTYPE CONSOLE}   uses SysUtils;   type TBlock = set of char;   const TheBlocks : array [0..19] of TBlock = ( [ 'B', 'O' ], [ 'X', 'K' ], [ 'D', 'Q' ], [ 'C', 'P' ], [ 'N', 'A' ], [ 'G', 'T' ], [ 'R', 'E' ], [ 'T', 'G' ], [ 'Q', 'D' ], [ 'F', 'S' ], [ 'J', 'W' ]...
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...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program prisonniers.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a f...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#q
q
s:{c where 0=x mod c:1+til x div 2} / proper divisors sd:sum s@ / sum of proper divisors abundant:{x<sd x} Filter:{y where x each y}
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#Java
Java
  import java.util.Random; import java.util.Scanner;   public class TwentyOneGame {   public static void main(String[] args) { new TwentyOneGame().run(true, 21, new int[] {1, 2, 3}); }   public void run(boolean computerPlay, int max, int[] valid) { String comma = ""; for ( int i = 0 ...
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
#Clojure
Clojure
(ns rosettacode.24game.solve (:require [clojure.math.combinatorics :as c] [clojure.walk :as w]))   (def ^:private op-maps (map #(zipmap [:o1 :o2 :o3] %) (c/selections '(* + - /) 3)))   (def ^:private patterns '( (:o1 (:o2 :n1 :n2) (:o3 :n3 :n4)) (:o1 :n1 (:o2 :n2 (:o3 :n3 :n4))) (:o1 (:o2 (:o3 :n1...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Kotlin
Kotlin
// version 1.1.2   class FourSquares( private val lo: Int, private val hi: Int, private val unique: Boolean, private val show: Boolean ) { private var a = 0 private var b = 0 private var c = 0 private var d = 0 private var e = 0 private var f = 0 private var g = 0 private...
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...
#ABAP
ABAP
REPORT z99bottles.   DATA lv_no_bottles(2) TYPE n VALUE 99.   DO lv_no_bottles TIMES. WRITE lv_no_bottles NO-ZERO. WRITE ' bottles of beer on the wall'. NEW-LINE. WRITE lv_no_bottles NO-ZERO. WRITE ' bottles of beer'. NEW-LINE. WRITE 'Take one down, pass it around'. NEW-LINE. SUBTRACT 1 FROM lv_no_bot...
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...
#Bracmat
Bracmat
( 24-game = m-w m-z 4numbers answer expr numbers , seed get-random convertBinaryMinusToUnary , convertDivisionToMultiplication isExpresssion reciprocal . (seed=.!arg:(~0:~/#?m-w.~0:~/#?m-z)) & seed$!arg & ( get-random = . 36969*mod$(!m-z.65536)+div$(!m-z.6553...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Racket
Racket
#lang racket   (define (cdr-empty ls) (if (empty? ls) empty (cdr ls)))   (define (names-of n) (define (names-of-tail ans raws-rest n) (if (zero? n) ans (names-of-tail (cons 1 (append (map + (take ans (length raws-rest)) ...
http://rosettacode.org/wiki/9_billion_names_of_God_the_integer
9 billion names of God the integer
This task is a variation of the short story by Arthur C. Clarke. (Solvers should be aware of the consequences of completing this task.) In detail, to specify what is meant by a   “name”: The integer 1 has 1 name     “1”. The integer 2 has 2 names   “1+1”,   and   “2”. The integer 3 has 3 names   “1+1+1”,   “2+1”,   ...
#Raku
Raku
my @todo = $[1]; my @sums = 0; sub nextrow($n) { for +@todo .. $n -> $l { my $r = []; for reverse ^$l -> $x { my @x := @todo[$x]; if @x { $r.push: @sums[$x] += @x.shift; } else { $r.push: @sums[$x]; } ...
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 ≤...
#Bird
Bird
use Console Math   define Main $a Console.Read $b Console.Read Console.Println Math.Add $a $b end
http://rosettacode.org/wiki/Ackermann_function
Ackermann function
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree. The Ackermann function is usually defined as follows: A ( m , n ) = { n + 1 if  m = 0 A ( m ...
#SNUSP
SNUSP
/==!/==atoi=@@@-@-----# | | Ackermann function | | /=========\!==\!====\ recursion: $,@/>,@/==ack=!\?\<+# | | | A(0,j) -> j+1 j i \<?\+>-@/# | | A(i,0) -> A(i-1,1) \@\>@\->@/@\<-@/# A(i,j) -> A(i-1,A(i,j-1)) ...
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...
#Draco
Draco
\util.g   proc nonrec ucase(char c) char: byte b; b := pretend(c, byte); b := b & ~32; pretend(b, char) corp   proc nonrec can_make_word(*char w) bool: [41] char blocks; word i; char ch; bool found, ok;   CharsCopy(&blocks[0], "BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM");   ok :=...
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...
#AutoHotkey
AutoHotkey
NumOfTrials := 20000 randomFailTotal := 0, strategyFailTotal := 0 prisoners := [], drawers := [], Cards := [] loop, 100 prisoners[A_Index] := A_Index ; create prisoners , drawers[A_Index] := true ; create drawers   loop, % NumOfTrials { loop, 100 Cards[A_Index] := A_Index ; create cards for this iteration ...
http://rosettacode.org/wiki/Abundant_odd_numbers
Abundant odd numbers
An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n. E.G. 12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of ...
#Quackery
Quackery
[ 0 swap factors witheach + ] is sigmasum ( n --> n )   0 -1 [ 2 + dup sigmasum over 2 * over < iff [ over echo sp echo cr dip 1+ ] else drop over 25 = until ] 2drop cr 0 -1 [ 2 + dup sigmasum over 2 * > if [ dip 1+ ] ove...
http://rosettacode.org/wiki/21_game
21 game
21 game You are encouraged to solve this task according to the task description, using any language you may know. 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly ...
#JavaScript
JavaScript
<!DOCTYPE html><html lang="en">   <head> <meta charset="UTF-8"> <meta name="keywords" content="Game 21"> <meta name="description" content=" 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose...
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
#COBOL
COBOL
>>SOURCE FORMAT FREE *> This code is dedicated to the public domain *> This is GNUCobol 2.0 identification division. program-id. twentyfoursolve. environment division. configuration section. repository. function all intrinsic. input-output section. file-control. select count-file assign to count-fil...
http://rosettacode.org/wiki/4-rings_or_4-squares_puzzle
4-rings or 4-squares puzzle
4-rings or 4-squares puzzle You are encouraged to solve this task according to the task description, using any language you may know. Task Replace       a, b, c, d, e, f,   and   g       with the decimal digits   LOW   ───►   HIGH such that the sum of the letters inside of each of the four large squares add up to t...
#Lua
Lua
function valid(unique,needle,haystack) if unique then for _,value in pairs(haystack) do if needle == value then return false end end end return true end   function fourSquare(low,high,unique,prnt) count = 0 if prnt then 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 dow...
#ACL2
ACL2
PROC Bottles(BYTE i) IF i=0 THEN Print("No more") ELSE PrintB(i) FI Print(" bottle") IF i#1 THEN Print("s") FI RETURN   PROC Main() BYTE i=[99]   WHILE i>0 DO Bottles(i) PrintE(" of beer on the wall,") Bottles(i) PrintE(" of beer,") Print("Take ") IF i>1 THEN Prin...
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...
#C
C
#include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <setjmp.h> #include <time.h>   jmp_buf ctx; const char *msg;   enum { OP_NONE = 0, OP_NUM, OP_ADD, OP_SUB, OP_MUL, OP_DIV };   typedef struct expr_t *expr, expr_t; struct expr_t { int op, val, used; expr left, right; };   #define N_DIGITS 4 expr_t dig...