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/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....
#Racket
Racket
  #lang racket   (define alphabet " ABCDEFGHIJKLMNOPQRSTUVWXYZ") (define (randch) (string-ref alphabet (random 27)))   (define (fitness s1 s2) (for/sum ([c1 (in-string s1)] [c2 (in-string s2)]) (if (eq? c1 c2) 1 0)))   (define (mutate s P) (define r (string-copy s)) (for ([i (in-range (string-length r))] #:wh...
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 ...
#Pascal
Pascal
function fib(n: integer):longInt; const Sqrt5 = sqrt(5.0); C1 = ln((Sqrt5+1.0)*0.5);//ln( 1.618..) //C2 = ln((1.0-Sqrt5)*0.5);//ln(-0.618 )) tsetsetse C2 = ln((Sqrt5-1.0)*0.5);//ln(+0.618 )) begin IF n>0 then begin IF odd(n) then fib := round((exp(C1*n) + exp(C2*n) )/Sqrt5) else fib := rou...
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...
#Eiffel
Eiffel
  note description: "recursive and iterative factorial example of a positive integer."   class FACTORIAL_EXAMPLE   create make   feature -- Initialization   make local n: NATURAL do n := 5 print ("%NFactorial of " + n.out + " = ") print (recursive_factorial (n)) end   feature -- Access   recursiv...
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) ...
#Z80_Assembly
Z80 Assembly
foreach n in ([1..100]) { if(n % 3 == 0) print("Fizz"); if(not (n%5)) "Buzz".print(); if(n%3 and n%5) print(n); println(); }
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:...
#Python
Python
[ stack ] is switch.arg ( --> [ )   [ switch.arg put ] is switch ( x --> )   [ switch.arg release ] is otherwise ( --> )   [ switch.arg share != iff ]else[ done otherwise ]'...
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....
#Raku
Raku
constant target = "METHINKS IT IS LIKE A WEASEL"; constant mutate_chance = .08; constant @alphabet = flat 'A'..'Z',' '; constant C = 100;   sub mutate { [~] (rand < mutate_chance ?? @alphabet.pick !! $_ for $^string.comb) } sub fitness { [+] $^string.comb Zeq target.comb }   loop ( my $parent = @alphabet.roll(targe...
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 ...
#Perl
Perl
sub fib_iter { my $n = shift; use bigint try => "GMP,Pari"; my ($v2,$v1) = (-1,1); ($v2,$v1) = ($v1,$v2+$v1) for 0..$n; $v1; }
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...
#Ela
Ela
fact = fact' 1L where fact' acc 0 = acc fact' acc n = fact' (n * acc) (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) ...
#zkl
zkl
foreach n in ([1..100]) { if(n % 3 == 0) print("Fizz"); if(not (n%5)) "Buzz".print(); if(n%3 and n%5) print(n); println(); }
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:...
#Quackery
Quackery
[ stack ] is switch.arg ( --> [ )   [ switch.arg put ] is switch ( x --> )   [ switch.arg release ] is otherwise ( --> )   [ switch.arg share != iff ]else[ done otherwise ]'...
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....
#Red
Red
Red[]   ; allowed characters alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ " ; target string target: "METHINKS IT IS LIKE A WEASEL" ; parameter controlling the number of children C: 10 ; parameter controlling the evolution rate RATE: 0.05   ; compute closeness of 'string' to 'target' fitness: function [string] [ sum: 0   r...
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 ...
#Phix
Phix
function fibonacci(integer n) -- iterative, works for -ve numbers atom a=0, b=1 if n=0 then return 0 end if if abs(n)>=79 then ?9/0 end if -- inaccuracies creep in above 78 for i=1 to abs(n)-1 do {a,b} = {b,a+b} end for if n<0 and remainder(n,2)=0 then return -b end if return b 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...
#Elixir
Elixir
defmodule Factorial do # Simple recursive function def fac(0), do: 1 def fac(n) when n > 0, do: n * fac(n - 1)   # Tail recursive function def fac_tail(0), do: 1 def fac_tail(n), do: fac_tail(n, 1) def fac_tail(1, acc), do: acc def fac_tail(n, acc) when n > 1, do: fac_tail(n - 1, acc * n)   # Tail re...
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) ...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 DEF FN m(a,b)=a-INT (a/b)*b 20 FOR a=1 TO 100 30 LET o$="" 40 IF FN m(a,3)=0 THEN LET o$="Fizz" 50 IF FN m(a,5)=0 THEN LET o$=o$+"Buzz" 60 IF o$="" THEN LET o$=STR$ a 70 PRINT o$ 80 NEXT a
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:...
#Racket
Racket
  #lang planet dyoo/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....
#REXX
REXX
/*REXX program demonstrates an evolutionary algorithm (by using mutation). */ parse arg children MR seed . /*get optional arguments from the C.L. */ if children=='' | children=="," then children=10 /*# children produced each generation. */ if MR =='' | MR =="," then MR= "4%" ...
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 ...
#Phixmonti
Phixmonti
def Fibonacci dup 0 < if "Invalid argument: " print else 1 1 rot 2 - for drop over over + endfor endif enddef   10 Fibonacci pstack print nl -10 Fibonacci print
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...
#Elm
Elm
  factorial : Int -> Int factorial n = if n < 1 then 1 else n*factorial(n-1)  
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:...
#Raku
Raku
  rebol [Title: "Brainfuck interpreter"]   tape: make object! [ pos: 1 data: [0] inc: does [ data/:pos: data/:pos + 1 ] dec: does [ data/:pos: data/:pos - 1 ] advance: does [ pos: pos + 1 if (length? data) <= pos [ append data 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....
#Ring
Ring
  # Project : Evolutionary algorithm   target = "METHINKS IT IS LIKE A WEASEL" parent = "IU RFSGJABGOLYWF XSMFXNIABKT" num = 0 mutationrate = 0.5 children = len(target) child = list(children) while parent != target bestfitness = 0 bestindex = 0 for index = 1 to children child[index...
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 ...
#PHP
PHP
function fibIter($n) { if ($n < 2) { return $n; } $fibPrev = 0; $fib = 1; foreach (range(1, $n-1) as $i) { list($fibPrev, $fib) = array($fib, $fib + $fibPrev); } return $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...
#Emacs_Lisp
Emacs Lisp
  ;; Functional (most elegant and best suited to Lisp dialects): (defun fact (n) "Return the factorial of integer N, which require to be positive or 0." ;; Elisp won't do any type checking automatically, so ;; good practice would be doing that ourselves: (if (not (and (integerp n) (>= n 0))) (error "Funct...
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:...
#Rebol
Rebol
  rebol [Title: "Brainfuck interpreter"]   tape: make object! [ pos: 1 data: [0] inc: does [ data/:pos: data/:pos + 1 ] dec: does [ data/:pos: data/:pos - 1 ] advance: does [ pos: pos + 1 if (length? data) <= pos [ append data 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....
#Ruby
Ruby
@target = "METHINKS IT IS LIKE A WEASEL" Charset = [" ", *"A".."Z"] COPIES = 100   def random_char; Charset.sample end   def fitness(candidate) sum = 0 candidate.chars.zip(@target.chars) {|x,y| sum += (x[0].ord - y[0].ord).abs} 100.0 * Math.exp(Float(sum) / -10.0) end   def mutation_rate(candidate) 1.0 - Math.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 ...
#Picat
Picat
go => println([fib_fun(I) : I in 1..10]), F1=fib_fun(2**10), println(f1=F1), nl.   table fib_fun(0) = 0. fib_fun(1) = 1. fib_fun(N) = fib_fun(N-1) + fib_fun(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...
#embedded_C_for_AVR_MCU
embedded C for AVR MCU
long factorial(int n) { long result = 1; do { result *= n; while(--n); return result; }
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:...
#REXX
REXX
/*REXX program implements the Brainf*ck (self─censored) language. */ @.=0 /*initialize the infinite "tape". */ p =0 /*the "tape" cell pointer. */ ! =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....
#Rust
Rust
//! Author : Thibault Barbie //! //! A simple evolutionary algorithm written in Rust.   extern crate rand;   use rand::Rng;   fn main() { let target = "METHINKS IT IS LIKE A WEASEL"; let copies = 100; let mutation_rate = 20; // 1/20 = 0.05 = 5%   let mut rng = rand::weak_rng();   // Generate first s...
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 ...
#PicoLisp
PicoLisp
(de fibo (N) (if (>= 2 N) 1 (+ (fibo (dec N)) (fibo (- 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...
#Erlang
Erlang
lists:foldl(fun(X,Y) -> X*Y end, 1, lists:seq(1,N)).
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:...
#Ruby
Ruby
use std::collections::HashMap; use std::env; use std::fs::File; use std::io::prelude::*; use std::io::stdin; use std::num::Wrapping;   fn main() { let args: Vec<_> = env::args().collect(); if args.len() < 2 { println!("Usage: {} [path] (--debug)", args[0]); return; }   let src: Vec<char>...
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....
#Scala
Scala
import scala.annotation.tailrec   case class LearnerParams(target:String,rate:Double,C:Int)   val chars = ('A' to 'Z') ++ List(' ') val randgen = new scala.util.Random def randchar = { val charnum = randgen.nextInt(chars.size) chars(charnum) }   class RichTraversable[T](t: Traversable[T]) { def maxBy[B](fn: ...
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 ...
#Pike
Pike
int fibIter(int n) { int fibPrev, fib, i; if (n < 2) { return 1; } fibPrev = 0; fib = 1; for (i = 1; i < n; i++) { int oldFib = fib; fib += fibPrev; fibPrev = oldFib; } return 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...
#ERRE
ERRE
  PROCEDURE FACTORIAL(X%->F) F=1 IF X%<>0 THEN FOR I%=X% TO 2 STEP Ä1 DO F=F*X% END FOR END IF END PROCEDURE  
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:...
#Rust
Rust
use std::collections::HashMap; use std::env; use std::fs::File; use std::io::prelude::*; use std::io::stdin; use std::num::Wrapping;   fn main() { let args: Vec<_> = env::args().collect(); if args.len() < 2 { println!("Usage: {} [path] (--debug)", args[0]); return; }   let src: Vec<char>...
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....
#Scheme
Scheme
  (import (scheme base) (scheme write) (srfi 27)) ; random numbers   (random-source-randomize! default-random-source)   (define target "METHINKS IT IS LIKE A WEASEL") ; target string (define C 100) ; size of population (define p 0.1) ; chance any char is mutated   ;; return a random character in giv...
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 ...
#PIR
PIR
.sub fib .param int n .local int nt .local int ft if n < 2 goto RETURNN nt = n - 1 ft = fib( nt ) dec nt nt = fib(nt) ft = ft + nt .return( ft ) RETURNN: .return( n ) end .end   .sub main :main .local int counter .local int f counter=0 LOOP: if counter > 20 goto DONE f = fib(counter) ...
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...
#Euphoria
Euphoria
function factorial(integer n) atom f = 1 while n > 1 do f *= n n -= 1 end while   return f end function
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:...
#Scala
Scala
  import scala.annotation._   trait Func[T] { val zero: T def inc(t: T): T def dec(t: T): T def in: T def out(t: T): Unit }   object ByteFunc extends Func[Byte] { override val zero: Byte = 0 override def inc(t: Byte) = ((t + 1) & 0xFF).toByte override def dec(t: Byte) = ((t - 1) & 0xFF).toByte...
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....
#Seed7
Seed7
$ include "seed7_05.s7i";   const string: table is "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";   const func integer: unfitness (in string: a, in string: b) is func result var integer: sum is 0; local var integer: index is 0; begin for index range 1 to length(a) do sum +:= ord(a[index] <> b[index]); end f...
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 ...
#PL.2FI
PL/I
/* Form the n-th Fibonacci number, n > 1. 12 March 2022 */ Fib: procedure (n) returns (fixed binary (31)); declare (i, n, f1, f2, f3) fixed binary (31);   f1 = 0; f2 = 1; do i = 1 to n-2; f3 = f1 + f2; f1 = f2; f2 = f3; end; return (f3);   end 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...
#Excel
Excel
  =fact(5)  
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:...
#Scheme
Scheme
$ include "seed7_05.s7i";   const proc: brainF (in string: source, inout file: input, inout file: output) is func local var array char: memory is 100000 times '\0;'; var integer: dataPointer is 50000; var integer: instructionPointer is 1; var integer: nestingLevel is 0; begin while instructionPo...
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....
#SequenceL
SequenceL
import <Utilities/Sequence.sl>;   AllowedChars := " ABCDEFGHIJKLMNOPQRSTUVWXYZ";   initializeParent(randChars(1)) := AllowedChars[randChars];   Fitness(target(1), current(1)) := let fit[i] := true when target[i] = current[i]; in size(fit);   Mutate(letter(0), rate(0), randRate(0), randChar(0)) := letter when r...
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 ...
#PL.2FM
PL/M
100H: BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT; PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;   PRINT$NUMBER: PROCEDURE (N); DECLARE S (6) BYTE INITIAL ('.....$'); DECLARE (N, P) ADDRESS, C BASED P BYTE; P = ....
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...
#Ezhil
Ezhil
  நிரல்பாகம் fact ( n ) @( n == 0 ) ஆனால் பின்கொடு 1 இல்லை பின்கொடு n*fact( n - 1 ) முடி முடி   பதிப்பி fact ( 10 )  
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:...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: brainF (in string: source, inout file: input, inout file: output) is func local var array char: memory is 100000 times '\0;'; var integer: dataPointer is 50000; var integer: instructionPointer is 1; var integer: nestingLevel is 0; begin while instructionPo...
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....
#Sidef
Sidef
define target = "METHINKS IT IS LIKE A WEASEL" define mutate_chance = 0.08 define alphabet = [('A'..'Z')..., ' '] define C = 100   func fitness(str) { str.chars ~Z== target.chars -> count(true) } func mutate(str) { str.gsub(/(.)/, {|s1| 1.rand < mutate_chance ? alphabet.pick : s1 }) }   for ( var (i, parent) = (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 ...
#PL.2FpgSQL
PL/pgSQL
CREATE OR REPLACE FUNCTION fib(n INTEGER) RETURNS INTEGER AS $$ BEGIN IF (n < 2) THEN RETURN n; END IF; RETURN fib(n - 1) + fib(n - 2); END; $$ LANGUAGE plpgsql;
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...
#F.23
F#
//val inline factorial : // ^a -> ^a // when ^a : (static member get_One : -> ^a) and // ^a : (static member ( + ) : ^a * ^a -> ^a) and // ^a : (static member ( * ) : ^a * ^a -> ^a) let inline factorial n = Seq.reduce (*) [ LanguagePrimitives.GenericOne .. n ]
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:...
#Sidef
Sidef
define tape_length = 50_000; define eof_val = -1; define unbalanced_exit_code = 1;   var cmd = 0; var cell = 0; var code = []; var loops = []; var tape = tape_length.of(0);   func get_input { static input_buffer = []; input_buffer.len || (input_buffer = ((STDIN.readline \\ return eof_val).chomp.chars.map{.ord})...
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....
#Sinclair_ZX81_BASIC
Sinclair ZX81 BASIC
10 LET A$="ABCDEFGHIJKLMNOPQRSTUVWXYZ " 20 LET T$="METHINKS IT IS LIKE A WEASEL" 30 LET L=LEN T$ 40 LET C=10 50 LET M=0.05 60 LET G=0 70 DIM C$(C,L) 80 LET P$="" 90 FOR I=1 TO L 100 LET P$=P$+A$(INT (RND*LEN A$)+1) 110 NEXT I 120 PRINT AT 1,0;P$ 130 LET S$=P$ 140 GOSUB 390 150 LET N=R 160 PRINT AT 1,30;N 170 P...
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 ...
#PL.2FSQL
PL/SQL
  CREATE OR REPLACE FUNCTION fnu_fibonacci(p_num INTEGER) RETURN INTEGER IS f INTEGER; p INTEGER; q INTEGER; BEGIN CASE WHEN p_num < 0 OR p_num != TRUNC(p_num) THEN raise_application_error(-20001, 'Invalid input: ' || p_num, TRUE); WHEN p_num IN (0, 1) THEN f := p_num; ...
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...
#Factor
Factor
USING: math.ranges sequences ;   : factorial ( n -- n ) [1,b] product ;
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:...
#Standard_ML
Standard ML
import Foundation   let valids = [">", "<", "+", "-", ".", ",", "[", "]"] as Set<Character> var ip = 0 var dp = 0 var data = [UInt8](count: 30_000, repeatedValue: 0)   let input = Process.arguments   if input.count != 2 { fatalError("Need one input file") }   let infile: String!   do { infile = try String(conte...
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....
#Smalltalk
Smalltalk
String subclass: Mutant [ <shape: #character>   Target := Mutant from: 'METHINKS IT IS LIKE A WEASEL'. Letters := ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'.   Mutant class >> run: c rate: p ["Run Evolutionary algorighm, using c copies and mutate rate p." | pool parent | parent := self newRan...
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 ...
#Plain_English
Plain English
To find a fibonacci number given a count: Put 0 into a number. Put 1 into another number. Loop. If a counter is past the count, put the number into the fibonacci number; exit. Add the number to the other number. Swap the number with the other number. Repeat.
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...
#FALSE
FALSE
[1\[$][$@*\1-]#%]f: ^'0- f;!.
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:...
#Swift
Swift
import Foundation   let valids = [">", "<", "+", "-", ".", ",", "[", "]"] as Set<Character> var ip = 0 var dp = 0 var data = [UInt8](count: 30_000, repeatedValue: 0)   let input = Process.arguments   if input.count != 2 { fatalError("Need one input file") }   let infile: String!   do { infile = try String(conte...
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....
#Swift
Swift
func evolve( to target: String, parent: inout String, mutationRate: Int, copies: Int ) { var parentFitness: Int { return fitness(target: target, sentence: parent) }   var generation = 0   while parent != target { generation += 1   let bestOfGeneration = (0..<copies) .map({_...
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 ...
#Pop11
Pop11
define fib(x); lvars a , b; 1 -> a; 1 -> b; repeat x - 1 times (a + b, b) -> (b, a); endrepeat; a; enddefine;
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...
#Fancy
Fancy
def class Number { def factorial { 1 upto: self . product } }   # print first ten factorials 1 upto: 10 do_each: |i| { i to_s ++ "! = " ++ (i factorial) println }
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:...
#Tcl
Tcl
#!/usr/bin/env bash # BrainF*** interpreter in bash if (( ! $# )); then printf >&2 'Usage: %s program-file\n' "$0" exit 1 fi   # load the program exec 3<"$1" program=() while IFS= read -r line <&3; do mapfile -t instr < <(tr -cd '[]<>.,+-' <<<"$line" | sed $'s/./&\\\n/g') program+=("${instr[@]}") done exec 3<&...
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....
#Tailspin
Tailspin
  def alphabet: [' ABCDEFGHIJKLMNOPQRSTUVWXYZ'...]; def target: ['METHINKS IT IS LIKE A WEASEL'...]; def generationSize: 100; def mutationPercent: 10;   source randomCharacter $alphabet::length -> SYS::randomInt -> $alphabet($+1)! end randomCharacter   templates countFitness @:0; $ -> \[i](when <=$target($i)> do ...
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 ...
#PostScript
PostScript
%!PS   % We want the 'n'th fibonacci number /n 13 def   % Prepare output canvas: /Helvetica findfont 20 scalefont setfont 100 100 moveto   %define the function recursively: /fib { dup 3 lt { pop 1 } { dup 1 sub fib exch 2 sub fib add } ifelse } def   (Fib\() show n (....) cvs sh...
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...
#Fantom
Fantom
class Main { static Int factorialRecursive (Int n) { if (n <= 1) return 1 else return n * (factorialRecursive (n - 1)) }   static Int factorialIterative (Int n) { Int product := 1 for (Int i := 2; i <=n ; ++i) { product *= i } return product }   static Int fac...
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:...
#TI-83_BASIC
TI-83 BASIC
#!/usr/bin/env bash # BrainF*** interpreter in bash if (( ! $# )); then printf >&2 'Usage: %s program-file\n' "$0" exit 1 fi   # load the program exec 3<"$1" program=() while IFS= read -r line <&3; do mapfile -t instr < <(tr -cd '[]<>.,+-' <<<"$line" | sed $'s/./&\\\n/g') program+=("${instr[@]}") done exec 3<&...
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....
#Tcl
Tcl
package require Tcl 8.5   # A function to select a random character from an argument string proc tcl::mathfunc::randchar s { string index $s [expr {int([string length $s]*rand())}] }   # Set up the initial variables set target "METHINKS IT IS LIKE A WEASEL" set charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ " set parent [subs...
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 ...
#Potion
Potion
recursive = (n): if (n <= 1): 1. else: recursive (n - 1) + recursive (n - 2)..   n = 40 ("fib(", n, ")= ", recursive (n), "\n") join print
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...
#Fermat
Fermat
666!
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:...
#TI-89_BASIC
TI-89 BASIC
#!/usr/bin/env bash # BrainF*** interpreter in bash if (( ! $# )); then printf >&2 'Usage: %s program-file\n' "$0" exit 1 fi   # load the program exec 3<"$1" program=() while IFS= read -r line <&3; do mapfile -t instr < <(tr -cd '[]<>.,+-' <<<"$line" | sed $'s/./&\\\n/g') program+=("${instr[@]}") done exec 3<&...
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....
#uBasic.2F4tH
uBasic/4tH
T = 0 ' Address of target L = 28 ' Length of string P = T + L ' Address of parent R = 6 ' Mutation rate in percent C = 7 ' Number of children B = 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 ...
#PowerBASIC
PowerBASIC
actual: displayed: F(88) 1100087778366101931 1100087778366101930 F(89) 1779979416004714189 1779979416004714190 F(90) 2880067194370816120 2880067194370816120 F(91) 4660046610375530309 4660046610375530310 F(92) 7540113804746346429 7540113804746346430
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...
#FOCAL
FOCAL
1.1 F N=0,10; D 2 1.2 S N=-3; D 2 1.3 S N=100; D 2 1.4 S N=300; D 2 1.5 Q   2.1 I (N)3.1,4.1 2.2 S R=1 2.3 F I=1,N; S R=R*I 2.4 T "FACTORIAL OF ", %3.0, N, " IS ", %8.0, R, ! 2.9 R   3.1 T "N IS NEGATIVE" !; D 2.9   4.1 T "FACTORIAL OF 0 IS 1" !; D 2.9
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:...
#UNIX_Shell
UNIX Shell
#!/usr/bin/env bash # BrainF*** interpreter in bash if (( ! $# )); then printf >&2 'Usage: %s program-file\n' "$0" exit 1 fi   # load the program exec 3<"$1" program=() while IFS= read -r line <&3; do mapfile -t instr < <(tr -cd '[]<>.,+-' <<<"$line" | sed $'s/./&\\\n/g') program+=("${instr[@]}") done exec 3<&...
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....
#Ursala
Ursala
#import std #import nat   rand_char = arc ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'   target = 'METHINKS IT IS LIKE A WEASEL'   parent = rand_char* target   fitness = length+ (filter ~=)+ zip/target   mutate("string","rate") = "rate"%~?(rand_char,~&)* "string"   C = 32   evolve = @iiX ~&l->r @r -*iota(C); @lS nleq$-&l+ ^(fitness,~...
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 ...
#PowerShell
PowerShell
  function FibonacciNumber ( $count ) { $answer = @(0,1) while ($answer.Length -le $count) { $answer += $answer[-1] + $answer[-2] } return $answer }  
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...
#Forth
Forth
: fac ( n -- n! ) 1 swap 1+ 1 ?do i * loop ;
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:...
#VBScript
VBScript
'Execute BrainFuck 'VBScript Implementation 'The Main Interpreter Function BFInpt(s, sp, d, dp, i, ip, o) While sp < Len(s) Select Case Mid(s, sp + 1, 1) Case "+" newd = Asc(d(dp)) + 1 If newd > 255 Then newd = newd Mod 256 'To take account of values over 255 ...
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....
#UTFool
UTFool
  ··· http://rosettacode.org/wiki/Evolutionary_algorithm ··· ■ Evolutionary § static target⦂ String: "METHINKS IT IS LIKE A WEASEL" letter⦂ char[]: "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".toCharArray° parent⦂ String random⦂ java.util.Random° rate⦂ double: 0.5 C⦂ int: 1000   ▶ fittness⦂ int · comp...
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 ...
#Processing
Processing
void setup() { size(400, 400); fill(255, 64); frameRate(2); } void draw() { int num = fibonacciNum(frameCount); println(frameCount, num); rect(0,0,num, num); if(frameCount==14) frameCount = -1; // restart } int fibonacciNum(int n) { return (n < 2) ? n : fibonacciNum(n - 1) + fibonacciNum(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...
#Fortran
Fortran
nfactorial = PRODUCT((/(i, i=1,n)/))
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:...
#Vlang
Vlang
fn main() { // example program is current Brain**** solution to // Hello world/Text task. only requires 10 bytes of data store! bf(10, '++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++ ++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>> >+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++. <+++++...
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....
#vbscript
vbscript
  'This is the string we want to "evolve" to. Any string of any length will 'do as long as it consists only of upper case letters and spaces.   Target = "METHINKS IT IS LIKE A WEASEL"   'This is the pool of letters that will be selected at random for a mutation   letters = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"   'A mutation r...
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 ...
#Prolog
Prolog
  fib(1, 1) :- !. fib(0, 0) :- !. fib(N, Value) :- A is N - 1, fib(A, A1), B is N - 2, fib(B, B1), Value is A1 + B1.  
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...
#FPr
FPr
fact==((1&),iota)\(1*2)&
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:...
#Wren
Wren
import "io" for Stdin   class Brainf__k { construct new(prog, memSize) { _prog = prog _memSize = memSize _mem = List.filled(memSize, 0) _ip = 0 _dp = 0 }   memVal_ { (_dp >= 0 && _dp < _memSize) ? _mem[_dp] : 0 }   execute() { while (_ip < _prog.count) { ...
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....
#Visual_Basic
Visual Basic
      Option Explicit   Private Sub Main() Dim Target Dim Parent Dim mutation_rate Dim children Dim bestfitness Dim bestindex Dim Index Dim fitness   Target = "METHINKS IT IS LIKE A WEASEL" Parent = "IU RFSGJABGOLYWF XSMFXNIABKT" mutation_rate = 0.5 children = 10 R...
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 ...
#Pure
Pure
fib n = loop 0 1 n with loop a b n = if n==0 then a else loop b (a+b) (n-1); 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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Function Factorial_Iterative(n As Integer) As Integer Var result = 1 For i As Integer = 2 To n result *= i Next Return result End Function   Function Factorial_Recursive(n As Integer) As Integer If n = 0 Then Return 1 Return n * Factorial_Recursive(n - 1) End Function   For i As Inte...
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:...
#x86_Assembly
x86 Assembly
#> newsyntax @in:PE @token:bf @PE:"function(Stack){ this.TestNext(Stack,\"Paren\",\"TK_POPEN\"); this.Move(Stack,2); let Check = function(t,v){ return AST.IsPreciseToken(Stack.Token,t,v); } let Write = function(v){ AST.ChunkWrite(Stack,v); } this.OpenChunk(Stack); while(!this.IsPreciseToken(Stack.Token,\"Pa...
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....
#Vlang
Vlang
import rand import rand.seed const target = "METHINKS IT IS LIKE A WEASEL".bytes() const set = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".bytes()       fn initialize() []u8 { rand.seed(seed.time_seed_array(2)) mut parent := []u8{len: target.len} for i in 0..parent.len { parent[i] = set[rand.intn(set.len) or {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 ...
#PureBasic
PureBasic
Macro Fibonacci (n) Int((Pow(((1+Sqr(5))/2),n)-Pow(((1-Sqr(5))/2),n))/Sqr(5)) EndMacro
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...
#friendly_interactive_shell
friendly interactive shell
  function factorial set x $argv[1] set result 1 for i in (seq $x) set result (expr $i '*' $result) end echo $result end  
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:...
#XBS
XBS
#> newsyntax @in:PE @token:bf @PE:"function(Stack){ this.TestNext(Stack,\"Paren\",\"TK_POPEN\"); this.Move(Stack,2); let Check = function(t,v){ return AST.IsPreciseToken(Stack.Token,t,v); } let Write = function(v){ AST.ChunkWrite(Stack,v); } this.OpenChunk(Stack); while(!this.IsPreciseToken(Stack.Token,\"Pa...
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....
#Wren
Wren
import "random" for Random   var target = "METHINKS IT IS LIKE A WEASEL" var set = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " var rand = Random.new()   // fitness: 0 is perfect fit. greater numbers indicate worse fit. var fitness = Fn.new { |a| (0...target.count).count { |i| a[i] != target[i] } }   // set m to mutation of p, with...
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 ...
#Purity
Purity
  data Fib1 = FoldNat < const (Cons One (Cons One Empty)), (uncurry Cons) . ((uncurry Add) . (Head, Head . Tail), id) >  
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...
#Frink
Frink
  // Calculate factorial with math operator x = 5 println[x!]   // Calculate factorial with built-in function println[factorial[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:...
#zkl
zkl
fcn bf(pgm,input=""){ pgm=pgm.text; // handle both String and Data const CELLS=0d30_000; if(Void==pgm.span("[","]")){ println("Mismatched brackets"); return(); } fcn(code,z,jmpTable){ // build jump table (for [ & ]) if(span:=code.span("[","]")){ a,b:=span; b+=a-1; jmpTable[a+z]=b+z; jmpTable[b+z]=a+z;...
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....
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic code declarations string 0; \use zero-terminated convention (instead of MSb)   def MutateRate = 15, \1 chance in 15 of a mutation Copies = 30; \number of mutated copies char Target, AlphaTbl; int SizeOfAlpha;     func ...