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/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#F.C5.8Drmul.C3.A6
Fōrmulæ
originalMatrix := [[1, 1, 1, 1], [2, 4, 8, 16], [3, 9, 27, 81], [4, 16, 64, 256], [5, 25, 125, 625]]; transposedMatrix := TransposedMat(originalMatrix);
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Phix
Phix
with javascript_semantics -- -- grid is eg for w=3,h=2: {"+---+---+---+", -- ("wall") -- "| ? | ? | ? |", -- ("cell") -- "+---+---+---+", -- ("wall") -- "| ? | ? | ? |", -- ("cell") -- "+---+---+---+", -- ...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Phix
Phix
with javascript_semantics function map_range(atom s, a1, a2, b1, b2) return b1+(s-a1)*(b2-b1)/(a2-a1) end function for i=0 to 10 by 2 do printf(1,"%2d : %g\n",{i,map_range(i,0,10,-1,0)}) end for
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#PicoLisp
PicoLisp
(scl 1)   (de mapRange (Val A1 A2 B1 B2) (+ B1 (*/ (- Val A1) (- B2 B1) (- A2 A1))) )     (for Val (range 0 10.0 1.0) (prinl (format (mapRange Val 0 10.0 -1.0 0) *Scl) ) )
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Octave
Octave
s = "The quick brown fox jumped over the lazy dog's back"; hash = md5sum(s, true); disp(hash)
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Emacs_Lisp
Emacs Lisp
; === Mandelbrot ============================================   (setq mandel-size (cons 76 34)) (setq xmin -2) (setq xmax .5) (setq ymin -1.2) (setq ymax 1.2) (setq max-iter 20)   (defun mandel-iter-point (x y) "Run the actual iteration for each point." (let ((xp 0) (yp 0) (it 0) (xt 0)) ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Pascal
Pascal
PROGRAM magic; (* Magic squares of odd order *) CONST n=9; VAR i,j :INTEGER; BEGIN (*magic*) WRITELN('The square order is: ',n); FOR i:=1 TO n DO BEGIN FOR j:=1 TO n DO WRITE((i*2-j+n-1) MOD n*n + (i*2+j-2) MOD n+1:5); WRITELN END; WRITELN('The magic number is: ',n*(n*n+1) DIV 2) END (*magic...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#GAP
GAP
# Built-in A := [[1, 2], [3, 4], [5, 6], [7, 8]]; B := [[1, 2, 3], [4, 5, 6]];   PrintArray(A); # [ [ 1, 2 ], # [ 3, 4 ], # [ 5, 6 ], # [ 7, 8 ] ]   PrintArray(B); # [ [ 1, 2, 3 ], # [ 4, 5, 6 ] ]   PrintArray(A * B); # [ [ 9, 12, 15 ], # [ 19, 26, 33 ], # [ 29, 40, 51 ], # ...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#PHP
PHP
<?php function A($k,$x1,$x2,$x3,$x4,$x5) { $b = function () use (&$b,&$k,$x1,$x2,$x3,$x4) { return A(--$k,$b,$x1,$x2,$x3,$x4); }; return $k <= 0 ? $x4() + $x5() : $b(); }   echo A(10, function () { return 1; }, function () { return -1; }, function () { return -1; }, ...
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#GAP
GAP
originalMatrix := [[1, 1, 1, 1], [2, 4, 8, 16], [3, 9, 27, 81], [4, 16, 64, 256], [5, 25, 125, 625]]; transposedMatrix := TransposedMat(originalMatrix);
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#PHP
PHP
<?php class Maze { protected $width; protected $height; protected $grid; protected $path; protected $horWalls; protected $vertWalls; protected $dirs; protected $isDebug;   public function __construct($x, $y, $debug = false) { $this->width = $x; $this->height = $y...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#PL.2FI
PL/I
  map: procedure options (main); /* 24/11/2011 */ declare (a1, a2, b1, b2) float; declare d fixed decimal (3,1);   do d = 0 to 10 by 0.9, 10; put skip edit ( d, ' maps to ', map(0, 10, -1, 0, d) ) (f(5,1), a, f(10,6)); end;   map: procedure (a1, a2, b1, b2, s) returns (float); declare (a1, a2, b1, ...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Ol
Ol
  (import (otus ffi)) (define libcrypto (load-dynamic-library "libcrypto.so.1.0.0")) (define MD5 (libcrypto type-vptr "MD5" type-string fft-unsigned-long type-string))  
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Erlang
Erlang
  -module(mandelbrot).   -export([test/0]).   magnitude(Z) -> R = complex:real(Z), I = complex:imaginary(Z), R * R + I * I.   mandelbrot(A, MaxI, Z, I) -> case (I < MaxI) and (magnitude(Z) < 2.0) of true -> NZ = complex:add(complex:mult(Z, Z), A), mandelbrot(A, MaxI, NZ, I + 1)...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Perl
Perl
 
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Phix
Phix
with javascript_semantics function magic_square(integer n) if mod(n,2)!=1 or n<1 then return false end if sequence square = repeat(repeat(0,n),n) for i=1 to n do for j=1 to n do square[i,j] = n*mod(2*i-j+n-1,n) + mod(2*i+j-2,n) + 1 end for end for return square end functi...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Generic
Generic
  generic coordinaat { ecs uuii   coordinaat() { ecs=+a uuii=+a}   coordinaat(ecs_set uuii_set) { ecs = ecs_set uuii=uuii_set }   operaator<(c) { iph ecs < c.ecs return troo iph c.ecs < ecs return phals iph uuii < c.uuii return troo return phals }   operaator==(connpair) // eecuuols and not eecuuols...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#PicoLisp
PicoLisp
(de a (K X1 X2 X3 X4 X5) (let (@K (cons K) B (cons)) # Explicit frame (set B (curry (@K B X1 X2 X3 X4) () (a (dec @K) (car B) X1 X2 X3 X4) ) ) (if (gt0 (car @K)) ((car B)) (+ (X4) (X5))) ) )   (a 10 '(() 1) '(() -1) '(() -1) '(() 1) '(() 0))
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#PL.2FI
PL/I
morb: proc options (main) reorder; dcl sysprint file; put skip list(a((10), lambda1, lambdam1, lambdam1, lambda0, lambda0)); a: proc(k, x1, x2, x3, x4, x5) returns(fixed bin (31)) recursive; dcl k fixed bin (31); dcl (x1, x2, x3, x4, x5) entry returns(fixed bin (31)); b: proc returns(f...
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Go
Go
package main   import ( "fmt"   "gonum.org/v1/gonum/mat" )   func main() { m := mat.NewDense(2, 3, []float64{ 1, 2, 3, 4, 5, 6, }) fmt.Println(mat.Formatted(m)) fmt.Println() fmt.Println(mat.Formatted(m.T())) }
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Picat
Picat
main => gen_maze(8,8).   main([RStr,CStr]) => MaxR = to_int(RStr), MaxC = to_int(CStr), gen_maze(MaxR,MaxC).   gen_maze(MaxR,MaxC) => Maze = new_array(MaxR,MaxC), foreach (R in 1..MaxR, C in 1..MaxC) Maze[R,C] = 0 end, gen_maze(Maze,MaxR,MaxC,1,1), display_maze(Maze,MaxR,MaxC...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#PowerShell
PowerShell
  function Group-Range { [CmdletBinding()] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, Position=0)] [ValidateCount(2,2)] [double[]] $Range1,   [Parameter(Mandatory=$true, Position=1)] [ValidateCo...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#OpenEdge.2FProgress
OpenEdge/Progress
MESSAGE 1 STRING( HEX-ENCODE( MD5-DIGEST( "" ) ) ) SKIP 2 STRING( HEX-ENCODE( MD5-DIGEST( "a" ) ) ) SKIP 3 STRING( HEX-ENCODE( MD5-DIGEST( "abc" ) ) ) SKIP 4 STRING( HEX-ENCODE( MD5-DIGEST( "message digest" ) ) ) SKIP 5 STRING( HEX-ENCODE( MD5-DIGEST( "abcdefghijklmnopqrstuvwxyz" ) ) ) SKIP 6 STRING(...
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#ERRE
ERRE
  PROGRAM MANDELBROT   !$KEY !$INCLUDE="PC.LIB"   BEGIN   SCREEN(7) GR_WINDOW(-2,1.5,2,-1.5) FOR X0=-2 TO 2 STEP 0.01 DO FOR Y0=-1.5 TO 1.5 STEP 0.01 DO X=0 Y=0   ITERATION=0 MAX_ITERATION=223   WHILE (X*X+Y*Y<=(2*2) AND ITERATION<MAX_ITERATION) DO X_TEMP=X*X-Y*Y+...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Picat
Picat
import util.   go => foreach(N in [3,5,17]) M=magic_square(N), print_matrix(M), check(M), nl end, nl.   % % Not as nice as the J solution. % But I like the chaining of the functions. % magic_square(N) = MS => if N mod 2 = 0 then printf("N (%d) is not odd!\n", N), halt end, R = mak...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#PicoLisp
PicoLisp
(load "@lib/simul.l") (de magic (A) (let (Grid (grid A A T T) Sum (/ (* A (inc (** A 2))) 2)) (println 'N A 'Sum Sum) # cut one important edge (with (last (last Grid)) (con (: 0 1))) (with (get Grid (inc (/ A 2)) A) (for N (* A A) (=: V N) (setq...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Go
Go
package main   import ( "fmt"   "gonum.org/v1/gonum/mat" )   func main() { a := mat.NewDense(2, 4, []float64{ 1, 2, 3, 4, 5, 6, 7, 8, }) b := mat.NewDense(4, 3, []float64{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, }) var m mat.Dense m.Mul(a, b...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Pop11
Pop11
define A(k, x1, x2, x3, x4, x5); define B(); k - 1 -> k; A(k, B, x1, x2, x3, x4) enddefine; if k <= 0 then x4() + x5() else B() endif enddefine; define one(); 1 enddefine; define minus_one(); -1 enddefine; define zero(); 0 enddefine; A(10, one, minus_one, minus_one, ...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Python
Python
#!/usr/bin/env python import sys sys.setrecursionlimit(1025)   def a(in_k, x1, x2, x3, x4, x5): k = [in_k] def b(): k[0] -= 1 return a(k[0], b, x1, x2, x3, x4) return x4() + x5() if k[0] <= 0 else b()   x = lambda i: lambda: i print(a(10, x(1), x(-1), x(-1), x(1), x(0)))  
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Groovy
Groovy
def matrix = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ]   matrix.each { println it } println() def transpose = matrix.transpose()   transpose.each { println it }
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#PicoLisp
PicoLisp
(load "@lib/simul.l")   (de maze (DX DY) (let Maze (grid DX DY) (let Fld (get Maze (rand 1 DX) (rand 1 DY)) (recur (Fld) (for Dir (shuffle '((west . east) (east . west) (south . north) (north . south))) (with ((car Dir) Fld) (unless (or (: west) (: east) (:...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#PureBasic
PureBasic
Structure RR a.f b.f EndStructure   Procedure.f MapRange(*a.RR, *b.RR, s) Protected.f a1, a2, b1, b2 a1=*a\a: a2=*a\b b1=*b\a: b2=*b\b ProcedureReturn b1 + ((s - a1) * (b2 - b1) / (a2 - a1)) EndProcedure     ;- Test the function If OpenConsole() Define.RR Range1, Range2 Range1\a=0: Range1\b=10 Rang...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Python
Python
>>> def maprange( a, b, s): (a1, a2), (b1, b2) = a, b return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))   >>> for s in range(11): print("%2g maps to %g" % (s, maprange( (0, 10), (-1, 0), s)))     0 maps to -1 1 maps to -0.9 2 maps to -0.8 3 maps to -0.7 4 maps to -0.6 5 maps to -0.5 6 maps to -0.4 7 maps to -0...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#PARI.2FGP
PARI/GP
#include <pari/pari.h> #include <openssl/md5.h>   #define HEX(x) (((x) < 10)? (x)+'0': (x)-10+'a')   /* * PARI/GP func: MD5 hash * * gp code: install("plug_md5", "s", "MD5", "<library path>"); */ GEN plug_md5(char *text) { char md[MD5_DIGEST_LENGTH]; char hash[sizeof(md) * 2 + 1]; int i;   MD5((unsigned ch...
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#F.23
F#
open System.Drawing open System.Windows.Forms type Complex = { re : float; im : float } let cplus (x:Complex) (y:Complex) : Complex = { re = x.re + y.re; im = x.im + y.im } let cmult (x:Complex) (y:Complex) : Complex = { re = x.re * y.re - x.im * y.im; ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#PL.2FI
PL/I
magic: procedure options (main); /* 18 April 2014 */ declare n fixed binary;   put skip list ('What is the order of the magic square?'); get list (n); if n < 3 | iand(n, 1) = 0 then do; put skip list ('The value is out of range'); stop; end; put skip list ('The order is ' || trim(n));   begin; ...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Groovy
Groovy
def assertConformable = { a, b -> assert a instanceof List assert b instanceof List assert a.every { it instanceof List && it.size() == b.size() } assert b.every { it instanceof List && it.size() == b[0].size() } }   def matmulWOIL = { a, b -> assertConformable(a, b)   def bt = b.transpose() ...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#R
R
n <- function(x) function()x   A <- function(k, x1, x2, x3, x4, x5) { B <- function() A(k <<- k-1, B, x1, x2, x3, x4) if (k <= 0) x4() + x5() else B() }   A(10, n(1), n(-1), n(-1), n(1), n(0))
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Racket
Racket
#lang racket   (define (A k x1 x2 x3 x4 x5) (define (B) (set! k (- k 1)) (A k B x1 x2 x3 x4)) (if (<= k 0) (+ (x4) (x5)) (B)))   (A 10 (lambda () 1) (lambda () -1) (lambda () -1) (lambda () 1) (lambda () 0))
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Haskell
Haskell
*Main> transpose [[1,2],[3,4],[5,6]] [[1,3,5],[2,4,6]]
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#PL.2FI
PL/I
*process source attributes xref or(!); mgg: Proc Options(main); /* REXX *************************************************************** * 04.09.2013 Walter Pachl translated from REXX version 3 **********************************************************************/ Dcl (MIN,MOD,RANDOM,REPEAT,SUBSTR) Builtin; Dcl S...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#R
R
tRange <- function(aRange, bRange, s) { #Guard clauses. We could write some proper error messages, but this is all we really need. stopifnot(length(aRange) == 2, length(bRange) == 2, is.numeric(aRange), is.numeric(bRange), is.numeric(s), s >= aRange[1], s <= aRange[2]) bRange[1] + ((s - aR...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Pascal
Pascal
  program GetMd5;   uses md5;   var strEncrypted : string;   begin strEncrypted := md5Print(md5String('The quick brown fox jumped over the lazy dog''s back')); writeln(strEncrypted); end.  
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Factor
Factor
  ! with ("::") or without (":") generalizations: ! : [a..b] ( steps a b -- a..b ) 2dup swap - 4 nrot 1 - / <range> ; :: [a..b] ( steps a b -- a..b ) a b b a - steps 1 - / <range> ;   : >char ( n -- c ) dup -1 = [ drop 32 ] [ 26 mod CHAR: a + ] if ;   ! iterates z' = z^2 + c, Factor does complex numbers! : iter ( ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#PureBasic
PureBasic
#N=9 Define.i i,j   If OpenConsole("Magic squares") PrintN("The square order is: "+Str(#N)) For i=1 To #N For j=1 To #N Print(RSet(Str((i*2-j+#N-1) % #N*#N + (i*2+j-2) % #N+1),5)) Next PrintN("") Next PrintN("The magic number is: "+Str(#N*(#N*#N+1)/2)) EndIf Input()
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Haskell
Haskell
import Data.List   mmult :: Num a => [[a]] -> [[a]] -> [[a]] mmult a b = [ [ sum $ zipWith (*) ar bc | bc <- (transpose b) ] | ar <- a ]   -- Example use: test = [[1, 2], [3, 4]] `mmult` [[-3, -8, 3], [-2, 1, 4]]
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Raku
Raku
sub A($k is copy, &x1, &x2, &x3, &x4, &x5) { $k <= 0 ?? x4() + x5() !! (my &B = { A(--$k, &B, &x1, &x2, &x3, &x4) })(); };   say A(10, {1}, {-1}, {-1}, {1}, {0});
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Haxe
Haxe
class Matrix { static function main() { var m = [ [1, 1, 1, 1], [2, 4, 8, 16], [3, 9, 27, 81], [4, 16, 64, 256], [5, 25, 125, 625] ]; var t = [ for (i in 0...m[0].length) [ for (j in 0...m.leng...
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Processing
Processing
int g_size = 10; color background_color = color (80, 80, 220); color runner = color (255, 50, 50); color visited_color = color(220, 240, 240); color done_color = color (100, 160, 250); int c_size;   Cell[][] cell; ArrayList<Cell> done = new ArrayList<Cell>(); ArrayList<Cell> visit = new ArrayList<Cell>(); Cell run_cell...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Racket
Racket
  #lang racket   (define (make-range-map a1 a2 b1 b2)  ;; returns a mapping function, doing computing the differences in  ;; advance so it's fast (let ([a (- a2 a1)] [b (- b2 b1)]) (λ(s) (exact->inexact (+ b1 (/ (* (- s a1) b) a))))))   (define map (make-range-map 0 10 -1 0)) (for ([i (in-range 0 11)]) (printf ...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Raku
Raku
sub getmapper(Range $a, Range $b) { my ($a1, $a2) = $a.bounds; my ($b1, $b2) = $b.bounds; return -> $s { $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1)) } }   my &mapper = getmapper(0 .. 10, -1 .. 0); for ^11 -> $x {say "$x maps to &mapper($x)"}
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Perl
Perl
use Digest::MD5 qw(md5_hex);   print md5_hex("The quick brown fox jumped over the lazy dog's back"), "\n";
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Fennel
Fennel
  #!/usr/bin/env fennel   (fn mandelzahl [cr ci max i tr ti tr2 ti2] "Calculates the Mandelbrot escape number of a complex point c" (if (>= i max) -1 (>= (+ tr2 ti2) 4) i (let [(tr ti) (values (+ (- tr2 ti2) cr) (+ (* tr ti 2) ci))] (mandelzahl cr ci max (+ i...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Python
Python
>>> def magic(n): for row in range(1, n + 1): print(' '.join('%*i' % (len(str(n**2)), cell) for cell in (n * ((row + col - 1 + n // 2) % n) + ((row + 2 * col - 2) % n) + 1 for col in range(1, n + 1)))) print('\nAll sum to magic number ...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#HicEst
HicEst
REAL :: m=4, n=2, p=3, a(m,n), b(n,p), res(m,p)   a = $ ! initialize to 1, 2, ..., m*n b = $ ! initialize to 1, 2, ..., n*p   res = 0 DO i = 1, m DO j = 1, p DO k = 1, n res(i,j) = res(i,j) + a(i,k) * b(k,j) ENDDO ENDDO ENDDO   DLG(DefWidth=4, Text=a, Text=b,Y=0, Text=res,Y=0)
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#REXX
REXX
/*REXX program performs the "man or boy" test as far as possible for N. */ do n=0 /*increment N from zero forever. */ say 'n='n a(N,x1,x2,x3,x4,x5) /*display the result to the terminal. */ end /*n*/ ...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Ruby
Ruby
def a(k, x1, x2, x3, x4, x5) b = lambda { k -= 1; a(k, b, x1, x2, x3, x4) } k <= 0 ? x4[] + x5[] : b[] end   puts a(10, lambda {1}, lambda {-1}, lambda {-1}, lambda {1}, lambda {0})
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#HicEst
HicEst
REAL :: mtx(2, 4)   mtx = 1.1 * $ WRITE() mtx   SOLVE(Matrix=mtx, Transpose=mtx) WRITE() mtx
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Prolog
Prolog
:- dynamic cell/2.   maze(Lig,Col) :- retractall(cell(_,_)),   new(D, window('Maze')),   % creation of the grid forall(between(0,Lig, I), (XL is 50, YL is I * 30 + 50, XR is Col * 30 + 50, new(L, line(XL, YL, XR, YL)), send(D, display, L))),   forall(between(0,Col, I), (XT is 50 + I * 30, Y...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#ReScript
ReScript
let map_range = ((a1, a2), (b1, b2), s) => { b1 +. ((s -. a1) *. (b2 -. b1) /. (a2 -. a1)) }   Js.log("Mapping [0,10] to [-1,0] at intervals of 1:")   for i in 0 to 10 { Js.log("f(" ++ Js.String.make(i) ++ ") = " ++ Js.String.make(map_range((0.0, 10.0), (-1.0, 0.0), float(i)))) }
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#REXX
REXX
/*REXX program maps and displays a range of numbers from one range to another range.*/ rangeA = 0 10 /*or: rangeA = ' 0 10 ' */ rangeB = -1 0 /*or: rangeB = " -1 0 " */ parse var rangeA L H inc= 1 do j...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Phix
Phix
$string = "The quick brown fox jumped over the lazy dog's back"; echo md5( $string );
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#FOCAL
FOCAL
1.1 S I1=-1.2; S I2=1.2; S R1=-2; S R2=.5 1.2 S MIT=30 1.3 F Y=1,24; D 2 1.4 Q   2.1 T ! 2.2 F X=1,70; D 3   3.1 S R=X*(R2-R1)/70+R1 3.2 S I=Y*(I2-I1)/24+I1 3.3 S C1=R; S C2=I 3.4 F T=1,MIT; D 4   4.1 S C3=C1 4.2 S C1=C1*C1 - C2*C2 4.3 S C2=C3*C2 + C2*C3 4.4 S C1=C1+R 4.5 S C2=C2+I 4.6 I (-FABS(C1)+2)5.1 4.7 I (-FABS(C...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#QB64
QB64
_Title "Magic Squares of Odd Order" '$Dynamic DefLng A-Z Dim Shared As Long m(1, 1)   Call magicSquare(5) Call magicSquare(15)   Sleep System   Sub magicSquare (n As Integer) Dim As Integer inc, count, row, col   If (n < 3) Or (n And 1) <> 1 Then n = 3 ReDim m(n, n) inc = 1 count = 1 row = 1 ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#R
R
> magic(5) [,1] [,2] [,3] [,4] [,5] [1,] 17 24 1 8 15 [2,] 23 5 7 14 16 [3,] 4 6 13 20 22 [4,] 10 12 19 21 3 [5,] 11 18 25 2 9
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Icon_and_Unicon
Icon and Unicon
  link matrix   procedure main () m1 := [[1,2,3], [4,5,6]] m2 := [[1,2],[3,4],[5,6]] m3 := mult_matrix (m1, m2) write ("Multiply:") write_matrix ("", m1) # first argument is filename, or "" for stdout write ("by:") write_matrix ("", m2) write ("Result: ") write_matrix ("", m3) end  
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Rust
Rust
use std::cell::Cell;   trait Arg { fn run(&self) -> i32; }   impl Arg for i32 { fn run(&self) -> i32 { *self } }   struct B<'a> { k: &'a Cell<i32>, x1: &'a Arg, x2: &'a Arg, x3: &'a Arg, x4: &'a Arg, }   impl<'a> Arg for B<'a> { fn run(&self) -> i32 { self.k.set(self.k.get() - 1)...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Scala
Scala
def A(in_k: Int, x1: =>Int, x2: =>Int, x3: =>Int, x4: =>Int, x5: =>Int): Int = { var k = in_k def B: Int = { k = k-1 A(k, B, x1, x2, x3, x4) } if (k<=0) x4+x5 else B } println(A(10, 1, -1, -1, 1, 0))
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Hope
Hope
uses lists; dec transpose : list (list alpha) -> list (list alpha); --- transpose ([]::_) <= []; --- transpose n <= map head n :: transpose (map tail n);
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#PureBasic
PureBasic
Enumeration ;indexes for types of offsets from maze coordinates (x,y) #visited ;used to index visited(x,y) in a given direction from current maze cell #maze ;used to index maze() in a given direction from current maze cell #wall ;used to index walls in maze() in a given direction from current maze cell ...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Ring
Ring
  # Project : Map range   decimals(1) al = 0 ah = 10 bl = -1 bh = 0 for n = 0 to 10 see "" + n + " maps to " + maprange(al, bl, n) + nl next   func maprange(al, bl, s) return bl + (s - al) * (bh - bl) / (ah - al)  
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Ruby
Ruby
def map_range(a, b, s) af, al, bf, bl = a.first, a.last, b.first, b.last bf + (s - af)*(bl - bf).quo(al - af) end   (0..10).each{|s| puts "%s maps to %g" % [s, map_range(0..10, -1..0, s)]}
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#PHP
PHP
$string = "The quick brown fox jumped over the lazy dog's back"; echo md5( $string );
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Forth
Forth
500 value max-iter   : mandel ( gmp F: imin imax rmin rmax -- ) 0e 0e { F: imin F: imax F: rmin F: rmax F: Zr F: Zi } dup bheight 0 do i s>f dup bheight s>f f/ imax imin f- f* imin f+ TO Zi dup bwidth 0 do i s>f dup bwidth s>f f/ rmax rmin f- f* rmin f+ TO Zr Zr Zi max-iter begin 1- dup ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Racket
Racket
#lang racket ;; Using "helpful formulae" in: ;; http://en.wikipedia.org/wiki/Magic_square#Method_for_constructing_a_magic_square_of_odd_order (define (squares n) n)   (define (last-no n) (sqr n))   (define (middle-no n) (/ (add1 (sqr n)) 2))   (define (M n) (* n (middle-no n)))   (define ((Ith-row-Jth-col n) I J) (+ ...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Raku
Raku
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 The magic number is 65
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#IDL
IDL
result = arr1 # arr2
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Scheme
Scheme
(define (A k x1 x2 x3 x4 x5) (define (B) (set! k (- k 1)) (A k B x1 x2 x3 x4)) (if (<= k 0) (+ (x4) (x5)) (B)))   (A 10 (lambda () 1) (lambda () -1) (lambda () -1) (lambda () 1) (lambda () 0))
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Sidef
Sidef
func a(k, x1, x2, x3, x4, x5) { func b { a(--k, b, x1, x2, x3, x4) }; k <= 0 ? (x4() + x5()) : b(); } say a(10, ->{1}, ->{-1}, ->{-1}, ->{1}, ->{0}); #=> -67
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#Icon_and_Unicon
Icon and Unicon
procedure transpose_matrix (matrix) result := [] # for each column every (i := 1 to *matrix[1]) do { col := [] # extract the number in each row for that column every (row := !matrix) do put (col, row[i]) # and push that column as a row in the result matrix put (result, col) } return resul...
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Python
Python
from random import shuffle, randrange   def make_maze(w = 16, h = 8): vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)] ver = [["| "] * w + ['|'] for _ in range(h)] + [[]] hor = [["+--"] * w + ['+'] for _ in range(h + 1)]   def walk(x, y): vis[y][x] = 1   d = [(x - 1, y), (x, y ...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Rust
Rust
use std::ops::{Add, Sub, Mul, Div};   fn map_range<T: Copy>(from_range: (T, T), to_range: (T, T), s: T) -> T where T: Add<T, Output=T> + Sub<T, Output=T> + Mul<T, Output=T> + Div<T, Output=T> { to_range.0 + (s - from_range.0) * (to_range.1 - to_range.0) / (from_range.1 - ...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Scala
Scala
def mapRange(a1:Double, a2:Double, b1:Double, b2:Double, x:Double):Double=b1+(x-a1)*(b2-b1)/(a2-a1)   for(i <- 0 to 10) println("%2d in [0, 10] maps to %5.2f in [-1, 0]".format(i, mapRange(0,10, -1,0, i)))
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#PicoLisp
PicoLisp
(let Str "The quick brown fox jumped over the lazy dog's back" (pack (mapcar '((B) (pad 2 (hex B))) (native "libcrypto.so" "MD5" '(B . 16) Str (length Str) '(NIL (16))) ) ) )
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Fortran
Fortran
program mandelbrot   implicit none integer , parameter :: rk = selected_real_kind (9, 99) integer , parameter :: i_max = 800 integer , parameter :: j_max = 600 integer , parameter :: n_max = 100 real (rk), parameter :: x_centre = -0.5_rk real (rk), parameter :: y_centre = 0.0_rk r...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#REXX
REXX
/*REXX program generates and displays magic squares (odd N will be a true magic square).*/ parse arg N . /*obtain the optional argument from CL.*/ if N=='' | N=="," then N=5 /*Not specified? Then use the default.*/ NN=N*N; w=length(NN) ...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#Idris
Idris
import Data.Vect   Matrix : Nat -> Nat -> Type -> Type Matrix m n t = Vect m (Vect n t)   multiply : Num t => Matrix m1 n t -> Matrix n m2 t -> Matrix m1 m2 t multiply a b = multiply' a (transpose b) where dot : Num t => Vect n t -> Vect n t -> t dot v1 v2 = sum $ map (\(s1, s2) => (s1 * s2)) (zip v1...
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Smalltalk
Smalltalk
Number>>x1: x1 x2: x2 x3: x3 x4: x4 x5: x5 | b k | k := self. b := [ k := k - 1. k x1: b x2: x1 x3: x2 x4: x3 x5: x4 ]. ^k <= 0 ifTrue: [ x4 value + x5 value ] ifFalse: b 10 x1: [1] x2: [-1] x3: [-1] x4: [1] x5: [0]
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Snap.21
Snap!
function a(k, x1, x2, x3, x4, x5) { let kk = { "k": k.k }; let b = function b() { kk.k--; return a(kk, b, x1, x2, x3, x4); }; return kk.k <= 0 ? x4() + x5() : b(); }   function x(n) { return function () { return n; }; }   print(a({ "k": 10 }, x(1), x(-1), x(-1), x(1), x(0)));
http://rosettacode.org/wiki/Matrix_transposition
Matrix transposition
Transpose an arbitrarily sized rectangular Matrix.
#IDL
IDL
m=[[1,1,1,1],[2, 4, 8, 16],[3, 9,27, 81],[5, 25,125, 625]] print,transpose(m)
http://rosettacode.org/wiki/Maze_generation
Maze generation
This page uses content from Wikipedia. The original article was at Maze generation algorithm. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Generate and show a maze, using the simple Depth...
#Racket
Racket
  #lang racket   ;; the structure representing a maze of size NxM (struct maze (N M tbl))   ;; managing cell properties (define (connections tbl c) (dict-ref tbl c '()))   (define (connect! tbl c n) (dict-set! tbl c (cons n (connections tbl c))) (dict-set! tbl n (cons c (connections tbl n))))   (define (connected?...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i";   const func float: mapRange (in float: a1, in float: a2, in float: b1, in float: b2, ref float: s) is return b1 + (s-a1)*(b2-b1)/(a2-a1);   const proc: main is func local var integer: number is 0; begin writeln("Mapping [0,10] to [-1,0] at intervals of 1...
http://rosettacode.org/wiki/Map_range
Map range
Given two ranges:   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   and   [ b 1 , b 2 ] {\displaystyle [b_{1},b_{2}]} ;   then a value   s {\displaystyle s}   in range   [ a 1 , a 2 ] {\displaystyle [a_{1},a_{2}]}   is linearly mapped to a value   t {\di...
#Sidef
Sidef
func map_range(a, b, x) { var (a1, a2, b1, b2) = (a.bounds, b.bounds); x-a1 * b2-b1 / a2-a1 + b1; }   var a = 0..10; var b = -1..0;   for x in a { say "#{x} maps to #{map_range(a, b, x)}"; }
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Pike
Pike
import String; import Crypto.MD5;   int main(){ write( string2hex( hash( "The quick brown fox jumped over the lazy dog's back" ) ) + "\n" ); }
http://rosettacode.org/wiki/Mandelbrot_set
Mandelbrot set
Mandelbrot set You are encouraged to solve this task according to the task description, using any language you may know. Task Generate and draw the Mandelbrot set. Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
#Frink
Frink
  // Maximum levels for each pixel. levels = 60   // Create a random color for each level. colors = new array[[levels]] for a = 0 to levels-1 colors@a = new color[randomFloat[0,1], randomFloat[0,1], randomFloat[0,1]]   // Make this number smaller for higher resolution. stepsize = .005   g = new graphics g.antialiase...
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Ring
Ring
  n=9 see "the square order is : " + n + nl for i=1 to n for j = 1 to n x = (i*2-j+n-1) % n*n + (i*2+j-2) % n + 1 see "" + x + " " next see nl next see "the magic number is : " + n*(n*n+1) / 2 + nl  
http://rosettacode.org/wiki/Magic_squares_of_odd_order
Magic squares of odd order
A magic square is an   NxN   square matrix whose numbers (usually integers) consist of consecutive numbers arranged so that the sum of each row and column,   and   both long (main) diagonals are equal to the same sum (which is called the   magic number   or   magic constant). The numbers are usually (but not always) t...
#Ruby
Ruby
def odd_magic_square(n) raise ArgumentError "Need odd positive number" if n.even? || n <= 0 n.times.map{|i| n.times.map{|j| n*((i+j+1+n/2)%n) + ((i+2*j-5)%n) + 1} } end   [3, 5, 9].each do |n| puts "\nSize #{n}, magic sum #{(n*n+1)/2*n}" fmt = "%#{(n*n).to_s.size + 1}d" * n odd_magic_square(n).each{|row| puts...
http://rosettacode.org/wiki/Matrix_multiplication
Matrix multiplication
Task Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.
#J
J
mp =: +/ .* NB. Matrix product   A =: ^/~>:i. 4 NB. Same A as in other examples (1 1 1 1, 2 4 8 16, 3 9 27 81,:4 16 64 256) B =:  %.A NB. Matrix inverse of A   '6.2' 8!:2 A mp B 1.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 1.00
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Sparkling
Sparkling
function a(k, x1, x2, x3, x4, x5) { let kk = { "k": k.k }; let b = function b() { kk.k--; return a(kk, b, x1, x2, x3, x4); }; return kk.k <= 0 ? x4() + x5() : b(); }   function x(n) { return function () { return n; }; }   print(a({ "k": 10 }, x(1), x(-1), x(-1), x(1), x(0)));
http://rosettacode.org/wiki/Man_or_boy_test
Man or boy test
Man or boy test You are encouraged to solve this task according to the task description, using any language you may know. Background: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguis...
#Standard_ML
Standard ML
fun a (k, x1, x2, x3, x4, x5) = if k <= 0 then x4 () + x5 () else let val m = ref k fun b () = ( m := !m - 1; a (!m, b, x1, x2, x3, x4) ) in b () end   val () = print (Int.toString (a (10, fn () => 1, fn () => ~1, fn () => ~1, fn () => 1, fn () => 0)) ^ "\n")