task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Vim_Script
Vim Script
Sub Main() End Sub
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...
#Factor
Factor
USING: arrays formatting fry io kernel math math.functions math.order math.ranges prettyprint sequences ;   : eban? ( n -- ? ) 1000000000 /mod 1000000 /mod 1000 /mod [ dup 30 66 between? [ 10 mod ] when ] tri@ 4array [ { 0 2 4 6 } member? ] all? ;   : .eban ( m n -- ) "eban numbers in [%d, %d]: " printf ; :...
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...
#FreeBASIC
FreeBASIC
  ' Eban_numbers ' Un número eban es un número que no tiene la letra e cuando el número está escrito en inglés. ' O más literalmente, los números escritos que contienen la letra e están prohibidos. ' ' Usaremos la versión americana de los números de ortografía (a diferencia de los británicos). ' 2000000000 son dos bil...
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 ...
#Groovy
Groovy
class NaiveMatrix {   List<List<Number>> contents = []   NaiveMatrix(Iterable<Iterable<Number>> elements) { contents.addAll(elements.collect{ row -> row.collect{ cell -> cell } }) assertWellFormed() }   void assertWellFormed() { assert contents != null assert contents.siz...
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.
#Factor
Factor
42 readln set
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.
#Forth
Forth
s" VARIABLE " pad swap move ." Variable name: " pad 9 + 80 accept pad swap 9 + evaluate
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.
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Type DynamicVariable As String name As String value End Type   Function FindVariableIndex(a() as DynamicVariable, v as String, nElements As Integer) As Integer v = LCase(Trim(v)) For i As Integer = 1 To nElements If a(i).name = v Then Return i Next Return 0 End Function   Dim As Int...
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
#AutoHotkey
AutoHotkey
Gui, Add, Picture, x100 y100 w2 h2 +0x4E +HWNDhPicture CreatePixel("FF0000", hPicture) Gui, Show, w320 h240, Example return   CreatePixel(Color, Handle) { VarSetCapacity(BMBITS, 4, 0), Numput("0x" . Color, &BMBITS, 0, "UInt") hBM := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0...
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...
#FreeBASIC
FreeBASIC
' version 09-08-2017 ' compile with: fbc -s console   Data 580, 34   Dim As UInteger dividend, divisor, answer, accumulator, i ReDim As UInteger table(1 To 32, 1 To 2)   Read dividend, divisor   i = 1 table(i, 1) = 1 : table(i, 2) = divisor   While table(i, 2) < dividend i += 1 table(i, 1) = table(i -1, 1) * 2 ...
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...
#Haskell
Haskell
import Data.Ratio (Ratio, (%), denominator, numerator)   egyptianFraction :: Integral a => Ratio a -> [Ratio a] egyptianFraction n | n < 0 = map negate (egyptianFraction (-n)) | n == 0 = [] | x == 1 = [n] | x > y = (x `div` y % 1) : egyptianFraction (x `mod` y % y) | otherwise = (1 % r) : egyptianFraction ((-...
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 ...
#Rust
Rust
fn double(a: i32) -> i32 { 2*a }   fn halve(a: i32) -> i32 { a/2 }   fn is_even(a: i32) -> bool { a % 2 == 0 }   fn ethiopian_multiplication(mut x: i32, mut y: i32) -> i32 { let mut sum = 0;   while x >= 1 { print!("{} \t {}", x, y); match is_even(x) { true => println!("...
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 ...
#Lua
Lua
local CA = { state = "..............................#..............................", bstr = { [0]="...", "..#", ".#.", ".##", "#..", "#.#", "##.", "###" }, new = function(self, rule) local inst = setmetatable({rule=rule}, self) for b = 0,7 do inst[inst.bstr[b]] = rule%2==0 and "." or "#" 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...
#Ursala
Ursala
#import nat   good_factorial = ~&?\1! product:-1^lrtPC/~& iota better_factorial = ~&?\1! ^T(~&lSL,@rS product:-1)+ ~&Z-~^*lrtPC/~& iota
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_Visual
Zoea Visual
  module Main; var x: integer; s: set; begin x := 10;writeln(x:3," is odd?",odd(x)); s := set(s);writeln(x:3," is odd?",0 in s); (* check right bit *) x := 11;writeln(x:3," is odd?",odd(x)); s := set(x);writeln(x:3," is odd?",0 in s); (* check right bit *) end Main.  
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...
#zonnon
zonnon
  module Main; var x: integer; s: set; begin x := 10;writeln(x:3," is odd?",odd(x)); s := set(s);writeln(x:3," is odd?",0 in s); (* check right bit *) x := 11;writeln(x:3," is odd?",odd(x)); s := set(x);writeln(x:3," is odd?",0 in s); (* check right bit *) end Main.  
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...
#Lua
Lua
local socket = require("socket")   local function has_value(tab, value) for i, v in ipairs(tab) do if v == value then return i end end return false end   local function checkOn(client) local line, err = client:receive() if line then client:send(line .. "\n") end if err and err ~= "timeout" t...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Visual_Basic
Visual Basic
Sub Main() End Sub
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Visual_Basic_.NET
Visual Basic .NET
Module General Sub Main() End Sub End Module
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Vlang
Vlang
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import "fmt"   type Range struct { start, end uint64 print bool }   func main() { rgs := []Range{ {2, 1000, true}, {1000, 4000, true}, {2, 1e4, false}, {2, 1e5, false}, {2, 1e6, false}, {2, 1e7, false}, {2, 1e8, false}, {2, ...
http://rosettacode.org/wiki/Draw_a_rotating_cube
Draw a rotating cube
Task Draw a rotating cube. It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional. Related ...
#Ada
Ada
with Ada.Numerics.Elementary_Functions;   with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Events.Events;   procedure Rotating_Cube is   Width  : constant := 500; Height : constant := 500; Offset : constant := 500.0 / 2.0;   Window  : SDL.Video.Windows.Window; Renderer : SDL.Vide...
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 ...
#Haskell
Haskell
{-# OPTIONS_GHC -fno-warn-duplicate-constraints #-} {-# LANGUAGE RankNTypes #-}   import Data.Array (Array, Ix) import Data.Array.Base   -- | Element-wise combine the values of two arrays 'a' and 'b' with 'f'. -- 'a' and 'b' must have the same bounds. zipWithA :: (IArray arr a, IArray arr b, IArray arr c, Ix i) => ...
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.
#GAP
GAP
# As is, will not work if val is a String Assign := function(var, val) Read(InputTextString(Concatenation(var, " := ", String(val), ";"))); end;
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.
#Genyris
Genyris
defvar (intern 'This is not a pipe.') 42 define |<weird>| 2009
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
#BASIC256
BASIC256
  rem http://rosettacode.org/wiki/Draw_a_pixel   graphsize 320, 240 color red plot 100, 100  
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
#BBC_BASIC
BBC BASIC
VDU 23, 22, 320; 240; 8, 8, 8, 0, 18, 0, 1, 25, 69, 100; 100;
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...
#Go
Go
package main   import "fmt"   func egyptianDivide(dividend, divisor int) (quotient, remainder int) { if dividend < 0 || divisor <= 0 { panic("Invalid argument(s)") } if dividend < divisor { return 0, dividend } powersOfTwo := []int{1} doublings := []int{divisor} doubling := d...
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...
#J
J
ef =: [: (}.~ 0={.) [: (, r2ef)/ 0 1 #: x: r2ef =: (<(<0);0) { ((] , -) >:@:<.&.%)^:((~:<.)@:%)@:{:^:a:
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 ...
#S-BASIC
S-BASIC
  $constant true = 0FFFFH $constant false = 0   function half(n = integer) = integer end = n / 2   function twice(n = integer) = integer end = n + n   rem - return true (-1) if n is even, otherwise false function even(n = integer) = integer var one = integer one = 1 rem - only variables are compared bitwise end...
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 ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ArrayPlot[CellularAutomaton[30, {0, 0, 0, 0, 1, 0, 0, 0}, 100]]
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 ...
#MATLAB
MATLAB
function init = cellularAutomaton(rule, init, n) init(n + 1, :) = 0; for k = 1 : n init(k + 1, :) = bitget(rule, 1 + filter2([4 2 1], init(k, :))); end
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...
#VBA
VBA
Public Function factorial(n As Integer) As Long factorial = WorksheetFunction.Fact(n) End Function
http://rosettacode.org/wiki/Even_or_odd
Even or odd
Task Test whether an integer is even or odd. There is more than one way to solve this task: Use the even and odd predicates, if the language provides them. Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd. Divide i by 2. The remainder equals...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 FOR n=-3 TO 4: GO SUB 30: NEXT n 20 STOP 30 LET odd=FN m(n,2) 40 PRINT n;" is ";("Even" AND odd=0)+("Odd" AND odd=1) 50 RETURN 60 DEF FN m(a,b)=a-INT (a/b)*b
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
server = SocketOpen[12321]; SocketListen[server, Function[{assoc}, With[{client = assoc["SourceSocket"], input = assoc["Data"]}, WriteString[client, ByteArrayToString[input]]; ] ]]
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Wart
Wart
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#WDTE
WDTE
(module  ;;The entry point for WASI is called _start (func $main (export "_start")   ) )  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#WebAssembly
WebAssembly
(module  ;;The entry point for WASI is called _start (func $main (export "_start")   ) )  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Wee_Basic
Wee Basic
 
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...
#Go
Go
package main   import "fmt"   type Range struct { start, end uint64 print bool }   func main() { rgs := []Range{ {2, 1000, true}, {1000, 4000, true}, {2, 1e4, false}, {2, 1e5, false}, {2, 1e6, false}, {2, 1e7, false}, {2, 1e8, false}, {2, ...
http://rosettacode.org/wiki/Draw_a_rotating_cube
Draw a rotating cube
Task Draw a rotating cube. It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional. Related ...
#AutoHotkey
AutoHotkey
; --------------------------------------------------------------- cubeSize := 200 deltaX := A_ScreenWidth/2 deltaY := A_ScreenHeight/2 keyStep := 1 mouseStep := 0.2 zoomStep := 1.1 playSpeed := 1 playTimer := 10 penSize := 5   /* HotKeys: !p:: Play/Stop !x:: change play to x-axis !y:: change play to y-axis !z...
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 ...
#Icon_and_Unicon
Icon and Unicon
procedure main() a := [[1,2,3],[4,5,6],[7,8,9]] b := [[9,8,7],[6,5,4],[3,2,1]] showMat(" a: ",a) showMat(" b: ",b) showMat("a+b: ",mmop("+",a,b)) showMat("a-b: ",mmop("-",a,b)) showMat("a*b: ",mmop("*",a,b)) showMat("a/b: ",mmop("/",a,b)) showMat("a^b: ",mmop("^",a,b)) showMat("a+2: ",ms...
http://rosettacode.org/wiki/Dutch_national_flag_problem
Dutch national flag problem
The Dutch national flag is composed of three coloured bands in the order:   red     (top)   then white,   and   lastly blue   (at the bottom). The problem posed by Edsger Dijkstra is: Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla...
#11l
11l
V colours_in_order = ‘Red White Blue’.split(‘ ’)   F dutch_flag_sort3(items) [String] r L(colour) :colours_in_order r.extend([colour] * items.count(colour)) R r   V balls = [‘Red’, ‘Red’, ‘Blue’, ‘Blue’, ‘Blue’, ‘Red’, ‘Red’, ‘Red’, ‘White’, ‘Blue’] print(‘Original Ball order: ’balls) V sorted_balls = du...
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.
#Go
Go
package main   import ( "bufio" "fmt" "log" "os" "strconv" "strings" )   func check(err error) { if err != nil { log.Fatal(err) } }   func main() { scanner := bufio.NewScanner(os.Stdin) n := 0 for n < 1 || n > 5 { fmt.Print("How many integer variables do you w...
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
#C
C
  #include<graphics.h>   int main() { initwindow(320,240,"Red Pixel");   putpixel(100,100,RED);   getch();   return 0; }  
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
#Commodore_BASIC
Commodore BASIC
10 COLOR 0,0,2,2: REM BLACK BACKGROUND AND BORDER, RED TEXT AND EXTRA COLOR 20 GRAPHIC 2:SCNCLR:REM SELECT HI-RES GRAPHICS AND CLEAR THE SCREEN 30 POINT 2,640,640:REM DRAW A POINT AT 640/1024*160,640/1024*160 40 GET K$:IF K$="" THEN 40: REM WAIT FOR KEYPRESS 50 GRAPHIC 0:REM BACK TO TEXT MODE
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...
#Groovy
Groovy
class EgyptianDivision { /** * Runs the method and divides 580 by 34 * * @param args not used */ static void main(String[] args) { divide(580, 34) }   /** * Divides <code>dividend</code> by <code>divisor</code> using the Egyptian Division-Algorithm and prints the * ...
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...
#Java
Java
import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.util.ArrayList; import java.util.Collections; import java.util.List;   public class EgyptianFractions { private static BigInteger gcd(BigInteger a, BigInteger b) { if (b.equals(BigInteger.ZERO)) { ...
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 ...
#Scala
Scala
  def ethiopian(i:Int, j:Int):Int= pairIterator(i,j).filter(x=> !isEven(x._1)).map(x=>x._2).foldLeft(0){(x,y)=>x+y}   def ethiopian2(i:Int, j:Int):Int= pairIterator(i,j).map(x=>if(isEven(x._1)) 0 else x._2).foldLeft(0){(x,y)=>x+y}   def ethiopian3(i:Int, j:Int):Int= { var res=0; for((h,d) <- pairIterator(i,...
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 ...
#Nim
Nim
import bitops   const Size = 32 LastBit = Size - 1 Lines = Size div 2 Rule = 90   type State = int # State is represented as an int and will be used as a bit string.   #---------------------------------------------------------------------------------------------------   template bitVal(state: State; n: typed...
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 ...
#Octave
Octave
clear all E=200; idx=round(E/2); z(1:1:E^2)=0; % init lattice z(idx)=1; % seed apex of triangle with a single cell A=2; % Number of bits-1 rule30 uses 3 so A=2 for n=1:1:E^2/2-E-2; % n=lines theta=0; % theta for a=0:1:A; theta=th...
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...
#VBScript
VBScript
Dim lookupTable(170), returnTable(170), currentPosition, input currentPosition = 0   Do While True input = InputBox("Please type a number (-1 to quit):") MsgBox "The factorial of " & input & " is " & factorial(CDbl(input)) Loop   Function factorial (x) If x = -1 Then WScript.Quit 0 End If Dim temp temp = lookup...
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...
#Nim
Nim
import asyncnet, asyncdispatch   proc processClient(client: AsyncSocket) {.async.} = while true: let line = await client.recvLine() await client.send(line & "\c\L")   proc serve() {.async.} = var server = newAsyncSocket() server.bindAddr(Port(12321)) server.listen()   while true: let client = awai...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Wren
Wren
 
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#X86_Assembly
X86 Assembly
section .text global _start   _start: mov eax, 1 int 0x80 ret
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#XPL0
XPL0
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#XQuery
XQuery
.
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...
#Groovy
Groovy
class Main { private static class Range { int start int end boolean print   Range(int s, int e, boolean p) { start = s end = e print = p } }   static void main(String[] args) { List<Range> rgs = Arrays.asList( ...
http://rosettacode.org/wiki/Draw_a_rotating_cube
Draw a rotating cube
Task Draw a rotating cube. It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional. Related ...
#BASIC256
BASIC256
global escala global tam global zoff global cylr   escala = 50 tam = 320 zoff = 0.5773502691896257645091487805019574556 cylr = 1.6329931618554520654648560498039275946   clg graphsize tam, tam   dim x(6) theta = 0.0 dtheta = 1.5 dt = 1.0 / 30 dim cylphi = {PI/6, 5*PI/6, 3*PI/2, 11*PI/6, PI/2, 7*PI/6}   while key = "" ...
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 ...
#J
J
scalar =: 10 vector =: 2 3 5 matrix =: 3 3 $ 7 11 13 17 19 23 29 31 37   scalar * scalar 100 scalar * vector 20 30 50 scalar * matrix 70 110 130 170 190 230 290 310 370   vector * vector 4 9 25 vector * matrix 14 22 26 51 57 69 145 155 185   matrix * matrix 49 121 169 289 361 5...
http://rosettacode.org/wiki/Dutch_national_flag_problem
Dutch national flag problem
The Dutch national flag is composed of three coloured bands in the order:   red     (top)   then white,   and   lastly blue   (at the bottom). The problem posed by Edsger Dijkstra is: Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla...
#ABAP
ABAP
  report z_dutch_national_flag_problem.   interface sorting_problem. methods: generate_unsorted_sequence importing lenght_of_sequence type int4 returning value(unsorted_sequence) type string,   sort_sequence changing sequence_to_be_sorted type string,   is_s...
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.
#Groovy
Groovy
def varname = 'foo' def value = 42   new GroovyShell(this.binding).evaluate("${varname} = ${value}")   assert foo == 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.
#Haskell
Haskell
data Var a = Var String a deriving Show main = do putStrLn "please enter you variable name" vName <- getLine let var = Var vName 42 putStrLn $ "this is your variable: " ++ show var
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
#Delphi
Delphi
  program Draw_a_pixel;   {$APPTYPE CONSOLE}   {$R *.res}   uses Windows, Messages, SysUtils;   var Msg: TMSG; LWndClass: TWndClass; hMainHandle: HWND;   procedure Paint(Handle: hWnd); forward;   procedure ReleaseResources; begin PostQuitMessage(0); end;   function WindowProc(hWnd, Msg: Longint; wParam: w...
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...
#Haskell
Haskell
import Data.List (unfoldr)   egyptianQuotRem :: Integer -> Integer -> (Integer, Integer) egyptianQuotRem m n = let expansion (i, x) | x > m = Nothing | otherwise = Just ((i, x), (i + i, x + x)) collapse (i, x) (q, r) | x < r = (q + i, r - x) | otherwise = (q, r) in foldr collap...
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...
#Julia
Julia
struct EgyptianFraction{T<:Integer} <: Real int::T frac::NTuple{N,Rational{T}} where N end   Base.show(io::IO, ef::EgyptianFraction) = println(io, "[", ef.int, "] ", join(ef.frac, " + ")) Base.length(ef::EgyptianFraction) = !iszero(ef.int) + length(ef.frac) function Base.convert(::Type{EgyptianFraction{T}}, fr:...
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 ...
#Scheme
Scheme
(define (halve num) (quotient num 2))   (define (double num) (* num 2))   (define (*mul-eth plier plicand acc) (cond ((zero? plier) acc) ((even? plier) (*mul-eth (halve plier) (double plicand) acc)) (else (*mul-eth (halve plier) (double plicand) (+ acc plicand)))))   (define (mul-eth plier plicand...
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 ...
#Perl
Perl
use strict; use warnings;   package Automaton { sub new { my $class = shift; my $rule = [ reverse split //, sprintf "%08b", shift ]; return bless { rule => $rule, cells => [ @_ ] }, $class; } sub next { my $this = shift; my @previous = @{$this->{cells}}; $this->{cells} = [ @{$this->{rule}}[ ...
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...
#Verbexx
Verbexx
// ---------------- // recursive method (requires INTV_T input parm) // ----------------   fact_r @FN [n] { @CASE when:(n < 0iv) {-1iv } when:(n == 0iv) { 1iv } else: { n * (@fact_r n-1iv) } };     // ---------------- // iterative method (requires ...
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...
#Objeck
Objeck
  use Net; use Concurrency;   bundle Default { class SocketServer { id : static : Int;   function : Main(args : String[]) ~ Nil { server := TCPSocketServer->New(12321); if(server->Listen(5)) { while(true) { client := server->Accept(); service := Service->New(id->ToStrin...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#XSLT
XSLT
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- code goes here --> </xsl:stylesheet>
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#xTalk
xTalk
on startup end startup
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#XUL
XUL
  <?xml version="1.0"?>  
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Yabasic
Yabasic
 
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...
#Haskell
Haskell
{-# LANGUAGE NumericUnderscores #-} import Data.List (intercalate) import Text.Printf (printf) import Data.List.Split (chunksOf)   isEban :: Int -> Bool isEban n = all (`elem` [0, 2, 4, 6]) z where (b, r1) = n `quotRem` (10 ^ 9) (m, r2) = r1 `quotRem` (10 ^ 6) (t, r3) = r2 `quotRem` (10 ^ 3) z = b : map...
http://rosettacode.org/wiki/Draw_a_rotating_cube
Draw a rotating cube
Task Draw a rotating cube. It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional. Related ...
#C
C
  #include<gl/freeglut.h>   double rot = 0; float matCol[] = {1,0,0,0};   void display(){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(30,1,1,0); glRotatef(rot,0,1,1); glMaterialfv(GL_FRONT,GL_DIFFUSE,matCol); glutWireCube(1); glPopMatrix(); glFlush(); }     void onIdle(){ rot +=...
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 ...
#Java
Java
  import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Stream;   @SuppressWarnings("serial") public class ElementWiseOp { static final Map<String, BiFunction<Double, Double, Double>> OPERATIONS = new HashMap<String, BiFunction<Double, Do...
http://rosettacode.org/wiki/Dutch_national_flag_problem
Dutch national flag problem
The Dutch national flag is composed of three coloured bands in the order:   red     (top)   then white,   and   lastly blue   (at the bottom). The problem posed by Edsger Dijkstra is: Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla...
#Action.21
Action!
INCLUDE "D2:SORT.ACT" ;from the Action! Tool Kit   PROC PrintArray(BYTE ARRAY a BYTE len) CHAR ARRAY colors(3)=['R 'W 'B] BYTE i,index   FOR i=0 TO len-1 DO index=a(i) Put(colors(index)) OD RETURN   BYTE FUNC IsSorted(BYTE ARRAY a BYTE len) BYTE i   IF len<=1 THEN RETURN (1) FI FOR i=0 TO ...
http://rosettacode.org/wiki/Dutch_national_flag_problem
Dutch national flag problem
The Dutch national flag is composed of three coloured bands in the order:   red     (top)   then white,   and   lastly blue   (at the bottom). The problem posed by Edsger Dijkstra is: Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla...
#Ada
Ada
with Ada.Text_IO, Ada.Numerics.Discrete_Random, Ada.Command_Line;   procedure Dutch_National_Flag is   type Colour_Type is (Red, White, Blue);   Number: Positive range 2 .. Positive'Last := Positive'Value(Ada.Command_Line.Argument(1)); -- no sorting if the Number of balls is less than 2   type Balls is...
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.
#J
J
require 'misc' (prompt 'Enter variable name: ')=: 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.
#Java
Java
public static void main(String... args){ HashMap<String, Integer> vars = new HashMap<String, Integer>(); //The variable name is stored as the String. The var type of the variable can be //changed by changing the second data type mentiones. However, it must be an object //or a wrapper cla...
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
#F.23
F#
open System.Windows.Forms open System.Drawing   let f = new Form() f.Size <- new Size(320,240) f.Paint.Add(fun e -> e.Graphics.FillRectangle(Brushes.Red, 100, 100 ,1,1)) Application.Run(f)
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
#Factor
Factor
USING: accessors arrays images images.testing images.viewer kernel literals math sequences ; IN: rosetta-code.draw-pixel   : draw-pixel ( -- ) B{ 255 0 0 } 100 100 <rgb-image> 320 240 [ 2array >>dim ] [ * ] 2bi [ { 0 0 0 } ] replicate B{ } concat-as >>bitmap [ set-pixel-at ] keep image-window ;   MAIN: draw...
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...
#J
J
doublings=:_1 }. (+:@]^:(> {:)^:a: (,~ 1:)) ansacc=: 1 }. (] + [ * {.@[ >: {:@:+)/@([,.doublings) egydiv=: (0,[)+1 _1*ansacc
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...
#Java
Java
  import java.util.ArrayList; import java.util.List;   public class EgyptianDivision {   /** * Runs the method and divides 580 by 34 * * @param args not used */ public static void main(String[] args) {   divide(580, 34);   }   /** * Divides <code>dividend</code> by <code...
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...
#Kotlin
Kotlin
// version 1.2.10   import java.math.BigInteger import java.math.BigDecimal import java.math.MathContext   val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bdZero = BigDecimal.ZERO val context = MathContext.UNLIMITED   fun gcd(a: BigInteger, b: BigInteger): BigInteger = if (b == bigZero) a else gcd(b...
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 ...
#Seed7
Seed7
const proc: double (inout integer: a) is func begin a *:= 2; end func;   const proc: halve (inout integer: a) is func begin a := a div 2; end func;   const func boolean: even (in integer: a) is return not odd(a);   const func integer: peasantMult (in var integer: a, in var integer: b) is func result...
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 ...
#Phix
Phix
with javascript_semantics string s = ".........#.........", t = s, r = "........" integer rule = 90, k, l = length(s) for i=1 to 8 do r[i] = iff(mod(rule,2)?'#':'.') rule = floor(rule/2) end for for i=0 to 50 do ?s for j=1 to l do k = (s[iff(j=1?l:j-1)]='#')*4 + (s[ j ...
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...
#Verilog
Verilog
module main;   function automatic [7:0] factorial; input [7:0] i_Num; begin if (i_Num == 1) factorial = 1; else factorial = i_Num * factorial(i_Num-1); end endfunction   initial begin $display("Factorial of 1 = %d", factorial(1)); $display("Factorial of 2 ...
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...
#Ol
Ol
  (define (timestamp) (syscall 201 "%c"))   (define (on-accept name fd) (lambda () (print "# " (timestamp) "> we got new visitor: " name)   (let*((ss1 ms1 (clock))) (let loop ((str #null) (stream (force (port->bytestream fd)))) (cond ((null? stream) #false) ((...
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Yorick
Yorick
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Z80_Assembly
Z80 Assembly
ret
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#Zig
Zig
pub fn main() void {}
http://rosettacode.org/wiki/Empty_program
Empty program
Task Create the simplest possible program that is still considered "correct."
#zkl
zkl
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...
#J
J
  Filter =: (#~`)(`:6)   itemAmend =: (29&< *. <&67)`(,: 10&|)} iseban =: [: *./ 0 2 4 6 e.~ [: itemAmend [: |: (4#1000)&#:     (;~ #) iseban Filter >: i. 1000 ┌──┬─────────────────────────────────────────────────────┐ │19│2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66│ └──┴───────────────────────────────────...
http://rosettacode.org/wiki/Draw_a_rotating_cube
Draw a rotating cube
Task Draw a rotating cube. It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional. Related ...
#C.23
C#
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.Windows.Threading;   namespace RotatingCube { public partial class Form1 : Form { double[][] nodes = { new double[] {-1, -1, -1}, new double[] {-1, -1, 1}, new double[] {-1, 1, -1}, ...
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 ...
#jq
jq
# Occurrences of .[0] in "operator" will refer to an element in self, # and occurrences of .[1] will refer to the corresponding element in other. def elementwise( operator; other ): length as $rows | if $rows == 0 then . else . as $self | other as $other | ($self[0]|length) as $cols | reduce range(0...
http://rosettacode.org/wiki/Dutch_national_flag_problem
Dutch national flag problem
The Dutch national flag is composed of three coloured bands in the order:   red     (top)   then white,   and   lastly blue   (at the bottom). The problem posed by Edsger Dijkstra is: Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla...
#ALGOL_68
ALGOL 68
BEGIN # Dutch national flag problem: sort a set of randomly arranged red, white and blue balls into order # # ball sets are represented by STRING items, red by "R", white by "W" and blue by "B" # # returns the balls sorted into red, white and blue order # PROC sort balls = ( STRING balls )STRING: BEGI...
http://rosettacode.org/wiki/Draw_a_cuboid
Draw a cuboid
Task Draw a   cuboid   with relative dimensions of   2 × 3 × 4. The cuboid can be represented graphically, or in   ASCII art,   depending on the language capabilities. To fulfill the criteria of being a cuboid, three faces must be visible. Either static or rotational projection is acceptable for this task. R...
#11l
11l
F cline(n, x, y, cde) print(String(cde[0]).rjust(n + 1)‘’ (cde[1] * (9 * x - 1))‘’ cde[0]‘’ (I cde.len > 2 {String(cde[2]).rjust(y + 1)} E ‘’))   F cuboid(x, y, z) cline(y + 1, x, 0, ‘+-’) L(i) 1 .. y cline(y - i + 1, x, i - 1, ‘/ |’) cline(0, x, y, ‘+-|’) ...
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.
#JavaScript
JavaScript
var varname = 'foo'; // pretend a user input that var value = 42; eval('var ' + varname + '=' + value);
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.
#jq
jq
"Enter a variable name:", (input as $var | ("Enter a value:" , (input as $value | { ($var) : $value })))