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/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#AWK
AWK
  # syntax: GAWK -f EBAN_NUMBERS.AWK # converted from FreeBASIC BEGIN { main(2,1000,1) main(1000,4000,1) main(2,10000,0) main(2,100000,0) main(2,1000000,0) main(2,10000000,0) main(2,100000000,0) exit(0) } function main(start,stop,printable, b,count,i,m,r,t) { printf("%d-%d:",start,s...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Factor
Factor
USING: combinators.short-circuit.smart grouping io kernel lists lists.lazy math math.primes math.primes.factors math.statistics prettyprint sequences sequences.deep ;   : duffinian? ( n -- ? ) { [ prime? not ] [ dup divisors sum simple-gcd 1 = ] } && ;   : duffinians ( -- list ) 3 lfrom [ duffinian? ] lfilter ;   :...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Go
Go
package main   import ( "fmt" "math" "rcu" )   func isSquare(n int) bool { s := int(math.Sqrt(float64(n))) return s*s == n }   func main() { limit := 200000 // say d := rcu.PrimeSieve(limit-1, true) d[1] = false for i := 2; i < limit; i++ { if !d[i] { continue ...
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 ...
#Excel
Excel
EVAL =LAMBDA(s, EVALUATE(s))     matrix ={1,2,3;4,5,6;7,8,9}
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#BBC_BASIC
BBC BASIC
INPUT "Enter a variable name: " name$ INPUT "Enter a numeric value: " numeric$ dummy% = EVAL("FNassign("+name$+","+numeric$+")") PRINT "Variable " name$ " now has the value "; EVAL(name$) END   DEF FNassign(RETURN n, v) : n = v : = 0
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Bracmat
Bracmat
( put$"Enter a variable name: " & get$:?name & whl ' ( put$"Enter a numeric value: " & get$:?numeric:~# ) & !numeric:?!name & put$(str$("Variable " !name " now has the value " !!name \n)) );
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#C.23
C#
using System; using System.Dynamic; using System.Collections.Generic;   public class Program { public static void Main() { string varname = Console.ReadLine(); //Let's pretend the user has entered "foo" dynamic expando = new ExpandoObject(); var map = expando as IDictionary<strin...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#Common_Lisp
Common Lisp
  (defun egyptian-division (dividend divisor) (let* ((doublings (reverse (loop for n = divisor then (* 2 n) until (> n dividend) collect n))) (powers-of-two (reverse (loop for n = 1 then (* 2 n) repeat (length...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#D
D
  import std.stdio;   version(unittest) { // empty } else { int main(string[] args) { import std.conv;   if (args.length < 3) { stderr.writeln("Usage: ", args[0], " dividend divisor"); return 1; }   ulong dividend = to!ulong(args[1]); ulong divisor...
http://rosettacode.org/wiki/Egyptian_fractions
Egyptian fractions
An   Egyptian fraction   is the sum of distinct unit fractions such as: 1 2 + 1 3 + 1 16 ( = 43 48 ) {\displaystyle {\tfrac {1}{2}}+{\tfrac {1}{3}}+{\tfrac {1}{16}}\,(={\tfrac {43}{48}})} Each fraction in the expression has a numerator equal to   1   (unity)   and a denominator that...
#Factor
Factor
USING: backtrack formatting fry kernel locals make math math.functions math.ranges sequences ; IN: rosetta-code.egyptian-fractions   : >improper ( r -- str ) >fraction "%d/%d" sprintf ;   : improper ( x y -- a b ) [ /i ] [ [ rem ] [ nip ] 2bi / ] 2bi ;   :: proper ( x y -- a b ) y x / ceiling :> d1 1 d1 / y neg x r...
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...
#Ruby
Ruby
class Node def initialize(length, edges = {}, suffix = 0) @length = length @edges = edges @suffix = suffix end   attr_reader :length attr_reader :edges attr_accessor :suffix end   EVEN_ROOT = 0 ODD_ROOT = 1   def eertree(s) tree = [ Node.new(0, {}, ODD_ROOT), ...
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 ...
#Red
Red
Red["Ethiopian multiplication"]   halve: function [n][n >> 1] double: function [n][n << 1] ;== even? already exists   ethiopian-multiply: function [ "Returns the product of two integers using Ethiopian multiplication" a [integer!] "The multiplicand" b [integer!] "The multiplier" ][ result: 0 while [...
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 ...
#Haskell
Haskell
import Data.Array (listArray, (!), bounds, elems)   step rule a = listArray (l,r) res where (l,r) = bounds a res = [rule (a!r) (a!l) (a!(l+1)) ] ++ [rule (a!(i-1)) (a!i) (a!(i+1)) | i <- [l+1..r-1] ] ++ [rule (a!(r-1)) (a!r) (a!l) ]   runCA rule = iterate (step 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...
#True_BASIC
True BASIC
DEF FNfactorial(n) LET f = 1 FOR i = 2 TO n LET f = f*i NEXT i LET FNfactorial = f END DEF 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...
#x86-64_Assembly
x86-64 Assembly
  evenOdd: mov rax,1 and rax,rdi ret  
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...
#XBS
XBS
#> Typed XBS evenOrOdd function true = even false = odd <# func evenOrOdd(a:number=0){ send a%2==0; } set arr:array = [0,1,2,3,4,5,6,7,9,10]; foreach(v of arr){ log(v+" is even? "+evenOrOdd(v)) }
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...
#Java
Java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;   public class EchoServer {   p...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Tiny_BASIC
Tiny BASIC
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Toka
Toka
bye
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Trith
Trith
 
http://rosettacode.org/wiki/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#C
C
#include "stdio.h" #include "stdbool.h"   #define ARRAY_LEN(a,T) (sizeof(a) / sizeof(T))   struct Interval { int start, end; bool print; };   int main() { struct Interval intervals[] = { {2, 1000, true}, {1000, 4000, true}, {2, 10000, false}, {2, 100000, false}, {2, 1...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#J
J
sigmasum=: >:@#.~/.~&.q: composite=: 1&< * 0 = 1&p: duffinian=: composite * 1 = ] +. sigmasum
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Julia
Julia
using Primes   function σ(n) f = [one(n)] for (p,e) in factor(n) f = reduce(vcat, [f*p^j for j in 1:e], init=f) end return sum(f) end   isDuffinian(n) = !isprime(n) && gcd(n, σ(n)) == 1   function testDuffinians() println("First 50 Duffinian numbers:") foreach(p -> print(rpad(p[2], 4), p...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[DuffianQ] DuffianQ[n_Integer] := CompositeQ[n] \[And] CoprimeQ[DivisorSigma[1, n], n] dns = Select[DuffianQ][Range[1000000]]; Take[dns, UpTo[50]] triplets = ToString[dns[[#]]] <> "\[LongDash]" <> ToString[dns[[# + 2]]] & /@ SequencePosition[Differences[dns], {1, 1}][[All, 1]] Multicolumn[triplets, {Automatic, ...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Perl
Perl
use strict; use warnings; use feature <say state>; use List::Util 'max'; use ntheory qw<divisor_sum is_prime gcd>;   sub table { my $t = shift() * (my $c = 1 + max map {length} @_); ( sprintf( ('%'.$c.'s')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr }   sub duffinian { my($n) = @_; state $c = 1; state @D; do { push @D, ...
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 ...
#Factor
Factor
USING: combinators.extras formatting kernel math.functions math.matrices math.vectors prettyprint sequences ;   : show ( a b words -- ) [ 3dup execute( x x -- x ) [ unparse ] dip "%u %u %s = %u\n" printf ] 2with each ; inline   : m^n ( m n -- m ) [ ^ ] curry matrix-map ; : m^ ( m m -- m ) [ v^ ...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Clojure
Clojure
(eval `(def ~(symbol (read)) 42))
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Common_Lisp
Common Lisp
  (setq var-name (read)) ; reads a name into var-name (set var-name 1) ; assigns the value 1 to a variable named as entered by the user  
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#Delphi
Delphi
  program Egyptian_division;   {$APPTYPE CONSOLE}   uses System.SysUtils, System.Math, System.Console; //https://github.com/JensBorrisholt/DelphiConsole   type TIntegerDynArray = TArray<Integer>;   TIntegerDynArrayHelper = record helper for TIntegerDynArray public procedure Add(value: Integer); end;  ...
http://rosettacode.org/wiki/Egyptian_fractions
Egyptian fractions
An   Egyptian fraction   is the sum of distinct unit fractions such as: 1 2 + 1 3 + 1 16 ( = 43 48 ) {\displaystyle {\tfrac {1}{2}}+{\tfrac {1}{3}}+{\tfrac {1}{16}}\,(={\tfrac {43}{48}})} Each fraction in the expression has a numerator equal to   1   (unity)   and a denominator that...
#FreeBASIC
FreeBASIC
' version 16-01-2017 ' compile with: fbc -s console   #Define max 30   #Include Once "gmp.bi"   Dim Shared As Mpz_ptr num(max), den(max)   Function Egyptian_fraction(fraction As String, ByRef whole As Integer, range As Integer = 0) As Integer   If InStr(fraction,"/") = 0 Then Print "Not a fraction, program ...
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Class Node Public Sub New(Len As Integer) Length = Len Edges = New Dictionary(Of Char, Integer) End Sub   Public Sub New(len As Integer, edg As Dictionary(Of Char, Integer), suf As Integer) Length = len Edges = If(IsNothing(edg...
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 ...
#Relation
Relation
  function half(x) set result = floor(x/2) end function   function double(x) set result = 2*x end function   function even(x) set result = (x/2 > floor(x/2)) end function   program ethiopian_mul(a,b) relation first, second while a >= 1 insert a, b set a = half(a) set b = double(b) end while extend third = even(first) *...
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 ...
#J
J
next=: ((8$2) #: [) {~ 2 #. 1 - [: |: |.~"1 0&_1 0 1@] ' *'{~90 next^:(i.9) 0 0 0 0 0 0 1 0 0 0 0 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 ...
#Java
Java
import java.awt.*; import java.awt.event.ActionEvent; import javax.swing.*; import javax.swing.Timer;   public class WolframCA extends JPanel { final int[] ruleSet = {30, 45, 50, 57, 62, 70, 73, 75, 86, 89, 90, 99, 101, 105, 109, 110, 124, 129, 133, 135, 137, 139, 141, 164,170, 232}; byte[][] cells; ...
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...
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT LOOP num=-1,12 IF (num==0,1) THEN f=1 ELSEIF (num<0) THEN PRINT num," is negative number" CYCLE ELSE f=VALUE(num) LOOP n=#num,2,-1 f=f*(n-1) ENDLOOP ENDIF formatnum=CENTER(num,+2," ") PRINT "factorial of ",formatnum," = ",f ENDLOOP
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...
#xEec
xEec
  >100 p i# jz-1 o# t h#1 ms jz2003 p >0110 h#2 r ms t h#1 ms p jz1002 h? jz2003 p jn0110 h#10 o$ p jn100 >2003 p p h#0 h#10 h$d h$d h$o h#32 h$s h$i h#32 jn0000 >1002 p p h#0 h#10 h$n h$e h$v h$e h#32 h$s h$i h#32 >0000 o$ p jn0000 jz100  
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...
#XLISP
XLISP
(defun my-evenp (x) (= (logand x 1) 0) )   (defun my-oddp (x) (/= (logand 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...
#JavaScript
JavaScript
const net = require('net');   function handleClient(conn) { console.log('Connection from ' + conn.remoteAddress + ' on port ' + conn.remotePort);   conn.setEncoding('utf-8');   let buffer = '';   function handleData(data) { for (let i = 0; i < data.length; i++) { const char = data.ch...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#True_BASIC
True BASIC
END
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#UNIX_Shell
UNIX Shell
#!/bin/sh
http://rosettacode.org/wiki/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#C.23
C#
using System;   namespace EbanNumbers { struct Interval { public int start, end; public bool print;   public Interval(int start, int end, bool print) { this.start = start; this.end = end; this.print = print; } }   class Program { st...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Phix
Phix
with javascript_semantics sequence duffinian = {false} integer n = 2, count = 0, triplet = 0, triple_count = 0 while triple_count<50 do bool bDuff = not is_prime(n) and gcd(n,sum(factors(n,1)))=1 duffinian &= bDuff if bDuff then count += 1 if count=50 then sequence s50 = apply(tr...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Raku
Raku
use Prime::Factor;   my @duffinians = lazy (3..*).hyper.grep: { !.is-prime && $_ gcd .&divisors.sum == 1 };   put "First 50 Duffinian numbers:\n" ~ @duffinians[^50].batch(10)».fmt("%3d").join: "\n";   put "\nFirst 40 Duffinian triplets:\n" ~ ((^∞).grep: -> $n { (@duffinians[$n] + 1 == @duffinians[$n + 1]) && (@duff...
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 ...
#Fortran
Fortran
  program element_operations implicit none   real(kind=4), dimension(3,3) :: a,b integer :: i   a=reshape([(i,i=1,9)],shape(a))   print*,'addition' b=a+a call print_arr(b)   print*,'multiplication' b=a*a call print_arr(b)   print*,'division' b=a/b call print_arr(b)   print*,'exponentiation' ...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#D.C3.A9j.C3.A0_Vu
Déjà Vu
local :var-name !run-blob !compile-string dup concat( ":" !prompt "Enter a variable name: " ) local var-name 42   #Assuming the user types THISISWEIRD, otherwise this'll error !. THISISWEIRD
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#E
E
def makeNounExpr := <elang:evm.makeNounExpr>   def dynVarName(name) { def variable := makeNounExpr(null, name, null)   return e`{   def a := 1 def b := 2 def c := 3   { def $variable := "BOO!" [a, b, c] }   }`.eval(safeScope) }   ? dynVarName("...
http://rosettacode.org/wiki/Draw_a_pixel
Draw a pixel
Task Create a window and draw a pixel in it, subject to the following:  the window is 320 x 240  the color of the pixel must be red (255,0,0)  the position of the pixel is x = 100, y = 100
#Action.21
Action!
PROC Main() BYTE CH=$02FC, ;Internal hardware value for last key pressed PALNTSC=$D014 ;To check if PAL or NTSC system is used   Graphics(8+16) ;Graphics 320x192 with 2 luminances IF PALNTSC=15 THEN SetColor(1,4,6) ;Red color for NTSC SetColor(2,4,15) ELSE SetColor(1,2,6) ;Red color for PAL ...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#Erlang
Erlang
-module(egypt).   -export([ediv/2]).   ediv(A, B) -> {Twos, Ds} = genpowers(A, [1], [B]), {Quot, C} = accumulate(A, Twos, Ds), {Quot, abs(C - A)}.   genpowers(A, [_|Ts], [D|Ds]) when D > A -> {Ts, Ds}; genpowers(A, [T|_] = Twos, [D|_] = Ds) -> genpowers(A, [2*T|Twos], [D*2|Ds]).   accumulate(N, Twos, Ds) ->...
http://rosettacode.org/wiki/Egyptian_fractions
Egyptian fractions
An   Egyptian fraction   is the sum of distinct unit fractions such as: 1 2 + 1 3 + 1 16 ( = 43 48 ) {\displaystyle {\tfrac {1}{2}}+{\tfrac {1}{3}}+{\tfrac {1}{16}}\,(={\tfrac {43}{48}})} Each fraction in the expression has a numerator equal to   1   (unity)   and a denominator that...
#Frink
Frink
  frac[p, q] := { a = makeArray[[0]] if p > q { a.push[floor[p / q]] p = p mod q } while p > 1 { d = ceil[q / p] a.push[1/d] [p, q] = [-q mod p, d q] } if p == 1 a.push[1/q] a }   showApproximations[false]   egypt[p, q] := join[" + ", f...
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...
#Wren
Wren
class Node { construct new() { _edges = {} // edges (or forward links) _link = null // suffix link (backward links) _len = 0 // the length of the node }   edges { _edges } link { _link } link=(l) { _link = l } len { _len } len=(l) { _len = l } ...
http://rosettacode.org/wiki/Ethiopian_multiplication
Ethiopian multiplication
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. Method: Take two numbers to be multiplied and write them down at the top of two columns. In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ...
#REXX
REXX
/*REXX program multiplies two integers by the Ethiopian (or Russian peasant) method. */ numeric digits 3000 /*handle some gihugeic integers. */ parse arg a b . /*get two numbers from the command line*/ say 'a=' a ...
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 ...
#JavaScript
JavaScript
const alive = '#'; const dead = '.';   // ------------------------------------------------------------[ Bit banging ]-- const setBitAt = (val, idx) => BigInt(val) | (1n << BigInt(idx)); const clearBitAt = (val, idx) => BigInt(val) & ~(1n << BigInt(idx)); const getBitAt = val => idx => (BigInt(val) >> BigInt(idx)) & 1n;...
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...
#TXR
TXR
$ txr -p '(n-perm-k 10 10)' 3628800
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#Xojo
Xojo
  For num As Integer = 1 To 5 If num Mod 2 = 0 Then MsgBox(Str(num) + " is even.") Else MsgBox(Str(num) + " is odd.") End If 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...
#XPL0
XPL0
include c:\cxpl\codes; int I; [for I:= -4 to +3 do [IntOut(0, I); Text(0, if I&1 then " is odd " else " is even "); Text(0, if rem(I/2)#0 then "odd" else "even"); CrLf(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...
#Julia
Julia
  using Sockets # for version 1.0 println("Echo server on port 12321") try server = listen(12321) instance = 0 while true sock = accept(server) instance += 1 socklabel = "$(getsockname(sock)) number $instance" @async begin println("Server connected to socket $soc...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Unlambda
Unlambda
i
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Ursa
Ursa
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Vala
Vala
void main() {}
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#VAX_Assembly
VAX Assembly
0000 0000 1 .entry main,0 ;register save mask 04 0002 2 ret ;return from main procedure 0003 3 .end main ;start address for linker
http://rosettacode.org/wiki/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#C.2B.2B
C++
#include <iostream>   struct Interval { int start, end; bool print; };   int main() { Interval intervals[] = { {2, 1000, true}, {1000, 4000, true}, {2, 10000, false}, {2, 100000, false}, {2, 1000000, false}, {2, 10000000, false}, {2, 100000000, false},...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Sidef
Sidef
func is_duffinian(n) { n.is_composite && n.is_coprime(n.sigma) }   say "First 50 Duffinian numbers:" say 50.by(is_duffinian)   say "\nFirst 15 Duffinian triplets:" 15.by{|n| ^3 -> all {|k| is_duffinian(n+k) } }.each {|n| printf("(%s, %s, %s)\n", n, n+1, n+2) }
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#Wren
Wren
import "./math" for Int, Nums import "./seq" for Lst import "./fmt" for Fmt   var limit = 200000 // say var d = Int.primeSieve(limit-1, false) d[1] = false for (i in 2...limit) { if (!d[i]) continue if (i % 2 == 0 && !Int.isSquare(i) && !Int.isSquare(i/2)) { d[i] = false continue } var ...
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 ...
#FreeBASIC
FreeBASIC
Dim Shared As Double a(1,2) = {{7, 8, 7}, {4, 0, 9}} Dim Shared As Double b(1,2) = {{4, 5, 1}, {6, 2, 1}} Dim Shared As Double c(1,2) Dim Shared As Double fila, columna Dim Shared As String p   Sub list(a() As Double) p = "[" For fila = 0 To Ubound(a,1) p &= "[" For columna = 0 To Ubound(b,2) ...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Delphi
Delphi
import system'dynamic; import extensions;   class TestClass { object theVariables;   constructor() { theVariables := new DynamicStruct() }   function() { auto prop := new MessageName(console.write:"Enter the variable name:".readLine()); (prop.setPropertyMessage())(theVari...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Elena
Elena
import system'dynamic; import extensions;   class TestClass { object theVariables;   constructor() { theVariables := new DynamicStruct() }   function() { auto prop := new MessageName(console.write:"Enter the variable name:".readLine()); (prop.setPropertyMessage())(theVari...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Emacs_Lisp
Emacs Lisp
(set (intern (read-string "Enter variable name: ")) 123)
http://rosettacode.org/wiki/Draw_a_pixel
Draw a pixel
Task Create a window and draw a pixel in it, subject to the following:  the window is 320 x 240  the color of the pixel must be red (255,0,0)  the position of the pixel is x = 100, y = 100
#Ada
Ada
with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Events.Events;   procedure Draw_A_Pixel is   Width  : constant := 320; Height  : constant := 200;   Window  : SDL.Video.Windows.Window; Renderer : SDL.Video.Renderers.Renderer;   procedure Wait is use type SDL.Events.Event_T...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#F.23
F#
// A function to perform Egyptian Division: Nigel Galloway August 11th., 2017 let egyptianDivision N G = let rec fn n g = seq{yield (n,g); yield! fn (n+n) (g+g)} Seq.foldBack (fun (n,i) (g,e)->if (i<=g) then ((g-i),(e+n)) else (g,e)) (fn 1 G |> Seq.takeWhile(fun (_,g)->g<=N)) (N,0)  
http://rosettacode.org/wiki/Egyptian_fractions
Egyptian fractions
An   Egyptian fraction   is the sum of distinct unit fractions such as: 1 2 + 1 3 + 1 16 ( = 43 48 ) {\displaystyle {\tfrac {1}{2}}+{\tfrac {1}{3}}+{\tfrac {1}{16}}\,(={\tfrac {43}{48}})} Each fraction in the expression has a numerator equal to   1   (unity)   and a denominator that...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "math/big" "strings" )   var zero = new(big.Int) var one = big.NewInt(1)   func toEgyptianRecursive(br *big.Rat, fracs []*big.Rat) []*big.Rat { if br.Num().Cmp(zero) == 0 { return fracs } iquo := new(big.Int) irem := new(big.Int) iquo.QuoRem(br.Denom...
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...
#zkl
zkl
class Node{ fcn init(length){ var edges=Dictionary(), # edges (or forward links). (char:Node) link=Void, # suffix link (backward links) sz =length; # node length. } } class Eertree{ fcn init(string=Void){ var nodes=List(), # two initial root nodes rto=Node(-1), # odd length r...
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 ...
#Ring
Ring
  x = 17 y = 34 p = 0 while x != 0 if not even(x) p += y see "" + x + " " + " " + y + nl else see "" + x + " ---" + nl ok x = halve(x) y = double(y) end see " " + " ===" + nl see " " + p   func double n return (n * 2) func halve n return floor(n / 2) func ...
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 ...
#jq
jq
# The ordinal value of the relevant states: def states: {"111": 1, "110": 2, "101": 3, "100": 4, "011": 5, "010": 6, "001": 7, "000": 8};   # Compute the next "state" # input: a state ("111" or "110" ...) # rule: the rule represented as a string of 0s and 1s # output: the next state "0" or "1" depending on the rule ...
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 ...
#Julia
Julia
  const lines = 10 const start = ".........#........." const rules = [90, 30, 14]   rule2poss(rule) = [rule & (1 << (i - 1)) != 0 for i in 1:8]   cells2bools(cells) = [cells[i] == '#' for i in 1:length(cells)]   bools2cells(bset) = prod([bset[i] ? "#" : "." for i in 1:length(bset)])   function transform(bset, ruleposs)...
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...
#UNIX_Shell
UNIX Shell
factorial() { set -- "$1" 1 until test "$1" -lt 2; do set -- "`expr "$1" - 1`" "`expr "$2" \* "$1"`" done echo "$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...
#Yabasic
Yabasic
for i = -5 to 5 print i, and(i,1), mod(i,2) 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...
#Z80_Assembly
Z80 Assembly
rrca jp nc,isEven
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...
#Kotlin
Kotlin
import java.net.ServerSocket import java.net.Socket   fun main() {   fun handleClient(conn: Socket) { conn.use { val input = conn.inputStream.bufferedReader() val output = conn.outputStream.bufferedWriter()   input.forEachLine { line -> output.write(line) ...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#VBA
VBA
Sub Demo() End Sub
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#VBScript
VBScript
'
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Verbexx
Verbexx
 
http://rosettacode.org/wiki/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#CLU
CLU
eban = cluster is numbers rep = null    % Next valid E-ban number in the range [0..999] next = proc (n: int) returns (int) signals (no_more) if n>=66 then signal no_more end if n<0 then return(0) end    % advance low digit (two four six) if (n//10=0) then n := (n/10)*10 + 2...
http://rosettacode.org/wiki/Eban_numbers
Eban numbers
Definition An   eban   number is a number that has no letter   e   in it when the number is spelled in English. Or more literally,   spelled numbers that contain the letter   e   are banned. The American version of spelling numbers will be used here   (as opposed to the British). 2,000,000,000   is two billio...
#D
D
import std.stdio;   struct Interval { int start, end; bool print; }   void main() { Interval[] intervals = [ {2, 1_000, true}, {1_000, 4_000, true}, {2, 10_000, false}, {2, 100_000, false}, {2, 1_000_000, false}, {2, 10_000_000, false}, {2, 100_000_000...
http://rosettacode.org/wiki/Duffinian_numbers
Duffinian numbers
A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k. E.G. 161 is a Duffinian number. It is composite. (7 × 23) The sigma sum 192 (1 + 7 + 23 + 161) is relatively prime to 161. Duffinian numbers are very common. It is not u...
#XPL0
XPL0
func IsPrime(N); \Return 'true' if N is prime int N, I; [if N <= 2 then return N = 2; if (N&1) = 0 then \even >2\ return false; for I:= 3 to sqrt(N) do [if rem(N/I) = 0 then return false; I:= I+1; ]; return true; ];   func SumDiv(Num); \Return sum of proper divisors of Num int Num, Div, Su...
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 ...
#Go
Go
package element   import ( "fmt" "math" )   type Matrix struct { ele []float64 stride int }   func MatrixFromRows(rows [][]float64) Matrix { if len(rows) == 0 { return Matrix{nil, 0} } m := Matrix{make([]float64, len(rows)*len(rows[0])), len(rows[0])} for rx, row := range rows...
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Epoxy
Epoxy
--Add user-defined variable to the stack const VarName: io.prompt("Input Variable Name: "), VarValue: io.prompt("Input Variable Value: ")   debug.newvar(VarName,VarValue)   --Outputting the results log(debug.getvar(VarName))
http://rosettacode.org/wiki/Dynamic_variable_names
Dynamic variable names
Task Create a variable with a user-defined name. The variable name should not be written in the program text, but should be taken from the user dynamically. See also   Eval in environment is a similar task.
#Erlang
Erlang
  -module( dynamic_variable_names ).   -export( [task/0] ).   task() -> {ok,[Variable_name]} = io:fread( "Variable name? ", "~a" ), Form = runtime_evaluation:form_from_string( erlang:atom_to_list(Variable_name) ++ "." ), io:fwrite( "~p has value ~p~n", [Variable_name, runtime_evaluation:evaluate_form(Form, ...
http://rosettacode.org/wiki/Draw_a_pixel
Draw a pixel
Task Create a window and draw a pixel in it, subject to the following:  the window is 320 x 240  the color of the pixel must be red (255,0,0)  the position of the pixel is x = 100, y = 100
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program dpixel.s */   /* compile with as */ /* link with gcc and options -lX11 -L/usr/lpp/X11/lib */   /********************************************/ /*Constantes */ /********************************************/ .equ STDOUT, ...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#Factor
Factor
USING: assocs combinators formatting kernel make math sequences ; IN: rosetta-code.egyptian-division   : table ( dividend divisor -- table ) [ [ 2dup >= ] [ dup , 2 * ] while ] { } make 2nip dup length <iota> [ 2^ ] map zip <reversed> ;   : accum ( a b dividend -- c ) [ 2dup [ first ] bi@ + ] dip < [ [ + ] ...
http://rosettacode.org/wiki/Egyptian_division
Egyptian division
Egyptian division is a method of dividing integers using addition and doubling that is similar to the algorithm of Ethiopian multiplication Algorithm: Given two numbers where the dividend is to be divided by the divisor: Start the construction of a table of two columns: powers_of_2, and doublings; by a first row of...
#Forth
Forth
  variable tab-end   : build ( m n -- ) pad tab-end ! swap >r 1 swap \ dividend on ret stack begin dup r@ <= while 2dup tab-end @ 2! [ 2 cells ] literal tab-end +! swap dup + swap dup + repeat 2drop rdrop ;   : e/mod ( m n -- q r ) over >r build 0 r> \ initial ...
http://rosettacode.org/wiki/Egyptian_fractions
Egyptian fractions
An   Egyptian fraction   is the sum of distinct unit fractions such as: 1 2 + 1 3 + 1 16 ( = 43 48 ) {\displaystyle {\tfrac {1}{2}}+{\tfrac {1}{3}}+{\tfrac {1}{16}}\,(={\tfrac {43}{48}})} Each fraction in the expression has a numerator equal to   1   (unity)   and a denominator that...
#Go
Go
package main   import ( "fmt" "math/big" "strings" )   var zero = new(big.Int) var one = big.NewInt(1)   func toEgyptianRecursive(br *big.Rat, fracs []*big.Rat) []*big.Rat { if br.Num().Cmp(zero) == 0 { return fracs } iquo := new(big.Int) irem := new(big.Int) iquo.QuoRem(br.Denom...
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 ...
#Ruby
Ruby
def halve(x) x/2 end def double(x) x*2 end   # iterative def ethiopian_multiply(a, b) product = 0 while a >= 1 p [a, b, a.even? ? "STRIKE" : "KEEP"] if $DEBUG product += b unless a.even? a = halve(a) b = double(b) end product end   # recursive def rec_ethiopian_multiply(a, b) return 0 if...
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 ...
#Kotlin
Kotlin
// version 1.1.51   import java.util.BitSet   const val SIZE = 32 const val LINES = SIZE / 2 const val RULE = 90   fun ruleTest(x: Int) = (RULE and (1 shl (7 and x))) != 0   infix fun Boolean.shl(bitCount: Int) = (if (this) 1 else 0) shl bitCount   fun Boolean.toInt() = if (this) 1 else 0   fun evolve(s: BitSet) { ...
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...
#Ursa
Ursa
def factorial (int n) decl int result set result 1 decl int i for (set i 1) (< i (+ n 1)) (inc i) set result (* result i) end return result end  
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#zkl
zkl
[-3..4].pump(fcn(n){ println(n," is ",n.isEven and "even" or "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...
#Zoea
Zoea
  program: even_or_odd case: 1 input: 2 output: even case: 2 input: 4 output: even case: 3 input: 1 output: odd case: 4 input: 7 output: 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...
#LFE
LFE
  (defun start () (spawn (lambda () (let ((`#(ok ,socket) (gen_tcp:listen 12321 `(#(packet line))))) (echo-loop socket)))))   (defun echo-loop (socket) (let* ((`#(ok ,conn) (gen_tcp:accept socket)) (handler (spawn (lambda () (handle conn))))) (lfe_io:format "Got connection: ~p~n...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Verilog
Verilog
module main; endmodule
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#VHDL
VHDL
entity dummy is end;   architecture empty of dummy is begin end;