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/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#REXX
REXX
/*REXX program validates a user "word" against a "command table" with abbreviations.*/ parse arg uw /*obtain optional arguments from the CL*/ if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin' say 'user words: ' uw   @= 'Add ALTer BAckup...
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 ...
#C.2B.2B
C++
#include <algorithm> #include <iostream> #include <numeric> #include <sstream> #include <vector>   std::vector<int> divisors(int n) { std::vector<int> divs{ 1 }; std::vector<int> divs2;   for (int i = 2; i*i <= n; i++) { if (n%i == 0) { int j = n / i; divs.push_back(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”,   ...
#11l
11l
V cache = [[BigInt(1)]] F cumu(n) L(l) :cache.len .. n V r = [BigInt(0)] L(x) 1 .. l r.append(r.last + :cache[l - x][min(x, l - x)])  :cache.append(r) R :cache[n]   F row(n) V r = cumu(n) R (0 .< n).map(i -> @r[i + 1] - @r[i])   print(‘rows:’) L(x) 1..10 print(‘#2:’.format(x)‘ ’...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Logtalk
Logtalk
  :- protocol(datep).   :- public(today/3). :- public(leap_year/1). :- public(name_of_day/3). :- public(name_of_month/3). :- public(days_in_month/3).   :- end_protocol.  
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Lua
Lua
BaseClass = {}   function class ( baseClass ) local new_class = {} local class_mt = { __index = new_class }   function new_class:new() local newinst = {} setmetatable( newinst, class_mt ) return newinst end   if not baseClass then baseClass = BaseClass end setmetatabl...
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 ...
#Potion
Potion
ack = (m, n): if (m == 0): n + 1 . elsif (n == 0): ack(m - 1, 1) . else: ack(m - 1, ack(m, n - 1)). .   4 times(m): 7 times(n): ack(m, n) print " " print. "\n" print.
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...
#Erlang
Erlang
  -module(abbreviateweekdays). -export([ main/0 ]).     uniq(L,Acc) -> io:fwrite("Min = ~p",[Acc]), io:fwrite(" Abbr:~p~n",[ sets:to_list(L) ]).   uniq(_, L, Acc) -> Abbr = [string:substr(X,1,Acc) || X <- L], % list of abbrevs, starting with substring 1,1: TempSet = sets:from_list( Abbr ), Temp...
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...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program problemABC64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantes...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#REXX
REXX
/*REXX program validates a user "word" against a "command table" with abbreviations.*/ parse arg uw /*obtain optional arguments from the CL*/ if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin' say 'user words: ' uw   @= 'add 1 alter 3 b...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Ruby
Ruby
#!/usr/bin/env ruby   cmd_table = File.read(ARGV[0]).split user_str = File.read(ARGV[1]).split   user_str.each do |abbr| candidate = cmd_table.find do |cmd| cmd.count('A-Z') <= abbr.length && abbr.casecmp(cmd[0...abbr.length]).zero? end   print candidate.nil? ? '*error*' : candidate.upcase   print ' ' end  ...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Rust
Rust
use std::collections::HashMap;   fn main() { let commands = " Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy \ COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find \ NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POW...
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 ...
#CLU
CLU
% Integer square root isqrt = proc (s: int) returns (int) x0: int := s / 2 if x0 = 0 then return(s) else x1: int := (x0 + s/x0) / 2 while x1 < x0 do x0 := x1 x1 := (x0 + s/x0) / 2 end return(x0) end end isqrt   % Calculate aliquot sum (fo...
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”,   ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program integerName64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstante...
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”,   ...
#Ada
Ada
with Ada.Text_IO; with Ada.Numerics.Big_Numbers.Big_Integers;   procedure Names_Of_God is   NN  : constant := 100_000; Row_Count  : constant := 25; Max_Column : constant := 79;   package Triangle is procedure Print; end Triangle;   package Row_Summer is procedure Calc (N : Integer);...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#M2000_Interpreter
M2000 Interpreter
Class BaseState { Private:       x as double=1212, z1 as currency=1000, k$="ok"       Module Err {                   Module "Class.BaseState"                   Error "not implement yet"       }       } Class AbstractOne { Public:       Group z {             Value {                   Link parent z1 to z1                ...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
  (* Define an interface, Foo, which requires that the functions Foo, Bar, and Baz be defined *) InterfaceFooQ[obj_] := ValueQ[Foo[obj]] && ValueQ[Bar[obj]] && ValueQ[Baz[obj]]; PrintFoo[obj_] := Print["Object ", obj, " does not implement interface Foo."]; PrintFoo[obj_?InterfaceFooQ] := Print[ "Foo: ", Foo[obj], "\...
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 ...
#PowerBASIC
PowerBASIC
FUNCTION PBMAIN () AS LONG DIM m AS QUAD, n AS QUAD   m = ABS(VAL(INPUTBOX$("Enter a whole number."))) n = ABS(VAL(INPUTBOX$("Enter another whole number.")))   MSGBOX STR$(Ackermann(m, n)) END FUNCTION   FUNCTION Ackermann (m AS QUAD, n AS QUAD) AS QUAD IF 0 = m THEN FUNCTION = n + 1 ELS...
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...
#F.23
F#
  let fN g=let rec fN n=if g|>List.map(fun(g:string)->g.[0..n])|>Set.ofList|>Set.count=(List.length g) then (n+1) else fN(n+1) fN 0  
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...
#ABAP
ABAP
  REPORT z_rosetta_abc.   " Type declaration for blocks of letters TYPES: BEGIN OF block, s1 TYPE char1, s2 TYPE char1, END OF block,   blocks_table TYPE STANDARD TABLE OF block.   DATA: blocks TYPE blocks_table.   CLASS word_maker DEFINITION. PUBLIC SECTION. CLASS-METHODS: c...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Ruby
Ruby
str = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3 compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate 3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2 forward 2 get help 1 hexType 4 input 1 powerI...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Scala
Scala
  object Main extends App { implicit class StrOps(i: String) { def isAbbreviationOf(target: String): Boolean = { @scala.annotation.tailrec def checkPAsPrefixOfM(p: List[Char], m: List[Char]): Boolean = (p, m) match { case (Nil, _) => true //prefix empty ...
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 ...
#Common_Lisp
Common Lisp
;; * Loading the external libraries (eval-when (:compile-toplevel :load-toplevel) (ql:quickload '("cl-annot" "iterate" "alexandria")))   ;; * The package definition (defpackage :abundant-numbers (:use :common-lisp :cl-annot :iterate) (:import-from :alexandria :butlast)) (in-package :abundant-numbers)   (annot:ena...
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”,   ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program integerName.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/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#MATLAB
MATLAB
classdef (Abstract) AbsClass ... end
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Mercury
Mercury
:- module eq. :- interface.   :- typeclass eq(T) where [ pred (T::in) == (T::in) is semidet, pred (T::in) \= (T::in) is semidet ].   :- pred f(T::in) is semidet <= eq(T).   :- type foo ---> foo( x :: int, str :: string ).   :- instance eq(foo).   :- implementat...
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 ...
#PowerShell
PowerShell
function ackermann ([long] $m, [long] $n) { if ($m -eq 0) { return $n + 1 }   if ($n -eq 0) { return (ackermann ($m - 1) 1) }   return (ackermann ($m - 1) (ackermann $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...
#Factor
Factor
USING: formatting io io.encodings.utf8 io.files kernel math sequences sets splitting ; IN: rosetta-code.abbreviations-automatic   : map-head ( seq n -- seq' ) [ short head ] curry map ;   : unique? ( seq n -- ? ) map-head all-unique? ;   : (abbr-length) ( seq -- n ) 1 [ 2dup unique? ] [ 1 + ] until nip ;   : abbr-l...
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...
#Go
Go
package main   import( "bufio" "fmt" "os" "strings" )   func distinctStrings(strs []string) []string { len := len(strs) set := make(map[string]bool, len) distinct := make([]string, 0, len) for _, str := range strs { if !set[str] { distinct = append(distinct, 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...
#Action.21
Action!
DEFINE COUNT="20" CHAR ARRAY sideA="BXDCNGRTQFJHVAOEFLPZ" CHAR ARRAY sideB="OKQPATEGDSWUINBRSYCM" BYTE ARRAY used(COUNT)   BYTE FUNC ToUpper(BYTE c) IF c>='a AND c<='z THEN RETURN (c-'a+'A) FI RETURN (c)   BYTE FUNC CanBeUsed(CHAR c) BYTE i   FOR i=0 TO COUNT-1 DO IF used(i)=0 AND (sideA(i+1)=c OR sid...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Rust
Rust
use std::collections::HashMap;   // The plan here is to build a hashmap of all the commands keyed on the minimum number of // letters than can be provided in the input to match. For each known command it will appear // in a list of possible commands for a given string lengths. A command can therefore appear a // number...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Tcl
Tcl
  proc appendCmd {word} { # Procedure to append the correct command from the global list ::cmds # for the word given as parameter to the global list ::result. # If a matching word has been found and appended to ::result, this procedure # behaves like a "continue" statement, causing the loop containing it to #...
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 ...
#D
D
import std.stdio;   int[] divisors(int n) { import std.range;   int[] divs = [1]; int[] divs2;   for (int i = 2; i * i <= n; i++) { if (n % i == 0) { int j = n / i; divs ~= i; if (i != j) { divs2 ~= j; } } } divs ~= ...
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”,   ...
#AutoHotkey
AutoHotkey
SetBatchLines -1   InputBox, Enter_value, Enter the no. of lines sought array := [] Loop, % 2*Enter_value - 1 Loop, % x := A_Index y := A_Index, Array[x, y] := 1   x := 3   Loop { base_r := x - 1 , x++ , y := 2 , index := x , new := 1   Loop, % base_r - 1 { array[x, new+1] := array[x-1, new] + array[base_r,...
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤...
#0815
0815
|x|+%
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Nemerle
Nemerle
using System.Console;   namespace RosettaCode { abstract class Fruit { abstract public Eat() : void; abstract public Peel() : void;   virtual public Cut() : void // an abstract class con contain a mixture of abstract and implemented methods { /...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   -- ----------------------------------------------------------------------------- class RCAbstractType public final   method main(args = String[]) public constant   say ' Testing' RCAbstractType.class.getSimpleName say ' Creating an objec...
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 ...
#Processing
Processing
int ackermann(int m, int n) { if (m == 0) return n + 1; else if (m > 0 && n == 0) return ackermann(m - 1, 1); else return ackermann( m - 1, ackermann(m, n - 1) ); }   // Call function to produce output: // the first 4x7 Ackermann numbers void setup() { for (int m=0; m<4; m++) { for (int n=0; n<7...
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...
#Groovy
Groovy
class Abbreviations { static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("days_of_week.txt"), "utf-8")) List<String> readAllLines = br.readLines()   for (int i = 0; i < readAllLines.size(); i++) { ...
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...
#Acurity_Architect
Acurity Architect
Using #HASH-OFF
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Scala
Scala
  object Main extends App { implicit class StrOps(i: String) { def isAbbreviationOf(target: String, targetMinLength: Int): Boolean = { @scala.annotation.tailrec def checkPAsPrefixOfM(p: List[Char], m: List[Char]): Boolean = (p, m) match { case (Nil, _) => true //prefi...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#VBA
VBA
Private Function ValidateUserWords(userstring As String) As String Dim s As String Dim user_words() As String Dim command_table As Scripting.Dictionary Set command_table = New Scripting.Dictionary Dim abbreviations As Scripting.Dictionary Set abbreviations = New Scripting.Dictionary abbrevia...
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 ...
#Delphi
Delphi
program AbundantOddNumbers;   {$APPTYPE CONSOLE}   uses SysUtils;   function SumProperDivisors(const N: Cardinal): Cardinal; var I, J: Cardinal; begin Result := 1; I := 3; while I < Sqrt(N)+1 do begin if N mod I = 0 then begin J := N div I; Inc(Result, I); if I <> J then Inc(Result, J); ...
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”,   ...
#C
C
#include <stdio.h> #include <gmp.h>   #define N 100000 mpz_t p[N + 1];   void calc(int n) { mpz_init_set_ui(p[n], 0);   for (int k = 1; k <= n; k++) { int d = n - k * (3 * k - 1) / 2; if (d < 0) break;   if (k&1)mpz_add(p[n], p[n], p[d]); else mpz_sub(p[n], p[n], p[d]);   d -= k; if (d < 0) break;   if ...
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 ≤...
#11l
11l
print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#newLISP
newLISP
; file: abstract.lsp ; url: http://rosettacode.org/wiki/Abstract_type ; author: oofoe 2012-01-28   ; Abstract Shape Class   (new Class 'Shape) ; Derive new class.   (define (Shape:Shape ; Shape constructor. (pen "X")) ; Default value. (list (context) ; Assemble data packet. (list '...
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 ...
#Prolog
Prolog
:- table ack/3. % memoization reduces the execution time of ack(4,1,X) from several % minutes to about one second on a typical desktop computer. ack(0, N, Ans) :- Ans is N+1. ack(M, 0, Ans) :- M>0, X is M-1, ack(X, 1, Ans). ack(M, N, Ans) :- M>0, N>0, X is M-1, Y is N-1, ack(M, Y, Ans2), ack(X, Ans2, An...
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...
#Haskell
Haskell
import Data.List (inits, intercalate, transpose) import qualified Data.Set as S   --------------- MINIMUM ABBREVIATION LENGTH --------------   minAbbrevnLength :: [String] -> Int minAbbrevlnLength [] = 0 minAbbrevnLength xs = length . head . S.toList . head $ dropWhile ((< n) . S.size) $ S.fromList ...
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...
#Ada
Ada
Build with gnatchop abc.ada; gnatmake abc_problem
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#SNOBOL4
SNOBOL4
  * Program: abbr_simple.sbl * To run: sbl abbr_simple.sbl * Description: Abbreviations, simple * Comment: Tested using the Spitbol for Linux version of SNOBOL4   commands = + "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3 " + "compress 4 copy 2 count 3 Coverlay 3 cursor 3 d...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Vedit_macro_language
Vedit macro language
// Command table: Buf_Switch(#10=Buf_Free) Ins_Text(" Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput Join SPlit SPLTJOIN ...
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 ...
#F.23
F#
  // Abundant odd numbers. Nigel Galloway: August 1st., 2021 let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i)) let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g) a...
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”,   ...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq; using System.Numerics;   namespace NamesOfGod { public class RowSummer { const int N = 100000; public BigInteger[] p;   private void calc(int n) /* Translated from C */ { p[n] = 0;   ...
http://rosettacode.org/wiki/A%2BB
A+B
A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used. Task Given two integers,   A and B. Their sum needs to be calculated. Input data Two integers are written in the input stream, separated by space(s): ( − 1000 ≤...
#360_Assembly
360 Assembly
* A+B 29/08/2015 APLUSB CSECT USING APLUSB,R12 LR R12,R15 OPEN (MYDATA,INPUT) LOOP GET MYDATA,PG read a single record XDECI R4,PG input A, in register 4 XDECI R5,PG+12 input B, in register 5 ...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Nim
Nim
type Comparable = concept x, y (x < y) is bool   Stack[T] = concept s, var v s.pop() is T v.push(T)   s.len is Ordinal   for value in s: value is T
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Nit
Nit
# Task: abstract type # # Methods without implementation are annotated `abstract`. # # Abstract classes and interfaces can contain abstract methods and concrete (i.e. non-abstract) methods. # Abstract classes can also have attributes. module abstract_type   interface Inter fun method1: Int is abstract fun method2: In...
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 ...
#Pure
Pure
A 0 n = n+1; A m 0 = A (m-1) 1 if m > 0; A m n = A (m-1) (A m (n-1)) if m > 0 && n > 0;
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...
#J
J
NB. y is words in boxes abbreviation_length =: monad define N =. # y for_i. i. >: >./ #&> y do. NB. if the length of the set of length i prefixes matches the length of the row if. N -: # ~. i ({. &>) y do. i return. end. end. )   NB. use: auto_abbreviate DAY_NAMES auto_abbreviate =: 3 :0 y =. y -. CR line...
http://rosettacode.org/wiki/ABC_problem
ABC problem
ABC problem You are encouraged to solve this task according to the task description, using any language you may know. You are given a collection of ABC blocks   (maybe like the ones you had when you were a kid). There are twenty blocks with two letters on each block. A complete alphabet is guaranteed amongst all sid...
#ALGOL_68
ALGOL 68
# determine whether we can spell words with a set of blocks #   # construct the list of blocks # [][]STRING blocks = ( ( "B", "O" ), ( "X", "K" ), ( "D", "Q" ), ( "C", "P" ) , ( "N", "A" ), ( "G", "T" ), ( "R", "E" ), ( "T", "G" ) ...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Tcl
Tcl
proc appendCmd {word} { # Procedure to append the correct command from the global list ::cmds # for the word given as parameter to the global list ::result. # If a matching word has been found and appended to ::result, this procedure # behaves like a "continue" statement, causing the loop containing it to # j...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Vlang
Vlang
import encoding.utf8   fn validate(commands []string, words []string, min_len []int) []string { mut results := []string{} if words.len == 0 { return results } for word in words { mut match_found := false wlen := word.len for i, command in commands { if min_len...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Wren
Wren
import "/fmt" for Fmt import "/str" for Str   var table = "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy " + "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find " + "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput " + ...
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 ...
#Factor
Factor
USING: arrays formatting io kernel lists lists.lazy math math.primes.factors sequences tools.memory.private ; IN: rosetta-code.abundant-odd-numbers   : σ ( n -- sum ) divisors sum ; : abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ; : abundant-odds-from ( n -- list ) dup even? [ 1 + ] when [ 2 + ] lfrom-by [ abundant?...
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”,   ...
#C.2B.2B
C++
  // Calculate hypotenuse n of OTT assuming only nothingness, unity, and hyp[n-1] if n>1 // Nigel Galloway, May 6th., 2013 #include <gmpxx.h> int N{123456}; mpz_class hyp[N-3]; const mpz_class G(const int n,const int g){return g>n?0:(g==1 or n-g<2)?1:hyp[n-g-2];}; void G_hyp(const int n){for(int i=0;i<N-2*n-1;i++) n==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 ≤...
#8th
8th
gets dup . space eval n:+ . cr
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Oberon-2
Oberon-2
  TYPE Animal = POINTER TO AnimalDesc; AnimalDec = RECORD [ABSTRACT] END;   (* Cat inherits from Animal *) Cat = POINTER TO CatDesc; CatDesc = RECORD (AnimalDesc) END;  
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Objeck
Objeck
  class ClassA { method : virtual : public : MethodA() ~ Int;   method : public : MethodA() ~ Int { return 0; } }  
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 ...
#Pure_Data
Pure Data
  #N canvas 741 265 450 436 10; #X obj 83 111 t b l; #X obj 115 163 route 0; #X obj 115 185 + 1; #X obj 83 380 f; #X obj 161 186 swap; #X obj 161 228 route 0; #X obj 161 250 - 1; #X obj 161 208 pack; #X obj 115 314 t f f; #X msg 161 272 \$1 1; #X obj 115 142 t l; #X obj 207 250 swap; #X obj 273 271 - 1; #X obj 207 272 ...
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...
#Java
Java
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map;   public class Abbreviations { public static void main(String[] args) throws IOException { Path path = Paths.get("days_of_week...
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...
#ALGOL_W
ALGOL W
% determine whether we can spell words with a set of blocks  % begin  % Returns true if we can spell the word using the blocks,  %  % false otherwise  %  % As strings are fixed length in Algol W, the length of the string is  ...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#VBA
VBA
Private Function ValidateUserWords(userstring As String) As String Dim s As String Dim user_words() As String Dim command_table As Scripting.Dictionary Set command_table = New Scripting.Dictionary Dim abbreviations As Scripting.Dictionary Set abbreviations = New Scripting.Dictionary abbrevia...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#Yabasic
Yabasic
data "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy" data "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find" data "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput" data "Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPerc...
http://rosettacode.org/wiki/Abbreviations,_easy
Abbreviations, easy
This task is an easier (to code) variant of the Rosetta Code task:   Abbreviations, simple. For this task, the following   command table   will be used: Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find ...
#zkl
zkl
commands:=Data(0,String, // "Add\0ALTer\0..." #<<< "Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput Join SPlit SPLTJOIN LOAD Loca...
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 ...
#Fortran
Fortran
  program main use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 implicit none integer,parameter :: dp=kind(0.0d0) character(len=*),parameter :: g='(*(g0,1x))' integer :: j, icount integer,allocatable :: list(:) real(kind=dp) :: tally   write(*,*)'N su...
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...
#11l
11l
F foursquares(lo, hi, unique, show) V solutions = 0 L(c) lo .. hi L(d) lo .. hi I !unique | (c != d) V a = c + d I a >= lo & a <= hi I !unique | (c != 0 & d != 0) L(e) lo .. hi I !unique | (e !C (a, c, d)) ...
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”,   ...
#Clojure
Clojure
(defn nine-billion-names [row column] (cond (<= row 0) 0 (<= column 0) 0 (< row column) 0 (= row 1) 1  :else (let [addend (nine-billion-names (dec row) (dec column)) augend (nine-billion-names (- row column) column)] (+ addend augend))))   (defn print-ro...
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 ≤...
#8080_Assembly
8080 Assembly
dad b ; HL += BC (i.e., add BC reg pair to HL reg pair) dad d ; HL += DE dad h ; HL += HL (also known as "mul HL by two") dad sp ; HL += SP (actually the only way to get at SP at all)
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#OCaml
OCaml
class virtual foo = object method virtual bar : int end
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Oforth
Oforth
Property new: Spherical(r) Spherical method: radius @r ; Spherical method: setRadius  := r ; Spherical method: perimeter @r 2 * PI * ; Spherical method: surface @r sq PI * 4 * ;   Object Class new: Ballon(color) Ballon is: Spherical Ballon method: initialize(color, r) color := color self setRadius(r) ;   Object C...
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 ...
#PureBasic
PureBasic
Procedure.q Ackermann(m, n) If m = 0 ProcedureReturn n + 1 ElseIf n = 0 ProcedureReturn Ackermann(m - 1, 1) Else ProcedureReturn Ackermann(m - 1, Ackermann(m, n - 1)) EndIf EndProcedure   Debug Ackermann(3,4)
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...
#JavaScript
JavaScript
  Array.prototype.hasDoubles = function() { let arr = this.slice(); while (arr.length > 1) { let cur = arr.shift(); if (arr.includes(cur)) return true; } return false; }   function getMinAbbrLen(arr) { if (arr.length <= 1) return ''; let testArr = [], len = 0, i; do { len++; for (i =...
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...
#Apex
Apex
static Boolean canMakeWord(List<String> src_blocks, String word) { if (String.isEmpty(word)) { return true; }   List<String> blocks = new List<String>(); for (String block : src_blocks) { blocks.add(block.toUpperCase()); }   for (Integer i = 0; i < word.length(); i++) { I...
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Vlang
Vlang
import encoding.utf8 import strconv fn read_table(table string) ([]string, []int) { fields := table.fields() mut commands := []string{} mut min_lens := []int{}   for i, max := 0, fields.len; i < max; { cmd := fields[i] mut cmd_len := cmd.len i++   if i < max { ...
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 ...
#FreeBASIC
FreeBASIC
  Declare Function SumaDivisores(n As Integer) As Integer   Dim numimpar As Integer = 1 Dim contar As Integer = 0 Dim sumaDiv As Integer = 0   Function SumaDivisores(n As Integer) As Integer ' Devuelve la suma de los divisores propios de n Dim suma As Integer = 1 Dim As Integer d, otroD   For d = 2 To C...
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...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program square4_64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM...
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”,   ...
#Common_Lisp
Common Lisp
(defun 9-billion-names (row column) (cond ((<= row 0) 0) ((<= column 0) 0) ((< row column) 0) ((equal row 1) 1) (t (let ((addend (9-billion-names (1- row) (1- column))) (augend (9-billion-names (- row column) column))) (+ addend augend)))))   (defun 9-billion-names-triangle (rows) (loop for row ...
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 ≤...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program addAetB.s */   /*******************************************/ /* Constantes */ /*******************************************/ .equ STDOUT, 1 // linux output .equ WRITE, 64 // call system Linux 64 bits .e...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#ooRexx
ooRexx
-- Example showing a class that defines an interface in ooRexx -- shape is the interface class that defines the methods a shape instance -- is expected to implement as abstract methods. Instances of the shape -- class need not directly subclass the interface, but can use multiple -- inheritance to mark itsel...
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 ...
#Purity
Purity
data Iter = f => FoldNat <const $f One, $f> data Ackermann = FoldNat <const Succ, Iter>
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...
#Julia
Julia
const text = """ Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë Ehud Segno Maksegno Erob Hamus Arbe Kedame Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit Guiragui Yerg...
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...
#APL
APL
abc←{{0=⍴⍵:1 ⋄ 0=⍴h←⊃⍵:0 ⋄ ∇(t←1↓⍵)~¨⊃h:1 ⋄ ∇(⊂1↓h),t}⍸¨↓⍵∘.∊⍺}
http://rosettacode.org/wiki/Abbreviations,_simple
Abbreviations, simple
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. For this task, the following   command table   will be used: add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 ...
#Wren
Wren
import "/fmt" for Fmt import "/str" for Str   var table = "add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3 " + "compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate " + "3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2...
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 ...
#Frink
Frink
isAbundantOdd[n] := sum[allFactors[n, true, false]] > n   n = 3 count = 0   println["The first 25 abundant odd numbers:"] do { if isAbundantOdd[n] { println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]] count = count + 1 }   n = n + 2 } while count < 25     println["\nThe thousandth ...
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...
#Ada
Ada
with Ada.Text_IO;   procedure Puzzle_Square_4 is   procedure Four_Rings (Low, High : in Natural; Unique, Show : in Boolean) is subtype Test_Range is Natural range Low .. High;   type Value_List is array (Positive range <>) of Natural; function Is_Unique (Values : Value_List) return Boolean is ...
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”,   ...
#Crystal
Crystal
def g(n, g) return 1 unless 1 < g && g < n-1 (2..g).reduce(1){ |res, q| res + (q > n-g ? 0 : g(n-g, q)) } end   (1..25).each { |n| puts (1..n).map { |g| "%4s" % g(n, g) }.join }
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 ≤...
#ABAP
ABAP
report z_sum_a_b. data: lv_output type i. selection-screen begin of block input. parameters: p_first type i, p_second type i. selection-screen end of block input.   at selection-screen output. %_p_first_%_app_%-text = 'First Number: '. %_p_second_%_app_%-text = 'Second Number: '.   start-of-selection. ...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#OxygenBasic
OxygenBasic
'ABSTRACT TYPES EXAMPLE 'PARTICLES type position {} type angle {} type velocity {} type mass {} type counter {} type particle position p angle a velocity v mass m end type class particles particle*q counter c method constructor (){} method destructor (){} method action (){} en...
http://rosettacode.org/wiki/Abstract_type
Abstract type
Abstract type is a type without instances or without definition. For example in object-oriented programming using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract ...
#Oz
Oz
declare class BaseQueue attr contents:nil   meth init raise notImplemented(self init) end end   meth enqueue(Item) raise notImplemented(self enqueue) end end   meth dequeue(?Item) raise notImplemented(self dequeue) end end   meth printContents ...
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 ...
#Python
Python
def ack1(M, N): return (N + 1) if M == 0 else ( ack1(M-1, 1) if N == 0 else ack1(M-1, ack1(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...
#Kotlin
Kotlin
// version 1.1.4-3   import java.io.File   val r = Regex("[ ]+")   fun main(args: Array<String>) { val lines = File("days_of_week.txt").readLines() for ((i, line) in lines.withIndex()) { if (line.trim().isEmpty()) { println() continue } val days = line.trim().spli...
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...
#AppleScript
AppleScript
set blocks to {"bo", "xk", "dq", "cp", "na", "gt", "re", "tg", "qd", "fs", ¬ "jw", "hu", "vi", "an", "ob", "er", "fs", "ly", "pc", "zm"}   canMakeWordWithBlocks("a", blocks) canMakeWordWithBlocks("bark", blocks) canMakeWordWithBlocks("book", blocks) canMakeWordWithBlocks("treat", blocks) canMakeWordWithBlocks("comm...