task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Klingphix
Klingphix
{ recursive } :factorial dup 1 great ( [dup 1 - factorial *] [drop 1] ) if ;   { iterative } :factorial2 1 swap [*] for ;   ( 0 22 ) [ "Factorial(" print dup print ") = " print factorial2 print nl ] for   " " input
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#F.23
F#
  printfn "-1 + 1 = %d" (-1+1)  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Factor
Factor
USING: math math.constants math.functions prettyprint ; 1 e pi C{ 0 1 } * ^ + .
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Forth
Forth
  ." e^(i*π) + 1 = " pi fcos 1e0 f+ f. '+ emit space pi fsin fs. 'i emit cr bye  
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 ...
#SNOBOL4
SNOBOL4
define("fib(a)") :(fib_end) fib fib = lt(a,2) a :s(return) fib = fib(a - 1) + fib(a - 2) :(return) fib_end   while a = trim(input) :f(end) output = a " " fib(a) :(while) end
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Klong
Klong
  factRecursive::{:[x>1;x*.f(x-1);1]} factIterative::{*/1+!x}  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Fortran
Fortran
  program euler use iso_fortran_env, only: output_unit, REAL64 implicit none   integer, parameter :: d=REAL64 real(kind=d), parameter :: e=exp(1._d), pi=4._d*atan(1._d) complex(kind=d), parameter :: i=(0._d,1._d)   write(output_unit,*) e**(pi*i) + 1 end program euler  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#FreeBASIC
