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/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 ...
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window import "./polygon" for Polygon   var DepthLimit = 7 var Hue = 0.15   class PythagorasTree { construct new(width, height) { Window.title = "Pythagoras Tree" Window.resize(width, height) Canvas.resize(width, height) }   init(...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Batch_File
Batch File
if condition exit
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#BBC_BASIC
BBC BASIC
IF condition% THEN QUIT
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...
#Java
Java
import Jama.Matrix; import Jama.QRDecomposition;   public class Decompose { public static void main(String[] args) { var matrix = new Matrix(new double[][] { {12, -51, 4}, { 6, 167, -68}, {-4, 24, -41}, });   var qr = new QRDecomposition(matrix); ...
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...
#D
D
#!/usr/bin/env rdmd   import std.stdio;   void main(in string[] args) { writeln("Program: ", args[0]); }
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...
#Dart
Dart
#!/usr/bin/env dart   main() { var program = new Options().script; print("Program: ${program}"); }
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#C.2B.2B
C++
#include <gmpxx.h> #include <primesieve.hpp>   #include <cstdint> #include <iomanip> #include <iostream>   size_t digits(const mpz_class& n) { return n.get_str().length(); }   mpz_class primorial(unsigned int n) { mpz_class p; mpz_primorial_ui(p.get_mpz_t(), n); return p; }   int main() { uint64_t index...
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,...
#F.23
F#
let isqrt n = let rec iter t = let d = n - t*t if (0 <= d) && (d < t+t+1) // t*t <= n < (t+1)*(t+1) then t else iter ((t+(n/t))/2) iter 1   let rec gcd a b = let t = a % b if t = 0 then b else gcd b t   let coprime a b = gcd a b = 1   let num_to ms = let mutable ctr = 0 l...
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      ...
#VBA
VBA
Public Sub quine() quote = Chr(34) comma = Chr(44) cont = Chr(32) & Chr(95) n = Array( _ "Public Sub quine()", _ " quote = Chr(34)", _ " comma = Chr(44)", _ " cont = Chr(32) & Chr(95)", _ " n = Array( _", _ " For i = 0 To 4", _ " Debug.Print n(i)", _ " Next i", _ " For i = 0 ...
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 ...
#Yabasic
Yabasic
Sub pythagoras_tree(x1, y1, x2, y2, depth) local dx, dy, x3, y3, x4, y4, x5, y5   If depth > limit Return   dx = x2 - x1 : dy = y1 - y2 x3 = x2 - dy : y3 = y2 - dx x4 = x1 - dy : y4 = y1 - dx x5 = x4 + (dx - dy) / 2 y5 = y4 - (dx + dy) / 2 //draw the box color 255 - depth * 20, 255, ...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Befunge
Befunge
_@
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Bracmat
Bracmat
#include <stdlib.h> /* More "natural" way of ending the program: finish all work and return from main() */ int main(int argc, char **argv) { /* work work work */ ... return 0; /* the return value is the exit code. see below */ }   if(problem){ exit(exit_code); /* On unix, exit code 0 indicates success,...
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...
#Julia
Julia
Q, R = qr([12 -51 4; 6 167 -68; -4 24 -41])
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...
#Delphi
Delphi
program ProgramName;   {$APPTYPE CONSOLE}   begin Writeln('Program name: ' + ParamStr(0)); Writeln('Command line: ' + CmdLine); end.
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...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
!print( "Name of this file: " get-from !args 0 )
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Clojure
Clojure
(ns example (:gen-class))   ; Generate Prime Numbers (Implementation from RosettaCode--link above) (defn primes-hashmap "Infinite sequence of primes using an incremental Sieve or Eratosthenes with a Hashmap" [] (letfn [(nxtoddprm [c q bsprms cmpsts] (if (>= c q) ;; only ever equal ; Up...
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,...
#Factor
Factor
USING: accessors arrays formatting kernel literals math math.functions math.matrices math.ranges sequences ; IN: rosettacode.pyth   CONSTANT: T1 { { 1 2 2 } { -2 -1 -2 } { 2 2 3 } } CONSTANT: T2 { { 1 2 2 } { 2 1 2 } { 2 2 3 } } CONSTANT: T3 { { -1 -2 -2 } { 2 1 2 } { 2 2 3 } }  ...
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      ...
#Verbexx
Verbexx
@VAR s = «@SAY (@FORMAT fmt:"@VAR s = %c%s%c;" 0x00AB s 0x00BB) s no_nl:;»; @SAY (@FORMAT fmt:"@VAR s = %c%s%c;" 0x00AB s 0x00BB) s no_nl:;
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 ...
#zkl
zkl
fcn pythagorasTree{ bitmap:=PPM(640,640,0xFF|FF|FF); // White background   fcn(bitmap, ax,ay, bx,by, depth=0){ if(depth>10) return(); dx,dy:=bx-ax, ay-by; x3,y3:=bx-dy, by-dx; x4,y4:=ax-dy, ay-dx; x5,y5:=x4 + (dx - dy)/2, y4 - (dx + dy)/2; bitmap.cross(x3,y3);bitmap.cross(x4,y...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#C
C
#include <stdlib.h> /* More "natural" way of ending the program: finish all work and return from main() */ int main(int argc, char **argv) { /* work work work */ ... return 0; /* the return value is the exit code. see below */ }   if(problem){ exit(exit_code); /* On unix, exit code 0 indicates success,...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#C.23
C#
if (problem) { Environment.Exit(1); }
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...
#Maple
Maple
with(LinearAlgebra): A:=<12,-51,4;6,167,-68;-4,24,-41>: Q,R:=QRDecomposition(A): Q; R;
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...
#EchoLisp
EchoLisp
  (js-eval "window.location.href") → "http://www.echolalie.org/echolisp/"  
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...
#Elena
Elena
import extensions;   public program() { console.printLine(program_arguments.asEnumerable()); // the whole command line   console.printLine(program_arguments[0]); // the program name }
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#CLU
CLU
% This program uses the 'bigint' cluster from % the 'misc.lib' included with PCLU.   isqrt = proc (s: int) returns (int) x0: int := s/2 if x0=0 then return(s) end x1: int := (x0 + s/x0)/2 while x1 < x0 do x0 := x1 x1 := (x0 + s/x0)/2 end return(x0) end isqrt   sieve = proc (n: in...
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Common_Lisp
Common Lisp
  (defun primorial-number-length (n w) (values (primorial-number n) (primorial-length w)))   (defun primorial-number (n) (loop for a below n collect (primorial a)))   (defun primorial-length (w) (loop for a in w collect (length (write-to-string (primorial a)))))   (defun primorial (n &optional (m 1) (k -1) (z 1) ...
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,...
#Forth
Forth
      \ Two methods to create Pythagorean Triples \ this code has been tested using Win32Forth and gforth   : pythag_fibo ( f1 f0 -- ) \ Create Pythagorean Triples from 4 element Fibonacci series \ this is called with the first two members of a 4 element Fibonacci series \ Price and Burkhart have two goo...
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      ...
#VHDL
VHDL
LIBRARY ieee; USE std.TEXTIO.all; entity quine is end entity quine; architecture beh of quine is type str_array is array(1 to 20) of string(1 to 80); ...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#C.2B.2B
C++
#include <cstdlib>   void problem_occured() { std::exit(EXIT_FAILURE); }
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Clojure
Clojure
(if problem (. System exit integerErrorCode)) ;conventionally, error code 0 is the code for "OK", ; while anything else is an actual problem ;optionally: (-> Runtime (. getRuntime) (. exit integerErrorCode)) }
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
{q,r}=QRDecomposition[{{12, -51, 4}, {6, 167, -68}, {-4, 24, -41}}]; q//MatrixForm   -> 6/7 3/7 -(2/7) -69/175 158/175 6/35 -58/175 6/175 -33/35   r//MatrixForm -> 14 21 -14 0 175 -70 0 0 35
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...
#Emacs_Lisp
Emacs Lisp
:;exec emacs -batch -l $0 -f main $*   ;;; Shebang from John Swaby ;;; http://www.emacswiki.org/emacs/EmacsScripts   (defun main () (let ((program (nth 2 command-line-args))) (message "Program: %s" program)))
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...
#Erlang
Erlang
%% Compile %% %% erlc scriptname.erl %% %% Run %% %% erl -noshell -s scriptname   -module(scriptname). -export([start/0]).   start() -> Program = ?FILE, io:format("Program: ~s~n", [Program]), init:stop().
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#D
D
  import std.stdio; import std.format; import std.bigint; import std.math; import std.algorithm;     int sieveLimit = 1300_000;   bool[] notPrime;   void main() { // initialize sieve(sieveLimit);   // output 1 foreach (i; 0..10) writefln("primorial(%d): %d", i, primorial(i));   // output 2 foreach (i; ...
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,...
#Fortran
Fortran
module triples implicit none   integer :: max_peri, prim, total integer :: u(9,3) = reshape((/ 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 /), & (/ 9, 3 /))   co...
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      ...
#Visual_Basic_.NET
Visual Basic .NET
Module Program Sub Main() Dim s = " Module Program Sub Main() Dim s = {0}{1}{0} Console.WriteLine(s, ChrW(34), s) End Sub End Module" Console.WriteLine(s, ChrW(34), s) End Sub End Module
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#COBOL
COBOL
IF problem STOP RUN END-IF
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Common_Lisp
Common Lisp
(defun terminate (status) #+sbcl ( sb-ext:quit :unix-status status) ; SBCL #+ccl ( ccl:quit status) ; Clozure CL #+clisp ( ext:quit status) ; GNU CLISP #+cmu ( unix:unix-exit status) ...
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...
#MATLAB_.2F_Octave
MATLAB / Octave
A = [12 -51 4 6 167 -68 -4 24 -41]; [Q,R]=qr(A)
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...
#Euphoria
Euphoria
constant cmd = command_line() puts(1,cmd[2])
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...
#F.23
F#
#light (* exec fsharpi --exec $0 --quiet *)   let scriptname = let args = System.Environment.GetCommandLineArgs()   let arg0 = args.[0]   if arg0.Contains("fsi") then let arg1 = args.[1] if arg1 = "--exec" then args.[2] else arg1 else arg0   let m...
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Delphi
Delphi
  defmodule SieveofEratosthenes do def init(lim) do find_primes(2,lim,(2..lim)) end   def find_primes(count,lim,nums) when (count * count) > lim do nums end   def find_primes(count,lim,nums) when (count * count) <= lim do find_primes(count+1,lim,Enum.reject(nums,&(rem(&1,count) == 0 and &1 > count...
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Elixir
Elixir
  defmodule SieveofEratosthenes do def init(lim) do find_primes(2,lim,(2..lim)) end   def find_primes(count,lim,nums) when (count * count) > lim do nums end   def find_primes(count,lim,nums) when (count * count) <= lim do find_primes(count+1,lim,Enum.reject(nums,&(rem(&1,count) == 0 and &1 > count...
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,...
#FreeBASIC
FreeBASIC
' version 30-05-2016 ' compile with: fbc -s console   ' primitive pythagoras triples ' a = m^2 - n^2, b = 2mn, c = m^2 + n^2 ' m, n are positive integers and m > n ' m - n = odd and GCD(m, n) = 1 ' p = a + b + c   ' max m for give perimeter ' p = m^2 - n^2 + 2mn + m^2 + n^2 ' p = 2mn + m^2 + m^2 + n^2 - n^2 = 2mn + 2m^...
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      ...
#WDTE
WDTE
let str => import 'strings'; let v => "let str => import 'strings';\nlet v => {q};\nstr.format v v -- io.writeln io.stdout;"; str.format v v -- io.writeln io.stdout;
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Computer.2Fzero_Assembly
Computer/zero Assembly
import core.stdc.stdio, core.stdc.stdlib;   extern(C) void foo() nothrow { "foo at exit".puts; }   extern(C) void bar() nothrow { "bar at exit".puts; }   extern(C) void spam() nothrow { "spam at exit".puts; }   int baz(in int x) pure nothrow in { assert(x != 0); } body { if (x < 0) return 10...
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...
#Maxima
Maxima
load(lapack)$ /* This may hang up in wxMaxima, if this happens, use xMaxima or plain Maxima in a terminal */   a: matrix([12, -51, 4], [ 6, 167, -68], [-4, 24, -41])$   [q, r]: dgeqrf(a)$   mat_norm(q . r - a, 1); 4.2632564145606011E-14   /* Note: the lapack package is a lisp translation of the...
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...
#Factor
Factor
#! /usr/bin/env factor   USING: namespaces io command-line ; IN: scriptname   : main ( -- ) script get print ;   MAIN: main
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...
#Forth
Forth
0 arg type cr \ gforth or gforth-fast, for example 1 arg type cr \ name of script
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#F.23
F#
  // Primorial Numbers. Nigel Galloway: August 3rd., 2021 primes32()|>Seq.scan((*)) 1|>Seq.take 10|>Seq.iter(printf "%d "); printfn "\n" [10;100;1000;10000;100000]|>List.iter(fun n->printfn "%d" ((int)(System.Numerics.BigInteger.Log10 (Seq.item n (primesI()|>Seq.scan((*)) 1I)))+1))  
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,...
#Go
Go
package main   import "fmt"   var total, prim, maxPeri int64   func newTri(s0, s1, s2 int64) { if p := s0 + s1 + s2; p <= maxPeri { prim++ total += maxPeri / p newTri(+1*s0-2*s1+2*s2, +2*s0-1*s1+2*s2, +2*s0-2*s1+3*s2) newTri(+1*s0+2*s1+2*s2, +2*s0+1*s1+2*s2, +2*s0+2*s1+3*s2) ...
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      ...
#Whitespace
Whitespace
                                      ...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#D
D
import core.stdc.stdio, core.stdc.stdlib;   extern(C) void foo() nothrow { "foo at exit".puts; }   extern(C) void bar() nothrow { "bar at exit".puts; }   extern(C) void spam() nothrow { "spam at exit".puts; }   int baz(in int x) pure nothrow in { assert(x != 0); } body { if (x < 0) return 10...
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...
#Nim
Nim
import math, strformat, strutils import arraymancer   #################################################################################################### # First part: QR decomposition.   proc eye(n: Positive): Tensor[float] = ## Return the (n, n) identity matrix. result = newTensor[float](n.int, n.int) for i in...
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...
#Fortran
Fortran
  ! program run with invalid name path/f ! !-*- mode: compilation; default-directory: "/tmp/" -*- !Compilation started at Sun Jun 2 00:18:31 ! !a=./f && make $a && OMP_NUM_THREADS=2 $a < unixdict.txt !gfortran -std=f2008 -Wall -fopenmp -ffree-form -fall-intrinsics -fimplicit-none f.f08 -o f ! !Compilation finished at ...
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Factor
Factor
USING: formatting kernel literals math math.functions math.primes sequences ; IN: rosetta-code.primorial-numbers   CONSTANT: primes $[ 1,000,000 nprimes ]   : digit-count ( n -- count ) log10 floor >integer 1 + ;   : primorial ( n -- m ) primes swap head product ;   : .primorial ( n -- ) dup primorial "Primorial(%d) = ...
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Fortran
Fortran
Base: 10 100 1,000 10,000 100,000 Secs: 554 278 185 117 52 - but wrong! 64-bit 300 241
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,...
#Groovy
Groovy
class Triple { BigInteger a, b, c def getPerimeter() { this.with { a + b + c } } boolean isValid() { this.with { a*a + b*b == c*c } } }   def initCounts (def n = 10) { (n..1).collect { 10g**it }.inject ([:]) { Map map, BigInteger perimeterLimit -> map << [(perimeterLimit): [primative: 0g, total:...
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      ...
#Wren
Wren
import "/fmt" for Fmt   var a = "import $c/fmt$c for Fmt$c$cvar a = $q$cFmt.lprint(a, [34, 34, 10, 10, a, 10])" Fmt.lprint(a, [34, 34, 10, 10, a, 10])
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#DBL
DBL
IF (CONDITION) STOP
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Delphi
Delphi
System.Halt;
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...
#PARI.2FGP
PARI/GP
matqr(M)
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...
#FreeBASIC_2
FreeBASIC
' FB 1.05.0 Win64   Print "The program was invoked like this => "; Command(0) + " " + Command(-1) Print "Press any key to quit" Sleep
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...
#Gambas
Gambas
Public Sub Main() Dim sTemp As String   Print "Command to start the program was ";;   For Each sTemp In Args.All Print sTemp;; Next   End
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#FreeBASIC
FreeBASIC
' version 22-09-2015 ' compile with: fbc -s console   Const As UInteger Base_ = 1000000000 ReDim Shared As UInteger primes()   Sub sieve(need As UInteger)   ' estimate is to high, but ensures that we have enough primes Dim As UInteger max = need * (Log(need) + Log(Log(need))) Dim As UInteger t = 1 ,x , x2 ...
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,...
#Haskell
Haskell
pytr :: Int -> [(Bool, Int, Int, Int)] pytr n = filter (\(_, a, b, c) -> a + b + c <= n) [ (prim a b c, a, b, c) | a <- xs, b <- drop a xs, c <- drop b xs, a ^ 2 + b ^ 2 == c ^ 2 ] where xs = [1 .. n] prim a b _ = gcd a b == 1   main :: IO () main = putStrLn $ ...
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      ...
#x86_Assembly
x86 Assembly
  .global _start;_start:mov $p,%rsi;mov $1,%rax;mov $1,%rdi;mov $255,%rdx;syscall;mov $q,%rsi;mov $1,%rax;mov $1,%rdx;syscall;mov $p,%rsi;mov $1,%rax;mov $255,%rdx;syscall;mov $q,%rsi;mov $1,%rax;mov $1,%rdx;syscall;mov $60,%rax;syscall;q:.byte 34;p:.ascii ".global _start;_start:mov $p,%rsi;mov $1,%rax;mov $1,%rdi;mov ...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#E
E
if (true) { interp.exitAtTop() }
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#EDSAC_order_code
EDSAC order code
if rcode != :ok, do: System.halt(1)
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...
#Perl
Perl
use strict; use warnings;   use PDL; use PDL::LinearAlgebra qw(mqr);   my $a = pdl( [12, -51, 4], [ 6, 167, -68], [-4, 24, -41], [-1, 1, 0], [ 2, 0, 3] );   my ($q, $r) = mqr($a); print $q, $r, $q x $r;
http://rosettacode.org/wiki/Proper_divisors
Proper divisors
The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder. For N > 1 they will always include 1,   but for N == 1 there are no proper divisors. Examples The proper divisors of     6     are   1, 2, and 3. The proper divisors of   100   are   1, 2, 4, 5...
#11l
11l
F proper_divs(n) R Array(Set((1 .. (n + 1) I/ 2).filter(x -> @n % x == 0 & @n != x)))   print((1..10).map(n -> proper_divs(n)))   V (n, leng) = max(((1..20000).map(n -> (n, proper_divs(n).len))), key' pd -> pd[1]) print(n‘ ’leng)
http://rosettacode.org/wiki/Problem_of_Apollonius
Problem of Apollonius
Task Implement a solution to the Problem of Apollonius   (description on Wikipedia)   which is the problem of finding the circle that is tangent to three specified circles   (colored black in the diagram below to the right). There is an   algebraic solution   which is pretty straightforward. The solutions to the ...
#11l
11l
T Circle Float x, y, r   F (x, y, r) .x = x .y = y .r = r   F String() R ‘Circle(x=#., y=#., r=#.)’.format(.x, .y, .r)   F solveApollonius(c1, c2, c3, s1, s2, s3) V (x1, y1, r1) = c1 V (x2, y2, r2) = c2 V (x3, y3, r3) = c3   V v11 = 2 * x2 - 2 * x1 V v12 = 2 * y2 - 2 * y1...
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...
#Genie
Genie
[indent=4] init print args[0] print Path.get_basename(args[0]) print Environment.get_application_name() print Environment.get_prgname()
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...
#Go
Go
package main   import ( "fmt" "os" )   func main() { fmt.Println("Program:", os.Args[0]) }
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Frink
Frink
primorial[n] := product[first[primes[], n]]   for n = 0 to 9 println["primorial[$n] = " + primorial[n]]   for n = [10, 100, 1000, 10000, 100000, million] println["Length of primorial $n is " + length[toString[primorial[n]]] + " decimal digits."]  
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Go
Go
package main   import ( "fmt" "math/big" "time"   "github.com/jbarham/primegen.go" )   func main() { start := time.Now() pg := primegen.New() var i uint64 p := big.NewInt(1) tmp := new(big.Int) for i <= 9 { fmt.Printf("primorial(%v) = %v\n", i, p) i++ p = p.Mul(p, tmp.SetUint64(pg.Next())) } for _, j ...
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,...
#Icon_and_Unicon
Icon and Unicon
  link numbers link printf   procedure main(A) # P-triples   plimit := (0 < integer(\A[1])) | 100 # get perimiter limit   nonprimitiveS := set() # record unique non-primitives triples primitiveS := set() # record unique primitive triples   u := 0 while (g := (u +:= 1)^2) + 3 * u + 2 < plimit / 2 d...
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      ...
#zkl
zkl
zkl: 123 123
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Elixir
Elixir
if rcode != :ok, do: System.halt(1)
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Emacs_Lisp
Emacs Lisp
(when something (kill-emacs))
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...
#Phix
Phix
-- demo/rosettacode/QRdecomposition.exw with javascript_semantics function matrix_mul(sequence a, b) integer arows = ~a, acols = ~a[1], brows = ~b, bcols = ~b[1] if acols!=brows then return 0 end if sequence c = repeat(repeat(0,bcols),arows) for i=1 to arows do for j=1 to bcols do ...
http://rosettacode.org/wiki/Proper_divisors
Proper divisors
The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder. For N > 1 they will always include 1,   but for N == 1 there are no proper divisors. Examples The proper divisors of     6     are   1, 2, and 3. The proper divisors of   100   are   1, 2, 4, 5...
#360_Assembly
360 Assembly
* Proper divisors 14/06/2016 PROPDIV CSECT USING PROPDIV,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) prolog ST R13,4(R15) " ST R15,8(R13) " ...
http://rosettacode.org/wiki/Problem_of_Apollonius
Problem of Apollonius
Task Implement a solution to the Problem of Apollonius   (description on Wikipedia)   which is the problem of finding the circle that is tangent to three specified circles   (colored black in the diagram below to the right). There is an   algebraic solution   which is pretty straightforward. The solutions to the ...
#Ada
Ada
package Apollonius is type Point is record X, Y : Long_Float := 0.0; end record;   type Circle is record Center : Point; Radius : Long_Float := 0.0; end record;   type Tangentiality is (External, Internal);   function Solve_CCC (Circle_1, Circle_2, Circle_3 : Circle; T1, T...
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...
#Groovy
Groovy
#!/usr/bin/env groovy   def program = getClass().protectionDomain.codeSource.location.path   println "Program: " + program
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...
#Haskell
Haskell
import System (getProgName)   main :: IO () main = getProgName >>= putStrLn . ("Program: " ++)
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Haskell
Haskell
  import Control.Arrow ((&&&)) import Data.List (scanl1, foldl1')   getNthPrimorial :: Int -> Integer getNthPrimorial n = foldl1' (*) (take n primes)   primes :: [Integer] primes = 2 : filter isPrime [3,5..]   isPrime :: Integer -> Bool isPrime = isPrime_ primes where isPrime_ :: [Integer] -> Integer -> Bool ...
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,...
#J
J
pytr=: 3 :0 r=. i. 0 3 for_a. 1 + i. <.(y-1)%3 do. b=. 1 + a + i. <.(y%2)-3*a%2 c=. a +&.*: b keep=. (c = <.c) *. y >: a+b+c if. 1 e. keep do. r=. r, a,.b ,.&(keep&#) c end. end. (,.~ prim"1)r )   prim=: 1 = 2 +./@{. |:
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Erlang
Erlang
% Implemented by Arjun Sunel if problem -> exit(1).
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#F.23
F#
open System   if condition then Environment.Exit 1
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...
#PowerShell
PowerShell
  function qr([double[][]]$A) { $m,$n = $A.count, $A[0].count $pm,$pn = ($m-1), ($n-1) [double[][]]$Q = 0..($m-1) | foreach{$row = @(0) * $m; $row[$_] = 1; ,$row} [double[][]]$R = $A | foreach{$row = $_; ,@(0..$pn | foreach{$row[$_]})} foreach ($h in 0..$pn) { [double[]]$u = $R[$h..$pm] | ...
http://rosettacode.org/wiki/Prime_triangle
Prime triangle
You will require a function f which when given an integer S will return a list of the arrangements of the integers 1 to S such that g1=1 gS=S and generally for n=1 to n=S-1 gn+gn+1 is prime. S=1 is undefined. For S=2 to S=20 print f(S) to form a triangle. Then again for S=2 to S=20 print the number of possible arrangem...
#ALGOL_68
ALGOL 68
BEGIN # find solutions to the "Prime Triangle" - a triangle of numbers that sum to primes # INT max number = 18; # largest number we will consider # # construct a primesieve and from that a table of pairs of numbers whose sum is prime # [ 0 : 2 * max number ]BOOL prime; prime[ 0 ] := prime[ 1 ] := FALSE...
http://rosettacode.org/wiki/Proper_divisors
Proper divisors
The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder. For N > 1 they will always include 1,   but for N == 1 there are no proper divisors. Examples The proper divisors of     6     are   1, 2, and 3. The proper divisors of   100   are   1, 2, 4, 5...
#Action.21
Action!
BYTE FUNC GetDivisors(INT a INT ARRAY divisors) INT i,max BYTE count   max=a/2 count=0 FOR i=1 TO max DO IF a MOD i=0 THEN divisors(count)=i count==+1 FI OD RETURN (count)   PROC Main() DEFINE MAXNUM="20000" INT i,j,count,max,ind INT ARRAY divisors(100) BYTE ARRAY pdc(MAXNUM+1)...
http://rosettacode.org/wiki/Problem_of_Apollonius
Problem of Apollonius
Task Implement a solution to the Problem of Apollonius   (description on Wikipedia)   which is the problem of finding the circle that is tangent to three specified circles   (colored black in the diagram below to the right). There is an   algebraic solution   which is pretty straightforward. The solutions to the ...
#Arturo
Arturo
define :circle [x y r][]   solveApollonius: function [c1 c2 c3 s1 s2 s3][ v11: sub 2*c2\x 2*c1\x v12: sub 2*c2\y 2*c1\y v13: (sub (sub c1\x*c1\x c2\x*c2\x) + (sub c1\y*c1\y c2\y*c2\y) c1\r*c1\r) + c2\r*c2\r v14: sub 2*s2*c2\r 2*s1*c1\r   v21: sub 2*c3\x 2*c2\x v22: sub 2*c3\y 2*c2\y v23: (su...
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() write(&progname) # obtain and write out the program name from the keyword &progname end
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...
#Io
Io
#!/usr/bin/env io   main := method( program := System args at(0)   ("Program: " .. program) println )   if (System args size > 0 and System args at(0) containsSeq("scriptname"), main)
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#J
J
primorial=:*/@:p:@i."0
http://rosettacode.org/wiki/Primorial_numbers
Primorial numbers
Primorial numbers are those formed by multiplying successive prime numbers. The primorial number series is:   primorial(0) =         1       (by definition)   primorial(1) =         2       (2)   primorial(2) =         6       (2×3)   primorial(3) =       30       (2×3×5)   primorial(4) =     210       (2×3×5×...
#Java
Java
import java.math.BigInteger;   public class PrimorialNumbers { final static int sieveLimit = 1300_000; static boolean[] notPrime = sieve(sieveLimit);   public static void main(String[] args) { for (int i = 0; i < 10; i++) System.out.printf("primorial(%d): %d%n", i, primorial(i));   ...
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,...
#Java
Java
  import java.math.BigInteger; import static java.math.BigInteger.ONE;   public class PythTrip{   public static void main(String[] args){ long tripCount = 0, primCount = 0;   //change this to whatever perimeter limit you want;the RAM's the limit BigInteger periLimit = BigInteger.valueOf(100)...
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Factor
Factor
USING: kernel system ;   t [ 0 exit ] when
http://rosettacode.org/wiki/Program_termination
Program termination
Task Show the syntax for a complete stoppage of a program inside a   conditional. This includes all threads/processes which are part of your program. Explain the cleanup (or lack thereof) caused by the termination (allocated memory, database connections, open files, object finalizers/destructors, run-on-exit hooks...
#Forth
Forth
debug @ if QUIT \ quit back to the interpreter else BYE \ exit forth environment completely (e.g. end of a Forth shell script) then