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/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Comal
Comal
PROC Recursive(n) CLOSED r:=1 IF n>1 THEN r:=n*Recursive(n-1) ENDIF RETURN r ENDPROC Recursive
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Vim_Script
Vim Script
for i in range(1, 100) if i % 15 == 0 echo "FizzBuzz" elseif i % 5 == 0 echo "Buzz" elseif i % 3 == 0 echo "Fizz" else echo i endif endfor
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Modula-3
Modula-3
// nanoquery has no function to get just a character // so we have to implement our own def get_char() c = "" while len(c)=0 c = input() end return c[0] end   // a function to handle fatal errors def fatal_error(errtext) println "%" + errtext println "usage: " + args[1] + " [filename.bf]...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Octave
Octave
global target; target = split("METHINKS IT IS LIKE A WEASEL", ""); charset = ["A":"Z", " "]; p = ones(length(charset), 1) ./ length(charset); parent = discrete_rnd(charset, p, length(target), 1); mutaterate = 0.1;   C = 1000;   function r = fitness(parent, target) r = sum(parent == target) ./ length(target); endfunct...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#NESL
NESL
function fib(n) = if n < 2 then n else fib(n - 2) + fib(n - 1);
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Visual_Basic_.NET
Visual Basic .NET
Module System_Command   Sub Main() Dim cmd As New Process cmd.StartInfo.FileName = "cmd.exe" cmd.StartInfo.RedirectStandardInput = True cmd.StartInfo.RedirectStandardOutput = True cmd.StartInfo.CreateNoWindow = True cmd.StartInfo.UseShellExecute = False   cmd....
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Wart
Wart
system "ls"
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Comefrom0x10
Comefrom0x10
n = 5 # calculates n! acc = 1   factorial comefrom   comefrom accumulate if n < 1   accumulate comefrom factorial acc = acc * n comefrom factorial if n is 0 n = n - 1   acc # prints the result
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Visual_Basic_.NET
Visual Basic .NET
  implement main open core, console   class predicates fizzbuzz : (integer) -> string procedure (i).   clauses fizzbuzz(X) = S :- X mod 15 = 0, S = "FizzBuzz", !. fizzbuzz(X) = S :- X mod 5 = 0, S = "Buzz", !. fizzbuzz(X) = S :- X mod 3 = 0, S = "Fizz", !. fizzbuzz(X) = S :- S = toString(X).   ...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Nanoquery