FreeBASIC
#define PI 3.141592653589793238462643383279502884197169399375105821 #define MAXITER 12   '--------------------------------------- ' complex numbers and their arithmetic '---------------------------------------   type complex r as double i as double end type   function conj( a as complex ) as complex dim a...
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 ...
#SNUSP
SNUSP
@!\+++++++++# /<<+>+>-\ fib\==>>+<<?!/>!\  ?/\ #<</?\!>/@>\?-<<</@>/@>/>+<-\ \-/ \  !\ !\ !\  ?/#
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#KonsolScript
KonsolScript
function factorial(Number n):Number { Var:Number ret; if (n >= 0) { ret = 1; Var:Number i = 1; for (i = 1; i <= n; i++) { ret = ret * i; } } else { ret = 0; } return ret; }
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Go
Go
package main   import ( "fmt" "math" "math/cmplx" )   func main() { fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0) }
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Groovy
Groovy
import static Complex.*   Number.metaClass.mixin ComplexCategory   def π = Math.PI def e = Math.E   println "e ** (π * i) + 1 = " + (e ** (π * i) + 1)   println "| e ** (π * i) + 1 | = " + (e ** (π * i) + 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 ...
#Softbridge_BASIC
Softbridge BASIC
  Function Fibonacci(n) x = 0 y = 1 i = 0 n = ABS(n) If n < 2 Then Fibonacci = n Else Do Until (i = n) sum = x+y x=y y=sum i=i+1 Loop Fibonacci = x End If   End Function  
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Kotlin
Kotlin
fun facti(n: Int) = when { n < 0 -> throw IllegalArgumentException("negative numbers not allowed") else -> { var ans = 1L for (i in 2..n) ans *= i ans } }   fun factr(n: Int): Long = when { n < 0 -> throw IllegalArgumentException("negative numbers not allowed") n < 2 -> 1L ...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Haskell
Haskell
import Data.Complex   eulerIdentityZeroIsh :: Complex Double eulerIdentityZeroIsh = exp (0 :+ pi) + 1   main :: IO () main = print eulerIdentityZeroIsh
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#J
J
  NB. Euler's number is the default base for power NB. using j's expressive numeric notation: 1 + ^ 0j1p1 0j1.22465e_16     NB. Customize the comparison tolerance to 10 ^ (-15) NB. to show that _1 (=!.1e_15) ^ 0j1p1 1       TAU =: 2p1   NB. tauday.com pi is wrong NB. with TAU as 2 pi, NB....
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 ...
#Spin
Spin
con _clkmode = xtal1 + pll16x _clkfreq = 80_000_000   obj ser : "FullDuplexSerial.spin"   pub main | i ser.start(31, 30, 0, 115200)   repeat i from 0 to 10 ser.dec(fib(i)) ser.tx(32)   waitcnt(_clkfreq + cnt) ser.stop cogstop(0)   pub fib(i) : b | a b := a := 1 repeat i a := b + (b :=...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lambdatalk
Lambdatalk
  {def fac {lambda {:n} {if {< :n 1} then 1 else {long_mult :n {fac {- :n 1}}}}}}   {fac 6} -> 720   {fac 100} -> 93326215443944152681699238856266700490715968264381621468592963895217599993229 915608941463976156518286253697920827223758251185210916864000000000000000000000000  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Java
Java
  public class EulerIdentity {   public static void main(String[] args) { System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0))); }   public static class Complex {   private double x, y;   public Complex(double re, double im) { x ...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#jq
jq
def multiply(x; y): if (x|type) == "number" then if (y|type) == "number" then [ x*y, 0 ] else [x * y[0], x * y[1]] end elif (y|type) == "number" then multiply(y;x) else [ x[0] * y[0] - x[1] * y[1], x[0] * y[1] + x[1] * y[0]] end;   def plus(x; y): if (x|type) == "number" then ...
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 ...
#SPL
SPL
fibo(n)= s5 = #.sqrt(5) <= (((1+s5)/2)^n-((1-s5)/2)^n)/s5 .
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lang5
Lang5
 : fact iota 1 + '* reduce ; 5 fact 120  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Julia
Julia
@show ℯ^(π * im) + 1 @assert ℯ^(π * im) ≈ -1
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Kotlin
Kotlin
// Version 1.2.40   import kotlin.math.sqrt import kotlin.math.PI   const val EPSILON = 1.0e-16 const val SMALL_PI = '\u03c0' const val APPROX_EQUALS = '\u2245'   class Complex(val real: Double, val imag: Double) { operator fun plus(other: Complex) = Complex(real + other.real, imag + other.imag)   opera...
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 ...
#SQL
SQL
  SELECT round ( EXP ( SUM (ln ( ( 1 + SQRT( 5 ) ) / 2) ) OVER ( ORDER BY level ) ) / SQRT( 5 ) ) fibo FROM dual CONNECT BY level <= 10;  
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#langur
langur
val .factorial = f fold(f .x x .y, pseries .n) writeln .factorial(7)
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Lambdatalk
Lambdatalk
  {require lib_complex}   '{C.exp {C.mul {C.new 0 1} {C.new {PI} 0}}} // e^πi = exp( [π,0] * [0,1] ) -> (-1 1.2246467991473532e-16) // = -1  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Lua
Lua
local c = { new = function(s,r,i) s.__index=s return setmetatable({r=r, i=i}, s) end, add = function(s,o) return s:new(s.r+o.r, s.i+o.i) end, exp = function(s) local e=math.exp(s.r) return s:new(e*math.cos(s.i), e*math.sin(s.i)) end, mul = function(s,o) return s:new(s.r*o.r+s.i*o.i, s.r*o.i+s.i*o.r) end } local...
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 ...
#SSEM
SSEM
10101000000000100000000000000000 0. -21 to c acc = -n 01101000000001100000000000000000 1. c to 22 temp = acc 00101000000001010000000000000000 2. Sub. 20 acc -= m 10101000000001100000000000000000 3. c to 21 n = acc 10101000000000100000000000000000 4. -21 to c acc = -n 1010100000000110000...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lasso
Lasso
define factorial(n) => { local(x = 1) with i in generateSeries(2, #n) do { #x *= #i } return #x }
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
E^(I Pi) + 1
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Nim
Nim
import math, complex   echo "exp(iπ) + 1 = ", exp(complex(0.0, PI)) + 1, " ~= 0"
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#OCaml
OCaml
# open Complex;; # let pi = acos (-1.0);; val pi : float = 3.14159265358979312 # add (exp { re = 0.0; im = pi }) { re = 1.0; im = 0.0 };; - : Complex.t = {re = 0.; im = 1.22464679914735321e-16}
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 ...
#Stata
Stata
program fib args n clear qui set obs `n' qui gen a=1 qui replace a=a[_n-1]+a[_n-2] in 3/l end
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Latitude
Latitude
factorial := { 1 upto ($1 + 1) product. }.
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Perl
Perl
use Math::Complex; print exp(pi * i) + 1, "\n";
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Phix
Phix
with javascript_semantics include builtins\complex.e complex i = complex_new(0,1), res = complex_add(complex_exp(complex_mul(PI,i)),1) ?complex_sprint(res,both:=true) ?complex_sprint(complex_round(res,1e16),true) ?complex_sprint(complex_round(res,1e15),true)
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 ...
#StreamIt
StreamIt
void->int feedbackloop Fib { join roundrobin(0,1); body in->int filter { work pop 1 push 1 peek 2 { push(peek(0) + peek(1)); pop(); } }; loop Identity<int>; split duplicate; enqueue(0); enqueue(1); }
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#LFE
LFE
  (defun factorial (n) (cond ((== n 0) 1) ((> n 0) (* n (factorial (- n 1))))))  
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Prolog
Prolog
  % reduce() prints the intermediate results so that one can see Prolog "thinking." % reduce(A, C) :- simplify(A, B), (B = A -> C = A; io:format("= ~w~n", [B]), reduce(B, C)).   simplify(exp(i*X), cos(X) + i*sin(X)) :- !.   simplify(0 + A, A) :- !. simplify(A + 0, A) :- !. simplify(A + B, C) :- integer(A), ...
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 ...
#SuperCollider
SuperCollider
  f = { |n| if(n < 2) { n } { f.(n-1) + f.(n-2) } }; (0..20).collect(f)  
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Liberty_BASIC
Liberty BASIC
for i =0 to 40 print " FactorialI( "; using( "####", i); ") = "; factorialI( i) print " FactorialR( "; using( "####", i); ") = "; factorialR( i) next i   wait   function factorialI( n) if n >1 then f =1 For i = 2 To n f = f * i ...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Python
Python
>>> import math >>> math.e ** (math.pi * 1j) + 1 1.2246467991473532e-16j
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#R
R
# lang R exp(1i * pi) + 1
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Racket
Racket
#lang racket (+ (exp (* 0+i pi)) 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 ...
#Swift
Swift
import Cocoa   func fibonacci(n: Int) -> Int { let square_root_of_5 = sqrt(5.0) let p = (1 + square_root_of_5) / 2 let q = 1 / p return Int((pow(p,CDouble(n)) + pow(q,CDouble(n))) / square_root_of_5 + 0.5) }   for i in 1...30 { println(fibonacci(i)) }
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lingo
Lingo
on fact (n) if n<=1 then return 1 return n * fact(n-1) end
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Raku
Raku
sub infix:<⁢> is tighter(&infix:<**>) { $^a * $^b };   say 'e**i⁢π + 1 ≅ 0 : ', e**i⁢π + 1 ≅ 0; say 'Error: ', e**i⁢π + 1;
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#REXX
REXX
/*REXX program proves Euler's identity by showing that: e^(i pi) + 1 ≡ 0 */ numeric digits length( pi() ) - length(.) /*define pi; set # dec. digs precision*/ cosPI= fmt( cos(pi) ) /*calculate the value of cos(pi). */ sinPI= fmt( sin(pi) ) ...
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#11l
11l
F euler(f, y0, a, b, h) V t = a V y = y0 L t <= b print(‘#2.3 #2.3’.format(t, y)) t += h y += h * f(t, y)   V newtoncooling = (time, temp) -> -0.07 * (temp - 20)   euler(newtoncooling, 100.0, 0.0, 100.0, 10.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 ...
#Tailspin
Tailspin
  templates nthFibonacci when <=0|=1> do $ ! otherwise ($ - 1 -> #) + ($ - 2 -> #) ! end nthFibonacci  
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lisaac
Lisaac
- factorial x : INTEGER : INTEGER <- ( + result : INTEGER; (x <= 1).if { result := 1; } else { result := x * factorial(x - 1); }; result );
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Ruby
Ruby
  include Math   E ** (PI * 1i) + 1 # => (0.0+0.0i)
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Rust
Rust
use std::f64::consts::PI;   extern crate num_complex; use num_complex::Complex;   fn main() { println!("{:e}", Complex::new(0.0, PI).exp() + 1.0); }
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Scala
Scala
import spire.math.{Complex, Real}   object Scratch extends App{ //Declare values with friendly names to clean up the final expression val e = Complex[Real](Real.e, 0) val pi = Complex[Real](Real.pi, 0) val i = Complex[Real](0, 1) val one = Complex.one[Real]   println(e.pow(pi*i) + one) }
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#Ada
Ada
  generic type Number is digits <>; package Euler is type Waveform is array (Integer range <>) of Number; function Solve ( F  : not null access function (T, Y : Number) return Number; Y0  : Number; T0, T1 : Number; N  : Positive )...
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 ...
#Tcl
Tcl
proc fibiter n { if {$n < 2} {return $n} set prev 1 set fib 1 for {set i 2} {$i < $n} {incr i} { lassign [list $fib [incr fib $prev]] prev fib } return $fib }
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#C.2B.2B
C++
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <map> #include <vector>   #include <primesieve.hpp>   class erdos_selfridge { public: explicit erdos_selfridge(int limit); uint64_t get_prime(int index) const { return primes_[index].first; } int get_category(int index);...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Little_Man_Computer
Little Man Computer
  // Little Man Computer // Reads an integer n and prints n factorial // Works for n = 0..6 LDA one // initialize factorial to 1 STA fac INP // get n from user BRZ done // if n = 0, return 1 STA n // else store n LDA one // initialize k = 1 outer STA...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Scheme
Scheme
; A way to get pi. (define pi (acos -1))   ; Print the value of e^(i*pi) + 1 -- should be 0. (printf "e^(i*pi) + 1 = ~a~%" (+ (exp (* +i pi)) 1))
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Sidef
Sidef
say ('e**i⁢π + 1 ≅ 0 : ', Num.e**Num.pi.i + 1 ≅ 0) say ('Error: ', Num.e**Num.pi.i + 1)
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#ALGOL_68
ALGOL 68
# Approximates y(t) in y'(t)=f(t,y) with y(a)=y0 and t=a..b and the step size h. # PROC euler = (PROC(REAL,REAL)REAL f, REAL y0, a, b, h)REAL: ( REAL y := y0, t := a; WHILE t < b DO printf(($g(-6,3)": "g(-7,3)l$, t, y)); y +:= h * f(t, y); t +:= h OD; printf($"done"l$); y ...
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 ...
#Tern
Tern
func fib(n) { if (n < 2) { return 1; } return fib(n - 1) + fib(n - 2); }
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#F.23
F#
  // Erdös-Selfridge categorization of primes. Nigel Galloway: April 12th., 2022 let rec fG n g=match n,g with ((_,1),_)|(_,[])->n |((_,p),h::_) when h>p->n |((p,q),h::_) when q%h=0->fG (p,q/h) g |(_,_::g)->fG n g let fN g=Seq.unfold(fun(n,g)->let n,g=n|>List.map(fun n->fG n g)|>List.partition(fun(_,n)->n<>1) in let g=...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#LiveCode
LiveCode
// recursive function factorialr n if n < 2 then return 1 else return n * factorialr(n-1) end if end factorialr   // using accumulator function factorialacc n acc if n = 0 then return acc else return factorialacc(n-1, n * acc) end if end factorialacc   function f...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Tcl
Tcl
# Set up complex sandbox (since we're doing a star import) namespace eval complex_ns { package require math::complexnumbers namespace import ::math::complexnumbers::*   set pi [expr {acos(-1)}]   set r [+ [exp [complex 0 $pi]] [complex 1 0]] puts "e**(pi*i) = [real $r]+[imag $r]i" }
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#Wren
Wren
import "/complex" for Complex   System.print((Complex.new(0, Num.pi).exp + Complex.one).toString)
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#ALGOL_W
ALGOL W
begin % Euler's method %  % Approximates y(t) in y'(t)=f(t,y) with y(a)=y0 and t=a..b and the step size h. % real procedure euler ( real procedure f; real value y0, a, b, h ) ; begin real y, t; y := y0; t := a; while t < b do begin write( r_format := "A", r_w := 8,...
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#BASIC
BASIC
PROCeuler("-0.07*(y-20)", 100, 0, 100, 2) PROCeuler("-0.07*(y-20)", 100, 0, 100, 5) PROCeuler("-0.07*(y-20)", 100, 0, 100, 10) END   DEF PROCeuler(df$, y, a, b, s) LOCAL t, @% @% = &2030A t = a WHILE t <= b PRINT t, y y += s * EVAL(df$) t += ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#TI-83_BASIC
TI-83 BASIC
[Y=] nMin=0 u(n)=u(n-1)+u(n-2) u(nMin)={1,0} [TABLE] n u(n) ------- ------- 0 0 1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21 9 34 10 55 11 89 12 144
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Factor
Factor
USING: assocs combinators formatting grouping grouping.extras io kernel math math.primes math.primes.factors math.statistics prettyprint sequences sequences.deep ;   PREDICATE: >3 < integer 3 > ;   GENERIC: depth ( seq -- n )   M: sequence depth 0 swap [ flatten1 [ 1 + ] dip ] to-fixed-point drop ;   M: integer dep...
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Go
Go
package main   import ( "fmt" "math" "rcu" )   var limit = int(math.Log(1e6) * 1e6 * 1.2) // should be more than enough var primes = rcu.Primes(limit)   var prevCats = make(map[int]int)   func cat(p int) int { if v, ok := prevCats[p]; ok { return v } pf := rcu.PrimeFactors(p + 1) all...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#LLVM
LLVM
; ModuleID = 'factorial.c' ; source_filename = "factorial.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 wo...
http://rosettacode.org/wiki/Euler%27s_identity
Euler's identity
This page uses content from Wikipedia. The original article was at Euler's_identity. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In mathematics, Euler's identity is the equality: ...
#zkl
zkl
var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library) Z,pi,e := GSL.Z, (0.0).pi, (0.0).e;   println("e^(\u03c0i) + 1 = %s \u2245 0".fmt( Z(e).pow(Z(0,1)*pi) + 1 )); println("TMI: ",(Z(e).pow(Z(0,1)*pi) + 1 ).format(0,25,"g"));
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#C
C
#include <stdio.h> #include <math.h>   typedef double (*deriv_f)(double, double); #define FMT " %7.3f"   void ivp_euler(deriv_f f, double y, int step, int end_t) { int t = 0;   printf(" Step %2d: ", (int)step); do { if (t % 10 == 0) printf(FMT, y); y += step * f(t, y); } while ((t += step) <= end_t); printf("\...
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 ...
#TI-89_BASIC
TI-89 BASIC
fib(n) when(n<2, n, fib(n-1) + fib(n-2))
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Java
Java
import java.util.*;   public class ErdosSelfridge { private int[] primes; private int[] category;   public static void main(String[] args) { ErdosSelfridge es = new ErdosSelfridge(1000000);   System.out.println("First 200 primes:"); for (var e : es.getPrimesByCategory(200).entrySet()...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Logo
Logo
to factorial :n if :n < 2 [output 1] output :n * factorial :n-1 end
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#C.23
C#
using System;   namespace prog { class MainClass { const float T0 = 100f; const float TR = 20f; const float k = 0.07f; readonly static float[] delta_t = {2.0f,5.0f,10.0f}; const int n = 100;   public delegate float func(float t); static float NewtonCooling(float t) { return -k * (t-TR); }   ...
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 ...
#Tiny_BASIC
Tiny BASIC
10 LET A = 0 20 LET B = 1 30 PRINT "Which F_n do you want?" 40 INPUT N 50 IF N = 0 THEN GOTO 140 60 IF N = 1 THEN GOTO 120 70 LET C = B + A 80 LET A = B 90 LET B = C 100 LET N = N - 1 110 GOTO 60 120 PRINT B 130 END 140 PRINT 0 150 END  
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Julia
Julia
using Primes   primefactors(n) = collect(keys(factor(n)))   function ErdösSelfridge(n) highfactors = filter(>(3), primefactors(n + 1)) category = 1 while !isempty(highfactors) highfactors = unique(reduce(vcat, [filter(>(3), primefactors(a + 1)) for a in highfactors])) category += 1 end ...
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Perl
Perl
use strict; use warnings; use feature 'say'; use List::Util 'max'; use ntheory qw/factor/; use Primesieve qw(generate_primes);   my @primes = (0, generate_primes (1, 10**8)); my %cat = (2 => 1, 3 => 1);   sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }   sub ES { my ($n) = @_; my @factors ...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#LOLCODE
LOLCODE
HAI 1.3   HOW IZ I Faktorial YR Number BOTH SAEM 1 AN BIGGR OF Number AN 1 O RLY? YA RLY FOUND YR 1 NO WAI FOUND YR PRODUKT OF Number AN I IZ Faktorial YR DIFFRENCE OF Number AN 1 MKAY OIC IF U SAY SO   IM IN YR LOOP UPPIN YR Index WILE DIFFRINT Index AN 13 VISIBLE Index "! = " I IZ Faktorial YR ...
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#C.2B.2B
C++
#include <iomanip> #include <iostream>   typedef double F(double,double);   /* Approximates y(t) in y'(t)=f(t,y) with y(a)=y0 and t=a..b and the step size h. */ void euler(F f, double y0, double a, double b, double h) { double y = y0; for (double t = a; t < b; t += h) { std::cout << std::fixed << st...
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 ...
#True_BASIC
True BASIC
FUNCTION fibonacci (n) LET n1 = 0 LET n2 = 1 FOR k = 1 TO ABS(n) LET sum = n1 + n2 LET n1 = n2 LET n2 = sum NEXT k IF n < 0 THEN LET fibonacci = n1 * ((-1) ^ ((-n) + 1)) ELSE LET fibonacci = n1 END IF END FUNCTION   PRINT fibonacci(0)  ! 0 PRINT fibo...
http://rosettacode.org/wiki/Esthetic_numbers
Esthetic numbers
An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1. E.G. 12 is an esthetic number. One and two differ by 1. 5654 is an esthetic number. Each digit is exactly 1 away from its neighbour. 890 is not an esthetic number. Nine and zero differ by 9. These examples are n...
#11l
11l
F isEsthetic(=n, b) I n == 0 {R 0B} V i = n % b n I/= b L n > 0 V j = n % b I abs(i - j) != 1 R 0B n I/= b i = j R 1B   F listEsths(Int64 n1, n2, m1, m2; perLine, all) [Int64] esths   F dfs(Int64 n, m, i) -> N I i C n .. m @esths.append(i) I i =...
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Phix
Phix
with javascript_semantics sequence escache = {} function es_cat(integer p) if p>length(escache) and platform()!=JS then escache &= repeat(0,p-length(escache)) end if integer category = escache[p] if not category then sequence f = filter(prime_factors(p+1,false,-1),">",3) categor...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Lua
Lua
function fact(n) return n > 0 and n * fact(n-1) or 1 end
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#Clay
Clay
  import printer.formatter as pf;   euler(f, y, a, b, h) { while (a < b) { println(pf.rightAligned(2, a), " ", y); a += h; y += h * f(y); } }   main() { for (i in [2.0, 5.0, 10.0]) { println("\nFor delta = ", i, ":"); euler((temp) => -0.07 * (temp - 20), 100.0, 0.0, 1...
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#Clojure
Clojure
(ns newton-cooling (:gen-class))   (defn euler [f y0 a b h] "Euler's Method. Approximates y(time) in y'(time)=f(time,y) with y(a)=y0 and t=a..b and the step size h." (loop [t a y y0 result []] (if (<= t b) (recur (+ t h) (+ y (* (f (+ t h) y) h)) (conj result [(double t) (double y)...
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 ...
#TSE_SAL
TSE SAL
    // library: math: get: series: fibonacci <description></description> <version control></version control> <version>1.0.0.0.3</version> <version control></version control> (filenamemacro=getmasfi.s) [<Program>] [<Research>] [kn, ri, su, 20-01-2013 22:04:02] INTEGER PROC FNMathGetSeriesFibonacciI( INTEGER nI ) // /...
http://rosettacode.org/wiki/Esthetic_numbers
Esthetic numbers
An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1. E.G. 12 is an esthetic number. One and two differ by 1. 5654 is an esthetic number. Each digit is exactly 1 away from its neighbour. 890 is not an esthetic number. Nine and zero differ by 9. These examples are n...
#ALGOL_68
ALGOL 68
BEGIN # find some esthetic numbers: numbers whose successive digits differ by 1 # # returns TRUE if n is esthetic in the specified base, FALSE otherwise # PRIO ISESTHETIC = 1; OP ISESTHETIC = ( INT n, base )BOOL: BEGIN INT v := ABS n; BOOL is esthetic := TRU...
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Raku
Raku
use Prime::Factor; use Lingua::EN::Numbers; use Math::Primesieve; my $sieve = Math::Primesieve.new;   my %cat = 2 => 1, 3 => 1;   sub Erdös-Selfridge ($n) { my @factors = prime-factors $n + 1; my $category = max %cat{ @factors }; unless %cat{ @factors[*-1] } { $category max= ( 1 + max %cat{ prime-fa...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { Locale 1033 ' ensure #,### print with comma Function factorial (n){ If n<0 then Error "Factorial Error!" If n>27 then Error "Overflow"   m=1@:While n>1 {m*=n:n--}:=m } Const Proportional=4 Const ProportionalLeftJustification=5 Co...
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#0815
0815
  }:s:|=<:2:x~#:e:=/~%~<:20:~$=<:73:x<:69:~$~$~<:20:~$=^:o:<:65: x<:76:=$=$~$<:6E:~$<:a:~$^:s:}:o:<:6F:x<:64:x~$~$$<:a:~$^:s:  
http://rosettacode.org/wiki/Euler_method
Euler method
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value.   It is an explicit method for solving initial value problems (IVPs), as described in the wikipedia page. The ODE has to be provided in the following form: d y ( t ) d t = f...
#COBOL
COBOL
DELEGATE-ID func. PROCEDURE DIVISION USING VALUE t AS FLOAT-LONG RETURNING ret AS FLOAT-LONG. END DELEGATE.   CLASS-ID. MainClass.   78 T0 VALUE 100.0. 78 TR VALUE 20.0. 78 k VALUE 0.07.   ...
http://rosettacode.org/wiki/Evaluate_binomial_coefficients
Evaluate binomial coefficients
This programming task, is to calculate ANY binomial coefficient. However, it has to be able to output   ( 5 3 ) {\displaystyle {\binom {5}{3}}} ,   which is   10. This formula is recommended: ( n k ) = n ! ( n − k ) ! k ! = n ( n − 1 ) ( n − 2 ) … ( n − k + 1 ) k ( k − 1...
#11l
11l
F binomial_coeff(n, k) V result = 1 L(i) 1..k result = result * (n - i + 1) / i R result   print(binomial_coeff(5, 3))
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 ...
#Turing
Turing
% Recursive function fibb (n: int) : int if n < 2 then result n else result fibb (n-1) + fibb (n-2) end if end fibb   % Iterative function ifibb (n: int) : int var a := 0 var b := 1 for : 1 .. n a := a + b b := a - b end for result a end ifibb   for i : ...
http://rosettacode.org/wiki/Esthetic_numbers
Esthetic numbers
An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1. E.G. 12 is an esthetic number. One and two differ by 1. 5654 is an esthetic number. Each digit is exactly 1 away from its neighbour. 890 is not an esthetic number. Nine and zero differ by 9. These examples are n...
#Arturo
Arturo
esthetic?: function [n, b][ if n=0 -> return false k: n % b l: n / b   while [l>0][ j: l % b if 1 <> abs k-j -> return false l: l / b k: j ] return true ]   HEX: "0000000000ABCDEF"   getHex: function [ds][ map ds 'd [ (d < 10)? -> to :string d ...
http://rosettacode.org/wiki/Erd%C3%B6s-Selfridge_categorization_of_primes
Erdös-Selfridge categorization of primes
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the firs...
#Rust
Rust
// [dependencies] // primal = "0.3"   use std::collections::BTreeMap;   struct ErdosSelfridge { primes: Vec<usize>, category: Vec<u32>, }   impl ErdosSelfridge { fn new(limit: usize) -> ErdosSelfridge { let mut es = ErdosSelfridge { primes: primal::Primes::all().take(limit).collect(), ...