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/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#PowerShell
PowerShell
$array = -15..37 $array | Where-Object { $_ % 2 -eq 0 }
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) ...
#Never
Never
func fizz_buzz() -> int { var i = 1;   for (i = 1; i <= 100; i = i + 1) { /* if (i % 15 == 0) */ if (i % 3 == 0 && i % 5 == 0) { prints("Fizz Buzz\n") } else if (i % 3 == 0) { prints("Fizz\n") } else if (i % 5 == 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 ...
#DWScript
DWScript
function fib(N : Integer) : Integer; begin if N < 2 then Result := 1 else Result := fib(N-2) + fib(N-1); End;
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#LFE
LFE
  (defun factors (n) (list-comp ((<- i (when (== 0 (rem n i))) (lists:seq 1 (trunc (/ n 2))))) i))  
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Prolog
Prolog
evens(D, Es) :- findall(E, (member(E, D), E mod 2 =:= 0), Es).
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) ...
#NewLISP
NewLISP
(dotimes (i 100) (println (cond ((= 0 (% i 15)) "FizzBuzz") ((= 0 (% i 3)) "Fizz") ((= 0 (% i 5)) "Buzz") ('t i))))
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 ...
#Dyalect
Dyalect
func fib(n) { if n < 2 { return n } else { return fib(n - 1) + fib(n - 2) } }   print(fib(30))
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Liberty_BASIC
Liberty BASIC
num = 10677106534462215678539721403561279 maxnFactors = 1000 dim primeFactors(maxnFactors), nPrimeFactors(maxnFactors) global nDifferentPrimeNumbersFound, nFactors, iFactor     print "Start finding all factors of ";num; ":"   nDifferentPrimeNumbersFound=0 dummy = factorize(num,2) nFactors = showPrimeFactors(num) dim f...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#PureBasic
PureBasic
Dim Tal.i(9) Dim Evens.i(0)   ;- Set up an array with random numbers For i=0 To ArraySize(Tal()) Tal(i)=Random(100) Next   ;- Pick out all Even and save them j=0 For i=0 To ArraySize(Tal()) If Tal(i)%2=0 ReDim Evens(j) ; extend the Array as we find new Even's Evens(j)=tal(i) j+1 EndIf Next   ;- Dis...
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) ...
#NewtonScript
NewtonScript
for i := 1 to 100 do begin if i mod 15 = 0 then print("FizzBuzz") else if i mod 3 = 0 then print("Fizz") else if i mod 5 = 0 then print("Buzz") else print(i); print("\n") end
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 ...
#E
E
def fib(n) { var s := [0, 1] for _ in 0..!n { def [a, b] := s s := [b, a+b] } return s[0] }
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lingo
Lingo
on factors(n) res = [1] repeat with i = 2 to n/2 if n mod i = 0 then res.add(i) end repeat res.add(n) return res end
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Python
Python
values = range(10) evens = [x for x in values if not x & 1] ievens = (x for x in values if not x & 1) # lazy # alternately but less idiomatic: evens = filter(lambda x: not x & 1, values)
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) ...
#Nickle
Nickle
/* Fizzbuzz in nickle */   void function fizzbuzz(size) { for (int i = 1; i < size; i++) { if (i % 15 == 0) { printf("Fizzbuzz\n"); } else if (i % 5 == 0) { printf("Buzz\n"); } else if (i % 3 == 0) { printf("Fizz\n"); } else { printf("%i\n", i); } } }   fizzbuzz(1000);
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 ...
#EasyLang
EasyLang
func fib n . res . if n < 2 res = n . prev = 0 val = 1 for _ range n - 1 res = prev + val prev = val val = res . . call fib 36 r print r
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Logo
Logo
to factors :n output filter [equal? 0 modulo :n ?] iseq 1 :n end   show factors 28  ; [1 2 4 7 14 28]
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Quackery
Quackery
[ [] ]'[ rot witheach [ tuck over do iff [ dip [ nested join ] ] else nip ] drop ] is only ( [ --> [ )   [ 1 & not ] is even ( n --> b )   [] 10 times [ 10 random join ] say "Ten arbitrary digits: " dup echo cr say "Only ...
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) ...
#Nim
Nim
for i in 1..100: if i mod 15 == 0: echo("FizzBuzz") elif i mod 3 == 0: echo("Fizz") elif i mod 5 == 0: echo("Buzz") else: echo(i)
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 ...
#EchoLisp
EchoLisp
  (define (fib n) (if (< n 2) n (+ (fib (- n 2)) (fib (1- n)))))   (remember 'fib #(0 1))   (for ((i 12)) (write (fib i))) 0 1 1 2 3 5 8 13 21 34 55 89  
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lua
Lua
function Factors( n ) local f = {}   for i = 1, n/2 do if n % i == 0 then f[#f+1] = i end end f[#f+1] = n   return f end
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Q
Q
x where 0=x mod 2
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) ...
#Nix
Nix
with (import <nixpkgs> { }).lib; with builtins; let fizzbuzz = { x ? 1 }: '' ${if (mod x 15 == 0) then "FizzBuzz" else if (mod x 3 == 0) then "Fizz" else if (mod x 5 == 0) then "Buzz" else (toString x)} '' + (if (x < 100) then fizzbuzz { x = x + 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 ...
#ECL
ECL
//Calculates Fibonacci sequence up to n steps using Binet's closed form solution     FibFunction(UNSIGNED2 n) := FUNCTION REAL Sqrt5 := Sqrt(5); REAL Phi := (1+Sqrt(5))/2; REAL Phi_Inv := 1/Phi; UNSIGNED FibValue := ROUND( ( POWER(Phi,n)-POWER(Phi_Inv,n) ) /Sqrt5); RETURN FibValue; END;   FibSeries(UNSIGNE...
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#M2000_Interpreter
M2000 Interpreter
  \\ Factors of an integer \\ For act as BASIC's FOR (if N<1 no loop start) FORM 60,40 SET SWITCHES "+FOR" MODULE LikeBasic { 10 INPUT N% 20 FOR I%=1 TO N% 30 IF N%/I%=INT(N%/I%) THEN PRINT I%, 40 NEXT I% 50 PRINT } CALL LikeBasic SET SWITCHES "-FOR" MODULE LikeM2000 { DEF DECIM...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#R
R
a <- 1:100 evennums <- a[ a%%2 == 0 ] print(evennums)
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) ...
#Oberon-2
Oberon-2
MODULE FizzBuzz;   IMPORT Out;   VAR i: INTEGER;   BEGIN FOR i := 1 TO 100 DO IF i MOD 15 = 0 THEN Out.String("FizzBuzz") ELSIF i MOD 5 = 0 THEN Out.String("Buzz") ELSIF i MOD 3 = 0 THEN Out.String("Fizz") ELSE Out.Int(i,0) END; Out.Ln...
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 ...
#EDSAC_order_code
EDSAC order code
[ Fibonacci sequence ==================   A program for the EDSAC   Calculates the nth Fibonacci number and displays it at the top of storage tank 3   The default value of n is 10   To calculate other Fibonacci numbers, set the starting value of the count to n-2   Works with Initial Orders 2 ]     ...
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Maple
Maple
  numtheory:-divisors(n);  
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Racket
Racket
  -> (filter even? '(0 1 2 3 4 5 6 7 8 9)) '(0 2 4 6 8)  
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) ...
#Objeck
Objeck
bundle Default { class Fizz { function : Main(args : String[]) ~ Nil { for(i := 0; i <= 100; i += 1;) { if(i % 15 = 0) { "FizzBuzz"->PrintLine(); } else if(i % 3 = 0) { "Fizz"->PrintLine(); } else if(i % 5 = 0) { "Buzz"->PrintLine(); ...
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 ...
#Eiffel
Eiffel
  class APPLICATION   create make   feature   fibonacci (n: INTEGER): INTEGER require non_negative: n >= 0 local i, n2, n1, tmp: INTEGER do n2 := 0 n1 := 1 from i := 1 until i >= n loop tmp := n1 n1 := n2 + n1 n2 := tmp i := i + 1 end Result := n1 if n = 0 ...
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
Factorize[n_Integer] := Divisors[n]
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Raku
Raku
my @a = 1..6; my @even = grep * %% 2, @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) ...
#Objective-C
Objective-C
// FizzBuzz in Objective-C #import <Foundation/Foundation.h>   int main(int argc, char* argv[]) { for (NSInteger i=1; I <= 101; i++) { if (i % 15 == 0) { NSLog(@"FizzBuzz\n"); } else if (i % 3 == 0) { NSLog(@"Fizz\n"); } else if (i % 5 == 0) { NSLog(@"Buzz\n"); } else { NSLog(@"%li\n", ...
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 ...
#Ela
Ela
fib = fib' 0 1 where fib' a b 0 = a fib' a b n = fib' b (a + b) (n - 1)
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#MATLAB_.2F_Octave
MATLAB / Octave
function fact(n); f = factor(n); % prime decomposition K = dec2bin(0:2^length(f)-1)-'0'; % generate all possible permutations F = ones(1,2^length(f)); for k = 1:size(K) F(k) = prod(f(~K(k,:))); % and compute products end; F = unique(F); % eliminate duplicates printf('There are ...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Raven
Raven
[ 0 1 2 3 4 5 6 7 8 9 ] as nums group nums each dup 1 & if drop list as evens
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) ...
#OCaml
OCaml
let fizzbuzz i = match i mod 3, i mod 5 with 0, 0 -> "FizzBuzz" | 0, _ -> "Fizz" | _, 0 -> "Buzz" | _ -> string_of_int i   let _ = for i = 1 to 100 do print_endline (fizzbuzz i) done
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 ...
#Elena
Elena
import extensions;   fibu(n) { int[] ac := new int[]{ 0,1 }; if (n < 2) { ^ ac[n] } else { for(int i := 2, i <= n, i+=1) { int t := ac[1]; ac[1] := ac[0] + ac[1]; ac[0] := t };   ^ ac[1] } }   public program() { ...
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Maxima
Maxima
(%i96) divisors(100); (%o96) {1,2,4,5,10,20,25,50,100}
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#REBOL
REBOL
a: [] repeat i 100 [append a i] ; Build and load array.   evens: [] repeat element a [if even? element [append evens element]]   print mold evens
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) ...
#Octave
Octave
for i = 1:100 if ( mod(i,15) == 0 ) disp("FizzBuzz"); elseif ( mod(i, 3) == 0 ) disp("Fizz") elseif ( mod(i, 5) == 0 ) disp("Buzz") else disp(i) endif endfor
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 ...
#Elixir
Elixir
defmodule Fibonacci do def fib(0), do: 0 def fib(1), do: 1 def fib(n), do: fib(0, 1, n-2)   def fib(_, prv, -1), do: prv def fib(prvprv, prv, n) do next = prv + prvprv fib(prv, next, n-1) end end   IO.inspect Enum.map(0..10, fn i-> Fibonacci.fib(i) end)
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#MAXScript
MAXScript
  fn factors n = ( return (for i = 1 to n+1 where mod n i == 0 collect i) )  
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Red
Red
Red [] orig: [] repeat i 10 [append orig i] ?? orig cpy: [] forall orig [if even? orig/1 [append cpy orig/1]] ;; or - because we know each second element is even :- ) ;; cpy: extract next orig 2 ?? cpy remove-each ele orig [odd? ele]  ;; destructive ?? orig  
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) ...
#Oforth
Oforth
: fizzbuzz | i | 100 loop: i [ null i 3 mod ifZero: [ "Fizz" + ] i 5 mod ifZero: [ "Buzz" + ] dup ifNull: [ drop i ] . ] ;
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 ...
#Elm
Elm
fibonacci : Int -> Int fibonacci n = if n < 2 then n else fibonacci(n - 2) + fibonacci(n - 1)
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Mercury
Mercury
:- module fac.   :- interface. :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module float, int, list, math, string.   main(!IO) :- io.command_line_arguments(Args, !IO), list.filter_map(string.to_int, Args, CleanArgs), list.foldl((pred(Arg::in, !.IO::di, !:IO::uo) i...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#REXX
REXX
/*REXX program selects all even numbers from an array and puts them ──► a new array.*/ parse arg N seed . /*obtain optional arguments from the CL*/ if N=='' | N=="," then N= 50 /*Not specified? Then use the default.*/ if datatype(seed,'W') then call random ,,seed ...
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) ...
#Ol
Ol
  (for-each (lambda (x) (print (cond ((and (zero? (mod x 3)) (zero? (mod x 5))) "FizzBuzz") ((zero? (mod x 3)) "Fizz") ((zero? (mod x 5)) "Buzz") (else x)))) (iota 100))  
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 ...
#Emacs_Lisp
Emacs Lisp
(defun fib (n a b c) (cond ((< c n) (fib n b (+ a b) (+ 1 c))) ((= c n) b) (t a)))   (defun fibonacci (n) (if (< n 2) n (fib n 0 1 1)))
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#min
min
(mod 0 ==) :divisor? (() 0 shorten) :new (new (over swons 'pred dip) pick times nip) :iota   (  :n n sqrt int iota  ; Only consider numbers up to sqrt(n). (n swap divisor?) filter =f1 f1 (n swap div) map reverse =f2  ; "Mirror" the list of divisors at sqrt(n). (f1 last f2 fi...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Ring
Ring
  aList = [1, 2, 3, 4, 5, 6] bArray = list(3) see evenSelect(aList)   func evenSelect aArray i = 0 for n = 1 to len(aArray) if (aArray[n] % 2) = 0 i = i + 1 bArray[i] = aArray[n] ok next return bArray  
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) ...
#OOC
OOC
fizz: func (n: Int) -> Bool { if(n % 3 == 0) { printf("Fizz") return true } return false }   buzz: func (n: Int) -> Bool { if(n % 5 == 0) { printf("Buzz") return true } return false }   main: func { for(n in 1..100) { fizz:= fizz(n) buzz:= buzz(n) fizz || buzz || printf("%d", n...
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 ...
#Erlang
Erlang
  -module(fib). -export([fib/1]).   fib(0) -> 0; fib(1) -> 1; fib(N) -> fib(N-1) + fib(N-2).  
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#MiniScript
MiniScript
factors = function(n) result = [1] for i in range(2, n) if n % i == 0 then result.push i end for return result end function   while true n = val(input("Number to factor (0 to quit)? ")) if n <= 0 then break print factors(n) end while
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Ruby
Ruby
# Enumerable#select returns a new array. ary = [1, 2, 3, 4, 5, 6] even_ary = ary.select {|elem| elem.even?} p even_ary # => [2, 4, 6]   # Enumerable#select also works with Range. range = 1..6 even_ary = range.select {|elem| elem.even?} p even_ary # => [2, 4, 6]
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) ...
#Order
Order
#include <order/interpreter.h>   // Get FB for one number #define ORDER_PP_DEF_8fizzbuzz ORDER_PP_FN( \ 8fn(8N, \ 8let((8F, 8fn(8N, 8G, \ 8is_0(8remainder(8N, 8G)))), \ 8cond((8ap(8F, 8N, 15), 8...
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 ...
#ERRE
ERRE
!------------------------------------------- ! derived from my book "PROGRAMMARE IN ERRE" ! iterative solution !-------------------------------------------   PROGRAM FIBONACCI   !$DOUBLE   !VAR F1#,F2#,TEMP#,COUNT%,N%   BEGIN  !main INPUT("Number",N%) F1=0 F2=1 REPEAT TEMP=F2 F2=F1+F2 F1...
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П9 1 П6 КИП6 ИП9 ИП6 / П8 ^ [x] x#0 21 - x=0 03 ИП6 С/П ИП8 П9 БП 04 1 С/П БП 21
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Run_BASIC
Run BASIC
dim a1(100) count = 100 for i = 1 to 100 a1(i) = int(rnd(0)*100)+1 count = count - (a1(i) mod 2) next   'dim the extract and fill it dim a2(count) for i = 1 to 100 if not(a1(i) mod 2) then n = n+1 a2(n) = a1(i) end if next   for i = 1 to count print a2(i) next
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#11l
11l
F perim_equal(p1, =p2) I p1.len != p2.len | Set(p1) != Set(p2) R 0B I any((0 .< p1.len).map(n -> @p2 == (@p1[n ..] [+] @p1[0 .< n]))) R 1B p2 = reversed(p2) R any((0 .< p1.len).map(n -> @p2 == (@p1[n ..] [+] @p1[0 .< n])))   F edge_to_periphery(e) V edges = sorted(e) [Int] p I !edges.em...
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) ...
#Oz
Oz
declare fun {FizzBuzz X} if X mod 15 == 0 then 'FizzBuzz' elseif X mod 3 == 0 then 'Fizz' elseif X mod 5 == 0 then 'Buzz' else X end end in for I in 1..100 do {Show {FizzBuzz I}} end
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 ...
#Euphoria
Euphoria
  function fibor(integer n) if n<2 then return n end if return fibor(n-1)+fibor(n-2) end function  
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#MUMPS
MUMPS
factors(num) New fctr,list,sep,sqrt If num<1 Quit "Too small a number" If num["." Quit "Not an integer" Set sqrt=num**0.5\1 For fctr=1:1:sqrt Set:num/fctr'["." list(fctr)=1,list(num/fctr)=1 Set (list,fctr)="",sep="[" For Set fctr=$Order(list(fctr)) Quit:fctr="" Set list=list_sep_fctr,sep="," Quit list_"]"   w $...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Rust
Rust
fn main() { println!("new vec filtered: "); let nums: Vec<i32> = (1..20).collect(); let evens: Vec<i32> = nums.iter().cloned().filter(|x| x % 2 == 0).collect(); println!("{:?}", evens);   // Filter an already existing vector println!("original vec filtered: "); let mut nums: Vec<i32> = (1..2...
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Go
Go
package main   import ( "fmt" "sort" )   // Check a slice contains a value. func contains(s []int, f int) bool { for _, e := range s { if e == f { return true } } return false }   // Assumes s1, s2 are of same length. func sliceEqual(s1, s2 []int) bool { for i := 0; 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) ...
#PARI.2FGP
PARI/GP
{for(n=1,100, print(if(n%3, if(n%5, n , "Buzz" ) , if(n%5, "Fizz" , "FizzBuzz" ) )) )}
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#Ada
Ada
logical_operator  ::= and | or | xor relational_operator  ::= = | /= | < | <= | > | >= binary_adding_operator  ::= + | – | & unary_adding_operator  ::= + | – multiplying_operator  ::= * | / | mod | rem highest_precedence_operator ::= ** | abs | not
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 ...
#Excel
Excel
FIBONACCI =LAMBDA(n, APPLYN(n - 2)( LAMBDA(xs, APPENDROWS(xs)( SUM( LASTNROWS(2)(xs) ) ) ) )({1;1}) )
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Nanoquery
Nanoquery
n = int(input())   for i in range(1, n / 2) if (n % i = 0) print i + " " end end println n
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Salmon
Salmon
iterate(x; comprehend(y; [1...10]; y % 2 == 0) (y)) x!;
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Haskell
Haskell
import Data.List (find, delete, (\\)) import Control.Applicative ((<|>))   ------------------------------------------------------------   newtype Perimeter a = Perimeter [a] deriving Show   instance Eq a => Eq (Perimeter a) where Perimeter p1 == Perimeter p2 = null (p1 \\ p2) && ((p1 `elem` zipWith const (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) ...
#Pascal
Pascal
program fizzbuzz(output); var i: integer; begin for i := 1 to 100 do if i mod 15 = 0 then writeln('FizzBuzz') else if i mod 3 = 0 then writeln('Fizz') else if i mod 5 = 0 then writeln('Buzz') else writeln(i) end.
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#ALGOL_68
ALGOL 68
BEGIN # show the results of exponentiation and unary minus in various combinations # FOR x FROM -5 BY 10 TO 5 DO FOR p FROM 2 TO 3 DO print( ( "x = ", whole( x, -2 ), " p = ", whole( p, 0 ) ) ); print( ( " -x**p ", whole( -x**p, -4 ) ) ); print( ( " -(x)**p ...
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#AWK
AWK
  # syntax: GAWK -f EXPONENTIATION_WITH_INFIX_OPERATORS_IN_OR_OPERATING_ON_THE_BASE.AWK # converted from FreeBASIC BEGIN { print(" x p | -x^p -(x)^p (-x)^p -(x^p)") print("--------+------------------------------------") for (x=-5; x<=5; x+=10) { for (p=2; p<=3; p++) { printf("%3d ...
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 ...
#F.23
F#
  let fibonacci n : bigint = let rec f a b n = match n with | 0 -> a | 1 -> b | n -> (f b (a + b) (n - 1)) f (bigint 0) (bigint 1) n > fibonacci 100;; val it : bigint = 354224848179261915075I
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#NetRexx
NetRexx
/* NetRexx *********************************************************** * 21.04.2013 Walter Pachl * 21.04.2013 add method main to accept argument(s) *********************************************************************/ options replace format comments java crossref symbols nobinary class divl method main(argwords=Stri...
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Sather
Sather
class MARRAY{T} < $ARR{T} is include ARRAY{T};   filter_by(r:ROUT{T}:BOOL):SAME is o:MARRAY{T} := #; loop e ::= elt!; if r.call(e) then o := o.append(#MARRAY{T}(|e|)); end; end; return o; end;   end;   class MAIN is main is a ::= #MARRAY{INT}(|5, 6, 7, 8, 9, 10, 11|); ...
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#J
J
NB. construct a list of all rotations of one of the faces NB. including all rotations of the reversed list. NB. Find out if the other face is a member of this list. NB. ,&:rotations -> append, but first enlist the rotations. rotations=. |."0 1~ i.@# reverse=: |. same_perimeter=: e. (,&:rotations...
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Julia
Julia
iseq(f, g) = any(n -> f == circshift(g, n), 1:length(g))   function toface(evec) try ret, edges = collect(evec[1]), copy(evec[2:end]) while !isempty(edges) i = findfirst(x -> ret[end] == x[1] || ret[end] == x[2], edges) push!(ret, ret[end] == edges[i][1] ? edges[i][2] : edges...
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) ...
#PDP-8_Assembly
PDP-8 Assembly
  /-------------------------------------------------------- /THIS PROGRAM PRINTS THE INTEGERS FROM 1 TO 100 (INCL). /WITH THE FOLLOWING RESTRICTIONS: / FOR MULTIPLES OF THREE, PRINT 'FIZZ' / FOR MULTIPLES OF FIVE, PRINT 'BUZZ' / FOR MULTIPLES OF BOTH THREE AND FIVE, PRINT 'FIZZBUZZ' /-------------------------------...
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#BASIC
BASIC
S$=" ":M$=CHR$(13):?M$" X P -X^P -(X)^P (-X)^P -(X^P)":FORX=-5TO+5STEP10:FORP=2TO3:?M$MID$("+",1+(X<0));X" "PRIGHT$(S$+STR$(-X^P),8)RIGHT$(S$+STR$(-(X)^P),8)RIGHT$(S$+STR$((-X)^P),8)RIGHT$(S$+STR$(-(X^P)),8);:NEXTP,X
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#F.23
F#
  printfn "-5.0**2.0=%f; -(5.0**2.0)=%f" (-5.0**2.0) (-(5.0**2.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 ...
#Factor
Factor
: fib ( n -- m ) dup 2 < [ [ 0 1 ] dip [ swap [ + ] keep ] times drop ] unless ;
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Nim
Nim
import intsets, math, algorithm   proc factors(n: int): seq[int] = var fs: IntSet for x in 1 .. int(sqrt(float(n))): if n mod x == 0: fs.incl(x) fs.incl(n div x)   for x in fs: result.add(x) result.sort()   echo factors(45)
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Scala
Scala
(1 to 100).filter(_ % 2 == 0)
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Nim
Nim
import algorithm, strutils   type Perimeter = seq[int] Face = tuple[name: char; perimeter: Perimeter] Edge = tuple[first, last: int]   const None = -1 # No point.   #---------------------------------------------------------------------------------------------------   func isSame(p1, p2: Perimeter): bool = ## ...
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Perl
Perl
use strict; use warnings; use feature 'say'; use Set::Scalar; use Set::Bag; use Storable qw(dclone);   sub show { my($pts) = @_; my $p='( '; $p .= '(' . join(' ',@$_) . ') ' for @$pts; $p.')' }   sub check_equivalence { my($a, $b) = @_; Set::Scalar->new(@$a) == Set::Scalar->new(@$b) }   sub edge_to_periphery { ...
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) ...
#Peloton
Peloton
<# DEFINE USERDEFINEDROUTINE LITERAL>__FizzBuzz|<# SUPPRESSAUTOMATICWHITESPACE> <# TEST ISITMODULUSZERO PARAMETER LITERAL>1|3</#> <# TEST ISITMODULUSZERO PARAMETER LITERAL>1|5</#> <# ONLYFIRSTOFLASTTWO><# SAY LITERAL>Fizz</#></#> <# ONLYSECONDOFLASTTWO><# SAY LITERAL>Buzz</#></#> <# BOTH><# SAY LITERAL>FizzBuzz</#></#>...
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#Factor
Factor
USING: infix locals prettyprint sequences sequences.generalizations sequences.repeating ;   :: row ( x p -- seq ) x p "-x**p" [infix -x**p infix] "-(x)**p" [infix -(x)**p infix] "(-x)**p" [infix (-x)**p infix] "-(x**p)" [infix -(x**p) infix] 10 narray ;   { "x value" "p value" } { "expression" "result" ...
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#FreeBASIC
FreeBASIC
print " x p | -x^p -(x)^p (-x)^p -(x^p)" print "----------------+---------------------------------------------" for x as integer = -5 to 5 step 10 for p as integer = 2 to 3 print using " ## ## | #### #### #### ####";_ x;p;(-x^p);(-(...
http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base
Exponentiation with infix operators in (or operating on) the base
(Many programming languages,   especially those with extended─precision integer arithmetic,   usually support one of **, ^, ↑ or some such for exponentiation.) Some languages treat/honor infix operators when performing exponentiation   (raising numbers to some power by the language's exponentiation operator,   if ...
#Go
Go
package main   import ( "fmt" "math" )   type float float64   func (f float) p(e float) float { return float(math.Pow(float64(f), float64(e))) }   func main() { ops := []string{"-x.p(e)", "-(x).p(e)", "(-x).p(e)", "-(x.p(e))"} for _, x := range []float{float(-5), float(5)} { for _, e := range []...
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 ...
#Falcon
Falcon
function fib_i(n)   if n < 2: return n   fibPrev = 1 fib = 1 for i in [2:n] tmp = fib fib += fibPrev fibPrev = tmp end return fib end
http://rosettacode.org/wiki/Factors_of_an_integer
Factors of an integer
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Niue
Niue
[ 'n ; [ negative-or-zero [ , ] if [ n not-factor [ , ] when ] else ] n times n ] 'factors ;   [ dup 0 <= ] 'negative-or-zero ; [ swap dup rot swap mod 0 = not ] 'not-factor ;   ( tests ) 100 factors .s .clr ( => 1 2 4 5 10 20 25 50 100 ) newline 53 factors .s .clr ( => 1 53 ) newline 64 factors .s .clr ( => 1 ...
http://rosettacode.org/wiki/Extreme_floating_point_values
Extreme floating point values
The IEEE floating point specification defines certain 'extreme' floating point values such as minus zero, -0.0, a value distinct from plus zero; not a number, NaN; and plus and minus infinity. The task is to use expressions involving other 'normal' floating point values in your language to calculate these, (and maybe ...
#Ada
Ada
  subtype Consistent_Float is Float range Float'Range; -- No IEEE ideals  
http://rosettacode.org/wiki/Factorial_base_numbers_indexing_permutations_of_a_collection
Factorial base numbers indexing permutations of a collection
You need a random arrangement of a deck of cards, you are sick of lame ways of doing this. This task is a super-cool way of doing this using factorial base numbers. The first 25 factorial base numbers in increasing order are: 0.0.0, 0.0.1, 0.1.0, 0.1.1, 0.2.0, 0.2.1, 1.0.0, 1.0.1, 1.1.0, 1.1.1,1.2.0, 1.2.1, 2.0.0, 2.0....
#AppleScript
AppleScript
-- Permutate a list according to a given factorial base number. on FBNShuffle(|Ω|, fbn) set astid to AppleScript's text item delimiters set AppleScript's text item delimiters to "." set fbnDigits to fbn's text items set AppleScript's text item delimiters to astid   repeat with m from 1 to (count fbn...
http://rosettacode.org/wiki/Factorions
Factorions
Definition A factorion is a natural number that equals the sum of the factorials of its digits. Example 145   is a factorion in base 10 because: 1! + 4! + 5! = 1 + 24 + 120 = 145 It can be shown (see talk page) that no factorion in base 10 can exceed   1,499,999. Task Write a progr...
#11l
11l
V fact = [1] L(n) 1..11 fact.append(fact[n-1] * n)   L(b) 9..12 print(‘The factorions for base ’b‘ are:’) L(i) 1..1'499'999 V fact_sum = 0 V j = i L j > 0 V d = j % b fact_sum += fact[d] j I/= b I fact_sum == i print(i, end' ‘ ’) print("\n")
http://rosettacode.org/wiki/Filter
Filter
Task Select certain elements from an Array into a new Array in a generic way. To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
#Scheme
Scheme
  (define filter (lambda (fn lst) (let iter ((lst lst) (result '())) (if (null? lst) (reverse result) (let ((item (car lst)) (rest (cdr lst))) (if (fn item) (iter rest (cons item result)) (iter rest result)))))))  
http://rosettacode.org/wiki/Faces_from_a_mesh
Faces from a mesh
A mesh defining a surface has uniquely numbered vertices, and named, simple-polygonal faces described usually by an ordered list of edge numbers going around the face, For example: External image of two faces Rough textual version without edges: 1 17 7 A B ...
#Phix
Phix
with javascript_semantics function perequiv(sequence a, b) -- Works by aligning and rotating in one step, so theoretically much faster on massive sets. -- (ahem, faster than multiple rotates, index-only loops would obviously be even faster...) bool res = (length(a)==length(b)) if res and length(a)>0 then ...