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/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#jq
jq
  # jq optimizes the recursive call of _gcd in the following: def gcd(a;b): def _gcd: if .[1] != 0 then [.[1], .[0] % .[1]] | _gcd else .[0] end; [a,b] | _gcd ;   def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;    
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Julia
Julia
using Primes   function ekgsequence(n, limit) ekg::Array{Int,1} = [1, n] while length(ekg) < limit for i in 2:2<<18 if all(j -> j != i, ekg) && gcd(ekg[end], i) > 1 push!(ekg, i) break end end end ekg end   function convergeat(n, m,...
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...
#Scheme
Scheme
(define empty-string "") (define (string-null? s) (string=? "" s)) (define (string-not-null? s) (string<? "" s))
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...
#Seed7
Seed7
# assign empty string to a variable s := ""   # check that string is empty s = ""   # check that string is not empty s <> ""
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PL.2FSQL
PL/SQL
BEGIN NULL; END;
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Plain_English
Plain English
To run: Start up. Shut down.
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Plain_TeX
Plain TeX
\bye
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 ...
#Phix
Phix
function emHalf(integer n) return floor(n/2) end function function emDouble(integer n) return n*2 end function function emIsEven(integer n) return (remainder(n,2)=0) end function function emMultiply(integer a, integer b) integer sum = 0 while a!=0 do if not emIsEven(a) then sum += b end if...
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...
#Sisal
Sisal
define main   function main(x : integer returns integer)   for a in 1, x returns value of product a end for   end function
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...
#S-BASIC
S-BASIC
  rem - return true (-1) if even, otherwise false (0) function even(i = integer) = integer var one = integer rem - both operands must be variables one = 1 end = ((i and one) = 0)   rem - exercise the function var i = integer for i = 1 to 10 step 3 print i; " is "; if even(i) then print "even" else ...
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#Scala
Scala
def isEven( v:Int ) : Boolean = v % 2 == 0 def isOdd( v:Int ) : Boolean = v % 2 != 0
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#BaCon
BaCon
OPEN "localhost:12321" FOR SERVER AS echo WHILE TRUE fd = ACCEPT(echo) PRINT "Incoming connection from: ", GETPEER$(fd) RECEIVE data$ FROM fd SEND data$ & CR$ & NL$ TO fd CLOSE SERVER fd WEND
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#C.2B.2B
C++
  #include <iostream> #include <iomanip> #include <string>   class oo { public: void evolve( int l, int rule ) { std::string cells = "O"; std::cout << " Rule #" << rule << ":\n"; for( int x = 0; x < l; x++ ) { addNoCells( cells ); std::cout << std::setw( 40 + ( sta...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Kotlin
Kotlin
// Version 1.2.60   fun gcd(a: Int, b: Int): Int { var aa = a var bb = b while (aa != bb) { if (aa > bb) aa -= bb else bb -= aa } return aa }   const val LIMIT = 100   fun main(args: Array<String>) { val starts = listOf(2, 5, 7, 9, 10) val ekg = Array(...
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...
#Self
Self
  "Put an empty string in a slot called 'str'" str: ''.   "Check that string is empty" str isEmpty.   "Check that string is not empty" str isEmpty 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...
#SenseTalk
SenseTalk
  set emptyString to ""   put emptyString   put emptyString is empty   put emptyString is not empty  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Pony
Pony
actor Main new create(e: Env) => ""
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Pop11
Pop11
;;; This is a valid Pop11 program that does absolutely nothing.
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PostScript
PostScript
%!PS
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 ...
#PHP
PHP
<?php function halve($x) { return floor($x/2); }   function double($x) { return $x*2; }   function iseven($x) { return !($x & 0x1); }   function ethiopicmult($plier, $plicand, $tutor) { if ($tutor) echo "ethiopic multiplication of $plier and $plicand\n"; $r = 0; while($plier >= 1) { if ( !iseven($plier)...
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...
#Slate
Slate
n@(Integer traits) factorial "The standard recursive definition." [ n isNegative ifTrue: [error: 'Negative inputs to factorial are invalid.']. n <= 1 ifTrue: [1] ifFalse: [n * ((n - 1) 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...
#Scheme
Scheme
> (even? 5) #f > (even? 42) #t > (odd? 5) #t > (odd? 42) #f
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...
#Seed7
Seed7
odd(aNumber)
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"SOCKLIB" PROC_initsockets   maxSess% = 8 DIM sock%(maxSess%-1), rcvd$(maxSess%-1), Buffer% 255   ON ERROR PRINT REPORT$ : PROC_exitsockets : END ON CLOSE PROC_exitsockets : QUIT   crlf$ = CHR$13 + CHR$10 port$ = "12321" host$ = FN_gethostname PR...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#D
D
import std.stdio, std.array, std.range, std.typecons, std.string, std.conv, std.algorithm; alias R = replicate;   void main() { enum nLines = 25; enum notCell = (in char c) pure => (c == '1') ? "0" : "1";   foreach (immutable rule; [90, 30]) { writeln("\nRule: ", rule); immutable rule...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Elixir
Elixir
  defmodule Elementary_cellular_automaton do def infinite(cell, rule, times) do each(cell, rule_pattern(rule), times) end   defp each(_, _, 0), do: :ok defp each(cells, rules, times) do IO.write String.duplicate(" ", times) IO.puts String.replace(cells, "0", ".") |> String.replace("1", "#") c = ...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[NextInSequence, EKGSequence] NextInSequence[seq_List] := Module[{last, new = 1, holes, max, sel, found, i}, last = Last[seq]; max = Max[seq]; holes = Complement[Range[max], seq]; sel = SelectFirst[holes, Not[CoprimeQ[last, #]] &]; If[MissingQ[sel], i = max; found = False; While[! found, ...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Nim
Nim
import algorithm, math, sets, strformat, strutils   #---------------------------------------------------------------------------------------------------   iterator ekg(n, limit: Positive): (int, int) = var values: HashSet[int] doAssert n >= 2 yield (1, 1) yield (2, n) values.incl(n) var i = 3 var prev = n...
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...
#Sidef
Sidef
var s = ""; var s = String.new;
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...
#Smalltalk
Smalltalk
"Assign empty string to a variable" str := ''.   "Check that string is empty" str isEmpty.   "Check that string is not empty" str isEmpty not. "alternatives:" str notEmpty str size = 0 str = ''
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PowerShell
PowerShell
  &{}  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Processing
Processing
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#ProDOS
ProDOS
IGNORELINE
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 ...
#Picat
Picat
ethiopian(Multiplier, Multiplicand) = ethiopian(Multiplier, Multiplicand,false).   ethiopian(Multiplier, Multiplicand,Tutor) = Result => if Tutor then printf("\n%d * %d:\n",Multiplier, Multiplicand) end, Result1 = 0, while (Multiplier >= 1) OldResult = Result1, if not even(Multiplier) then Re...
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...
#Smalltalk
Smalltalk
Number extend [ my_factorial [ (self < 2) ifTrue: [ ^1 ] ifFalse: [ ^ (2 to: self) fold: [ :a :b | a * b ] ] ] ].   7 factorial printNl. 7 my_factorial printNl.
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...
#SenseTalk
SenseTalk
  set num to random of 100 -- start with a random number from 1 to 100   // use the 'is a' operator to test the value if num is an odd number then put num & " is odd"   // see if num is divisible by 2 if num is divisible by 2 then put num & " is even (is divisible by 2)"   // check to see if the remainder is 0 when div...
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...
#SequenceL
SequenceL
even(x) := x mod 2 = 0; odd(x) := x mod 2 = 1;
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <unistd.h> #include <sys/wait.h> #include <signal.h>   #define MAX_ENQUEUED 20 #define BUF_LEN 256 #define PORT_STR "12321"   /* --------------------------------------...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Go
Go
package main   import ( "fmt" "strings" )   func btoi(b bool) int { if b { return 1 } return 0 }   func evolve(l, rule int) { fmt.Printf(" Rule #%d:\n", rule) cells := "O" for x := 0; x < l; x++ { cells = addNoCells(cells) width := 40 + (len(cells) >> 1) f...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Perl
Perl
use List::Util qw(none sum);   sub gcd { my ($u,$v) = @_; $v ? gcd($v, $u%$v) : abs($u) } sub shares_divisors_with { gcd( $_[0], $_[1]) > 1 }   sub EKG { my($n,$limit) = @_; my @ekg = (1, $n); while (@ekg < $limit) { for my $i (2..1e18) { next unless none { $_ == $i } @ekg and shares_div...
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...
#SNOBOL4
SNOBOL4
* ASSIGN THE NULL STRING TO X X = * CHECK THAT X IS INDEED NULL EQ(X, NULL)  :S(YES) OUTPUT = 'NOT NULL' :(END) YES OUTPUT = 'NULL' END  
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...
#Standard_ML
Standard ML
(* Assign empty string to a variable *) val s = "" (* Check that a string is empty*) s = "" (* Check that a string is nonempty *) s <> ""
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Programming_Language
Programming Language
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PSQL
PSQL
EXECUTE BLOCK AS BEGIN END
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PureBasic
PureBasic
 
http://rosettacode.org/wiki/Eertree
Eertree
An eertree is a data structure designed for efficient processing of certain palindrome tasks, for instance counting the number of sub-palindromes in an input string. The data structure has commonalities to both tries and suffix trees.   See links below. Task Construct an eertree for the string "eertree", then outp...
#11l
11l
T Node Int length Int suffix [Char = Int] edges   F (length, suffix = 0) .length = length .suffix = suffix   -V oddRoot = 1   F eertree(s) V tree = [Node(0, :oddRoot), Node(-1, :oddRoot)] V suffix = :oddRoot L(c) s V i = L.index V n = suffix Int k L k = ...
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 ...
#PicoLisp
PicoLisp
(de halve (N) (/ N 2) )   (de double (N) (* N 2) )   (de even? (N) (not (bit? 1 N)) )   (de ethiopian (X Y) (let R 0 (while (>= X 1) (or (even? X) (inc 'R Y)) (setq X (halve X) Y (double Y) ) ) R ) )
http://rosettacode.org/wiki/Elementary_cellular_automaton
Elementary cellular automaton
An elementary cellular automaton is a one-dimensional cellular automaton where there are two possible states (labeled 0 and 1) and the rule to determine the state of a cell in the next generation depends only on the current state of the cell and its two immediate neighbors. Those three values can be encoded with three ...
#11l
11l
V SIZE = 32 V LINES = SIZE I/ 2 V RULE = 90   F ruleTest(x) R I :RULE [&] (1 << (7 [&] x)) != 0 {1} E 0   F bitVal(s, bit) R I (s >> bit) [&] 1 != 0 {1} E 0   F evolve(&s) V t = 0 t [|]= ruleTest((bitVal(s, 0) << 2) [|] (bitVal(s, :SIZE - 1) << 1) [|] bitVal(s, :SIZE - 2)) << (:SIZE - 1) t [|]= ruleTest(...
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...
#SNOBOL4
SNOBOL4
define('rfact(n)') :(rfact_end) rfact rfact = le(n,0) 1 :s(return) rfact = n * rfact(n - 1) :(return) rfact_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...
#SETL
SETL
xs := {1..10}; evens := {x in xs | even( x )}; odds := {x in xs | odd( x )}; print( evens ); print( odds );
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...
#Shen
Shen
(define even? 0 -> true X -> (odd? (- X 1)))   (define odd? 0 -> false X -> (even? (- X 1)))
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#C.23
C#
using System.Net.Sockets; using System.Threading;   namespace ConsoleApplication1 { class Program { static TcpListener listen; static Thread serverthread;   static void Main(string[] args) { listen = new TcpListener(System.Net.IPAddress.Parse("127.0.0.1"), 12321); ...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Haskell
Haskell
{-# LANGUAGE DeriveFunctor #-}   import Control.Comonad import Data.InfList (InfList (..), (+++)) import qualified Data.InfList as Inf   data Cells a = Cells (InfList a) a (InfList a) deriving Functor   view n (Cells l x r) = reverse (Inf.take n l) ++ [x] ++ (Inf.take n r)   fromList [] = fromList [0] fromList (x:x...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#J
J
ext9=: (9#1-{.!.1),],9#1-{:!.1 trim=: |.@(}.~ ] i. 1-{.)^:2 next=: trim@(((8$2) #: [) {~ 2 #. 1 - [: |: |.~"1 0&_1 0 1@]) ext9
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#jq
jq
  def lpad($len; $fill): tostring | ($len - length) as $l | ($fill * $l)[:$l] + .;   def lpad($len): lpad($len; " ");   # Like *ix `tr` but it is as though $to is padded with blanks def tr($from;$to): explode as $s | ($from | explode) as $f | ($to | explode) as $t | reduce range(0;length) as $i ([]; ($f...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Phix
Phix
with javascript_semantics constant LIMIT = 100 constant starts = {2, 5, 7, 9, 10} sequence ekg = {} string fmt = "EKG(%2d): ["&join(repeat("%d",min(LIMIT,30))," ")&"]\n" for s=1 to length(starts) do ekg = append(ekg,{1,starts[s]}&repeat(0,LIMIT-2)) for n=3 to LIMIT do -- a potential sequence member cann...
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...
#Stata
Stata
scalar s=""   display s==""   * Alternatively, check the length display length(s)==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...
#Swift
Swift
var s = "" if s.isEmpty { // alternately, s == "" println("s is empty") } else { println("s is not empty") }
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Python
Python
1 QUIT
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#QUACKASM
QUACKASM
1 QUIT
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Quackery
Quackery
 
http://rosettacode.org/wiki/Eertree
Eertree
An eertree is a data structure designed for efficient processing of certain palindrome tasks, for instance counting the number of sub-palindromes in an input string. The data structure has commonalities to both tries and suffix trees.   See links below. Task Construct an eertree for the string "eertree", then outp...
#C.23
C#
using System; using System.Collections.Generic;   namespace Eertree { class Node { public Node(int length) { this.Length = length; // empty or this.Edges = new Dictionary<char, int>(); }   public Node(int length, Dictionary<char, int> edges, int suffix) { ...
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 ...
#Pike
Pike
int ethopian_multiply(int l, int r) { int halve(int n) { return n/2; }; int double(int n) { return n*2; }; int(0..1) evenp(int n) { return !(n%2); };   int product = 0; do { write("%5d %5d\n", l, r); if (!evenp(l)) product += r; l = halve(l); r = doubl...
http://rosettacode.org/wiki/Elementary_cellular_automaton
Elementary cellular automaton
An elementary cellular automaton is a one-dimensional cellular automaton where there are two possible states (labeled 0 and 1) and the rule to determine the state of a cell in the next generation depends only on the current state of the cell and its two immediate neighbors. Those three values can be encoded with three ...
#Action.21
Action!
DEFINE ROW_LEN="320" DEFINE MAX_COL="319" DEFINE MAX_ROW="191"   PROC GenerateMask(BYTE rule BYTE ARRAY mask) BYTE i   FOR i=0 TO 7 DO mask(i)=rule&1 rule==RSH 1 OD RETURN   PROC InitRow(BYTE ARRAY row) INT c   FOR c=0 TO MAX_COL DO row(c)=0 OD row(ROW_LEN RSH 1)=1 RETURN   PROC DrawRow(BY...
http://rosettacode.org/wiki/Elementary_cellular_automaton
Elementary cellular automaton
An elementary cellular automaton is a one-dimensional cellular automaton where there are two possible states (labeled 0 and 1) and the rule to determine the state of a cell in the next generation depends only on the current state of the cell and its two immediate neighbors. Those three values can be encoded with three ...
#Ada
Ada
with Ada.Text_IO; procedure Elementary_Cellular_Automaton is   type t_Rule is new Integer range 0..2**8-1; type t_State is array (Integer range <>) of Boolean;   Cell_Image : constant array (Boolean) of Character := ('.', '#');   function Image (State : in t_State) return String is (Cell_Image(State(S...
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...
#Spin
Spin
con _clkmode = xtal1 + pll16x _clkfreq = 80_000_000   obj ser : "FullDuplexSerial.spin"   pub main | i ser.start(31, 30, 0, 115200)   repeat i from 0 to 10 ser.dec(fac(i)) ser.tx(32)   waitcnt(_clkfreq + cnt) ser.stop cogstop(0)   pub fac(n) : f f := 1 repeat while n > 0 f *= n 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...
#Sidef
Sidef
var n = 42; say n.is_odd; # false say n.is_even; # true
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...
#Smalltalk
Smalltalk
5 even 5 odd
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#Clojure
Clojure
(use '[clojure.contrib.server-socket :only (create-server)]) (use '[clojure.contrib.duck-streams :only (read-lines write-lines)])   (defn echo [input output] (write-lines (java.io.PrintWriter. output true) (read-lines input)))   (create-server 12321 echo)
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Julia
Julia
function ecainfinite(cells, rule, n) notcell(cell) = (cell == '1') ? '0' : '1' rulebits = reverse(string(rule, base = 2, pad = 8)) neighbors2next = Dict(string(n - 1, base=2, pad=3) => rulebits[n] for n in 1:8) ret = String[] for i in 1:n push!(ret, cells) cells = notcell(cells[1])^2...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Kotlin
Kotlin
// version 1.1.51   fun evolve(l: Int, rule: Int) { println(" Rule #$rule:") var cells = StringBuilder("*") for (x in 0 until l) { addNoCells(cells) val width = 40 + (cells.length shr 1) println(cells.padStart(width)) cells = step(cells, rule) } }   fun step(cells: String...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Python
Python
from itertools import count, islice, takewhile from math import gcd   def EKG_gen(start=2): """\ Generate the next term of the EKG together with the minimum cache of numbers left in its production; (the "state" of the generator). Using math.gcd """ c = count(start + 1) last, so_far = start,...
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...
#Tcl
Tcl
set s "" if {$s eq ""} {puts "s contains an empty string"} if {$s ne ""} {puts "s contains a non-empty string"}
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...
#TorqueScript
TorqueScript
$empty = "";
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Quite_BASIC
Quite BASIC
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#R
R
  #lang racket  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Racket
Racket
  #lang racket  
http://rosettacode.org/wiki/Eertree
Eertree
An eertree is a data structure designed for efficient processing of certain palindrome tasks, for instance counting the number of sub-palindromes in an input string. The data structure has commonalities to both tries and suffix trees.   See links below. Task Construct an eertree for the string "eertree", then outp...
#C.2B.2B
C++
#include <iostream> #include <functional> #include <map> #include <vector>   struct Node { int length; std::map<char, int> edges; int suffix;   Node(int l) : length(l), suffix(0) { /* empty */ }   Node(int l, const std::map<char, int>& m, int s) : length(l), edges(m), suffix(s) { ...
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 ...
#PL.2FI
PL/I
  declare (L(30), R(30)) fixed binary; declare (i, s) fixed binary;   L, R = 0; put skip list ('Hello, please type two values and I will print their product:'); get list (L(1), R(1)); put edit ('The product of ', trim(L(1)), ' and ', trim(R(1)), ' is ') (a); do i = 1 by 1 while (L(i) ^= 0); ...
http://rosettacode.org/wiki/Elementary_cellular_automaton
Elementary cellular automaton
An elementary cellular automaton is a one-dimensional cellular automaton where there are two possible states (labeled 0 and 1) and the rule to determine the state of a cell in the next generation depends only on the current state of the cell and its two immediate neighbors. Those three values can be encoded with three ...
#ALGOL_68
ALGOL 68
BEGIN # elementary cellular automaton # COMMENT returns the next state from state using rule; s must be at least 2 characters long and consist of # and - only COMMENT PROC next state = ( STRING state, INT rule )STRING: BEGIN COMMENT returns 1 or 0 depending on whether c = # or not COMMENT ...
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...
#SPL
SPL
fact(n)=  ? n!>1, <=1 <= n*fact(n-1) .
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...
#SNOBOL4
SNOBOL4
DEFINE('even(n)')  :(even_end) even even = (EQ(REMDR(n, 2), 0) 'even', 'odd') :(RETURN) even_end   OUTPUT = "-2 is " even(-2) OUTPUT = "-1 is " even(-1) OUTPUT = "0 is " even(0) OUTPUT = "1 is " even(1) OUTPUT = "2 is " even(2) 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...
#SNUSP
SNUSP
  $====!/?\==even# - - #odd==\?/  
http://rosettacode.org/wiki/Echo_server
Echo server
Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from local...
#CoffeeScript
CoffeeScript
  net = require("net") server = net.createServer (conn) -> console.log "Connection from #{conn.remoteAddress} on port #{conn.remotePort}" conn.setEncoding "utf8" buffer = "" conn.on "data", (data) -> i = 0   while i <= data.length char = data.charAt(i) buffer += char if char is "\n" ...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
CellularAutomaton[18, {{1}, 0}, 15] // ArrayPlot CellularAutomaton[30, {{1}, 0}, 15] // ArrayPlot
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Nim
Nim
import strutils     func step(cells: string; rule: int): string = for i in 0..(cells.len - 3): var bin = 0 var b = 2 for n in i..(i + 2): inc bin, ord(cells[n] == '*') shl b b = b shr 1 let a = if (rule and 1 shl bin) != 0: '*' else: '.' result.add(a)     func addNoCells(cells: var str...
http://rosettacode.org/wiki/Elementary_cellular_automaton/Infinite_length
Elementary cellular automaton/Infinite length
The purpose of this task is to create a version of an Elementary cellular automaton whose number of cells is only limited by the memory size of the computer. To be precise, consider the state of the automaton to be made of an infinite number of cells, but with a bounded support. In other words, to describe the state o...
#Perl
Perl
sub evolve { my ($rule, $pattern) = @_; my $offset = 0;   while (1) { my ($l, $r, $st); $pattern =~ s/^((.)\g2*)/$2$2/ and $l = $2, $offset -= length($2); $pattern =~ s/(.)\g1*$/$1$1/ and $r = $1;   $st = $pattern;   $pattern =~ tr/01/.#/; printf "%5d| %s%s\n", $offset, ' ' x (40 + $offset), $pattern; ...
http://rosettacode.org/wiki/EKG_sequence_convergence
EKG sequence convergence
The sequence is from the natural numbers and is defined by: a(1) = 1; a(2) = Start = 2; for n > 2, a(n) shares at least one prime factor with a(n-1) and is the smallest such natural number not already used. The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed)....
#Raku
Raku
sub infix:<shares-divisors-with> { ($^a gcd $^b) > 1 }   sub next-EKG ( *@s ) { return first { @s ∌ $_ and @s.tail shares-divisors-with $_ }, 2..*; }   sub EKG ( Int $start ) { 1, $start, &next-EKG … * }   sub converge-at ( @ints ) { my @ekgs = @ints.map: &EKG;   return (2 .. *).first: -> $i...
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...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT s="" IF (s=="") PRINT "s is an empty string" IF (s!="") PRINT "s is a non-empty string"  
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...
#TXR
TXR
@(bind a "")
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Raku
Raku
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Raven
Raven
rebol []
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#REBOL
REBOL
rebol []
http://rosettacode.org/wiki/Element-wise_operations
Element-wise operations
This task is similar to:   Matrix multiplication   Matrix transposition Task Implement basic element-wise matrix-matrix and scalar-matrix operations, which can be referred to in other, higher-order tasks. Implement:   addition   subtraction   multiplication   division   exponentiation Extend the task if ...
#Ada
Ada
with Ada.Text_IO, Matrix_Scalar;   procedure Scalar_Ops is   subtype T is Integer range 1 .. 3;   package M is new Matrix_Scalar(T, T, Integer);   -- the functions to solve the task function "+" is new M.Func("+"); function "-" is new M.Func("-"); function "*" is new M.Func("*"); ...
http://rosettacode.org/wiki/Eertree
Eertree
An eertree is a data structure designed for efficient processing of certain palindrome tasks, for instance counting the number of sub-palindromes in an input string. The data structure has commonalities to both tries and suffix trees.   See links below. Task Construct an eertree for the string "eertree", then outp...
#D
D
import std.array; import std.stdio;   void main() { auto tree = eertree("eertree"); writeln(subPalindromes(tree)); }   struct Node { int length; int[char] edges; int suffix; }   const evenRoot = 0; const oddRoot = 1;   Node[] eertree(string s) { Node[] tree = [ Node(0, null, oddRoot), ...
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 ...
#PL.2FSQL
PL/SQL
CREATE OR REPLACE PACKAGE ethiopian IS   FUNCTION multiply ( left IN INTEGER, right IN INTEGER) RETURN INTEGER;   END ethiopian; /   CREATE OR REPLACE PACKAGE BODY ethiopian IS   FUNCTION is_even(item IN INTEGER) RETURN BOOLEAN IS BEGIN RETURN item MOD 2 = 0; END is_even;   FUNCTION do...
http://rosettacode.org/wiki/Elementary_cellular_automaton
Elementary cellular automaton
An elementary cellular automaton is a one-dimensional cellular automaton where there are two possible states (labeled 0 and 1) and the rule to determine the state of a cell in the next generation depends only on the current state of the cell and its two immediate neighbors. Those three values can be encoded with three ...
#AutoHotkey
AutoHotkey
state := StrSplit("0000000001000000000") rule := 90 output := "Rule: " rule Loop, 10 { output .= "`n" A_Index "`t" PrintState(state) state := NextState(state, rule) } Gui, Font,, Courier New Gui, Add, Text,, % output Gui, Show return   GuiClose: ExitApp   ; Returns the next state based on the current state and rule. ...
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...
#SSEM
SSEM
11100000000000100000000000000000 0. -7 to c 10101000000000010000000000000000 1. Sub. 21 10100000000001100000000000000000 2. c to 5 10100000000000100000000000000000 3. -5 to c 10100000000001100000000000000000 4. c to 5 00000000000000000000000000000000 5. generated at run time 00000000000001110000000000000000...
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...
#SPL
SPL
> n, 0..9  ? #.even(n), #.output(n," even")  ? #.odd(n), #.output(n," odd") <
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...
#SQL
SQL
-- Setup a table with some integers CREATE TABLE ints(INT INTEGER); INSERT INTO ints VALUES (-1); INSERT INTO ints VALUES (0); INSERT INTO ints VALUES (1); INSERT INTO ints VALUES (2);   -- Are they even or odd? SELECT INT, CASE MOD(INT, 2) WHEN 0 THEN 'Even' ELSE 'Odd' END FROM ints;