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/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#AWK
AWK
1
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Axe
Axe
:.PRGMNAME :
http://rosettacode.org/wiki/Enforced_immutability
Enforced immutability
Task Demonstrate any means your language has to prevent the modification of values, or to create objects that cannot be modified after they have been created.
#Wren
Wren
class A { construct new(f) { _f = f // sets field _f to the argument f }   // getter property to allow access to _f f { _f }   // setter property to allow _f to be mutated f=(other) { _f = other } }   var a = A.new(6) System.print(a.f) a.f = 8 System.print(a.f)
http://rosettacode.org/wiki/Enforced_immutability
Enforced immutability
Task Demonstrate any means your language has to prevent the modification of values, or to create objects that cannot be modified after they have been created.
#Z80_Assembly
Z80 Assembly
List: byte 2,3,4,5,6 ;this could be either mutable or immutable, it depends on the hardware.
http://rosettacode.org/wiki/Enforced_immutability
Enforced immutability
Task Demonstrate any means your language has to prevent the modification of values, or to create objects that cannot be modified after they have been created.
#zkl
zkl
List(1,2,3).del(0) //--> L(2,3) ROList(1,2,3).del(0) //-->SyntaxError : Can't find del, which means you can't call it d:=Dictionary(); d.add("one",1) D(one:1) d.makeReadOnly(); d.add("2",2) //-->AccessError(This Dictionary is read only)
http://rosettacode.org/wiki/Entropy
Entropy
Task Calculate the Shannon entropy   H   of a given input string. Given the discrete random variable X {\displaystyle X} that is a string of N {\displaystyle N} "symbols" (total characters) consisting of n {\displaystyle n} different characters (n=2 for binary), the Shannon entropy of X in bit...
#EchoLisp
EchoLisp
  (lib 'hash) ;; counter: hash-table[key]++ (define (count++ ht k ) (hash-set ht k (1+ (hash-ref! ht k 0))))   (define (hi count n ) (define pi (// count n)) (- (* pi (log2 pi))))   ;; (H [string|list]) → entropy (bits) (define (H info) (define S (if(string? info) (string->list info) info)) (define ht (make-hash))...
http://rosettacode.org/wiki/Ethiopian_multiplication
Ethiopian multiplication
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. Method: Take two numbers to be multiplied and write them down at the top of two columns. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ...
#D
D
int ethiopian(int n1, int n2) pure nothrow @nogc in { assert(n1 >= 0, "Multiplier can't be negative"); } body { static enum doubleNum = (in int n) pure nothrow @nogc => n * 2; static enum halveNum = (in int n) pure nothrow @nogc => n / 2; static enum isEven = (in int n) pure nothrow @nogc => !(n & 1);  ...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#Logo
Logo
to equilibrium.iter :i :before :after :tail :ret if equal? :before :after [make "ret lput :i :ret] if empty? butfirst :tail [output :ret] output equilibrium.iter :i+1 (:before+first :tail) (:after-first butfirst :tail) (butfirst :tail) :ret end to equilibrium.index :list output equilibrium.iter 1 0 (apply "sum ...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#Lua
Lua
  function array_sum(t) assert(type(t) == "table", "t must be a table!") local sum = 0 for i=1, #t do sum = sum + t[i] end return sum end   function equilibrium_index(t) assert(type(t) == "table", "t must be a table!") local left, right, ret = 0, array_sum(t), -1 for i,j in pairs(t) do right ...
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Python
Python
import os os.environ['HOME']
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#R
R
Sys.getenv("PATH")
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Racket
Racket
  #lang racket (getenv "HOME")  
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Raku
Raku
say %*ENV<HOME>;
http://rosettacode.org/wiki/Euler%27s_sum_of_powers_conjecture
Euler's sum of powers conjecture
There is a conjecture in mathematics that held for over two hundred years before it was disproved by the finding of a counterexample in 1966 by Lander and Parkin. Euler's (disproved) sum of powers   conjecture At least k positive kth powers are required to sum to a kth power, except for the trivial case...
#JavaScript
JavaScript
var eulers_sum_of_powers = function (iMaxN) {   var aPow5 = []; var oPow5ToN = {};   for (var iP = 0; iP <= iMaxN; iP++) { var iPow5 = Math.pow(iP, 5); aPow5.push(iPow5); oPow5ToN[iPow5] = iP; }   for (var i0 = 1; i0 <= iMaxN; i0++) { for (var i1 = 1; i1 <= i0; i1++) ...
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...
#Octave
Octave
% built in factorial printf("%d\n", factorial(50));   % let's define our recursive... function fact = my_fact(n) if ( n <= 1 ) fact = 1; else fact = n * my_fact(n-1); endif endfunction   printf("%d\n", my_fact(50));   % let's define our iterative function fact = iter_fact(n) fact = 1; for i = 2:n ...
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...
#Delphi
Delphi
  program EvenOdd;   {$APPTYPE CONSOLE}   {$R *.res}   uses System.SysUtils;   procedure IsOdd(aValue: Integer); var Odd: Boolean; begin Odd := aValue and 1 <> 0; Write(Format('%d is ', [aValue])); if Odd then Writeln('odd') else Writeln('even'); end;   var i: Integer; begin for i := -5 to 10 d...
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...
#Vlang
Vlang
import math // Fdy is a type for fntion f used in Euler's method. type Fdy = fn(f64, f64) f64   // euler_step computes a single new value using Euler's method. // Note that step size h is a parameter, so a variable step size // could be used. fn euler_step(f Fdy, x f64, y f64, h f64) f64 { return y + h*f(x, y) }   ...
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...
#MATLAB_.2F_Octave
MATLAB / Octave
>> nchoosek(5,3) ans = 10
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...
#Maxima
Maxima
binomial( 5, 3); /* 10 */ binomial(-5, 3); /* -35 */ binomial( 5, -3); /* 0 */ binomial(-5, -3); /* 0 */ binomial( 3, 5); /* 0 */   binomial(x, 3); /* ((x - 2)*(x - 1)*x)/6 */   binomial(3, 1/2); /* binomial(3, 1/2) */ makegamma(%); /* 32/(5*%pi) */   binomial(a, b); ...
http://rosettacode.org/wiki/Emirp_primes
Emirp primes
An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.) Task   show the first   twenty   emirps   show all emirps between   7,700   and   8,000   show the   10,000th   emirp In each list, the numbe...
#D
D
bool isEmirp(uint n) pure nothrow @nogc { bool isPrime(in uint n) pure nothrow @nogc { if (n == 2 || n == 3) return true; else if (n < 2 || n % 2 == 0 || n % 3 == 0) return false; for (uint div = 5, inc = 2; div ^^ 2 <= n; div += inc, inc = 6 - inc) ...
http://rosettacode.org/wiki/Elliptic_curve_arithmetic
Elliptic curve arithmetic
Elliptic curves   are sometimes used in   cryptography   as a way to perform   digital signatures. The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   elliptic curve DSA   protocol. In a nutshell, an elliptic curve is a...
#Racket
Racket
  #lang racket (define a 0) (define b 7) (define (ε? x) (<= (abs x) 1e-14)) (define (== p q) (for/and ([pi p] [qi q]) (ε? (- pi qi)))) (define zero #(0 0)) (define (zero? p) (== p zero)) (define (neg p) (match-define (vector x y) p) (vector x (- y))) (define (⊕ p q) (cond [(== q (neg p)) zero] [else ...
http://rosettacode.org/wiki/Elliptic_curve_arithmetic
Elliptic curve arithmetic
Elliptic curves   are sometimes used in   cryptography   as a way to perform   digital signatures. The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   elliptic curve DSA   protocol. In a nutshell, an elliptic curve is a...
#Raku
Raku
unit module EC; our ($A, $B) = (0, 7);   role Horizon { method gist { 'EC Point at horizon' } } class Point { has ($.x, $.y); multi method new( $x, $y where $y**2 ~~ $x**3 + $A*$x + $B ) { self.bless(:$x, :$y) } multi method new(Horizon $) { self.bless but Horizon } method gist { "EC Point a...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#OxygenBasic
OxygenBasic
  enum fruits apple pear orange = 14 banana mango end enum   print banana '15   'fruits values: ' apple 0 ' pear 1 ' orange 14 ' banana 15 ' mango 16  
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Oz
Oz
declare fun {IsFruit A} {Member A [apple banana cherry]} end in {Show {IsFruit banana}}
http://rosettacode.org/wiki/Empty_string
Empty string
Languages may have features for dealing specifically with empty strings (those containing no characters). Task   Demonstrate how to assign an empty string to a variable.   Demonstrate how to check that a string is empty.   Demonstrate how to check that a string is not empty. Other tasks related to string oper...
#C
C
#include <string.h>   /* ... */   /* assign an empty string */ const char *str = "";   /* to test a null string */ if (str) { ... }   /* to test if string is empty */ if (str[0] == '\0') { ... }   /* or equivalently use strlen function strlen will seg fault on NULL pointer, so check first */ if ( (str == NULL) || (...
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#Liberty_BASIC
Liberty BASIC
  dim info$(10, 10) files "c:\", info$()   qtyFiles=val(info$(0,0)) n = qtyFiles+1 'begin directory info   folder$ = info$(n,0) 'path to first directory in c:   files folder$, info$() 're-fill array with data from sub folder   if val(info$(0,0)) + val(info$(0, 1)) <> 0 then print "Folder ";folder$;" is not empty....
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#Lingo
Lingo
on isDirEmpty (dir) return getNthFileNameInFolder(dir, 1) = EMPTY end
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#BASIC
BASIC
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Batch_File
Batch File
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#BaCon
BaCon
 
http://rosettacode.org/wiki/Entropy
Entropy
Task Calculate the Shannon entropy   H   of a given input string. Given the discrete random variable X {\displaystyle X} that is a string of N {\displaystyle N} "symbols" (total characters) consisting of n {\displaystyle n} different characters (n=2 for binary), the Shannon entropy of X in bit...
#Elena
Elena
import system'math; import system'collections; import system'routines; import extensions;   extension op { logTwo() = self.ln() / 2.ln(); }   public program() { var input := console.readLine(); var infoC := 0.0r; var table := Dictionary.new();   input.forEach:(ch) { var n := tabl...
http://rosettacode.org/wiki/Entropy
Entropy
Task Calculate the Shannon entropy   H   of a given input string. Given the discrete random variable X {\displaystyle X} that is a string of N {\displaystyle N} "symbols" (total characters) consisting of n {\displaystyle n} different characters (n=2 for binary), the Shannon entropy of X in bit...
#Elixir
Elixir
defmodule RC do def entropy(str) do leng = String.length(str) String.graphemes(str) |> Enum.group_by(&(&1)) |> Enum.map(fn{_,value} -> length(value) end) |> Enum.reduce(0, fn count, entropy -> freq = count / leng entropy - freq * :math.log2(freq) end) end end   IO.inspec...
http://rosettacode.org/wiki/Ethiopian_multiplication
Ethiopian multiplication
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. Method: Take two numbers to be multiplied and write them down at the top of two columns. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ...
#dc
dc
0k [ Make sure we're doing integer division ]sx [ 2 / ] sH [ Define "halve" function in register H ]sx [ 2 * ] sD [ Define "double" function in register D ]sx [ 2 % 1 r - ] sE [ Define "even?" function in register E ]sx   [ Entry into the main Ethiopian multiplication...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
equilibriumIndex[data_]:=Reap[ Do[If[Total[data[[;; n - 1]]] == Total[data[[n + 1 ;;]]],Sow[n]], {n, Length[data]}]][[2, 1]]
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#MATLAB
MATLAB
function indicies = equilibriumIndex(list)   indicies = [];   for i = (1:numel(list)) if ( sum(-list(1:i)) == sum(-list(i:end)) ) indicies = [indicies i]; end end   end
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#REBOL
REBOL
print get-env "HOME"
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Retro
Retro
here "HOME" getEnv here puts
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#REXX
REXX
/*REXX program shows how to get an environmental variable under Windows*/   x=value('TEMP',,'SYSTEM')
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Ring
Ring
  see get("path")  
http://rosettacode.org/wiki/Euler%27s_sum_of_powers_conjecture
Euler's sum of powers conjecture
There is a conjecture in mathematics that held for over two hundred years before it was disproved by the finding of a counterexample in 1966 by Lander and Parkin. Euler's (disproved) sum of powers   conjecture At least k positive kth powers are required to sum to a kth power, except for the trivial case...
#jq
jq
# Search for y in 1 .. maxn (inclusive) for a solution to SIGMA (xi ^ 5) = y^5 # and for each solution with x0<=x1<=...<x3, print [x0, x1, x3, x3, y] # def sum_of_powers_conjecture(maxn): def p5: . as $in | (.*.) | ((.*.) * $in); def fifth: log / 5 | exp;   # return the fifth root if . is a power of 5 def integ...
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...
#Oforth
Oforth
: fact(n) n ifZero: [ 1 ] else: [ n n 1- fact * ] ;
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...
#DWScript
DWScript
var isOdd := Odd(i);
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...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
even n: = 0 % n 2   odd: not even   !. odd 0 !. even 0 !. odd 7 !. even 7  
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...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   proc Euler(Step); \Display cooling temperatures using Euler's method int Step; int Time; real Temp; [Text(0, "Step "); IntOut(0, Step); Text(0, " "); Time:= 0; Temp:= 100.0; repeat if rem(Time/10) = 0 then RlOut(0, Temp); Temp:= Temp + float(...
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...
#Wren
Wren
import "/fmt" for Fmt import "/trait" for Stepped   var euler = Fn.new { |f, y, step, end| Fmt.write(" Step $2d: ", step) for (t in Stepped.new(0..end, step)) { if (t%10 == 0) Fmt.write(" $7.3f", y) y = y + step * f.call(y) } System.print() }   var analytic = Fn.new { System.write(" ...
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...
#min
min
((dup 0 ==) 'succ (dup pred) '* linrec) :fact ('dup dip dup ((fact) () (- fact) (fact * div)) spread) :binomial   5 3 binomial puts!
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...
#MINIL
MINIL
// Number of combinations nCr 00 0E Go: ENT R0 // n 01 1E ENT R1 // r 02 2C CLR R2 03 2A Loop: ADD1 R2 04 0D DEC R0 05 1D DEC R1 06 C3 JNZ Loop 07 3C CLR R3 // for result 08 3A ADD1 R3 09 0A Next: ADD1 R0 0A 1A ADD1 R1 0B 50 R5...
http://rosettacode.org/wiki/Emirp_primes
Emirp primes
An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.) Task   show the first   twenty   emirps   show all emirps between   7,700   and   8,000   show the   10,000th   emirp In each list, the numbe...
#Delphi
Delphi
defmodule Emirp do defp prime?(2), do: true defp prime?(n) when n<2 or rem(n,2)==0, do: false defp prime?(n), do: prime?(n,3)   defp prime?(n,k) when n<k*k, do: true defp prime?(n,k) when rem(n,k)==0, do: false defp prime?(n,k), do: prime?(n,k+2)   def emirp?(n) do if prime?(n) do reverse = to_s...
http://rosettacode.org/wiki/Emirp_primes
Emirp primes
An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.) Task   show the first   twenty   emirps   show all emirps between   7,700   and   8,000   show the   10,000th   emirp In each list, the numbe...
#Elixir
Elixir
defmodule Emirp do defp prime?(2), do: true defp prime?(n) when n<2 or rem(n,2)==0, do: false defp prime?(n), do: prime?(n,3)   defp prime?(n,k) when n<k*k, do: true defp prime?(n,k) when rem(n,k)==0, do: false defp prime?(n,k), do: prime?(n,k+2)   def emirp?(n) do if prime?(n) do reverse = to_s...
http://rosettacode.org/wiki/Elliptic_curve_arithmetic
Elliptic curve arithmetic
Elliptic curves   are sometimes used in   cryptography   as a way to perform   digital signatures. The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   elliptic curve DSA   protocol. In a nutshell, an elliptic curve is a...
#REXX
REXX
/*REXX program defines (for any 2 points on the curve), returns the sum of the 2 points.*/ numeric digits 100 /*try to ensure a min. of accuracy loss*/ a= func(1)  ; say ' a = ' show(a) b= func(2)  ; say ' b = ...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Pascal
Pascal
type phase = (red, green, blue);
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Perl
Perl
# Using an array my @fruits = qw(apple banana cherry);   # Using a hash my %fruits = ( apple => 0, banana => 1, cherry => 2 );
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Phix
Phix
enum apple, banana, orange enum apple=5, banana=10, orange=
http://rosettacode.org/wiki/Empty_string
Empty string
Languages may have features for dealing specifically with empty strings (those containing no characters). Task   Demonstrate how to assign an empty string to a variable.   Demonstrate how to check that a string is empty.   Demonstrate how to check that a string is not empty. Other tasks related to string oper...
#C.23
C#
using System;   class Program { static void Main (string[] args) { string example = string.Empty; if (string.IsNullOrEmpty(example)) { } if (!string.IsNullOrEmpty(example)) { } } }
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#Lua
Lua
  function scandir(directory) local i, t, popen = 0, {}, io.popen local pfile = popen('ls -a "'..directory..'"') for filename in pfile:lines() do if filename ~= '.' and filename ~= '..' then i = i + 1 t[i] = filename end end pfile:close() return t end   function isemptydir(directory) return #scandir(di...
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#Maple
Maple
  emptydirectory := proc (dir) is(listdir(dir) = [".", ".."]); end proc;  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#BASIC256
BASIC256
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#BBC_BASIC
BBC BASIC
 
http://rosettacode.org/wiki/Entropy
Entropy
Task Calculate the Shannon entropy   H   of a given input string. Given the discrete random variable X {\displaystyle X} that is a string of N {\displaystyle N} "symbols" (total characters) consisting of n {\displaystyle n} different characters (n=2 for binary), the Shannon entropy of X in bit...
#Emacs_Lisp
Emacs Lisp
(defun shannon-entropy (input) (let ((freq-table (make-hash-table)) (entropy 0) (length (+ (length input) 0.0))) (mapcar (lambda (x) (puthash x (+ 1 (gethash x freq-table 0)) freq-table)) input) (maphash (lambda (k v) (set 'entropy (+ entropy (* (/ v length) ...
http://rosettacode.org/wiki/Ethiopian_multiplication
Ethiopian multiplication
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. Method: Take two numbers to be multiplied and write them down at the top of two columns. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ...
#Delphi
Delphi
proc nonrec halve(word n) word: n >> 1 corp proc nonrec double(word n) word: n << 1 corp proc nonrec even(word n) bool: n & 1 = 0 corp   proc nonrec emul(word a, b) word: word total; total := 0; while a > 0 do if not even(a) then total := total + b fi; a := halve(a); b :=...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   numeric digits 20 runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- @see http://www.geeksforgeeks.org/equilibrium-index-of-an-array/ method equilibriumIndex(sequence) private static ...
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Ruby
Ruby
ENV['HOME']
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Run_BASIC
Run BASIC
' ------- Major environment variables ------------------------------------------- 'DefaultDir$ - The folder path where program files are read/written by default 'Platform$ - The operating system on which Run BASIC is being hosted 'UserInfo$ - This is information about the user's web browser 'UrlKeys$ ...
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Rust
Rust
use std::env;   fn main() { println!("{:?}", env::var("HOME")); println!(); for (k, v) in env::vars().filter(|(k, _)| k.starts_with('P')) { println!("{}: {}", k, v); } }  
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Scala
Scala
sys.env.get("HOME")
http://rosettacode.org/wiki/Euler%27s_sum_of_powers_conjecture
Euler's sum of powers conjecture
There is a conjecture in mathematics that held for over two hundred years before it was disproved by the finding of a counterexample in 1966 by Lander and Parkin. Euler's (disproved) sum of powers   conjecture At least k positive kth powers are required to sum to a kth power, except for the trivial case...
#Julia
Julia
  const lim = 250 const pwr = 5 const p = [i^pwr for i in 1:lim]   x = zeros(Int, pwr-1) y = 0   for a in combinations(1:lim, pwr-1) b = searchsorted(p, sum(p[a])) 0 < length(b) || continue x = a y = b[1] break end   if y == 0 println("No solution found for power = ", pwr, " and limit = ", lim, ...
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...
#Order
Order
#include <order/interpreter.h>   #define ORDER_PP_DEF_8fac \ ORDER_PP_FN(8fn(8N, \ 8if(8less_eq(8N, 0), \ 1, \ 8mul(8N, 8fac(8dec(8N))))))   ORDER_PP(8to_lit(8fac(8))) // 40320
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...
#EDSAC_order_code
EDSAC order code
[ Even or odd ===========   A program for the EDSAC   Determines whether the number stored at address 15@ is even or odd, and prints 'E' or 'O' accordingly   Works with Initial Orders 2 ]   T56K [ load point ] GK [ base address ]   O11@ [ print letter shift ] T10@ [ cle...
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...
#Eiffel
Eiffel
--bit testing if i.bit_and (1) = 0 then -- i is even end   --built-in bit testing (uses bit_and) if i.bit_test (0) then -- i is odd end   --integer remainder (modulo) if i \\ 2 = 0 then -- i is even 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...
#zkl
zkl
const FMT=" %7.3f";   fcn ivp_euler(f,y,step,end_t){ print(" Step %2d: ".fmt(step)); foreach t in ([0..end_t,step]){ if (t % 10 == 0) print(FMT.fmt(y)); y += f(t,y) * step; } println(); }   fcn analytic{ print(" Time: "); foreach t in ([0..100,10]){ print(" %7g".fmt(t)) } print("\nA...
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...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 LET d$="-0.07*(y-20)": LET y=100: LET a=0: LET b=100: LET s=10 20 LET t=a 30 IF t<=b THEN PRINT t;TAB 10;y: LET y=y+s*VAL d$: LET t=t+s: GO TO 30
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...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П1 <-> П0 ПП 22 П2 ИП1 ПП 22 П3 ИП0 ИП1 - ПП 22 ИП3 * П3 ИП2 ИП3 / С/П ВП П0 1 ИП0 * L0 25 В/О
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...
#Nanoquery
Nanoquery
def binomialCoeff(n, k) result = 1 for i in range(1, k) result = result * (n-i+1) / i end return result end   if main println binomialCoeff(5,3) end
http://rosettacode.org/wiki/Emirp_primes
Emirp primes
An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.) Task   show the first   twenty   emirps   show all emirps between   7,700   and   8,000   show the   10,000th   emirp In each list, the numbe...
#F.23
F#
  // Generate emirps. Nigel Galloway: November 19th., 2017 let emirp = let rec fN n g = match n with |0->g |_->fN (n/10) (g*10+n%10) let fG n g = n<>g && isPrime g primes32() |> Seq.filter (fun n -> fG n (fN n 0))  
http://rosettacode.org/wiki/Elliptic_curve_arithmetic
Elliptic curve arithmetic
Elliptic curves   are sometimes used in   cryptography   as a way to perform   digital signatures. The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   elliptic curve DSA   protocol. In a nutshell, an elliptic curve is a...
#Sage
Sage
Ellie = EllipticCurve(RR,[0,7]) # RR = field of real numbers   # a point (x,y) on Ellie, given y def point ( y) : x = var('x') x = (y^2 - 7 - x^3).roots(x,ring=RR,multiplicities = False)[0] P = Ellie([x,y]) return P   print(Ellie) P = point(1) print('P',P) Q = point(2) print('Q',Q) S = P+Q print('S = P ...
http://rosettacode.org/wiki/Elliptic_curve_arithmetic
Elliptic curve arithmetic
Elliptic curves   are sometimes used in   cryptography   as a way to perform   digital signatures. The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   elliptic curve DSA   protocol. In a nutshell, an elliptic curve is a...
#Sidef
Sidef
module EC {   var A = 0 var B = 7   class Horizon { method to_s { "EC Point at horizon" }   method *(_) { self }   method -(_) { self } }   class Point(Number x, Number y) { method to_s { "EC Poin...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#PHP
PHP
// Using an array/hash $fruits = array( "apple", "banana", "cherry" ); $fruits = array( "apple" => 0, "banana" => 1, "cherry" => 2 );   // If you are inside a class scope class Fruit { const APPLE = 0; const BANANA = 1; const CHERRY = 2; }   // Then you can access them as such $value = Fruit::APPLE;   // Or, you ...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Picat
Picat
fruit(apple,1). fruit(banana,2). fruit(cherry,4).   print_fruit_name(N) :- fruit(Name,N), printf("It is %w\nn", Name).
http://rosettacode.org/wiki/Empty_string
Empty string
Languages may have features for dealing specifically with empty strings (those containing no characters). Task   Demonstrate how to assign an empty string to a variable.   Demonstrate how to check that a string is empty.   Demonstrate how to check that a string is not empty. Other tasks related to string oper...
#C.2B.2B
C++
#include <string>   // ...     // empty string declaration std::string str; // (default constructed) std::string str(); // (default constructor, no parameters) std::string str{}; // (default initialized) std::string str(""); // (const char[] conversion) std::string str{""}; // (const char[]...
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
EmptyDirectoryQ[x_] := (SetDirectory[x]; If[FileNames[] == {}, True, False])   Example use: EmptyDirectoryQ["C:\\Program Files\\Wolfram Research\\Mathematica\\9"] ->True
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#MATLAB_.2F_Octave
MATLAB / Octave
  function x = isEmptyDirectory(p) if isdir(p) f = dir(p) x = length(f)>2; else error('Error: %s is not a directory'); end; end;  
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#min
min
(ls bool not) :empty-dir?
http://rosettacode.org/wiki/Empty_directory
Empty directory
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other...
#MS-DOS
MS-DOS
C:\>rd GAMES Unable to remove: GAMES.   C:\>
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#bc
bc
*
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Beeswax
Beeswax
*
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Befunge
Befunge
@
http://rosettacode.org/wiki/Entropy
Entropy
Task Calculate the Shannon entropy   H   of a given input string. Given the discrete random variable X {\displaystyle X} that is a string of N {\displaystyle N} "symbols" (total characters) consisting of n {\displaystyle n} different characters (n=2 for binary), the Shannon entropy of X in bit...
#Erlang
Erlang
  -module( entropy ).   -export( [shannon/1, task/0] ).   shannon( String ) -> shannon_information_content( lists:foldl(fun count/2, dict:new(), String), erlang:length(String) ).   task() -> shannon( "1223334444" ).       count( Character, Dict ) -> dict:update_counter( Character, 1, Dict ).   shannon_information_conte...
http://rosettacode.org/wiki/Ethiopian_multiplication
Ethiopian multiplication
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. Method: Take two numbers to be multiplied and write them down at the top of two columns. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ...
#Draco
Draco
proc nonrec halve(word n) word: n >> 1 corp proc nonrec double(word n) word: n << 1 corp proc nonrec even(word n) bool: n & 1 = 0 corp   proc nonrec emul(word a, b) word: word total; total := 0; while a > 0 do if not even(a) then total := total + b fi; a := halve(a); b :=...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#Nim
Nim
import math, sequtils, strutils   iterator eqindex(data: openArray[int]): int = var suml, ddelayed = 0 var sumr = sum(data) for i,d in data: suml += ddelayed sumr -= d ddelayed = d if suml == sumr: yield i   const d = @[@[-7, 1, 5, 2, -4, 3, 0], @[2, 4, 6], @[2, 9, 2]...
http://rosettacode.org/wiki/Equilibrium_index
Equilibrium index
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices. For example, in a sequence   A {\displaystyle A} :   A 0 = − 7 {\displaystyle A_{0}=-7}   A 1 = 1 {\displaystyle A_{1}=1} ...
#Objeck
Objeck
class Rosetta { function : Main(args : String[]) ~ Nil { sequence := [-7, 1, 5, 2, -4, 3, 0]; EqulibriumIndices(sequence); }   function : EqulibriumIndices(sequence : Int[]) ~ Nil { # find total sum totalSum := 0; each(i : sequence) { totalSum += sequence[i]; };   # compare runni...
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func begin writeln(getenv("HOME")); end func;
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Sidef
Sidef
say ENV{'HOME'};
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Slate
Slate
Environment variables at: 'PATH'. "==> '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'"
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#Smalltalk
Smalltalk
  OSProcess thisOSProcess environment at: #HOME. OSProcess thisOSProcess environment at: #PATH. OSProcess thisOSProcess environment at: #USER.  
http://rosettacode.org/wiki/Environment_variables
Environment variables
Task Show how to get one of your process's environment variables. The available variables vary by system;   some of the common ones available on Unix include:   PATH   HOME   USER
#SNOBOL4
SNOBOL4
output = host(4,'PATH') end
http://rosettacode.org/wiki/Euler%27s_sum_of_powers_conjecture
Euler's sum of powers conjecture
There is a conjecture in mathematics that held for over two hundred years before it was disproved by the finding of a counterexample in 1966 by Lander and Parkin. Euler's (disproved) sum of powers   conjecture At least k positive kth powers are required to sum to a kth power, except for the trivial case...
#Kotlin
Kotlin
fun main(args: Array<String>) { val p5 = LongArray(250){ it.toLong() * it * it * it * it } var sum: Long var y: Int var found = false loop@ for (x0 in 0 .. 249) for (x1 in 0 .. x0 - 1) for (x2 in 0 .. x1 - 1) for (x3 in 0 .. x2 - 1) { sum = p5[...
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...
#Oz
Oz
fun {Fac1 N} {FoldL {List.number 1 N 1} Number.'*' 1} end
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...
#Elixir
Elixir
defmodule RC do import Integer   def even_or_odd(n) when is_even(n), do: "#{n} is even" def even_or_odd(n) , do: "#{n} is odd" # In second "def", the guard clauses of "is_odd(n)" is unnecessary.   # Another definition way def even_or_odd2(n) do if is_even(n), do: "#{n} is even", else:...
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...
#Emacs_Lisp
Emacs Lisp
(require 'cl-lib)   (defun even-or-odd-p (n) (if (cl-evenp n) 'even 'odd))   (defun even-or-odd-p (n) (if (zerop (% n 2)) 'even 'odd))   (message "%d is %s" 3 (even-or-oddp 3)) (message "%d is %s" 2 (even-or-oddp 2))
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...
#Nim
Nim
proc binomialCoeff(n, k: int): int = result = 1 for i in 1..k: result = result * (n-i+1) div i   echo binomialCoeff(5, 3)