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/Yellowstone_sequence
Yellowstone sequence
The Yellowstone sequence, also called the Yellowstone permutation, is defined as: For n <= 3, a(n) = n For n >= 4, a(n) = the smallest number not already in sequence such that a(n) is relatively prime to a(n-1) and is not relatively prime to a(n-2). The sequence is a permutation of the natural n...
#XPL0
XPL0
func GCD(N, D); \Return the greatest common divisor of N and D int N, D, R; \numerator, denominator, remainder [if D > N then [R:=D; D:=N; N:=R]; \swap D and N while D > 0 do [R:= rem(N/D); N:= D; D:= R; ]; return N; ];   int I, A(30+1), N, T; [for I:= 1 to 3 do A(I):= I; ...
http://rosettacode.org/wiki/Yellowstone_sequence
Yellowstone sequence
The Yellowstone sequence, also called the Yellowstone permutation, is defined as: For n <= 3, a(n) = n For n >= 4, a(n) = the smallest number not already in sequence such that a(n) is relatively prime to a(n-1) and is not relatively prime to a(n-2). The sequence is a permutation of the natural n...
#zkl
zkl
fcn yellowstoneW{ // --> iterator Walker.zero().tweak(fcn(a,b){ foreach i in ([1..]){ if(not b.holds(i) and i.gcd(a[-1])==1 and i.gcd(a[-2]) >1){ a.del(0).append(i); // only keep last two terms b[i]=True; return(i); } } }.fp(List(2,3), Dictionary(1,True, 2,True, 3,True))).pus...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Ol
Ol
  (define x (expt 5 (expt 4 (expt 3 2)))) (print (div x (expt 10 (- (log 10 x) 20))) "..." (mod x (expt 10 20))) (print "totally digits: " (log 10 x))  
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#ooRexx
ooRexx
  --REXX program to show arbitrary precision integers. numeric digits 200000 check = '62060698786608744707...92256259918212890625'   start = .datetime~new n = 5 ** (4 ** (3**2)) time = .datetime~new - start say 'elapsed time for the calculation:' time say sampl = left(n, 20)"..."right(n, 20)   say ' check:' check say '...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Plain_TeX
Plain TeX
\def\genfibolist#1{% #creates the fibo list which sum>=#1 \let\fibolist\empty\def\targetsum{#1}\def\fibosum{0}% \genfibolistaux1,1\relax } \def\genfibolistaux#1,#2\relax{% \ifnum\fibosum<\targetsum\relax \edef\fibosum{\number\numexpr\fibosum+#2}% \edef\fibolist{#2,\fibolist}% \edef\tempfibo{\noexpand\genfiboli...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#PowerShell
PowerShell
  function Get-ZeckendorfNumber ( $N ) { # Calculate relevant portation of Fibonacci series $Fib = @( 1, 1 ) While ( $Fib[-1] -lt $N ) { $Fib += $Fib[-1] + $Fib[-2] }   # Start with 0 $ZeckendorfNumber = 0   # For each number in the relevant portion of Fibonacci series For ( $i = $Fib...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#D
D
import std.stdio; const N = 101; // #doors + 1 void main() { bool[N] doors = false; for(auto door=1; door<N; door++ ) { for(auto i=door; i<N; i+=door ) doors[i] = !doors[i]; if (doors[door]) write(door, " "); } }
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Halon
Halon
$array = [];   $array[] = 1; $array["key"] = 3;   $array[0] = 2;   echo $array[0]; echo $array["key"];
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Vlang
Vlang
import math.complex fn main() { a := complex.complex(1, 1) b := complex.complex(3.14159, 1.25) println("a: $a") println("b: $b") println("a + b: ${a+b}") println("a * b: ${a*b}") println("-a: ${a.addinv()}") println("1 / a: ${complex.complex(1,0)/a}") println("a̅: ...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Wortel
Wortel
@class Complex { &[r i] @: { ^r || r 0 ^i || i 0 ^m +@sq^r @sq^i } add &o @new Complex[+ ^r o.r + ^i o.i] mul &o @new Complex[-* ^r o.r * ^i o.i +* ^r o.i * ^i o.r] neg &^ @new Complex[@-^r @-^i] inv &^ @new Complex[/ ^r ^m / @-^i ^m] toString &^?{ =^i 0 "{^r}" =^r 0 "{^i}i" >^i 0 ...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Quackery
Quackery
/O> 0 0 ** ...   Stack: 1  
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#R
R
print(0^0)
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Racket
Racket
#lang racket ;; as many zeros as I can think of... (define zeros (list 0  ; unspecified number type 0. ; hinted as float #e0 ; explicitly exact #i0 ; explicitly inexact 0+0i ; exact complex 0.+0.i ; float inexact ))...
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#FormulaOne
FormulaOne
  // First, let's give some type-variables some values: Nationality = Englishman | Swede | Dane | Norwegian | German Colour = Red | Green | Yellow | Blue | White Cigarette = PallMall | Dunhill | BlueMaster | Blend | Prince Domestic = Dog | Bird | Cat | Zebra ...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#HicEst
HicEst
CHARACTER xml*1000, output*1000 READ(ClipBoard) xml   EDIT(Text=xml, Right='<item', Right=5, GetPosition=a, Right='</item>', Left, GetPosition=z) WRITE(Text=output) xml( a : z), $CRLF   i = 1 1 EDIT(Text=xml, SetPosition=i, SePaRators='<>', Right='<price>', Word=1, Parse=price, GetPosition=i, ERror=99) IF(i >...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Java
Java
import java.io.StringReader; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource;   public class XMLPar...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#J
J
yinyang=:3 :0 radii=. y*1 3 6 ranges=. i:each radii squares=. ,"0/~each ranges circles=. radii ([ >: +/"1&.:*:@])each squares cInds=. ({:radii) +each circles #&(,/)each squares   M=. ' *.' {~ circles (* 1 + 0 >: {:"1)&(_1&{::) squares offset=. 3*y,0 M=. '*' ((_2 {:: cInds) <@:+"1 offset)} M M=. '.' ...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
Y f: labda y: labda: call y @y f labda x: x @x call   labda f: labda n: if < 1 n: * n f -- n else: 1 set :fac Y   labda f: labda n: if < 1 n: + f - n 2 f -- n else: 1 set :fib Y   !. fac 6 !. fib 6
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#Erlang
Erlang
  -module( zigzag ).   -export( [matrix/1, task/0] ).   matrix( N ) -> {{_X_Y, N}, Proplist} = lists:foldl( fun matrix_as_proplist/2, {{{0, 0}, N}, []}, lists:seq(0, (N * N) - 1) ), [columns( X, Proplist ) || X <- lists:seq(0, N - 1)].   task() -> matrix( 5 ).       columns( Column, Proplist ) -> lists:sort( [Value |...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Oz
Oz
declare Pow5432 = {Pow 5 {Pow 4 {Pow 3 2}}} S = {Int.toString Pow5432} Len = {Length S} in {System.showInfo {List.take S 20}#"..."# {List.drop S Len-20}#" ("#Len#" Digits)"}
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#PARI.2FGP
PARI/GP
num_first_last_digits(a=5,b=4^3^2,n=20)={ my(L = b*log(a)/log(10), m=Mod(a,10^n)^b); [L\1+1, 10^frac(L)\10^(1-n), lift(m)] \\ where x\y = floor(x/y) but more efficient } print("Length, first and last 20 digits of 5^4^3^2: ", num_first_last_digits()) \\ uses default values a=5, b=4^3^2, n=20
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#PureBasic
PureBasic
Procedure.s zeck(n.i) Dim f.i(1) : Define i.i=1, o$ f(0)=1 : f(1)=1 While f(i)<n i+1 : ReDim f(ArraySize(f())+1) : f(i)=f(i-1)+f(i-2) Wend For i=i To 1 Step -1 If n>=f(i) : o$+"1" : n-f(i) : Else : o$+"0" : EndIf Next If Len(o$)>1 : o$=LTrim(o$,"0") : EndIf ProcedureReturn o$ EndProcedure...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Dafny
Dafny
  datatype Door = Closed | Open   method InitializeDoors(n:int) returns (doors:array<Door>) // Precondition: n must be a valid array size. requires n >= 0 // Postcondition: doors is an array, which is not an alias for any other // object, with a length of n, all of whose elements are Closed. The "fresh" // (n...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Harbour
Harbour
// Declare and initialize two-dimensional array local arr1 := { { "NITEM", "N", 10, 0 }, { "CONTENT", "C", 60, 0 } } // Create an empty array local arr2 := {} // Declare three-dimensional array local arr3[ 2, 100, 3 ] // Create an array local arr4 := Array( 50 )   // Array can be dynamically ...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Wren
Wren
import "/complex" for Complex   var x = Complex.new(1, 3) var y = Complex.new(5, 2) System.print("x =  %(x)") System.print("y =  %(y)") System.print("x + y =  %(x + y)") System.print("x - y =  %(x - y)") System.print("x * y =  %(x * y)") System.print("x / y =  %(x / y)") System.print("-x =  %(-x)") System.pr...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Raku
Raku
say ' type n n**n exp(n,n)'; say '-------- -------- -------- --------';   for 0, 0.0, FatRat.new(0), 0e0, 0+0i { printf "%8s  %8s  %8s  %8s\n", .^name, $_, $_**$_, exp($_,$_); }
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Red
Red
Red[] print 0 ** 0 print power 0 0 print math [0 ** 0]
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#GAP
GAP
leftOf  :=function(setA, vA, setB, vB) local i; for i in [1..4] do if ( setA[i] = vA) and (setB[i+1] = vB) then return true ;fi; od; return false; end;   nextTo  :=function(setA, vA, setB, vB) local i; for i in [1..4] do if ( setA[i] = vA) and (setB[i+1] = vB) then return true ;fi; if ( setB[i] = vB) and (...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#JavaScript
JavaScript
//create XMLDocument object from file var xhr = new XMLHttpRequest(); xhr.open('GET', 'file.xml', false); xhr.send(null); var doc = xhr.responseXML;   //get first <item> element var firstItem = doc.evaluate( '//item[1]', doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; alert( firstItem.textConten...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#Java
Java
package org.rosettacode.yinandyang;   import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel;   public class YinYangGenerator { private final int size;   public YinYangGenerat...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#E
E
def y := fn f { fn x { x(x) }(fn y { f(fn a { y(y)(a) }) }) } def fac := fn f { fn n { if (n<2) {1} else { n*f(n-1) } }} def fib := fn f { fn n { if (n == 0) {0} else if (n == 1) {1} else { f(n-1) + f(n-2) } }}
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#ERRE
ERRE
PROGRAM ZIG_ZAG   !$DYNAMIC DIM ARRAY%[0,0]   BEGIN SIZE%=5  !$DIM ARRAY%[SIZE%-1,SIZE%-1]   I%=1 J%=1 FOR E%=0 TO SIZE%^2-1 DO ARRAY%[I%-1,J%-1]=E% IF ((I%+J%) AND 1)=0 THEN IF J%<SIZE% THEN J%+=1 ELSE I%+=2 END IF IF I%>1 THEN I%-=1 END IF ...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Pascal
Pascal
program GMP_Demo;   uses math, gmp;   var a: mpz_t; out: pchar; len: longint; i: longint;   begin mpz_init_set_ui(a, 5); mpz_pow_ui(a, a, 4 ** (3 ** 2)); len := mpz_sizeinbase(a, 10); writeln('GMP says size is: ', len); out := mpz_get_str(NIL, 10, a); writeln('Actual size is: ', length(out))...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Python
Python
def fib(): memo = [1, 2] while True: memo.append(sum(memo)) yield memo.pop(0)   def sequence_down_from_n(n, seq_generator): seq = [] for s in seq_generator(): seq.append(s) if s >= n: break return seq[::-1]   def zeckendorf(n): if n == 0: return [0] seq = sequ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Dart
Dart
main() { for (var k = 1, x = new List(101); k <= 100; k++) { for (int i = k; i <= 100; i += k) x[i] = !x[i]; if (x[k]) print("$k open"); } }
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Haskell
Haskell
import Data.Array.IO   main = do arr <- newArray (1,10) 37 :: IO (IOArray Int Int) a <- readArray arr 1 writeArray arr 1 64 b <- readArray arr 1 print (a,b)
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#XPL0
XPL0
include c:\cxpl\codes;   func real CAdd(A, B, C); \Return complex sum of two complex numbers real A, B, C; [C(0):= A(0) + B(0); C(1):= A(1) + B(1); return C; ];   func real CMul(A, B, C); \Return complex product of two complex numbers real A, B, C; [C(0):= A(0)*B(0) - A(1)*B(1); C(1):= A(1)*B(0) + A(0)*...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Yabasic
Yabasic
rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem CADDI/CADDR addition of complex numbers Z1 + Z2 with Z1 = a1 + b1 *i Z2 = a2 + b2*i rem CADDI returns imaginary part and CADDR the real part rem +++++++++++++++++++++++++++++++++++++++++++++++++++...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Relation
Relation
  echo pow(0,0) // 1  
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#REXX
REXX
/*REXX program shows the results of raising zero to the zeroth power.*/ say '0 ** 0 (zero to the zeroth power) ───► ' 0**0
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#Go
Go
package main   import ( "fmt" "log" "strings" )   // Define some types   type HouseSet [5]*House type House struct { n Nationality c Colour a Animal d Drink s Smoke } type Nationality int8 type Colour int8 type Animal int8 type Drink int8 type Smoke int8  ...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Julia
Julia
using LibExpat   xdoc = raw"""<inventory title="OmniCorp Store #45x10^3"> <section name="health"> <item upc="123456789" stock="12"> <name>Invisibility Cream</name> <price>14.50</price> <description>Makes you invisible</description> </item> <item upc="445322344" stock="18"> <name>Le...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Kotlin
Kotlin
// version 1.1.3   import javax.xml.parsers.DocumentBuilderFactory import org.xml.sax.InputSource import java.io.StringReader import javax.xml.xpath.XPathFactory import javax.xml.xpath.XPathConstants import org.w3c.dom.Node import org.w3c.dom.NodeList   val xml = """ <inventory title="OmniCorp Store #45x10^3"> <sect...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#JavaScript
JavaScript
  function Arc(posX,posY,radius,startAngle,endAngle,color){//Angle in radians. this.posX=posX; this.posY=posY; this.radius=radius; this.startAngle=startAngle; this.endAngle=endAngle; this.color=color; } //0,0 is the top left of the screen var YingYang=[ new Arc(0.5,0.5,1,0.5*Math.PI,1.5*Math.PI,"white"),//Half white se...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#EchoLisp
EchoLisp
  ;; Ref : http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html   (define Y (lambda (X) ((lambda (procedure) (X (lambda (arg) ((procedure procedure) arg)))) (lambda (procedure) (X (lambda (arg) ((procedure procedure) arg)))))))   ; Fib (define Fib* (lambda (func-arg) (lambd...
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#Euphoria
Euphoria
function zigzag(integer size) sequence s integer i, j, d, max s = repeat(repeat(0,size),size) i = 1 j = 1 d = -1 max = size*size for n = 1 to floor(max/2)+1 do s[i][j] = n s[size-i+1][size-j+1] = max-n+1 i += d j-= d if i < 1 then i += 1 d = -d ...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Perl
Perl
use Math::BigInt; my $x = Math::BigInt->new('5') ** Math::BigInt->new('4') ** Math::BigInt->new('3') ** Math::BigInt->new('2'); my $y = "$x"; printf("5**4**3**2 = %s...%s and has %i digits\n", substr($y,0,20), substr($y,-20), length($y));
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Phix
Phix
with javascript_semantics include mpfr.e atom t0 = time() mpz res = mpz_init() mpz_ui_pow_ui(res,5,power(4,power(3,2))) string s = mpz_get_short_str(res), e = elapsed(time()-t0) printf(1,"5^4^3^2 = %s (%s)\n", {s,e})
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Quackery
Quackery
[ 2 base put echo base release ] is binecho ( n --> )   [ 0 swap ' [ 2 1 ] [ 2dup 0 peek < iff [ behead drop ] done dup 0 peek over 1 peek + swap join again ] witheach [ rot 1 << unrot 2dup < iff drop else [ - dip...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Dc
Dc
  ## NB: This code uses the dc command "r" via register "r". ## You may comment out the unwanted version. [SxSyLxLy]sr # this should work with every "dc" [r]sr # GNU dc can exchange top 2 stack values by "r" ## Now use "lrx" instead of "r" ...   0k # we work without decimal places [q]sq ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#hexiscript
hexiscript
let a arr 2 # fixed size let a[0] 123 # index starting at 0 let a[1] "test" # can hold different types   println a[1]
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#zkl
zkl
var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library) (GSL.Z(3,4) + GSL.Z(1,2)).println(); // (4.00+6.00i) (GSL.Z(3,4) - GSL.Z(1,2)).println(); // (2.00+2.00i) (GSL.Z(3,4) * GSL.Z(1,2)).println(); // (-5.00+10.00i) (GSL.Z(3,4) / GSL.Z(1,2)).println(); // (2.20-0.40i) (GSL.Z(1,0) / GSL.Z(1,1)).println(...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#zonnon
zonnon
  module Numbers; type {public,immutable} Complex = record re,im: real; end Complex;   operator {public} "+" (a,b: Complex): Complex; var r: Complex; begin r.re := a.re + b.re; r.im := a.im + b.im; return r end "+";   operator {public} "-" (a,b: Complex): Complex; var r: Complex; begin r.re := a.re - b.re; ...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Ring
Ring
  x = 0 y = 0 z = pow(x,y) see "z=" + z + nl # z=1  
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Ruby
Ruby
require 'bigdecimal'   [0, 0.0, Complex(0), Rational(0), BigDecimal("0")].each do |n| printf "%10s: ** -> %s\n" % [n.class, n**n] end
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Rust
Rust
fn main() { println!("{}",0u32.pow(0)); }
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#Haskell
Haskell
module Main where   import Control.Applicative ((<$>), (<*>)) import Control.Monad (foldM, forM_) import Data.List ((\\))   -- types data House = House { color :: Color -- <trait> :: House -> <Trait> , man :: Man , pet :: Pet , drink :: Drink , smoke :: Smoke } deriving (Eq, Show...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Ksh
Ksh
  #!/bin/ksh   # Perform XPath queries on a XML Document   # # Variables: # typeset -T Xml_t=( typeset -h 'UPC' upc typeset -i -h 'num in stock' stock=0 typeset -h 'name' name typeset -F2 -h 'price' price typeset -h 'description' description   function init_item { typeset key ; key="$1" typeset val ;...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Lasso
Lasso
// makes extracting attribute values easier define xml_attrmap(in::xml_namedNodeMap_attr) => { local(out = map) with attr in #in do #out->insert(#attr->name = #attr->value) return #out }   local( text = '<inventory title="OmniCorp Store #45x10^3"> <section name="health"> <item upc="123456789" stock="12"> ...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#jq
jq
  def svg: "<svg width='100%' height='100%' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>" ;   def draw_yinyang(x; scale): "<use xlink:href='#y' transform='translate(\(x),\(x)) scale(\(scale))'/>";   def define_yinyang: "<defs> <g id='y'> <circle...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#Julia
Julia
function yinyang(n::Int=3) radii = (i * n for i in (1, 3, 6)) ranges = collect(collect(-r:r) for r in radii) squares = collect(collect((x, y) for x in rnge, y in rnge) for rnge in ranges) circles = collect(collect((x, y) for (x,y) in sqrpoints if hypot(x, y) ≤ radius) for (sqrpo...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#Eero
Eero
#import <Foundation/Foundation.h>   typedef int (^Func)(int) typedef Func (^FuncFunc)(Func) typedef Func (^RecursiveFunc)(id) // hide recursive typing behind dynamic typing   Func fix(FuncFunc f) Func r(RecursiveFunc g) int s(int x) return g(g)(x) return f(s) return r(r)   int main(int argc, const cha...
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#F.23
F#
  //Produce a zig zag matrix - Nigel Galloway: April 7th., 2015 let zz l a = let N = Array2D.create l a 0 let rec gng (n, i, g, e) = N.[n,i] <- g match e with | _ when i=a-1 && n=l-1 -> N | 1 when n = l-1 -> gng (n, i+1, g+1, 2) | 2 when i = a-1 -> gng (n+1, i, g+1, 1) | 1 when...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#PHP
PHP
<?php $y = bcpow('5', bcpow('4', bcpow('3', '2'))); printf("5**4**3**2 = %s...%s and has %d digits\n", substr($y,0,20), substr($y,-20), strlen($y)); ?>
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#PicoLisp
PicoLisp
(let L (chop (** 5 (** 4 (** 3 2)))) (prinl (head 20 L) "..." (tail 20 L)) (length L) )
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#R
R
zeckendorf <- function(number) {   # Get an upper limit on Fibonacci numbers needed to cover number indexOfFibonacciNumber <- function(n) { if (n < 1) { 2 } else { Phi <- (1 + sqrt(5)) / 2 invertClosedFormula <- log(n * sqrt(5)) / log(Phi) ceiling(invertClosedFormula) } }   u...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#DCL
DCL
  $! doors.com $! Excecute by running @doors at prompt. $ square = 1 $ incr = 3 $ count2 = 0 $ d = 1 $ LOOP2: $ count2 = count2 + 1 $ IF (d .NE. square) $ THEN WRITE SYS$OUTPUT "door ''d' is closed" $ ELSE WRITE SYS$OUTPUT "door ''d' is open" $ square = incr + square $ ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#HicEst
HicEst
REAL :: n = 3, Astat(n), Bdyn(1, 1)   Astat(2) = 2.22222222 WRITE(Messagebox, Name) Astat(2)   ALLOCATE(Bdyn, 2*n, 3*n) Bdyn(n-1, n) = -123 WRITE(Row=27) Bdyn(n-1, n)   ALIAS(Astat, n-1, last2ofAstat, 2) WRITE(ClipBoard) last2ofAstat ! 2.22222222 0
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#ZX_Spectrum_Basic
ZX Spectrum Basic
5 LET complex=2: LET r=1: LET i=2 10 DIM a(complex): LET a(r)=1.0: LET a(i)=1.0 20 DIM b(complex): LET b(r)=PI: LET b(i)=1.2 30 DIM o(complex) 40 REM add 50 LET o(r)=a(r)+b(r) 60 LET o(i)=a(i)+b(i) 70 PRINT "Result of addition is:": GO SUB 1000 80 REM mult 90 LET o(r)=a(r)*b(r)-a(i)*b(i) 100 LET o(i)=a(i)*b(r)+a(r)*b(i...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#S-lang
S-lang
print(0^0);
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Scala
Scala
assert(math.pow(0, 0) == 1, "Scala blunder, should go back to school !")
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Scheme
Scheme
(display (expt 0 0)) (newline) (display (expt 0.0 0.0)) (newline) (display (expt 0+0i 0+0i)) (newline)
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#J
J
ehs=: 5$a:   cr=: (('English';'red') 0 3} ehs);<('Dane';'tea') 0 2}ehs cr=: cr, (('German';'Prince') 0 4}ehs);<('Swede';'dog') 0 1 }ehs   cs=: <('PallMall';'birds') 4 1}ehs cs=: cs, (('yellow';'Dunhill') 3 4}ehs);<('BlueMaster';'beer') 4 2}ehs   lof=: (('coffee';'green')2 3}ehs);<(<'white')3}ehs   next=: <((<'Blend') 4...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#LiveCode
LiveCode
put revXMLCreateTree(fld "FieldXML",true,true,false) into xmltree   // task 1 put revXMLEvaluateXPath(xmltree,"//item[1]") into nodepath put revXMLText(xmltree,nodepath,true)   // task 2 put revXMLDataFromXPathQuery(xmltree,"//item/price",,comma)   // task 3 put revXMLDataFromXPathQuery(xmltree,"//name") into namenodes...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Lua
Lua
require 'lxp' data = [[<inventory title="OmniCorp Store #45x10^3"> <section name="health"> <item upc="123456789" stock="12"> <name>Invisibility Cream</name> <price>14.50</price> <description>Makes you invisible</description> </item> <item upc="445322344" stock="18"> <name>Levitatio...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#Kotlin
Kotlin
// version 1.1.2   import java.awt.Color import java.awt.Graphics import java.awt.Image import java.awt.image.BufferedImage import javax.swing.ImageIcon import javax.swing.JFrame import javax.swing.JPanel import javax.swing.JLabel   class YinYangGenerator { private fun drawYinYang(size: Int, g: Graphics) { ...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#Ela
Ela
fix = \f -> (\x -> & f (x x)) (\x -> & f (x x))   fac _ 0 = 1 fac f n = n * f (n - 1)   fib _ 0 = 0 fib _ 1 = 1 fib f n = f (n - 1) + f (n - 2)   (fix fac 12, fix fib 12)
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#Factor
Factor
USING: columns fry kernel make math math.ranges prettyprint sequences sequences.cords sequences.extras ; IN: rosetta-code.zig-zag-matrix   : [1,b,1] ( n -- seq ) [1,b] dup but-last-slice <reversed> cord-append ;   : <reversed-evens> ( seq -- seq' ) [ even? [ <reversed> ] when ] map-index ;   : diagonals ( n -- ...
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Pike
Pike
> string res = (string)pow(5,pow(4,pow(3,2))); > res[..19] == "62060698786608744707"; Result: 1 > res[<19..] == "92256259918212890625"; Result: 1 > sizeof(result); Result: 183231
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#PowerShell
PowerShell
# Perform calculation $BigNumber = [BigInt]::Pow( 5, [BigInt]::Pow( 4, [BigInt]::Pow( 3, 2 ) ) )   # Display first and last 20 digits $BigNumberString = [string]$BigNumber $BigNumberString.Substring( 0, 20 ) + "..." + $BigNumberString.Substring( $BigNumberString.Length - 20, 20 )   # Display number of digits $BigNum...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Racket
Racket
  #lang racket (require math)   (define (fibs n) (reverse (for/list ([i (in-naturals 2)] #:break (> (fibonacci i) n)) (fibonacci i))))   (define (zechendorf n) (match/values (for/fold ([n n] [xs '()]) ([f (fibs n)]) (if (> f n) (values n (cons 0 xs)) (values (- n f) (cons 1 x...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Delphi
Delphi
proc nonrec main() void: byte DOORS = 100; [DOORS+1] bool door_open; unsigned DOORS i, j;   /* make sure all doors are closed */ for i from 1 upto DOORS do door_open[i] := false od;   /* pass through the doors */ for i from 1 upto DOORS do for j from i by i upto DOORS do ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#HolyC
HolyC
// Create an array of fixed size U8 array[10] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;   // The first element of a HolyC array is indexed at 0. To set a value: array[0] = 123;   // Access an element Print("%d\n", array[0]);
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i"; include "complex.s7i";   const proc: main is func begin writeln("0 ** 0 = " <& 0 ** 0); writeln("0.0 ** 0 = " <& 0.0 ** 0); writeln("0.0 ** 0.0 = " <& 0.0 ** 0.0); writeln("0.0+0i ** 0 = " <& complex(0.0) ** 0); end func;  
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#SenseTalk
SenseTalk
set a to 0 set b to 0   put a to the power of b // Prints: 1
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#Java
Java
package org.rosettacode.zebra;   import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set;   public class Zebra {   private static final int[] orders = {1, 2, 3, 4, 5}; private static final String[] nations = {"English", "Danish", "German...
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
example = Import["test.txt", "XML"]; Cases[example, XMLElement["item", _ , _] , Infinity] // First Cases[example, XMLElement["price", _, List[n_]] -> n, Infinity] // Column Cases[example, XMLElement["name", _, List[n_]] -> n, Infinity] // Column
http://rosettacode.org/wiki/XML/XPath
XML/XPath
Perform the following three XPath queries on the XML Document below: //item[1]: Retrieve the first "item" element //price/text(): Perform an action on each "price" element (print it out) //name: Get an array of all the "name" elements XML Document: <inventory title="OmniCorp Store #45x10^3"> <section name="heal...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java symbols binary   import javax.xml.parsers. import javax.xml.xpath. import org.w3c.dom. import org.w3c.dom.Node import org.xml.sax.   xmlStr = '' - || '<inventory title="OmniCorp Store #45x10^3">' - || ' <section name="health">' - || ' <item upc="123456789" st...
http://rosettacode.org/wiki/Yin_and_yang
Yin and yang
One well-known symbol of the philosophy of duality known as yin and yang is the taijitu. Task   Create a function that, given a parameter representing size, generates such a symbol scaled to the requested size.   Generate and display the symbol for two different (small) sizes.
#Lambdatalk
Lambdatalk
  {{SVG 580 580} {YY 145 145 300} {YY 270 195 50} {YY 270 345 50} }   {def YY {lambda {:x :y :s} {{G :x :y :s} {CIRCLE 0.5 0.5 0.5 black 0 0} {{G 0.5 0 1} {HALF_CIRCLE}} {CIRCLE 0.5 0.25 0.25 black 0 0} {CIRCLE 0.5 0.75 0.25 white 0 0} {CIRCLE 0.5 0.25 0.1 white 0 0} {CIRCLE 0.5 0.75 0.1 b...
http://rosettacode.org/wiki/Y_combinator
Y combinator
In strict functional programming and the lambda calculus, functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions. This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's stat...
#Elena
Elena
import extensions;   singleton YCombinator { fix(func) = (f){(x){ x(x) }((g){ f((x){ (g(g))(x) })})}(func); }   public program() { var fib := YCombinator.fix:(f => (i => (i <= 1) ? i : (f(i-1) + f(i-2)) )); var fact := YCombinator.fix:(f => (i => (i == 0) ? 1 : (f(i-1) * i) ));   console.printLi...
http://rosettacode.org/wiki/Zig-zag_matrix
Zig-zag matrix
Task Produce a zig-zag array. A   zig-zag   array is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you zig-zag along the array's   anti-diagonals. For a graphical representation, see   JPG zigzag   (JPG uses such arrays to encode images). For example, gi...
#Fan
Fan
using gfx // for Point; convenient x/y wrapper   ** ** A couple methods for generating a 'zigzag' array like ** ** 0 1 5 6 ** 2 4 7 12 ** 3 8 11 13 ** 9 10 14 15 ** class ZigZag { ** return an n x n array of uninitialized Int static Int[][] makeSquareArray(Int n) { Int[][] grid := Int[][,] {it....
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#Prolog
Prolog
  task(Length) :- N is 5^4^3^2,   number_codes(N, Codes), append(`62060698786608744707`, _, Codes), append(_, `92256259918212890625`, Codes),   length(Codes, Length).  
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included)
Arbitrary-precision integers (included)
Using the in-built capabilities of your language, calculate the integer value of: 5 4 3 2 ...
#PureBasic
PureBasic
IncludeFile "Decimal.pbi"   ;- Declare the variables that will be used Define.Decimal *a Define n, L$, R$, out$, digits.s   ;- 4^3^2 is withing 32 bit range, so normal procedures can be used n=Pow(4,Pow(3,2))   ;- 5^n is larger then 31^2, so the same library call as in the "Long multiplication" task is used *a=PowerDec...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Raku
Raku
printf "%2d: %8s\n", $_, zeckendorf($_) for 0 .. 20;   multi zeckendorf(0) { '0' } multi zeckendorf($n is copy) { constant FIBS = (1,2, *+* ... *).cache; [~] map { $n -= $_ if my $digit = $n >= $_; +$digit; }, reverse FIBS ...^ * > $n; }
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Draco
Draco
proc nonrec main() void: byte DOORS = 100; [DOORS+1] bool door_open; unsigned DOORS i, j;   /* make sure all doors are closed */ for i from 1 upto DOORS do door_open[i] := false od;   /* pass through the doors */ for i from 1 upto DOORS do for j from i by i upto DOORS do ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Icon_and_Unicon
Icon and Unicon
record aThing(a, b, c) # arbitrary object (record or class) for illustration   procedure main() A0 := [] # empty list A0 := list() # empty list (default size 0) A0 := list(0) # empty list (literal size 0)   A1 := list(10) # 10 elements, default init...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Sidef
Sidef
[0, Complex(0, 0)].each {|n| say n**n }
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Sinclair_ZX81_BASIC
Sinclair ZX81 BASIC
PRINT 0**0
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Smalltalk
Smalltalk
  0 raisedTo: 0 0.0 raisedTo: 0.0  
http://rosettacode.org/wiki/Zebra_puzzle
Zebra puzzle
Zebra puzzle You are encouraged to solve this task according to the task description, using any language you may know. The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved programmatically. It has several variants, one of them this:   There are five houses.   The English man lives ...
#jq
jq
  # Attempt to unify the input object with the specified object def unify( object ): # Attempt to unify the input object with the specified tag:value def unify2(tag; value): if . == null then null elif .[tag] == value then . elif .[tag] == null then .[tag] = value else null end; reduce (obje...