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/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Pascal
Pascal
program DeceptiveNumbers; {$IfDef FPC} {$Optimization ON,ALL} {$ENDIF} {$IfDef Windows} {$APPTYPE CONSOLE} {$ENDIF} uses sysutils; const LIMIT = 100000;//1E6 at home takes over (5 min) now 1m10s RepInitLen = 13; //Uint64 19 decimal digits -> max 6 digits divisor DecimalDigits = 10*1000*1000*1000*1000;//1E13 R...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Perl
Perl
use strict; use warnings; use Math::AnyNum qw(imod is_prime);   my($x,@D) = 2; while ($x++) { push @D, $x if 1 == $x%2 and !is_prime $x and 0 == imod(1x($x-1),$x); last if 25 == @D } print "@D\n";
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Phix
Phix
with javascript_semantics constant limit = 70 atom t0 = time() include mpfr.e mpz repunit = mpz_init(0) integer n = 1, count = 0 printf(1,"The first %d deceptive numbers are:\n",limit) while count<limit do -- No repunit is ever divisible by 2 or 5 since it ends in 1. -- If n is 3*k, sum(digits(repunit))=3*k-1, ...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Raku
Raku
my \R = [\+] 1, 10, 100 … *; put (2..∞).grep( {$_ % 2 && $_ % 3 && $_ % 5 && !.is-prime} ).grep( { R[$_-2] %% $_ } )[^25];
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Rust
Rust
// [dependencies] // primal = "0.3" // rug = "1.15.0"   fn main() { println!("First 100 deceptive numbers:"); use rug::Integer; let mut repunit = Integer::from(11); let mut n: u32 = 3; let mut count = 0; while count != 100 { if n % 3 != 0 && n % 5 != 0 && !primal::is_prime(n as u64) && r...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Sidef
Sidef
say 100.by {|n| n.is_composite && (divmod(powmod(10, n-1, n)-1, 9, n) == 0) }.join(' ')
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Vlang
Vlang
import math.big   fn is_prime(n int) bool { if n < 2 { return false } else if n%2 == 0 { return n == 2 } else if n%3 == 0 { return n == 3 } else { mut d := 5 for d*d <= n { if n%d == 0 { return false } d += 2 ...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Wren
Wren
/* deceptive_numbers.wren */   import "./gmp" for Mpz import "./math" for Int   var count = 0 var limit = 25 var n = 17 var repunit = Mpz.from(1111111111111111) var deceptive = [] while (count < limit) { if (!Int.isPrime(n) && n % 3 != 0 && n % 5 != 0) { if (repunit.isDivisibleUi(n)) { deceptive...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#6502_Assembly
6502 Assembly
LDA $00  ;read the byte at memory address $00 STA $20  ;store it at memory address $20
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Aime
Aime
list L1, L2;   # Lists are heterogeneous: l_append(L1, 3); l_append(L1, "deep");   # and may contain self references. # A self references in the last position: l_link(L1, -1, L1);   # List may also contain mutual references. # Create a new list in the last position: l_n_list(L1, -1); # Add a reference to the top level ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Arturo
Arturo
x: #[ name: "John" surname: "Doe" age: 34 hobbies: [ "Cycling", "History", "Programming", "Languages", "Psychology", "Buddhism" ] sayHello: function [][ print "Hello there!" ] ]   print ["Name of first person:" x\name]   y: new x y\...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#AutoHotkey
AutoHotkey
DeepCopy(Array, Objs=0) { If !Objs Objs := Object() Obj := Array.Clone() ; produces a shallow copy in that any sub-objects are not cloned Objs[&Array] := Obj ; Save this new array - & returns the address of Array in memory For Key, Val in Obj If (IsObject(Val)) ; If it is a subarray ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#AWK
AWK
BEGIN { for (elem in original) copied[elem] = original[elem] }
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Babel
Babel
babel> [1 2 3] dup dup 0 7 0 1 move sd ! ---TOS--- [val 0x7 0x2 0x3 ] [val 0x7 0x2 0x3 ] ---BOS---
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#C
C
  #include<stdio.h>   typedef struct{ int a; }layer1;   typedef struct{ layer1 l1; float b,c; }layer2;   typedef struct{ layer2 l2; layer1 l1; int d,e; }layer3;   void showCake(layer3 cake){ printf("\ncake.d = %d",cake.d); printf("\ncake.e = %d",cake.e); printf("\ncake.l1.a = %d",cake.l1.a); printf("\ncake.l2...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#C.23
C#
using System;   namespace prog { class MainClass { class MyClass : ICloneable { public MyClass() { f = new int[3]{2,3,5}; c = '1'; }   public object Clone() { MyClass cpy = (MyClass) this.MemberwiseClone(); cpy.f = (int[]) this.f.Clone(); return cpy; }   public char c; public ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#C.2B.2B
C++
  #include <array> #include <iostream> #include <list> #include <map> #include <vector>   int main() { // make a nested structure to copy - a map of arrays containing vectors of strings auto myNumbers = std::vector<std::string>{"one", "two", "three", "four"}; auto myColors = std::vector<std::string>{"red", ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Common_Lisp
Common Lisp
$ clisp -q [1]> (setf *print-circle* t) T [2]> (let ((a (cons 1 nil))) (setf (cdr a) a)) ;; create circular list #1=(1 . #1#) [3]> (read-from-string "#1=(1 . #1#)") ;; read it from a string #1=(1 . #1#) ;; a similar circular list is returned
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
local :(copy-action) {}   (copy-action)!list obj cache: local :new [] set-to cache obj new for i range 0 -- len obj: push-to new (deepcopy) @obj! i cache return new   (copy-action)!dict obj cache: local :new {} set-to cache obj new for key in keys obj: set-to new (deepcopy) @key cache (deepcopy) @obj! @key c...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Delphi
Delphi
  program DeepCopyApp;   {$APPTYPE CONSOLE}   uses System.TypInfo;   type TTypeA = record value1: integer; value2: char; value3: string[10]; value4: Boolean; function DeepCopy: TTypeA; end;   { TTypeA }   function TTypeA.DeepCopy: TTypeA; begin CopyRecord(@result, @self, TypeInfo(TTypeA)); e...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#E
E
def deSubgraphKit := <elib:serial.deSubgraphKit> def deepcopy(x) { return deSubgraphKit.recognize(x, deSubgraphKit.makeBuilder()) }
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Erlang
Erlang
1> A = <<"abcdefghijklmnopqrstuvwxyz">>. <<"abcdefghijklmnopqrstuvwxyz">> 2> B = <<A/binary, A/binary, A/binary, A/binary>>. <<"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz">> 3> <<_:10/binary, C:80/binary, _/binary>> = B. <<"abcdefghijklmnopqrstuvwxyzabcdefgh...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Factor
Factor
USING: accessors arrays io kernel named-tuples prettyprint sequences sequences.deep ;   ! Define a simple class TUPLE: foo bar baz ;   ! Allow instances of foo to be modified like an array INSTANCE: foo named-tuple   ! Create a foo object composed of mutable objects V{ 1 2 3 } V{ 4 5 6 } [ clone ] bi@ foo boa   ! creat...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#FreeBASIC
FreeBASIC
  Type DeepCopy value1 As Integer value2 As String * 1 value3 As String value4 As Boolean value5 As Double End Type Dim As DeepCopy a, b   a.value1 = 10 a.value2 = "A" a.value3 = "OK" a.value4 = True a.value5 = 1.985766472453666   b = a a.value1 = 20 a.value2 = "B" a.value3 = "NOK" a.value4 = False ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Go
Go
package main   import "fmt"   // a complex data structure type cds struct { i int // no special handling needed for deep copy s string // no special handling b []byte // copied easily with append function m map[int]bool // deep copy requires looping }   // a method func (c c...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Icon_and_Unicon
Icon and Unicon
procedure deepcopy(A, cache) #: return a deepcopy of A local k   /cache := table() # used to handle multireferenced objects if \cache[A] then return cache[A]   case type(A) of { "table"|"list": { cache[A] := copy(A) every cache[A][k := key(A)] := deepcopy(A[k], ca...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#J
J
a=:b=: 2 2 2 2 2 NB. two copies of the same array b=: 3 (2)} b NB. modify one of the arrays b 2 2 3 2 2 a 2 2 2 2 2
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Java
Java
  import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable;   public class DeepCopy {   public static void main(String[] args) { Person p1 = new Person("Clark", "Kent", new Address("1 World Cen...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#11l
11l
F deconv(g, f) V result = [0]*(g.len - f.len + 1) L(&e) result V n = L.index e = g[n] V lower_bound = I n >= f.len {n - f.len + 1} E 0 L(i) lower_bound .< n e -= result[i] * f[n - i] e /= f[0] R result   V h = [-8,-9,-3,-1,-6,7] V f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#JavaScript
JavaScript
  var deepcopy = function(o){ return JSON.parse(JSON.stringify(src)); };   var src = {foo:0,bar:[0,1]}; print(JSON.stringify(src)); var dst = deepcopy(src); print(JSON.stringify(src));  
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#jq
jq
[1,2] | . as $x | . as $y
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO;   procedure Main is package real_io is new Float_IO (Long_Float); use real_io;   type Vector is array (Natural range <>) of Long_Float;   function deconv (g, f : Vector) return Vector is len : Positive := Integer'Max ((g'Length - f'length), (f'length - g'leng...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Julia
Julia
# v0.6.0   cp = deepcopy(obj)
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Kotlin
Kotlin
// Version 1.2.31   import java.io.Serializable import java.io.ByteArrayOutputStream import java.io.ByteArrayInputStream import java.io.ObjectOutputStream import java.io.ObjectInputStream   fun <T : Serializable> deepCopy(obj: T?): T? { if (obj == null) return null val baos = ByteArrayOutputStream() val oos...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#BBC_BASIC
BBC BASIC
*FLOAT 64 DIM h(5), f(15), g(20) h() = -8,-9,-3,-1,-6,7 f() = -3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1 g() = 24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7   PROCdeconv(g(), f(), x()) PRINT "deconv(g,f) = " FNprintarray(x()) x() -= h() : IF SUM(x())...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <complex.h>   double PI; typedef double complex cplx;   void _fft(cplx buf[], cplx out[], int n, int step) { if (step < n) { _fft(out, buf, n, step * 2); _fft(out + step, buf + step, n, step * 2);   for (int i = 0; i < n; i += 2 * step) { cplx ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Lasso
Lasso
local(copy) = #myobject->ascopydeep
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Lingo
Lingo
-- Supports lists, property lists, images, script instances and scalar values (integer, float, string, symbol). on deepcopy (var, cycleCheck) case ilk(var) of #list, #propList, #image: return var.duplicate() #instance: if string(var) starts "<Xtra " then return var -- deep copy makes no sense for Xtra...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Common_Lisp
Common Lisp
;; Assemble the mxn matrix A from the 2D row vector x. (defun make-conv-matrix (x m n) (let ((lx (cadr (array-dimensions x))) (A (make-array `(,m ,n) :initial-element 0)))   (loop for j from 0 to (- n 1) do (loop for i from 0 to (- m 1) do (setf (aref A i j) (co...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Lua
Lua
function _deepcopy(o, tables)   if type(o) ~= 'table' then return o end   if tables[o] ~= nil then return tables[o] end   local new_o = {} tables[o] = new_o   for k, v in next, o, nil do local new_k = _deepcopy(k, tables) local new_v = _deepcopy(v, tables) new_o[new_k] = new_v end   ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
a = {"foo", \[Pi], {<| "deep" -> {# + 1 &, {{"Mathematica"}, {{"is"}, {"a"}}, {{{"cool"}}}, \ {{"programming"}, {"language!"}}}}|>}}; b = a; a[[2]] -= 3; a[[3, 1, 1, 1]] = #^2 &; Print[a]; Print[b];
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#D
D
T[] deconv(T)(in T[] g, in T[] f) pure nothrow { int flen = f.length; int glen = g.length; auto result = new T[glen - flen + 1]; foreach (int n, ref e; result) { e = g[n]; immutable lowerBound = (n >= flen) ? n - flen + 1 : 0; foreach (i; lowerBound .. n) e -= res...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Nim
Nim
deepCopy(newObj, obj)
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#OCaml
OCaml
let rec copy t = if Obj.is_int t then t else let tag = Obj.tag t in if tag = Obj.double_tag then t else if tag = Obj.closure_tag then t else if tag = Obj.string_tag then Obj.repr (String.copy (Obj.obj t)) else if tag = 0 || tag = Obj.double_array_tag then begin let size = Obj.size t in ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Ada
Ada
type My_Type is range 1..10;
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Fortran
Fortran
  ! Build ! Windows: ifort /I "%IFORT_COMPILER11%\mkl\include\ia32" deconv1d.f90 "%IFORT_COMPILER11%\mkl\ia32\lib\*.lib" ! Linux:   program deconv ! Use gelsd from LAPACK95. use mkl95_lapack, only : gelsd   implicit none real(8), allocatable :: g(:), href(:), A(:,:), f(:) real(8), pointer :: h(:), r(:) ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#OxygenBasic
OxygenBasic
  'DEEP COPY FOR A RECURSIVE TREE STRUCTURE   uses console   class branches ' static int count int level int a,b,c branches*branch1 branches*branch2 ' method constructor(int n) ========================= level=n count++ output count tab level cr if level>0 new branches n1(n-1) ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#PARI.2FGP
PARI/GP
  #!/usr/bin/perl use strict; use warnings; use Storable; use Data::Dumper;   my $src = { foo => 0, bar => [0, 1] }; $src->{baz} = $src; my $dst = Storable::dclone($src); print Dumper($src); print Dumper($dst);  
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#ALGOL_68
ALGOL 68
# assume max int <= ABS - max negative int # INT max bounded = ( LENG max int * max int > long max int | ENTIER sqrt(max int) | max int );   MODE RANGE = STRUCT(INT lwb, upb); MODE BOUNDED = STRUCT(INT value, RANGE range); FORMAT bounded repr = $g"["g(-0)":"g(-0)"]"$;   # Define some useful operators for looping ...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Go
Go
package main   import "fmt"   func main() { h := []float64{-8, -9, -3, -1, -6, 7} f := []float64{-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1} g := []float64{24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96, 96, 31, 55, 36, 29, -43, -7} fmt.Println(h) fmt.Println(decon...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Perl
Perl
  #!/usr/bin/perl use strict; use warnings; use Storable; use Data::Dumper;   my $src = { foo => 0, bar => [0, 1] }; $src->{baz} = $src; my $dst = Storable::dclone($src); print Dumper($src); print Dumper($dst);  
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Phix
Phix
object a, b a = {1,{2,3},"four",{5.6,7,{8.9}}} b = a b[3] = 4 ?a ?b
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#ATS
ATS
(*   Here is the type:   *)   typedef rosetta_code_primitive_type = [i : int | 1 <= i; i <= 10] int i   (*   You do not have to insert bounds checking, and the compiler inserts no bounds checking. You simply *cannot* assign an out-of-range value.   (Proviso: unless you do some serious cheating.)   *)   implement main...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#C.23
C#
using System; using System.Globalization;   struct LimitedInt : IComparable, IComparable<LimitedInt>, IConvertible, IEquatable<LimitedInt>, IFormattable { const int MIN_VALUE = 1; const int MAX_VALUE = 10;   public static readonly LimitedInt MinValue = new LimitedInt(MIN_VALUE); public static readonly L...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Haskell
Haskell
deconv1d :: [Double] -> [Double] -> [Double] deconv1d xs ys = takeWhile (/= 0) $ deconv xs ys where [] `deconv` _ = [] (0:xs) `deconv` (0:ys) = xs `deconv` ys (x:xs) `deconv` (y:ys) = let q = x / y in q : zipWith (-) xs (scale q ys ++ repeat 0) `deconv` (y : ys)   scale :: Double -> [Double] -...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#PHP
PHP
<?php class Foo { public function __clone() { $this->child = clone $this->child; } }   $object = new Foo; $object->some_value = 1; $object->child = new stdClass; $object->child->some_value = 1;   $deepcopy = clone $object; $deepcopy->some_value++; $deepcopy->child->some_value++;   echo "Object conta...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#PicoLisp
PicoLisp
(mapcar copy List)
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#C.2B.2B
C++
#include <stdexcept>   class tiny_int { public: tiny_int(int i): value(i) { if (value < 1) throw std::out_of_range("tiny_int: value smaller than 1"); if (value > 10) throw std::out_of_range("tiny_int: value larger than 10"); } operator int() const { return value; } tiny_int& op...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#J
J
Ai=: (i.@] =/ i.@[ -/ i.@>:@-)&# divide=: [ +/ .*~ [:%.&.x: ] +/ .* Ai
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Java
Java
import java.util.Arrays;   public class Deconvolution1D { public static int[] deconv(int[] g, int[] f) { int[] h = new int[g.length - f.length + 1]; for (int n = 0; n < h.length; n++) { h[n] = g[n]; int lower = Math.max(n - f.length + 1, 0); for (int i = lower; i ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#PureBasic
PureBasic
Macro PrintStruc(StrucVal) PrintN(Str(StrucVal#\value1)) PrintN(Chr(StrucVal#\value2)) PrintN(StrucVal#\value3) If StrucVal#\value4 PrintN("TRUE") Else PrintN("FALSE") EndIf PrintN("") EndMacro   Structure TTypeA value1.i value2.c value3.s[10] value4.b EndStructure   Define.TTypeA a, b...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Python
Python
import copy deepcopy_of_obj = copy.deepcopy(obj)
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Clojure
Clojure
(defn tinyint [^long value] (if (<= 1 value 10) (proxy [Number] [] (doubleValue [] value) (longValue [] value)) (throw (ArithmeticException. "integer overflow"))))
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Common_Lisp
Common Lisp
(deftype one-to-ten () '(integer 1 10))
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#11l
11l
T Sphere Float cx, cy, cz, r F (cx, cy, cz, r) .cx = cx .cy = cy .cz = cz .r = r   F dotp(v1, v2) V d = dot(v1, v2) R I d < 0 {-d} E 0.0   F hit_sphere(sph, x0, y0) V x = x0 - sph.cx V y = y0 - sph.cy V zsq = sph.r ^ 2 - (x ^ 2 + y ^ 2) I zsq < 0 R (0B, 0.0, 0.0) ...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Julia
Julia
h = [-8, -9, -3, -1, -6, 7] g = [24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96, 96, 31, 55, 36, 29, -43, -7] f = [-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1]   hanswer = deconv(float.(g), float.(f)) println("The deconvolution deconv(g, f) is $hanswer, which is the same as h = $h\n")   fanswe...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Kotlin
Kotlin
// version 1.1.3   fun deconv(g: DoubleArray, f: DoubleArray): DoubleArray { val fs = f.size val h = DoubleArray(g.size - fs + 1) for (n in h.indices) { h[n] = g[n] val lower = if (n >= fs) n - fs + 1 else 0 for (i in lower until n) h[n] -= h[i] * f[n -i] h[n] /= f[0] ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Racket
Racket
  #lang racket   (define (deepcopy x)  ;; make sure that all sharings are shown (parameterize ([print-graph #t]) (read (open-input-string (format "~s" x)))))   (define (try x)  ;; use the same setting to see that it worked (parameterize ([print-graph #t]) (printf "original: ~s\n" x) (printf "deepcopy: ~s\...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Raku
Raku
my %x = foo => 0, bar => [0, 1]; my %y = %x.deepmap(*.clone);   %x<bar>[1]++; say %x; say %y;
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#11l
11l
V digits = ‘0123456789’   F deBruijn(k, n) V alphabet = :digits[0 .< k] V a = [Byte(0)] * (k * n) [Byte] seq   F db(Int t, Int p) -> N I t > @n I @n % p == 0 @seq.extend(@a[1 .< p + 1]) E @a[t] = @a[t - p] @db(t + 1, p) V j = @a[t - p] + 1 ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#D
D
import std.exception, std.string, std.traits;   /++ A bounded integral type template. Template params: - min: the minimal value - max: the maximal value - I: the type used to store the value internally +/ struct BoundedInt(alias min, alias max, I = int) { // Static checks static assert(isIntegral!(typeof(min)))...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Ada
Ada
with Ada.Numerics.Elementary_Functions; with Ada.Numerics.Generic_Real_Arrays;   with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Video.Palettes; with SDL.Events.Events;   procedure Death_Star is   Width  : constant := 400; Height  : constant := 400;   package Float_Arrays is new...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Lua
Lua
function deconvolve(f, g) local h = setmetatable({}, {__index = function(self, n) if n == 1 then self[1] = g[1] / f[1] else self[n] = g[n] for i = 1, n - 1 do self[n] = self[n] - self[i] * (f[n - i + 1] or 0) end self[n] = self[n] / f[1] end ret...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Ruby
Ruby
# _orig_ is a Hash that contains an Array. orig = { :num => 1, :ary => [2, 3] } orig[:cycle] = orig # _orig_ also contains itself.   # _copy_ becomes a deep copy of _orig_. copy = Marshal.load(Marshal.dump orig)   # These changes to _orig_ never affect _copy_, # because _orig_ and _copy_ are disjoint structures. orig[:...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Rust
Rust
// The compiler can automatically implement Clone on structs (assuming all members have implemented Clone). #[derive(Clone)] struct Tree<T> { left: Leaf<T>, data: T, right: Leaf<T>, }   type Leaf<T> = Option<Box<Tree<T>>>;   impl<T> Tree<T> { fn root(data: T) -> Self { Self { left: None, data, r...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#11l
11l
F randomGenerator(=seed, n) [Int] r -V max_int32 = 7FFF'FFFF seed = seed [&] max_int32   L r.len < n seed = (seed * 214013 + 2531011) [&] max_int32 r [+]= seed >> 16   R r   F deal(seed) V nc = 52 V cards = Array((nc - 1 .< -1).step(-1)) V rnd = randomGenerator(seed, nc) L(r) rnd ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#8080_Assembly
8080 Assembly
bdos: equ 5 ; BDOS entry point putch: equ 2 ; Write character to console puts: equ 9 ; Write string to console org 100h lhld bdos+1 ; Put stack at highest usable address sphl ;;; Generate de_bruijn(10,4) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mvi c,40 ; Zero out a[] xra a lxi d,arr zloop: stax d inx d dcr c ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#8086_Assembly
8086 Assembly
putch: equ 2 ; Print character puts: equ 9 ; Print string cpu 8086 bits 16 section .text org 100h ;;; Calculate de_bruijn(10, 4) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; xor ax,ax ; zero a[] mov di,arr mov cx,20 ; 20 words = 40 bytes rep stosw mov di,seq ; start of sequence mov dx,0101h ; db(1,1) call db_ mo...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Delphi
Delphi
type TinyInt(Integer value) { throw @Overflow(value) when value is <1 or >10 } with Lookup, Show   func TinyInt as Integer => this.value   func TinyInt + (other) => TinyInt(this.value + other as Integer)   func TinyInt * (other) => TinyInt(this.value * other as Integer)   func TinyInt - (other) => TinyInt(this.valu...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Dyalect
Dyalect
type TinyInt(Integer value) { throw @Overflow(value) when value is <1 or >10 } with Lookup, Show   func TinyInt as Integer => this.value   func TinyInt + (other) => TinyInt(this.value + other as Integer)   func TinyInt * (other) => TinyInt(this.value * other as Integer)   func TinyInt - (other) => TinyInt(this.valu...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#AutoHotkey
AutoHotkey
#NoEnv SetBatchLines, -1 #SingleInstance, Force   ; Uncomment if Gdip.ahk is not in your standard library #Include, Gdip.ahk   ; Settings X := 200, Y := 200, Width := 200, Height := 200 ; Location and size of sphere rotation := 60 ; degrees ARGB := 0xFFFF0000 ; Color=Solid Red   If !pToken := Gdip_Startup() ; Start gdi...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
  deconv[f_List, g_List] := Module[{A = SparseArray[ Table[Band[{n, 1}] -> f[[n]], {n, 1, Length[f]}], {Length[g], Length[f] - 1}]}, Take[LinearSolve[A, g], Length[g] - Length[f] + 1]]  
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#MATLAB
MATLAB
>> h = [-8,-9,-3,-1,-6,7]; >> g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7]; >> f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]; >> deconv(g,f)   ans =   -8.0000 -9.0000 -3.0000 -1.0000 -6.0000 7.0000   >> deconv(g,h)   ans =   -3 -6 -1 8 -6 3 -1 -9 ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Scheme
Scheme
  (define (deep-copy-1 exp) ;; basic version that copies an arbitrary tree made up of pairs (cond ((pair? exp) (cons (deep-copy-1 (car exp)) (deep-copy-1 (cdr exp)))) ;; cases for extra container data types can be ;; added here, like vectors and so on (else ;; atomic objects (if (string? exp) (...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; procedure FreeCell is type State is mod 2**31; type Deck is array (0..51) of String(1..2);   package Random is procedure Init(Seed: State); function Rand return State; end Random; package body Random is S : State := State'First; procedure Init(Se...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Fixed; use Ada.Strings; with Ada.Strings.Unbounded;   procedure De_Bruijn_Sequences is   function De_Bruijn (K, N : Positive) return String is use Ada.Strings.Unbounded;   Alphabet : constant String := "0123456789";   subtyp...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#E
E
def MyNumber := 1..10   for i :MyNumber in [0, 5, 10, 15, 20, 25] { println(i) }
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#EchoLisp
EchoLisp
  (require 'types) (require 'math)   ;; type defined by a predicate (define (one-ten? x) (in-interval? x 1 10)) (type One-ten [Integer & one-ten?])   ;; OR by an enumeration (type One-ten [ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 ])   ;; EXPLICIT type checking ;; type-of? returns a Boolean   (type-of? 5 One-ten) → #t (t...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Brlcad
Brlcad
# We need a database to hold the objects opendb deathstar.g y   # We will be measuring in kilometers units km   # Create a sphere of radius 60km centred at the origin in sph1.s sph 0 0 0 60   # We will be subtracting an overlapping sphere with a radius of 40km # The resultant hole will be smaller than this, because we ...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#C
C
#include <stdio.h> #include <math.h> #include <unistd.h>   const char *shades = ".:!*oe&#%@";   double light[3] = { -50, 0, 50 }; void normalize(double * v) { double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); v[0] /= len; v[1] /= len; v[2] /= len; }   double dot(double *x, double *y) { double d = x[0]*y[0] + x[1...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Nim
Nim
proc deconv(g, f: openArray[float]): seq[float] = var h: seq[float] = newSeq[float](len(g) - len(f) + 1) for n in 0..<len(h): h[n] = g[n] var lower: int if n >= len(f): lower = n - len(f) + 1 for i in lower..<n: h[n] -= h[i] * f[n - i] h[n] /= f[0] h   let h = [-8'f64, -9, -3, -1, ...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Perl
Perl
use Math::Cartesian::Product;   sub deconvolve { our @g; local *g = shift; our @f; local *f = shift; my(@m,@d);   my $h = 1 + @g - @f; push @m, [(0) x $h, $g[$_]] for 0..$#g; for my $j (0..$h-1) { for my $k (0..$#f) { $m[$j + $k][$j] = $f[$k] } } rref(\@m); ...
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Sidef
Sidef
var src = Hash(foo => 0, bar => [0,1])   # Add a cyclic reference src{:baz} = src   # Make a deep clone var dst = src.dclone   # The address of src say src.object_id say src{:baz}.object_id   # The address of dst say dst.object_id say dst{:baz}.object_id
http://rosettacode.org/wiki/Deepcopy
Deepcopy
Task Demonstrate how to copy data structures containing complex heterogeneous and cyclic semantics. This is often referred to as deep copying, and is normally required where structures are mutable and to ensure that independent copies can be manipulated without side-effects. If this facility is not built into the la...
#Tcl
Tcl
set deepCopy [string range ${valueToCopy}x 0 end-1]
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#AutoHotkey
AutoHotkey
FreeCell(num){ cards := "A23456789TJQK", suits := "♣♦♥♠", card := [], Counter := 0 loop, parse, cards { ThisCard := A_LoopField loop, parse, suits Card[Counter++] := ThisCard . A_LoopField } loop, 52 { a := MS(num) num:=a[1] MyCardNo := mod(a[2],53-A_Index) MyCard := Card[MyCardNo] Card[MyCardNo]...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#BASIC
BASIC
10 DEFINT A-Z 20 K = 10: N = 4 30 DIM A(K*N), S(K^N+N), T(5), P(5), V(K^N\8) 40 GOSUB 200 50 PRINT "Length: ",S 60 PRINT "First 130:" 70 FOR I=0 TO 129: PRINT USING "#";S(I);: NEXT 80 PRINT: PRINT "Last 130:" 90 FOR I=S-130 TO S-1: PRINT USING "#";S(I);: NEXT 100 PRINT 110 GOSUB 600 120 PRINT "Reversing...": GOSUB 500:...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Elena
Elena
import extensions;   sealed struct TinyInt : BaseNumber { int value;   int cast() = value;   constructor(int n) { if (n <= 1 || n >= 10) { InvalidArgumentException.raise() };   value := n }   cast t(string s) { value := s.toInt();   ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Euphoria
Euphoria
type My_Type(integer i) return i >= 1 and i <= 10 end type
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#D
D
import std.stdio, std.math, std.numeric, std.algorithm;   struct V3 { double[3] v;   @property V3 normalize() pure nothrow const @nogc { immutable double len = dotProduct(v, v).sqrt; return [v[0] / len, v[1] / len, v[2] / len].V3; }   double dot(in ref V3 y) pure nothrow const @nogc { ...
http://rosettacode.org/wiki/Deconvolution/1D
Deconvolution/1D
The convolution of two functions F {\displaystyle {\mathit {F}}} and H {\displaystyle {\mathit {H}}} of an integer variable is defined as the function G {\displaystyle {\mathit {G}}} satisfying G ( n ) = ∑ m = − ∞ ∞ F ( m ) H ( n − m ) {\displaystyle G(n)=\sum _{m=-\inft...
#Phix
Phix
with javascript_semantics function deconv(sequence g, f) integer lf = length(f), lg = length(g), lh = lg-lf+1 sequence h = repeat(0,lh) for n=1 to lh do atom e = g[n] for i=max(n-lf,0) to n-2 do e -= h[i+1] * f[n-i] end for h[n] = e/f[1] end for return h e...