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/Pseudo-random_numbers/Middle-square_method
Pseudo-random numbers/Middle-square method
Middle-square_method Generator The Method To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i...
#VBA
VBA
Option Explicit Dim seed As Long Sub Main() Dim i As Integer seed = 675248 For i = 1 To 5 Debug.Print Rand Next i End Sub Function Rand() As Variant Dim s As String s = CStr(seed ^ 2) Do While Len(s) <> 12 s = "0" + s Loop seed = Val(Mid(s, 4, 6)) Rand = seed End ...
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method
Pseudo-random numbers/Middle-square method
Middle-square_method Generator The Method To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i...
#Visual_Basic
Visual Basic
Option Explicit Dim seed As Long Sub Main() Dim i As Integer seed = 675248 For i = 1 To 5 Debug.Print Rand Next i End Sub Function Rand() As Variant Dim s As String s = CStr(seed ^ 2) Do While Len(s) <> 12 s = "0" + s Loop seed = Val(Mid(s, 4, 6)) Rand = seed End ...
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method
Pseudo-random numbers/Middle-square method
Middle-square_method Generator The Method To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i...
#Wren
Wren
var random = Fn.new { |seed| ((seed * seed)/1e3).floor % 1e6 }   var seed = 675248 for (i in 1..5) System.print(seed = random.call(seed))
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Pony
Pony
actor Main new create(env: Env) => let a = """env.out.print("actor Main\nnew create(env: Env) =>\nlet a = \"\"\""+a+"\"\"\"\n"+a)""" env.out.print("actor Main\nnew create(env: Env) =>\nlet a = \"\"\""+a+"\"\"\"\n"+a)
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#C.2B.2B
C++
#include <array> #include <iostream>   int64_t mod(int64_t x, int64_t y) { int64_t m = x % y; if (m < 0) { if (y < 0) { return m - y; } else { return m + y; } } return m; }   class RNG { private: // First generator const std::array<int64_t, 3> a1{ ...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Phix
Phix
puts(1,"NB: These are not expected to match the task spec!\n") set_rand(42) for i=1 to 5 do printf(1,"%d\n",rand(-1)) end for set_rand(987654321) sequence s = repeat(0,5) for i=1 to 100000 do s[floor(rnd()*5)+1] += 1 end for ?s
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#JavaScript
JavaScript
(() => { 'use strict';   // main :: IO () const main = () => { const xs = takeWhileGen( x => 2200 >= x, mergeInOrder( powersOfTwo(), fmapGen(x => 5 * x, powersOfTwo()) ) );   return ( console.log(JSON.str...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#J
J
gnuplot --persist -e 'plot"<ijconsole /tmp/pt.ijs"w l'
http://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
Pseudo-random numbers/Splitmix64
Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes s...
#Raku
Raku
class splitmix64 { has $!state;   submethod BUILD ( Int :$seed where * >= 0 = 1 ) { $!state = $seed }   method next-int { my $next = $!state = ($!state + 0x9e3779b97f4a7c15) +& (2⁶⁴ - 1); $next = ($next +^ ($next +> 30)) * 0xbf58476d1ce4e5b9 +& (2⁶⁴ - 1); $next = ($next +^ ($next +> ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#ANSI_Standard_BASIC
ANSI Standard BASIC
100 DECLARE EXTERNAL SUB tri 110 ! 120 PUBLIC NUMERIC U0(3,3), U1(3,3), U2(3,3), all, prim 130 DIM seed(3) 140 MAT READ U0, U1, U2 150 DATA 1, -2, 2, 2, -1, 2, 2, -2, 3 160 DATA 1, 2, 2, 2, 1, 2, 2, 2, 3 170 DATA -1, 2, 2, -2, 1, 2, -2, 2, 3 180 ! 190 MAT READ seed 200 DATA 3, 4, 5 210 FOR power = 1 TO 7 220 LET al...
http://rosettacode.org/wiki/Pseudo-random_numbers/Middle-square_method
Pseudo-random numbers/Middle-square method
Middle-square_method Generator The Method To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number i...
#XPL0
XPL0
real Seed; func Random; [Seed:= Floor(Mod(Seed*Seed/1e3, 1e6)); return fix(Seed); ];   int N; [Seed:= 675248.; for N:= 1 to 5 do [IntOut(0, Random); ChOut(0, ^ )]; ]
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#PowerBASIC
PowerBASIC
FUNCTION PBMAIN () AS LONG REDIM s(1 TO DATACOUNT) AS STRING o$ = READ$(1) d$ = READ$(2) FOR n& = 1 TO DATACOUNT s(n&) = READ$(n&) NEXT OPEN o$ FOR OUTPUT AS 1 FOR n& = 3 TO DATACOUNT - 1 PRINT #1, s(n&) NEXT PRINT #1, FOR n& = 1 TO DATACOUNT PRINT #1, d$ ...
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#D
D
import std.math; import std.stdio;   long mod(long x, long y) { long m = x % y; if (m < 0) { if (y < 0) { return m - y; } else { return m + y; } } return m; }   class RNG { private: // First generator immutable(long []) a1 = [0, 1403580, -810728]; ...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Python
Python
mask64 = (1 << 64) - 1 mask32 = (1 << 32) - 1 CONST = 6364136223846793005     class PCG32():   def __init__(self, seed_state=None, seed_sequence=None): if all(type(x) == int for x in (seed_state, seed_sequence)): self.seed(seed_state, seed_sequence) else: self.state = self.in...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#jq
jq
# Emit a proof that the input is a pythagorean quad, or else false def is_pythagorean_quad: . as $d | (.*.) as $d2 | first( label $continue_a | range(1; $d) | . as $a | (.*.) as $a2 | if 3*$a2 > $d2 then break $continue_a else . end | label $continue_b | range($a; $d) | . as $b | (.*.) as $b2 ...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Julia
Julia
function quadruples(N::Int=2200) r = falses(N) ab = falses(2N ^ 2)   for a in 1:N, b in a:N ab[a ^ 2 + b ^ 2] = true end   s = 3 for c in 1:N s1, s, s2 = s, s + 2, s + 2 for d in c+1:N if ab[s1] r[d] = true end s1 += s2 s2 += 2 ...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Java
Java
import java.awt.*; import java.awt.geom.Path2D; import javax.swing.*;   public class PythagorasTree extends JPanel { final int depthLimit = 7; float hue = 0.15f;   public PythagorasTree() { setPreferredSize(new Dimension(640, 640)); setBackground(Color.white); }   private void drawTr...
http://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
Pseudo-random numbers/Splitmix64
Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes s...
#REXX
REXX
/*REXX program generates pseudo─random numbers using the split mix 64 bit method.*/ numeric digits 200 /*ensure enough decimal digs for mult. */ parse arg n reps pick seed1 seed2 . /*obtain optional arguments from the CL*/ if n=='' | n=="," then n= ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#Arturo
Arturo
triples: new [] loop 1..50 'x [ loop 1..50 'y [ loop (max @[x y])..100 'z [ if 100 > sum @[x y z] [ if (z^2) = add x^2 y^2 -> 'triples ++ @[sort @[x y z]] ] ] ] ] unique 'triples   print ["Found" size triples "pythagorean triples with a...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#PowerShell
PowerShell
$S = '$S = $S.Substring(0,5) + [string][char]39 + $S + [string][char]39 + [string][char]10 + $S.Substring(5)' $S.Substring(0,5) + [string][char]39 + $S + [string][char]39 + [string][char]10 + $S.Substring(5)
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Factor
Factor
USING: arrays kernel math math.order math.statistics math.vectors prettyprint sequences ;   CONSTANT: m1 4294967087 CONSTANT: m2 4294944443   : seed ( n -- seq1 seq2 ) dup 1 m1 between? t assert= 0 0 3array dup ;   : new-state ( seq1 seq2 n -- new-seq ) [ dup ] [ vdot ] [ rem prefix but-last ] tri* ;   : next-s...
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Forth
Forth
6 array (seed) \ holds the seed 6 array (gens) \ holds the generators \ set up constants 0 (gens) 0 th ! \ 1st generator 1403580 (gens) 1 th ! -810728 (gens) 2 th ! 527612 (gens) 3 th ! \ 2n...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Raku
Raku
class PCG32 { has $!state; has $!incr; constant mask32 = 2³² - 1; constant mask64 = 2⁶⁴ - 1; constant const = 6364136223846793005;   submethod BUILD ( Int :$seed = 0x853c49e6748fea9b, # default seed Int :$incr = 0xda3e39cb94b95bdb # default increment ) { $!incr = ...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Kotlin
Kotlin
// version 1.1.3   const val MAX = 2200 const val MAX2 = MAX * MAX - 1   fun main(args: Array<String>) { val found = BooleanArray(MAX + 1) // all false by default val p2 = IntArray(MAX + 1) { it * it } // pre-compute squares   // compute all possible positive values of d * d - c * c and map them back...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#JavaScript
JavaScript
<!DOCTYPE html> <html lang="en">   <head> <meta charset="UTF-8"> <style> canvas { position: absolute; top: 45%; left: 50%; width: 640px; height: 640px; margin: -320px 0 0 -320px; } </style> </head>   <body> <canvas><...
http://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
Pseudo-random numbers/Splitmix64
Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes s...
#Ruby
Ruby
class Splitmix64 MASK64 = (1 << 64) - 1 C1, C2, C3 = 0x9e3779b97f4a7c15, 0xbf58476d1ce4e5b9, 0x94d049bb133111eb   def initialize(seed = 0) = @state = seed & MASK64   def rand_i z = @state = (@state + C1) & MASK64 z = ((z ^ (z >> 30)) * C2) & MASK64 z = ((z ^ (z >> 27)) * C3) & MASK64 (z ^ (z >>...
http://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
Pseudo-random numbers/Splitmix64
Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes s...
#Sidef
Sidef
class Splitmix64(state) {   define ( mask64 = (2**64 - 1) )   method next_int { var n = (state = ((state + 0x9e3779b97f4a7c15) & mask64)) n = ((n ^ (n >> 30)) * 0xbf58476d1ce4e5b9 & mask64) n = ((n ^ (n >> 27)) * 0x94d049bb133111eb & mask64) (n ^ (n >> 31)) & mask64 ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#APL
APL
  ⍝ Determine whether given list of integers has GCD = 1 primitive←∧/1=2∨/⊢ ⍝ Filter list given as right operand by applying predicate given as left operand filter←{⍵⌿⍨⍺⍺ ⍵}   ⍝ Function pytriples finds all triples given a maximum perimeter ∇res←pytriples maxperimeter;sos;sqrt;cartprod;ascending;ab_max;c_max;a_b_pairs;...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Processing
Processing
String p="String p=%c%s%1$c;System.out.printf(p,34,p);";System.out.printf(p,34,p);
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Prolog
Prolog
quine :- listing(quine).
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Go
Go
package main   import ( "fmt" "log" "math" )   var a1 = []int64{0, 1403580, -810728} var a2 = []int64{527612, 0, -1370589}   const m1 = int64((1 << 32) - 209) const m2 = int64((1 << 32) - 22853) const d = m1 + 1   // Python style modulus func mod(x, y int64) int64 { m := x % y if m < 0 { if ...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#REXX
REXX
Numeric Digits 40 N = 6364136223846793005 state = x2d('853c49e6748fea9b',16) inc = x2d('da3e39cb94b95bdb',16) Call seed 42,54 Do zz=1 To 5 res=nextint() Say int2str(res) End Call seed 987654321,1 cnt.=0 Do i=1 To 100000 z=nextfloat() cnt.z=cnt.z+1 End Say '' Say 'The counts for 100,000 repetitions are...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Lua
Lua
-- initialize local N = 2200 local ar = {} for i=1,N do ar[i] = false end   -- process for a=1,N do for b=a,N do if (a % 2 ~= 1) or (b % 2 ~= 1) then local aabb = a * a + b * b for c=b,N do local aabbcc = aabb + c * c local d = math.floor(math.sqrt...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#jq
jq
  # viewBox = <min-x> <min-y> <width> <height> # Input: {svg, minx, miny, maxx, maxy} def svg: "<svg viewBox='\(.minx - 4|floor) \(.miny - 4 |floor) \(6 + .maxx - .minx|ceil) \(6 + .maxy - .miny|ceil)'", " preserveAspectRatio='xMinYmin meet'", " xmlns='http://www.w3.org/2000/svg' >", .svg, "</svg>";  ...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Julia
Julia
using Gadfly using DataFrames   const xarray = zeros(Float64, 80000) const yarray = zeros(Float64, 80000) const arraypos = ones(Int32,1) const maxdepth = zeros(Int32, 1)     function addpoints(x1, y1, x2, y2) xarray[arraypos[1]] = x1 xarray[arraypos[1]+1] = x2 yarray[arraypos[1]] = y1 yarray[arraypos[1...
http://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
Pseudo-random numbers/Splitmix64
Splitmix64 is the default pseudo-random number generator algorithm in Java and is included / available in many other languages. It uses a fairly simple algorithm that, though it is considered to be poor for cryptographic purposes, is very fast to calculate, and is "good enough" for many random number needs. It passes s...
#Wren
Wren
import "/big" for BigInt   var Const1 = BigInt.fromBaseString("9e3779b97f4a7c15", 16) var Const2 = BigInt.fromBaseString("bf58476d1ce4e5b9", 16) var Const3 = BigInt.fromBaseString("94d049bb133111eb", 16) var Mask64 = (BigInt.one << 64) - BigInt.one   class Splitmix64 { construct new(state) { _state = sta...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#AutoHotkey
AutoHotkey
#NoEnv SetBatchLines, -1 #SingleInstance, Force   ; Greatest common divisor, from http://rosettacode.org/wiki/Greatest_common_divisor#AutoHotkey gcd(a,b) { Return b=0 ? Abs(a) : Gcd(b,mod(a,b)) }   count_triples(max) { primitives := 0, triples := 0, m := 2 while m <= (max / 2)**0.5 { n := mod(m, 2) + 1 ,p := 2*...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#PureBasic
PureBasic
s$="s$= : Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)" : Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Haskell
Haskell
import Data.List   randoms :: Int -> [Int] randoms seed = unfoldr go ([seed,0,0],[seed,0,0]) where go (x1,x2) = let x1i = sum (zipWith (*) x1 a1) `mod` m1 x2i = sum (zipWith (*) x2 a2) `mod` m2 in Just $ ((x1i - x2i) `mod` m1, (x1i:init x1, x2i:init x2))   a1 = [0, 1403580, -810728] ...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Ruby
Ruby
class PCG32 MASK64 = (1 << 64) - 1 MASK32 = (1 << 32) - 1 CONST = 6364136223846793005   def seed(seed_state, seed_sequence) @state = 0 @inc = ((seed_sequence << 1) | 1) & MASK64 next_int @state = @state + seed_state next_int end   def next_int old = @state @state = ((old * CONST...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
max = 2200; maxsq = max^2; d = Range[max]^2; Dynamic[{a, b, Length[d]}] Do[ Do[ c = Range[1, Floor[(maxsq - a^2 - b^2)^(1/2)]]; dposs = a^2 + b^2 + c^2; d = Complement[d, dposs] , {b, Floor[(maxsq - a^2)^(1/2)]} ] , {a, Floor[maxsq^(1/2)]} ] Sqrt[d]
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Modula-2
Modula-2
MODULE PythagoreanQuadruples; FROM FormatString IMPORT FormatString; FROM RealMath IMPORT sqrt; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   PROCEDURE WriteInteger(i : INTEGER); VAR buffer : ARRAY[0..16] OF CHAR; BEGIN FormatString("%i", buffer, i); WriteString(buffer) E...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Kotlin
Kotlin
// version 1.1.2   import java.awt.* import java.awt.geom.Path2D import javax.swing.*   class PythagorasTree : JPanel() { val depthLimit = 7 val hue = 0.15f   init { preferredSize = Dimension(640, 640) background = Color.white }   private fun drawTree(g: Graphics2D, x1: Float, y1: Fl...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#AWK
AWK
  # syntax: GAWK -f PYTHAGOREAN_TRIPLES.AWK # converted from Go BEGIN { printf("%5s %11s %11s %11s %s\n","limit","limit","triples","primitives","seconds") for (max_peri=10; max_peri<=1E9; max_peri*=10) { t = systime() prim = 0 total = 0 new_tri(3,4,5) printf("10^%-2d %11d %11d %11d...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Python
Python
w = "print('w = ' + chr(34) + w + chr(34) + chr(10) + w)" print('w = ' + chr(34) + w + chr(34) + chr(10) + w)
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Java
Java
public class App { private static long mod(long x, long y) { long m = x % y; if (m < 0) { if (y < 0) { return m - y; } else { return m + y; } } return m; }   public static class RNG { // first generat...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Scheme
Scheme
(import (scheme small) (srfi 33))   (define PCG-DEFAULT-MULTIPLIER 6364136223846793005) (define MASK64 (- (arithmetic-shift 1 64) 1)) (define MASK32 (- (arithmetic-shift 1 32) 1))   (define-record-type <pcg32-random> (make-pcg32-random-record) pcg32? (state pcg32-state pcg32-state!) (inc pcg32-inc pcg32-inc!)) ...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Nim
Nim
import math   const N = 2_200   template isOdd(n: int): bool = (n and 1) != 0   var r = newSeq[bool](N + 1)   for a in 1..N: for b in a..N: if a.isOdd and b.isOdd: continue let aabb = a * a + b * b for c in b..N: let aabbcc = aabb + c * c d = sqrt(aabbcc.float).int if aabbcc == d * d and...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Pascal
Pascal
program pythQuad; //find phythagorean Quadrupel up to a,b,c,d <= 2200 //a^2 + b^2 +c^2 = d^2 //find all values of d which are not possible //brute force //split in two procedure to reduce register pressure for CPU32   const MaxFactor =2200; limit = MaxFactor*MaxFactor; type tIdx = NativeUint; tSum = NativeUint;...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#M2000_Interpreter
M2000 Interpreter
  MODULE Pythagoras_tree { CLS 5, 0 ' MAGENTA, NO SPLIT SCREEN PEN 14 ' YELLOW \\ code from zkl/Free Basic LET w = scale.x, h = w * 11 div 16 LET w2 = w div 2, diff = w div 12 LET TreeOrder = 6 pythagoras_tree(w2 - diff, h -10, w2 + diff, h -10, 0)   SUB pythagoras_tree(x1, y1, x2, y2, depth)   IF depth...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
n = 7; colors = Blend[{Orange, Yellow, Green}, #] & /@ Subdivide[n - 1]; ClearAll[NextConfigs, NewConfig] NewConfig[b1_List, b2_List] := Module[{diff, perp}, diff = b2 - b1; perp = Cross[b2 - b1]; <|"quad" -> Polygon[{b1, b2, b2 + perp, b1 + perp}], "triang" -> Polygon[{b1 + 1.5 perp + diff/2, b1 + perp, b2 + per...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#BBC_BASIC
BBC BASIC
DIM U0%(2,2), U1%(2,2), U2%(2,2), seed%(2) U0%() = 1, -2, 2, 2, -1, 2, 2, -2, 3 U1%() = 1, 2, 2, 2, 1, 2, 2, 2, 3 U2%() = -1, 2, 2, -2, 1, 2, -2, 2, 3   seed%() = 3, 4, 5 FOR power% = 1 TO 7 all% = 0 : prim% = 0 PROCtri(seed%(), 10^power%, all%, prim%) ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Quackery
Quackery
[ ' [ ' unbuild dup 4 split rot space rot 3 times join echo$ ] unbuild dup 4 split rot space rot 3 times join echo$ ]
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#R
R
(function(){x<-intToUtf8(34);s<-"(function(){x<-intToUtf8(34);s<-%s%s%s;cat(sprintf(s,x,s,x))})()";cat(sprintf(s,x,s,x))})()
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Julia
Julia
const a1 = [0, 1403580, -810728] const m1 = 2^32 - 209 const a2 = [527612, 0, -1370589] const m2 = 2^32 - 22853 const d = m1 + 1   mutable struct MRG32k3a x1::Tuple{Int64, Int64, Int64} x2::Tuple{Int64, Int64, Int64} MRG32k3a() = new((0, 0, 0), (0, 0, 0)) MRG32k3a(seed_state) = new((seed_state, 0, 0), (...
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Kotlin
Kotlin
import kotlin.math.floor   fun mod(x: Long, y: Long): Long { val m = x % y return if (m < 0) { if (y < 0) { m - y } else { m + y } } else m }   class RNG { // first generator private val a1 = arrayOf(0L, 1403580L, -810728L) private val m1 = (1L shl...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Sidef
Sidef
class PCG32(seed, incr) {   has state   define ( mask32 = (2**32 - 1), mask64 = (2**64 - 1), N = 6364136223846793005, )   method init { seed := 1 incr := 2 incr = (((incr << 1) | 1) & mask64) state = (((incr + seed)*N + incr) & mask64) } ...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Perl
Perl
my $N = 2200; push @sq, $_**2 for 0 .. $N; my @not = (0) x $N; @not[0] = 1;     for my $d (1 .. $N) { my $last = 0; for my $a (reverse ceiling($d/3) .. $d) { for my $b (1 .. ceiling($a/2)) { my $ab = $sq[$a] + $sq[$b]; last if $ab > $sq[$d]; my $x = sqrt($sq[$d] - $ab...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Nim
Nim
import imageman   const Width = 1920 Height = 1080 MaxDepth = 10 Color = ColorRGBU([byte 0, 255, 0])     proc drawTree(img: var Image; x1, y1, x2, y2: int; depth: Natural) =   if depth == 0: return   let dx = x2 - x1 dy = y1 - y2 x3 = x2 - dy y3 = y2 - dx x4 = x1 - dy y4 = y1 - dx ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#Bracmat
Bracmat
(pythagoreanTriples= total prim max-peri U . (.(1,-2,2) (2,-1,2) (2,-2,3)) (.(1,2,2) (2,1,2) (2,2,3)) (.(-1,2,2) (-2,1,2) (-2,2,3))  : ?U & ( new-tri = i t p Urows Urow Ucols , a b c loop A B C .  !arg:(,?a,?b,?c) & !a+!b+!c:~>!max-peri:?p & 1+!p...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Racket
Racket
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Nim
Nim
import algorithm, math, sequtils, strutils, tables   const # First generator. a1 = [int64 0, 1403580, -810728] m1: int64 = 2^32 - 209 # Second generator. a2 = [int64 527612, 0, -1370589] m2: int64 = 2^32 - 22853   d = m1 + 1   type MRG32k3a = object x1: array[3, int64] # List of three last values of g...
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Pari.2FGP
Pari/GP
a1 = [0, 1403580, -810728]; m1 = 2^32-209; a2 = [527612, 0, -1370589]; m2 = 2^32-22853; d = m1+1; seed(s)=x1=x2=[s,0,0]; next_int()= { my(x1i=a1*x1~%m1, x2i=a2*x2~%m2); x1 = [x1i, x1[1], x1[2]]; x2 = [x2i, x2[1], x2[2]]; (x1i-x2i)%m1 + 1; } next_float()=next_int()/d;   seed(1234567); vector(5,i,next_int()) seed...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Standard_ML
Standard ML
type pcg32 = LargeWord.word * LargeWord.word   local infix 5 >> val op >> = LargeWord.>> and m = 0w6364136223846793005 : LargeWord.word and rotate32 = fn a as (x, n) => Word32.orb (Word32.>> a, Word32.<< (x, Word.andb (~ n, 0w31))) in fun pcg32Init (seed, seq) : pcg32 = let val inc = LargeWord.<...
http://rosettacode.org/wiki/Pseudo-random_numbers/PCG32
Pseudo-random numbers/PCG32
Some definitions to help in the explanation Floor operation https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Greatest integer less than or equal to a real number. Bitwise Logical shift operators (c-inspired) https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts Binary bits of value shifted left or ri...
#Wren
Wren
import "/big" for BigInt   var Const = BigInt.new("6364136223846793005") var Mask64 = (BigInt.one << 64) - BigInt.one var Mask32 = (BigInt.one << 32) - BigInt.one   class Pcg32 { construct new() { _state = BigInt.fromBaseString("853c49e6748fea9b", 16) _inc = BigInt.fromBaseString("da3e39cb94b95...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Phix
Phix
with javascript_semantics constant N = 2200, N2 = N*N*2 sequence found = repeat(false,N), squares = repeat(false,N2) -- first mark all numbers that can be the sum of two squares for a=1 to N do integer a2 = a*a for b=a to N do squares[a2+b*b] = true end for end for -- now find all ...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Ol
Ol
  (import (lib gl)) (import (OpenGL version-1-0)) (gl:set-window-size 700 600) (gl:set-window-title "http://rosettacode.org/wiki/Pythagoras_tree")   (glLineWidth 2) (gl:set-renderer (lambda (mouse) (glClear GL_COLOR_BUFFER_BIT) (glLoadIdentity) (glOrtho -3 4 -1 5 0 1)   (let loop ((a '(0 . 0)) (b '(1 . 0)) ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#C
C
#include <stdio.h> #include <stdlib.h>   typedef unsigned long long xint; typedef unsigned long ulong;   inline ulong gcd(ulong m, ulong n) { ulong t; while (n) { t = n; n = m % n; m = t; } return m; }   int main() { ulong a, b, c, pytha = 0, prim = 0, max_p = 100; xint aa, bb, cc;   for (a = 1;...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Raku
Raku
my &f = {say $^s, $^s.raku;}; f "my \&f = \{say \$^s, \$^s.raku;}; f "  
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Perl
Perl
use strict; use warnings; use feature 'say';   package MRG32k3a {   use constant { m1 => 2**32 - 209, m2 => 2**32 - 22853 };   use Const::Fast; const my @a1 => < 0 1403580 -810728>; const my @a2 => <527612 0 -1370589>;   sub new { my ($class,undef,$seed) = @_; ...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#PicoLisp
PicoLisp
(de quadruples (N) (let (AB NIL S 3 R) (for A N (for (B A (>= N B) (inc B)) (idx 'AB (+ (* A A) (* B B)) T ) ) ) (for C N (let (S1 S S2) (inc 'S 2) (setq S2 S) (for (D (+ C 1) (>= N D) (inc D...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#PureBasic
PureBasic
OpenConsole() limite.i = 2200 s.i = 3 Dim l.i(limite) Dim ladd.i(limite * limite * 2)   For x.i = 1 To limite x2.i = x * x For y = x To limite ladd(x2 + y * y) = 1 Next y Next x   For x.i = 1 To limite s1.i = s s.i + 2 s2.i = s For y = x +1 To limite If ladd(s1) = 1 l(y) = 1 EndIf s1...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#PARI.2FGP
PARI/GP
\\ Pythagoras Tree (w/recursion) \\ 4/11/16 aev plotline(x1,y1,x2,y2)={plotmove(0, x1,y1);plotrline(0,x2-x1,y2-y1);}   pythtree(ax,ay,bx,by,d=0)={ my(dx,dy,x3,y3,x4,y4,x5,y5); if(d>10, return()); dx=bx-ax; dy=ay-by; x3=bx-dy; y3=by-dx; x4=ax-dy; y4=ay-dx; x5=x4+(dx-dy)\2; y5=y4-(dx+dy)\2; plotline(ax,ay,bx,by); plotlin...
http://rosettacode.org/wiki/QR_decomposition
QR decomposition
Any rectangular m × n {\displaystyle m\times n} matrix A {\displaystyle {\mathit {A}}} can be decomposed to a product of an orthogonal matrix Q {\displaystyle {\mathit {Q}}} and an upper (right) triangular matrix R {\displaystyle {\mathit {R}}} , as described in QR decompositi...
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays; with Ada.Numerics.Generic_Elementary_Functions; procedure QR is   procedure Show (mat : Real_Matrix) is package FIO is new Ada.Text_IO.Float_IO (Float); begin for row in mat'Range (1) loop for co...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#C.2B.2B
C++
#include <cmath> #include <iostream> #include <numeric> #include <tuple> #include <vector>   using namespace std;   auto CountTriplets(unsigned long long maxPerimeter) { unsigned long long totalCount = 0; unsigned long long primitveCount = 0; auto max_M = (unsigned long long)sqrt(maxPerimeter/2) + 1; fo...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#REBOL
REBOL
rebol [] q: [print ["rebol [] q:" mold q "do q"]] do q
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Phix
Phix
with javascript_semantics constant -- First generator a1 = {0, 1403580, -810728}, m1 = power(2,32) - 209, -- Second Generator a2 = {527612, 0, -1370589}, m2 = power(2,32) - 22853, d = m1 + 1 sequence x1 = {0, 0, 0}, /* list of three last values of gen #1 */ x2 = {0, 0, 0} /* l...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Python
Python
def quad(top=2200): r = [False] * top ab = [False] * (top * 2)**2 for a in range(1, top): for b in range(a, top): ab[a * a + b * b] = True s = 3 for c in range(1, top): s1, s, s2 = s, s + 2, s + 2 for d in range(c + 1, top): if ab[s1]: ...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Perl
Perl
use Imager;   sub tree { my ($img, $x1, $y1, $x2, $y2, $depth) = @_;   return () if $depth <= 0;   my $dx = ($x2 - $x1); my $dy = ($y1 - $y2);   my $x3 = ($x2 - $dy); my $y3 = ($y2 - $dx); my $x4 = ($x1 - $dy); my $y4 = ($y1 - $dx); my $x5 = ($x4 + 0.5 * ($dx - $dy)); my $y5 = ($...
http://rosettacode.org/wiki/QR_decomposition
QR decomposition
Any rectangular m × n {\displaystyle m\times n} matrix A {\displaystyle {\mathit {A}}} can be decomposed to a product of an orthogonal matrix Q {\displaystyle {\mathit {Q}}} and an upper (right) triangular matrix R {\displaystyle {\mathit {R}}} , as described in QR decompositi...
#Axiom
Axiom
)abbrev package TESTP TestPackage TestPackage(R:Join(Field,RadicalCategory)): with unitVector: NonNegativeInteger -> Vector(R) "/": (Vector(R),R) -> Vector(R) "^": (Vector(R),NonNegativeInteger) -> Vector(R) solveUpperTriangular: (Matrix(R),Vector(R)) -> Vector(R) signValue: R -> R householder: ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#C.23
C#
using System;   namespace RosettaCode.CSharp { class Program { static void Count_New_Triangle(ulong A, ulong B, ulong C, ulong Max_Perimeter, ref ulong Total_Cnt, ref ulong Primitive_Cnt) { ulong Perimeter = A + B + C;   if (Perimeter <= Max_Perimeter) { ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#REXX
REXX
/*REXX program outputs its own 1─line source.*/ say sourceline(1)
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Ring
Ring
v = "see substr(`v = ` + char(34) + `@` + char(34) + nl + `@` ,`@`,v)" see substr(`v = ` + char(34) + `@` + char(34) + nl + `@` ,`@`,v)
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Python
Python
# Constants a1 = [0, 1403580, -810728] m1 = 2**32 - 209 # a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 # d = m1 + 1   class MRG32k3a():   def __init__(self, seed_state=123): self.seed(seed_state)   def seed(self, seed_state): assert 0 <seed_state < d, f"Out of Range 0 x < {d}" self.x1 =...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#R
R
squares <- d <- seq_len(2200)^2 aAndb <- outer(squares, squares, '+') aAndb <- aAndb[upper.tri(aAndb, diag = TRUE)] sapply(squares, function(c) d <<- setdiff(d, aAndb + c)) print(sqrt(d))
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Racket
Racket
#lang racket   (require data/bit-vector)   (define (quadruples top) (define top+1 (add1 top)) (define 1..top (in-range 1 top+1)) (define r (make-bit-vector top+1)) (define ab (make-bit-vector (add1 (sqr (* top 2))))) (for* ((a 1..top) (b (in-range a top+1))) (bit-vector-set! ab (+ (sqr a) (sqr b)) #t))   (f...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Phix
Phix
-- demo\rosetta\PythagorasTree.exw with javascript_semantics include pGUI.e Ihandle dlg, canvas cdCanvas cddbuffer, cdcanvas enum FILL, BORDER procedure drawTree(atom x1, y1, x2, y2, integer depth, dd) atom dx = x2 - x1, dy = y1 - y2, x3 = x2 - dy, y3 = y2 - dx, x4 = x1 - dy, ...
http://rosettacode.org/wiki/QR_decomposition
QR decomposition
Any rectangular m × n {\displaystyle m\times n} matrix A {\displaystyle {\mathit {A}}} can be decomposed to a product of an orthogonal matrix Q {\displaystyle {\mathit {Q}}} and an upper (right) triangular matrix R {\displaystyle {\mathit {R}}} , as described in QR decompositi...
#BBC_BASIC
BBC BASIC
*FLOAT 64 @% = &2040A INSTALL @lib$+"ARRAYLIB"   REM Test matrix for QR decomposition: DIM A(2,2) A() = 12, -51, 4, \ \ 6, 167, -68, \ \ -4, 24, -41   REM Do the QR decomposition: DIM Q(2,2), R(2,2) PROCqrdecompose(A(), Q(), R()) PRINT ...
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#Clojure
Clojure
(defn gcd [a b] (if (zero? b) a (recur b (mod a b))))   (defn pyth [peri] (for [m (range 2 (Math/sqrt (/ peri 2))) n (range (inc (mod m 2)) m 2) ; n<m, opposite polarity  :let [p (* 2 m (+ m n))] ; = a+b+c for this (m,n)  :while (<= p peri)  :when (= 1 (gcd m n))  :let [m2 (* ...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Ruby
Ruby
_="_=%p;puts _%%_";puts _%_
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Rust
Rust
fn main() { let x = "fn main() {\n let x = "; let y = "print!(\"{}{:?};\n let y = {:?};\n {}\", x, x, y, y)\n}\n"; print!("{}{:?}; let y = {:?}; {}", x, x, y, y) }
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Raku
Raku
class MRG32k3a { has @!x1; has @!x2;   constant a1 = 0, 1403580, -810728; constant a2 = 527612, 0, -1370589; constant m1 = 2**32 - 209; constant m2 = 2**32 - 22853;   submethod BUILD ( Int :$seed where 0 < * <= m1 = 1 ) { @!x1 = @!x2 = $seed, 0, 0 }   method next-int { @!x1.unshi...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#Raku
Raku
my \N = 2200; my @sq = (0 .. N)»²; my @not = False xx N; @not[0] = True;   (1 .. N).race.map: -> $d { my $last = 0; for $d ... ($d/3).ceiling -> $a { for 1 .. ($a/2).ceiling -> $b { last if (my $ab = @sq[$a] + @sq[$b]) > @sq[$d]; if (@sq[$d] - $ab).sqrt.narrow ~~ Int { ...
http://rosettacode.org/wiki/Pythagoras_tree
Pythagoras tree
The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem. Task Construct a Pythagoras tree of order 7 using only vectors (no rotation or ...
#Processing
Processing
void tree(float x1, float y1, float x2, float y2, int depth) {   if (depth <= 0) { return; }   float dx = (x2 - x1); float dy = (y1 - y2);   float x3 = (x2 - dy); float y3 = (y2 - dx); float x4 = (x1 - dy); float y4 = (y1 - dx); float x5 = (x4 + 0.5*(dx - dy)); float y5 = (y4 - 0.5*(dx + dy));  ...
http://rosettacode.org/wiki/QR_decomposition
QR decomposition
Any rectangular m × n {\displaystyle m\times n} matrix A {\displaystyle {\mathit {A}}} can be decomposed to a product of an orthogonal matrix Q {\displaystyle {\mathit {Q}}} and an upper (right) triangular matrix R {\displaystyle {\mathit {R}}} , as described in QR decompositi...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h>   typedef struct { int m, n; double ** v; } mat_t, *mat;   mat matrix_new(int m, int n) { mat x = malloc(sizeof(mat_t)); x->v = malloc(sizeof(double*) * m); x->v[0] = calloc(sizeof(double), m * n); for (int i = 0; i < m; i++) x->v[i] = x->v[0] + n * i; x...
http://rosettacode.org/wiki/Program_name
Program name
The task is to programmatically obtain the name used to invoke the program. (For example determine whether the user ran "python hello.py", or "python hellocaller.py", a program importing the code from "hello.py".) Sometimes a multiline shebang is necessary in order to provide the script name to a language's internal A...
#11l
11l
:start: print(‘Program: ’:argv[0])
http://rosettacode.org/wiki/Pythagorean_triples
Pythagorean triples
A Pythagorean triple is defined as three positive integers ( a , b , c ) {\displaystyle (a,b,c)} where a < b < c {\displaystyle a<b<c} , and a 2 + b 2 = c 2 . {\displaystyle a^{2}+b^{2}=c^{2}.} They are called primitive triples if a , b , c {\displaystyle a,b,c} are co-prime,...
#CoffeeScript
CoffeeScript
  gcd = (x, y) -> return x if y == 0 gcd(y, x % y)   # m,n generate primitive Pythag triples # # preconditions: # m, n are integers of different parity # m > n # gcd(m,n) == 1 (coprime) # # m, n generate: [m*m - n*n, 2*m*n, m*m + n*n] # perimeter is 2*m*m + 2*m*n = 2 * m * (m+n) count_triples = (max_perim) ->...
http://rosettacode.org/wiki/Quine
Quine
A quine is a self-referential program that can, without any external access, output its own source. A   quine   (named after Willard Van Orman Quine)   is also known as:   self-reproducing automata   (1972)   self-replicating program         or   self-replicating computer program   self-reproducing program      ...
#Scala
Scala
val q = "\"" * 3 val c = """val q = "\"" * 3 val c = %s%s%s println(c format (q, c, q)) """ println(c format (q, c, q))
http://rosettacode.org/wiki/Pseudo-random_numbers/Combined_recursive_generator_MRG32k3a
Pseudo-random numbers/Combined recursive generator MRG32k3a
MRG32k3a Combined recursive generator (pseudo-code) /* Constants */ /* First generator */ a1 = [0, 1403580, -810728] m1 = 2**32 - 209 /* Second Generator */ a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a x1 = [0, 0, 0] /* list of three last values of...
#Ruby
Ruby
def mod(x, y) m = x % y if m < 0 then if y < 0 then return m - y else return m + y end end return m end   # Constants # First generator A1 = [0, 1403580, -810728] A1.freeze M1 = (1 << 32) - 209 # Second generator A2 = [527612, 0, -1370589] A2.freeze M2 = (...
http://rosettacode.org/wiki/Pythagorean_quadruples
Pythagorean quadruples
One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):   a2   +   b2   +   c2     =     d2 An example:   22   +   32   +   62     =     72 which is:   4    +   9    +   36     =     49 Task For positive integers up   2,200   (inclusive),   for all values of   ...
#REXX
REXX
/*REXX pgm computes/shows (integers), D that aren't possible for: a² + b² + c² = d² */ parse arg hi . /*obtain optional argument from the CL.*/ if hi=='' | hi=="," then hi=2200; high= 3 * hi /*Not specified? Then use the default.*/ @.=. ...