Nanoquery
// nanoquery has no function to get just a character // so we have to implement our own def get_char() c = "" while len(c)=0 c = input() end return c[0] end   // a function to handle fatal errors def fatal_error(errtext) println "%" + errtext println "usage: " + args[1] + " [filename.bf]...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Oforth
Oforth
200 Constant new: C 5 Constant new: RATE   : randChar // -- c 27 rand dup 27 == ifTrue: [ drop ' ' ] else: [ 'A' + 1- ] ;   : fitness(a b -- n) a b zipWith(#==) sum ;   : mutate(s -- s') s map(#[ 100 rand RATE <= ifTrue: [ drop randChar ] ]) charsAsString ;    : evolve(target) | parent | ListBuffer in...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#NetRexx
NetRexx
/* NetRexx */   options replace format comments java crossref savelog symbols   numeric digits 210000 /*prepare for some big 'uns. */ parse arg x y . /*allow a single number or range.*/ if x == '' then do /*no input? Then assume -30-->+30*/ x = -30 y =...
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Wren
Wren
/* run_system_command.wren */ class Command { foreign static exec(name, param) // the code for this is provided by Go }   Command.exec("ls", "-lt") System.print() Command.exec("dir", "")
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#x86_Assembly
x86 Assembly
  ; Executes '/bin/ls' ; Build with: ; nasm -felf32 execls.asm ; ld -m elf_i386 execls.o -o execls   global _start section .text   _start: mov eax, 0x0B ; sys_execve(char *str, char **args, char **envp) mov ebx, .path ; pathname push DWORD 0 push DWORD .path lea ecx, [esp] ; arg...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Common_Lisp
Common Lisp
(defun factorial (n) (if (zerop n) 1 (* n (factorial (1- n)))))
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Visual_Prolog
Visual Prolog
  implement main open core, console   class predicates fizzbuzz : (integer) -> string procedure (i).   clauses fizzbuzz(X) = S :- X mod 15 = 0, S = "FizzBuzz", !. fizzbuzz(X) = S :- X mod 5 = 0, S = "Buzz", !. fizzbuzz(X) = S :- X mod 3 = 0, S = "Fizz", !. fizzbuzz(X) = S :- S = toString(X).   ...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Never
Never
  record BFI { cmd : char; next : BFI; jmp : BFI; }   record MEM { val : int; next : MEM; prev : MEM; }   func compile(prog : string) -> BFI { var i = 0; var n = BFI; var p = BFI; var j = BFI; var pgm = BFI;   for (i = 0; i < length(prog); i = i + 1) { n = BFI('0'...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#OoRexx
OoRexx
  /* Weasel.rex - Me thinks thou art a weasel. - G,M.D. - 2/25/2011 */ arg C M /* C is the number of children parent produces each generation. */ /* M is the mutation rate of each gene (character) */   call initialize generation = 0 do until parent = target most_fitness = fitness(parent) most_fit = parent ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#NewLISP
NewLISP
(define (fibonacci n) (let (L '(0 1)) (dotimes (i n) (setq L (list (L 1) (apply + L)))) (L 1)) )  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Yabasic
Yabasic
system("dir") //It will return the exit code of the command; its output (if any) will be lost.     print system$("dir") //Returns the output as a large string.
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#zkl
zkl
System.cmd(System.isWindows and "dir" or "ls")
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#ZX_Spectrum_Basic
ZX Spectrum Basic
PAUSE 100
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Computer.2Fzero_Assembly
Computer/zero Assembly
LDA x BRZ done_i  ; 0! = 1   STA i   loop_i: LDA fact STA n   LDA i SUB one BRZ done_i   STA j   loop_j: LDA fact ADD n STA fact   LDA j SUB one BRZ done_j   STA j JMP loop_j   done_...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Vlang
Vlang
const ( fizz = Tuple{true, false} buzz = Tuple{false, true} fizzbuzz = Tuple{true, true} )   struct Tuple{ val1 bool val2 bool }   fn fizz_or_buzz( val int ) Tuple { return Tuple{ val % 3 == 0, val % 5 == 0 } }   fn fizzbuzz( n int ) { for i in 1..(n + 1) { match fizz_or_buzz(i) { ...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#NewLISP
NewLISP
  ; This module translates a string containing a ; Brainf*** program into a list of NewLISP expressions. ; Attempts to optimize consecutive +, -, > and < operations ; as well as bracket loops.   ; Create a namespace and put the following definitions in it   (context 'BF)   ; If BF:quiet is true, BF:run will return the ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#OxygenBasic
OxygenBasic
    'EVOLUTION   target="METHINKS IT IS LIKE A WEASEL" le=len target progeny=string le,"X"   quad seed declare QueryPerformanceCounter lib "kernel32.dll" (quad*q) QueryPerformanceCounter seed   Function Rand(sys max) as sys mov eax,max inc eax imul edx,seed,0x8088405 inc edx mov seed,edx mul ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#NGS
NGS
F fib(n:Int) { n < 2 returns n local a = 1, b = 1 # i is automatically local because of for() for(i=2; i<n; i=i+1) { local next = a + b a = b b = next } b }
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Crystal
Crystal
def factorial(x : Int) ans = 1 (1..x).each do |i| ans *= i end return ans end
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#VTL-2
VTL-2
10 N=1 20 #=30 30 #=N/3*0+%=0*110 40 #=N/5*0+%=0*130 50 #=!+30 60 ?=N 70 ?="" 80 N=N+1 90 #=100>N*20 100 #=999 110 ?="Fizz"; 120 #=! 130 ?="Buzz"; 140 #=! 180 #=70
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Nim
Nim
import os   var code = if paramCount() > 0: readFile paramStr 1 else: readAll stdin tape = newSeq[char]() d = 0 i = 0   proc run(skip = false): bool = while d >= 0 and i < code.len: if d >= tape.len: tape.add '\0'   if code[i] == '[': inc i let p = i while run(tape[d] ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Oz
Oz
declare Target = "METHINKS IT IS LIKE A WEASEL" C = 100 MutateRate = 5 %% percent   proc {Main} X0 = {MakeN {Length Target} RandomChar} in for Xi in {Iterate Evolve X0} break:Break do {System.showInfo Xi} if Xi == Target then {Break} end end end   fun {Evolve Xi} Copies...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Nial
Nial
fibi is op n { if n<2 then n else x1:=0; x2:=1; for i with tell (n - 1) do x:=x1+x2; x1:=x2; x2:=x; endfor; x2 endif};
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#D
D
uint factorial(in uint n) pure nothrow @nogc in { assert(n <= 12); } body { uint result = 1; foreach (immutable i; 1 .. n + 1) result *= i; return result; }   // Computed and printed at compile-time. pragma(msg, 12.factorial);   void main() { import std.stdio;   // Computed and printed a...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Wart
Wart
for i 1 (i <= 100) ++i prn (if (divides i 15) "FizzBuzz" (divides i 3) "Fizz" (divides i 5) "Buzz"  :else i)
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Objeck
Objeck
class Brainfu_k { @program : String; @mem : Int[]; @ip : Int; @dp : Int;   New(program : String, size : Int) { @program := program; @mem := Int → New[size]; }   function : Main(args : String[]) ~ Nil { if(args → Size() = 2) { Brainfu_k → New(args[0], args[1] → ToInt()) → Execute(); };...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#PARI.2FGP
PARI/GP
target="METHINKS IT IS LIKE A WEASEL"; fitness(s)=-dist(Vec(s),Vec(target)); dist(u,v)=sum(i=1,min(#u,#v),u[i]!=v[i])+abs(#u-#v); letter()=my(r=random(27)); if(r==26, " ", Strchr(r+65)); insert(v,x=letter())= { my(r=random(#v+1)); if(r==0, return(concat([x],v))); if(r==#v, return(concat(v,[x]))); concat(concat(v[1....
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Nim
Nim
proc Fibonacci(n: int): int64 = var fn = float64(n) var p: float64 = (1.0 + sqrt(5.0)) / 2.0 var q: float64 = 1.0 / p return int64((pow(p, fn) + pow(q, fn)) / sqrt(5.0))
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Dart
Dart
int fact(int n) { if(n<0) { throw new IllegalArgumentException('Argument less than 0'); } return n==0 ? 1 : n*fact(n-1); }   main() { print(fact(10)); print(fact(-1)); }
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#WDTE
WDTE
let io => import 'io'; let s => import 'stream';   let multiple of n => == (% n of) 0;   let fizzbuzz n => switch n { multiple (* 3 5) => 'FizzBuzz'; multiple 3 => 'Fizz'; multiple 5 => 'Buzz'; default => n; } -- io.writeln io.stdout;   s.range 1 101 -> s.map fizzbuzz -> s.drain;
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#OCaml
OCaml
  (define (bf program stack-length) (let ((program (string-append program "]")); end (program-counter 0) (stack (make-bytevector stack-length 0)) (stack-pointer 0)) (letrec ((skip (lambda (PC sp in) (let loop ((pc PC) (sp sp) (in in)) ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Pascal
Pascal
PROGRAM EVOLUTION (OUTPUT);   CONST TARGET = 'METHINKS IT IS LIKE A WEASEL'; COPIES = 100; (* 100 children in each generation. *) RATE = 1000; (* About one character in 1000 will be a mutation. *)   TYPE STRLIST = ARRAY [1..COPIES] OF STRING;   FUNCTION RANDCHAR : CHAR; (* Generate a random letter or space. *) ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Nix
Nix
fibonacci = n: if n <= 1 then n else (fibonacci (n - 1) + fibonacci (n - 2));
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#dc
dc
[* * (n) lfx -- (factorial of n) *]sz [ 1 Sp [product = 1]sz [ [Loop while 1 < n:]sz d lp * sp [product = n * product]sz 1 - [n = n - 1]sz d 1 <f ]Sf d 1 <f Lfsz [Drop loop.]sz sz [Drop n.]sz Lp [Push product.]sz ]sf   [* * For exam...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Whitespace
Whitespace
@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Ol
Ol
  (define (bf program stack-length) (let ((program (string-append program "]")); end (program-counter 0) (stack (make-bytevector stack-length 0)) (stack-pointer 0)) (letrec ((skip (lambda (PC sp in) (let loop ((pc PC) (sp sp) (in in)) ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Perl
Perl
use List::Util 'reduce'; use List::MoreUtils 'false';   ### Generally useful declarations   sub randElm {$_[int rand @_]}   sub minBy (&@) {my $f = shift; reduce {$f->($b) < $f->($a) ? $b : $a} @_;}   sub zip {@_ or return (); for (my ($n, @a) = 0 ;; ++$n) {my @row; foreach (@_) {$n < @$_ or ret...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Oberon-2
Oberon-2
  MODULE Fibonacci; IMPORT Out := NPCT:Console;   PROCEDURE Fibs(VAR r: ARRAY OF LONGREAL); VAR i: LONGINT; BEGIN r[0] := 1.0; r[1] := 1.0; FOR i := 2 TO LEN(r) - 1 DO r[i] := r[i - 2] + r[i - 1]; END END Fibs;   PROCEDURE FibsR(n: LONGREAL): LONGREAL; BEGIN IF n < 2. THEN RETURN n ELSE RETURN...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Delphi
Delphi
program Factorial1;   {$APPTYPE CONSOLE}   function FactorialIterative(aNumber: Integer): Int64; var i: Integer; begin Result := 1; for i := 1 to aNumber do Result := i * Result; end;   begin Writeln('5! = ', FactorialIterative(5)); end.
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Wortel
Wortel
@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#PARI.2FGP
PARI/GP
BF(prog)={ prog=Vec(Str(prog)); my(codeptr,ptr=1,v=vector(1000),t); while(codeptr++ <= #prog, t=prog[codeptr]; if(t=="+", v[ptr]++ , if(t=="-", v[ptr]-- , if(t==">", ptr++ , if(t=="<", ptr-- , if(t=="[" && !v[ptr], t=1; while(t, if(prog[code...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Phix
Phix
with javascript_semantics constant target = "METHINKS IT IS LIKE A WEASEL", AZS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", C = 5000, -- children in each generation P = 15 -- probability of mutation (1 in 15) function fitness(string sample, string target) return sum(sq_eq(sample,target)) e...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Objeck
Objeck
bundle Default { class Fib { function : Main(args : String[]), Nil { for(i := 0; i <= 10; i += 1;) { Fib(i)->PrintLine(); }; }   function : native : Fib(n : Int), Int { if(n < 2) { return n; };   return Fib(n-1) + Fib(n-2); } } }
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Draco
Draco
/* Note that ulong is 32 bits, so fac(12) is the largest * supported value. This is why the input parameter * is a byte. The parameters are all unsigned. */ proc nonrec fac(byte n) ulong: byte i; ulong rslt; rslt := 1; for i from 2 upto n do rslt := rslt * i od; rslt corp   proc nonre...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Wren
Wren
for (i in 1..100) { if (i % 15 == 0) { System.print("FizzBuzz") } else if (i % 3 == 0) { System.print("Fizz") } else if (i % 5 == 0) { System.print("Buzz") } else { System.print(i) } }
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Pascal
Pascal
  program rcExceuteBrainF;   uses Crt;   Const DataSize= 1024; // Size of Data segment MaxNest= 1000; // Maximum nesting depth of []   procedure ExecuteBF(Source: string); var Dp: pByte; // Used as the Data Pointer DataSeg:...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#PHP
PHP
  define('TARGET','METHINKS IT IS LIKE A WEASEL'); define('TBL','ABCDEFGHIJKLMNOPQRSTUVWXYZ ');   define('MUTATE',15); define('COPIES',30); define('TARGET_COUNT',strlen(TARGET)); define('TBL_COUNT',strlen(TBL));   // Determine number of different chars between a and b   function unfitness($a,$b) { $sum=0; ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Objective-C
Objective-C
-(long)fibonacci:(int)position { long result = 0; if (position < 2) { result = position; } else { result = [self fibonacci:(position -1)] + [self fibonacci:(position -2)]; } return result; }
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Dragon
Dragon
select "std" factorial = 1 n = readln() for(i=1,i<=n,++i) { factorial = factorial * i } showln "factorial of " + n + " is " + factorial  
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#X86_Assembly
X86 Assembly
  ; x86_64 linux nasm   section .bss number resb 4   section .data fizz: db "Fizz" buzz: db "Buzz" newLine: db 10   section .text global _start   _start:   mov rax, 1  ; initialize counter   loop: push rax call fizzBuzz pop rax inc rax cmp rax, 100 jle loop   mov rax, 60 mov rdi, 0 ...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Perl
Perl
#!/usr/bin/perl   my %code = split ' ', <<'END'; > $ptr++ < $ptr-- + $memory[$ptr]++ - $memory[$ptr]-- , $memory[$ptr]=ord(getc) . print(chr($memory[$ptr])) [ while($memory[$ptr]){ ] } END   my ($ptr, @memory) = 0; eval join ';', map @code{ /./g }, <>;
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Picat
Picat
go => _ = random2(), Target = "METHINKS IT IS LIKE A WEASEL", Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", C = 50, % Population size in each generation M = 80,  % Mutation rate per individual in a generation (0.8)   evo(Target,Chars,C,M),   nl.     evo(Target,Chars,C,M) => if member(T,Target), not member(T, ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#OCaml
OCaml
let fib_iter n = if n < 2 then n else let fib_prev = ref 1 and fib = ref 1 in for num = 2 to n - 1 do let temp = !fib in fib := !fib + !fib_prev; fib_prev := temp done; !fib
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#DWScript
DWScript
function IterativeFactorial(n : Integer) : Integer; var i : Integer; begin Result := 1; for i := 2 to n do Result *= i; end;
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#XLISP
XLISP
(defun fizzbuzz () (defun fizzb (x y) (display (cond ((= (mod x 3) (mod x 5) 0) "FizzBuzz") ((= (mod x 3) 0) "Fizz") ((= (mod x 5) 0) "Buzz") (t x))) (newline) (if (< x y) (fizzb (+ x 1) y))) (fizzb 1 100))   (fizzbuzz)
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Phix
Phix
procedure bfi(string pgm) sequence jumptable = repeat(0,length(pgm)), loopstack = {}, data = repeat(0,10) -- size?? integer skip = 0, ch, loopstart, pc, dp -- -- compile (pack/strip comments and link jumps) -- for i=1 to length(pgm) do ch = pgm[i] switch ch do ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#PicoLisp
PicoLisp
(load "@lib/simul.l")   (setq *Target (chop "METHINKS IT IS LIKE A WEASEL"))   # Generate random character (de randChar () (if (=0 (rand 0 26)) " " (char (rand `(char "A") `(char "Z"))) ) )   # Fitness function (Hamming distance) (de fitness (A) (cnt = A *Target) )   # Genetic algorithm (gen (make ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Octave
Octave
% recursive function fibo = recfibo(n) if ( n < 2 ) fibo = n; else fibo = recfibo(n-1) + recfibo(n-2); endif endfunction
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Dyalect
Dyalect
func factorial(n) { if n < 2 { 1 } else { n * factorial(n - 1) } }
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#XMIDAS
XMIDAS
startmacro loop 100 count calc/quiet three ^count 3 modulo calc/quiet five ^count 5 modulo if ^three eq 0 and ^five eq 0 say "fizzbuzz" elseif ^three eq 0 say "fizz" elseif ^five eq 0 say "buzz" else say ^count endif endloop endmacro
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#PHP
PHP
<?php function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) { do { switch($s[$_s]) { case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break; case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break; case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break; case '<': $_d--; break; ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Pike
Pike
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";   string mutate(string data, int rate) { array(int) alphabet=(array(int))chars; multiset index = (multiset)enumerate(sizeof(data)); while(rate) { int pos = random(index); data[pos]=random(alphabet); rate--; } return data; } ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Oforth
Oforth
: fib 0 1 rot #[ tuck + ] times drop ;
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Dylan
Dylan
  define method factorial (n) if (n < 1) error("invalid argument"); else reduce1(\*, range(from: 1, to: n)) end end method;  
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Xojo
Xojo
For i As Integer = 1 To 100 If i Mod 3 = 0 And i Mod 5 = 0 Then Print("FizzBuzz") ElseIf i Mod 3 = 0 Then Print("Fizz") ElseIf i Mod 5 = 0 Then Print("Buzz") Else Print(Str(i)) End If Next
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#PicoLisp
PicoLisp
(off "Program")   (de compile (File) (let Stack NIL (setq "Program" (make (in File (while (char) (case @ (">" (link '(setq Data (or ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Pony
Pony
use "random"   actor Main let _env: Env let _rand: MT = MT // Mersenne Twister let _target: String = "METHINKS IT IS LIKE A WEASEL" let _possibilities: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " let _c: U16 = 100 // number of spawn per generation let _min_mutate_rate: F64 = 0.09 let _perfect_fitness: USize = ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Ol
Ol
FIBON: REM Fibonacci sequence is generated to the Organiser II floating point variable limit. REM CLEAR/ON key quits. REM Mikesan - http://forum.psion2.org/ LOCAL A,B,C A=1 :B=1 :C=1 PRINT A, DO C=A+B A=B B=C PRINT A, UNTIL GET=1
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
factorial: 1 while over: * over swap -- swap drop swap
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#XPath_2.0
XPath 2.0
for $n in 1 to 100 return concat('fizz'[not($n mod 3)], 'buzz'[not($n mod 5)], $n[$n mod 15 = (1,2,4,7,8,11,13,14)])
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#PL.2FM
PL/M
100H:   /* CP/M BDOS CALLS */ BDOS: PROCEDURE (FN, ARG) BYTE; DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;   READ$CHAR: PROCEDURE BYTE; RETURN BDOS(1, 0); END READ$CHAR; WRITE$CHAR: PROCEDURE (CHAR); DECLARE CHAR BYTE; CHAR = BDOS(2, CHAR); END WRITE$CHAR; PRINT: PROCEDURE (STRING); DECLARE STRING ADDRE...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Prolog
Prolog
target("METHINKS IT IS LIKE A WEASEL").   rndAlpha(64, 32). % Generate a single random character rndAlpha(P, P). % 32 is a space, and 65->90 are upper case rndAlpha(Ch) :- random(N), P is truncate(64+(N*27)), !, rndAlpha(P, Ch).   rndTxt(0, []). % Generate some random text (fixed length) rndTxt(Len, [H...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#OPL
OPL
FIBON: REM Fibonacci sequence is generated to the Organiser II floating point variable limit. REM CLEAR/ON key quits. REM Mikesan - http://forum.psion2.org/ LOCAL A,B,C A=1 :B=1 :C=1 PRINT A, DO C=A+B A=B B=C PRINT A, UNTIL GET=1
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#E
E
pragma.enable("accumulator") def factorial(n) { return accum 1 for i in 2..n { _ * i } }
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#XPL0
XPL0
code CrLf=9, IntOut=11, Text=12; int N; [for N:= 1 to 100 do [if rem(N/3)=0 then Text(0,"Fizz"); if rem(N/5)=0 then Text(0,"Buzz") else if rem(N/3)#0 then IntOut(0,N); CrLf(0); ]; ]
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Pointless
Pointless
-- Code based on -- https://github.com/allisio/pointless/blob/master/lib/examples/brainfuck.ptls   output = iterate(run, vm) |> takeUntil(isFinished) |> map(vm => vm.outVal) |> filter(notEq(None)) |> map(char) |> printElems   ----------------------------------------------------------   vm = VM { ip = 0 ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#PureBasic
PureBasic
Define population = 100, mutationRate = 6 Define.s target$ = "METHINKS IT IS LIKE A WEASEL" Define.s charSet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "   Procedure.i fitness(Array aspirant.c(1), Array target.c(1)) Protected i, len, fit len = ArraySize(aspirant()) For i = 0 To len If aspirant(i) = target(i): fit +1: En...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Order
Order
#include <order/interpreter.h>   #define ORDER_PP_DEF_8fib_rec \ ORDER_PP_FN(8fn(8N, \ 8if(8less(8N, 2), \ 8N, \ 8add(8fib_rec(8sub(8N, 1)), \ 8f...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#EasyLang
EasyLang
func factorial n . r . r = 1 i = 2 while i <= n r = r * i i += 1 . . call factorial 7 r print r
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#XSLT
XSLT
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" encoding="utf-8"/>   <!-- Outputs a line for a single FizzBuzz iteration. --> <xsl:template name="fizzbuzz-single"> <xsl:param name="n"/>   <!-- $s will be "", "Fizz",...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Potion
Potion
# Where `code` is a string. bf = (code) : tape = (0) tape_pos = 0 brackets = () i = -1 while (++i < code length) : if (code(i) == ">"): if (++tape_pos == tape length): tape append(0).. elsif (code(i) == "<"): tape_pos--. elsif (code(i) == "+"): tape(tape_pos) = tape(tape_pos) + 1. ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Python
Python
from string import letters from random import choice, random   target = list("METHINKS IT IS LIKE A WEASEL") charset = letters + ' ' parent = [choice(charset) for _ in range(len(target))] minmutaterate = .09 C = range(100)   perfectfitness = float(len(target))   def fitness(trial): 'Sum of matching chars by posi...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Oz
Oz
fun{FibI N} Temp = {NewCell 0} A = {NewCell 0} B = {NewCell 1} in for I in 1..N do Temp := @A + @B A := @B B := @Temp end @A end
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#EchoLisp
EchoLisp
  (define (fact n) (for/product ((f (in-range 2 (1+ n)))) f)) (fact 10) → 3628800  
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Yabasic
Yabasic
for(i = 1; i <= 100; i++) { if(i % 3 == 0) write, format="%s", "Fizz"; if(i % 5 == 0) write, format="%s", "Buzz"; if(i % 3 && i % 5) write, format="%d", i; write, ""; }
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Prolog
Prolog
/****************************************** Starting point, call with program in atom. *******************************************/ brain(Program) :- atom_chars(Program, Instructions), process_bf_chars(Instructions).   brain_from_file(File) :- % or from file... read_file_to_codes(File, Codes, []), maplist(char_cod...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#R
R
set.seed(1234, kind="Mersenne-Twister")   ## Easier if the string is a character vector target <- unlist(strsplit("METHINKS IT IS LIKE A WEASEL", ""))   charset <- c(LETTERS, " ") parent <- sample(charset, length(target), replace=TRUE)   mutaterate <- 0.01   ## Number of offspring in each generation C <- 100   ## Hammi...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#PARI.2FGP
PARI/GP
fibonocci(n)
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#EGL
EGL
  function fact(n int in) returns (bigint) if (n < 0) writestdout("No negative numbers"); return (0); end ans bigint = 1; for (i int from 1 to n) ans *= i; end return (ans); end  
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Yorick
Yorick
for(i = 1; i <= 100; i++) { if(i % 3 == 0) write, format="%s", "Fizz"; if(i % 5 == 0) write, format="%s", "Buzz"; if(i % 3 && i % 5) write, format="%d", i; write, ""; }
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#PureBasic
PureBasic
[ stack ] is switch.arg ( --> [ )   [ switch.arg put ] is switch ( x --> )   [ switch.arg release ] is otherwise ( --> )   [ switch.arg share != iff ]else[ done otherwise ]'...