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/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#REBOL
REBOL
write %output.txt read %input.txt   ; No line translations: write/binary %output.txt read/binary %input.txt   ; Save a web page: write/binary %output.html read http://rosettacode.org  
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Red
Red
  file: read %input.txt write %output.txt file
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 ...
#AutoIt
AutoIt
#AutoIt Version: 3.2.10.0 $n0 = 0 $n1 = 1 $n = 10 MsgBox (0,"Iterative Fibonacci ", it_febo($n0,$n1,$n))   Func it_febo($n_0,$n_1,$N) $first = $n_0 $second = $n_1 $next = $first + $second $febo = 0 For $i = 1 To $N-3 $first = $second $second = $next $next = $first + $second Next i...
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 |...
#Clojure
Clojure
(defn factors [n] (filter #(zero? (rem n %)) (range 1 (inc n))))   (print (factors 45))
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#Nim
Nim
import math, complex, strutils   # Works with floats and complex numbers as input proc fft[T: float | Complex[float]](x: openarray[T]): seq[Complex[float]] = let n = x.len if n == 0: return   result.newSeq(n)   if n == 1: result[0] = (when T is float: complex(x[0]) else: x[0]) return   var evens, odds...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#REXX
REXX
/*REXX program uses exponent─and─mod operator to test possible Mersenne numbers. */ numeric digits 20 /*this will be increased if necessary. */ parse arg N spec /*obtain optional arguments from the CL*/ if N=='' | N=="," then N= 88 ...
http://rosettacode.org/wiki/Farey_sequence
Farey sequence
The   Farey sequence   Fn   of order   n   is the sequence of completely reduced fractions between   0   and   1   which, when in lowest terms, have denominators less than or equal to   n,   arranged in order of increasing size. The   Farey sequence   is sometimes incorrectly called a   Farey series. Each Farey se...
#XPL0
XPL0
proc Farey(N); \Show Farey sequence for N \Translation of Python program on Wikipedia: int N, A, B, C, D, K, T; [A:= 0; B:= 1; C:= 1; D:= N; Text(0, "0/1"); while C <= N do [K:= (N+B)/D; T:= C; C:= K*C - A; A:= T; T:= D; D:= K*D - B; B:= T; ChOut(0, ^ ); IntOut(0, A); C...
http://rosettacode.org/wiki/Farey_sequence
Farey sequence
The   Farey sequence   Fn   of order   n   is the sequence of completely reduced fractions between   0   and   1   which, when in lowest terms, have denominators less than or equal to   n,   arranged in order of increasing size. The   Farey sequence   is sometimes incorrectly called a   Farey series. Each Farey se...
#Yabasic
Yabasic
// Rosetta Code problem: https://rosettacode.org/wiki/Farey_sequence // by Jjuanhdez, 06/2022   for i = 1 to 11 print "F", i, " = "; farey(i, FALSE) next i print for i = 100 to 1000 step 100 print "F", i; if i <> 1000 then print " "; else print ""; : fi print " = "; farey(i, FALSE) next i end  ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Nim
Nim
import sequtils, strutils   proc fiblike(start: seq[int]): auto = var memo = start proc fibber(n: int): int = if n < memo.len: return memo[n] else: var ans = 0 for i in n-start.len ..< n: ans += fibber(i) memo.add ans return ans return fibber   let fibo = fiblike(@[1,...
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.
#Lambdatalk
Lambdatalk
    {def filter {lambda {:bool :a} {if {S.empty? {S.rest :a}} then {:bool {S.first :a}} else {:bool {S.first :a}} {filter :bool {S.rest :a}}}}}   {def even? {lambda {:w} {if {= {% :w 2} 0} then :w else}}} {def odd? {lambda {:w} {if {= {% :w 2} 1} then :w else}}}   {filter even? {S.serie 1 20}} -> 2 4...
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) ...
#Lambdatalk
Lambdatalk
  1. direct:   {S.map {lambda {:i} {if {= {% :i 15} 0} then fizzbuzz else {if {= {% :i 3} 0} then fizz else {if {= {% :i 5} 0} then buzz else :i}}}} {S.serie 1 100}} -> 1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 17 fizz 19 buzz fizz 22 23 fizz buzz 26 fizz 28 29 fizzbuzz 31...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Retro
Retro
with files' here dup "input.txt" slurp "output.txt" spew
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#REXX
REXX
/*REXX program reads a file and copies the contents into an output file (on a line by line basis).*/ iFID = 'input.txt' /*the name of the input file. */ oFID = 'output.txt' /* " " " " output " */ call lineout iFID,,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 ...
#AWK
AWK
$ awk 'func fib(n){return(n<2?n:fib(n-1)+fib(n-2))}{print "fib("$1")="fib($1)}' 10 fib(10)=55
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 |...
#CLU
CLU
isqrt = proc (s: int) returns (int) x0: int := s/2 if x0=0 then return(s) end x1: int := (x0 + s/x0)/2 while x1<x0 do x0, x1 := x1, (x1 + s/x1)/2 end return(x0) end isqrt   factors = iter (n: int) yields (int) yield(1) for i: int in int$from_to(2,isqrt(n)) do if n//i=0 th...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#OCaml
OCaml
open Complex   let fac k n = let m2pi = -4.0 *. acos 0.0 in polar 1.0 (m2pi*.(float k)/.(float n))   let merge l r n = let f (k,t) x = (succ k, (mul (fac k n) x) :: t) in let z = List.rev (snd (List.fold_left f (0,[]) r)) in (List.map2 add l z) @ (List.map2 sub l z)   let fft lst = let rec ditfft2 a n...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Ring
Ring
  # Project : Factors of a Mersenne number   see "A factor of M929 is " + mersennefactor(929) + nl see "A factor of M937 is " + mersennefactor(937) + nl   func mersennefactor(p) if not isprime(p) return -1 ok for k = 1 to 50 q = 2*k*p + 1 if (q && 7) = 1 or (q && 7...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Ruby
Ruby
require 'prime'   def mersenne_factor(p) limit = Math.sqrt(2**p - 1) k = 1 while (2*k*p - 1) < limit q = 2*k*p + 1 if q.prime? and (q % 8 == 1 or q % 8 == 7) and trial_factor(2,p,q) # q is a factor of 2**p-1 return q end k += 1 end nil end   def trial_factor(base, exp, mod) squar...
http://rosettacode.org/wiki/Farey_sequence
Farey sequence
The   Farey sequence   Fn   of order   n   is the sequence of completely reduced fractions between   0   and   1   which, when in lowest terms, have denominators less than or equal to   n,   arranged in order of increasing size. The   Farey sequence   is sometimes incorrectly called a   Farey series. Each Farey se...
#zkl
zkl
fcn farey(n){ f1,f2:=T(0,1),T(1,n); // fraction is (num,dnom) print("%d/%d %d/%d".fmt(0,1,1,n)); while(f2[1]>1){ k,t  :=(n + f1[1])/f2[1], f1; f1,f2 = f2,T(f2[0]*k - t[0], f2[1]*k - t[1]); print(" %d/%d".fmt(f2.xplode())); } println(); }
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Ol
Ol
  (define (n-fib-iterator ll) (cons (car ll) (lambda () (n-fib-iterator (append (cdr ll) (list (fold + 0 ll)))))))  
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.
#Lang5
Lang5
: filter over swap execute select ; 10 iota "2 % not" filter . "\n" .   # [ 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) ...
#langur
langur
for .i of 100 { writeln given(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i) }
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Ring
Ring
  fn1 = "ReadMe.txt" fn2 = "ReadMe2.txt"   fp = fopen(fn1,"r") str = fread(fp, getFileSize(fp)) fclose(fp)   fp = fopen(fn2,"w") fwrite(fp, str) fclose(fp) see "OK" + nl   func getFileSize fp c_filestart = 0 c_fileend = 2 fseek(fp,0,c_fileend) nfilesize = ftell(fp) fseek(fp,0,c_filestart) ...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Ruby
Ruby
str = File.open('input.txt', 'rb') {|f| f.read} File.open('output.txt', 'wb') {|f| f.write str}
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 ...
#Axe
Axe
Lbl FIB r₁→N 0→I 1→J For(K,1,N) I+J→T J→I T→J End J Return
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 |...
#COBOL
COBOL
  IDENTIFICATION DIVISION. PROGRAM-ID. FACTORS. DATA DIVISION. WORKING-STORAGE SECTION. 01 CALCULATING. 03 NUM USAGE BINARY-LONG VALUE ZERO. 03 LIM USAGE BINARY-LONG VALUE ZERO. 03 CNT USAGE BINARY-LONG VALUE ZERO. 03 DIV USAGE BINA...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#ooRexx
ooRexx
Numeric Digits 16 list='1 1 1 1 0 0 0 0' n=words(list) x=.array~new(n) Do i=1 To n x[i]=.complex~new(word(list,i),0) End Call show 'FFT in',x call fft x Call show 'FFT out',x Exit   show: Procedure Use Arg data,x Say '---data--- num real-part imaginary-part' Say '---------- --- --------- ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Rust
Rust
fn bit_count(mut n: usize) -> usize { let mut count = 0; while n > 0 { n >>= 1; count += 1; } count }   fn mod_pow(p: usize, n: usize) -> usize { let mut square = 1; let mut bits = bit_count(p); while bits > 0 { square = square * square; bits -= 1; if ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Scala
Scala
  /** Find factors of a Mersenne number * * The implementation finds factors for M929 and further. * * @example M59 = 2^059 - 1 = 576460752303423487 ( 2 msec) * @example = 179951 × 3203431780337. */ object FactorsOfAMersenneNumber extends App {   val two: BigInt = 2 // An infinite stream of pri...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#PARI.2FGP
PARI/GP
gen(n)=k->my(v=vector(k,i,1));for(i=3,min(k,n),v[i]=2^(i-2));for(i=n+1,k,v[i]=sum(j=i-n,i-1,v[j]));v genV(n)=v->for(i=3,min(#v,n),v[i]=2^(i-2));for(i=n+1,#v,v[i]=sum(j=i-n,i-1,v[j]));v for(n=2,10,print(n"\t"gen(n)(10)))
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.
#langur
langur
val .arr = series 7   writeln " array: ", .arr writeln "filtered: ", where f .x div 2, .arr
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) ...
#Lasso
Lasso
with i in generateSeries(1, 100) select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Run_BASIC
Run BASIC
open "input.txt" for input as #in fileLen = LOF(#in) 'Length Of File fileData$ = input$(#in, fileLen) 'read entire file close #in   open "output.txt" for output as #out print #out, fileData$ 'write entire fie close #out end   ' or directly with no intermediate fileData$   open "input.txt" for ...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Rust
Rust
use std::fs::File; use std::io::{Read, Write};   fn main() { let mut file = File::open("input.txt").unwrap(); let mut data = Vec::new(); file.read_to_end(&mut data).unwrap(); let mut file = File::create("output.txt").unwrap(); file.write_all(&data).unwrap(); }  
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 ...
#Babel
Babel
fib { <- 0 1 { dup <- + -> swap } -> times zap } <
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 |...
#CoffeeScript
CoffeeScript
# Reference implementation for finding factors is slow, but hopefully # robust--we'll use it to verify the more complicated (but hopefully faster) # algorithm. slow_factors = (n) -> (i for i in [1..n] when n % i == 0)   # The rest of this code does two optimizations: # 1) When you find a prime factor, divide it out...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#PARI.2FGP
PARI/GP
FFT(v)=my(t=-2*Pi*I/#v,tt);vector(#v,k,tt=t*(k-1);sum(n=0,#v-1,v[n+1]*exp(tt*n))); FFT([1,1,1,1,0,0,0,0])
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Scheme
Scheme
  #lang scheme   ;;; this needs to be changed for other R6RS implementations (require rnrs/arithmetic/bitwise-6)   ;;; modpow, as per the task description. (define (modpow exponent base) (let loop ([square 1] [index (- (bitwise-length exponent) 1)]) (if (< index 0) square (loop (modulo (* (if (bit...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Pascal
Pascal
program FibbonacciN (output);   type TintArray = array of integer; const Name: array[2..11] of string = ('Fibonacci: ', 'Tribonacci: ', 'Tetranacci: ', 'Pentanacci: ', 'Hexanacci:...
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.
#Lasso
Lasso
local(original = array(1,2,3,4,5,6,7,8,9,10)) local(evens = (with item in #original where #item % 2 == 0 select #item) -> asstaticarray) #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) ...
#LaTeX
LaTeX
\documentclass{minimal} \usepackage{ifthen} \usepackage{intcalc} \newcounter{mycount} \newboolean{fizzOrBuzz} \newcommand\fizzBuzz[1]{% \setcounter{mycount}{1}\whiledo{\value{mycount}<#1} { \setboolean{fizzOrBuzz}{false} \ifthenelse{\equal{\intcalcMod{\themycount}{3}}{0}}{\setboolean{fizzOrBuzz}{true}Fizz}{...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Scala
Scala
import java.io.{ FileNotFoundException, PrintWriter }   object FileIO extends App { try { val MyFileTxtTarget = new PrintWriter("output.txt")   scala.io.Source.fromFile("input.txt").getLines().foreach(MyFileTxtTarget.println) MyFileTxtTarget.close() } catch { case e: FileNotFoundException => println...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Scheme
Scheme
; Open ports for the input and output files (define in-file (open-input-file "input.txt")) (define out-file (open-output-file "output.txt"))   ; Read and write characters from the input file ; to the output file one by one until end of file (do ((c (read-char in-file) (read-char in-file))) ((eof-object? c)) ...
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 ...
#bash
bash
  $ fib=1;j=1;while((fib<100));do echo $fib;((k=fib+j,fib=j,j=k));done  
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 |...
#Common_Lisp
Common Lisp
(defun factors (n &aux (lows '()) (highs '())) (do ((limit (1+ (isqrt n))) (factor 1 (1+ factor))) ((= factor limit) (when (= n (* limit limit)) (push limit highs)) (remove-duplicates (nreconc lows highs))) (multiple-value-bind (quotient remainder) (floor n factor) (when (zerop ...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#Pascal
Pascal
  PROGRAM RDFT;   (*)   Free Pascal Compiler version 3.2.0 [2020/06/14] for x86_64 The free and readable alternative at C/C++ speeds compiles natively to almost any platform, including raspberry PI * Can run independently from DELPHI / Lazarus   For debian Linux: apt -y install f...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func boolean: isPrime (in integer: number) is func result var boolean: prime is FALSE; local var integer: upTo is 0; var integer: testNum is 3; begin if number = 2 then prime := TRUE; elsif odd(number) and number > 2 then upTo := sqrt(number); ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Sidef
Sidef
func mtest(b, p) { var bits = b.base(2).digits for (var sq = 1; bits; sq %= p) { sq *= sq sq += sq if bits.shift==1 } sq == 1 }   for m (2..60 -> grep{ .is_prime }, 929) { var f = 0 var x = (2**m - 1) var q { |k| q = (2*k*m + 1) q%8 ~~ [1,7] || q.is_prime ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Perl
Perl
use strict; use warnings; use feature <say signatures>; no warnings 'experimental'; use List::Util <max sum>;   sub fib_n ($n = 2, $xs = [1], $max = 100) { my @xs = @$xs; while ( $max > (my $len = @xs) ) { push @xs, sum @xs[ max($len - $n, 0) .. $len-1 ]; } @xs }   say $_-1 . ': ' . join ' ', (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.
#Liberty_BASIC
Liberty BASIC
' write random nos between 1 and 100 ' to array1 counting matches as we go dim array1(100) count=100 for i = 1 to 100 array1(i) = int(rnd(0)*100)+1 count=count-(array1(i) mod 2) next   'dim the extract and fill it dim array2(count) for i = 1 to 100 if not(array1(i) mod 2) then n=n+1 array2(n...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Liberty_BASIC
Liberty BASIC
# fizzbuzz in LIL for {set i 1} {$i <= 100} {inc i} { set show "" if {[expr $i % 3 == 0]} {set show "Fizz"} if {[expr $i % 5 == 0]} {set show $show"Buzz"} if {[expr [length $show] == 0]} {set show $i} print $show }
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "osfiles.s7i";   const proc: main is func begin copyFile("input.txt", "output.txt"); end func;
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#SenseTalk
SenseTalk
put file "input.txt" into fileContents put fileContents into file "output.txt"
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 ...
#BASIC
BASIC
?OVERFLOW ERROR IN 220
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 |...
#Crystal
Crystal
struct Int def factors() (1..self).select { |n| (self % n).zero? } end end
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#Perl
Perl
use strict; use warnings; use Math::Complex;   sub fft { return @_ if @_ == 1; my @evn = fft(@_[grep { not $_ % 2 } 0 .. $#_ ]); my @odd = fft(@_[grep { $_ % 2 } 1 .. $#_ ]); my $twd = 2*i* pi / @_; $odd[$_] *= exp( $_ * -$twd ) for 0 .. $#odd; return (map { $evn[$_] + $odd[$_] } 0 .. $#evn ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Swift
Swift
import Foundation   extension BinaryInteger { var isPrime: Bool { if self == 0 || self == 1 { return false } else if self == 2 { return true }   let max = Self(ceil((Double(self).squareRoot())))   for i in stride(from: 2, through: max, by: 1) where self % i == 0 { return false ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Tcl
Tcl
proc int2bits {n} { binary scan [binary format I1 $n] B* binstring return [split [string trimleft $binstring 0] ""]   # another method if {$n == 0} {return 0} set bits [list] while {$n > 0} { lappend bits [expr {$n % 2}] set n [expr {$n / 2}] } return [lreverse $bits] }  ...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Phix
Phix
with javascript_semantics function nacci_noo(integer n, s, l) if n<2 then return n+n*l end if if n=2 then return 1 end if atom res = nacci_noo(n-1,s,l) for i=2 to min(s,n-1) do res += nacci_noo(n-i,s,l) end for return res end function constant names = split("lucas fibo tribo tetra pent...
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.
#Lisaac
Lisaac
+ a, b : ARRAY[INTEGER]; a := ARRAY[INTEGER].create_with_capacity 10 lower 0; b := ARRAY[INTEGER].create_with_capacity 10 lower 0; 1.to 10 do { i : INTEGER; a.add_last i; }; a.foreach { item : INTEGER; (item % 2 = 0).if { b.add_last item; }; };
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) ...
#LIL
LIL
# fizzbuzz in LIL for {set i 1} {$i <= 100} {inc i} { set show "" if {[expr $i % 3 == 0]} {set show "Fizz"} if {[expr $i % 5 == 0]} {set show $show"Buzz"} if {[expr [length $show] == 0]} {set show $i} print $show }
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Sidef
Sidef
var in = %f'input.txt'.open_r; var out = %f'output.txt'.open_w;   in.each { |line| out.print(line); };
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Slate
Slate
(File newNamed: 'input.txt' &mode: File Read) sessionDo: [| :in | (File newNamed: 'output.txt' &mode: File CreateWrite) sessionDo: [| :out | in >> out]]
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 ...
#Batch_File
Batch File
::fibo.cmd @echo off if "%1" equ "" goto :eof call :fib %1 echo %errorlevel% goto :eof   :fib setlocal enabledelayedexpansion if %1 geq 2 goto :ge2 exit /b %1   :ge2 set /a r1 = %1 - 1 set /a r2 = %1 - 2 call :fib !r1! set r1=%errorlevel% call :fib !r2! set r2=%errorlevel% set /a r0 = r1 + r2 exit /b !r0!
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 |...
#D
D
import std.stdio, std.math, std.algorithm;   T[] factors(T)(in T n) pure nothrow { if (n == 1) return [n];   T[] res = [1, n]; T limit = cast(T)real(n).sqrt + 1; for (T i = 2; i < limit; i++) { if (n % i == 0) { res ~= i; immutable q = n / i; if (q > i...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#Phix
Phix
-- -- demo\rosetta\FastFourierTransform.exw -- ===================================== -- -- Originally written by Robert Craig and posted to EuForum Dec 13, 2001 -- constant REAL = 1, IMAG = 2 type complex(sequence x) return length(x)=2 and atom(x[REAL]) and atom(x[IMAG]) end type function p2round(integer x) ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#TI-83_BASIC
TI-83 BASIC
remainder(A,B) equivalent to iPart(B*fPart(A/B))
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#uBasic.2F4tH
uBasic/4tH
Print "A factor of M929 is "; FUNC(_FNmersenne_factor(929)) Print "A factor of M937 is "; FUNC(_FNmersenne_factor(937))   End   _FNmersenne_factor Param(1) Local(2)   If (FUNC(_FNisprime(a@)) = 0) Then Return (-1)   For b@ = 1 TO 99999 c@ = (2*a@*b@) + 1 If (FUNC(_FNisprime(c@))) Then If (AND (c@, 7...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#PHP
PHP
<?php /** * @author Elad Yosifon */   /** * @param int $x * @param array $series * @param int $n * @return array */ function fib_n_step($x, &$series = array(1, 1), $n = 15) { $count = count($series);   if($count > $x && $count == $n) // exit point { return $series; }   if($count < $n) { if($count >= $x...
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.
#Logo
Logo
to even? :n output equal? 0 modulo :n 2 end show filter "even? [1 2 3 4]  ; [2 4]   show filter [equal? 0 modulo ? 2] [1 2 3 4]
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) ...
#LiveCode
LiveCode
repeat with i = 1 to 100 switch case i mod 15 = 0 put "FizzBuzz" & cr after fizzbuzz break case i mod 5 = 0 put "Buzz" & cr after fizzbuzz break case i mod 3 = 0 put "Fizz" & cr after fizzbuzz break default ...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Smalltalk
Smalltalk
| in out | in := FileStream open: 'input.txt' mode: FileStream read. out := FileStream open: 'output.txt' mode: FileStream write. [ in atEnd ] whileFalse: [ out nextPut: (in next) ]
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Snabel
Snabel
  let: q Bin list; 'input.txt' rfile read {{@q $1 push} when} for @q 'output.txt' rwfile write 0 $1 &+ for  
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 ...
#Battlestar
Battlestar
  // Fibonacci sequence, recursive version fun fibb loop a = funparam[0] break (a < 2)   a--   // Save "a" while calling fibb a -> stack   // Set the parameter and call fibb funparam[0] = a call fibb   // Handle the return value and restore "a"...
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 |...
#Dart
Dart
import 'dart:math'; factors(n) { var factorsArr = []; factorsArr.add(n); factorsArr.add(1); for(var test = n - 1; test >= sqrt(n).toInt(); test--) if(n % test == 0) { factorsArr.add(test); factorsArr.add(n / test); } return factorsArr; } void main() { print(factors(5688)); }
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#PHP
PHP
  <?php   class Complex { public $real; public $imaginary;   function __construct($real, $imaginary){ $this->real = $real; $this->imaginary = $imaginary; }   function Add($other, $dst){ $dst->real = $this->real + $other->real; $dst->imaginary = $this->imaginary + $oth...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#VBScript
VBScript
' Factors of a Mersenne number for i=1 to 59 z=i if z=59 then z=929 ':) 61 turns into 929. if isPrime(z) then r=testM(z) zz=left("M" & z & space(4),4) if r=0 then Wscript.echo zz & " prime." else Wscript.echo...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#PicoLisp
PicoLisp
(de nacci (Init Cnt) (let N (length Init) (make (made Init) (do (- Cnt N) (link (apply + (tail N (made)))) ) ) ) )
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.
#Lua
Lua
function filter(t, func) local ret = {} for i, v in ipairs(t) do ret[#ret+1] = func(v) and v or nil end return ret end   function even(a) return a % 2 == 0 end   print(unpack(filter({1, 2, 3, 4 ,5, 6, 7, 8, 9, 10}, even)))
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) ...
#LiveScript
LiveScript
[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#SNOBOL4
SNOBOL4
  input(.input,5,,'input.txt') output(.output,6,,'output.txt') while output = input  :s(while) end
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Standard_ML
Standard ML
fun copyFile (from, to) = let val instream = TextIO.openIn from val outstream = TextIO.openOut to val () = TextIO.output (outstream, TextIO.inputAll instream) val () = TextIO.closeIn instream val () = TextIO.closeOut outstream in true end handle _ => false;
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 ...
#BBC_BASIC
BBC BASIC
PRINT FNfibonacci_r(1), FNfibonacci_i(1) PRINT FNfibonacci_r(13), FNfibonacci_i(13) PRINT FNfibonacci_r(26), FNfibonacci_i(26) END   DEF FNfibonacci_r(N) IF N < 2 THEN = N = FNfibonacci_r(N-1) + FNfibonacci_r(N-2)   DEF FNfibonacci_i(N) LOCAL F, I, P, T IF N ...
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 |...
#Dc
Dc
  [Enter positive number: ]P ? sn [Factors of ]P lnn [ are: ]P [q]sq 1si [[ ]P lin]sp [ li ln <q ln li % 0=p li1+si lxx ]dsxx AP  
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#PicoLisp
PicoLisp
# apt-get install libfftw3-dev   (scl 4)   (de FFTW_FORWARD . -1) (de FFTW_ESTIMATE . 64)   (de fft (Lst) (let (Len (length Lst) In (native "libfftw3.so" "fftw_malloc" 'N (* Len 16)) Out (native "libfftw3.so" "fftw_malloc" 'N (* Len 16)) P (native "libfftw3.so" "fftw_plan_dft_1d" 'N ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Visual_Basic
Visual Basic
Sub mersenne() Dim q As Long, k As Long, p As Long, d As Long Dim factor As Long, i As Long, y As Long, z As Long Dim prime As Boolean q = 929 'input value For k = 1 To 1048576 '2**20 p = 2 * k * q + 1 If (p And 7) = 1 Or (p And 7) = 7 Then 'p=*001 or p=*111 'p is ...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Vlang
Vlang
import math const qlimit = int(2e8)   fn main() { mtest(31) mtest(67) mtest(929) }   fn mtest(m int) { // the function finds odd prime factors by // searching no farther than sqrt(N), where N = 2^m-1. // the first odd prime is 3, 3^2 = 9, so M3 = 7 is still too small. // M4 = 15 is first num...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#PL.2FI
PL/I
(subscriptrange, fixedoverflow, size): n_step_Fibonacci: procedure options (main); declare line character (100) varying; declare (i, j, k) fixed binary;   put ('n-step Fibonacci series: Please type the initial values on one line:'); get edit (line) (L); line = trim(line); k = tally(line, ' ') - tally(...
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.
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Print (1,2,3,4,5,6,7,8)#filter(lambda ->number mod 2=0) } Checkit  
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) ...
#LLVM
LLVM
; ModuleID = 'fizzbuzz.c' ; source_filename = "fizzbuzz.c" ; target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" ; target triple = "x86_64-pc-windows-msvc19.21.27702"   ; This is not strictly LLVM, as it uses the C library function "printf". ; LLVM does not provide a way to print values, so the alternative woul...
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Stata
Stata
program copyfile file open fin using `1', read text file open fout using `2', write text replace   file read fin line while !r(eof) { file write fout `"`line'"' _newline file read fin line } file close fin file close fout end   copyfile input.txt output.txt
http://rosettacode.org/wiki/File_input/output
File input/output
File input/output is part of Short Circuit's Console Program Basics selection. Task Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   via an intermediate variable. In other words, your program will demonstrate:   how to read from a file into a variable   how to write ...
#Tcl
Tcl
set in [open "input.txt" r] set out [open "output.txt" w] # Obviously, arbitrary transformations could be added to the data at this point puts -nonewline $out [read $in] close $in close $out
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 ...
#bc
bc
#! /usr/bin/bc -q   define fib(x) { if (x <= 0) return 0; if (x == 1) return 1;   a = 0; b = 1; for (i = 1; i < x; i++) { c = a+b; a = b; b = c; } return c; } fib(1000) quit
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 |...
#Delphi
Delphi
func Iterator.Where(pred) { for x in this when pred(x) { yield x } }   func Integer.Factors() { (1..this).Where(x => this % x == 0) }   for x in 45.Factors() { print(x) }
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#PL.2FI
PL/I
test: PROCEDURE OPTIONS (MAIN, REORDER); /* Derived from Fortran Rosetta Code */   /* In-place Cooley-Tukey FFT */ FFT: PROCEDURE (x) RECURSIVE; DECLARE x(*) COMPLEX FLOAT (18); DECLARE t COMPLEX FLOAT (18); DECLARE ( N, Half_N ) FIXED BINARY (31); DECLARE ( i, j ) FIXED BINARY (31); DECLARE (even...
http://rosettacode.org/wiki/Fast_Fourier_transform
Fast Fourier transform
Task Calculate the   FFT   (Fast Fourier Transform)   of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers, the output should be the magnitude   (i.e.:   sqrt(re2 + im2)...
#PowerShell
PowerShell
Function FFT($Arr){ $Len = $Arr.Count   If($Len -le 1){Return $Arr}   $Len_Over_2 = [Math]::Floor(($Len/2))   $Output = New-Object System.Numerics.Complex[] $Len   $EvenArr = @() $OddArr = @()   For($i = 0; $i -lt $Len; $i++){ If($i % 2){ $OddArr+=$Arr[$i] }Else...
http://rosettacode.org/wiki/Factors_of_a_Mersenne_number
Factors of a Mersenne number
A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy,...
#Wren
Wren
import "/math" for Int import "/fmt" for Conv, Fmt   var trialFactor = Fn.new { |base, exp, mod| var square = 1 var bits = Conv.itoa(exp, 2).toList var ln = bits.count for (i in 0...ln) { square = square * square * (bits[i] == "1" ? base : 1) % mod } return square == 1 }   var mersenneFa...
http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
Fibonacci n-step number sequences
These number series are an expansion of the ordinary Fibonacci sequence where: For n = 2 {\displaystyle n=2} we have the Fibonacci sequence; with initial values [ 1 , 1 ] {\displaystyle [1,1]} and F k 2 = F k − 1 2 + F k − 2 2 {\displaystyle F_{k}^{2}=F_{k-1}^{2}+F_{k-2}^{2}} ...
#Powershell
Powershell
#Create generator of extended fibonaci Function Get-ExtendedFibonaciGenerator($InitialValues ){ $Values = $InitialValues { #exhaust initial values first before calculating next values by summation if ($InitialValues.Length -gt 0) { $NextValue = $InitialValues[0] $Script: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.
#Maple
Maple
  evennum:=proc(nums::list(integer)) return select(x->type(x, even), nums); end proc;  
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) ...
#Lobster
Lobster
include "std.lobster"   forbias(100, 1) i: fb := (i % 3 == 0 and "fizz" or "") + (i % 5 == 0 and "buzz" or "") print fb.length and fb or "" + i