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_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...
#Prolog
Prolog
assign_empty_string(Variable) :- Variable = "".   is_empty_string(String) :- String == "". not_empty_string(String) :- String \== "".  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#NetRexx
NetRexx
class empty
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#NewLISP
NewLISP
;
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Nim
Nim
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 ...
#Objective-C
Objective-C
#import <stdio.h>   BOOL iseven(int x) { return (x&1) == 0; }   @interface EthiopicMult : NSObject + (int)mult: (int)plier by: (int)plicand; + (int)halve: (int)a; + (int)double: (int)a; @end   @implementation EthiopicMult + (int)mult: (int)plier by: (int)plicand { int r = 0; while(plier >= 1) { if ( !iseven(p...
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...
#Scala
Scala
def factorial(n: Int)={ var res = 1 for(i <- 1 to n) res *= i res }
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...
#PL.2FM
PL/M
100H: BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT; PUT$CHAR: PROCEDURE (CH); DECLARE CH BYTE; CALL BDOS(2, CH); END PUT$CHAR; PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9, S); END PRINT;   DECLARE I BYTE; DO I='0' TO '9'; CALL PUT$CHA...
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...
#Plain_English
Plain English
To run: Start up. If 56 is even, write "56 is even!" to the console. If 4 is odd, write "4 is odd!" to the console. Wait for the escape key. Shut down.
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...
#PureBasic
PureBasic
Procedure.s isStringEmpty(a.s) If a ProcedureReturn "String is not empty, it contains '" + a + "'." Else ProcedureReturn "String is empty, or null." EndIf EndProcedure   If OpenConsole() Define a.s = "" Define b.s = "stuff" PrintN(isStringEmpty(a)) PrintN(isStringEmpty(b))   Print(#CRLF$ + #CRL...
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...
#Python
Python
  s = '' # or: s = str()   if not s or s == '': print("String is empty")   if len(s) == 0: print("String is empty") else: print("String not empty")     # boolean test function for python2 and python3 # test for regular (non-unicode) strings # unicode strings # None def emptystring(s): if isinstance(s, ('...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Nit
Nit
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#NS-HUBASIC
NS-HUBASIC
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Objeck
Objeck
bundle Default { class Empty { function : Main(args : String[]) ~ Nil { } }
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 ...
#OCaml
OCaml
(* We optimize a bit by not keeping the intermediate lists, and summing the right column on-the-fly, like in the C version. The function takes "halve" and "double" operators and "is_even" predicate as arguments, but also "is_zero", "zero" and "add". This allows for more general uses of the ethiopian multipl...
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...
#Scheme
Scheme
(define (factorial n) (if (<= n 0) 1 (* n (factorial (- 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...
#PowerShell
PowerShell
  $IsOdd = -not ( [bigint]$N ).IsEven $IsEven = ( [bigint]$N ).IsEven  
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...
#Processing
Processing
  boolean isEven(int i){ return i%2 == 0; }   boolean isOdd(int i){ return i%2 == 1; }  
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)....
#11l
11l
F ekg(n, limit) Set[Int] values assert(n >= 2) V r = [(1, 1), (2, n)] values.add(n) V i = 3 V prev = n L i <= limit V val = 2 L I val !C values & gcd(val, prev) != 1 values.add(val) r [+]= (i, val) prev = val L.break val+...
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...
#QB64_2
QB64
DIM s1 AS STRING 'initialized empty IF LEN(s1) = 0 THEN PRINT "Empty"   s2$ = "" IF s2$ = "" THEN PRINT "Empty"   s3$ = "cat" IF LEN(s3$) <> 0 THEN PRINT "Not empty" IF s3$ <> "" THEN PRINT "Still 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...
#Quackery
Quackery
Welcome to Quackery.   Enter "leave" to leave the shell.   /O> $ "" temp put ( move an empty string to temp ) ... temp share ( copy the empty string on temp to the stack ) ... $ '' = ( compare the top of stack to an empty string, and replace it with .....
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Objective-C
Objective-C
int main(int argc, const char **argv) { return 0; }
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#OCaml
OCaml
;;
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Octave
Octave
oforth empty.of
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 ...
#Octave
Octave
function r = halve(a) r = floor(a/2); endfunction   function r = doublit(a) r = a*2; endfunction   function r = iseven(a) r = mod(a,2) == 0; endfunction   function r = ethiopicmult(plier, plicand, tutor=false) r = 0; if (tutor) printf("ethiopic multiplication of %d and %d\n", plier, plicand); endif wh...
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...
#Scilab
Scilab
answer = factorial(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...
#Prolog
Prolog
  even(N) :- (between(0, inf, N); integer(N) ), 0 is N mod 2.  
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...
#PureBasic
PureBasic
;use last bit method isOdd = i & 1 ;isOdd is non-zero if i is odd isEven = i & 1 ! 1 ;isEven is non-zero if i is even   ;use modular method isOdd = i % 2 ;isOdd is non-zero if i is odd isEven = i % 2 ! 1 ;isEven is non-zero if i is even
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)....
#Action.21
Action!
INCLUDE "D2:SORT.ACT" ;from the Action! Tool Kit   BYTE FUNC Contains(BYTE ARRAY a BYTE len,b) BYTE i   IF len=0 THEN RETURN (0) FI FOR i=0 TO len-1 DO IF a(i)=b THEN RETURN (1) FI OD RETURN (0)   BYTE FUNC Gcd(BYTE a,b) BYTE tmp   IF a<b THEN tmp=a a=b b=tmp FI   WHILE b#0 D...
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)....
#Ada
Ada
with Ada.Text_IO; with Ada.Containers.Generic_Array_Sort;   procedure EKG_Sequences is   type Element_Type is new Integer;   type Index_Type is new Integer range 1 .. 100; subtype Show_Range is Index_Type range 1 .. 30;   type Sequence is array (Index_Type range <>) of Element_Type; subtype EKG_Seque...
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...
#Quite_BASIC
Quite BASIC
10 let s="" 20 if s="" then let o="" 30 if s<>"" then let o="not " 40 print "The string is ";o;"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...
#R
R
s <- ''   if (s == '') cat('Empty\n') #or if (nchar(s) == 0) cat('Empty\n')   if (s != '') cat('Not empty\n') #or if (nchar(s) > 0) cat('Not empty\n')
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Oforth
Oforth
oforth empty.of
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Ol
Ol
  0
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#OOC
OOC
 
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 ...
#Oforth
Oforth
: halve 2 / ; : double 2 * ;   : ethiopian dup ifZero: [ nip return ] over double over halve ethiopian swap isEven ifTrue: [ nip ] else: [ + ] ;
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...
#Seed7
Seed7
const func bigInteger: factorial (in bigInteger: n) is func result var bigInteger: fact is 1_; local var bigInteger: i is 0_; begin for i range 1_ to n do fact *:= i; end for; end func;
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...
#Python
Python
>>> def is_odd(i): return bool(i & 1)   >>> def is_even(i): return not is_odd(i)   >>> [(j, is_odd(j)) for j in range(10)] [(0, False), (1, True), (2, False), (3, True), (4, False), (5, True), (6, False), (7, True), (8, False), (9, True)] >>> [(j, is_even(j)) for j in range(10)] [(0, True), (1, False), (2, True), (3, 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)....
#C
C
#include <stdio.h> #include <stdlib.h>   #define TRUE 1 #define FALSE 0 #define LIMIT 100   typedef int bool;   int compareInts(const void *a, const void *b) { int aa = *(int *)a; int bb = *(int *)b; return aa - bb; }   bool contains(int a[], int b, size_t len) { int i; for (i = 0; i < len; ++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...
#Racket
Racket
#lang racket   (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...
#Raku
Raku
my $s = ''; say 'String is empty' unless $s; say 'String is not empty' if $s;
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#OpenLisp
OpenLisp
  #!/openlisp/uxlisp -shell ()  
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 ...
#Ol
Ol
  (define (ethiopian-multiplication l r) (let ((even? (lambda (n) (eq? (mod n 2) 0))))   (let loop ((sum 0) (l l) (r r)) (print "sum: " sum ", l: " l ", r: " r) (if (eq? l 0) sum (loop (if (even? l) (+ sum r) sum) (floor (/ l 2)) (* r 2))))))...
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...
#Self
Self
n 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...
#Quackery
Quackery
[ 1 & ] is odd ( n --> b )   [ odd not ] is even ( n --> b )
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...
#R
R
is.even <- function(x) !is.odd(x)   is.odd <- function(x) intToBits(x)[1] == 1 #or is.odd <- function(x) x %% 2 == 1
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)....
#F.23
F#
  // Generate EKG Sequences. Nigel Galloway: December 6th., 2018 let EKG n=seq{ let fN,fG=let i=System.Collections.Generic.Dictionary<int,int>() let fN g=(if not (i.ContainsKey g) then i.[g]<-g);(g,i.[g]) ((fun e->i.[e]<-i.[e]+e), (fun l->l|>List.map fN)) let fU l=...
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...
#Rascal
Rascal
str s = ""; if (s=="") print("string s is empty"); if (s!="") print("string s 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...
#Red
Red
Red [] s: copy ""  ;; assign empty string ?? s if empty? s [print "string is empty "]  ;; check if string is empty s: "abc" prin s unless empty? s [print " not empty"]  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Openscad
Openscad
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#OxygenBasic
OxygenBasic
     
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Oz
Oz
unit
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 ...
#ooRexx
ooRexx
declare fun {Halve X} X div 2 end fun {Double X} X * 2 end fun {Even X} {Abs X mod 2} == 0 end %% standard function: Int.isEven   fun {EthiopicMult X Y} X >= 0 = true %% assert: X must not be negative   Rows = for L in X; L>0; {Halve L} %% C-like iter...
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...
#SequenceL
SequenceL
factorial(n) := product(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...
#Racket
Racket
(even? 6) ; -> true (even? 5) ; -> false (odd? 6) ; -> false (odd? 5) ; -> 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...
#Raku
Raku
subset Even of Int where * %% 2; subset Odd of Int where * % 2;   say 1 ~~ Even; # false say 1 ~~ Odd; # true say 1.5 ~~ Odd # false ( 1.5 is not an Int )
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)....
#Factor
Factor
USING: combinators.short-circuit formatting fry io kernel lists lists.lazy math math.statistics prettyprint sequences sequences.generalizations ;   : ekg? ( n seq -- ? ) { [ member? not ] [ last gcd nip 1 > ] } 2&& ;   : (ekg) ( seq -- seq' ) 2 lfrom over [ ekg? ] curry lfilter car suffix! ;   : ekg ( n limit -...
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)....
#Go
Go
package main   import ( "fmt" "sort" )   func contains(a []int, b int) bool { for _, j := range a { if j == b { return true } } return false }   func gcd(a, b int) int { for a != b { if a > b { a -= b } else { b -= a } ...
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...
#Retro
Retro
  ( by creating a variable ) "" keepString variable: foo   ( by setting an existing variable 'foo' ) "" keepString !foo  
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...
#REXX
REXX
/*REXX program shows how to assign an empty string, & then check for empty/not-empty str*/   /*─────────────── 3 simple ways to assign an empty string to a variable.*/ auk='' /*uses two single quotes (also called apostrophes); easier to peruse. */ ide="" /*uses two quotes, sometimes...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PARI.2FGP
PARI/GP
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Pascal
Pascal
program ProgramName;   begin end.
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PepsiScript
PepsiScript
#include default-libraries   #author .   class .:
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 ...
#Oz
Oz
declare fun {Halve X} X div 2 end fun {Double X} X * 2 end fun {Even X} {Abs X mod 2} == 0 end %% standard function: Int.isEven   fun {EthiopicMult X Y} X >= 0 = true %% assert: X must not be negative   Rows = for L in X; L>0; {Halve L} %% C-like iter...
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...
#SETL
SETL
$ Recursive proc fact(n); if (n < 2) then return 1; else return n * fact(n - 1); end if; end proc;   $ Iterative proc factorial(n); v := 1; for i in {2..n} loop v *:= i; end loop; return v; end proc;
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...
#Rascal
Rascal
public bool isEven(int n) = (n % 2) == 0; public bool isOdd(int n) = (n % 2) == 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...
#Red
Red
Red [ date: 2021-10-24 red-version: 0.6.4 description: "Test whether an integer is even or odd." ]   print even? 10 ;== true print odd? 10 ;== false
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)....
#Haskell
Haskell
import Data.List (findIndex, isPrefixOf, tails) import Data.Maybe (fromJust)   ----------------------- EKG SEQUENCE ---------------------   seqEKGRec :: Int -> Int -> [Int] -> [Int] seqEKGRec _ 0 l = l seqEKGRec k n [] = seqEKGRec k (n - 2) [k, 1] seqEKGRec k n l@(h : t) = seqEKGRec k (pred n) ( head ...
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...
#Ring
Ring
  cStr = NULL # empty string if cStr = NULL see "cstr is an empty string!" + nl else see "cstr is not empty string!" + nl ok  
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...
#Robotic
Robotic
  set "$string" to "" if "$string.length" = 0 then "empty" * "Not an empty string." end   : "empty" * "Empty string" end  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Perl
Perl
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Phix
Phix
main.
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PHP
PHP
main.
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 ...
#PARI.2FGP
PARI/GP
halve(n)=n\2; double(n)=2*n; even(n)=!(n%2); multE(a,b)={ my(d=0); while(a, if(!even(a), d+=b); a=halve(a); b=double(b)); d };
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...
#Shen
Shen
(define factorial 0 -> 1 X -> (* X (factorial (- X 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...
#ReScript
ReScript
let is_even = d => mod(d, 2) == 0   let is_odd = d => mod(d, 2) != 0
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...
#REXX
REXX
/*REXX program tests and displays if an integer is even or odd using different styles.*/ !.=0; do j=0 by 2 to 8;  !.j=1; end /*assign 0,2,4,6,8 to a "true" value.*/ /* [↑] assigns even digits to "true".*/ numeric digits 1000 ...
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...
#Ada
Ada
with Ada.Text_IO; with Ada.IO_Exceptions; with GNAT.Sockets; procedure Echo_Server is Receiver  : GNAT.Sockets.Socket_Type; Connection : GNAT.Sockets.Socket_Type; Client  : GNAT.Sockets.Sock_Addr_Type; Channel  : GNAT.Sockets.Stream_Access; begin GNAT.Sockets.Create_Socket (Socket => Receiver); ...
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)....
#J
J
  Until =: 2 :'u^:(0-:v)^:_' NB. unused but so fun prime_factors_of_tail =: ~.@:q:@:{: numbers_not_in_list =: -.~ >:@:i.@:(>./)     ekg =: 3 :0 NB. return next sequence if. 1 = # y do. NB. initialize 1 , y return. end. a =. prime_factors_of_tail y b =. numbers_not_in_list y index_o...
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...
#Ruby
Ruby
s = "" s = String.new s = "any string"; s.clear
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...
#Run_BASIC
Run BASIC
var$ = "" ' -------------- 'empty string ' ------------- if var$="" then print "String is Empty" if len(var$)=0 then print "String is Empty" ' ------------- 'not empty string ' ------------- if var$<>"" then print "String Not empty." if len(var$)>0 then print "String Not empty."
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Picat
Picat
main.
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PicoLisp
PicoLisp
(de foo ())
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Pike
Pike
int main(){}
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 ...
#Pascal
Pascal
program EthiopianMultiplication; {$IFDEF FPC} {$MODE DELPHI} {$ENDIF} function Double(Number: Integer): Integer; begin Result := Number * 2 end;   function Halve(Number: Integer): Integer; begin Result := Number div 2 end;   function Even(Number: Integer): Boolean; begin Result := Nu...
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...
#Sidef
Sidef
func factorial_recursive(n) { n == 0 ? 1 : (n * __FUNC__(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...
#Ring
Ring
  size = 10 for i = 1 to size if i % 2 = 1 see "" + i + " is odd" + nl else see "" + i + " is even" + nl ok next  
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...
#Ruby
Ruby
print "evens: " p -5.upto(5).select(&:even?) print "odds: " p -5.upto(5).select(&: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...
#Aime
Aime
void readc(dispatch w, file i, file o, data b) { integer e; data t;   while (1) { e = f_b_read(i, t, 1 << 10); if (e < 1) { if (e == -1) { w_resign(w, i); }   break; } else { e = b_frame(t, '\n'); if (e != -1...
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)....
#Java
Java
  import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map;   public class EKGSequenceConvergence {   public static void main(String[] args) { System.out.println("Calculate and show here the first 10 members of EKG[2], EKG[5], EKG[7], EK...
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...
#Rust
Rust
let s = ""; println!("is empty: {}", s.is_empty()); let t = "x"; println!("is empty: {}", t.is_empty()); let a = String::new(); println!("is empty: {}", a.is_empty()); let b = "x".to_string(); println!("is empty: {}", b.is_empty()); println!("is not empty: {}", !b.is_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...
#Scala
Scala
// assign empty string to a variable val s="" // check that string is empty s.isEmpty // true s=="" // true s.size==0 // true // check that string is not empty s.nonEmpty // false s!="" // false s.size>0 // false
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PIR
PIR
.sub empty_program .end
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Pixilang
Pixilang
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#PL.2FI
PL/I
s: proc options (main); end;
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 ...
#Perl
Perl
use strict;   sub halve { int((shift) / 2); } sub double { (shift) * 2; } sub iseven { ((shift) & 1) == 0; }   sub ethiopicmult { my ($plier, $plicand, $tutor) = @_; print "ethiopic multiplication of $plier and $plicand\n" if $tutor; my $r = 0; while ($plier >= 1) { $r += $plicand unless iseven($pl...
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...
#Simula
Simula
begin integer procedure factorial(n); integer n; begin integer fact, i; fact := 1; for i := 2 step 1 until n do fact := fact * i; factorial := fact end; integer f; outtext("factorials:"); outimage; for f := 0, 1, 2, 6, 9 do begin outint(f, 2); ...
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...
#Run_BASIC
Run BASIC
for i = 1 to 10 if i and 1 then print i;" is odd" else print i;" is even" next i
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#Rust
Rust
let is_odd = |x: i32| x & 1 == 1; let is_even = |x: i32| x & 1 == 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...
#AutoHotkey
AutoHotkey
#SingleInstance Force Network_Port = 12321 Network_Address = 127.0.0.1   NewData := false DataReceived = Gosub Connection_Init return   Connection_Init: OnExit, ExitSub socket := PrepareForIncomingConnection(Network_Address, Network_Port) if socket = -1 ExitApp   Process, Exist DetectHiddenWindows On ScriptMainWind...
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...
#11l
11l
F step(cells, rule) V result = ‘’ L(i) 0 .< cells.len - 2 V bin = 0 V b = 2 L(n) i .< i + 3 bin += Int(cells[n] == ‘*’) << b b >>= 1 V a = I (rule [&] (1 << bin)) != 0 {‘*’} E ‘.’ result ‘’= a R result   F addNoCells(&cells) V left = I cells[0] == ‘*’ {‘.’}...