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."
#ALGOL_W
ALGOL W
.
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.
#Pascal
Pascal
use constant PI => 3.14159; use constant MSG => "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.
#Perl
Perl
use constant PI => 3.14159; use constant MSG => "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.
#Phix
Phix
with javascript_semantics 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.
#PHP
PHP
define("PI", 3.14159265358); define("MSG", "Hello World");
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...
#Clojure
Clojure
(defn entropy [s] (let [len (count s), log-2 (Math/log 2)] (->> (frequencies s) (map (fn [[_ v]] (let [rf (/ v len)] (-> (Math/log rf) (/ log-2) (* rf) Math/abs)))) (reduce +))))
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 ...
#Clojure
Clojure
(defn halve [n] (bit-shift-right n 1))   (defn twice [n] ; 'double' is taken (bit-shift-left n 1))   (defn even [n] ; 'even?' is the standard fn (zero? (bit-and n 1)))   (defn emult [x y] (reduce + (map second (filter #(not (even (first %))) ; a.k.a. 'odd?' (take-while #(p...
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} ...
#Icon_and_Unicon
Icon and Unicon
procedure main(arglist) L := if *arglist > 0 then arglist else [-7, 1, 5, 2, -4, 3, 0] # command line args or default every writes( "equilibrium indicies of [ " | (!L ||" ") | "] = " | (eqindex(L)||" ") | "\n" ) end   procedure eqindex(L) # generate equilibrium points in a list L or fail local s,l,i   every (s := 0, ...
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
#Maple
Maple
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
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
Environment["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
#MATLAB_.2F_Octave
MATLAB / Octave
getenv('HOME') getenv('PATH') getenv('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
#Mercury
Mercury
:- module env_var. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module maybe, string.   main(!IO) :- io.get_environment_var("HOME", MaybeValue, !IO), ( MaybeValue = yes(Value), io.write_string("HOME is " ++ Value ++ "\n", !IO)  ; ...
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...
#Sidef
Sidef
func generate_esthetic(root, upto, callback, b=10) {   var v = root.digits2num(b)   return nil if (v > upto) callback(v)   var t = root.head   __FUNC__([t+1, root...], upto, callback, b) if (t+1 < b) __FUNC__([t-1, root...], upto, callback, b) if (t-1 >= 0) }   func between_esthetic(from, upto,...
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...
#FreeBASIC
FreeBASIC
' version 14-09-2015 ' compile with: fbc -s console   ' some constants calculated when the program is compiled   Const As UInteger max = 250 Const As ULongInt pow5_max = CULngInt(max) * max * max * max * max ' limit x1, x2, x3 Const As UInteger limit_x1 = (pow5_max / 4) ^ 0.2 Const As UInteger limit_x2 = (pow5_max / 3)...
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...
#Nim
Nim
  import math let i:int = fac(x)  
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...
#Clojure
Clojure
(if (even? some-var) (do-even-stuff)) (if (odd? some-var) (do-odd-stuff))
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...
#Ring
Ring
  decimals(3) see euler("return -0.07*(y-20)", 100, 0, 100, 2) + nl see euler("return -0.07*(y-20)", 100, 0, 100, 5) + nl see euler("return -0.07*(y-20)", 100, 0, 100, 10) + nl   func euler df, y, a, b, s t = a while t <= b see "" + t + " " + y + nl y += s * eval(df) ...
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...
#Ruby
Ruby
def euler(y, a, b, h) a.step(b,h) do |t| puts "%7.3f %7.3f" % [t,y] y += h * yield(t,y) end end   [10, 5, 2].each do |step| puts "Step = #{step}" euler(100,0,100,step) {|time, temp| -0.07 * (temp - 20) } puts end
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...
#Julia
Julia
@show 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...
#K
K
{[n;k]_(*/(k-1)_1+!n)%(*/1+!k)} . 5 3 10
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...
#AWK
AWK
  function is_prime(n, p) { if (!(n%2) || !(n%3)) { return 0 } p = 1 while(p*p < n) if (n%(p += 4) == 0 || n%(p += 2) == 0) { return 0 } return 1 }   function reverse(n, r) { r = 0 for (r = 0; int(n) != 0; n /= 10) r = r*...
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...
#Java
Java
import static java.lang.Math.*; import java.util.Locale;   public class Test {   public static void main(String[] args) { Pt a = Pt.fromY(1); Pt b = Pt.fromY(2); System.out.printf("a = %s%n", a); System.out.printf("b = %s%n", b); Pt c = a.plus(b); System.out.printf("c...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#JSON
JSON
{"fruits" : { "apple" : null, "banana" : null, "cherry" : null } {"fruits" : { "apple" : 0, "banana" : 1, "cherry" : 2 }
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Julia
Julia
  @enum Fruits APPLE BANANA CHERRY  
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Kotlin
Kotlin
// version 1.0.5-2   enum class Animals { CAT, DOG, ZEBRA }   enum class Dogs(val id: Int) { BULLDOG(1), TERRIER(2), WOLFHOUND(4) }   fun main(args: Array<String>) { for (value in Animals.values()) println("${value.name.padEnd(5)} : ${value.ordinal}") println() for (value in Dogs.values()) println("...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator
Elementary cellular automaton/Random Number Generator
Rule 30 is considered to be chaotic enough to generate good pseudo-random numbers. As a matter of fact, rule 30 is used by the Mathematica software for its default random number generator. Steven Wolfram's recommendation for random number generation from rule 30 consists in extracting successive bits in a fixed positi...
#Perl
Perl
package Automaton { sub new { my $class = shift; my $rule = [ reverse split //, sprintf "%08b", shift ]; return bless { rule => $rule, cells => [ @_ ] }, $class; } sub next { my $this = shift; my @previous = @{$this->{cells}}; $this->{cells} = [ @{$this->{rule}}[ map ...
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...
#Arturo
Arturo
s: ""   if empty? s -> print "the string is empty" if 0 = size s -> print "yes, the string is empty"   s: "hello world"   if not? empty? s -> print "the string is not empty" if 0 < size s -> print "no, the string is not empty"
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...
#Asymptote
Asymptote
string c; //implicitly assigned an empty string if (length(c) == 0) { write("Empty string"); } else { write("Non empty string"); }   string s = ""; //explicitly assigned an empty string if (s == "") { write("Empty string"); } if (s != "") { write("Non empty string"); }   string t = "not empty"; if (t != "")...
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...
#Wren
Wren
import "/dynamic" for Struct import "/big" for BigInt import "/fmt" for Fmt import "/math" for Boolean import "random" for Random   var rand = Random.new()   // rational ec point: x and y are BigInts var Epnt = Struct.create("Epnt", ["x", "y"])   // elliptic curve parameters: N is a BigInt, G is an Epnt, rest are integ...
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...
#Elixir
Elixir
path = hd(System.argv) IO.puts File.dir?(path) and Enum.empty?( File.ls!(path) )
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...
#Erlang
Erlang
3> {ok, []} = file:list_dir_all("/usr"). ** exception error: no match of right hand side value {ok,["X11R6","X11","standalone","share","sbin","local", "libexec","lib","bin"]} 4> {ok, []} = file:list_dir_all("/asd"). ** exception error: no match of right hand side value {...
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...
#F.23
F#
open System.IO let isEmptyDirectory x = (Directory.GetFiles x).Length = 0 && (Directory.GetDirectories x).Length = 0
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...
#Factor
Factor
USE: io.directories : empty-directory? ( path -- ? ) directory-entries empty? ;
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#AmigaE
AmigaE
PROC main() ENDPROC
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#AppleScript
AppleScript
return
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.
#PicoLisp
PicoLisp
: (de pi () 4) -> pi   : (pi) -> 4
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.
#PL.2FI
PL/I
*process source attributes xref; constants: Proc Options(main); Dcl three Bin Fixed(15) Value(3); Put Skip List(1/three); Put Skip List(1/3); 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.
#PowerBASIC
PowerBASIC
$me = "myname" %age = 35
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.
#PureBasic
PureBasic
#i_Const1 = 11 #i_Const2 = 3.1415 #i_Const3 = "A'm a string"
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...
#CLU
CLU
% NOTE: when compiling with Portable CLU, % this program needs to be merged with 'useful.lib' to get log() % % pclu -merge $CLUHOME/lib/useful.lib -compile entropy.clu   shannon = proc (s: string) returns (real)  % find the frequency of each character freq: array[int] := array[int]$fill(0, 256, 0) for c: cha...
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...
#CoffeeScript
CoffeeScript
entropy = (s) -> freq = (s) -> result = {} for ch in s.split "" result[ch] ?= 0 result[ch]++ return result   frq = freq s n = s.length ((frq[f]/n for f of frq).reduce ((e, p) -> e - p * Math.log(p)), 0) * Math.LOG2E   console.log "The entropy of the string...
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 ...
#CLU
CLU
halve = proc (n: int) returns (int) return(n/2) end halve   double = proc (n: int) returns (int) return(n*2) end double   even = proc (n: int) returns (bool) return(n//2 = 0) end even   e_mul = proc (a, b: int) returns (int) total: int := 0   while (a > 0) do if ~even(a) then total := total ...
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} ...
#J
J
equilidx=: +/\ I.@:= +/\.
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} ...
#Java
Java
  public class Equlibrium { public static void main(String[] args) { int[] sequence = {-7, 1, 5, 2, -4, 3, 0}; equlibrium_indices(sequence); }   public static void equlibrium_indices(int[] sequence){ //find total sum int totalSum = 0; for (int n : sequence) { totalSum += n; } //compare running sum t...
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
#min
min
$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
#Modula-3
Modula-3
MODULE EnvVars EXPORTS Main;   IMPORT IO, Env;   VAR k, v: TEXT;   BEGIN IO.Put(Env.Get("HOME") & "\n");   FOR i := 0 TO Env.Count - 1 DO Env.GetNth(i, k, v); IO.Put(k & " = " & v & "\n") END END EnvVars.
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
#MUMPS
MUMPS
Set X=$ZF(-1,"show logical") Set X=$ZF(-1,"show symbol")
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
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method sysEnvironment(vn = '') public static if vn.length > 0 then do envName = vn envValu = System.getenv(envName) if env...
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...
#Swift
Swift
extension Sequence { func take(_ n: Int) -> [Element] { var res = [Element]()   for el in self { guard res.count != n else { return res }   res.append(el) }   return res } }   extension String { func isEsthetic(base: Int = 10) -> Bool { zip(dropFirst(0), dropFirst()) ...
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...
#Go
Go
package main   import ( "fmt" "log" )   func main() { fmt.Println(eulerSum()) }   func eulerSum() (x0, x1, x2, x3, y int) { var pow5 [250]int for i := range pow5 { pow5[i] = i * i * i * i * i } for x0 = 4; x0 < len(pow5); x0++ { for x1 = 3; x1 < x0; x1++ { for x2 = 2; x2 < x1; x2++ { for x3 = 1; x3 < ...
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...
#Niue
Niue
[ dup 1 > [ dup 1 - factorial * ] when ] 'factorial ;   ( test ) 4 factorial . ( => 24 ) 10 factorial . ( => 3628800 )
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...
#COBOL
COBOL
IF FUNCTION REM(Num, 2) = 0 DISPLAY Num " is even." ELSE DISPLAY Num " is odd." END-IF
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...
#CoffeeScript
CoffeeScript
isEven = (x) -> !(x%2)
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...
#Rust
Rust
fn header() { print!(" Time: "); for t in (0..100).step_by(10) { print!(" {:7}", t); } println!(); }   fn analytic() { print!("Analytic: "); for t in (0..=100).step_by(10) { print!(" {:7.3}", 20.0 + 80.0 * (-0.07 * f64::from(t)).exp()); } println!(); }   fn euler<F: Fn...
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...
#Scala
Scala
  object App{   def main(args : Array[String]) = {   def cooling( step : Int ) = { eulerStep( (step , y) => {-0.07 * (y - 20)} , 100.0,0,100,step) } cooling(10) cooling(5) cooling(2) } def eulerStep( func : (Int,Double) => Double,y0 : Double, begin : Int, end : Int , step : ...
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...
#Kotlin
Kotlin
// version 2.0   fun binomial(n: Int, k: Int) = when { n < 0 || k < 0 -> throw IllegalArgumentException("negative numbers not allowed") n == k -> 1L else -> { val kReduced = min(k, n - k) // minimize number of steps var result = 1L var numerator = n var d...
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...
#C
C
#include <stdio.h>   typedef unsigned uint; int is_prime(uint n) { if (!(n%2) || !(n%3)) return 0; uint p = 1; while(p*p < n) if (n%(p += 4) == 0 || n%(p += 2) == 0) return 0; return 1; }   uint reverse(uint n) { uint r; for (r = 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...
#Julia
Julia
struct Point{T<:AbstractFloat} x::T y::T end Point{T}() where T<:AbstractFloat = Point{T}(Inf, Inf) Point() = Point{Float64}()   Base.show(io::IO, p::Point{T}) where T = iszero(p) ? print(io, "Zero{$T}") : @printf(io, "{%s}(%.3f, %.3f)", T, p.x, p.y) Base.copy(p::Point) = Point(p.x, p.y) Base.iszero(p::Point{T}...
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...
#Kotlin
Kotlin
// version 1.1.4   const val C = 7   class Pt(val x: Double, val y: Double) { val zero get() = Pt(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)   val isZero get() = x > 1e20 || x < -1e20   fun dbl(): Pt { if (isZero) return this val l = 3.0 * x * x / (2.0 * y) val t = l * l - 2...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Lingo
Lingo
-- parent script "Enumeration"   property ancestor   on new (me) data = [:] repeat with i = 2 to the paramCount data[param(i)] = i-1 end repeat me.ancestor = data return me end   on setAt (me) -- do nothing end   on setProp (me) -- do nothing end   on deleteAt (me) -- do nothing end   on deleteProp ...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Lua
Lua
  local fruit = {apple = 0, banana = 1, cherry = 2}  
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { \\ need revision 15, version 9.4 Enum Fruit {apple, banana, cherry} Enum Fruit2 {apple2=10, banana2=20, cherry2=30} Print apple, banana, cherry Print apple2, banana2, cherry2 Print Len(apple)=0 Print Len(banana)=1 Print Len(cherry)=2 Print Len(c...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator
Elementary cellular automaton/Random Number Generator
Rule 30 is considered to be chaotic enough to generate good pseudo-random numbers. As a matter of fact, rule 30 is used by the Mathematica software for its default random number generator. Steven Wolfram's recommendation for random number generation from rule 30 consists in extracting successive bits in a fixed positi...
#Phix
Phix
with javascript_semantics --string s = ".........#.........", --(original) string s = "...............................#"& "................................", --string s = "#"&repeat('.',100), -- [2] t=s, r = "........" integer rule = 30, k, l = length(s), w = 0 for i=1 to 8 do r[i] = iff(mod(ru...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator
Elementary cellular automaton/Random Number Generator
Rule 30 is considered to be chaotic enough to generate good pseudo-random numbers. As a matter of fact, rule 30 is used by the Mathematica software for its default random number generator. Steven Wolfram's recommendation for random number generation from rule 30 consists in extracting successive bits in a fixed positi...
#Python
Python
from elementary_cellular_automaton import eca, eca_wrap   def rule30bytes(lencells=100): cells = '1' + '0' * (lencells - 1) gen = eca(cells, 30) while True: yield int(''.join(next(gen)[0] for i in range(8)), 2)   if __name__ == '__main__': print([b for i,b in zip(range(10), rule30bytes())])
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...
#AutoHotkey
AutoHotkey
;; Traditional ; Assign an empty string: var = ; Check that a string is empty: If var = MsgBox the var is empty ; Check that a string is not empty If var != Msgbox the var is not empty     ;; Expression mode: ; Assign an empty string: var := "" ; Check that a string is empty: If (var = "") MsgBox the var is em...
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...
#Avail
Avail
emptyStringVar : string := ""; Assert: emptyStringVar = ""; Assert: emptyStringVar = <>; Assert: emptyStringVar is empty; Assert: |emptyStringVar| = 0;
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   #Include "dir.bi"   Function IsDirEmpty(dirPath As String) As Boolean Err = 0 ' check dirPath is a valid directory Dim As String fileName = Dir(dirPath, fbDirectory) If Len(fileName) = 0 Then Err = 1000 ' dirPath is not a valid path Return False End If ' now check if there are a...
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...
#Gambas
Gambas
Public Sub Main() Dim sFolder As String = User.home &/ "Rosetta" Dim sDir As String[] = Dir(sFolder) Dim sTemp As String Dim sOutput As String = sfolder & " is NOT empty"   Try sTemp = sDir[0] If Error Then sOutput = sfolder & " is empty"   Print sOutput   End
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Argile
Argile
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#ARM_Assembly
ARM Assembly
.text .global _start _start: mov r0, #0 mov r7, #1 svc #0
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.
#Python
Python
>>> s = "Hello" >>> s[0] = "h"   Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> s[0] = "h" TypeError: 'str' object does not support item assignment
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.
#Racket
Racket
(struct coordinate (x y)) ; immutable struct
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.
#Raku
Raku
constant $pi = 3.14159; constant $msg = "Hello World";   constant @arr = (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.
#REXX
REXX
/*REXX program emulates immutable variables (as a post-computational check). */ call immutable '$=1' /* ◄─── assigns an immutable variable. */ call immutable ' pi = 3.14159' /* ◄─── " " " " */ call immutable 'radius= 2*pi/4 ' ...
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...
#Common_Lisp
Common Lisp
(defun entropy (string) (let ((table (make-hash-table :test 'equal)) (entropy 0)) (mapc (lambda (c) (setf (gethash c table) (+ (gethash c table 0) 1))) (coerce string 'list)) (maphash (lambda (k v) (decf entropy (* (/ v (length input-string)) (l...
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 ...
#COBOL
COBOL
*>* Ethiopian multiplication   IDENTIFICATION DIVISION. PROGRAM-ID. ethiopian-multiplication. DATA DIVISION. LOCAL-STORAGE SECTION. 01 l PICTURE 9(10) VALUE 17. 01 r PICTURE 9(10) VALUE 34. 01 ethiopian-multiply PICTURE 9(20). ...
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} ...
#JavaScript
JavaScript
function equilibrium(a) { var N = a.length, i, l = [], r = [], e = [] for (l[0] = a[0], r[N - 1] = a[N - 1], i = 1; i<N; i++) l[i] = l[i - 1] + a[i], r[N - i - 1] = r[N - i] + a[N - i - 1] for (i = 0; i < N; i++) if (l[i] === r[i]) e.push(i) return e }   // test & output [ [-7, 1, 5, 2, -4, 3, 0], // 3,...
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
#NewLISP
NewLISP
> (env "SHELL") "/bin/zsh" > (env "TERM") "xterm"
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
#Nim
Nim
import os echo 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
#NSIS
NSIS
ExpandEnvStrings $0 "%PATH%" ; Retrieve PATH and place it in builtin register 0. ExpandEnvStrings $1 "%USERPROFILE%" ; Retrieve the user's profile location and place it in builtin register 1. ExpandEnvStrings $2 "%USERNAME%" ; Retrieve the user's account name and place it in builtin register 2.
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
#Objective-C
Objective-C
[[[NSProcessInfo processInfo] environment] objectForKey:@"HOME"]
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...
#Wren
Wren
import "./fmt" for Conv, Fmt   var isEsthetic = Fn.new { |n, b| if (n == 0) return false var i = n % b n = (n/b).floor while (n > 0) { var j = n % b if ((i - j).abs != 1) return false n = (n/b).floor i = j } return true }   var esths = []   var dfs // recursive f...
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...
#Groovy
Groovy
class EulerSumOfPowers { static final int MAX_NUMBER = 250   static void main(String[] args) { boolean found = false long[] fifth = new long[MAX_NUMBER]   for (int i = 1; i <= MAX_NUMBER; i++) { long i2 = i * i fifth[i - 1] = i2 * i2 * i }   for (i...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Nyquist
Nyquist
(defun factorial (n) (do ((x n (* x n))) ((= n 1) x) (setq n (1- 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...
#ColdFusion
ColdFusion
  function f(numeric n) { return n mod 2?"odd":"even" }  
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...
#Common_Lisp
Common Lisp
(if (evenp some-var) (do-even-stuff)) (if (oddp some-other-var) (do-odd-stuff))
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...
#SequenceL
SequenceL
import <Utilities/Conversion.sl>; import <Utilities/Sequence.sl>;   T0 := 100.0; TR := 20.0; k := 0.07;   main(args(2)) := let results[i] := euler(newtonCooling, T0, 100, stringToInt(args[i]), 0, "delta_t = " ++ args[i]); in delimit(results, '\n');   newtonCooling(t) := -k * (t - TR);   euler: (float -> 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...
#Sidef
Sidef
func euler_method(t0, t1, k, step_size) { var results = [[0, t0]] for s in (step_size..100 -> by(step_size)) { t0 -= ((t0 - t1) * k * step_size) results << [s, t0] } return results; }   func analytical(t0, t1, k, time) { (t0 - t1) * exp(-time * k) + t1 }   var (T0, T1, k) = (100, 20,...
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...
#Lambdatalk
Lambdatalk
    {def C {lambda {:n :p} {/ {* {S.serie :n {- :n :p -1} -1}} {* {S.serie :p 1 -1}}}}} -> C   {C 16 8} -> 12870   1{S.map {lambda {:n} {br}1 {S.map {C :n} {S.serie 1 {- :n 1}}} 1} {S.serie 2 16}} -> 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28...
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...
#C.23
C#
using static System.Console; using System; using System.Linq; using System.Collections.Generic;   public class Program { public static void Main() { const int limit = 1_000_000; WriteLine("First 20:"); WriteLine(FindEmirpPrimes(limit).Take(20).Delimit()); WriteLine();   Write...
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...
#Nim
Nim
import math, strformat   const B = 7   type Point = tuple[x, y: float]   #---------------------------------------------------------------------------------------------------   template zero(): Point = (Inf, Inf)   #---------------------------------------------------------------------------------------------------   f...
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...
#OCaml
OCaml
  (* Task : Elliptic_curve_arithmetic *)   (* Using the secp256k1 elliptic curve (a=0, b=7), define the addition operation on points on the curve. Extra credit: define the full elliptic curve arithmetic (still not modular, though) by defining a "multiply" function. *)   (*** Helpers ***)   type ec_...
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#M4
M4
define(`enums', `define(`$2',$1)`'ifelse(eval($#>2),1,`enums(incr($1),shift(shift($@)))')') define(`enum', `enums(1,$@)') enum(a,b,c,d) `c='c
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
MapIndexed[Set, {A, B, F, G}] ->{{1}, {2}, {3}, {4}}   A ->{1}   B ->{2}   G ->{4}
http://rosettacode.org/wiki/Enumerations
Enumerations
Task Create an enumeration of constants with and without explicit values.
#MATLAB_.2F_Octave
MATLAB / Octave
stuff = {'apple', [1 2 3], 'cherry',1+2i}   stuff =   'apple' [1x3 double] 'cherry' [1.000000000000000 + 2.000000000000000i]
http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator
Elementary cellular automaton/Random Number Generator
Rule 30 is considered to be chaotic enough to generate good pseudo-random numbers. As a matter of fact, rule 30 is used by the Mathematica software for its default random number generator. Steven Wolfram's recommendation for random number generation from rule 30 consists in extracting successive bits in a fixed positi...
#Racket
Racket
#lang racket ;; below is the code from the parent task (require "Elementary_cellular_automata.rkt") (require racket/fixnum)   ;; This is the RNG automaton (define (CA30-random-generator #:rule [rule 30] ; rule 30 is random, maybe you're interested in using others  ;; width of the CA... this is implemen...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator
Elementary cellular automaton/Random Number Generator
Rule 30 is considered to be chaotic enough to generate good pseudo-random numbers. As a matter of fact, rule 30 is used by the Mathematica software for its default random number generator. Steven Wolfram's recommendation for random number generation from rule 30 consists in extracting successive bits in a fixed positi...
#Raku
Raku
class Automaton { has $.rule; has @.cells; has @.code = $!rule.fmt('%08b').flip.comb».Int;   method gist { "|{ @!cells.map({+$_ ?? '#' !! ' '}).join }|" }   method succ { self.new: :$!rule, :@!code, :cells( @!code[ 4 «*« @!cells.rotate(-1)  »+«...
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...
#AWK
AWK
#!/usr/bin/awk -f BEGIN { # Demonstrate how to assign an empty string to a variable. a=""; b="XYZ"; print "a = ",a; print "b = ",b; print "length(a)=",length(a); print "length(b)=",length(b); # Demonstrate how to check that a string is empty. print "Is a empty ?",length(a)==0; print "Is a not ...
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...
#Axe
Axe
""→Str1 !If length(Str1) Disp "EMPTY",i Else Disp "NOT EMPTY",i 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...
#Go
Go
package main   import ( "fmt" "io/ioutil" "log" )   func main() { empty, err := IsEmptyDir("/tmp") if err != nil { log.Fatalln(err) } if empty { fmt.Printf("/tmp is empty\n") } else { fmt.Printf("/tmp is not empty\n") } }   func IsEmptyDir(name string) (bool, error) { entries, err := ioutil.ReadDir(name...