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/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#D
D
void main() { // Named enumeration (commonly used enum in D). // The underlying type is a 32 bit int. enum Fruits1 { apple, banana, cherry }   // You can assign an enum to the general type, but not the opposite: int f1 = Fruits1.banana; // No error. // Fruits1 f2 = 1; // Error: cannot implicitly...
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.
#Clojure
Clojure
user> (def d [1 2 3 4 5]) ; immutable vector #'user/d user> (assoc d 3 7) [1 2 3 7 5] user> d [1 2 3 4 5]
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.
#COBOL
COBOL
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9.
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.
#D
D
import std.random;   // enum allows to define manifest (compile-time) constants: int sqr(int x) { return x ^^ 2; } enum int x = 5; enum y = sqr(5); // Forces Compile-Time Function Evaluation (CTFE).   // enums are compile-time constants: enum MyEnum { A, B, C }     // immutable defines values that can't change: immutab...
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...
#Aime
Aime
integer c; real h, v; index x; data s;   for (, c in (s = argv(1))) { x[c] += 1r; }   h = 0; for (, v in x) { v /= ~s; h -= v * log2(v); }   o_form("/d6/\n", h);
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...
#ALGOL_68
ALGOL 68
BEGIN # calculate the shannon entropy of a string # PROC shannon entropy = ( STRING s )REAL: BEGIN INT string length = ( UPB s - LWB s ) + 1; # count the occurences of each character # [ 0 : max abs char ]INT char count; FOR char pos FROM LWB ch...
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 ...
#AWK
AWK
function halve(x) { return int(x/2) }   function double(x) { return x*2 }   function iseven(x) { return x%2 == 0 }   function ethiopian(plier, plicand) { r = 0 while(plier >= 1) { if ( !iseven(plier) ) { r += plicand } plier = halve(plier) plicand = double(plicand) } return r }   BEG...
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} ...
#Clojure
Clojure
(defn equilibrium [lst] (loop [acc '(), i 0, left 0, right (apply + lst), lst lst] (if (empty? lst) (reverse acc) (let [[x & xs] lst right (- right x) acc (if (= left right) (cons i acc) acc)] (recur acc (inc i) (+ left x) right xs)))))
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} ...
#Common_Lisp
Common Lisp
(defun dflt-on-nil (v dflt) (if v v dflt))   (defun eq-index (v) (do* ((stack nil) (i 0 (+ 1 i)) (rest v (cdr rest)) (lsum 0) (rsum (apply #'+ (cdr v)))) ;; Reverse here is not strictly necessary ((null rest) (reverse stack)) (if (eql lsum rsum) (push i stack...
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
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Var v = Environ("SystemRoot") Print v Sleep
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
#Frink
Frink
callJava["java.lang.System", "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
#FunL
FunL
println( System.getenv('PATH') ) println( $home ) println( $user )
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...
#Phix
Phix
constant aleph = "0123456789ABCDEF" function efill(string s, integer ch, i) -- min-fill, like 10101 or 54321 or 32101 s[i] = ch for j=i+1 to length(s) do ch = iff(ch>='1'?iff(ch='A'?'9':ch-1):'1') s[j] = ch end for return s end function function esthetic(string s, integer base = ...
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...
#Delphi
Delphi
n = 250 len p5[] n len h5[] 65537 for i range n p5[i] = i * i * i * i * i h5[p5[i] mod 65537] = 1 . func search a s . y . y = -1 b = n while a + 1 < b i = (a + b) div 2 if p5[i] > s b = i elif p5[i] < s a = i else a = b y = i . . . for x0 range n for x1 range x0...
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...
#MUMPS
MUMPS
factorial(num) New ii,result If num<0 Quit "Negative number" If num["." Quit "Not an integer" Set result=1 For ii=1:1:num Set result=result*ii Quit result   Write $$factorial(0) ; 1 Write $$factorial(1) ; 1 Write $$factorial(2) ; 2 Write $$factorial(3) ; 6 Write $$factorial(10) ; 3628800 Write $$factorial(-6) ; Neg...
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...
#BASIC
BASIC
10 INPUT "ENTER A NUMBER: ";N 20 IF N/2 <> INT(N/2) THEN PRINT "THE NUMBER IS ODD":GOTO 40 30 PRINT "THE NUMBER IS EVEN" 40 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...
#Batch_File
Batch File
  @echo off set /p i=Insert number: ::bitwise and set /a "test1=%i%&1" ::divide last character by 2 set /a test2=%i:~-1%/2 ::modulo set /a test3=%i% %% 2   set test pause>nul  
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...
#Oforth
Oforth
: euler(f, y, a, b, h) | t | a b h step: t [ System.Out t <<wjp(6, JUSTIFY_RIGHT, 3) " : " << y << cr t y f perform h * y + ->y ] ;
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...
#Pascal
Pascal
    {$mode delphi} PROGRAM Euler;   TYPE TNewtonCooling = FUNCTION (t: REAL) : REAL;   CONST T0 : REAL = 100.0; CONST TR : REAL = 20.0; CONST k : REAL = 0.07; CONST time : INTEGER = 100; CONST step : INTEGER = 10; CONST dt : ARRAY[0..3] of REAL = (1.0,2.0,5.0,10.0);   VAR i : INTEGER;   FUNCTION NewtonCooling(...
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Function factorial(n As Integer) As Integer If n < 1 Then Return 1 Dim product As Integer = 1 For i As Integer = 2 To n product *= i Next Return Product End Function   Function binomial(n As Integer, k As Integer) As Integer If n < 0 OrElse k < 0 OrElse n <= k Then Return 1 Dim pro...
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 ...
#x86_Assembly
x86 Assembly
TITLE i hate visual studio 4 (Fibs.asm) ; __ __/--------\ ; >__ \ / | |\ ; \ \___/ @ \ / \__________________ ; \____ \ / \\\ ; \____ Coded with love by: ||| ; \ Alexander Alvon...
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#Phix
Phix
without js -- command_line, file i/o function entropy(sequence s) sequence symbols = {}, counts = {} integer N = length(s) for i=1 to N do object si = s[i] integer k = find(si,symbols) if k=0 then symbols = append(symbols,si) counts = append(count...
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#PHP
PHP
<?php $h = 0; $s = file_get_contents(__FILE__); $l = strlen($s); foreach ( count_chars($s, 1) as $c ) $h -= ( $c / $l ) * log( $c / $l, 2 ); echo $h;
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Delphi
Delphi
type fruit = (apple, banana, cherry); ape = (gorilla = 0, chimpanzee = 1, orangutan = 5);
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#DWScript
DWScript
type TFruit = (Apple, Banana, Cherry); type TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);
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...
#11l
11l
I fs:list_dir(input()).empty print(‘empty’) E print(‘not empty’)
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.
#Delphi
Delphi
const STR1 = 'abc'; // regular constant STR2: string = 'def'; // typed constant
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.
#Dyalect
Dyalect
let pi = 3.14 let helloWorld = "Hello, world!"
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.
#E
E
def x := 1   x := 2 # this is an error
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.
#Ela
Ela
open unsafe.cell r = ref 0
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...
#ALGOL_W
ALGOL W
begin  % calculates the shannon entropy of a string  %  % strings are fixed length in algol W and the length is part of the  %  % type, so we declare the string parameter to be the longest possible %  % string length (256 characters) and have a second parameter to  %  % spec...
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...
#APL
APL
  ENTROPY←{-+/R×2⍟R←(+⌿⍵∘.=∪⍵)÷⍴⍵}   ⍝ How it works: ⎕←UNIQUE←∪X←'1223334444' 1234 ⎕←TABLE_OF_OCCURENCES←X∘.=UNIQUE 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 ⎕←COUNT←+⌿TABLE_OF_OCCURENCES 1 2 3 4 ⎕←N←⍴X 10 ⎕←RATIO←COUNT÷N 0.1 0.2 0.3 0.4 ...
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 ...
#BASIC
BASIC
  REM Ethiopian multiplication X = 17 Y = 34 TOT = 0 WHILE X >= 1 PRINT X; PRINT " "; A = X GOSUB CHECKEVEN: IF ISEVEN = 0 THEN TOT = TOT + Y PRINT Y; ENDIF PRINT A = X GOSUB HALVE: X = A A = Y GOSUB DOUBLE: Y = A WEND PRINT "= "; PRINT TOT END   REM Subroutines are required, th...
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} ...
#D
D
import std.stdio, std.algorithm, std.range, std.functional;   auto equilibrium(Range)(Range r) pure nothrow @safe /*@nogc*/ { return r.length.iota.filter!(i => r[0 .. i].sum == r[i + 1 .. $].sum); }   void main() { [-7, 1, 5, 2, -4, 3, 0].equilibrium.writeln; }
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} ...
#Delphi
Delphi
import extensions; import system'routines; import system'collections; import extensions'routines;   class EquilibriumEnumerator : Enumerator { int left; int right; int index; Enumerator en;   constructor new(Enumerator en) { this en := en;   self.reset() ...
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
#Go
Go
package main   import ( "fmt" "os" )   func main() { fmt.Println(os.Getenv("SHELL")) }
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
#Gri
Gri
get env \foo HOME show "\foo"
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
#Groovy
Groovy
System.getenv().each { property, value -> println "$property = $value"}
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...
#PicoLisp
PicoLisp
(de esthetic (N Base) (let Lst (make (loop (yoke (% N Base)) (T (=0 (setq N (/ N Base)))) ) ) (and (fully =1 (make (for (L Lst (cdr L) (cdr L)) (link (abs (- (car L) (cadr L)))) ) ) ) (pack ...
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...
#EasyLang
EasyLang
n = 250 len p5[] n len h5[] 65537 for i range n p5[i] = i * i * i * i * i h5[p5[i] mod 65537] = 1 . func search a s . y . y = -1 b = n while a + 1 < b i = (a + b) div 2 if p5[i] > s b = i elif p5[i] < s a = i else a = b y = i . . . for x0 range n for x1 range x0...
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...
#MyrtleScript
MyrtleScript
func factorial args: int a : returns: int { int factorial = a repeat int i = (a - 1) : i == 0 : i-- { factorial *= i } return factorial }
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...
#BBC_BASIC
BBC BASIC
IF FNisodd%(14) PRINT "14 is odd" ELSE PRINT "14 is even" IF FNisodd%(15) PRINT "15 is odd" ELSE PRINT "15 is even" IF FNisodd#(9876543210#) PRINT "9876543210 is odd" ELSE PRINT "9876543210 is even" IF FNisodd#(9876543211#) PRINT "9876543211 is odd" ELSE PRINT "9876543211 is even" 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...
#bc
bc
i = -3   /* Assumes that i is an integer. */ scale = 0 if (i % 2 == 0) "i is even " if (i % 2) "i is odd "
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...
#Perl
Perl
sub euler_method { my ($t0, $t1, $k, $step_size) = @_; my @results = ( [0, $t0] );   for (my $s = $step_size; $s <= 100; $s += $step_size) { $t0 -= ($t0 - $t1) * $k * $step_size; push @results, [$s, $t0]; }   return @results; }   sub analytical { ...
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...
#Frink
Frink
  println[binomial[5,3]]  
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...
#FunL
FunL
def choose( n, k ) | k < 0 or k > n = 0 choose( n, 0 ) = 1 choose( n, n ) = 1 choose( n, k ) = product( [(n - i)/(i + 1) | i <- 0:min( k, n - k )] )   println( choose(5, 3) ) println( choose(60, 30) )
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 ...
#xEec
xEec
  h#1 h#1 h#1 o# h#10 o$ p >f o# h#10 o$ p ma h? jnext p t jnf  
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#Picat
Picat
  entropy(File) = E => Bytes = read_file_bytes(File), F = [0: I in 1..256], foreach (B in Bytes) B1 := B + 1, F[B1] := F[B1] + 1 end, HM = 0, foreach (C in F) if (C > 0) then HM := HM + C * log(2, C) end end, L = Bytes.length, E = log(2, L)...
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#PicoLisp
PicoLisp
  (scl 8) (load "@lib/math.l")   (setq LN2 0.693147180559945309417)   (setq Me (let F (file) (pack (car F) (cadr F))))   (setq Hist NIL Sz 0) (in Me (use Ch (while (setq Ch (rd 1)) (inc 'Sz) (if (assoc Ch Hist) (con @ (inc (cdr @))) (setq Hist (cons (cons Ch 1...
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#Python
Python
import math from collections import Counter   def entropy(s): p, lns = Counter(s), float(len(s)) return -sum( count/lns * math.log(count/lns, 2) for count in p.values())   with open(__file__) as f: b=f.read()   print(entropy(b))
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#Racket
Racket
  #lang racket (require math) (define (log2 x) (/ (log x) (log 2))) (define ds (string->list (file->string "entropy.rkt"))) (define n (length ds)) (- (for/sum ([(d c) (in-hash (samples->hash ds))]) (* (/ c n) (log2 (/ c n)))))  
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#E
E
def apple { to value() { return 0 } } def banana { to value() { return 1 } } def cherry { to value() { return 2 } }
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#EGL
EGL
// Without explicit values enumeration FruitsKind APPLE, BANANA, CHERRY end   program EnumerationTest   function main() whatFruitAmI(FruitsKind.CHERRY); end   function whatFruitAmI(fruit FruitsKind) case (fruit) when(FruitsKind.APPLE) syslib.writestdout("You're an apple."); when(FruitsKind.BANANA) ...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Elixir
Elixir
fruits = [:apple, :banana, :cherry] fruits = ~w(apple banana cherry)a # Above-mentioned different notation val = :banana Enum.member?(fruits, val) #=> true val in fruits #=> true
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...
#11l
11l
V s = ‘’ I s.empty print(‘String s is empty.’) I !s.empty print(‘String s is not empty.’)
http://rosettacode.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
Elliptic Curve Digital Signature Algorithm
Elliptic curves. An elliptic curve E over ℤp (p ≥ 5) is defined by an equation of the form y^2 = x^3 + ax + b, where a, b ∈ ℤp and the discriminant ≢ 0 (mod p), together with a special point 𝒪 called the point at infinity. The set E(ℤp) consists of all points (x, y), with x, y ∈ ℤp, which satisfy the above defining eq...
#C
C
  /* subject: Elliptic curve digital signature algorithm, toy version for small modulus N. tested : gcc 4.6.3, tcc 0.9.27 */ #include <stdio.h> #include <stdlib.h> #include <time.h>   // 64-bit integer type typedef long long int dlong; // rational ec point typedef struct { dlong x, y; } epnt; // elliptic cu...
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...
#8086_Assembly
8086 Assembly
; this routine attempts to remove the directory and returns an error code if it cannot.   mov ax,seg dirname ;load into AX the segment where dirname is stored. mov ds,ax ;load the segment register DS with the segment of dirname mov dx,offset dirname ;load into DX the offset of dirnam...
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...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Directories; procedure EmptyDir is function Empty (path : String) return String is use Ada.Directories; result : String := "Is empty."; procedure check (ent : Directory_Entry_Type) is begin if Simple_Name (ent) /= "." and Simple_Name (ent) /= ".....
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#11l
11l
BR 14 END
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.
#Elixir
Elixir
iex(1)> x = 10 # bind 10 iex(2)> 10 = x # Pattern matching 10 iex(3)> x = 20 # rebound 20 iex(4)> ^x = 10 # pin operator ^ ** (MatchError) no match of right hand side value: 10
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.
#Erlang
Erlang
X = 10, X = 20.
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.
#Euphoria
Euphoria
constant n = 1 constant s = {1,2,3} constant str = "immutable string"
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.
#F.23
F#
let hello = "Hello!"
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...
#Arturo
Arturo
entropy: function [s][ t: #[] loop s 'c [ unless key? t c -> t\[c]: 0 t\[c]: t\[c] + 1 ] result: new 0 loop values t 'x -> 'result - (x//(size s)) * log x//(size s) 2   return result ]   print entropy "1223334444"
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...
#AutoHotkey
AutoHotkey
MsgBox, % Entropy(1223334444)   Entropy(n) { a := [], len := StrLen(n), m := n while StrLen(m) { s := SubStr(m, 1, 1) m := RegExReplace(m, s, "", c) a[s] := c } for key, val in a { m := Log(p := val / len) e -= p * m / Log(2) } return, e }
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 ...
#Batch_File
Batch File
  @echo off :: Pick 2 random, non-zero, 2-digit numbers to send to :_main set /a param1=%random% %% 98 + 1 set /a param2=%random% %% 98 + 1 call:_main %param1% %param2% pause>nul exit /b :: This is the main function that outputs the answer in the form of "%1 * %2 = %answer%" :_main setlocal enabledelayedexpansion set ...
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} ...
#Elena
Elena
import extensions; import system'routines; import system'collections; import extensions'routines;   class EquilibriumEnumerator : Enumerator { int left; int right; int index; Enumerator en;   constructor new(Enumerator en) { this en := en;   self.reset() ...
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} ...
#Elixir
Elixir
defmodule Equilibrium do def index(list) do last = length(list) Enum.filter(0..last-1, fn i -> Enum.sum(Enum.slice(list, 0, i)) == Enum.sum(Enum.slice(list, i+1..last)) 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
#Haskell
Haskell
import System.Environment main = do getEnv "HOME" >>= print -- get env var getEnvironment >>= print -- get the entire environment as a list of (key, value) pairs
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
#hexiscript
hexiscript
println env "HOME" println env "PATH" println env "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
#HicEst
HicEst
CHARACTER string*255   string = "PATH=" SYSTEM(GEteNV = string)
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...
#Prolog
Prolog
main:- forall(between(2, 16, Base), (Min_index is Base * 4, Max_index is Base * 6, print_esthetic_numbers1(Base, Min_index, Max_index))), print_esthetic_numbers2(1000, 9999, 16), nl, print_esthetic_numbers2(100000000, 130000000, 8).   print_esthetic_numbers1(Base, Min_index, Max_...
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...
#EchoLisp
EchoLisp
  (define dim 250)   ;; speed up n^5 (define (p5 n) (* n n n n n)) (remember 'p5) ;; memoize   ;; build vector of all y^5 - x^5 diffs - length 30877 (define all-y^5-x^5 (for*/vector [(x (in-range 1 dim)) (y (in-range (1+ x) dim))] (- (p5 y) (p5 x))))   ;; sort to use vector-search (begin (vector-sort! < 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...
#Nanoquery
Nanoquery
def factorial(n) result = 1 for i in range(1, n) result = result * i end return result 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...
#Beads
Beads
beads 1 program 'Even or odd'   calc main_init loop across:[-10, -5, 10, 5] val:v log "{v}\todd:{is_odd(v)}\teven:{is_even(v)}"
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...
#Phix
Phix
-- -- demo\rosetta\Euler_method.exw -- ============================= -- with javascript_semantics function ivp_euler(atom y, integer f, step, end_t) sequence res = {} for t=0 to end_t by step do if remainder(t,10)==0 then res &= y end if y += step * call_func(f,{t, y}) end for return res...
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...
#GAP
GAP
# Built-in Binomial(5, 3); # 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...
#Go
Go
package main import "fmt" import "math/big"   func main() { fmt.Println(new(big.Int).Binomial(5, 3)) fmt.Println(new(big.Int).Binomial(60, 30)) }
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 ...
#XLISP
XLISP
(DEFUN FIBONACCI (N) (FLOOR (+ (/ (EXPT (/ (+ (SQRT 5) 1) 2) N) (SQRT 5)) 0.5)))
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#Raku
Raku
say log(2) R/ [+] map -> \p { p * -log p }, $_.comb.Bag.values >>/>> +$_ given slurp($*PROGRAM-NAME).comb
http://rosettacode.org/wiki/Entropy/Narcissist
Entropy/Narcissist
Task Write a computer program that computes and shows its own   entropy. Related Tasks   Fibonacci_word   Entropy
#REXX
REXX
/*REXX program calculates the "information entropy" for ~this~ REXX program. */ numeric digits length( e() ) % 2 - length(.) /*use 1/2 of the decimal digits of E. */ #= 0; @.= 0; $=; $$=; recs= sourceline() /*define some handy─dandy REXX vars. */ do m=1 for recs; $=$||sourceLine(m...
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...
#11l
11l
T Point Float x, y   F (x = Float.infinity, y = Float.infinity) .x = x .y = y   F.const copy() R Point(.x, .y)   F.const is_zero() R .x > 1e20 | .x < -1e20   F neg() R Point(.x, -.y)   F dbl() I .is_zero() R .copy() I .y == 0 R Point() ...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Erlang
Erlang
type Fruit = | Apple = 0 | Banana = 1 | Cherry = 2   let basket = [ Fruit.Apple ; Fruit.Banana ; Fruit.Cherry ] Seq.iter (printfn "%A") basket
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#F.23
F#
type Fruit = | Apple = 0 | Banana = 1 | Cherry = 2   let basket = [ Fruit.Apple ; Fruit.Banana ; Fruit.Cherry ] Seq.iter (printfn "%A") basket
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...
#6502_Assembly
6502 Assembly
EmptyString: byte 0
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...
#68000_Assembly
68000 Assembly
EmptyString: DC.B 0 EVEN
http://rosettacode.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
Elliptic Curve Digital Signature Algorithm
Elliptic curves. An elliptic curve E over ℤp (p ≥ 5) is defined by an equation of the form y^2 = x^3 + ax + b, where a, b ∈ ℤp and the discriminant ≢ 0 (mod p), together with a special point 𝒪 called the point at infinity. The set E(ℤp) consists of all points (x, y), with x, y ∈ ℤp, which satisfy the above defining eq...
#FreeBASIC
FreeBASIC
  'subject: Elliptic curve digital signature algorithm, ' toy version for small modulus N. 'tested : FreeBasic 1.05.0   'rational ec point type epnt as longint x, y end type 'elliptic curve parameters type curve as long a, b as longint N as epnt G as longint r end type 'signature pair type pair ...
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...
#ALGOL_68
ALGOL 68
# returns TRUE if the specified directory is empty, FALSE if it doesn't exist or is non-empty # PROC is empty directory = ( STRING directory )BOOL: IF NOT file is directory( directory ) THEN # directory doesn't exist # FALSE ELSE # directory is empty if it contains no files or ...
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...
#Arturo
Arturo
emptyDir?: function [folder]-> empty? list folder   print emptyDir? "."
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#360_Assembly
360 Assembly
BR 14 END
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#6502_Assembly
6502 Assembly
org $0801  ;start assembling at this address db $0E,$08,$0A,$00,$9E,$20,$28,$32,$30,$36,$34,$29,$00,$00,$00 ;required init code rts  ;return to basic
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.
#Factor
Factor
TUPLE: range { from read-only } { length read-only } { step read-only } ;
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.
#Forth
Forth
  256 constant one-hex-dollar s" Hello world" 2constant hello \ "hello" holds the address and length of an anonymous string. 355 119 2constant ratio-pi \ 2constant can also define ratios (e.g. pi) 3.14159265e fconstant pi  
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.
#Fortran
Fortran
real, parameter :: pi = 3.141593
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.
#FreeBASIC
FreeBASIC
#define IMMUT1 32767 'constants can be created in the preprocessor dim as const uinteger IMMUT2 = 2222 'or explicitly declared as constants  
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...
#AWK
AWK
#!/usr/bin/awk -f { for (i=1; i<= length($0); i++) { H[substr($0,i,1)]++; N++; } }   END { for (i in H) { p = H[i]/N; E -= p * log(p); } print E/log(2); }
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 ...
#BCPL
BCPL
get "libhdr"   let halve(i) = i>>1 and double(i) = i<<1 and even(i) = (i&1) = 0   let emul(x, y) = emulr(x, y, 0) and emulr(x, y, ac) = x=0 -> ac, emulr(halve(x), double(y), even(x) -> ac, ac + y)   let start() be writef("%N*N", emul(17, 34))
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} ...
#ERRE
ERRE
  PROGRAM EQUILIBRIUM   DIM LISTA[6]   PROCEDURE EQ(LISTA[]->RES$) LOCAL I%,R,S,E$ FOR I%=0 TO UBOUND(LISTA,1) DO S+=LISTA[I%] END FOR FOR I%=0 TO UBOUND(LISTA,1) DO IF R=S-R-LISTA[I%] THEN E$+=STR$(I%)+"," END IF R+=LISTA[I%] END FOR RES$=LEFT$(E$,LEN(E$)-1) END PROCEDURE   BEGIN ...
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} ...
#Euphoria
Euphoria
function equilibrium(sequence s) integer lower_sum, higher_sum sequence indices lower_sum = 0 higher_sum = 0 for i = 1 to length(s) do higher_sum += s[i] end for indices = {} for i = 1 to length(s) do higher_sum -= s[i] if lower_sum = higher_sum then i...
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
#i
i
software { print(load("$HOME")) print(load("$USER")) print(load("$PATH")) }