/* strlen() */
+
+void
+fail(const char *message)
+{
+ fprintf(stderr, "%s: error 0x%08lx\n", ERR_get_error());
+ exit(1);
+}
+
+int
+main()
+{
+ BIGNUM two, three, four, five;
+ BIGNUM answer;
+ BN_CTX *context;
+ size_t length;
+ char *string;
+
+ context = BN_CTX_new();
+ if (context == NULL)
+ fail("BN_CTX_new");
+
+ /* answer = 5 ** 4 ** 3 ** 2 */
+ BN_init(&two);
+ BN_init(&three);
+ BN_init(&four);
+ BN_init(&five);
+ if (BN_set_word(&two, 2) == 0 ||
+ BN_set_word(&three, 3) == 0 ||
+ BN_set_word(&four, 4) == 0 ||
+ BN_set_word(&five, 5) == 0)
+ fail("BN_set_word");
+ BN_init(&answer);
+ if (BN_exp(&answer, &three, &two, context) == 0 ||
+ BN_exp(&answer, &four, &answer, context) == 0 ||
+ BN_exp(&answer, &five, &answer, context) == 0)
+ fail("BN_exp");
+
+ /* string = decimal answer */
+ string = BN_bn2dec(&answer);
+ if (string == NULL)
+ fail("BN_bn2dec");
+
+ length = strlen(string);
+ printf(" First 20 digits: %.20s\n", string);
+ if (length >= 20)
+ printf(" Last 20 digits: %.20s\n", string + length - 20);
+ printf("Number of digits: %zd\n", length);
+
+ OPENSSL_free(string);
+ BN_free(&answer);
+ BN_free(&five);
+ BN_free(&four);
+ BN_free(&three);
+ BN_free(&two);
+ BN_CTX_free(context);
+
+ return 0;
+}
diff --git a/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-1.clj b/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-1.clj
new file mode 100644
index 0000000000..fb911a500b
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-1.clj
@@ -0,0 +1,12 @@
+(defn exp [n k] (reduce * (repeat k n)))
+
+(def big (->> 2 (exp 3) (exp 4) (exp 5)))
+(def sbig (str big))
+
+(assert (= "62060698786608744707" (.substring sbig 0 20)))
+(assert (= "92256259918212890625" (.substring sbig (- (count sbig) 20))))
+(println (count sbig) "digits")
+
+(println (str (.substring sbig 0 20) ".."
+ (.substring sbig (- (count sbig) 20)))
+ (str "(" (count sbig) " digits)"))
diff --git a/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-2.clj b/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-2.clj
new file mode 100644
index 0000000000..70c00fc896
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Clojure/arbitrary-precision-integers-included-2.clj
@@ -0,0 +1,5 @@
+(defn exp [n k]
+ (cond
+ (zero? (mod k 2)) (recur (* n n) (/ k 2))
+ (zero? (mod k 3)) (recur (* n n n) (/ k 3))
+ :else (reduce * (repeat k n))))
diff --git a/Task/Arbitrary-precision-integers-included/Common-Lisp/arbitrary-precision-integers-included.lisp b/Task/Arbitrary-precision-integers-included/Common-Lisp/arbitrary-precision-integers-included.lisp
new file mode 100644
index 0000000000..9d75c9feba
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Common-Lisp/arbitrary-precision-integers-included.lisp
@@ -0,0 +1,3 @@
+(let ((s (format () "~s" (expt 5 (expt 4 (expt 3 2))))))
+ (format t "~a...~a, length ~a" (subseq s 0 20)
+ (subseq s (- (length s) 20)) (length s)))
diff --git a/Task/Arbitrary-precision-integers-included/D/arbitrary-precision-integers-included.d b/Task/Arbitrary-precision-integers-included/D/arbitrary-precision-integers-included.d
new file mode 100644
index 0000000000..3206a0fc59
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/D/arbitrary-precision-integers-included.d
@@ -0,0 +1,6 @@
+import std.stdio, std.bigint, std.conv;
+
+void main() {
+ auto s = text(BigInt(5) ^^ 4 ^^ 3 ^^ 2);
+ writefln("5^4^3^2 = %s..%s (%d digits)", s[0..20], s[$-20..$], s.length);
+}
diff --git a/Task/Arbitrary-precision-integers-included/E/arbitrary-precision-integers-included.e b/Task/Arbitrary-precision-integers-included/E/arbitrary-precision-integers-included.e
new file mode 100644
index 0000000000..45384c7657
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/E/arbitrary-precision-integers-included.e
@@ -0,0 +1,10 @@
+? def value := 5**(4**(3**2)); null
+? def decimal := value.toString(10); null
+? decimal(0, 20)
+# value: "62060698786608744707"
+
+? decimal(decimal.size() - 20)
+# value: "92256259918212890625"
+
+? decimal.size()
+# value: 183231
diff --git a/Task/Arbitrary-precision-integers-included/Emacs-Lisp/arbitrary-precision-integers-included.l b/Task/Arbitrary-precision-integers-included/Emacs-Lisp/arbitrary-precision-integers-included.l
new file mode 100644
index 0000000000..1d6a049d06
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Emacs-Lisp/arbitrary-precision-integers-included.l
@@ -0,0 +1,9 @@
+(let* ((answer (calc-eval "5**4**3**2"))
+ (length (length answer)))
+ (message "%s has %d digits"
+ (if (> length 40)
+ (format "%s...%s"
+ (substring answer 0 20)
+ (substring answer (- length 20) length))
+ answer)
+ length))
diff --git a/Task/Arbitrary-precision-integers-included/Erlang/arbitrary-precision-integers-included.erl b/Task/Arbitrary-precision-integers-included/Erlang/arbitrary-precision-integers-included.erl
new file mode 100644
index 0000000000..706332b1bd
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Erlang/arbitrary-precision-integers-included.erl
@@ -0,0 +1,20 @@
+-module(arbitrary).
+-compile([export_all]).
+
+pow(B,E) when E > 0 ->
+ pow(B,E,1).
+
+pow(_,0,_) -> 0;
+pow(B,1,Acc) -> Acc * B;
+pow(B,P,Acc) when P rem 2 == 0 ->
+ pow(B*B,P div 2, Acc);
+pow(B,P,Acc) ->
+ pow(B,P-1,Acc*B).
+
+test() ->
+ I = pow(5,pow(4,pow(3,2))),
+ [S] = io_lib:format("~b",[I]),
+ L = length(S),
+ Prefix = lists:sublist(S,20),
+ Suffix = lists:sublist(S,L-19,20),
+ io:format("Length: ~b~nPrefix:~s~nSuffix:~s~n",[L,Prefix,Suffix]).
diff --git a/Task/Arbitrary-precision-integers-included/Factor/arbitrary-precision-integers-included.factor b/Task/Arbitrary-precision-integers-included/Factor/arbitrary-precision-integers-included.factor
new file mode 100644
index 0000000000..4fbd7a7d5d
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Factor/arbitrary-precision-integers-included.factor
@@ -0,0 +1,7 @@
+USING: formatting kernel math.functions math.parser sequences ;
+IN: rosettacode.bignums
+
+: test-bignums ( -- )
+ 5 4 3 2 ^ ^ ^ number>string
+ [ 20 head ] [ 20 tail* ] [ length ] tri
+ "5^4^3^2 is %s...%s and has %d digits\n" printf ;
diff --git a/Task/Arbitrary-precision-integers-included/Frink/arbitrary-precision-integers-included.frink b/Task/Arbitrary-precision-integers-included/Frink/arbitrary-precision-integers-included.frink
new file mode 100644
index 0000000000..c586f383e1
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Frink/arbitrary-precision-integers-included.frink
@@ -0,0 +1,3 @@
+a = 5^4^3^2
+as = "$a" // Coerce to string
+println["Length=" + length[as] + ", " + left[as,20] + "..." + right[as,20]]
diff --git a/Task/Arbitrary-precision-integers-included/GAP/arbitrary-precision-integers-included.gap b/Task/Arbitrary-precision-integers-included/GAP/arbitrary-precision-integers-included.gap
new file mode 100644
index 0000000000..7fc6805214
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/GAP/arbitrary-precision-integers-included.gap
@@ -0,0 +1,8 @@
+n:=5^(4^(3^2));;
+s := String(n);;
+m := Length(s);
+# 183231
+s{[1..20]};
+# "62060698786608744707"
+s{[m-19..m]};
+# "92256259918212890625"
diff --git a/Task/Arbitrary-precision-integers-included/Go/arbitrary-precision-integers-included.go b/Task/Arbitrary-precision-integers-included/Go/arbitrary-precision-integers-included.go
new file mode 100644
index 0000000000..91527a94ce
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Go/arbitrary-precision-integers-included.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "fmt"
+ "math/big"
+)
+
+func main() {
+ answer := big.NewInt(42)
+ answer.Exp(big.NewInt(5), answer.Exp(big.NewInt(4),
+ answer.Exp(big.NewInt(3), big.NewInt(2), nil), nil), nil)
+ answer_string := answer.String()
+ length := len(answer_string)
+ fmt.Printf("has %d digits: %s ... %s\n",
+ length,
+ answer_string[0:20],
+ answer_string[length-20:])
+}
diff --git a/Task/Arbitrary-precision-integers-included/Golfscript/arbitrary-precision-integers-included.golf b/Task/Arbitrary-precision-integers-included/Golfscript/arbitrary-precision-integers-included.golf
new file mode 100644
index 0000000000..22b8260274
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Golfscript/arbitrary-precision-integers-included.golf
@@ -0,0 +1,5 @@
+5 4 3 2??? # Calculate 5^(4^(3^2))
+`.. # Convert to string and make two copies
+20p # Print the last 20 digits
+,p # Print the length
diff --git a/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-1.groovy b/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-1.groovy
new file mode 100644
index 0000000000..17a9a1b4fa
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-1.groovy
@@ -0,0 +1 @@
+def bigNumber = 5G ** (4 ** (3 ** 2))
diff --git a/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-2.groovy b/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-2.groovy
new file mode 100644
index 0000000000..c0d98ff5a1
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Groovy/arbitrary-precision-integers-included-2.groovy
@@ -0,0 +1,6 @@
+def bigString = bigNumber.toString()
+
+assert bigString[0..<20] == "62060698786608744707"
+assert bigString[-20..-1] == "92256259918212890625"
+
+println bigString.size()
diff --git a/Task/Arbitrary-precision-integers-included/Haskell/arbitrary-precision-integers-included.hs b/Task/Arbitrary-precision-integers-included/Haskell/arbitrary-precision-integers-included.hs
new file mode 100644
index 0000000000..e5f6738b4d
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Haskell/arbitrary-precision-integers-included.hs
@@ -0,0 +1,4 @@
+main = do
+ let y = show ( 5^4^3^2 )
+ let l = length y
+ putStrLn ("5**4**3**2 = " ++ take 20 y ++ "..." ++ drop (l-20) y ++ " and has " ++ show l ++ " digits")
diff --git a/Task/Arbitrary-precision-integers-included/Icon/arbitrary-precision-integers-included.icon b/Task/Arbitrary-precision-integers-included/Icon/arbitrary-precision-integers-included.icon
new file mode 100644
index 0000000000..bec1a3f863
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Icon/arbitrary-precision-integers-included.icon
@@ -0,0 +1,8 @@
+procedure main()
+ x := 5^4^3^2
+ write("done with computation")
+ x := string(x)
+ write("5 ^ 4 ^ 3 ^ 2 has ",*x," digits")
+ write("The first twenty digits are ",x[1+:20])
+ write("The last twenty digits are ",x[0-:20])
+end
diff --git a/Task/Arbitrary-precision-integers-included/J/arbitrary-precision-integers-included.j b/Task/Arbitrary-precision-integers-included/J/arbitrary-precision-integers-included.j
new file mode 100644
index 0000000000..8a628a10bd
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/J/arbitrary-precision-integers-included.j
@@ -0,0 +1,6 @@
+ Pow5432=: 5^4^3^2x
+ Pow5432=: ^/ 5 4 3 2x NB. alternate J solution
+ # ": Pow5432 NB. number of digits
+183231
+ 20 ({. , '...' , -@[ {. ]) ": Pow5432 NB. 20 first & 20 last digits
+62060698786608744707...92256259918212890625
diff --git a/Task/Arbitrary-precision-integers-included/Java/arbitrary-precision-integers-included.java b/Task/Arbitrary-precision-integers-included/Java/arbitrary-precision-integers-included.java
new file mode 100644
index 0000000000..6d9f1d5c70
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Java/arbitrary-precision-integers-included.java
@@ -0,0 +1,11 @@
+import java.math.BigInteger;
+
+class Program {
+ public static void main(String[] args) {
+ BigInteger x = BigInteger.valueOf(5).pow(BigInteger.valueOf(4).pow(BigInteger.valueOf(3).pow(2).intValue()).intValue());
+ String y = x.toString();
+ int l = y.length();
+ System.out.printf("5**4**3**2 = %s...%s and has %d digits\n",
+ y.substring(0,20), y.substring(l-20), l);
+ }
+}
diff --git a/Task/Arbitrary-precision-integers-included/Julia/arbitrary-precision-integers-included.julia b/Task/Arbitrary-precision-integers-included/Julia/arbitrary-precision-integers-included.julia
new file mode 100644
index 0000000000..902ae23e88
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Julia/arbitrary-precision-integers-included.julia
@@ -0,0 +1,11 @@
+julia> @elapsed big = string(BigInt(5)^4^3^2)
+0.06799983978271484 seconds
+
+julia> length(big)
+183231
+
+julia> big[1:20]
+"62060698786608744707"
+
+julia> big[end-20:end]
+"892256259918212890625"
diff --git a/Task/Arbitrary-precision-integers-included/Liberty-BASIC/arbitrary-precision-integers-included.liberty b/Task/Arbitrary-precision-integers-included/Liberty-BASIC/arbitrary-precision-integers-included.liberty
new file mode 100644
index 0000000000..b4d97021ac
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Liberty-BASIC/arbitrary-precision-integers-included.liberty
@@ -0,0 +1,3 @@
+a$ = str$( 5^(4^(3^2)))
+print len( a$)
+print left$( a$, 20); "......"; right$( a$, 20)
diff --git a/Task/Arbitrary-precision-integers-included/MATLAB/arbitrary-precision-integers-included.m b/Task/Arbitrary-precision-integers-included/MATLAB/arbitrary-precision-integers-included.m
new file mode 100644
index 0000000000..4dec511994
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/MATLAB/arbitrary-precision-integers-included.m
@@ -0,0 +1,13 @@
+>> answer = vpi(5)^(vpi(4)^(vpi(3)^vpi(2)));
+>> numDigits = order(answer) + 1
+
+numDigits =
+
+ 183231
+
+>> [sprintf('%d',leadingdigit(answer,20)) '...' sprintf('%d',trailingdigit(answer,20))]
+%First and Last 20 Digits
+
+ans =
+
+62060698786608744707...92256259918212890625
diff --git a/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-1.maple b/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-1.maple
new file mode 100644
index 0000000000..d79c875847
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-1.maple
@@ -0,0 +1,7 @@
+> n := 5^(4^(3^2)):
+> length( n ); # number of digits
+ 183231
+
+> s := convert( n, 'string' ):
+> s[ 1 .. 20 ], s[ -20 .. -1 ]; # extract first and last twenty digits
+ "62060698786608744707", "92256259918212890625"
diff --git a/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-2.maple b/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-2.maple
new file mode 100644
index 0000000000..3329ccf6fd
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Maple/arbitrary-precision-integers-included-2.maple
@@ -0,0 +1,3 @@
+> interface( elisiondigitsbefore = 20, elisiondigitsafter = 20 ):
+> 5^(4^(3^2)):
+ 62060698786608744707[...183191 digits...]92256259918212890625
diff --git a/Task/Arbitrary-precision-integers-included/Mathematica/arbitrary-precision-integers-included.mathematica b/Task/Arbitrary-precision-integers-included/Mathematica/arbitrary-precision-integers-included.mathematica
new file mode 100644
index 0000000000..ce95e04c25
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Mathematica/arbitrary-precision-integers-included.mathematica
@@ -0,0 +1,2 @@
+s:=ToString[5^4^3^2];
+Print[StringTake[s,20]<>"..."<>StringTake[s,-20]<>" ("<>ToString@StringLength@s<>" digits)"];
diff --git a/Task/Arbitrary-precision-integers-included/Maxima/arbitrary-precision-integers-included.maxima b/Task/Arbitrary-precision-integers-included/Maxima/arbitrary-precision-integers-included.maxima
new file mode 100644
index 0000000000..7420e2f7ec
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Maxima/arbitrary-precision-integers-included.maxima
@@ -0,0 +1,3 @@
+block([s, n], s: string(5^4^3^2), n: slength(s), print(substring(s, 1, 21), "...", substring(s, n - 19)), n);
+/* 62060698786608744707...92256259918212890625
+183231 */
diff --git a/Task/Arbitrary-precision-integers-included/PHP/arbitrary-precision-integers-included.php b/Task/Arbitrary-precision-integers-included/PHP/arbitrary-precision-integers-included.php
new file mode 100644
index 0000000000..5b9940bd32
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/PHP/arbitrary-precision-integers-included.php
@@ -0,0 +1,4 @@
+
diff --git a/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-1.pl b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-1.pl
new file mode 100644
index 0000000000..16f8bb144f
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-1.pl
@@ -0,0 +1,4 @@
+use Math::BigInt;
+my $x = Math::BigInt->new('5') ** Math::BigInt->new('4') ** Math::BigInt->new('3') ** Math::BigInt->new('2');
+my $y = "$x";
+printf("5**4**3**2 = %s...%s and has %i digits\n", substr($y,0,20), substr($y,-20), length($y));
diff --git a/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-2.pl b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-2.pl
new file mode 100644
index 0000000000..0ac8cb28d6
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-2.pl
@@ -0,0 +1,4 @@
+use bigint;
+my $x = 5**4**3**2;
+my $y = "$x";
+printf("5**4**3**2 = %s...%s and has %i digits\n", substr($y,0,20), substr($y,-20), length($y));
diff --git a/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-3.pl b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-3.pl
new file mode 100644
index 0000000000..2a2c2692b8
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Perl/arbitrary-precision-integers-included-3.pl
@@ -0,0 +1,3 @@
+$ time perl transparent-bigint.pl
+5**4**3**2 = 62060698786608744707...92256259918212890625 and has 183231 digits
+ 1m4.28s real 1m4.30s user 0m0.00s system
diff --git a/Task/Arbitrary-precision-integers-included/PicoLisp/arbitrary-precision-integers-included.l b/Task/Arbitrary-precision-integers-included/PicoLisp/arbitrary-precision-integers-included.l
new file mode 100644
index 0000000000..f8d0095c14
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/PicoLisp/arbitrary-precision-integers-included.l
@@ -0,0 +1,3 @@
+(let L (chop (** 5 (** 4 (** 3 2))))
+ (prinl (head 20 L) "..." (tail 20 L))
+ (length L) )
diff --git a/Task/Arbitrary-precision-integers-included/Python/arbitrary-precision-integers-included.py b/Task/Arbitrary-precision-integers-included/Python/arbitrary-precision-integers-included.py
new file mode 100644
index 0000000000..9c73f44c8e
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Python/arbitrary-precision-integers-included.py
@@ -0,0 +1,3 @@
+>>> y = str( 5**4**3**2 )
+>>> print ("5**4**3**2 = %s...%s and has %i digits" % (y[:20], y[-20:], len(y)))
+5**4**3**2 = 62060698786608744707...92256259918212890625 and has 183231 digits
diff --git a/Task/Arbitrary-precision-integers-included/R/arbitrary-precision-integers-included.r b/Task/Arbitrary-precision-integers-included/R/arbitrary-precision-integers-included.r
new file mode 100644
index 0000000000..7c3443d92f
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/R/arbitrary-precision-integers-included.r
@@ -0,0 +1,6 @@
+library(gmp)
+large=pow.bigz(5,pow.bigz(4,pow.bigz(3,2)))
+largestr=as.character(large)
+cat("first 20 digits:",substr(largestr,1,20),"\n",
+ "last 20 digits:",substr(largestr,nchar(largestr)-19,nchar(largestr)),"\n",
+ "number of digits: ",nchar(largestr),"\n")
diff --git a/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-1.rexx b/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-1.rexx
new file mode 100644
index 0000000000..c708819f2c
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-1.rexx
@@ -0,0 +1,12 @@
+/*REXX program to calculate and demonstrate arbitrary precision numbers.*/
+numeric digits 200000
+check = 62060698786608744707...92256259918212890625
+ n = 5 ** (4 ** (3 ** 2)) /*calc. multiple exponentations. */
+sampl = left(n, 20)'...'right(n, 20)
+say ' check:' check
+say 'sample:' sampl
+say 'digits:' length(n)
+say
+if check==sampl then say 'passed!'
+ else say 'failed!'
+ /*stick a fork in it, we're done.*/
diff --git a/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-2.rexx b/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-2.rexx
new file mode 100644
index 0000000000..4753dbe0da
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/REXX/arbitrary-precision-integers-included-2.rexx
@@ -0,0 +1,21 @@
+/*REXX program to calculate and demonstrate arbitrary precision numbers.*/
+numeric digits 5 /*set to low precision for speed.*/
+check = 62060698786608744707...92256259918212890625
+
+ n=5** (4** (3** 2)) /*calc. multiple exponentations. */
+
+parse var n 'E' pow . /*POW might be null, so N is OK.*/
+
+if pow\=='' then do /*general case: POW might be < 0*/
+ numeric digits abs(pow)+9 /*recalc. with more digits.*/
+ n=5** (4** (3** 2)) /*calc. multiple exponentations. */
+ end
+
+sampl = left(n, 20)'...'right(n, 20)
+say ' check:' check
+say 'sample:' sampl
+say 'digits:' length(n)
+say
+if check==sampl then say 'passed!'
+ else say 'failed!'
+ /*stick a fork in it, we're done.*/
diff --git a/Task/Arbitrary-precision-integers-included/Racket/arbitrary-precision-integers-included.rkt b/Task/Arbitrary-precision-integers-included/Racket/arbitrary-precision-integers-included.rkt
new file mode 100644
index 0000000000..f9150a2615
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Racket/arbitrary-precision-integers-included.rkt
@@ -0,0 +1,9 @@
+#lang racket
+
+(define answer (number->string (foldr expt 1 '(5 4 3 2))))
+(define len (string-length answer))
+
+(printf "Got ~a digits~n" len)
+(printf "~a ... ~a~n"
+ (substring answer 0 20)
+ (substring answer (- len 20) len))
diff --git a/Task/Arbitrary-precision-integers-included/Ruby/arbitrary-precision-integers-included.rb b/Task/Arbitrary-precision-integers-included/Ruby/arbitrary-precision-integers-included.rb
new file mode 100644
index 0000000000..ff50bf1764
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Ruby/arbitrary-precision-integers-included.rb
@@ -0,0 +1,2 @@
+irb(main):001:0> y = ( 5**4**3**2 ).to_s; puts "5**4**3**2 = #{y[0..19]}...#{y[-20..-1]} and has #{y.length} digits"
+5**4**3**2 = 62060698786608744707...92256259918212890625 and has 183231 digits
diff --git a/Task/Arbitrary-precision-integers-included/Sather/arbitrary-precision-integers-included.sa b/Task/Arbitrary-precision-integers-included/Sather/arbitrary-precision-integers-included.sa
new file mode 100644
index 0000000000..9b96acc2ed
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Sather/arbitrary-precision-integers-included.sa
@@ -0,0 +1,22 @@
+class MAIN is
+ main is
+ r:INTI;
+ p1 ::= "62060698786608744707";
+ p2 ::= "92256259918212890625";
+
+ -- computing 5^(4^(3^2)), it could be written
+ -- also e.g. (5.inti)^((4.inti)^((3.inti)^(2.inti)))
+ r := (3.pow(2)).inti;
+ r := (4.inti).pow(r);
+ r := (5.inti).pow(r);
+
+ sr ::= r.str; -- string rappr. of the number
+ if sr.head(p1.size) = p1
+ and sr.tail(p2.size) = p2 then
+ #OUT + "result is ok..\n";
+ else
+ #OUT + "oops\n";
+ end;
+ #OUT + "# of digits: " + sr.size + "\n";
+ end;
+end;
diff --git a/Task/Arbitrary-precision-integers-included/Scala/arbitrary-precision-integers-included.scala b/Task/Arbitrary-precision-integers-included/Scala/arbitrary-precision-integers-included.scala
new file mode 100644
index 0000000000..5c23ab93a4
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Scala/arbitrary-precision-integers-included.scala
@@ -0,0 +1,21 @@
+scala> BigInt(5) modPow (BigInt(4) pow (BigInt(3) pow 2).toInt, BigInt(10) pow 20)
+res21: scala.math.BigInt = 92256259918212890625
+
+scala> (BigInt(5) pow (BigInt(4) pow (BigInt(3) pow 2).toInt).toInt).toString
+res22: String = 6206069878660874470748320557284679309194219265199117173177383244
+78446890420544620839553285931321349485035253770303663683982841794590287939217907
+89641300156281305613064874236198955114921296922487632406742326659692228562195387
+46210423235340883954495598715281862895110697243759768434501295076608139350684049
+01191160699929926568099301259938271975526587719565309995276438998093283175080241
+55833224724855977970015112594128926594587205662421861723789001208275184293399910
+13912158886504596553858675842231519094813553261073608575593794241686443569888058
+92732524316323249492420512640962691673104618378381545202638771401061171968052873
+21414945463925055899307933774904078819911387324217976311238875802878310483037255
+33789567769926391314746986316354035923183981697660495275234703657750678459919...
+scala> res22 take 20
+res23: String = 62060698786608744707
+
+scala> res22 length
+res24: Int = 183231
+
+scala>
diff --git a/Task/Arbitrary-precision-integers-included/Scheme/arbitrary-precision-integers-included.ss b/Task/Arbitrary-precision-integers-included/Scheme/arbitrary-precision-integers-included.ss
new file mode 100644
index 0000000000..eb4a9716cb
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Scheme/arbitrary-precision-integers-included.ss
@@ -0,0 +1,5 @@
+(define x (expt 5 (expt 4 (expt 3 2))))
+(define y (number->string x))
+(define l (string-length y))
+(display (string-append "5**4**3**2 = " (substring y 0 20) "..." (substring y (- l 20) l) " and has " (number->string l) " digits"))
+(newline)
diff --git a/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-1.st b/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-1.st
new file mode 100644
index 0000000000..bc43ca6f12
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-1.st
@@ -0,0 +1,5 @@
+|num|
+num := (5 raisedTo: (4 raisedTo: (3 raisedTo: 2))) asString.
+Transcript
+ show: (num first: 20), '...', (num last: 20); cr;
+ show: 'digits: ', num size asString.
diff --git a/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-2.st b/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-2.st
new file mode 100644
index 0000000000..0174b99ebf
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Smalltalk/arbitrary-precision-integers-included-2.st
@@ -0,0 +1,7 @@
+|num numstr|
+num := (2 to: 5) fold: [:exp :base| base raisedTo: exp].
+numstr := num asString.
+'<1s>...<2s> digits:<3p>'
+ expandMacrosWith: (numstr first: 20)
+ with: (numstr last: 20)
+ with: numstr size.
diff --git a/Task/Arbitrary-precision-integers-included/Tcl/arbitrary-precision-integers-included.tcl b/Task/Arbitrary-precision-integers-included/Tcl/arbitrary-precision-integers-included.tcl
new file mode 100644
index 0000000000..71fdc22752
--- /dev/null
+++ b/Task/Arbitrary-precision-integers-included/Tcl/arbitrary-precision-integers-included.tcl
@@ -0,0 +1,7 @@
+set bigValue [expr {5**4**3**2}]
+puts "5**4**3**2 has [string length $bigValue] digits"
+if {[string match "62060698786608744707*92256259918212890625" $bigValue]} {
+ puts "Value starts with 62060698786608744707, ends with 92256259918212890625"
+} else {
+ puts "Value does not match 62060698786608744707...92256259918212890625"
+}
diff --git a/Task/Arena-storage-pool/J/arena-storage-pool-1.j b/Task/Arena-storage-pool/J/arena-storage-pool-1.j
new file mode 100644
index 0000000000..204a72e77e
--- /dev/null
+++ b/Task/Arena-storage-pool/J/arena-storage-pool-1.j
@@ -0,0 +1,27 @@
+coclass 'integerPool'
+require 'jmf'
+create=: monad define
+ Lim=: y*SZI_jmf_
+ Next=: -SZI_jmf_
+ Pool=: mema Lim
+)
+
+destroy=: monad define
+ memf Pool
+ codestroy''
+)
+
+alloc=: monad define
+ assert.Lim >: Next=: Next+SZI_jmf_
+ r=.Pool,Next,1,JINT
+ r set y
+ r
+)
+
+get=: adverb define
+ memr m
+)
+
+set=: adverb define
+ y memw m
+)
diff --git a/Task/Arena-storage-pool/J/arena-storage-pool-2.j b/Task/Arena-storage-pool/J/arena-storage-pool-2.j
new file mode 100644
index 0000000000..897c1622c2
--- /dev/null
+++ b/Task/Arena-storage-pool/J/arena-storage-pool-2.j
@@ -0,0 +1,9 @@
+ pool0=: 3 conew 'integerPool'
+ x0=: alloc__pool0 0
+ x1=: alloc__pool0 0
+ x2=: alloc__pool0 0
+ x0 set__pool0 7
+ x1 set__pool0 8
+ x2 set__pool0 9
+ x0 get__pool0 + x1 get__pool0 + x2 get__pool0
+24
diff --git a/Task/Arena-storage-pool/J/arena-storage-pool-3.j b/Task/Arena-storage-pool/J/arena-storage-pool-3.j
new file mode 100644
index 0000000000..b08dc2799d
--- /dev/null
+++ b/Task/Arena-storage-pool/J/arena-storage-pool-3.j
@@ -0,0 +1 @@
+ destroy__pool0 _
diff --git a/Task/Arena-storage-pool/Mathematica/arena-storage-pool.mathematica b/Task/Arena-storage-pool/Mathematica/arena-storage-pool.mathematica
new file mode 100644
index 0000000000..c401b4becc
--- /dev/null
+++ b/Task/Arena-storage-pool/Mathematica/arena-storage-pool.mathematica
@@ -0,0 +1 @@
+f[x_] := x^2
diff --git a/Task/Arithmetic-Complex/Factor/arithmetic-complex.factor b/Task/Arithmetic-Complex/Factor/arithmetic-complex.factor
new file mode 100644
index 0000000000..91689d7e6d
--- /dev/null
+++ b/Task/Arithmetic-Complex/Factor/arithmetic-complex.factor
@@ -0,0 +1,18 @@
+USING: combinators kernel math math.functions prettyprint ;
+
+C{ 1 2 } C{ 0.9 -2.78 } {
+ [ + . ] ! addition
+ [ - . ] ! subtraction
+ [ * . ] ! multiplication
+ [ / . ] ! division
+ [ ^ . ] ! power
+} 2cleave
+
+C{ 1 2 } {
+ [ neg . ] ! negation
+ [ 1 swap / . ] ! multiplicative inverse
+ [ conjugate . ] ! complex conjugate
+ [ sin . ] ! sine
+ [ log . ] ! natural logarithm
+ [ sqrt . ] ! square root
+} cleave
diff --git a/Task/Arithmetic-Complex/GAP/arithmetic-complex.gap b/Task/Arithmetic-Complex/GAP/arithmetic-complex.gap
new file mode 100644
index 0000000000..165525440d
--- /dev/null
+++ b/Task/Arithmetic-Complex/GAP/arithmetic-complex.gap
@@ -0,0 +1,19 @@
+# GAP knows gaussian integers, gaussian rationals (i.e. Q[i]), and cyclotomic fields. Here are some examples.
+# E(n) is an nth primitive root of 1
+i := Sqrt(-1);
+# E(4)
+(3 + 2*i)*(5 - 7*i);
+# 29-11*E(4)
+1/i;
+# -E(4)
+Sqrt(-3);
+# E(3)-E(3)^2
+
+i in GaussianIntegers;
+# true
+i/2 in GaussianIntegers;
+# false
+i/2 in GaussianRationals;
+# true
+Sqrt(-3) in Cyclotomics;
+# true
diff --git a/Task/Arithmetic-Complex/Groovy/arithmetic-complex-1.groovy b/Task/Arithmetic-Complex/Groovy/arithmetic-complex-1.groovy
new file mode 100644
index 0000000000..085c50b795
--- /dev/null
+++ b/Task/Arithmetic-Complex/Groovy/arithmetic-complex-1.groovy
@@ -0,0 +1,94 @@
+class Complex {
+ final Number real, imag
+
+ static final Complex I = [0,1] as Complex
+
+ Complex(Number real) { this(real, 0) }
+
+ Complex(real, imag) { this.real = real; this.imag = imag }
+
+ Complex plus (Complex c) { [real + c.real, imag + c.imag] as Complex }
+
+ Complex plus (Number n) { [real + n, imag] as Complex }
+
+ Complex minus (Complex c) { [real - c.real, imag - c.imag] as Complex }
+
+ Complex minus (Number n) { [real - n, imag] as Complex }
+
+ Complex multiply (Complex c) { [real*c.real - imag*c.imag , imag*c.real + real*c.imag] as Complex }
+
+ Complex multiply (Number n) { [real*n , imag*n] as Complex }
+
+ Complex div (Complex c) { this * c.recip() }
+
+ Complex div (Number n) { this * (1/n) }
+
+ Complex negative () { [-real, -imag] as Complex }
+
+ /** the complex conjugate of this complex number.
+ * Overloads the bitwise complement (~) operator. */
+ Complex bitwiseNegate () { [real, -imag] as Complex }
+
+ /** the magnitude of this complex number. */
+ // could also use Math.sqrt( (this * (~this)).real )
+ Number abs () { Math.sqrt( real*real + imag*imag ) }
+
+ /** the complex reciprocal of this complex number. */
+ Complex recip() { (~this) / ((this * (~this)).real) }
+
+ /** derived angle θ (theta) for polar form.
+ * Normalized to 0 ≤ θ < 2π. */
+ Number getTheta() {
+ def theta = Math.atan2(imag,real)
+ theta = theta < 0 ? theta + 2 * Math.PI : theta
+ }
+
+ /** derived magnitude ρ (rho) for polar form. */
+ Number getRho() { this.abs() }
+
+ /** Runs Euler's polar-to-Cartesian complex conversion,
+ * converting [ρ, θ] inputs into a [real, imag]-based complex number */
+ static Complex fromPolar(Number rho, Number theta) {
+ [rho * Math.cos(theta), rho * Math.sin(theta)] as Complex
+ }
+
+ /** Creates new complex with same magnitude ρ, but different angle θ */
+ Complex withTheta(Number theta) { fromPolar(this.rho, theta) }
+
+ /** Creates new complex with same angle θ, but different magnitude ρ */
+ Complex withRho(Number rho) { fromPolar(rho, this.theta) }
+
+ static Complex exp(Complex c) { fromPolar(Math.exp(c.real), c.imag) }
+
+ static Complex log(Complex c) { [Math.log(c.rho), c.theta] as Complex }
+
+ Complex power(Complex c) {
+ this == 0 && c != 0 \
+ ? [0] as Complex \
+ : c == 1 \
+ ? this \
+ : exp( log(this) * c )
+ }
+
+ Complex power(Number n) { this ** ([n, 0] as Complex) }
+
+ boolean equals(other) {
+ other != null && (other instanceof Complex \
+ ? [real, imag] == [other.real, other.imag] \
+ : other instanceof Number && [real, imag] == [other, 0])
+ }
+
+ int hashCode() { [real, imag].hashCode() }
+
+ String toString() {
+ def realPart = "${real}"
+ def imagPart = imag.abs() == 1 ? "i" : "${imag.abs()}i"
+ real == 0 && imag == 0 \
+ ? "0" \
+ : real == 0 \
+ ? (imag > 0 ? '' : "-") + imagPart \
+ : imag == 0 \
+ ? realPart \
+ : realPart + (imag > 0 ? " + " : " - ") + imagPart
+ }
+}
diff --git a/Task/Arithmetic-Complex/Groovy/arithmetic-complex-2.groovy b/Task/Arithmetic-Complex/Groovy/arithmetic-complex-2.groovy
new file mode 100644
index 0000000000..c42cc548b5
--- /dev/null
+++ b/Task/Arithmetic-Complex/Groovy/arithmetic-complex-2.groovy
@@ -0,0 +1,36 @@
+def tol = 0.000000001 // tolerance: acceptable "wrongness" to account for rounding error
+
+println 'Demo 1: functionality as requested'
+def a = [5,3] as Complex
+println 'a == ' + a
+def b = [0.5,6] as Complex
+println 'b == ' + b
+
+println "a + b == (${a}) + (${b}) == " + (a + b)
+println "a * b == (${a}) * (${b}) == " + (a * b)
+assert a + (-a) == 0
+println "-a == -(${a}) == " + (-a)
+assert (a * a.recip() - 1).abs() < tol
+println "1/a == (${a}).recip() == " + (a.recip())
+println()
+
+println 'Demo 2: other functionality not requested, but important for completeness'
+println "a - b == (${a}) - (${b}) == " + (a - b)
+println "a / b == (${a}) / (${b}) == " + (a / b)
+println "a ** b == (${a}) ** (${b}) == " + (a ** b)
+println 'a.real == ' + a.real
+println 'a.imag == ' + a.imag
+println 'a.rho == ' + a.rho
+println 'a.theta == ' + a.theta
+println '|a| == ' + a.abs()
+println 'a_bar == ' + ~a
+
+def rho = 10
+def piOverTheta = 3
+def theta = Math.PI / piOverTheta
+def fromPolar1 = Complex.fromPolar(rho, theta) // direct polar-to-cartesian conversion
+def fromPolar2 = Complex.exp(Complex.I * theta) * rho // Euler's equation
+println "rho*cos(theta) + rho*i*sin(theta) == ${rho}*cos(pi/${piOverTheta}) + ${rho}*i*sin(pi/${piOverTheta}) == " + fromPolar1
+println "rho * exp(i * theta) == ${rho} * exp(i * pi/${piOverTheta}) == " + fromPolar2
+assert (fromPolar1 - fromPolar2).abs() < tol
+println()
diff --git a/Task/Arithmetic-Complex/IDL/arithmetic-complex.idl b/Task/Arithmetic-Complex/IDL/arithmetic-complex.idl
new file mode 100644
index 0000000000..446f3c6dc9
--- /dev/null
+++ b/Task/Arithmetic-Complex/IDL/arithmetic-complex.idl
@@ -0,0 +1,10 @@
+x=complex(1,1)
+ y=complex(!pi,1.2)
+ print,x+y
+( 4.14159, 2.20000)
+ print,x*y
+( 1.94159, 4.34159)
+ print,-x
+( -1.00000, -1.00000)
+ print,1/x
+( 0.500000, -0.500000)
diff --git a/Task/Arithmetic-Complex/Icon/arithmetic-complex-1.icon b/Task/Arithmetic-Complex/Icon/arithmetic-complex-1.icon
new file mode 100644
index 0000000000..51a0282957
--- /dev/null
+++ b/Task/Arithmetic-Complex/Icon/arithmetic-complex-1.icon
@@ -0,0 +1,22 @@
+procedure main()
+
+SetupComplex()
+a := complex(1,2)
+b := complex(3,4)
+
+c := complex(&pi,1.5)
+d := complex(1)
+e := complex(,1)
+
+every v := !"abcde" do write(v," := ",cpxstr(variable(v)))
+
+write("a+b := ", cpxstr(cpxadd(a,b)))
+write("a-b := ", cpxstr(cpxsub(a,b)))
+write("a*b := ", cpxstr(cpxmul(a,b)))
+write("a/b := ", cpxstr(cpxdiv(a,b)))
+write("neg(a) := ", cpxstr(cpxneg(a)))
+write("inv(a) := ", cpxstr(cpxinv(a)))
+write("conj(a) := ", cpxstr(cpxconj(a)))
+write("abs(a) := ", cpxabs(a))
+write("neg(1) := ", cpxstr(cpxneg(1)))
+end
diff --git a/Task/Arithmetic-Complex/Icon/arithmetic-complex-2.icon b/Task/Arithmetic-Complex/Icon/arithmetic-complex-2.icon
new file mode 100644
index 0000000000..dce6305779
--- /dev/null
+++ b/Task/Arithmetic-Complex/Icon/arithmetic-complex-2.icon
@@ -0,0 +1,27 @@
+link complex # for complex number support
+
+procedure SetupComplex() #: used to setup safe complex
+COMPLEX() # replace complex record constructor
+SetupComplex := 1 # never call here again
+return
+end
+
+procedure COMPLEX(rpart,ipart) #: new safe record constructor and coercion
+initial complex :=: COMPLEX # get in front of record constructor
+return if /ipart & (type(rpart) == "complex")
+ then rpart # already complex
+ else COMPLEX( real(\rpart | 0.0), real(\ipart|0) ) # create a new complex number
+end
+
+procedure cpxneg(z) #: negate z
+ z := complex(z) # coerce
+ return complex( -z.rpart, -z.ipart)
+end
+
+procedure cpxinv(z) #: inverse of z
+ local denom
+ z := complex(z) # coerce
+
+ denom := z.rpart ^ 2 + z.ipart ^ 2
+ return complex(z.rpart / denom, z.ipart / denom)
+end
diff --git a/Task/Arithmetic-Complex/J/arithmetic-complex.j b/Task/Arithmetic-Complex/J/arithmetic-complex.j
new file mode 100644
index 0000000000..1e48b12c99
--- /dev/null
+++ b/Task/Arithmetic-Complex/J/arithmetic-complex.j
@@ -0,0 +1,10 @@
+ x=: 1j1
+ y=: 3.14159j1.2
+ x+y
+4.14159j2.2
+ x*y
+1.94159j4.34159
+ %x
+0.5j_0.5
+ -x
+_1j_1
diff --git a/Task/Arithmetic-Complex/Liberty-BASIC/arithmetic-complex.liberty b/Task/Arithmetic-Complex/Liberty-BASIC/arithmetic-complex.liberty
new file mode 100644
index 0000000000..bdec8aa4d1
--- /dev/null
+++ b/Task/Arithmetic-Complex/Liberty-BASIC/arithmetic-complex.liberty
@@ -0,0 +1,51 @@
+mainwin 50 10
+
+print " Adding"
+call cprint cadd$( complex$( 1, 1), complex$( 3.14159265, 1.2))
+print " Multiplying"
+call cprint cmulti$( complex$( 1, 1), complex$( 3.14159265, 1.2))
+print " Inverting"
+call cprint cinv$( complex$( 1, 1))
+print " Negating"
+call cprint cneg$( complex$( 1, 1))
+
+end
+
+sub cprint cx$
+ print "( "; word$( cx$, 1); " + i *"; word$( cx$, 2); ")"
+end sub
+
+function complex$( a , bj )
+''complex number string-object constructor
+ complex$ = str$( a ) ; " " ; str$( bj )
+end function
+
+function cadd$( a$ , b$ )
+ ar = val( word$( a$ , 1 ) )
+ ai = val( word$( a$ , 2 ) )
+ br = val( word$( b$ , 1 ) )
+ bi = val( word$( b$ , 2 ) )
+ cadd$ = complex$( ar + br , ai + bi )
+end function
+
+function cmulti$( a$ , b$ )
+ ar = val( word$( a$ , 1 ) )
+ ai = val( word$( a$ , 2 ) )
+ br = val( word$( b$ , 1 ) )
+ bi = val( word$( b$ , 2 ) )
+ cmulti$ = complex$( ar * br - ai * bi _
+ , ar * bi + ai * br )
+end function
+
+function cneg$( a$)
+ ar = val( word$( a$ , 1 ) )
+ ai = val( word$( a$ , 2 ) )
+ cneg$ =complex$( 0 -ar, 0 -ai)
+end function
+
+function cinv$( a$)
+ ar = val( word$( a$ , 1 ) )
+ ai = val( word$( a$ , 2 ) )
+ D =ar^2 +ai^2
+ cinv$ =complex$( ar /D , 0 -ai /D )
+end function
diff --git a/Task/Arithmetic-Complex/Maple/arithmetic-complex-1.maple b/Task/Arithmetic-Complex/Maple/arithmetic-complex-1.maple
new file mode 100644
index 0000000000..617211d721
--- /dev/null
+++ b/Task/Arithmetic-Complex/Maple/arithmetic-complex-1.maple
@@ -0,0 +1,2 @@
+x := 1+I;
+y := Pi+I*1.2;
diff --git a/Task/Arithmetic-Complex/Maple/arithmetic-complex-2.maple b/Task/Arithmetic-Complex/Maple/arithmetic-complex-2.maple
new file mode 100644
index 0000000000..e8bfaa3a9d
--- /dev/null
+++ b/Task/Arithmetic-Complex/Maple/arithmetic-complex-2.maple
@@ -0,0 +1,4 @@
+x*y;
+ ==> (1 + I) (Pi + 1.2 I)
+simplify(x*y);
+ ==> 1.941592654 + 4.341592654 I
diff --git a/Task/Arithmetic-Complex/Maple/arithmetic-complex-3.maple b/Task/Arithmetic-Complex/Maple/arithmetic-complex-3.maple
new file mode 100644
index 0000000000..87eea46285
--- /dev/null
+++ b/Task/Arithmetic-Complex/Maple/arithmetic-complex-3.maple
@@ -0,0 +1,4 @@
+x+y;
+x*y;
+-x;
+1/x;
diff --git a/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-1.mathematica b/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-1.mathematica
new file mode 100644
index 0000000000..2d1676d719
--- /dev/null
+++ b/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-1.mathematica
@@ -0,0 +1,11 @@
+x=1+2I
+y=3+4I
+
+x+y => 4 + 6 I
+x-y => -2 - 2 I
+y x => -5 + 10 I
+y/x => 11/5 - (2 I)/5
+x^3 => -11 - 2 I
+y^4 => -527 - 336 I
+x^y => (1 + 2 I)^(3 + 4 I)
+N[x^y] => 0.12901 + 0.0339241 I
diff --git a/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-2.mathematica b/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-2.mathematica
new file mode 100644
index 0000000000..9a01c0ce4e
--- /dev/null
+++ b/Task/Arithmetic-Complex/Mathematica/arithmetic-complex-2.mathematica
@@ -0,0 +1,9 @@
+Exp Log
+Sin Cos Tan Csc Sec Cot
+ArcSin ArcCos ArcTan ArcCsc ArcSec ArcCot
+Sinh Cosh Tanh Csch Sech Coth
+ArcSinh ArcCosh ArcTanh ArcCsch ArcSech ArcCoth
+Sinc
+Haversine InverseHaversine
+Factorial Gamma PolyGamma LogGamma
+Erf BarnesG Hyperfactorial Zeta ProductLog RamanujanTauL
diff --git a/Task/Arithmetic-Complex/Maxima/arithmetic-complex.maxima b/Task/Arithmetic-Complex/Maxima/arithmetic-complex.maxima
new file mode 100644
index 0000000000..7dfb7d243e
--- /dev/null
+++ b/Task/Arithmetic-Complex/Maxima/arithmetic-complex.maxima
@@ -0,0 +1,44 @@
+z1: 5 + 2 * %i;
+2*%i+5
+
+z2: 3 - 7 * %i;
+3-7*%i
+
+carg(z1);
+atan(2/5)
+
+cabs(z1);
+sqrt(29)
+
+rectform(z1 * z2);
+29-29*%i
+
+polarform(z1);
+sqrt(29)*%e^(%i*atan(2/5))
+
+conjugate(z1);
+5-2*%i
+
+z1 + z2;
+8-5*%i
+
+z1 - z2;
+9*%i+2
+
+z1 * z2;
+(3-7*%i)*(2*%i+5)
+
+z1 * z2, rectform;
+29-29*%i
+
+z1 / z2;
+(2*%i+5)/(3-7*%i)
+
+z1 / z2, rectform;
+(41*%i)/58+1/58
+
+realpart(z1);
+5
+
+imagpart(z1);
+2
diff --git a/Task/Arithmetic-Complex/Modula-2/arithmetic-complex.mod2 b/Task/Arithmetic-Complex/Modula-2/arithmetic-complex.mod2
new file mode 100644
index 0000000000..de5fc2b329
--- /dev/null
+++ b/Task/Arithmetic-Complex/Modula-2/arithmetic-complex.mod2
@@ -0,0 +1,66 @@
+MODULE complex;
+
+IMPORT InOut;
+
+TYPE Complex = RECORD R, Im : REAL END;
+
+VAR z : ARRAY [0..3] OF Complex;
+
+PROCEDURE ShowComplex (str : ARRAY OF CHAR; p : Complex);
+
+BEGIN
+ InOut.WriteString (str); InOut.WriteString (" = ");
+ InOut.WriteReal (p.R, 6, 2);
+ IF p.Im >= 0.0 THEN InOut.WriteString (" + ") ELSE InOut.WriteString (" - ") END;
+ InOut.WriteReal (ABS (p.Im), 6, 2); InOut.WriteString (" i ");
+ InOut.WriteLn; InOut.WriteBf
+END ShowComplex;
+
+PROCEDURE AddComplex (x1, x2 : Complex; VAR x3 : Complex);
+
+BEGIN
+ x3.R := x1.R + x2.R;
+ x3.Im := x1.Im + x2.Im
+END AddComplex;
+
+PROCEDURE SubComplex (x1, x2 : Complex; VAR x3 : Complex);
+
+BEGIN
+ x3.R := x1.R - x2.R;
+ x3.Im := x1.Im - x2.Im
+END SubComplex;
+
+PROCEDURE MulComplex (x1, x2 : Complex; VAR x3 : Complex);
+
+BEGIN
+ x3.R := x1.R * x2.R - x1.Im * x2.Im;
+ x3.Im := x1.R * x2.Im + x1.Im * x2.R
+END MulComplex;
+
+PROCEDURE InvComplex (x1 : Complex; VAR x2 : Complex);
+
+BEGIN
+ x2.R := x1.R / (x1.R * x1.R + x1.Im * x1.Im);
+ x2.Im := -1.0 * x1.Im / (x1.R * x1.R + x1.Im * x1.Im)
+END InvComplex;
+
+PROCEDURE NegComplex (x1 : Complex; VAR x2 : Complex);
+
+BEGIN
+ x2.R := - x1.R; x2.Im := - x1.Im
+END NegComplex;
+
+BEGIN
+ InOut.WriteString ("Enter two complex numbers : ");
+ InOut.WriteBf;
+ InOut.ReadReal (z[0].R); InOut.ReadReal (z[0].Im);
+ InOut.ReadReal (z[1].R); InOut.ReadReal (z[1].Im);
+ ShowComplex ("z1", z[0]); ShowComplex ("z2", z[1]);
+ InOut.WriteLn;
+ AddComplex (z[0], z[1], z[2]); ShowComplex ("z1 + z2", z[2]);
+ SubComplex (z[0], z[1], z[2]); ShowComplex ("z1 - z2", z[2]);
+ MulComplex (z[0], z[1], z[2]); ShowComplex ("z1 * z2", z[2]);
+ InvComplex (z[0], z[2]); ShowComplex ("1 / z1", z[2]);
+ NegComplex (z[0], z[2]); ShowComplex (" - z1", z[2]);
+ InOut.WriteLn
+END complex.
diff --git a/Task/Arithmetic-Integer/FALSE/arithmetic-integer.false b/Task/Arithmetic-Integer/FALSE/arithmetic-integer.false
new file mode 100644
index 0000000000..44472f01f4
--- /dev/null
+++ b/Task/Arithmetic-Integer/FALSE/arithmetic-integer.false
@@ -0,0 +1,8 @@
+12 7
+\$@$@$@$@$@$@$@$@$@$@\ { 6 copies }
+"sum = "+."
+difference = "-."
+product = "*."
+quotient = "/."
+modulus = "/*-."
+"
diff --git a/Task/Arithmetic-Integer/Factor/arithmetic-integer-1.factor b/Task/Arithmetic-Integer/Factor/arithmetic-integer-1.factor
new file mode 100644
index 0000000000..b8f74e2c70
--- /dev/null
+++ b/Task/Arithmetic-Integer/Factor/arithmetic-integer-1.factor
@@ -0,0 +1,17 @@
+USING: combinators io kernel math math.functions math.order
+math.parser prettyprint ;
+
+"a=" "b=" [ write readln string>number ] bi@
+{
+ [ + "sum: " write . ]
+ [ - "difference: " write . ]
+ [ * "product: " write . ]
+ [ / "quotient: " write . ]
+ [ /i "integer quotient: " write . ]
+ [ rem "remainder: " write . ]
+ [ mod "modulo: " write . ]
+ [ max "maximum: " write . ]
+ [ min "minimum: " write . ]
+ [ gcd "gcd: " write . drop ]
+ [ lcm "lcm: " write . ]
+} 2cleave
diff --git a/Task/Arithmetic-Integer/Factor/arithmetic-integer-2.factor b/Task/Arithmetic-Integer/Factor/arithmetic-integer-2.factor
new file mode 100644
index 0000000000..8cd761db5c
--- /dev/null
+++ b/Task/Arithmetic-Integer/Factor/arithmetic-integer-2.factor
@@ -0,0 +1,13 @@
+a=8
+b=12
+sum: 20
+difference: -4
+product: 96
+quotient: 2/3
+integer quotient: 0
+remainder: 8
+modulo: 8
+maximum: 12
+minimum: 8
+gcd: 4
+lcm: 24
diff --git a/Task/Arithmetic-Integer/Frink/arithmetic-integer-1.frink b/Task/Arithmetic-Integer/Frink/arithmetic-integer-1.frink
new file mode 100644
index 0000000000..8eff493125
--- /dev/null
+++ b/Task/Arithmetic-Integer/Frink/arithmetic-integer-1.frink
@@ -0,0 +1,7 @@
+[a,b] = input["Enter numbers",["a","b"]]
+ops=["+", "-", "*", "/", "div" ,"mod" ,"^"]
+for op = ops
+{
+ str = "$a $op $b"
+ println["$str = " + eval[str]]
+}
diff --git a/Task/Arithmetic-Integer/Frink/arithmetic-integer-2.frink b/Task/Arithmetic-Integer/Frink/arithmetic-integer-2.frink
new file mode 100644
index 0000000000..d00fa36cf1
--- /dev/null
+++ b/Task/Arithmetic-Integer/Frink/arithmetic-integer-2.frink
@@ -0,0 +1,7 @@
+10 + 20 = 30
+10 - 20 = -10
+10 * 20 = 200
+10 / 20 = 1/2 (exactly 0.5)
+10 div 20 = 0
+10 mod 20 = 10
+10 ^ 20 = 100000000000000000000
diff --git a/Task/Arithmetic-Integer/GAP/arithmetic-integer.gap b/Task/Arithmetic-Integer/GAP/arithmetic-integer.gap
new file mode 100644
index 0000000000..03b9f4a2d5
--- /dev/null
+++ b/Task/Arithmetic-Integer/GAP/arithmetic-integer.gap
@@ -0,0 +1,15 @@
+run := function()
+ local a, b, f;
+ f := InputTextUser();
+ Print("a =\n");
+ a := Int(Chomp(ReadLine(f)));
+ Print("b =\n");
+ b := Int(Chomp(ReadLine(f)));
+ Display(Concatenation(String(a), " + ", String(b), " = ", String(a + b)));
+ Display(Concatenation(String(a), " - ", String(b), " = ", String(a - b)));
+ Display(Concatenation(String(a), " * ", String(b), " = ", String(a * b)));
+ Display(Concatenation(String(a), " / ", String(b), " = ", String(QuoInt(a, b)))); # toward 0
+ Display(Concatenation(String(a), " mod ", String(b), " = ", String(RemInt(a, b)))); # nonnegative
+ Display(Concatenation(String(a), " ^ ", String(b), " = ", String(a ^ b)));
+ CloseStream(f);
+end;
diff --git a/Task/Arithmetic-Integer/Groovy/arithmetic-integer-1.groovy b/Task/Arithmetic-Integer/Groovy/arithmetic-integer-1.groovy
new file mode 100644
index 0000000000..60b5d42676
--- /dev/null
+++ b/Task/Arithmetic-Integer/Groovy/arithmetic-integer-1.groovy
@@ -0,0 +1,14 @@
+def arithmetic = { a, b ->
+ println """
+ a + b = ${a} + ${b} = ${a + b}
+ a - b = ${a} - ${b} = ${a - b}
+ a * b = ${a} * ${b} = ${a * b}
+ a / b = ${a} / ${b} = ${a / b} !!! Converts to floating point!
+(int)(a / b) = (int)(${a} / ${b}) = ${(int)(a / b)} !!! Truncates downward after the fact
+ a.intdiv(b) = ${a}.intdiv(${b}) = ${a.intdiv(b)} !!! Behaves as if truncating downward, actual implementation varies
+ a % b = ${a} % ${b} = ${a % b}
+
+Exponentiation is also a base arithmetic operation in Groovy, so:
+ a ** b = ${a} ** ${b} = ${a ** b}
+"""
+}
diff --git a/Task/Arithmetic-Integer/Groovy/arithmetic-integer-2.groovy b/Task/Arithmetic-Integer/Groovy/arithmetic-integer-2.groovy
new file mode 100644
index 0000000000..884dcbc243
--- /dev/null
+++ b/Task/Arithmetic-Integer/Groovy/arithmetic-integer-2.groovy
@@ -0,0 +1 @@
+arithmetic(5,3)
diff --git a/Task/Arithmetic-Integer/Haxe/arithmetic-integer.haxe b/Task/Arithmetic-Integer/Haxe/arithmetic-integer.haxe
new file mode 100644
index 0000000000..d18971aa92
--- /dev/null
+++ b/Task/Arithmetic-Integer/Haxe/arithmetic-integer.haxe
@@ -0,0 +1,13 @@
+class BasicIntegerArithmetic {
+ public static function main() {
+ var args =Sys.args();
+ if (args.length < 2) return;
+ var a = Std.parseFloat(args[0]);
+ var b = Std.parseFloat(args[1]);
+ trace("a+b = " + (a+b));
+ trace("a-b = " + (a-b));
+ trace("a*b = " + (a*b));
+ trace("a/b = " + (a/b));
+ trace("a%b = " + (a%b));
+ }
+}
diff --git a/Task/Arithmetic-Integer/HicEst/arithmetic-integer-1.hicest b/Task/Arithmetic-Integer/HicEst/arithmetic-integer-1.hicest
new file mode 100644
index 0000000000..9eba7b52df
--- /dev/null
+++ b/Task/Arithmetic-Integer/HicEst/arithmetic-integer-1.hicest
@@ -0,0 +1,13 @@
+DLG(Edit=A, Edit=B, TItle='Enter numeric A and B')
+WRITE(Name) A, B
+WRITE() ' A + B = ', A + B
+WRITE() ' A - B = ', A - B
+WRITE() ' A * B = ', A * B
+WRITE() ' A / B = ', A / B ! no truncation
+WRITE() 'truncate A / B = ', INT(A / B) ! truncates towards 0
+WRITE() 'round next A / B = ', NINT(A / B) ! truncates towards next integer
+WRITE() 'round down A / B = ', FLOOR(A / B) ! truncates towards minus infinity
+WRITE() 'round up A / B = ', CEILING(A / B) ! truncates towards plus infinity
+WRITE() 'remainder of A / B = ', MOD(A, B) ! same sign as A
+WRITE() 'A to the power of B = ', A ^ B
+WRITE() 'A to the power of B = ', A ** B
diff --git a/Task/Arithmetic-Integer/HicEst/arithmetic-integer-2.hicest b/Task/Arithmetic-Integer/HicEst/arithmetic-integer-2.hicest
new file mode 100644
index 0000000000..3df70d1ff6
--- /dev/null
+++ b/Task/Arithmetic-Integer/HicEst/arithmetic-integer-2.hicest
@@ -0,0 +1,12 @@
+A=5; B=-4;
+ A + B = 1
+ A - B = 9
+ A * B = -20
+ A / B = -1.25
+truncate A / B = -1
+round next A / B = -1
+round down A / B = -2
+round up A / B = -1
+remainder of A / B = 1
+A to the power of B = 16E-4
+A to the power of B = 16E-4
diff --git a/Task/Arithmetic-Integer/Icon/arithmetic-integer.icon b/Task/Arithmetic-Integer/Icon/arithmetic-integer.icon
new file mode 100644
index 0000000000..b40bbed194
--- /dev/null
+++ b/Task/Arithmetic-Integer/Icon/arithmetic-integer.icon
@@ -0,0 +1,13 @@
+procedure main()
+writes("Input 1st integer a := ")
+a := integer(read())
+writes("Input 2nd integer b := ")
+b := integer(read())
+
+write(" a + b = ",a+b)
+write(" a - b = ",a-b)
+write(" a * b = ",a*b)
+write(" a / b = ",a/b, " rounds toward 0")
+write(" a % b = ",a%b, " remainder sign matches a")
+write(" a ^ b = ",a^b)
+end
diff --git a/Task/Arithmetic-Integer/Inform-7/arithmetic-integer.inf b/Task/Arithmetic-Integer/Inform-7/arithmetic-integer.inf
new file mode 100644
index 0000000000..a3ed14b6e0
--- /dev/null
+++ b/Task/Arithmetic-Integer/Inform-7/arithmetic-integer.inf
@@ -0,0 +1,24 @@
+Enter Two Numbers is a room.
+
+Numerically entering is an action applying to one number. Understand "[number]" as numerically entering.
+
+The first number is a number that varies.
+
+After numerically entering for the first time:
+ now the first number is the number understood.
+
+After numerically entering for the second time:
+ let A be the first number;
+ let B be the number understood;
+ say "[A] + [B] = [A + B]."; [operator syntax]
+ say "[A] - [B] = [A minus B]."; [English syntax]
+ let P be given by P = A * B where P is a number; [inline equation]
+ say "[A] * [B] = [P].";
+ let Q be given by the Division Formula; [named equation]
+ say "[A] / [B] = [Q].";
+ say "[A] mod [B] = [remainder after dividing A by B].";
+ end the story.
+
+Equation - Division Formula
+ Q = A / B
+where Q is a number, A is a number, and B is a number.
diff --git a/Task/Arithmetic-Integer/J/arithmetic-integer-1.j b/Task/Arithmetic-Integer/J/arithmetic-integer-1.j
new file mode 100644
index 0000000000..45320c252e
--- /dev/null
+++ b/Task/Arithmetic-Integer/J/arithmetic-integer-1.j
@@ -0,0 +1 @@
+calc =: + , - , * , <.@% , |~ , ^
diff --git a/Task/Arithmetic-Integer/J/arithmetic-integer-2.j b/Task/Arithmetic-Integer/J/arithmetic-integer-2.j
new file mode 100644
index 0000000000..f4d5b7779f
--- /dev/null
+++ b/Task/Arithmetic-Integer/J/arithmetic-integer-2.j
@@ -0,0 +1,2 @@
+ 17 calc 3
+20 14 51 5 2 4913
diff --git a/Task/Arithmetic-Integer/J/arithmetic-integer-3.j b/Task/Arithmetic-Integer/J/arithmetic-integer-3.j
new file mode 100644
index 0000000000..553e36ec43
--- /dev/null
+++ b/Task/Arithmetic-Integer/J/arithmetic-integer-3.j
@@ -0,0 +1,11 @@
+labels =: ];.2 'Sum: Difference: Product: Quotient: Remainder: Exponentiation: '
+combine =: ,. ":@,.
+bia =: labels combine calc
+
+ 17 bia 3
+Sum: 20
+Difference: 14
+Product: 51
+Quotient: 5
+Remainder: 2
+Exponentiation: 4913
diff --git a/Task/Arithmetic-Integer/LSE64/arithmetic-integer.lse64 b/Task/Arithmetic-Integer/LSE64/arithmetic-integer.lse64
new file mode 100644
index 0000000000..05b086764d
--- /dev/null
+++ b/Task/Arithmetic-Integer/LSE64/arithmetic-integer.lse64
@@ -0,0 +1,10 @@
+over : 2 pick
+2dup : over over
+
+arithmetic : \
+ " A=" ,t over , sp " B=" ,t dup , nl \
+ " A+B=" ,t 2dup + , nl \
+ " A-B=" ,t 2dup - , nl \
+ " A*B=" ,t 2dup * , nl \
+ " A/B=" ,t 2dup / , nl \
+ " A%B=" ,t % , nl
diff --git a/Task/Arithmetic-Integer/Liberty-BASIC/arithmetic-integer.liberty b/Task/Arithmetic-Integer/Liberty-BASIC/arithmetic-integer.liberty
new file mode 100644
index 0000000000..90b480548c
--- /dev/null
+++ b/Task/Arithmetic-Integer/Liberty-BASIC/arithmetic-integer.liberty
@@ -0,0 +1,9 @@
+input "Enter the first integer: "; first
+input "Enter the second integer: "; second
+
+print "The sum is " ; first + second
+print "The difference is " ; first -second
+print "The product is " ; first *second
+if second <>0 then print "The integer quotient is " ; int( first /second); " (rounds towards 0)" else print "Division by zero not allowed."
+print "The remainder is " ; first MOD second; " (sign matches first operand)"
+print "The first raised to the power of the second is " ; first ^second
diff --git a/Task/Arithmetic-Integer/Logo/arithmetic-integer.logo b/Task/Arithmetic-Integer/Logo/arithmetic-integer.logo
new file mode 100644
index 0000000000..6f7521d0d1
--- /dev/null
+++ b/Task/Arithmetic-Integer/Logo/arithmetic-integer.logo
@@ -0,0 +1,9 @@
+to operate :a :b
+ (print [a =] :a)
+ (print [b =] :b)
+ (print [a + b =] :a + :b)
+ (print [a - b =] :a - :b)
+ (print [a * b =] :a * :b)
+ (print [a / b =] int :a / :b)
+ (print [a mod b =] modulo :a :b)
+end
diff --git a/Task/Arithmetic-Integer/M4/arithmetic-integer-1.m4 b/Task/Arithmetic-Integer/M4/arithmetic-integer-1.m4
new file mode 100644
index 0000000000..53ea1fcdf0
--- /dev/null
+++ b/Task/Arithmetic-Integer/M4/arithmetic-integer-1.m4
@@ -0,0 +1,5 @@
+eval(A+B)
+eval(A-B)
+eval(A*B)
+eval(A/B)
+eval(A%B)
diff --git a/Task/Arithmetic-Integer/M4/arithmetic-integer-2.m4 b/Task/Arithmetic-Integer/M4/arithmetic-integer-2.m4
new file mode 100644
index 0000000000..964c65119d
--- /dev/null
+++ b/Task/Arithmetic-Integer/M4/arithmetic-integer-2.m4
@@ -0,0 +1,3 @@
+define(`A', 4)dnl
+define(`B', 6)dnl
+include(`operations.m4')
diff --git a/Task/Arithmetic-Integer/MAXScript/arithmetic-integer.max b/Task/Arithmetic-Integer/MAXScript/arithmetic-integer.max
new file mode 100644
index 0000000000..46fb6f0a9f
--- /dev/null
+++ b/Task/Arithmetic-Integer/MAXScript/arithmetic-integer.max
@@ -0,0 +1,8 @@
+x = getKBValue prompt:"First number"
+y = getKBValue prompt:"Second number:"
+
+format "Sum: %\n" (x + y)
+format "Difference: %\n" (x - y)
+format "Product: %\n" (x * y)
+format "Quotient: %\n" (x / y)
+format "Remainder: %\n" (mod x y)
diff --git a/Task/Arithmetic-Integer/ML-I/arithmetic-integer.ml b/Task/Arithmetic-Integer/ML-I/arithmetic-integer.ml
new file mode 100644
index 0000000000..cbd315f61d
--- /dev/null
+++ b/Task/Arithmetic-Integer/ML-I/arithmetic-integer.ml
@@ -0,0 +1,15 @@
+MCSKIP "WITH" NL
+"" Arithmetic/Integer
+"" assumes macros on input stream 1, terminal on stream 2
+MCSKIP MT,<>
+MCINS %.
+MCDEF SL SPACES NL AS DoIt();
+Input an integer: 15;
+Input another integer: 12;
+Sum = 27
+Difference = 3
+Product = 180
+Quotient = 1
+Remainder = 3
+>
diff --git a/Task/Arithmetic-Integer/Mathematica/arithmetic-integer.mathematica b/Task/Arithmetic-Integer/Mathematica/arithmetic-integer.mathematica
new file mode 100644
index 0000000000..43cbb29286
--- /dev/null
+++ b/Task/Arithmetic-Integer/Mathematica/arithmetic-integer.mathematica
@@ -0,0 +1,9 @@
+a = Input["Give me an integer please!"];
+b = Input["Give me another integer please!"];
+Print["You gave me ", a, " and ", b];
+Print["sum: ", a + b];
+Print["difference: ", a - b];
+Print["product: ", a b];
+Print["integer quotient: ", IntegerPart[a/b]];
+Print["remainder: ", Mod[a, b]];
+Print["exponentiation: ", a^b];
diff --git a/Task/Arithmetic-Integer/Maxima/arithmetic-integer.maxima b/Task/Arithmetic-Integer/Maxima/arithmetic-integer.maxima
new file mode 100644
index 0000000000..251702785e
--- /dev/null
+++ b/Task/Arithmetic-Integer/Maxima/arithmetic-integer.maxima
@@ -0,0 +1,10 @@
+block(
+ [a: read("a"), b: read("b")],
+ print(a + b),
+ print(a - b),
+ print(a * b),
+ print(a / b),
+ print(quotient(a, b)),
+ print(remainder(a, b)),
+ a^b
+);
diff --git a/Task/Arithmetic-Integer/Mercury/arithmetic-integer.mercury b/Task/Arithmetic-Integer/Mercury/arithmetic-integer.mercury
new file mode 100644
index 0000000000..558bec0439
--- /dev/null
+++ b/Task/Arithmetic-Integer/Mercury/arithmetic-integer.mercury
@@ -0,0 +1,42 @@
+:- module arith_int.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int, list, string.
+
+main(!IO) :-
+ io.command_line_arguments(Args, !IO),
+ ( if
+ Args = [AStr, BStr],
+ string.to_int(AStr, A),
+ string.to_int(BStr, B)
+ then
+ io.format("A + B = %d\n", [i(A + B)], !IO),
+ io.format("A - B = %d\n", [i(A - B)], !IO),
+ io.format("A * B = %d\n", [i(A * B)], !IO),
+
+ % Division: round towards zero.
+ %
+ io.format("A / B = %d\n", [i(A / B)], !IO),
+
+ % Division: round towards minus infinity.
+ %
+ io.format("A div B = %d\n", [i(A div B)], !IO),
+
+ % Modulus: X mod Y = X - (X div Y) * Y.
+ %
+ io.format("A mod B = %d\n", [i(A mod B)], !IO),
+
+ % Remainder: X rem Y = X - (X / Y) * Y.
+ %
+ io.format("A rem B = %d\n", [i(A rem B)], !IO),
+
+ % Exponentiation is done using the function int.pow/2.
+ %
+ io.format("A `pow` B = %d\n", [i(A `pow` B)], !IO)
+ else
+ io.set_exit_status(1, !IO)
+ ).
diff --git a/Task/Arithmetic-Integer/Metafont/arithmetic-integer.metafont b/Task/Arithmetic-Integer/Metafont/arithmetic-integer.metafont
new file mode 100644
index 0000000000..b03551472f
--- /dev/null
+++ b/Task/Arithmetic-Integer/Metafont/arithmetic-integer.metafont
@@ -0,0 +1,18 @@
+string s[];
+message "input number a: ";
+s1 := readstring;
+message "input number b: ";
+s2 := readstring;
+a := scantokens s1;
+b := scantokens s2;
+
+def outp(expr op) =
+ message "a " & op & " b = " & decimal(a scantokens(op) b) enddef;
+
+outp("+");
+outp("-");
+outp("*");
+outp("div");
+outp("mod");
+
+end
diff --git a/Task/Arithmetic-Integer/Modula-2/arithmetic-integer.mod2 b/Task/Arithmetic-Integer/Modula-2/arithmetic-integer.mod2
new file mode 100644
index 0000000000..e7bf2cfa1d
--- /dev/null
+++ b/Task/Arithmetic-Integer/Modula-2/arithmetic-integer.mod2
@@ -0,0 +1,17 @@
+MODULE ints;
+
+IMPORT InOut;
+
+VAR a, b : INTEGER;
+
+BEGIN
+ InOut.WriteString ("Enter two integer numbers : "); InOut.WriteBf;
+ InOut.ReadInt (a);
+ InOut.ReadInt (b);
+ InOut.WriteString ("a + b = "); InOut.WriteInt (a + b, 9); InOut.WriteLn;
+ InOut.WriteString ("a - b = "); InOut.WriteInt (a - b, 9); InOut.WriteLn;
+ InOut.WriteString ("a * b = "); InOut.WriteInt (a * b, 9); InOut.WriteLn;
+ InOut.WriteString ("a / b = "); InOut.WriteInt (a DIV b, 9); InOut.WriteLn;
+ InOut.WriteString ("a MOD b = "); InOut.WriteInt (a MOD b, 9); InOut.WriteLn;
+ InOut.WriteLn;
+END ints.
diff --git a/Task/Arithmetic-Integer/Modula-3/arithmetic-integer.mod3 b/Task/Arithmetic-Integer/Modula-3/arithmetic-integer.mod3
new file mode 100644
index 0000000000..97c0973dc9
--- /dev/null
+++ b/Task/Arithmetic-Integer/Modula-3/arithmetic-integer.mod3
@@ -0,0 +1,15 @@
+MODULE Arith EXPORTS Main;
+
+IMPORT IO, Fmt;
+
+VAR a, b: INTEGER;
+
+BEGIN
+ a := IO.GetInt();
+ b := IO.GetInt();
+ IO.Put("a+b = " & Fmt.Int(a + b) & "\n");
+ IO.Put("a-b = " & Fmt.Int(a - b) & "\n");
+ IO.Put("a*b = " & Fmt.Int(a * b) & "\n");
+ IO.Put("a DIV b = " & Fmt.Int(a DIV b) & "\n");
+ IO.Put("a MOD b = " & Fmt.Int(a MOD b) & "\n");
+END Arith.
diff --git a/Task/Arithmetic-Rational/GAP/arithmetic-rational.gap b/Task/Arithmetic-Rational/GAP/arithmetic-rational.gap
new file mode 100644
index 0000000000..1ff53cb71f
--- /dev/null
+++ b/Task/Arithmetic-Rational/GAP/arithmetic-rational.gap
@@ -0,0 +1,4 @@
+2/3 in Rationals;
+# true
+2/3 + 3/4;
+# 17/12
diff --git a/Task/Arithmetic-Rational/Groovy/arithmetic-rational-1.groovy b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-1.groovy
new file mode 100644
index 0000000000..150460ab5a
--- /dev/null
+++ b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-1.groovy
@@ -0,0 +1,130 @@
+class Rational implements Comparable {
+ final BigInteger numerator, denominator
+
+ static final Rational ONE = new Rational(1, 1)
+
+ static final Rational ZERO = new Rational(0, 1)
+
+ Rational(BigInteger whole) { this(whole, 1) }
+
+ Rational(BigDecimal decimal) {
+ this(
+ decimal.scale() < 0 ? decimal.unscaledValue()*10**(-decimal.scale()) : decimal.unscaledValue(),
+ decimal.scale() < 0 ? 1 : 10**(decimal.scale())
+ )
+ }
+
+ Rational(num, denom) {
+ assert denom != 0 : "Denominator must not be 0"
+ def values = denom > 0 ? [num, denom] : [-num, -denom] //reduce(num, denom)
+
+ numerator = values[0]
+ denominator = values[1]
+ }
+
+ private List reduce(BigInteger num, BigInteger denom) {
+ BigInteger sign = ((num < 0) != (denom < 0)) ? -1 : 1
+ num = num.abs()
+ denom = denom.abs()
+ BigInteger commonFactor = gcd(num, denom)
+
+ [num.intdiv(commonFactor) * sign, denom.intdiv(commonFactor)]
+ }
+
+ public Rational toLeastTerms() {
+ def reduced = reduce(numerator, denominator)
+ new Rational(reduced[0], reduced[1])
+ }
+
+ private BigInteger gcd(BigInteger n, BigInteger m) { n == 0 ? m : { while(m%n != 0) { def t=n; n=m%n; m=t }; n }() }
+
+ Rational plus (Rational r) { new Rational(numerator*r.denominator + r.numerator*denominator, denominator*r.denominator) }
+
+ Rational plus (BigInteger n) { new Rational(numerator + n*denominator, denominator) }
+
+ Rational next () { new Rational(numerator + denominator, denominator) }
+
+ Rational minus (Rational r) { new Rational(numerator*r.denominator - r.numerator*denominator, denominator*r.denominator) }
+
+ Rational minus (BigInteger n) { new Rational(numerator - n*denominator, denominator) }
+
+ Rational previous () { new Rational(numerator - denominator, denominator) }
+
+ Rational multiply (Rational r) { new Rational(numerator*r.numerator, denominator*r.denominator) }
+
+ Rational multiply (BigInteger n) { new Rational(numerator*n, denominator) }
+
+ Rational div (Rational r) { new Rational(numerator*r.denominator, denominator*r.numerator) }
+
+ Rational div (BigInteger n) { new Rational(numerator, denominator*n) }
+
+ BigInteger intdiv (BigInteger n) { numerator.intdiv(denominator*n) }
+
+ Rational negative () { new Rational(-numerator, denominator) }
+
+ Rational abs () { new Rational(numerator.abs(), denominator) }
+
+ Rational reciprocal() { new Rational(denominator, numerator) }
+
+ Rational power(BigInteger n) { new Rational(numerator ** n, denominator ** n) }
+
+ boolean asBoolean() { numerator != 0 }
+
+ BigDecimal toBigDecimal() { (numerator as BigDecimal)/(denominator as BigDecimal) }
+
+ BigInteger toBigInteger() { numerator.intdiv(denominator) }
+
+ Double toDouble() { toBigDecimal().toDouble() }
+
+ double doubleValue() { toDouble() as double }
+
+ Float toFloat() { toBigDecimal().toFloat() }
+
+ float floatValue() { toFloat() as float }
+
+ Integer toInteger() { toBigInteger().toInteger() }
+
+ int intValue() { toInteger() as int }
+
+ Long toLong() { toBigInteger().toLong() }
+
+ long longValue() { toLong() as long }
+
+ Object asType(Class type) {
+ switch (type) {
+ case this.getClass(): return this
+ case Boolean.class: return asBoolean()
+ case BigDecimal.class: return toBigDecimal()
+ case BigInteger.class: return toBigInteger()
+ case Double.class: return toDouble()
+ case Float.class: return toFloat()
+ case Integer.class: return toInteger()
+ case Long.class: return toLong()
+ case String.class: return toString()
+ default: throw new ClassCastException("Cannot convert from type Rational to type " + type)
+ }
+ }
+
+ boolean equals(o) {
+ compareTo(o) == 0
+ }
+
+ int compareTo(o) {
+ o instanceof Rational \
+ ? compareTo(o as Rational) \
+ : o instanceof Number \
+ ? compareTo(o as Number)\
+ : (Double.NaN as int)
+ }
+
+ int compareTo(Rational r) { numerator*r.denominator <=> denominator*r.numerator }
+
+ int compareTo(Number n) { numerator <=> denominator*(n as BigInteger) }
+
+ int hashCode() { [numerator, denominator].hashCode() }
+
+ String toString() {
+ def reduced = reduce(numerator, denominator)
+ "${reduced[0]}//${reduced[1]}"
+ }
+}
diff --git a/Task/Arithmetic-Rational/Groovy/arithmetic-rational-2.groovy b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-2.groovy
new file mode 100644
index 0000000000..4638a46b10
--- /dev/null
+++ b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-2.groovy
@@ -0,0 +1,74 @@
+def x = new Rational(5, 20)
+def y = new Rational(9, 12)
+def z = new Rational(0, 10000)
+
+println x
+println y
+println z
+println (x <=> y)
+println ((x as Rational).compareTo(y))
+assert x*3 == y
+assert (z + 1) <= y*4
+assert x != y
+
+println "x + y == ${x} + ${y} == ${x + y}"
+println "x + z == ${x} + ${z} == ${x + z}"
+println "x - y == ${x} - ${y} == ${x - y}"
+println "x - z == ${x} - ${z} == ${x - z}"
+println "x * y == ${x} * ${y} == ${x * y}"
+println "y ** 3 == ${y} ** 3 == ${y ** 3}"
+println "x * z == ${x} * ${z} == ${x * z}"
+println "x / y == ${x} / ${y} == ${x / y}"
+try { print "x / z == ${x} / ${z} == "; println "${x / z}" }
+catch (Throwable t) { println t.message }
+
+println "-x == -${x} == ${-x}"
+println "-y == -${y} == ${-y}"
+println "-z == -${z} == ${-z}"
+
+print "x as int == ${x} as int == "; println x.intValue()
+print "x as double == ${x} as double == "; println x.doubleValue()
+print "1 / x as int == 1 / ${x} as int == "; println x.reciprocal().intValue()
+print "1.0 / x == 1.0 / ${x} == "; println x.reciprocal().doubleValue()
+print "y as int == ${y} as int == "; println y.intValue()
+print "y as double == ${y} as double == "; println y.doubleValue()
+print "1 / y as int == 1 / ${y} as int == "; println y.reciprocal().intValue()
+print "1.0 / y == 1.0 / ${y} == "; println y.reciprocal().doubleValue()
+print "z as int == ${z} as int == "; println z.intValue()
+print "z as double == ${z} as double == "; println z.doubleValue()
+try { print "1 / z as int == 1 / ${z} as int == "; println z.reciprocal().intValue() }
+catch (Throwable t) { println t.message }
+try { print "1.0 / z == 1.0 / ${z} == "; println z.reciprocal().doubleValue() }
+catch (Throwable t) { println t.message }
+
+println "++x == ++ ${x} == ${++x}"
+println "++y == ++ ${y} == ${++y}"
+println "++z == ++ ${z} == ${++z}"
+println "-- --x == -- -- ${x} == ${-- (--x)}"
+println "-- --y == -- -- ${y} == ${-- (--y)}"
+println "-- --z == -- -- ${z} == ${-- (--z)}"
+println x
+println y
+println z
+
+println (x <=> y)
+assert x*3 == y
+assert (z + 1) <= y*4
+assert (x < y)
+
+println (new Rational(25))
+println (new Rational(25.0))
+println (new Rational(0.25))
+
+println Math.PI
+println (new Rational(Math.PI))
+println ((new Rational(Math.PI)).toBigDecimal())
+println ((new Rational(Math.PI)) as BigDecimal)
+println ((new Rational(Math.PI)) as Double)
+println ((new Rational(Math.PI)) as double)
+println ((new Rational(Math.PI)) as boolean)
+println (z as boolean)
+try { println ((new Rational(Math.PI)) as Date) }
+catch (Throwable t) { println t.message }
+try { println ((new Rational(Math.PI)) as char) }
+catch (Throwable t) { println t.message }
diff --git a/Task/Arithmetic-Rational/Groovy/arithmetic-rational-3.groovy b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-3.groovy
new file mode 100644
index 0000000000..1421eca833
--- /dev/null
+++ b/Task/Arithmetic-Rational/Groovy/arithmetic-rational-3.groovy
@@ -0,0 +1,26 @@
+def factorize = { target ->
+ if (target == 1L) {
+ return [1L]
+ } else if ([2L, 3L].contains(target)) {
+ return [1L, target]
+ }
+ def targetSqrt = Math.ceil(Math.sqrt(target)) as long
+ def lowfactors = (2L..(targetSqrt)).findAll { (target % it) == 0 }
+
+ if (lowfactors.isEmpty()) {
+ return [1L, target]
+ }
+
+ def nhalf = lowfactors.size() - ((lowfactors[-1] == targetSqrt) ? 1 : 0)
+
+ return ([1L] + lowfactors + ((nhalf-1)..0).collect { target.intdiv(lowfactors[it]) } + [target]).unique()
+}
+
+1.upto(2**19) {
+ if ((it % 100000) == 0) { println "HT" }
+ else if ((it % 1000) == 0) { print "." }
+
+ def factors = factorize(it)
+ def isPerfect = factors.collect{ factor -> new Rational( factor ).reciprocal() }.sum() == new Rational(2)
+ if (isPerfect) { println() ; println ([perfect: it, factors: factors]) }
+}
diff --git a/Task/Arithmetic-Rational/Icon/arithmetic-rational-1.icon b/Task/Arithmetic-Rational/Icon/arithmetic-rational-1.icon
new file mode 100644
index 0000000000..42d43bf7a0
--- /dev/null
+++ b/Task/Arithmetic-Rational/Icon/arithmetic-rational-1.icon
@@ -0,0 +1,34 @@
+procedure main()
+ limit := 2^19
+
+ write("Perfect numbers up to ",limit," (using rational arithmetic):")
+ every write(is_perfect(c := 2 to limit))
+ write("End of perfect numbers")
+
+ # verify the rest of the implementation
+
+ zero := makerat(0) # from integer
+ half := makerat(0.5) # from real
+ qtr := makerat("1/4") # from strings ...
+ one := makerat("1")
+ mone := makerat("-1")
+
+ verifyrat("eqrat",zero,zero)
+ verifyrat("ltrat",zero,half)
+ verifyrat("ltrat",half,zero)
+ verifyrat("gtrat",zero,half)
+ verifyrat("gtrat",half,zero)
+ verifyrat("nerat",zero,half)
+ verifyrat("nerat",zero,zero)
+ verifyrat("absrat",mone,)
+
+end
+
+procedure is_perfect(c) #: test for perfect numbers using rational arithmetic
+ rsum := rational(1, c, 1)
+ every f := 2 to sqrt(c) do
+ if 0 = c % f then
+ rsum := addrat(rsum,addrat(rational(1,f,1),rational(1,integer(c/f),1)))
+ if rsum.numer = rsum.denom = 1 then
+ return c
+end
diff --git a/Task/Arithmetic-Rational/Icon/arithmetic-rational-2.icon b/Task/Arithmetic-Rational/Icon/arithmetic-rational-2.icon
new file mode 100644
index 0000000000..7828b55afd
--- /dev/null
+++ b/Task/Arithmetic-Rational/Icon/arithmetic-rational-2.icon
@@ -0,0 +1,61 @@
+procedure verifyrat(p,r1,r2) #: verification tests for rational procedures
+return write("Testing ",p,"( ",rat2str(r1),", ",rat2str(\r2) | &null," ) ==> ","returned " || rat2str(p(r1,r2)) | "failed")
+end
+
+procedure makerat(x) #: make rational (from integer, real, or strings)
+local n,d
+static c
+initial c := &digits++'+-'
+
+ return case type(x) of {
+ "real" : real2rat(x)
+ "integer" : ratred(rational(x,1,1))
+ "string" : if x ? ( n := integer(tab(many(c))), ="/", d := integer(tab(many(c))), pos(0)) then
+ ratred(rational(n,d,1))
+ else
+ makerat(numeric(x))
+ }
+end
+
+procedure absrat(r1) #: abs(rational)
+ r1 := ratred(r1)
+ r1.sign := 1
+ return r1
+end
+
+invocable all # for string invocation
+
+procedure xoprat(op,r1,r2) #: support procedure for binary operations that cross denominators
+ local numer, denom, div
+
+ r1 := ratred(r1)
+ r2 := ratred(r2)
+
+ return if op(r1.numer * r2.denom,r2.numer * r1.denom) then r2 # return right argument on success
+end
+
+procedure eqrat(r1,r2) #: rational r1 = r2
+return xoprat("=",r1,r2)
+end
+
+procedure nerat(r1,r2) #: rational r1 ~= r2
+return xoprat("~=",r1,r2)
+end
+
+procedure ltrat(r1,r2) #: rational r1 < r2
+return xoprat("<",r1,r2)
+end
+
+procedure lerat(r1,r2) #: rational r1 <= r2
+return xoprat("<=",r1,r2)
+end
+
+procedure gerat(r1,r2) #: rational r1 >= r2
+return xoprat(">=",r1,r2)
+end
+
+procedure gtrat(r1,r2) #: rational r1 > r2
+return xoprat(">",r1,r2)
+end
+
+link rational
diff --git a/Task/Arithmetic-Rational/Icon/arithmetic-rational-3.icon b/Task/Arithmetic-Rational/Icon/arithmetic-rational-3.icon
new file mode 100644
index 0000000000..f62052e43c
--- /dev/null
+++ b/Task/Arithmetic-Rational/Icon/arithmetic-rational-3.icon
@@ -0,0 +1,15 @@
+ record rational(numer, denom, sign) # rational type
+
+ addrat(r1,r2) # Add rational numbers r1 and r2.
+ divrat(r1,r2) # Divide rational numbers r1 and r2.
+ medrat(r1,r2) # Form mediant of r1 and r2.
+ mpyrat(r1,r2) # Multiply rational numbers r1 and r2.
+ negrat(r) # Produce negative of rational number r.
+ rat2real(r) # Produce floating-point approximation of r
+ rat2str(r) # Convert the rational number r to its string representation.
+ real2rat(v,p) # Convert real to rational with precision p (default 1e-10). Warning: excessive p gives ugly fractions
+ reciprat(r) # Produce the reciprocal of rational number r.
+ str2rat(s) # Convert the string representation (such as "3/2") to a rational number
+ subrat(r1,r2) # Subtract rational numbers r1 and r2.
+
+ gcd(i, j) # returns greatest common divisor of i and j
diff --git a/Task/Arithmetic-Rational/J/arithmetic-rational-1.j b/Task/Arithmetic-Rational/J/arithmetic-rational-1.j
new file mode 100644
index 0000000000..43410ffad4
--- /dev/null
+++ b/Task/Arithmetic-Rational/J/arithmetic-rational-1.j
@@ -0,0 +1,2 @@
+ 3r4*2r5
+3r10
diff --git a/Task/Arithmetic-Rational/J/arithmetic-rational-2.j b/Task/Arithmetic-Rational/J/arithmetic-rational-2.j
new file mode 100644
index 0000000000..69202bf44d
--- /dev/null
+++ b/Task/Arithmetic-Rational/J/arithmetic-rational-2.j
@@ -0,0 +1 @@
+ is_perfect_rational=: 2 = (1 + i.) +/@:%@([ #~ 0 = |) ]
diff --git a/Task/Arithmetic-Rational/J/arithmetic-rational-3.j b/Task/Arithmetic-Rational/J/arithmetic-rational-3.j
new file mode 100644
index 0000000000..3e4a5cd64e
--- /dev/null
+++ b/Task/Arithmetic-Rational/J/arithmetic-rational-3.j
@@ -0,0 +1,2 @@
+factors=: */&>@{@((^ i.@>:)&.>/)@q:~&__
+is_perfect_rational=: 2= +/@:%@,@factors
diff --git a/Task/Arithmetic-Rational/J/arithmetic-rational-4.j b/Task/Arithmetic-Rational/J/arithmetic-rational-4.j
new file mode 100644
index 0000000000..22a9cdb013
--- /dev/null
+++ b/Task/Arithmetic-Rational/J/arithmetic-rational-4.j
@@ -0,0 +1,4 @@
+ I.is_perfect_rational@"0 i.2^19
+6 28 496 8128
+ I.is_perfect_rational@x:@"0 i.2^19x
+6 28 496 8128
diff --git a/Task/Arithmetic-Rational/J/arithmetic-rational-5.j b/Task/Arithmetic-Rational/J/arithmetic-rational-5.j
new file mode 100644
index 0000000000..4a3f32d884
--- /dev/null
+++ b/Task/Arithmetic-Rational/J/arithmetic-rational-5.j
@@ -0,0 +1,2 @@
+ (#~ is_perfect_rational"0) (* <:@+:) 2^i.10x
+6 28 496 8128
diff --git a/Task/Arithmetic-Rational/Liberty-BASIC/arithmetic-rational.liberty b/Task/Arithmetic-Rational/Liberty-BASIC/arithmetic-rational.liberty
new file mode 100644
index 0000000000..c2f7fa1baa
--- /dev/null
+++ b/Task/Arithmetic-Rational/Liberty-BASIC/arithmetic-rational.liberty
@@ -0,0 +1,120 @@
+n=2^19
+for testNumber=1 to n
+ sum$=castToFraction$(0)
+ for factorTest=1 to sqr(testNumber)
+ if GCD(factorTest,testNumber)=factorTest then sum$=add$(sum$,add$(reciprocal$(castToFraction$(factorTest)),reciprocal$(castToFraction$(testNumber/factorTest))))
+ next factorTest
+ if equal(sum$,castToFraction$(2))=1 then print testNumber
+next testNumber
+end
+
+function abs$(a$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ bNumerator=abs(aNumerator)
+ bDenominator=abs(aDenominator)
+ b$=str$(bNumerator)+"/"+str$(bDenominator)
+ abs$=simplify$(b$)
+end function
+
+function negate$(a$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ bNumerator=-1*aNumerator
+ bDenominator=aDenominator
+ b$=str$(bNumerator)+"/"+str$(bDenominator)
+ negate$=simplify$(b$)
+end function
+
+function add$(a$,b$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ bNumerator=val(word$(b$,1,"/"))
+ bDenominator=val(word$(b$,2,"/"))
+ cNumerator=(aNumerator*bDenominator+bNumerator*aDenominator)
+ cDenominator=aDenominator*bDenominator
+ c$=str$(cNumerator)+"/"+str$(cDenominator)
+ add$=simplify$(c$)
+end function
+
+function subtract$(a$,b$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ bNumerator=val(word$(b$,1,"/"))
+ bDenominator=val(word$(b$,2,"/"))
+ cNumerator=(aNumerator*bDenominator-bNumerator*aDenominator)
+ cDenominator=aDenominator*bDenominator
+ c$=str$(cNumerator)+"/"+str$(cDenominator)
+ subtract$=simplify$(c$)
+end function
+
+function multiply$(a$,b$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ bNumerator=val(word$(b$,1,"/"))
+ bDenominator=val(word$(b$,2,"/"))
+ cNumerator=aNumerator*bNumerator
+ cDenominator=aDenominator*bDenominator
+ c$=str$(cNumerator)+"/"+str$(cDenominator)
+ multiply$=simplify$(c$)
+end function
+
+function divide$(a$,b$)
+ divide$=multiply$(a$,reciprocal$(b$))
+end function
+
+function simplify$(a$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ gcd=GCD(aNumerator,aDenominator)
+ if aNumerator<0 and aDenominator<0 then gcd=-1*gcd
+ bNumerator=aNumerator/gcd
+ bDenominator=aDenominator/gcd
+ b$=str$(bNumerator)+"/"+str$(bDenominator)
+ simplify$=b$
+end function
+
+function reciprocal$(a$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ reciprocal$=str$(aDenominator)+"/"+str$(aNumerator)
+end function
+
+function equal(a$,b$)
+ if simplify$(a$)=simplify$(b$) then equal=1:else equal=0
+end function
+
+function castToFraction$(a)
+ do
+ exp=exp+1
+ a=a*10
+ loop until a=int(a)
+ castToFraction$=simplify$(str$(a)+"/"+str$(10^exp))
+end function
+
+function castToReal(a$)
+ aNumerator=val(word$(a$,1,"/"))
+ aDenominator=val(word$(a$,2,"/"))
+ castToReal=aNumerator/aDenominator
+end function
+
+function castToInt(a$)
+ castToInt=int(castToReal(a$))
+end function
+
+function GCD(a,b)
+ if a=0 then
+ GCD=1
+ else
+ if a>=b then
+ while b
+ c = a
+ a = b
+ b = c mod b
+ GCD = abs(a)
+ wend
+ else
+ GCD=GCD(b,a)
+ end if
+ end if
+end function
diff --git a/Task/Arithmetic-Rational/Maple/arithmetic-rational-1.maple b/Task/Arithmetic-Rational/Maple/arithmetic-rational-1.maple
new file mode 100644
index 0000000000..61c9f3dc12
--- /dev/null
+++ b/Task/Arithmetic-Rational/Maple/arithmetic-rational-1.maple
@@ -0,0 +1,8 @@
+> a := 3 / 5;
+ a := 3/5
+
+> numer( a );
+ 3
+
+> denom( a );
+ 5
diff --git a/Task/Arithmetic-Rational/Maple/arithmetic-rational-2.maple b/Task/Arithmetic-Rational/Maple/arithmetic-rational-2.maple
new file mode 100644
index 0000000000..e8d5d0acb2
--- /dev/null
+++ b/Task/Arithmetic-Rational/Maple/arithmetic-rational-2.maple
@@ -0,0 +1,2 @@
+> b := 4 / 6;
+ b := 2/3
diff --git a/Task/Arithmetic-Rational/Maple/arithmetic-rational-3.maple b/Task/Arithmetic-Rational/Maple/arithmetic-rational-3.maple
new file mode 100644
index 0000000000..6c5eb15ebf
--- /dev/null
+++ b/Task/Arithmetic-Rational/Maple/arithmetic-rational-3.maple
@@ -0,0 +1,21 @@
+> a + b;
+ 19
+ --
+ 15
+
+> a * b;
+ 2/5
+
+> a / b;
+ 9/10
+
+> a - b;
+ -1
+ --
+ 15
+
+> a + 1;
+ 8/5
+
+> a - 1;
+ -2/5
diff --git a/Task/Arithmetic-Rational/Maple/arithmetic-rational-4.maple b/Task/Arithmetic-Rational/Maple/arithmetic-rational-4.maple
new file mode 100644
index 0000000000..1186136af9
--- /dev/null
+++ b/Task/Arithmetic-Rational/Maple/arithmetic-rational-4.maple
@@ -0,0 +1,6 @@
+> evalf( 22 / 7 ); # default is 10 digits
+ 3.142857143
+
+> evalf[100]( 22 / 7 ); # 100 digits
+3.142857142857142857142857142857142857142857142857142857142857142857\
+ 142857142857142857142857142857143
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-1.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-1.mathematica
new file mode 100644
index 0000000000..7427db21f9
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-1.mathematica
@@ -0,0 +1,26 @@
+4/16
+3/8
+8/4
+4Pi/2
+16!/10!
+Sqrt[9/16]
+Sqrt[3/4]
+(23/12)^5
+2 + 1/(1 + 1/(3 + 1/4))
+
+1/2+1/3+1/5
+8/Pi+Pi/8 //Together
+13/17 + 7/31
+Sum[1/n,{n,1,100}] (*summation of 1/1 + 1/2 + 1/3 + 1/4+ .........+ 1/99 + 1/100*)
+
+1/2-1/3
+a=1/3;a+=1/7
+
+1/4==2/8
+1/4>3/8
+Pi/E >23/20
+1/3!=123/370
+Sin[3]/Sin[2]>3/20
+
+Numerator[6/9]
+Denominator[6/9]
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-2.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-2.mathematica
new file mode 100644
index 0000000000..7228dbd8e6
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-2.mathematica
@@ -0,0 +1,3 @@
+c/(2 c)
+(b^2 - c^2)/(b - c) // Cancel
+1/2 + b/c // Together
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-3.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-3.mathematica
new file mode 100644
index 0000000000..b4ff08b7c1
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-3.mathematica
@@ -0,0 +1,3 @@
+1/2
+b+c
+(2 b+c) / (2 c)
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-4.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-4.mathematica
new file mode 100644
index 0000000000..e4812dc77c
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-4.mathematica
@@ -0,0 +1 @@
+1+2*{1,2,3}^3
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-5.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-5.mathematica
new file mode 100644
index 0000000000..5505fa9236
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-5.mathematica
@@ -0,0 +1 @@
+{3, 17, 55}
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-6.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-6.mathematica
new file mode 100644
index 0000000000..0101f2d1f3
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-6.mathematica
@@ -0,0 +1,4 @@
+found={};
+CheckPerfect[num_Integer]:=If[Total[1/Divisors[num]]==2,AppendTo[found,num]];
+Do[CheckPerfect[i],{i,1,2^25}];
+found
diff --git a/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-7.mathematica b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-7.mathematica
new file mode 100644
index 0000000000..f15295c89a
--- /dev/null
+++ b/Task/Arithmetic-Rational/Mathematica/arithmetic-rational-7.mathematica
@@ -0,0 +1 @@
+{6, 28, 496, 8128, 33550336}
diff --git a/Task/Arithmetic-Rational/Maxima/arithmetic-rational.maxima b/Task/Arithmetic-Rational/Maxima/arithmetic-rational.maxima
new file mode 100644
index 0000000000..522fdd418c
--- /dev/null
+++ b/Task/Arithmetic-Rational/Maxima/arithmetic-rational.maxima
@@ -0,0 +1,30 @@
+/* Rational numbers are builtin */
+a: 3 / 11;
+3/11
+
+b: 117 / 17;
+117/17
+
+a + b;
+1338/187
+
+a - b;
+-1236/187
+
+a * b;
+351/187
+
+a / b;
+17/429
+
+a^5;
+243/161051
+
+num(a);
+3
+
+denom(a);
+11
+
+ratnump(a);
+true
diff --git a/Task/Arithmetic-evaluation/Factor/arithmetic-evaluation.factor b/Task/Arithmetic-evaluation/Factor/arithmetic-evaluation.factor
new file mode 100644
index 0000000000..c8461deafe
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Factor/arithmetic-evaluation.factor
@@ -0,0 +1,42 @@
+USING: accessors kernel locals math math.parser peg.ebnf ;
+IN: rosetta.arith
+
+TUPLE: operator left right ;
+TUPLE: add < operator ; C: add
+TUPLE: sub < operator ; C: sub
+TUPLE: mul < operator ; C: mul
+TUPLE: div < operator ; C: div
+
+EBNF: expr-ast
+spaces = [\n\t ]*
+digit = [0-9]
+number = (digit)+ => [[ string>number ]]
+
+value = spaces number:n => [[ n ]]
+ | spaces "(" exp:e spaces ")" => [[ e ]]
+
+fac = fac:a spaces "*" value:b => [[ a b
]]
+ | fac:a spaces "/" value:b => [[ a b ]]
+ | value
+
+exp = exp:a spaces "+" fac:b => [[ a b
]]
+ | exp:a spaces "-" fac:b => [[ a b ]]
+ | fac
+
+main = exp:e spaces !(.) => [[ e ]]
+;EBNF
+
+GENERIC: eval-ast ( ast -- result )
+
+M: number eval-ast ;
+
+: recursive-eval ( ast -- left-result right-result )
+ [ left>> eval-ast ] [ right>> eval-ast ] bi ;
+
+M: add eval-ast recursive-eval + ;
+M: sub eval-ast recursive-eval - ;
+M: mul eval-ast recursive-eval * ;
+M: div eval-ast recursive-eval / ;
+
+: evaluate ( string -- result )
+ expr-ast eval-ast ;
diff --git a/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-1.groovy b/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-1.groovy
new file mode 100644
index 0000000000..d0082a39dd
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-1.groovy
@@ -0,0 +1,144 @@
+enum Op {
+ ADD('+', 2),
+ SUBTRACT('-', 2),
+ MULTIPLY('*', 1),
+ DIVIDE('/', 1);
+
+ static {
+ ADD.operation = { a, b -> a + b }
+ SUBTRACT.operation = { a, b -> a - b }
+ MULTIPLY.operation = { a, b -> a * b }
+ DIVIDE.operation = { a, b -> a / b }
+ }
+
+ final String symbol
+ final int precedence
+ Closure operation
+
+ private Op(String symbol, int precedence) {
+ this.symbol = symbol
+ this.precedence = precedence
+ }
+
+ String toString() { symbol }
+
+ static Op fromSymbol(String symbol) {
+ Op.values().find { it.symbol == symbol }
+ }
+}
+
+interface Expression {
+ Number evaluate();
+}
+
+class Constant implements Expression {
+ Number value
+
+ Constant (Number value) { this.value = value }
+
+ Constant (String str) {
+ try { this.value = str as BigInteger }
+ catch (e) { this.value = str as BigDecimal }
+ }
+
+ Number evaluate() { value }
+
+ String toString() { "${value}" }
+}
+
+class Term implements Expression {
+ Op op
+ Expression left, right
+
+ Number evaluate() { op.operation(left.evaluate(), right.evaluate()) }
+
+ String toString() { "(${op} ${left} ${right})" }
+}
+
+void fail(String msg, Closure cond = {true}) {
+ if (cond()) throw new IllegalArgumentException("Cannot parse expression: ${msg}")
+}
+
+Expression parse(String expr) {
+ def tokens = tokenize(expr)
+ def elements = groupByParens(tokens, 0)
+ parse(elements)
+}
+
+List tokenize(String expr) {
+ def tokens = []
+ def constStr = ""
+ def captureConstant = { i ->
+ if (constStr) {
+ try { tokens << new Constant(constStr) }
+ catch (NumberFormatException e) { fail "Invalid constant '${constStr}' near position ${i}" }
+ constStr = ''
+ }
+ }
+ for(def i = 0; i tokens.size() }
+ def subGroup = groupByParens(tokens[i+1..-1], depth+1)
+ tokenGroups << subGroup[0..-2]
+ i += subGroup[-1] + 1
+ break
+ case ')':
+ fail("Unbalanced parens, found extra ')'") { deepness == 0 }
+ tokenGroups << i
+ return tokenGroups
+ default:
+ tokenGroups << token
+ }
+ }
+ fail("Unbalanced parens, unclosed groupings at end of expression") { deepness != 0 }
+ def n = tokenGroups.size()
+ fail("The operand/operator sequence is wrong") { n%2 == 0 }
+ (0.. 1) {
+ def n = elements.size()
+ fail ("The operand/operator sequence is wrong") { n%2 == 0 }
+ def groupLoc = (0.. elements[i] instanceof List }
+ if (groupLoc != null) {
+ elements[groupLoc] = parse(elements[groupLoc])
+ continue
+ }
+ def opLoc = (0.. elements[i] instanceof Op && elements[i].precedence == 1 } \
+ ?: (0.. elements[i] instanceof Op && elements[i].precedence == 2 }
+ if (opLoc != null) {
+ fail ("Operator out of sequence") { opLoc%2 == 0 }
+ def term = new Term(left:elements[opLoc-1], op:elements[opLoc], right:elements[opLoc+1])
+ elements[(opLoc-1)..(opLoc+1)] = [term]
+ continue
+ }
+ }
+ return elements[0] instanceof List ? parse(elements[0]) : elements[0]
+}
diff --git a/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-2.groovy b/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-2.groovy
new file mode 100644
index 0000000000..d2df101dde
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Groovy/arithmetic-evaluation-2.groovy
@@ -0,0 +1,36 @@
+def testParse = {
+ def ex = parse(it)
+ print """
+Input: ${it}
+AST: ${ex}
+value: ${ex.evaluate()}
+"""
+}
+
+
+testParse('1+1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+1/15)/14)/13)/12)/11)/10)/9)/8)/7)/6)/5)/4)/3)/2')
+assert (parse('1+1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+(1+1/15)/14)/13)/12)/11)/10)/9)/8)/7)/6)/5)/4)/3)/2')
+ .evaluate() - Math.E).abs() < 0.0000000000001
+testParse('1 + 2*(3 - 2*(3 - 2)*((2 - 4)*5 - 22/(7 + 2*(3 - 1)) - 1)) + 1')
+testParse('1 - 5 * 2 / 20 + 1')
+testParse('(1 - 5) * 2 / (20 + 1)')
+testParse('2 * (3 + ((5) / (7 - 11)))')
+testParse('(2 + 3) / (10 - 5)')
+testParse('(1 + 2) * 10 / 100')
+testParse('(1 + 2 / 2) * (5 + 5)')
+testParse('2*-3--4+-.25')
+testParse('2*(-3)-(-4)+(-.25)')
+testParse('((11+15)*15)*2-(3)*4*1')
+testParse('((11+15)*15)* 2 + (3) * -4 *1')
+testParse('(((((1)))))')
+testParse('-35')
+println()
+
+try { testParse('((11+15)*1') } catch (e) { println e }
+try { testParse('((11+15)*1)))') } catch (e) { println e }
+try { testParse('((11+15)*x)') } catch (e) { println e }
+try { testParse('+++++') } catch (e) { println e }
+try { testParse('1 /') } catch (e) { println e }
+try { testParse('1++') } catch (e) { println e }
+try { testParse('*1') } catch (e) { println e }
+try { testParse('/ 1 /') } catch (e) { println e }
diff --git a/Task/Arithmetic-evaluation/Icon/arithmetic-evaluation.icon b/Task/Arithmetic-evaluation/Icon/arithmetic-evaluation.icon
new file mode 100644
index 0000000000..a7e0c3cae4
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Icon/arithmetic-evaluation.icon
@@ -0,0 +1,101 @@
+procedure main() #: simple arithmetical parser / evaluator
+ write("Usage: Input expression = Abstract Syntax Tree = Value, ^Z to end.")
+ repeat {
+ writes("Input expression : ")
+ if not writes(line := read()) then break
+ if map(line) ? { (x := E()) & pos(0) } then
+ write(" = ", showAST(x), " = ", evalAST(x))
+ else
+ write(" rejected")
+ }
+end
+
+procedure evalAST(X) #: return the evaluated AST
+ local x
+
+ if type(X) == "list" then {
+ x := evalAST(get(X))
+ while x := get(X)(x, evalAST(get(X) | stop("Malformed AST.")))
+ }
+ return \x | X
+end
+
+procedure showAST(X) #: return a string representing the AST
+ local x,s
+
+ s := ""
+ every x := !X do
+ s ||:= if type(x) == "list" then "(" || showAST(x) || ")" else x
+ return s
+end
+
+########
+# When you're writing a big parser, a few utility recognisers are very useful
+#
+procedure ws() # skip optional whitespace
+ suspend tab(many(' \t')) | ""
+end
+
+procedure digits()
+ suspend tab(many(&digits))
+end
+
+procedure radixNum(r) # r sets the radix
+ static chars
+ initial chars := &digits || &lcase
+ suspend tab(many(chars[1 +: r]))
+end
+########
+
+global token
+record HansonsDevice(precedence,associativity)
+
+procedure opinfo()
+ static O
+ initial {
+ O := HansonsDevice([], table(&null)) # parsing table
+ put(O.precedence, ["+", "-"], ["*", "/", "%"], ["^"]) # Lowest to Highest precedence
+ every O.associativity[!!O.precedence] := 1 # default to 1 for LEFT associativity
+ O.associativity["^"] := 0 # RIGHT associativity
+ }
+ return O
+end
+
+procedure E(k) #: Expression
+ local lex, pL
+ static opT
+ initial opT := opinfo()
+
+ /k := 1
+ lex := []
+ if not (pL := opT.precedence[k]) then # this op at this level?
+ put(lex, F())
+ else {
+ put(lex, E(k + 1))
+ while ws() & put(lex, token := =!pL) do
+ put(lex, E(k + opT.associativity[token]))
+ }
+ suspend if *lex = 1 then lex[1] else lex # strip useless []
+end
+
+procedure F() #: Factor
+ suspend ws() & ( # skip optional whitespace, and ...
+ (="+" & F()) | # unary + and a Factor, or ...
+ (="-" || V()) | # unary - and a Value, or ...
+ (="-" & [-1, "*", F()]) | # unary - and a Factor, or ...
+ 2(="(", E(), ws(), =")") | # parenthesized subexpression, or ...
+ V() # just a value
+ )
+end
+
+procedure V() #: Value
+ local r
+ suspend ws() & numeric( # skip optional whitespace, and ...
+ =(r := 1 to 36) || ="r" || radixNum(r) | # N-based number, or ...
+ digits() || (="." || digits() | "") || exponent() # plain number with optional fraction
+ )
+end
+
+procedure exponent()
+ suspend tab(any('eE')) || =("+" | "-" | "") || digits() | ""
+end
diff --git a/Task/Arithmetic-evaluation/J/arithmetic-evaluation-1.j b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-1.j
new file mode 100644
index 0000000000..05d141904e
--- /dev/null
+++ b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-1.j
@@ -0,0 +1,66 @@
+parse=:parse_parser_
+eval=:monad define
+ 'gerund structure'=:y
+ gerund@.structure
+)
+
+coclass 'parser'
+classify=: '$()*/+-'&(((>:@#@[ # 2:) #: 2 ^ i.)&;:)
+
+rules=: ''
+patterns=: ,"0 assert 1
+
+addrule=: dyad define
+ rules=: rules,;:x
+ patterns=: patterns,+./@classify"1 y
+)
+
+'Term' addrule '$()', '0', '+-',: '0'
+'Factor' addrule '$()+-', '0', '*/',: '0'
+'Parens' addrule '(', '*/+-0', ')',: ')*/+-0$'
+rules=: rules,;:'Move'
+
+buildTree=: monad define
+ words=: ;:'$',y
+ queue=: classify '$',y
+ stack=: classify '$$$$'
+ tokens=: ]&.>i.#words
+ tree=: ''
+ while.(#queue)+.6<#stack do.
+ rule=: rules {~ i.&1 patterns (*./"1)@:(+./"1) .(*."1)4{.stack
+ rule`:6''
+ end.
+ 'syntax' assert 1 0 1 1 1 1 -: {:"1 stack
+ gerund=: literal&.> (<,'%') (I. words=<,'/')} words
+ gerund;1{tree
+)
+
+literal=:monad define ::]
+ ".'t=.',y
+ 5!:1<'t'
+)
+
+Term=: Factor=: monad define
+ stack=: ({.stack),(classify '0'),4}.stack
+ tree=: ({.tree),(<1 2 3{tree),4}.tree
+)
+
+Parens=: monad define
+ stack=: (1{stack),3}.stack
+ tree=: (1{tree),3}.tree
+)
+
+Move=: monad define
+ 'syntax' assert 0<#queue
+ stack=: ({:queue),stack
+ queue=: }:queue
+ tree=: ({:tokens),tree
+ tokens=: }:tokens
+)
+
+parse=:monad define
+ tmp=: conew 'parser'
+ r=: buildTree__tmp y
+ coerase tmp
+ r
+)
diff --git a/Task/Arithmetic-evaluation/J/arithmetic-evaluation-2.j b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-2.j
new file mode 100644
index 0000000000..cd7e9275c8
--- /dev/null
+++ b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-2.j
@@ -0,0 +1,2 @@
+ eval parse '1+2*3/(4-5+6)'
+2.2
diff --git a/Task/Arithmetic-evaluation/J/arithmetic-evaluation-3.j b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-3.j
new file mode 100644
index 0000000000..6db0a6250c
--- /dev/null
+++ b/Task/Arithmetic-evaluation/J/arithmetic-evaluation-3.j
@@ -0,0 +1,10 @@
+ parse '2*3/(4-5)'
+┌─────────────────────────────────────────────────────┬───────────────────┐
+│┌───┬───────┬───┬───────┬───┬─┬───────┬───┬───────┬─┐│┌───────┬─┬───────┐│
+││┌─┐│┌─────┐│┌─┐│┌─────┐│┌─┐│(│┌─────┐│┌─┐│┌─────┐│)│││┌─┬─┬─┐│4│┌─┬─┬─┐││
+│││$│││┌─┬─┐│││*│││┌─┬─┐│││%││ ││┌─┬─┐│││-│││┌─┬─┐││ ││││1│2│3││ ││6│7│8│││
+││└─┘│││0│2│││└─┘│││0│3│││└─┘│ │││0│4│││└─┘│││0│5│││ │││└─┴─┴─┘│ │└─┴─┴─┘││
+││ ││└─┴─┘││ ││└─┴─┘││ │ ││└─┴─┘││ ││└─┴─┘││ ││└───────┴─┴───────┘│
+││ │└─────┘│ │└─────┘│ │ │└─────┘│ │└─────┘│ ││ │
+│└───┴───────┴───┴───────┴───┴─┴───────┴───┴───────┴─┘│ │
+└─────────────────────────────────────────────────────┴───────────────────┘
diff --git a/Task/Arithmetic-evaluation/Julia/arithmetic-evaluation.julia b/Task/Arithmetic-evaluation/Julia/arithmetic-evaluation.julia
new file mode 100644
index 0000000000..7a5eb59458
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Julia/arithmetic-evaluation.julia
@@ -0,0 +1,41 @@
+julia> expr="2 * (3 -1) + 2 * 5"
+"2 * (3 -1) + 2 * 5"
+
+julia> parsed = parse(expr) #Julia provides low-level access to language parser for AST/Expr creation
+:(+(*(2,-(3,1)),*(2,5)))
+
+julia> t = typeof(parsed)
+Expr
+
+julia> names(t) #shows type fields
+(:head,:args,:typ)
+
+julia> parsed.args #Inspect our 'Expr' type innards
+3-element Any Array:
+ :+
+ :(*(2,-(3,1)))
+ :(*(2,5))
+
+julia> typeof(parsed.args[2]) #'Expr' types can nest
+Expr
+
+julia> parsed.args[2].args
+3-element Any Array:
+ :*
+ 2
+ :(-(3,1))
+
+julia> parsed.args[2].args[3].args #Will nest until lowest level of AST
+3-element Any Array:
+ :-
+ 3
+ 1
+
+julia> eval(parsed)
+14
+
+julia> eval(parse("1 - 5 * 2 / 20 + 1"))
+1.5
+
+julia> eval(parse("2 * (3 + ((5) / (7 - 11)))"))
+3.5
diff --git a/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-1.mathematica b/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-1.mathematica
new file mode 100644
index 0000000000..b68beefc1c
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-1.mathematica
@@ -0,0 +1,34 @@
+(*parsing:*)
+parse[string_] :=
+ Module[{e},
+ StringCases[string,
+ "+" | "-" | "*" | "/" | "(" | ")" |
+ DigitCharacter ..] //. {a_String?DigitQ :>
+ e[ToExpression@a], {x___, PatternSequence["(", a_e, ")"],
+ y___} :> {x, a,
+ y}, {x :
+ PatternSequence[] |
+ PatternSequence[___, "(" | "+" | "-" | "*" | "/"],
+ PatternSequence[op : "+" | "-", a_e], y___} :> {x, e[op, a],
+ y}, {x :
+ PatternSequence[] | PatternSequence[___, "(" | "+" | "-"],
+ PatternSequence[a_e, op : "*" | "/", b_e], y___} :> {x,
+ e[op, a, b],
+ y}, {x :
+ PatternSequence[] | PatternSequence[___, "(" | "+" | "-"],
+ PatternSequence[a_e, b_e], y___} :> {x, e["*", a, b],
+ y}, {x : PatternSequence[] | PatternSequence[___, "("],
+ PatternSequence[a_e, op : "+" | "-", b_e],
+ y : PatternSequence[] |
+ PatternSequence[")" | "+" | "-", ___]} :> {x, e[op, a, b],
+ y}} //. {e -> List, {a_Integer} :> a, {a_List} :> a}]
+
+(*evaluation*)
+evaluate[a_Integer] := a;
+evaluate[{"+", a_}] := evaluate[a];
+evaluate[{"-", a_}] := -evaluate[a];
+evaluate[{"+", a_, b_}] := evaluate[a] + evaluate[b];
+evaluate[{"-", a_, b_}] := evaluate[a] - evaluate[b];
+evaluate[{"*", a_, b_}] := evaluate[a]*evaluate[b];
+evaluate[{"/", a_, b_}] := evaluate[a]/evaluate[b];
+evaluate[string_String] := evaluate[parse[string]]
diff --git a/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-2.mathematica b/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-2.mathematica
new file mode 100644
index 0000000000..156ef89de8
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Mathematica/arithmetic-evaluation-2.mathematica
@@ -0,0 +1,2 @@
+parse["-1+2(3+4*-5/6)"]
+evaluate["-1+2(3+4*-5/6)"]
diff --git a/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-1.j b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-1.j
new file mode 100644
index 0000000000..886ffca52e
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-1.j
@@ -0,0 +1,3 @@
+mean=: +/ % #
+ (mean , */ %:~ #)^:_] 1,%%:2
+0.8472130847939792 0.8472130847939791
diff --git a/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-2.j b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-2.j
new file mode 100644
index 0000000000..42b9305572
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-2.j
@@ -0,0 +1,2 @@
+ ~.(mean , */ %:~ #)^:_] 1,%%:2
+0.8472130847939792
diff --git a/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-3.j b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-3.j
new file mode 100644
index 0000000000..7fd85b0ff0
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/J/arithmetic-geometric-mean-3.j
@@ -0,0 +1,6 @@
+ (mean, */ %:~ #)^:a: 1,%%:2
+ 1 0.7071067811865475
+0.8535533905932737 0.8408964152537145
+0.8472249029234942 0.8472012667468915
+0.8472130848351929 0.8472130847527654
+0.8472130847939792 0.8472130847939791
diff --git a/Task/Arithmetic-geometric-mean/Liberty-BASIC/arithmetic-geometric-mean.liberty b/Task/Arithmetic-geometric-mean/Liberty-BASIC/arithmetic-geometric-mean.liberty
new file mode 100644
index 0000000000..429ff1e011
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Liberty-BASIC/arithmetic-geometric-mean.liberty
@@ -0,0 +1,13 @@
+print agm(1, 1/sqr(2))
+print using("#.#################",agm(1, 1/sqr(2)))
+
+function agm(a,g)
+ do
+ absdiff = abs(a-g)
+ an=(a+g)/2
+ gn=sqr(a*g)
+ a=an
+ g=gn
+ loop while abs(an-gn)< absdiff
+ agm = a
+end function
diff --git a/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-1.maple b/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-1.maple
new file mode 100644
index 0000000000..3b173b4997
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-1.maple
@@ -0,0 +1,6 @@
+> evalf( GaussAGM( 1, 1 / sqrt( 2 ) ) ); # default precision is 10 digits
+ 0.8472130847
+
+> evalf[100]( GaussAGM( 1, 1 / sqrt( 2 ) ) ); # to 100 digits
+0.847213084793979086606499123482191636481445910326942185060579372659\
+ 7340048341347597232002939946112300
diff --git a/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-2.maple b/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-2.maple
new file mode 100644
index 0000000000..5f33866d21
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Maple/arithmetic-geometric-mean-2.maple
@@ -0,0 +1,2 @@
+> GaussAGM( 1.0, 1 / sqrt( 2 ) );
+ 0.8472130847
diff --git a/Task/Arithmetic-geometric-mean/Mathematica/arithmetic-geometric-mean.mathematica b/Task/Arithmetic-geometric-mean/Mathematica/arithmetic-geometric-mean.mathematica
new file mode 100644
index 0000000000..1dcbbcae92
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Mathematica/arithmetic-geometric-mean.mathematica
@@ -0,0 +1,2 @@
+PrecisionDigits = 85;
+AGMean[a_, b_] := FixedPoint[{ (Plus@@#)/2, Sqrt[Times@@#] }&, N[{a,b}, PrecisionDigits]][[1]]
diff --git a/Task/Arithmetic-geometric-mean/Maxima/arithmetic-geometric-mean.maxima b/Task/Arithmetic-geometric-mean/Maxima/arithmetic-geometric-mean.maxima
new file mode 100644
index 0000000000..fb68dbb533
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Maxima/arithmetic-geometric-mean.maxima
@@ -0,0 +1,4 @@
+agm(a, b) := %pi/4*(a + b)/elliptic_kc(((a - b)/(a + b))^2)$
+
+agm(1, 1/sqrt(2)), bfloat, fpprec: 85;
+/* 8.472130847939790866064991234821916364814459103269421850605793726597340048341347597232b-1 */
diff --git a/Task/Array-concatenation/Factor/array-concatenation-1.factor b/Task/Array-concatenation/Factor/array-concatenation-1.factor
new file mode 100644
index 0000000000..15bfb21a64
--- /dev/null
+++ b/Task/Array-concatenation/Factor/array-concatenation-1.factor
@@ -0,0 +1 @@
+append
diff --git a/Task/Array-concatenation/Factor/array-concatenation-2.factor b/Task/Array-concatenation/Factor/array-concatenation-2.factor
new file mode 100644
index 0000000000..150f26f30b
--- /dev/null
+++ b/Task/Array-concatenation/Factor/array-concatenation-2.factor
@@ -0,0 +1,3 @@
+( scratchpad ) USE: sequences
+( scratchpad ) { 1 2 } { 3 4 } append .
+{ 1 2 3 4 }
diff --git a/Task/Array-concatenation/Fantom/array-concatenation.fantom b/Task/Array-concatenation/Fantom/array-concatenation.fantom
new file mode 100644
index 0000000000..aaf8b0bbb5
--- /dev/null
+++ b/Task/Array-concatenation/Fantom/array-concatenation.fantom
@@ -0,0 +1,5 @@
+> a := [1,2,3]
+> b := [4,5,6]
+> a.addAll(b)
+> a
+[1,2,3,4,5,6]
diff --git a/Task/Array-concatenation/GAP/array-concatenation.gap b/Task/Array-concatenation/GAP/array-concatenation.gap
new file mode 100644
index 0000000000..a9d534615d
--- /dev/null
+++ b/Task/Array-concatenation/GAP/array-concatenation.gap
@@ -0,0 +1,10 @@
+# Concatenate arrays
+Concatenation([1, 2, 3], [4, 5, 6], [7, 8, 9]);
+# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
+
+# Append to a variable
+a := [1, 2, 3];
+Append(a, [4, 5, 6);
+Append(a, [7, 8, 9]);
+a;
+# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
diff --git a/Task/Array-concatenation/Gosu/array-concatenation.gosu b/Task/Array-concatenation/Gosu/array-concatenation.gosu
new file mode 100644
index 0000000000..3cd2a392ed
--- /dev/null
+++ b/Task/Array-concatenation/Gosu/array-concatenation.gosu
@@ -0,0 +1,6 @@
+var listA = { 1, 2, 3 }
+var listB = { 4, 5, 6 }
+
+var listC = listA.concat( listB )
+
+print( listC ) // prints [1, 2, 3, 4, 5, 6]
diff --git a/Task/Array-concatenation/Groovy/array-concatenation-1.groovy b/Task/Array-concatenation/Groovy/array-concatenation-1.groovy
new file mode 100644
index 0000000000..4ed31b0c49
--- /dev/null
+++ b/Task/Array-concatenation/Groovy/array-concatenation-1.groovy
@@ -0,0 +1 @@
+def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"]
diff --git a/Task/Array-concatenation/Groovy/array-concatenation-2.groovy b/Task/Array-concatenation/Groovy/array-concatenation-2.groovy
new file mode 100644
index 0000000000..64ef5c96ea
--- /dev/null
+++ b/Task/Array-concatenation/Groovy/array-concatenation-2.groovy
@@ -0,0 +1 @@
+println list
diff --git a/Task/Array-concatenation/HicEst/array-concatenation.hicest b/Task/Array-concatenation/HicEst/array-concatenation.hicest
new file mode 100644
index 0000000000..67a02970ec
--- /dev/null
+++ b/Task/Array-concatenation/HicEst/array-concatenation.hicest
@@ -0,0 +1,6 @@
+REAL :: a(7), b(3), c(10)
+
+c = a
+DO i = 1, LEN(b)
+ c(i + LEN(a)) = b(i)
+ENDDO
diff --git a/Task/Array-concatenation/IDL/array-concatenation-1.idl b/Task/Array-concatenation/IDL/array-concatenation-1.idl
new file mode 100644
index 0000000000..1ee93be148
--- /dev/null
+++ b/Task/Array-concatenation/IDL/array-concatenation-1.idl
@@ -0,0 +1,10 @@
+ > a = [1,2,3]
+ > b = [4,5,6]
+ > help,a
+ A INT = Array[3]
+ > help,b
+ B INT = Array[3]
+ > print,a
+ 1 2 3
+ > print,b
+ 4 5 6
diff --git a/Task/Array-concatenation/IDL/array-concatenation-2.idl b/Task/Array-concatenation/IDL/array-concatenation-2.idl
new file mode 100644
index 0000000000..9e87f15671
--- /dev/null
+++ b/Task/Array-concatenation/IDL/array-concatenation-2.idl
@@ -0,0 +1,4 @@
+ > help,[a,b]
+ INT = Array[6]
+ > print,[a,b]
+ 1 2 3 4 5 6
diff --git a/Task/Array-concatenation/IDL/array-concatenation-3.idl b/Task/Array-concatenation/IDL/array-concatenation-3.idl
new file mode 100644
index 0000000000..a5c3c99e5e
--- /dev/null
+++ b/Task/Array-concatenation/IDL/array-concatenation-3.idl
@@ -0,0 +1,5 @@
+ > help,[[a],[b]]
+ INT = Array[3, 2]
+ > print,[[a],[b]]
+ 1 2 3
+ 4 5 6
diff --git a/Task/Array-concatenation/IDL/array-concatenation-4.idl b/Task/Array-concatenation/IDL/array-concatenation-4.idl
new file mode 100644
index 0000000000..695b3325be
--- /dev/null
+++ b/Task/Array-concatenation/IDL/array-concatenation-4.idl
@@ -0,0 +1,13 @@
+ > b = transpose(b)
+ > help,b
+ B INT = Array[1, 3]
+ > print,b
+ 4
+ 5
+ 6
+ > print,[a,b]
+ Unable to concatenate variables because the dimensions do not agree: B.
+ Execution halted at: $MAIN$
+ > print,[[a],[b]]
+ Unable to concatenate variables because the dimensions do not agree: B.
+ Execution halted at: $MAIN$
diff --git a/Task/Array-concatenation/Icon/array-concatenation.icon b/Task/Array-concatenation/Icon/array-concatenation.icon
new file mode 100644
index 0000000000..fb55e17143
--- /dev/null
+++ b/Task/Array-concatenation/Icon/array-concatenation.icon
@@ -0,0 +1,10 @@
+procedure main()
+ L1 := [1, 2, 3, 4]
+ L2 := [11, 12, 13, 14]
+ L3 := L1 ||| L2
+
+ sep := ""
+ every writes(sep, !L3) do
+ sep := ", "
+ write()
+end
diff --git a/Task/Array-concatenation/Inform-7/array-concatenation.inf b/Task/Array-concatenation/Inform-7/array-concatenation.inf
new file mode 100644
index 0000000000..3c166d234b
--- /dev/null
+++ b/Task/Array-concatenation/Inform-7/array-concatenation.inf
@@ -0,0 +1,3 @@
+let A be {1, 2, 3};
+let B be {4, 5, 6};
+add B to A;
diff --git a/Task/Array-concatenation/Ioke/array-concatenation.ioke b/Task/Array-concatenation/Ioke/array-concatenation.ioke
new file mode 100644
index 0000000000..3d80c0f70e
--- /dev/null
+++ b/Task/Array-concatenation/Ioke/array-concatenation.ioke
@@ -0,0 +1,3 @@
+iik> [1,2,3] + [3,2,1]
+[1,2,3] + [3,2,1]
++> [1, 2, 3, 3, 2, 1]
diff --git a/Task/Array-concatenation/J/array-concatenation-1.j b/Task/Array-concatenation/J/array-concatenation-1.j
new file mode 100644
index 0000000000..bb635fcb9b
--- /dev/null
+++ b/Task/Array-concatenation/J/array-concatenation-1.j
@@ -0,0 +1,4 @@
+ array1 =: 1 2 3
+ array2 =: 4 5 6
+ array1 , array2
+1 2 3 4 5 6
diff --git a/Task/Array-concatenation/J/array-concatenation-2.j b/Task/Array-concatenation/J/array-concatenation-2.j
new file mode 100644
index 0000000000..6da7a7468b
--- /dev/null
+++ b/Task/Array-concatenation/J/array-concatenation-2.j
@@ -0,0 +1,33 @@
+ ]ab=: 3 3 $ 'aaabbbccc'
+aaa
+bbb
+ccc
+ ]wx=: 3 3 $ 'wxyz'
+wxy
+zwx
+yzw
+ ab , wx
+aaa
+bbb
+ccc
+wxy
+zwx
+yzw
+ ab ,. wx
+aaawxy
+bbbzwx
+cccyzw
+ ab ,: wx
+aaa
+bbb
+ccc
+
+wxy
+zwx
+yzw
+ $ ab , wx NB. applies to first (highest) axis
+6 3
+ $ ab ,. wx NB. applies to last (atomic) axis
+3 6
+ $ ab ,: wx NB. applies to new (higher) axis
+2 3 3
diff --git a/Task/Array-concatenation/Julia/array-concatenation.julia b/Task/Array-concatenation/Julia/array-concatenation.julia
new file mode 100644
index 0000000000..edd741fcf0
--- /dev/null
+++ b/Task/Array-concatenation/Julia/array-concatenation.julia
@@ -0,0 +1,5 @@
+a = [1,2,3]
+b = [4,5,6]
+ab = [a,b]
+#alternative
+ab = vcat(a,b)
diff --git a/Task/Array-concatenation/K/array-concatenation-1.k b/Task/Array-concatenation/K/array-concatenation-1.k
new file mode 100644
index 0000000000..bb9ef52688
--- /dev/null
+++ b/Task/Array-concatenation/K/array-concatenation-1.k
@@ -0,0 +1,4 @@
+ a: 1 2 3
+ b: 4 5 6
+ a,b
+1 2 3 4 5 6
diff --git a/Task/Array-concatenation/K/array-concatenation-2.k b/Task/Array-concatenation/K/array-concatenation-2.k
new file mode 100644
index 0000000000..04ee56b1ab
--- /dev/null
+++ b/Task/Array-concatenation/K/array-concatenation-2.k
@@ -0,0 +1,32 @@
+ ab:3 3#"abcdefghi"
+("abc"
+ "def"
+ "ghi")
+
+ dd:3 3#"012345678"
+("012"
+ "345"
+ "678")
+
+ ab,dd
+("abc"
+ "def"
+ "ghi"
+ "012"
+ "345"
+ "678")
+
+ +ab,dd / flip (transpose) join
+("adg036"
+ "beh147"
+ "cfi258")
+
+ ab,'dd / eachpair join
+("abc012"
+ "def345"
+ "ghi678")
+
+ +(+ab),dd
+("abc036"
+ "def147"
+ "ghi258")
diff --git a/Task/Array-concatenation/Lang5/array-concatenation.lang5 b/Task/Array-concatenation/Lang5/array-concatenation.lang5
new file mode 100644
index 0000000000..d65862fb34
--- /dev/null
+++ b/Task/Array-concatenation/Lang5/array-concatenation.lang5
@@ -0,0 +1 @@
+[1 2] [3 4] append
diff --git a/Task/Array-concatenation/Liberty-BASIC/array-concatenation.liberty b/Task/Array-concatenation/Liberty-BASIC/array-concatenation.liberty
new file mode 100644
index 0000000000..0b7f146bc0
--- /dev/null
+++ b/Task/Array-concatenation/Liberty-BASIC/array-concatenation.liberty
@@ -0,0 +1,18 @@
+ x=10
+ y=20
+ dim array1(x)
+ dim array2(y)
+
+[concatenate]
+ dim array3(x + y)
+ for i = 1 to x
+ array3(i) = array1(i)
+ next
+ for i = 1 to y
+ array3(i + x) = array2(i)
+ next
+
+[print]
+ for i = 1 to x + y
+ print array3(i)
+ next
diff --git a/Task/Array-concatenation/Logo/array-concatenation.logo b/Task/Array-concatenation/Logo/array-concatenation.logo
new file mode 100644
index 0000000000..16d0c03a2c
--- /dev/null
+++ b/Task/Array-concatenation/Logo/array-concatenation.logo
@@ -0,0 +1,4 @@
+to combine-arrays :a1 :a2
+ output listtoarray sentence arraytolist :a1 arraytolist :a2
+end
+show combine-arrays {1 2 3} {4 5 6} ; {1 2 3 4 5 6}
diff --git a/Task/Array-concatenation/Maple/array-concatenation-1.maple b/Task/Array-concatenation/Maple/array-concatenation-1.maple
new file mode 100644
index 0000000000..9e470e6e48
--- /dev/null
+++ b/Task/Array-concatenation/Maple/array-concatenation-1.maple
@@ -0,0 +1,25 @@
+> A := Array( [ 1, 2, 3 ] );
+ A := [1, 2, 3]
+
+> B := Vector['row']( [ sin( x ), cos( x ), tan( x ) ] );
+ B := [sin(x), cos(x), tan(x)]
+
+> ArrayTools:-Concatenate( 1, A, B ); # stack vertically
+ [ 1 2 3 ]
+ [ ]
+ [sin(x) cos(x) tan(x)]
+
+> ArrayTools:-Concatenate( 2, A, B ); # stack horizontally
+ [1, 2, 3, sin(x), cos(x), tan(x)]
+
+> M := << a, b, c ; d, e, f >>; # a matrix
+ [a b c]
+ M := [ ]
+ [d e f]
+
+> ArrayTools:-Concatenate( 1, M, A );
+ [a b c]
+ [ ]
+ [d e f]
+ [ ]
+ [1 2 3]
diff --git a/Task/Array-concatenation/Maple/array-concatenation-2.maple b/Task/Array-concatenation/Maple/array-concatenation-2.maple
new file mode 100644
index 0000000000..79b61516f5
--- /dev/null
+++ b/Task/Array-concatenation/Maple/array-concatenation-2.maple
@@ -0,0 +1,6 @@
+> ArrayTools:-Concatenate( 1, A, M );
+ [1 2 3]
+ [ ]
+ [a b c]
+ [ ]
+ [d e f]
diff --git a/Task/Array-concatenation/Maple/array-concatenation-3.maple b/Task/Array-concatenation/Maple/array-concatenation-3.maple
new file mode 100644
index 0000000000..e68b99028d
--- /dev/null
+++ b/Task/Array-concatenation/Maple/array-concatenation-3.maple
@@ -0,0 +1,11 @@
+> L1 := [ 1, 2, 3 ];
+ L1 := [1, 2, 3]
+
+> L2 := [ a, b, c ];
+ L2 := [a, b, c]
+
+> [ op( L1 ), op( L2 ) ];
+ [1, 2, 3, a, b, c]
+
+> [ L1[], L2[] ]; # equivalent, just different syntax
+ [1, 2, 3, a, b, c]
diff --git a/Task/Array-concatenation/Mathematica/array-concatenation.mathematica b/Task/Array-concatenation/Mathematica/array-concatenation.mathematica
new file mode 100644
index 0000000000..80670e5562
--- /dev/null
+++ b/Task/Array-concatenation/Mathematica/array-concatenation.mathematica
@@ -0,0 +1,3 @@
+Join[{1,2,3}, {4,5,6}]
+
+-> {1, 2, 3, 4, 5, 6}
diff --git a/Task/Array-concatenation/Maxima/array-concatenation.maxima b/Task/Array-concatenation/Maxima/array-concatenation.maxima
new file mode 100644
index 0000000000..48f54aee6d
--- /dev/null
+++ b/Task/Array-concatenation/Maxima/array-concatenation.maxima
@@ -0,0 +1,23 @@
+u: [1, 2, 3, 4]$
+v: [5, 6, 7, 8, 9, 10]$
+append(u, v);
+/* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] */
+
+/* There are also functions for matrices */
+
+a: matrix([6, 1, 8],
+ [7, 5, 3],
+ [2, 9, 4])$
+
+addcol(a, ident(3));
+/* matrix([6, 1, 8, 1, 0, 0],
+ [7, 5, 3, 0, 1, 0],
+ [2, 9, 4, 0, 0, 1]) */
+
+addrow(a, ident(3));
+/* matrix([6, 1, 8],
+ [7, 5, 3],
+ [2, 9, 4],
+ [1, 0, 0],
+ [0, 1, 0],
+ [0, 0, 1]) */
diff --git a/Task/Array-concatenation/Mercury/array-concatenation.mercury b/Task/Array-concatenation/Mercury/array-concatenation.mercury
new file mode 100644
index 0000000000..aba0703fbb
--- /dev/null
+++ b/Task/Array-concatenation/Mercury/array-concatenation.mercury
@@ -0,0 +1 @@
+A `append` B = C
diff --git a/Task/Arrays/Factor/arrays-1.factor b/Task/Arrays/Factor/arrays-1.factor
new file mode 100644
index 0000000000..316ffebc5a
--- /dev/null
+++ b/Task/Arrays/Factor/arrays-1.factor
@@ -0,0 +1,7 @@
+{ 1 2 3 }
+{
+ [ "The initial array: " write . ]
+ [ [ 42 1 ] dip set-nth ]
+ [ "Modified array: " write . ]
+ [ "The element we modified: " write [ 1 ] dip nth . ]
+} cleave
diff --git a/Task/Arrays/Factor/arrays-2.factor b/Task/Arrays/Factor/arrays-2.factor
new file mode 100644
index 0000000000..1c7793c4dd
--- /dev/null
+++ b/Task/Arrays/Factor/arrays-2.factor
@@ -0,0 +1,6 @@
+V{ 1 2 3 }
+{
+ [ "The initial vector: " write . ]
+ [ [ 42 ] dip push ]
+ [ "Modified vector: " write . ]
+} cleave
diff --git a/Task/Arrays/GAP/arrays.gap b/Task/Arrays/GAP/arrays.gap
new file mode 100644
index 0000000000..8dc56657b7
--- /dev/null
+++ b/Task/Arrays/GAP/arrays.gap
@@ -0,0 +1,45 @@
+# Arrays are better called lists in GAP. Lists may have elements of mixed types, e$
+v := [ 10, 7, "bob", true, [ "inner", 5 ] ];
+# [ 10, 7, "bob", true, [ "inner", 5 ] ]
+
+# List index runs from 1 to Size(v)
+v[1];
+# 10
+
+v[0];
+# error
+
+v[5];
+# [ "inner", 5 ]
+
+v[6];
+# error
+
+# One can assign a value to an undefined element
+v[6] := 100;
+
+# Even if it's not after the last: a list may have undefined elements
+v[10] := 1000;
+v;
+# [ 10, 7, "bob", true, [ "inner", 5 ], 100,,,, 1000 ]
+
+# And one can check for defined values
+IsBound(v[10]);
+# true
+
+IsBound(v[9]);
+# false
+
+# Size of the list
+Size(v);
+# 10
+
+# Appending a list to the end of another
+Append(v, [ 8, 9]);
+v;
+# [ 10, 7, "bob", true, [ "inner", 5 ], 100,,,, 1000, 8, 9 ]
+
+# Adding an element at the end
+Add(v, "added");
+v;
+# [ 10, 7, "bob", true, [ "inner", 5 ], 100,,,, 1000, 8, 9, "added" ]
diff --git a/Task/Arrays/GML/arrays-1.gml b/Task/Arrays/GML/arrays-1.gml
new file mode 100644
index 0000000000..c956a6e8ee
--- /dev/null
+++ b/Task/Arrays/GML/arrays-1.gml
@@ -0,0 +1,4 @@
+array[0] = ' '
+array[1] = 'A'
+array[2] = 'B'
+array[3] = 'C'
diff --git a/Task/Arrays/GML/arrays-2.gml b/Task/Arrays/GML/arrays-2.gml
new file mode 100644
index 0000000000..7b918c83b6
--- /dev/null
+++ b/Task/Arrays/GML/arrays-2.gml
@@ -0,0 +1,2 @@
+for(i = 0; i < k; i += 1)
+ array[i] = i + 1
diff --git a/Task/Arrays/GML/arrays-3.gml b/Task/Arrays/GML/arrays-3.gml
new file mode 100644
index 0000000000..aede078472
--- /dev/null
+++ b/Task/Arrays/GML/arrays-3.gml
@@ -0,0 +1,12 @@
+array[1,1] = 1
+array[1,2] = 2
+array[1,3] = 3
+array[1,4] = 4
+array[2,1] = 2
+array[2,2] = 4
+array[2,3] = 6
+array[2,4] = 8
+array[3,1] = 3
+array[3,2] = 6
+array[3,3] = 9
+array[3,4] = 12
diff --git a/Task/Arrays/GML/arrays-4.gml b/Task/Arrays/GML/arrays-4.gml
new file mode 100644
index 0000000000..cc01ddee35
--- /dev/null
+++ b/Task/Arrays/GML/arrays-4.gml
@@ -0,0 +1,3 @@
+for(i = 1; i <= k; i += 1)
+ for(j = 1; j <= h; j += 1)
+ array[i,j] = i * j
diff --git a/Task/Arrays/GUISS/arrays.guiss b/Task/Arrays/GUISS/arrays.guiss
new file mode 100644
index 0000000000..c17a7d445e
--- /dev/null
+++ b/Task/Arrays/GUISS/arrays.guiss
@@ -0,0 +1 @@
+Start,Programs,Lotus 123,Type:Bob[downarrow],Kat[downarrow],Sarah[downarrow]
diff --git a/Task/Arrays/Gambas/arrays.gambas b/Task/Arrays/Gambas/arrays.gambas
new file mode 100644
index 0000000000..2848498fb1
--- /dev/null
+++ b/Task/Arrays/Gambas/arrays.gambas
@@ -0,0 +1,8 @@
+DIM mynumbers AS INTEGER[]
+myfruits AS STRING[]
+
+mynumbers[0] = 1.5
+mynumbers[1] = 2.3
+
+myfruits[0] = "apple"
+myfruits[1] = "banana"
diff --git a/Task/Arrays/Golfscript/arrays.golf b/Task/Arrays/Golfscript/arrays.golf
new file mode 100644
index 0000000000..28bd325e50
--- /dev/null
+++ b/Task/Arrays/Golfscript/arrays.golf
@@ -0,0 +1,5 @@
+[1 2 3]:a; # numeric only array, assigned to a and then dropped
+10,:a; # assign to a [0 1 2 3 4 5 6 7 8 9]
+a 0= puts # pick element at index 0 (stack: 0)
+a 10+puts # append 10 to the end of a
+10 a+puts # prepend 10 to a
diff --git a/Task/Arrays/Groovy/arrays-1.groovy b/Task/Arrays/Groovy/arrays-1.groovy
new file mode 100644
index 0000000000..2a8ce1e5e1
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-1.groovy
@@ -0,0 +1,20 @@
+def aa = [ 1, 25, 31, -3 ] // list
+def a = [0] * 100 // list of 100 zeroes
+def b = 1..9 // range notation
+def c = (1..10).collect { 2.0**it } // each output element is 2**(corresponding invoking list element)
+
+// There are no true "multi-dimensional" arrays in Groovy (as in most C-derived languages).
+// Use lists of lists in natural ("row major") order as a stand in.
+def d = (0..1).collect { i -> (1..5).collect { j -> 2**(5*i+j) as double } }
+def e = [ [ 1.0, 2.0, 3.0, 4.0 ],
+ [ 5.0, 6.0, 7.0, 8.0 ],
+ [ 9.0, 10.0, 11.0, 12.0 ],
+ [ 13.0, 14.0, 15.0, 16.0 ] ]
+
+println aa
+println b
+println c
+println()
+d.each { print "["; it.each { elt -> printf "%7.1f ", elt }; println "]" }
+println()
+e.each { print "["; it.each { elt -> printf "%7.1f ", elt }; println "]" }
diff --git a/Task/Arrays/Groovy/arrays-2.groovy b/Task/Arrays/Groovy/arrays-2.groovy
new file mode 100644
index 0000000000..b938fea146
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-2.groovy
@@ -0,0 +1,3 @@
+def identity = { n ->
+ (1..n).collect { i -> (1..n).collect { j -> i==j ? 1.0 : 0.0 } }
+}
diff --git a/Task/Arrays/Groovy/arrays-3.groovy b/Task/Arrays/Groovy/arrays-3.groovy
new file mode 100644
index 0000000000..7eb3f0c35e
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-3.groovy
@@ -0,0 +1,7 @@
+def i2 = identity(2)
+def i15 = identity(15)
+
+
+i2.each { print "["; it.each { elt -> printf "%4.1f ", elt }; println "]" }
+println()
+i15.each { print "["; it.each { elt -> printf "%4.1f ", elt }; println "]" }
diff --git a/Task/Arrays/Groovy/arrays-4.groovy b/Task/Arrays/Groovy/arrays-4.groovy
new file mode 100644
index 0000000000..cb92128ca2
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-4.groovy
@@ -0,0 +1,11 @@
+def strings = ['Mary', 'had', 'a', 'little', 'lamb', ". It's", 'fleece', 'was', 'white', 'as', 'snow']
+
+println strings
+
+strings[0] = 'Arthur'
+strings[4] = 'towel'
+strings[6] = 'stain'
+strings[8] = 'ripe'
+strings[10] = 'strawberries'
+
+println strings
diff --git a/Task/Arrays/Groovy/arrays-5.groovy b/Task/Arrays/Groovy/arrays-5.groovy
new file mode 100644
index 0000000000..67067d3105
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-5.groovy
@@ -0,0 +1 @@
+println strings[-1]
diff --git a/Task/Arrays/Groovy/arrays-6.groovy b/Task/Arrays/Groovy/arrays-6.groovy
new file mode 100644
index 0000000000..8d3f9ba85d
--- /dev/null
+++ b/Task/Arrays/Groovy/arrays-6.groovy
@@ -0,0 +1,3 @@
+println strings[0, 7, 2, 3, 8]
+println strings[0..4]
+println strings[0..3, -5]
diff --git a/Task/Arrays/HicEst/arrays-1.hicest b/Task/Arrays/HicEst/arrays-1.hicest
new file mode 100644
index 0000000000..410727cc4f
--- /dev/null
+++ b/Task/Arrays/HicEst/arrays-1.hicest
@@ -0,0 +1,11 @@
+REAL :: n = 3, Astat(n), Bdyn(1, 1)
+
+Astat(2) = 2.22222222
+WRITE(Messagebox, Name) Astat(2)
+
+ALLOCATE(Bdyn, 2*n, 3*n)
+Bdyn(n-1, n) = -123
+WRITE(Row=27) Bdyn(n-1, n)
+
+ALIAS(Astat, n-1, last2ofAstat, 2)
+WRITE(ClipBoard) last2ofAstat ! 2.22222222 0
diff --git a/Task/Arrays/HicEst/arrays-2.hicest b/Task/Arrays/HicEst/arrays-2.hicest
new file mode 100644
index 0000000000..ae65dbdff8
--- /dev/null
+++ b/Task/Arrays/HicEst/arrays-2.hicest
@@ -0,0 +1,98 @@
+record aThing(a, b, c) # arbitrary object (record or class) for illustration
+
+procedure main()
+ A0 := [] # empty list
+ A0 := list() # empty list (default size 0)
+ A0 := list(0) # empty list (literal size 0)
+
+ A1 := list(10) # 10 elements, default initializer &null
+ A2 := list(10, 1) # 10 elements, initialized to 1
+
+ # literal array construction - arbitrary dynamically typed members
+ A3 := [1, 2, 3, ["foo", "bar", "baz"], aThing(1, 2, 3), "the end"]
+
+ # left-end workers
+ # NOTE: get() is a synonym for pop() which allows nicely-worded use of put() and get() to implement queues
+ #
+ Q := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+ x := pop(A0) # x is 1
+ x := get(A0) # x is 2
+ push(Q,0)
+ # Q is now [0,3, 4, 5, 6, 7, 8, 9, 10]
+
+ # right-end workers
+ x := pull(Q) # x is 10
+ put(Q, 100) # Q is now [0, 3, 4, 5, 6, 7, 8, 9, 100]
+
+ # push and put return the list they are building
+ # they also can have multiple arguments which work like repeated calls
+
+ Q2 := put([],1,2,3) # Q2 is [1,2,3]
+ Q3 := push([],1,2,3) # Q3 is [3,2,1]
+ Q4 := push(put(Q2),4),0] # Q4 is [0,1,2,3,4] and so is Q2
+
+ # array access follows with A as the sample array
+ A := [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
+
+ # get element indexed from left
+ x := A[1] # x is 10
+ x := A[2] # x is 20
+ x := A[10] # x is 100
+
+ # get element indexed from right
+ x := A[-1] # x is 100
+ x := A[-2] # x is 90
+ x := A[-10] # x is 10
+
+ # copy array to show assignment to elements
+ B := copy(A)
+
+ # assign element indexed from left
+ B[1] := 11
+ B[2] := 21
+ B[10] := 101
+ # B is now [11, 21, 30, 50, 60, 60, 70, 80, 90, 101]
+
+ # assign element indexed from right - see below
+ B[-1] := 102
+ B[-2] := 92
+ B[-10] := 12
+ # B is now [12, 21, 30, 50, 60, 60, 70, 80, 92, 102]
+
+ # list slicing
+ # the unusual nature of the slice - returning 1 less element than might be expected
+ # in many languages - is best understood if you imagine indexes as pointing to BEFORE
+ # the item of interest. When a slice is made, the elements between the two points are
+ # collected. eg in the A[3 : 6] sample, it will get the elements between the [ ] marks
+ #
+ # sample list: 10 20 [30 40 50] 60 70 80 90 100
+ # positive indexes: 1 2 3 4 5 6 7 8 9 10 11
+ # non-positive indexes: -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
+ #
+ # I have deliberately drawn the indexes between the positions of the values.
+ # The nature of this indexing brings simplicity to string operations
+ #
+ # list slicing can also use non-positive indexes to access values from the right.
+ # The final index of 0 shown above shows how the end of the list can be nominated
+ # without having to know it's length
+ #
+ # NOTE: list slices are distinct lists, so assigning to the slice
+ # or a member of the slice does not change the values in A
+ #
+ # Another key fact to understand: once the non-positive indexes and length-offsets are
+ # resolved to a simple positive index, the index pair (if two are given) are swapped
+ # if necessary to yield the elements between the two.
+ #
+ S := A[3 : 6] # S is [30, 40, 50]
+ S := A[6 : 3] # S is [30, 40, 50] not illegal or erroneous
+ S := A[-5 : -8] # S is [30, 40, 50]
+ S := A[-8 : -5] # S is [30, 40, 50] also legal and meaningful
+
+ # list slicing with length request
+ S := A[3 +: 3] # S is [30, 40, 50]
+ S := A[6 -: 3] # S is [30, 40, 50]
+ S := A[-8 +: 3] # S is [30, 40, 50]
+ S := A[-5 -: 3] # S is [30, 40, 50]
+ S := A[-8 -: -3] # S is [30, 40, 50]
+ S := A[-5 +: -3] # S is [30, 40, 50]
+end
diff --git a/Task/Arrays/HicEst/arrays-3.hicest b/Task/Arrays/HicEst/arrays-3.hicest
new file mode 100644
index 0000000000..a3a972a13f
--- /dev/null
+++ b/Task/Arrays/HicEst/arrays-3.hicest
@@ -0,0 +1,3 @@
+# Unicon provides a number of extensions
+# insert and delete work on lists allowing changes in the middle
+# possibly others
diff --git a/Task/Arrays/Io/arrays.io b/Task/Arrays/Io/arrays.io
new file mode 100644
index 0000000000..66b00c3f43
--- /dev/null
+++ b/Task/Arrays/Io/arrays.io
@@ -0,0 +1,5 @@
+foo := list("foo", "bar", "baz")
+foo at(1) println // bar
+foo append("Foobarbaz")
+foo println
+foo atPut(2, "barbaz") // baz becomes barbaz
diff --git a/Task/Arrays/J/arrays.j b/Task/Arrays/J/arrays.j
new file mode 100644
index 0000000000..35ff36045b
--- /dev/null
+++ b/Task/Arrays/J/arrays.j
@@ -0,0 +1,28 @@
+ 1 NB. a stand-alone scalar value is an array without any axis
+1
+ NB. invoking any array produces that array as the result
+ {. array=: 1 3, 6#0 NB. create, name, then get head item of the array: 1 3 0 0 0 0 0 0
+1
+ 0 { array NB. another way to get the head item
+1
+ aword=: 'there' NB. a literal array
+ 0 1 3 2 2 { aword NB. multiple items can be drawn in a single action
+three
+ ]twoD=: 3 5 $ 'abcdefghijklmnopqrstuvwxyz'
+abcde
+fghij
+klmno
+ 1 { twoD NB. item 1 from twoD - a list of three items
+fghij
+ 1 {"1 twoD NB. item 1 from each rank-1 item of twoD (i.e. column 1)
+bgl
+ (<2 2){ twoD NB. bracket indexing is not used in J
+m
+ 'X' 1} aword NB. amend item 1
+tXere
+ aword=: 'X' 1 4} aword NB. in-place amend of items 1 and 4
+tXerX
+ 'X' (0 0;1 1;2 2)} twoD NB. amend specified items
+Xbcde
+fXhij
+klXno
diff --git a/Task/Arrays/KonsolScript/arrays.konso b/Task/Arrays/KonsolScript/arrays.konso
new file mode 100644
index 0000000000..fe4fea1e5d
--- /dev/null
+++ b/Task/Arrays/KonsolScript/arrays.konso
@@ -0,0 +1,11 @@
+//creates an array of length 3
+Array:New array[3]:Number;
+
+function main() {
+ Var:Number length;
+ Array:GetLength(array, length) //retrieve length of array
+ Konsol:Log(length)
+
+ array[0] = 5; //assign value
+ Konsol:Log(array[0]) //retrieve value and display
+}
diff --git a/Task/Arrays/LSE64/arrays.lse64 b/Task/Arrays/LSE64/arrays.lse64
new file mode 100644
index 0000000000..2112e8b9ee
--- /dev/null
+++ b/Task/Arrays/LSE64/arrays.lse64
@@ -0,0 +1,3 @@
+10 myArray :array
+0 array 5 [] ! # store 0 at the sixth cell in the array
+array 5 [] @ # contents of sixth cell in array
diff --git a/Task/Arrays/LSL/arrays.lsl b/Task/Arrays/LSL/arrays.lsl
new file mode 100644
index 0000000000..1f9bddca0f
--- /dev/null
+++ b/Task/Arrays/LSL/arrays.lsl
@@ -0,0 +1,28 @@
+default {
+ state_entry() {
+ list lst = ["1", "2", "3"];
+ llSay(0, "Create and Initialize a List\nList=["+llList2CSV(lst)+"]\n");
+
+ lst += ["A", "B", "C"];
+ llSay(0, "Append to List\nList=["+llList2CSV(lst)+"]\n");
+
+ lst = llListInsertList(lst, ["4", "5", "6"], 3);
+ llSay(0, "List Insertion\nList=["+llList2CSV(lst)+"]\n");
+
+ lst = llListReplaceList(lst, ["a", "b", "c"], 3, 5);
+ llSay(0, "Replace a portion of a list\nList=["+llList2CSV(lst)+"]\n");
+
+ lst = llListRandomize(lst, 1);
+ llSay(0, "Randomize a List\nList=["+llList2CSV(lst)+"]\n");
+
+ lst = llListSort(lst, 1, TRUE);
+ llSay(0, "Sort a List\nList=["+llList2CSV(lst)+"]\n");
+
+ lst = [1, 2.0, "string", (key)NULL_KEY, ZERO_VECTOR, ZERO_ROTATION];
+ string sCSV = llList2CSV(lst);
+ llSay(0, "Serialize a List of different datatypes to a string\n(integer, float, string, key, vector, rotation)\nCSV=\""+sCSV+"\"\n");
+
+ lst = llCSV2List(sCSV);
+ llSay(0, "Deserialize a string CSV List\n(note that all elements are now string datatype)\nList=["+llList2CSV(lst)+"]\n");
+ }
+}
diff --git a/Task/Arrays/Liberty-BASIC/arrays.liberty b/Task/Arrays/Liberty-BASIC/arrays.liberty
new file mode 100644
index 0000000000..82bdcd5e5f
--- /dev/null
+++ b/Task/Arrays/Liberty-BASIC/arrays.liberty
@@ -0,0 +1,13 @@
+dim Array(10)
+
+Array(0) = -1
+Array(10) = 1
+
+print Array( 0), Array( 10)
+
+REDIM Array( 100)
+
+print Array( 0), Array( 10)
+
+Array( 0) = -1
+print Array( 0), Array( 10)
diff --git a/Task/Arrays/Lisaac/arrays.lisaac b/Task/Arrays/Lisaac/arrays.lisaac
new file mode 100644
index 0000000000..1c969b1700
--- /dev/null
+++ b/Task/Arrays/Lisaac/arrays.lisaac
@@ -0,0 +1,5 @@
++ a : ARRAY(INTEGER);
+a := ARRAY(INTEGER).create 0 to 9;
+a.put 1 to 0;
+a.put 3 to 1;
+a.item(1).print;
diff --git a/Task/Arrays/Logo/arrays.logo b/Task/Arrays/Logo/arrays.logo
new file mode 100644
index 0000000000..acb5dbfe95
--- /dev/null
+++ b/Task/Arrays/Logo/arrays.logo
@@ -0,0 +1,5 @@
+array 5 ; default origin is 1, every item is empty
+(array 5 0) ; custom origin
+make "a {1 2 3 4 5} ; array literal
+setitem 1 :a "ten ; Logo is dynamic; arrays can contain different types
+print item 1 :a ; ten
diff --git a/Task/Arrays/Mathematica/arrays.mathematica b/Task/Arrays/Mathematica/arrays.mathematica
new file mode 100644
index 0000000000..737b0baada
--- /dev/null
+++ b/Task/Arrays/Mathematica/arrays.mathematica
@@ -0,0 +1,3 @@
+a = Array[Sin, 10]
+a[[1]]
+Delete[a, 2]
diff --git a/Task/Arrays/Maxima/arrays.maxima b/Task/Arrays/Maxima/arrays.maxima
new file mode 100644
index 0000000000..44750b326a
--- /dev/null
+++ b/Task/Arrays/Maxima/arrays.maxima
@@ -0,0 +1,25 @@
+/* Declare an array, subscripts run from 0 to max value */
+array(a, flonum, 20, 20, 3)$
+
+arrayinfo(a);
+/* [complete, 3, [20, 20, 3]] */
+
+a[0, 0]: 1.0;
+
+listarray(a);
+/* [1.0, 0.0, 0.0, ..., 0.0] */
+
+/* Show all declared arrays */
+arrays;
+/* [a] */
+
+
+/* One may also use an array without declaring it, it's a hashed array */
+b[1]: 1000;
+b['x]: 3/4; /* hashed array may have any subscript */
+
+arrayinfo(b);
+/* [hashed, 1, [1], [x]] */
+
+listarray(b);
+/* [1000, 3/4] */
diff --git a/Task/Arrays/Modula-3/arrays-1.mod3 b/Task/Arrays/Modula-3/arrays-1.mod3
new file mode 100644
index 0000000000..3aecf873fe
--- /dev/null
+++ b/Task/Arrays/Modula-3/arrays-1.mod3
@@ -0,0 +1 @@
+VAR a: ARRAY [1..10] OF INTEGER;
diff --git a/Task/Arrays/Modula-3/arrays-2.mod3 b/Task/Arrays/Modula-3/arrays-2.mod3
new file mode 100644
index 0000000000..fd03aa8e5e
--- /dev/null
+++ b/Task/Arrays/Modula-3/arrays-2.mod3
@@ -0,0 +1,2 @@
+VAR a := ARRAY [1..10] OF INTEGER {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+VAR arr1 := ARRAY [1..10] OF INTEGER {1, ..} (* Initialize all elements to 1. *)
diff --git a/Task/Arrays/Modula-3/arrays-3.mod3 b/Task/Arrays/Modula-3/arrays-3.mod3
new file mode 100644
index 0000000000..aeffb7495b
--- /dev/null
+++ b/Task/Arrays/Modula-3/arrays-3.mod3
@@ -0,0 +1,2 @@
+VAR arr := ARRAY [1..3] OF INTEGER {1, 2, 3};
+VAR myVar := a[2];
diff --git a/Task/Arrays/Modula-3/arrays-4.mod3 b/Task/Arrays/Modula-3/arrays-4.mod3
new file mode 100644
index 0000000000..ba800feba1
--- /dev/null
+++ b/Task/Arrays/Modula-3/arrays-4.mod3
@@ -0,0 +1,2 @@
+VAR arr := ARRAY [1..3] OF INTEGER;
+arr[1] := 10;
diff --git a/Task/Assertions/Factor/assertions.factor b/Task/Assertions/Factor/assertions.factor
new file mode 100644
index 0000000000..98dc50509e
--- /dev/null
+++ b/Task/Assertions/Factor/assertions.factor
@@ -0,0 +1,2 @@
+USING: kernel ;
+42 assert=
diff --git a/Task/Assertions/GAP/assertions.gap b/Task/Assertions/GAP/assertions.gap
new file mode 100644
index 0000000000..c2f2a6a54c
--- /dev/null
+++ b/Task/Assertions/GAP/assertions.gap
@@ -0,0 +1,19 @@
+# See section 7.5 of reference manual
+
+# GAP has assertions levels. An assertion is tested if its level
+# is less then the global level.
+
+# Set global level
+SetAssertionLevel(10);
+
+a := 1;
+Assert(20, a > 1, "a should be greater than one");
+# nothing happens
+
+a := 1;
+Assert(4, a > 1, "a should be greater than one");
+# error
+
+# Show current global level
+AssertionLevel();
+# 10
diff --git a/Task/Assertions/Groovy/assertions-1.groovy b/Task/Assertions/Groovy/assertions-1.groovy
new file mode 100644
index 0000000000..e6c5230576
--- /dev/null
+++ b/Task/Assertions/Groovy/assertions-1.groovy
@@ -0,0 +1,3 @@
+def checkTheAnswer = {
+ assert it == 42 : "This: " + it + " is not the answer!"
+}
diff --git a/Task/Assertions/Groovy/assertions-2.groovy b/Task/Assertions/Groovy/assertions-2.groovy
new file mode 100644
index 0000000000..6e8661a609
--- /dev/null
+++ b/Task/Assertions/Groovy/assertions-2.groovy
@@ -0,0 +1,4 @@
+println "before 42..."
+checkTheAnswer(42)
+println "before 'Hello Universe'..."
+checkTheAnswer("Hello Universe")
diff --git a/Task/Assertions/Icon/assertions-1.icon b/Task/Assertions/Icon/assertions-1.icon
new file mode 100644
index 0000000000..993292f5d0
--- /dev/null
+++ b/Task/Assertions/Icon/assertions-1.icon
@@ -0,0 +1,5 @@
+...
+runerr(n,( expression ,"Assertion/error - message.")) # Throw (and possibly trap) an error number n if expression succeeds.
+...
+stop(( expression ,"Assertion/stop - message.")) # Terminate program if expression succeeds.
+...
diff --git a/Task/Assertions/Icon/assertions-2.icon b/Task/Assertions/Icon/assertions-2.icon
new file mode 100644
index 0000000000..4111a3796b
--- /dev/null
+++ b/Task/Assertions/Icon/assertions-2.icon
@@ -0,0 +1,12 @@
+$define DEBUG 1 # this allows the assertions to go through
+
+procedure check (a)
+ if DEBUG then stop (42 = a, " is invalid value for 'a'")
+ write (a)
+end
+
+procedure main ()
+ check (10)
+ check (42)
+ check (12)
+end
diff --git a/Task/Assertions/J/assertions.j b/Task/Assertions/J/assertions.j
new file mode 100644
index 0000000000..78b94ed685
--- /dev/null
+++ b/Task/Assertions/J/assertions.j
@@ -0,0 +1 @@
+ assert n = 42
diff --git a/Task/Assertions/Julia/assertions.julia b/Task/Assertions/Julia/assertions.julia
new file mode 100644
index 0000000000..f51e34b12c
--- /dev/null
+++ b/Task/Assertions/Julia/assertions.julia
@@ -0,0 +1,9 @@
+#assert() function takes expression as 1st argument, failed-assertion message as optional 2nd argument
+julia> assert(x==42,"x is not 42")
+ERROR: assertion failed: x is not 42
+#@assert macro checks the supplied conditional expression, with the expression returned in the failed-assertion message
+julia> @assert x==42
+ERROR: assertion failed: :((x==42))
+#Julia also has type assertions of the form, x::Type which can be appended to a variable for type-checking at any point
+julia> x::String
+ERROR: type: typeassert: expected String, got Int32
diff --git a/Task/Assertions/Lisaac/assertions.lisaac b/Task/Assertions/Lisaac/assertions.lisaac
new file mode 100644
index 0000000000..54439b444d
--- /dev/null
+++ b/Task/Assertions/Lisaac/assertions.lisaac
@@ -0,0 +1 @@
+? { n = 42 };
diff --git a/Task/Assertions/Maple/assertions.maple b/Task/Assertions/Maple/assertions.maple
new file mode 100644
index 0000000000..9a95639594
--- /dev/null
+++ b/Task/Assertions/Maple/assertions.maple
@@ -0,0 +1,3 @@
+a := 5:
+ASSERT( a = 42 );
+ASSERT( a = 42, "a is not the answer to life, the universe, and everything" );
diff --git a/Task/Assertions/Mathematica/assertions.mathematica b/Task/Assertions/Mathematica/assertions.mathematica
new file mode 100644
index 0000000000..9bc7ab1537
--- /dev/null
+++ b/Task/Assertions/Mathematica/assertions.mathematica
@@ -0,0 +1 @@
+Assert[var===42]
diff --git a/Task/Assertions/Metafont/assertions-1.metafont b/Task/Assertions/Metafont/assertions-1.metafont
new file mode 100644
index 0000000000..ad8fccc717
--- /dev/null
+++ b/Task/Assertions/Metafont/assertions-1.metafont
@@ -0,0 +1 @@
+def assert(expr t) = if not (t): errmessage("assertion failed") fi enddef;
diff --git a/Task/Assertions/Metafont/assertions-2.metafont b/Task/Assertions/Metafont/assertions-2.metafont
new file mode 100644
index 0000000000..abc812a1e2
--- /dev/null
+++ b/Task/Assertions/Metafont/assertions-2.metafont
@@ -0,0 +1,3 @@
+n := 41;
+assert(n=42);
+message "ok";
diff --git a/Task/Assertions/Modula-3/assertions.mod3 b/Task/Assertions/Modula-3/assertions.mod3
new file mode 100644
index 0000000000..36c3815842
--- /dev/null
+++ b/Task/Assertions/Modula-3/assertions.mod3
@@ -0,0 +1 @@
+<*ASSERT a = 42*>
diff --git a/Task/Associative-array-Creation/Factor/associative-array-creation.factor b/Task/Associative-array-Creation/Factor/associative-array-creation.factor
new file mode 100644
index 0000000000..9578618bef
--- /dev/null
+++ b/Task/Associative-array-Creation/Factor/associative-array-creation.factor
@@ -0,0 +1,6 @@
+H{ { "one" 1 } { "two" 2 } }
+{ [ "one" swap at . ]
+ [ 2 swap value-at . ]
+ [ "three" swap at . ]
+ [ [ 3 "three" ] dip set-at ]
+ [ "three" swap at . ] } cleave
diff --git a/Task/Associative-array-Creation/Fantom/associative-array-creation.fantom b/Task/Associative-array-Creation/Fantom/associative-array-creation.fantom
new file mode 100644
index 0000000000..d12c31b105
--- /dev/null
+++ b/Task/Associative-array-Creation/Fantom/associative-array-creation.fantom
@@ -0,0 +1,17 @@
+class Main
+{
+ public static Void main ()
+ {
+ // create a map which maps Ints to Strs, with given key-value pairs
+ Int:Str map := [1:"alpha", 2:"beta", 3:"gamma"]
+
+ // create an empty map
+ Map map2 := [:]
+ // now add some numbers mapped to their doubles
+ 10.times |Int i|
+ {
+ map2[i] = 2*i
+ }
+
+ }
+}
diff --git a/Task/Associative-array-Creation/Groovy/associative-array-creation-1.groovy b/Task/Associative-array-Creation/Groovy/associative-array-creation-1.groovy
new file mode 100644
index 0000000000..3fc5ed102e
--- /dev/null
+++ b/Task/Associative-array-Creation/Groovy/associative-array-creation-1.groovy
@@ -0,0 +1,10 @@
+map = [:]
+map[7] = 7
+map['foo'] = 'foovalue'
+map.put('bar', 'barvalue')
+map.moo = 'moovalue'
+
+assert 7 == map[7]
+assert 'foovalue' == map.foo
+assert 'barvalue' == map['bar']
+assert 'moovalue' == map.get('moo')
diff --git a/Task/Associative-array-Creation/Groovy/associative-array-creation-2.groovy b/Task/Associative-array-Creation/Groovy/associative-array-creation-2.groovy
new file mode 100644
index 0000000000..4f3e5d78eb
--- /dev/null
+++ b/Task/Associative-array-Creation/Groovy/associative-array-creation-2.groovy
@@ -0,0 +1,6 @@
+map = [7:7, foo:'foovalue', bar:'barvalue', moo:'moovalue']
+
+assert 7 == map[7]
+assert 'foovalue' == map.foo
+assert 'barvalue' == map['bar']
+assert 'moovalue' == map.get('moo')
diff --git a/Task/Associative-array-Creation/Icon/associative-array-creation.icon b/Task/Associative-array-Creation/Icon/associative-array-creation.icon
new file mode 100644
index 0000000000..b94f5e929c
--- /dev/null
+++ b/Task/Associative-array-Creation/Icon/associative-array-creation.icon
@@ -0,0 +1,6 @@
+procedure main()
+ local t
+ t := table()
+ t["foo"] := "bar"
+ write(t["foo"])
+end
diff --git a/Task/Associative-array-Creation/Inform-7/associative-array-creation-1.inf b/Task/Associative-array-Creation/Inform-7/associative-array-creation-1.inf
new file mode 100644
index 0000000000..3bff2ad87f
--- /dev/null
+++ b/Task/Associative-array-Creation/Inform-7/associative-array-creation-1.inf
@@ -0,0 +1,18 @@
+Hash Bar is a room.
+
+Connection relates various texts to one number. The verb to be connected to implies the connection relation.
+
+"foo" is connected to 12.
+"bar" is connected to 34.
+"baz" is connected to 56.
+
+When play begins:
+ [change values]
+ now "bleck" is connected to 78;
+ [check values]
+ if "foo" is connected to 12, say "good.";
+ if "bar" is not connected to 56, say "good.";
+ [retrieve values]
+ let V be the number that "baz" relates to by the connection relation;
+ say "'baz' => [V].";
+ end the story.
diff --git a/Task/Associative-array-Creation/Inform-7/associative-array-creation-2.inf b/Task/Associative-array-Creation/Inform-7/associative-array-creation-2.inf
new file mode 100644
index 0000000000..db9f750318
--- /dev/null
+++ b/Task/Associative-array-Creation/Inform-7/associative-array-creation-2.inf
@@ -0,0 +1,15 @@
+Hash Bar is a room.
+
+When play begins:
+ let R be a various-to-one relation of texts to numbers;
+ [initialize the relation]
+ now R relates "foo" to 12;
+ now R relates "bar" to 34;
+ now R relates "baz" to 56;
+ [check values]
+ if R relates "foo" to 12, say "good.";
+ if R does not relate "bar" to 56, say "good.";
+ [retrieve values]
+ let V be the number that "baz" relates to by R;
+ say "'baz' => [V].";
+ end the story.
diff --git a/Task/Associative-array-Creation/Ioke/associative-array-creation.ioke b/Task/Associative-array-Creation/Ioke/associative-array-creation.ioke
new file mode 100644
index 0000000000..7aba2c6a62
--- /dev/null
+++ b/Task/Associative-array-Creation/Ioke/associative-array-creation.ioke
@@ -0,0 +1 @@
+{a: "a", b: "b"}
diff --git a/Task/Associative-array-Creation/J/associative-array-creation-1.j b/Task/Associative-array-Creation/J/associative-array-creation-1.j
new file mode 100644
index 0000000000..f63108d899
--- /dev/null
+++ b/Task/Associative-array-Creation/J/associative-array-creation-1.j
@@ -0,0 +1,5 @@
+coclass 'assocArray'
+ encode=: 'z', (a.{~;48 65 97(+ i.)&.>10 26 26) {~ 62x #.inv 256x #. a.&i.
+ get=: ".@encode
+ has=: 0 <: nc@<@encode
+ set=:4 :'(encode x)=:y'
diff --git a/Task/Associative-array-Creation/J/associative-array-creation-2.j b/Task/Associative-array-Creation/J/associative-array-creation-2.j
new file mode 100644
index 0000000000..2bda49123b
--- /dev/null
+++ b/Task/Associative-array-Creation/J/associative-array-creation-2.j
@@ -0,0 +1,13 @@
+ example=: conew 'assocArray'
+ 'foo' set__example 1 2 3
+1 2 3
+ 'bar' set__example 4 5 6
+4 5 6
+ get__example 'foo'
+1 2 3
+ has__example 'foo'
+1
+ bletch__example=: 7 8 9
+ get__example 'bletch'
+7 8 9
+ codestroy__example''
diff --git a/Task/Associative-array-Creation/K/associative-array-creation-1.k b/Task/Associative-array-Creation/K/associative-array-creation-1.k
new file mode 100644
index 0000000000..0aeedbdd77
--- /dev/null
+++ b/Task/Associative-array-Creation/K/associative-array-creation-1.k
@@ -0,0 +1,6 @@
+ / creating an dictionary
+ d1:.((`foo;1); (`bar;2); (`baz;3))
+
+ / extracting a value
+ d1[`bar]
+2
diff --git a/Task/Associative-array-Creation/K/associative-array-creation-2.k b/Task/Associative-array-Creation/K/associative-array-creation-2.k
new file mode 100644
index 0000000000..18027d82a8
--- /dev/null
+++ b/Task/Associative-array-Creation/K/associative-array-creation-2.k
@@ -0,0 +1,9 @@
+ d2: .() / create empty dictionary
+ d2[`"zero"]:0
+ d2[`"one"]:1
+ d2[`"two"]:2
+
+ d2
+.((`zero;0;)
+ (`one;1;)
+ (`two;2;))
diff --git a/Task/Associative-array-Creation/K/associative-array-creation-3.k b/Task/Associative-array-Creation/K/associative-array-creation-3.k
new file mode 100644
index 0000000000..ed9ffc7d88
--- /dev/null
+++ b/Task/Associative-array-Creation/K/associative-array-creation-3.k
@@ -0,0 +1,5 @@
+ !d2 / the keys
+`zero `one `two
+
+ d2[] / the values
+0 1 2
diff --git a/Task/Associative-array-Creation/Lang5/associative-array-creation.lang5 b/Task/Associative-array-Creation/Lang5/associative-array-creation.lang5
new file mode 100644
index 0000000000..408de045bf
--- /dev/null
+++ b/Task/Associative-array-Creation/Lang5/associative-array-creation.lang5
@@ -0,0 +1,17 @@
+: dip swap '_ set execute _ ; : nip swap drop ;
+: first 0 extract nip ; : second 1 extract nip ;
+
+: assoc-in swap keys eq ;
+: assoc-index' over keys swap eq [1] index collapse ;
+: at swap assoc-index' subscript collapse second ;
+: delete-at swap assoc-index' first remove ;
+: keys 1 transpose first ;
+: set-at
+ over 'dup dip assoc-in '+ reduce if 'dup dip delete-at then
+ "swap 2 compress 1 compress" dip swap append ;
+
+[['foo 5]]
+10 'bar rot set-at
+'bar over at .
+'hello 'bar rot set-at
+20 'baz rot set-at .
diff --git a/Task/Associative-array-Creation/Liberty-BASIC/associative-array-creation.liberty b/Task/Associative-array-Creation/Liberty-BASIC/associative-array-creation.liberty
new file mode 100644
index 0000000000..c8d5132d9e
--- /dev/null
+++ b/Task/Associative-array-Creation/Liberty-BASIC/associative-array-creation.liberty
@@ -0,0 +1,12 @@
+data "red", "255 50 50", "green", "50 255 50", "blue", "50 50 255"
+data "my fave", "220 120 120", "black", "0 0 0"
+
+myAssocList$ =""
+
+for i =1 to 5
+ read k$
+ read dat$
+ call sl.Set myAssocList$, k$, dat$
+next i
+
+print " Key 'green' is associated with data item "; sl.Get$( myAssocList$, "green")
diff --git a/Task/Associative-array-Creation/Logo/associative-array-creation.logo b/Task/Associative-array-Creation/Logo/associative-array-creation.logo
new file mode 100644
index 0000000000..a30d35e696
--- /dev/null
+++ b/Task/Associative-array-Creation/Logo/associative-array-creation.logo
@@ -0,0 +1,6 @@
+pprop "animals "cat 5
+pprop "animals "dog 4
+pprop "animals "mouse 11
+print gprop "animals "cat ; 5
+remprop "animals "dog
+show plist "animals ; [mouse 11 cat 5]
diff --git a/Task/Associative-array-Creation/Maple/associative-array-creation-1.maple b/Task/Associative-array-Creation/Maple/associative-array-creation-1.maple
new file mode 100644
index 0000000000..673fa248cc
--- /dev/null
+++ b/Task/Associative-array-Creation/Maple/associative-array-creation-1.maple
@@ -0,0 +1,11 @@
+> T := table( [ (2,3) = 4, "foo" = 1, sin(x) = cos(x) ] );
+ T := table(["foo" = 1, sin(x) = cos(x), (2, 3) = 4])
+
+> T[2,3];
+ 4
+
+> T[sin(x)];
+ cos(x)
+
+> T["foo"];
+ 1
diff --git a/Task/Associative-array-Creation/Maple/associative-array-creation-2.maple b/Task/Associative-array-Creation/Maple/associative-array-creation-2.maple
new file mode 100644
index 0000000000..816d973f6e
--- /dev/null
+++ b/Task/Associative-array-Creation/Maple/associative-array-creation-2.maple
@@ -0,0 +1,5 @@
+> T[ "bar" ] := 2;
+ T["bar"] := 2
+
+> T[ "bar" ];
+ 2
diff --git a/Task/Associative-array-Creation/Maple/associative-array-creation-3.maple b/Task/Associative-array-Creation/Maple/associative-array-creation-3.maple
new file mode 100644
index 0000000000..bada120c23
--- /dev/null
+++ b/Task/Associative-array-Creation/Maple/associative-array-creation-3.maple
@@ -0,0 +1,5 @@
+> T[ "foo" ] := evaln( T[ "foo" ] );
+ T["foo"] := T["foo"]
+
+> T[ "foo" ];
+ T["foo"]
diff --git a/Task/Associative-array-Creation/Mathematica/associative-array-creation.mathematica b/Task/Associative-array-Creation/Mathematica/associative-array-creation.mathematica
new file mode 100644
index 0000000000..747508b30e
--- /dev/null
+++ b/Task/Associative-array-Creation/Mathematica/associative-array-creation.mathematica
@@ -0,0 +1 @@
+a[2] = "string"; a["sometext"] = 23;
diff --git a/Task/Associative-array-Creation/Maxima/associative-array-creation.maxima b/Task/Associative-array-Creation/Maxima/associative-array-creation.maxima
new file mode 100644
index 0000000000..1600675ed3
--- /dev/null
+++ b/Task/Associative-array-Creation/Maxima/associative-array-creation.maxima
@@ -0,0 +1,7 @@
+/* No need to declare anything, undeclared arrays are hashed */
+
+h[1]: 6;
+h[9]: 2;
+
+arrayinfo(h);
+[hashed, 1, [1], [9]]
diff --git a/Task/Associative-array-Iteration/Factor/associative-array-iteration.factor b/Task/Associative-array-Iteration/Factor/associative-array-iteration.factor
new file mode 100644
index 0000000000..822084c470
--- /dev/null
+++ b/Task/Associative-array-Iteration/Factor/associative-array-iteration.factor
@@ -0,0 +1 @@
+H{ { "hi" "there" } { "a" "b" } } [ ": " glue print ] assoc-each
diff --git a/Task/Associative-array-Iteration/Fantom/associative-array-iteration.fantom b/Task/Associative-array-Iteration/Fantom/associative-array-iteration.fantom
new file mode 100644
index 0000000000..8b880636be
--- /dev/null
+++ b/Task/Associative-array-Iteration/Fantom/associative-array-iteration.fantom
@@ -0,0 +1,22 @@
+class Main
+{
+ public static Void main ()
+ {
+ Int:Str map := [1:"alpha", 2:"beta", 3:"gamma"]
+
+ map.keys.each |Int key|
+ {
+ echo ("Key is: $key")
+ }
+
+ map.vals.each |Str value|
+ {
+ echo ("Value is: $value")
+ }
+
+ map.each |Str value, Int key|
+ {
+ echo ("Key $key maps to $value")
+ }
+ }
+}
diff --git a/Task/Associative-array-Iteration/Groovy/associative-array-iteration.groovy b/Task/Associative-array-Iteration/Groovy/associative-array-iteration.groovy
new file mode 100644
index 0000000000..f03ef217d4
--- /dev/null
+++ b/Task/Associative-array-Iteration/Groovy/associative-array-iteration.groovy
@@ -0,0 +1,12 @@
+def map = [lastName: "Anderson", firstName: "Thomas", nickname: "Neo", age: 24, address: "everywhere"]
+
+println "Entries:"
+map.each { println it }
+
+println()
+println "Keys:"
+map.keySet().each { println it }
+
+println()
+println "Values:"
+map.values().each { println it }
diff --git a/Task/Associative-array-Iteration/Icon/associative-array-iteration.icon b/Task/Associative-array-Iteration/Icon/associative-array-iteration.icon
new file mode 100644
index 0000000000..aee359326b
--- /dev/null
+++ b/Task/Associative-array-Iteration/Icon/associative-array-iteration.icon
@@ -0,0 +1,15 @@
+procedure main()
+ t := table()
+ every t[a := !"ABCDE"] := map(a)
+
+ every pair := !sort(t) do
+ write("\t",pair[1]," -> ",pair[2])
+
+ writes("Keys:")
+ every writes(" ",key(t))
+ write()
+
+ writes("Values:")
+ every writes(" ",!t)
+ write()
+end
diff --git a/Task/Associative-array-Iteration/J/associative-array-iteration-1.j b/Task/Associative-array-Iteration/J/associative-array-iteration-1.j
new file mode 100644
index 0000000000..b26a093be4
--- /dev/null
+++ b/Task/Associative-array-Iteration/J/associative-array-iteration-1.j
@@ -0,0 +1 @@
+nl__example 0
diff --git a/Task/Associative-array-Iteration/J/associative-array-iteration-2.j b/Task/Associative-array-Iteration/J/associative-array-iteration-2.j
new file mode 100644
index 0000000000..bd621ffa82
--- /dev/null
+++ b/Task/Associative-array-Iteration/J/associative-array-iteration-2.j
@@ -0,0 +1 @@
+get__example each nl__example 0
diff --git a/Task/Associative-array-Iteration/J/associative-array-iteration-3.j b/Task/Associative-array-Iteration/J/associative-array-iteration-3.j
new file mode 100644
index 0000000000..cf26dc6d72
--- /dev/null
+++ b/Task/Associative-array-Iteration/J/associative-array-iteration-3.j
@@ -0,0 +1 @@
+(,&< get__example) each nl__example 0
diff --git a/Task/Associative-array-Iteration/K/associative-array-iteration-1.k b/Task/Associative-array-Iteration/K/associative-array-iteration-1.k
new file mode 100644
index 0000000000..a3c7501846
--- /dev/null
+++ b/Task/Associative-array-Iteration/K/associative-array-iteration-1.k
@@ -0,0 +1 @@
+ d: .((`"hello";1); (`"world";2);(`"!";3))
diff --git a/Task/Associative-array-Iteration/K/associative-array-iteration-2.k b/Task/Associative-array-Iteration/K/associative-array-iteration-2.k
new file mode 100644
index 0000000000..5ad9f2a40b
--- /dev/null
+++ b/Task/Associative-array-Iteration/K/associative-array-iteration-2.k
@@ -0,0 +1,7 @@
+ !d
+`hello `world `"!"
+
+ $!d / convert keys (symbols) as strings
+("hello"
+ "world"
+ ,"!")
diff --git a/Task/Associative-array-Iteration/K/associative-array-iteration-3.k b/Task/Associative-array-Iteration/K/associative-array-iteration-3.k
new file mode 100644
index 0000000000..5453975112
--- /dev/null
+++ b/Task/Associative-array-Iteration/K/associative-array-iteration-3.k
@@ -0,0 +1,4 @@
+ `0:{,/$x,": ",d[x]}'!d
+hello: 1
+world: 2
+!: 3
diff --git a/Task/Associative-array-Iteration/K/associative-array-iteration-4.k b/Task/Associative-array-Iteration/K/associative-array-iteration-4.k
new file mode 100644
index 0000000000..b70fa5fdf1
--- /dev/null
+++ b/Task/Associative-array-Iteration/K/associative-array-iteration-4.k
@@ -0,0 +1,5 @@
+ d[]
+1 2 3
+
+ {x+1}'d[]
+2 3 4
diff --git a/Task/Associative-array-Iteration/Lang5/associative-array-iteration.lang5 b/Task/Associative-array-Iteration/Lang5/associative-array-iteration.lang5
new file mode 100644
index 0000000000..6dffe5c7e6
--- /dev/null
+++ b/Task/Associative-array-Iteration/Lang5/associative-array-iteration.lang5
@@ -0,0 +1,4 @@
+: first 0 extract nip ; : second 1 extract nip ; : nip swap drop ;
+: say(*) dup first " => " 2 compress "" join . second . ;
+
+[['foo 5] ['bar 10] ['baz 20]] 'say apply drop
diff --git a/Task/Associative-array-Iteration/Liberty-BASIC/associative-array-iteration.liberty b/Task/Associative-array-Iteration/Liberty-BASIC/associative-array-iteration.liberty
new file mode 100644
index 0000000000..186e4f0ca9
--- /dev/null
+++ b/Task/Associative-array-Iteration/Liberty-BASIC/associative-array-iteration.liberty
@@ -0,0 +1,23 @@
+data "red", "255 50 50", "green", "50 255 50", "blue", "50 50 255"
+data "my fave", "220 120 120", "black", "0 0 0"
+
+myAssocList$ =""
+
+for i =1 to 5
+ read k$
+ read dat$
+ call sl.Set myAssocList$, k$, dat$
+next i
+
+keys$ = "" ' List to hold the keys in myList$.
+keys = 0
+
+keys = sl.Keys( myAssocList$, keys$)
+print " Number of key-data pairs ="; keys
+
+For i = 1 To keys
+ keyName$ = sl.Get$( keys$, Str$( i))
+ Print " Key "; i; ":", keyName$, "Data: ", sl.Get$( myAssocList$, keyName$)
+Next i
+
+end
diff --git a/Task/Associative-array-Iteration/M4/associative-array-iteration.m4 b/Task/Associative-array-Iteration/M4/associative-array-iteration.m4
new file mode 100644
index 0000000000..de54853879
--- /dev/null
+++ b/Task/Associative-array-Iteration/M4/associative-array-iteration.m4
@@ -0,0 +1,35 @@
+divert(-1)
+define(`for',
+ `ifelse($#,0,``$0'',
+ `ifelse(eval($2<=$3),1,
+ `pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')
+define(`new',`define(`$1[size]key',0)')
+define(`asize',`defn(`$1[size]key')')
+define(`aget',`defn(`$1[$2]')')
+define(`akget',`defn(`$1[$2]key')')
+define(`avget',`aget($1,akget($1,$2))')
+define(`aset',
+ `ifdef($1[$2],
+ `',
+ `define(`$1[size]key',incr(asize(`$1')))`'define($1[asize(`$1')]key,$2)')`'define($1[$2],$3)')
+define(`dquote', ``$@'')
+define(`akeyvalue',`dquote(akget($1,$2),aget($1,akget($1,$2)))')
+define(`akey',`dquote(akget($1,$2))')
+define(`avalue',`dquote(aget($1,akget($1,$2)))')
+divert
+new(`a')
+aset(`a',`wow',5)
+aset(`a',`wow',flame)
+aset(`a',`bow',7)
+key-value pairs
+for(`x',1,asize(`a'),
+ `akeyvalue(`a',x)
+')
+keys
+for(`x',1,asize(`a'),
+ `akey(`a',x)
+')
+values
+for(`x',1,asize(`a'),
+ `avalue(`a',x)
+')
diff --git a/Task/Associative-array-Iteration/Maple/associative-array-iteration.maple b/Task/Associative-array-Iteration/Maple/associative-array-iteration.maple
new file mode 100644
index 0000000000..9e035253a6
--- /dev/null
+++ b/Task/Associative-array-Iteration/Maple/associative-array-iteration.maple
@@ -0,0 +1,21 @@
+> T := table( [ "a" = 1, "b" = 2, ("c","d") = 3 ] ):
+> for i in indices( T ) do print( i, T[ op( i ) ] ) end:
+ ["a"], 1
+
+ ["c", "d"], 3
+
+ ["b"], 2
+
+> for i in indices( T ) do print( op( i ) ) end:
+ "a"
+
+ "c", "d"
+
+ "b"
+
+> for i in entries( T ) do print( i) end:
+ [1]
+
+ [3]
+
+ [2]
diff --git a/Task/Associative-array-Iteration/Mathematica/associative-array-iteration.mathematica b/Task/Associative-array-Iteration/Mathematica/associative-array-iteration.mathematica
new file mode 100644
index 0000000000..b7b02488df
--- /dev/null
+++ b/Task/Associative-array-Iteration/Mathematica/associative-array-iteration.mathematica
@@ -0,0 +1,8 @@
+keys=DownValues[#,Sort->False][[All,1,1,1]]&;
+hashes=#/@keys[#]&;
+
+a[2]="string";a["sometext"]=23;
+keys[a]
+->{2,sometext}
+hashes[a]
+->{string,23}
diff --git a/Task/Atomic-updates/Groovy/atomic-updates.groovy b/Task/Atomic-updates/Groovy/atomic-updates.groovy
new file mode 100644
index 0000000000..54c4701691
--- /dev/null
+++ b/Task/Atomic-updates/Groovy/atomic-updates.groovy
@@ -0,0 +1,79 @@
+class Buckets {
+
+ def cells = []
+ final n
+
+ Buckets(n, limit=1000, random=new Random()) {
+ this.n = n
+ (0..
+ synchronized(buckets) {
+ def targetDiff = (buckets[i]-buckets[j]).intdiv(2)
+ if (targetDiff < 0) {
+ buckets.transfer(j, i, -targetDiff)
+ } else {
+ buckets.transfer(i, j, targetDiff)
+ }
+ }
+}
+
+def randomize = { i, j ->
+ synchronized(buckets) {
+ def targetLimit = buckets[i] + buckets[j]
+ def targetI = random.nextInt(targetLimit + 1)
+ if (targetI < buckets[i]) {
+ buckets.transfer(i, j, buckets[i] - targetI)
+ } else {
+ buckets.transfer(j, i, targetI - buckets[i])
+ }
+ }
+}
+
+Thread.start {
+ def start = System.currentTimeMillis()
+ while (start + 10000 > System.currentTimeMillis()) {
+ def i = random.nextInt(buckets.n)
+ def j = random.nextInt(buckets.n)
+ makeCloser(i, j)
+ }
+}
+
+Thread.start {
+ def start = System.currentTimeMillis()
+ while (start + 10000 > System.currentTimeMillis()) {
+ def i = random.nextInt(buckets.n)
+ def j = random.nextInt(buckets.n)
+ randomize(i, j)
+ }
+}
+
+def start = System.currentTimeMillis()
+while (start + 10000 > System.currentTimeMillis()) {
+ synchronized(buckets) {
+ def sum = buckets.cells.sum()
+ println "${new Date()}: checksum: ${sum} buckets: ${buckets}"
+ }
+ Thread.sleep(500)
+}
diff --git a/Task/Average-loop-length/J/average-loop-length-1.j b/Task/Average-loop-length/J/average-loop-length-1.j
new file mode 100644
index 0000000000..b9c6260f74
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-1.j
@@ -0,0 +1,4 @@
+ (~.@, {&0 0@{:)^:_] 0
+0
+ (~.@, {&0 0@{:)^:_] 1
+1 0
diff --git a/Task/Average-loop-length/J/average-loop-length-2.j b/Task/Average-loop-length/J/average-loop-length-2.j
new file mode 100644
index 0000000000..49b3251ee1
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-2.j
@@ -0,0 +1,2 @@
+ 0 0 ([: # (] ~.@, {:@] { [)^:_) 1
+2
diff --git a/Task/Average-loop-length/J/average-loop-length-3.j b/Task/Average-loop-length/J/average-loop-length-3.j
new file mode 100644
index 0000000000..b06059a95b
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-3.j
@@ -0,0 +1,5 @@
+ (#.inv i.@^~)2
+0 0
+0 1
+1 0
+1 1
diff --git a/Task/Average-loop-length/J/average-loop-length-4.j b/Task/Average-loop-length/J/average-loop-length-4.j
new file mode 100644
index 0000000000..20fa310518
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-4.j
@@ -0,0 +1,12 @@
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)1
+1
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)2
+1.5
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)3
+1.88889
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)4
+2.21875
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)5
+2.5104
+ (+/ % #)@,@((#.inv i.@^~) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)6
+2.77469
diff --git a/Task/Average-loop-length/J/average-loop-length-5.j b/Task/Average-loop-length/J/average-loop-length-5.j
new file mode 100644
index 0000000000..72354f9914
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-5.j
@@ -0,0 +1,3 @@
+ ana=: +/@(!@[ % !@- * ^) 1+i.
+ ana"0]1 2 3 4 5 6
+1 1.5 1.88889 2.21875 2.5104 2.77469
diff --git a/Task/Average-loop-length/J/average-loop-length-6.j b/Task/Average-loop-length/J/average-loop-length-6.j
new file mode 100644
index 0000000000..d6d0b7b384
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-6.j
@@ -0,0 +1,3 @@
+ sim=: (+/ % #)@,@((]?@$~1e4,]) ([: # (] ~.@, {:@] { [)^:_)"1 0/ i.)
+ sim"0]1 2 3 4 5 6
+1 1.5034 1.8825 2.22447 2.51298 2.76898
diff --git a/Task/Average-loop-length/J/average-loop-length-7.j b/Task/Average-loop-length/J/average-loop-length-7.j
new file mode 100644
index 0000000000..2c81a8d2df
--- /dev/null
+++ b/Task/Average-loop-length/J/average-loop-length-7.j
@@ -0,0 +1,25 @@
+ (;:'N average analytic error'),:,.each(;ana"0 ([;];-|@%[) sim"0)1+i.20
++--+-------+--------+-----------+
+|N |average|analytic|error |
++--+-------+--------+-----------+
+| 1| 1| 1 | 0|
+| 2| 1.5|1.49955 | 0.0003|
+| 3|1.88889| 1.8928 | 0.00207059|
+| 4|2.21875|2.23082 | 0.00544225|
+| 5| 2.5104|2.52146 | 0.00440567|
+| 6|2.77469|2.78147 | 0.00244182|
+| 7|3.01814| 3.0101 | 0.00266346|
+| 8|3.24502|3.25931 | 0.00440506|
+| 9|3.45832|3.45314 | 0.00149532|
+|10|3.66022| 3.6708 | 0.00289172|
+|11|3.85237|3.84139 | 0.00285049|
+|12|4.03607|4.03252 |0.000881304|
+|13|4.21235|4.18358 | 0.00682833|
+|14|4.38203|4.38791 | 0.00134132|
+|15|4.54581|4.54443 |0.000302246|
+|16|4.70426|4.71351 | 0.00196721|
+|17|4.85787|4.85838 |0.000104089|
+|18|5.00706|5.00889 |0.000365752|
+|19| 5.1522|5.14785 |0.000843052|
+|20|5.29358|5.28587 | 0.00145829|
++--+-------+--------+-----------+
diff --git a/Task/Average-loop-length/Mathematica/average-loop-length.mathematica b/Task/Average-loop-length/Mathematica/average-loop-length.mathematica
new file mode 100644
index 0000000000..5aada18963
--- /dev/null
+++ b/Task/Average-loop-length/Mathematica/average-loop-length.mathematica
@@ -0,0 +1,9 @@
+Grid@Prepend[
+ Table[{n, #[[1]], #[[2]],
+ Row[{Round[10000 Abs[#[[1]] - #[[2]]]/#[[2]]]/100., "%"}]} &@
+ N[{Mean[Array[
+ Length@NestWhileList[#, 1, UnsameQ[##] &, All] - 1 &[# /.
+ MapIndexed[#2[[1]] -> #1 &,
+ RandomInteger[{1, n}, n]] &] &, 10000]],
+ Sum[n! n^(n - k - 1)/(n - k)!, {k, n}]/n^(n - 1)}, 5], {n, 1,
+ 20}], {"N", "average", "analytical", "error"}]
diff --git a/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-1.factor b/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-1.factor
new file mode 100644
index 0000000000..0287b01854
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-1.factor
@@ -0,0 +1,4 @@
+USING: math math.statistics ;
+
+: arithmetic-mean ( seq -- n )
+ [ 0 ] [ mean ] if-empty ;
diff --git a/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-2.factor b/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-2.factor
new file mode 100644
index 0000000000..2fa6a27324
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Factor/averages-arithmetic-mean-2.factor
@@ -0,0 +1,2 @@
+( scratchpad ) { 2 3 5 } arithmetic-mean >float
+3.333333333333333
diff --git a/Task/Averages-Arithmetic-mean/Fantom/averages-arithmetic-mean.fantom b/Task/Averages-Arithmetic-mean/Fantom/averages-arithmetic-mean.fantom
new file mode 100644
index 0000000000..01aa636498
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Fantom/averages-arithmetic-mean.fantom
@@ -0,0 +1,18 @@
+class Main
+{
+ static Float average (Float[] nums)
+ {
+ if (nums.size == 0) return 0.0f
+ Float sum := 0f
+ nums.each |num| { sum += num }
+ return sum / nums.size.toFloat
+ }
+
+ public static Void main ()
+ {
+ [[,], [1f], [1f,2f,3f,4f]].each |Float[] i|
+ {
+ echo ("Average of $i is: " + average(i))
+ }
+ }
+}
diff --git a/Task/Averages-Arithmetic-mean/Fish/averages-arithmetic-mean.fish b/Task/Averages-Arithmetic-mean/Fish/averages-arithmetic-mean.fish
new file mode 100644
index 0000000000..1b90fd7d66
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Fish/averages-arithmetic-mean.fish
@@ -0,0 +1,3 @@
+!vl0=?vl1=?vl&!
+v< +<>0n; >n;
+>l1)?^&,n;
diff --git a/Task/Averages-Arithmetic-mean/GAP/averages-arithmetic-mean.gap b/Task/Averages-Arithmetic-mean/GAP/averages-arithmetic-mean.gap
new file mode 100644
index 0000000000..3e419b56cd
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/GAP/averages-arithmetic-mean.gap
@@ -0,0 +1,12 @@
+Mean := function(v)
+ local n;
+ n := Length(v);
+ if n = 0 then
+ return 0;
+ else
+ return Sum(v)/n;
+ fi;
+end;
+
+Mean([3, 1, 4, 1, 5, 9]);
+# 23/6
diff --git a/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-1.groovy b/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-1.groovy
new file mode 100644
index 0000000000..260715106d
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-1.groovy
@@ -0,0 +1 @@
+def avg = { list -> list == [] ? 0 : list.sum() / list.size() }
diff --git a/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-2.groovy b/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-2.groovy
new file mode 100644
index 0000000000..c75883f8ed
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Groovy/averages-arithmetic-mean-2.groovy
@@ -0,0 +1,3 @@
+println avg(0..9)
+println avg([2,2,2,4,2])
+println avg ([])
diff --git a/Task/Averages-Arithmetic-mean/HicEst/averages-arithmetic-mean.hicest b/Task/Averages-Arithmetic-mean/HicEst/averages-arithmetic-mean.hicest
new file mode 100644
index 0000000000..c54768692a
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/HicEst/averages-arithmetic-mean.hicest
@@ -0,0 +1,5 @@
+REAL :: vec(100) ! no zero-length arrays in HicEst
+
+ vec = $ - 1/2 ! 0.5 ... 99.5
+ mean = SUM(vec) / LEN(vec) ! 50
+END
diff --git a/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-1.idl b/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-1.idl
new file mode 100644
index 0000000000..5ec124c9f6
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-1.idl
@@ -0,0 +1,2 @@
+x = [3,1,4,1,5,9]
+print,mean(x)
diff --git a/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-2.idl b/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-2.idl
new file mode 100644
index 0000000000..165a52130e
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/IDL/averages-arithmetic-mean-2.idl
@@ -0,0 +1,3 @@
+print,moment(x)
+; ==>
+ 3.83333 8.96667 0.580037 -1.25081
diff --git a/Task/Averages-Arithmetic-mean/Icon/averages-arithmetic-mean.icon b/Task/Averages-Arithmetic-mean/Icon/averages-arithmetic-mean.icon
new file mode 100644
index 0000000000..cb9b8421ba
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Icon/averages-arithmetic-mean.icon
@@ -0,0 +1,4 @@
+procedure main(args)
+ every (s := 0) +:= !args
+ write((real(s)/(0 ~= *args)) | 0)
+end
diff --git a/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-1.j b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-1.j
new file mode 100644
index 0000000000..306c387f9c
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-1.j
@@ -0,0 +1 @@
+mean=: +/ % #
diff --git a/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-2.j b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-2.j
new file mode 100644
index 0000000000..9511cb7e1b
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-2.j
@@ -0,0 +1,7 @@
+ mean 3 1 4 1 5 9
+3.83333
+ mean $0 NB. $0 is a zero-length vector
+0
+ x=: 20 4 ?@$ 0 NB. a 20-by-4 table of random (0,1) numbers
+ mean x
+0.58243 0.402948 0.477066 0.511155
diff --git a/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-3.j b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-3.j
new file mode 100644
index 0000000000..597a63f235
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/J/averages-arithmetic-mean-3.j
@@ -0,0 +1,11 @@
+mean1=: 3 : 0
+ z=. 0
+ for_i. i.#y do. z=. z+i{y end.
+ z % #y
+)
+ mean1 3 1 4 1 5 9
+3.83333
+ mean1 $0
+0
+ mean1 x
+0.58243 0.402948 0.477066 0.511155
diff --git a/Task/Averages-Arithmetic-mean/Julia/averages-arithmetic-mean.julia b/Task/Averages-Arithmetic-mean/Julia/averages-arithmetic-mean.julia
new file mode 100644
index 0000000000..8ff131b323
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Julia/averages-arithmetic-mean.julia
@@ -0,0 +1,5 @@
+julia> mean([1,2,3])
+2.0
+
+julia> mean([])
+ERROR: mean of empty collection undefined: []
diff --git a/Task/Averages-Arithmetic-mean/K/averages-arithmetic-mean.k b/Task/Averages-Arithmetic-mean/K/averages-arithmetic-mean.k
new file mode 100644
index 0000000000..de1aaf1ec9
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/K/averages-arithmetic-mean.k
@@ -0,0 +1,5 @@
+ mean: {(+/x)%#x}
+ mean 1 2 3 5 7
+3.6
+ mean@!0 / empty array
+0.0
diff --git a/Task/Averages-Arithmetic-mean/LSL/averages-arithmetic-mean.lsl b/Task/Averages-Arithmetic-mean/LSL/averages-arithmetic-mean.lsl
new file mode 100644
index 0000000000..1c048b656f
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LSL/averages-arithmetic-mean.lsl
@@ -0,0 +1,22 @@
+integer MAX_ELEMENTS = 10;
+integer MAX_VALUE = 100;
+default {
+ state_entry() {
+ list lst = [];
+ integer x = 0;
+ for(x=0 ; x$L(X,"^") SET S=S+$P(X,"^",I),I=I+1
+ QUIT (S/$L(X,"^"))
diff --git a/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-1.maple b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-1.maple
new file mode 100644
index 0000000000..67b0acc214
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-1.maple
@@ -0,0 +1,4 @@
+mean := proc( a :: indexable )
+ local i;
+ Normalizer( add( i, i in a ) / numelems( a ) )
+end proc:
diff --git a/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-2.maple b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-2.maple
new file mode 100644
index 0000000000..babb9bc8d0
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-2.maple
@@ -0,0 +1,21 @@
+> mean( { 1/2, 2/3, 3/4, 4/5, 5/6 } ); # set
+ 71
+ ---
+ 100
+
+> mean( [ a, 2, c, 2.3, e ] ); # list
+ 0.8600000000 + a/5 + c/5 + e/5
+
+> mean( Array( [ 1, sin( s ), 3, exp( I*t ), 5 ] ) ); # array
+ 9/5 + 1/5 sin(s) + 1/5 exp(t I)
+
+> mean( [ sin(s)^2, cos(s)^2 ] );
+ 2 2
+ 1/2 sin(s) + 1/2 cos(s)
+
+> Normalizer := simplify: # use a stronger normalizer than the default
+> mean( [ sin(s)^2, cos(s)^2 ] );
+ 1/2
+
+> mean([]); # empty argument causes an exception to be raised.
+Error, (in mean) numeric exception: division by zero
diff --git a/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-3.maple b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-3.maple
new file mode 100644
index 0000000000..5a85ec92f4
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-3.maple
@@ -0,0 +1 @@
+mean := () -> Normalizer( `+`( args ) / nargs ):
diff --git a/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-4.maple b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-4.maple
new file mode 100644
index 0000000000..ec9d29bf5b
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-4.maple
@@ -0,0 +1,10 @@
+> mean( 1, 2, 3, 4, 5 );
+ 3
+
+> mean( a + b, b + c, c + d, d + e, e + a );
+ 2 a 2 b 2 c 2 d 2 e
+ --- + --- + --- + --- + ---
+ 5 5 5 5 5
+
+> mean(); # again, an exception is raised
+Error, (in mean) numeric exception: division by zero
diff --git a/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-5.maple b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-5.maple
new file mode 100644
index 0000000000..bd195d12c2
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maple/averages-arithmetic-mean-5.maple
@@ -0,0 +1 @@
+mean := ( s :: seq(algebraic) ) -> Normalizer( `+`( args ) / nargs ):
diff --git a/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-1.mathematica b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-1.mathematica
new file mode 100644
index 0000000000..f6c81a5a84
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-1.mathematica
@@ -0,0 +1,2 @@
+Unprotect[Mean];
+Mean[{}] := 0
diff --git a/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-2.mathematica b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-2.mathematica
new file mode 100644
index 0000000000..4865f5ed52
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-2.mathematica
@@ -0,0 +1,6 @@
+Mean[{3,4,5}]
+Mean[{3.2,4.5,5.9}]
+Mean[{-4, 1.233}]
+Mean[{}]
+Mean[{1/2,1/3,1/4,1/5}]
+Mean[{a,c,Pi,-3,a}]
diff --git a/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-3.mathematica b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-3.mathematica
new file mode 100644
index 0000000000..db0a6114db
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Mathematica/averages-arithmetic-mean-3.mathematica
@@ -0,0 +1,6 @@
+4
+4.53333
+-1.3835
+0
+77/240
+1/5 (-3+2 a+c+Pi)
diff --git a/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-1.mathprog b/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-1.mathprog
new file mode 100644
index 0000000000..fd0787365f
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-1.mathprog
@@ -0,0 +1,24 @@
+/*Arithmetic Mean of a large number of Integers
+ - or - solve a very large constraint matrix
+ over 1 million rows and columns
+ Nigel_Galloway
+ March 18th., 2008.
+*/
+
+param e := 20;
+set Sample := {1..2**e-1};
+
+var Mean;
+var E{z in Sample};
+
+/* sum of variances is zero */
+zumVariance: sum{z in Sample} E[z] = 0;
+
+/* Mean + variance[n] = Sample[n] */
+variances{z in Sample}: Mean + E[z] = z;
+
+solve;
+
+printf "The arithmetic mean of the integers from 1 to %d is %f\n", 2**e-1, Mean;
+
+end;
diff --git a/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-2.mathprog b/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-2.mathprog
new file mode 100644
index 0000000000..290f280013
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Mathprog/averages-arithmetic-mean-2.mathprog
@@ -0,0 +1,22 @@
+GLPSOL: GLPK LP/MIP Solver, v4.47
+Parameter(s) specified in the command line:
+ --nopresol --math AM.mprog
+Reading model section from AM.mprog...
+24 lines were read
+Generating zumVariance...
+Generating variances...
+Model has been successfully generated
+Scaling...
+ A: min|aij| = 1.000e+000 max|aij| = 1.000e+000 ratio = 1.000e+000
+Problem data seem to be well scaled
+Constructing initial basis...
+Size of triangular part = 1048575
+GLPK Simplex Optimizer, v4.47
+1048576 rows, 1048576 columns, 3145725 non-zeros
+ 0: obj = 0.000000000e+000 infeas = 5.498e+011 (1)
+* 1: obj = 0.000000000e+000 infeas = 0.000e+000 (0)
+OPTIMAL SOLUTION FOUND
+Time used: 2.0 secs
+Memory used: 1393.8 Mb (1461484590 bytes)
+The arithmetic mean of the integers from 1 to 1048575 is 524288.000000
+Model has been successfully processed
diff --git a/Task/Averages-Arithmetic-mean/Maxima/averages-arithmetic-mean.maxima b/Task/Averages-Arithmetic-mean/Maxima/averages-arithmetic-mean.maxima
new file mode 100644
index 0000000000..3e54624546
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Maxima/averages-arithmetic-mean.maxima
@@ -0,0 +1 @@
+mean([2, 7, 11, 17]);
diff --git a/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-1.mod2 b/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-1.mod2
new file mode 100644
index 0000000000..71458f9848
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-1.mod2
@@ -0,0 +1,10 @@
+PROCEDURE Avg;
+
+VAR avg : REAL;
+
+BEGIN
+ avg := sx / n;
+ InOut.WriteString ("Average = ");
+ InOut.WriteReal (avg, 8, 2);
+ InOut.WriteLn
+END Avg;
diff --git a/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-2.mod2 b/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-2.mod2
new file mode 100644
index 0000000000..de34683407
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Modula-2/averages-arithmetic-mean-2.mod2
@@ -0,0 +1,14 @@
+PROCEDURE Average (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL;
+
+(* Calculate the average over 'Samples' values, stored in array 'Data'. *)
+
+VAR sum : REAL;
+ n : CARDINAL;
+
+BEGIN
+ sum := 0.0;
+ FOR n := 0 TO Samples - 1 DO
+ sum := sum + Data [n]
+ END;
+ RETURN sum / FLOAT(Samples)
+END Average;
diff --git a/Task/Averages-Mean-angle/J/averages-mean-angle-1.j b/Task/Averages-Mean-angle/J/averages-mean-angle-1.j
new file mode 100644
index 0000000000..00f37b5218
--- /dev/null
+++ b/Task/Averages-Mean-angle/J/averages-mean-angle-1.j
@@ -0,0 +1 @@
+avgAngleD=: (_1 { [: (**|)&.+.@(+/ % #)&.(*.inv) 1,.])&.(1r180p1&*)
diff --git a/Task/Averages-Mean-angle/J/averages-mean-angle-2.j b/Task/Averages-Mean-angle/J/averages-mean-angle-2.j
new file mode 100644
index 0000000000..7d2fd083f5
--- /dev/null
+++ b/Task/Averages-Mean-angle/J/averages-mean-angle-2.j
@@ -0,0 +1,6 @@
+rfd=: 1r180p1&* NB. convert angle to radians from degrees
+toComplex=: *.inv NB. maps integer pairs as length, complex angle (in radians)
+mean=: +/ % # NB. calculate arithmetic mean
+roundComplex=: (* * |)&.+. NB. discard an extraneous least significant bit of precision from a complex value whose magnitude is in the vicinity of 1
+avgAngleR=: _1 { [: roundComplex@mean&.toComplex 1 ,. ] NB. calculate average angle in radians
+avgAngleD=: avgAngleR&.rfd
diff --git a/Task/Averages-Mean-angle/J/averages-mean-angle-3.j b/Task/Averages-Mean-angle/J/averages-mean-angle-3.j
new file mode 100644
index 0000000000..885df3edfe
--- /dev/null
+++ b/Task/Averages-Mean-angle/J/averages-mean-angle-3.j
@@ -0,0 +1,6 @@
+ avgAngleD 10 350
+0
+ avgAngleD 90 180 270 360 NB. result not meaningful
+0
+ avgAngleD 10 20 30
+20
diff --git a/Task/Averages-Mean-angle/Liberty-BASIC/averages-mean-angle.liberty b/Task/Averages-Mean-angle/Liberty-BASIC/averages-mean-angle.liberty
new file mode 100644
index 0000000000..e2ff4d591a
--- /dev/null
+++ b/Task/Averages-Mean-angle/Liberty-BASIC/averages-mean-angle.liberty
@@ -0,0 +1,42 @@
+global Pi
+Pi =3.1415926535
+
+print "Mean Angle( "; chr$( 34); "350,10"; chr$( 34); ") = "; using( "###.#", meanAngle( "350,10")); " degrees." ' 0
+print "Mean Angle( "; chr$( 34); "90,180,270,360"; chr$( 34); ") = "; using( "###.#", meanAngle( "90,180,270,360")); " degrees." ' -90
+print "Mean Angle( "; chr$( 34); "10,20,30"; chr$( 34); ") = "; using( "###.#", meanAngle( "10,20,30")); " degrees." ' 20
+
+end
+
+function meanAngle( angles$)
+ term =1
+ while word$( angles$, term, ",") <>""
+ angle =val( word$( angles$, term, ","))
+ sumSin = sumSin +sin( degRad( angle))
+ sumCos = sumCos +cos( degRad( angle))
+ term =term +1
+ wend
+ meanAngle= radDeg( atan2( sumSin, sumCos))
+ if abs( sumSin) +abs( sumCos) <0.001 then notice "Not Available." +_
+ chr$( 13) +"(" +angles$ +")" +_
+ chr$( 13) +"Result nearly equals zero vector." +_
+ chr$( 13) +"Displaying '666'.": meanAngle =666
+
+end function
+
+function degRad( theta)
+ degRad =theta *Pi /180
+end function
+
+function radDeg( theta)
+ radDeg =theta *180 /Pi
+end function
+
+function atan2( y, x)
+ if x >0 then at =atn( y /x)
+ if y >=0 and x <0 then at =atn( y /x) +pi
+ if y <0 and x <0 then at =atn( y /x) -pi
+ if y >0 and x =0 then at = pi /2
+ if y <0 and x =0 then at = 0 -pi /2
+ if y =0 and x =0 then notice "undefined": end
+ atan2 =at
+end function
diff --git a/Task/Averages-Mean-angle/Maple/averages-mean-angle-1.maple b/Task/Averages-Mean-angle/Maple/averages-mean-angle-1.maple
new file mode 100644
index 0000000000..9a05c5cab1
--- /dev/null
+++ b/Task/Averages-Mean-angle/Maple/averages-mean-angle-1.maple
@@ -0,0 +1,2 @@
+> [ 350, 10 ] *~ Unit(arcdeg);
+ [350 [arcdeg], 10 [arcdeg]]
diff --git a/Task/Averages-Mean-angle/Maple/averages-mean-angle-2.maple b/Task/Averages-Mean-angle/Maple/averages-mean-angle-2.maple
new file mode 100644
index 0000000000..9716729cf3
--- /dev/null
+++ b/Task/Averages-Mean-angle/Maple/averages-mean-angle-2.maple
@@ -0,0 +1,5 @@
+MeanAngle := proc( L )
+ uses Units:-Standard; # for unit-awareness
+ local u;
+ evalf( convert( argument( add( u, u = exp~( I *~ L ) ) ), 'units', 'radian', 'degree' ) )
+end proc:
diff --git a/Task/Averages-Mean-angle/Maple/averages-mean-angle-3.maple b/Task/Averages-Mean-angle/Maple/averages-mean-angle-3.maple
new file mode 100644
index 0000000000..a794c4f804
--- /dev/null
+++ b/Task/Averages-Mean-angle/Maple/averages-mean-angle-3.maple
@@ -0,0 +1,8 @@
+> MeanAngle( [ 350, 10 ] *~ Unit(arcdeg) );
+ 0.
+
+> MeanAngle( [ 90, 180, 270, 360 ] *~ Unit(arcdeg) );
+ 0.
+
+> MeanAngle( [ 10, 20, 30 ] *~ Unit(arcdeg) );
+ 20.00000000
diff --git a/Task/Averages-Mean-angle/Mathematica/averages-mean-angle.mathematica b/Task/Averages-Mean-angle/Mathematica/averages-mean-angle.mathematica
new file mode 100644
index 0000000000..9092bcf811
--- /dev/null
+++ b/Task/Averages-Mean-angle/Mathematica/averages-mean-angle.mathematica
@@ -0,0 +1 @@
+meanAngle[data_List] := N@Arg[Mean[Exp[I data Degree]]]/Degree
diff --git a/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-1.j b/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-1.j
new file mode 100644
index 0000000000..b1a2252a09
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-1.j
@@ -0,0 +1,5 @@
+require 'types/datetime'
+parseTimes=: ([: _&".;._2 ,&':');._2
+secsFromTime=: 24 60 60 #. ] NB. convert from time to seconds
+rft=: 2r86400p1 * secsFromTime NB. convert from time to radians
+meanTime=: 'hh:mm:ss' fmtTime [: secsFromTime [: avgAngleR&.rft parseTimes
diff --git a/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-2.j b/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-2.j
new file mode 100644
index 0000000000..128331b151
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/J/averages-mean-time-of-day-2.j
@@ -0,0 +1,2 @@
+ meanTime '23:00:17 23:40:20 00:12:45 00:17:19 '
+23:47:43
diff --git a/Task/Averages-Mean-time-of-day/Mathematica/averages-mean-time-of-day.mathematica b/Task/Averages-Mean-time-of-day/Mathematica/averages-mean-time-of-day.mathematica
new file mode 100644
index 0000000000..e2c129ca31
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/Mathematica/averages-mean-time-of-day.mathematica
@@ -0,0 +1,8 @@
+meanTime[list_] :=
+ StringJoin@
+ Riffle[ToString /@
+ Floor@{Mod[24 #, 24], Mod[24*60 #, 60], Mod[24*60*60 #, 60]} &[
+ Arg[Mean[
+ Exp[FromDigits[ToExpression@StringSplit[#, ":"], 60] & /@
+ list/(24*60*60) 2 Pi I]]]/(2 Pi)], ":"];
+meanTime[{"23:00:17", "23:40:20", "00:12:45", "00:17:19"}]
diff --git a/Task/Averages-Median/Factor/averages-median-1.factor b/Task/Averages-Median/Factor/averages-median-1.factor
new file mode 100644
index 0000000000..5113bd9971
--- /dev/null
+++ b/Task/Averages-Median/Factor/averages-median-1.factor
@@ -0,0 +1,27 @@
+USING: arrays kernel locals math math.functions random sequences ;
+IN: median
+
+: pivot ( seq -- pivot ) random ;
+
+: split ( seq pivot -- {lt,eq,gt} )
+ [ [ < ] curry partition ] keep
+ [ = ] curry partition
+ 3array ;
+
+DEFER: nth-in-order
+:: nth-in-order-recur ( seq ind -- elt )
+ seq dup pivot split
+ dup [ length ] map 0 [ + ] accumulate nip
+ dup [ ind <= [ 1 ] [ 0 ] if ] map sum 1 -
+ [ swap nth ] curry bi@
+ ind swap -
+ nth-in-order ;
+
+: nth-in-order ( seq ind -- elt )
+ dup 0 =
+ [ drop first ]
+ [ nth-in-order-recur ]
+ if ;
+
+: median ( seq -- median )
+ dup length 1 - 2 / floor nth-in-order ;
diff --git a/Task/Averages-Median/Factor/averages-median-2.factor b/Task/Averages-Median/Factor/averages-median-2.factor
new file mode 100644
index 0000000000..1ec9951602
--- /dev/null
+++ b/Task/Averages-Median/Factor/averages-median-2.factor
@@ -0,0 +1,4 @@
+( scratchpad ) 11 iota median .
+5
+( scratchpad ) 10 iota median .
+4
diff --git a/Task/Averages-Median/GAP/averages-median.gap b/Task/Averages-Median/GAP/averages-median.gap
new file mode 100644
index 0000000000..b4afcb0bad
--- /dev/null
+++ b/Task/Averages-Median/GAP/averages-median.gap
@@ -0,0 +1,14 @@
+Median := function(v)
+ local n, w;
+ w := SortedList(v);
+ n := Length(v);
+ return (w[QuoInt(n + 1, 2)] + w[QuoInt(n, 2) + 1]) / 2;
+end;
+
+a := [41, 56, 72, 17, 93, 44, 32];
+b := [41, 72, 17, 93, 44, 32];
+
+Median(a);
+# 44
+Median(b);
+# 85/2
diff --git a/Task/Averages-Median/Groovy/averages-median-1.groovy b/Task/Averages-Median/Groovy/averages-median-1.groovy
new file mode 100644
index 0000000000..2bc8acd0ab
--- /dev/null
+++ b/Task/Averages-Median/Groovy/averages-median-1.groovy
@@ -0,0 +1,9 @@
+def median(Iterable col) {
+ def s = col as SortedSet
+ if (s == null) return null
+ if (s.empty) return 0
+ def n = s.size()
+ def m = n.intdiv(2)
+ def l = s.collect { it }
+ n%2 == 1 ? l[m] : (l[m] + l[m-1])/2
+}
diff --git a/Task/Averages-Median/Groovy/averages-median-2.groovy b/Task/Averages-Median/Groovy/averages-median-2.groovy
new file mode 100644
index 0000000000..79cb8b7197
--- /dev/null
+++ b/Task/Averages-Median/Groovy/averages-median-2.groovy
@@ -0,0 +1,7 @@
+def a = [4.4, 2.3, -1.7, 7.5, 6.6, 0.0, 1.9, 8.2, 9.3, 4.5]
+def sz = a.size()
+
+(0..sz).each {
+ println """${median(a[0..<(sz-it)])} == median(${a[0..<(sz-it)]})
+${median(a[it...)@midpt { /:~)
diff --git a/Task/Averages-Median/J/averages-median-3.j b/Task/Averages-Median/J/averages-median-3.j
new file mode 100644
index 0000000000..15dc1d4bd0
--- /dev/null
+++ b/Task/Averages-Median/J/averages-median-3.j
@@ -0,0 +1,3 @@
+ median=: ~.@(<. , >.)@midpt { /:~
+ median 1 9 2 4
+2 4
diff --git a/Task/Averages-Median/Julia/averages-median.julia b/Task/Averages-Median/Julia/averages-median.julia
new file mode 100644
index 0000000000..407dbf74ec
--- /dev/null
+++ b/Task/Averages-Median/Julia/averages-median.julia
@@ -0,0 +1,4 @@
+ julia> values = [1:10]
+ [1,2,3,4,5,6,7,8,9,10]
+ julia> median(values)
+ 5.5
diff --git a/Task/Averages-Median/LSL/averages-median.lsl b/Task/Averages-Median/LSL/averages-median.lsl
new file mode 100644
index 0000000000..1c048b656f
--- /dev/null
+++ b/Task/Averages-Median/LSL/averages-median.lsl
@@ -0,0 +1,22 @@
+integer MAX_ELEMENTS = 10;
+integer MAX_VALUE = 100;
+default {
+ state_entry() {
+ list lst = [];
+ integer x = 0;
+ for(x=0 ; xintmiddle then median= a( 1 +intmiddle) else median =( a( intmiddle) +a( intmiddle +1)) /2
+ end function
diff --git a/Task/Averages-Median/MUMPS/averages-median.mumps b/Task/Averages-Median/MUMPS/averages-median.mumps
new file mode 100644
index 0000000000..2a5177b05c
--- /dev/null
+++ b/Task/Averages-Median/MUMPS/averages-median.mumps
@@ -0,0 +1,14 @@
+MEDIAN(X)
+ ;X is assumed to be a list of numbers separated by "^"
+ ;I is a loop index
+ ;L is the length of X
+ ;Y is a new array
+ QUIT:'$DATA(X) "No data"
+ QUIT:X="" "Empty Set"
+ NEW I,ODD,L,Y
+ SET L=$LENGTH(X,"^"),ODD=L#2,I=1
+ ;The values in the vector are used as indices for a new array Y, which sorts them
+ FOR QUIT:I>L SET Y($PIECE(X,"^",I))=1,I=I+1
+ ;Go to the median index, or the lesser of the middle if there is an even number of elements
+ SET J="" FOR I=1:1:$SELECT(ODD:L\2+1,'ODD:L/2) SET J=$ORDER(Y(J))
+ QUIT $SELECT(ODD:J,'ODD:(J+$ORDER(Y(J)))/2)
diff --git a/Task/Averages-Median/Maple/averages-median-1.maple b/Task/Averages-Median/Maple/averages-median-1.maple
new file mode 100644
index 0000000000..d16efdbddf
--- /dev/null
+++ b/Task/Averages-Median/Maple/averages-median-1.maple
@@ -0,0 +1,5 @@
+> Statistics:-Median( [ 1, 5, 3, 2, 4 ] );
+ 3.
+
+> Statistics:-Median( [ 1, 5, 3, 6, 2, 4 ] );
+ 3.50000000000000
diff --git a/Task/Averages-Median/Maple/averages-median-2.maple b/Task/Averages-Median/Maple/averages-median-2.maple
new file mode 100644
index 0000000000..f6a03260ca
--- /dev/null
+++ b/Task/Averages-Median/Maple/averages-median-2.maple
@@ -0,0 +1,4 @@
+median1 := proc()
+ local L := sort( [ args ] );
+ ( L[ iquo( 1 + nargs, 2 ) ] + L[ 1 + iquo( nargs, 2 ) ] ) / 2
+end proc:
diff --git a/Task/Averages-Median/Maple/averages-median-3.maple b/Task/Averages-Median/Maple/averages-median-3.maple
new file mode 100644
index 0000000000..7897ac995e
--- /dev/null
+++ b/Task/Averages-Median/Maple/averages-median-3.maple
@@ -0,0 +1,5 @@
+> median1( 1, 5, 3, 2, 4 ); # 3
+ 3
+
+> median1( 1, 5, 3, 6, 4, 2 ); # 7/2
+ 7/2
diff --git a/Task/Averages-Median/Mathematica/averages-median-1.mathematica b/Task/Averages-Median/Mathematica/averages-median-1.mathematica
new file mode 100644
index 0000000000..b715fb8878
--- /dev/null
+++ b/Task/Averages-Median/Mathematica/averages-median-1.mathematica
@@ -0,0 +1,2 @@
+Median[{1, 5, 3, 2, 4}]
+Median[{1, 5, 3, 6, 4, 2}]
diff --git a/Task/Averages-Median/Mathematica/averages-median-2.mathematica b/Task/Averages-Median/Mathematica/averages-median-2.mathematica
new file mode 100644
index 0000000000..5cb0fa1dd6
--- /dev/null
+++ b/Task/Averages-Median/Mathematica/averages-median-2.mathematica
@@ -0,0 +1,7 @@
+mymedian[x_List]:=Module[{t=Sort[x],L=Length[x]},
+ If[Mod[L,2]==0,
+ (t[[L/2]]+t[[L/2+1]])/2
+ ,
+ t[[(L+1)/2]]
+ ]
+]
diff --git a/Task/Averages-Median/Mathematica/averages-median-3.mathematica b/Task/Averages-Median/Mathematica/averages-median-3.mathematica
new file mode 100644
index 0000000000..a47b57290b
--- /dev/null
+++ b/Task/Averages-Median/Mathematica/averages-median-3.mathematica
@@ -0,0 +1,2 @@
+mymedian[{1, 5, 3, 2, 4}]
+mymedian[{1, 5, 3, 6, 4, 2}]
diff --git a/Task/Averages-Median/Maxima/averages-median.maxima b/Task/Averages-Median/Maxima/averages-median.maxima
new file mode 100644
index 0000000000..f01c9cb51f
--- /dev/null
+++ b/Task/Averages-Median/Maxima/averages-median.maxima
@@ -0,0 +1,3 @@
+/* built-in */
+median([41, 56, 72, 17, 93, 44, 32]); /* 44 */
+median([41, 72, 17, 93, 44, 32]); /* 85/2 */
diff --git a/Task/Averages-Mode/Factor/averages-mode.factor b/Task/Averages-Mode/Factor/averages-mode.factor
new file mode 100644
index 0000000000..6f3109dcd3
--- /dev/null
+++ b/Task/Averages-Mode/Factor/averages-mode.factor
@@ -0,0 +1 @@
+{ 11 9 4 9 4 9 } mode ! 9
diff --git a/Task/Averages-Mode/GAP/averages-mode.gap b/Task/Averages-Mode/GAP/averages-mode.gap
new file mode 100644
index 0000000000..14397cc90e
--- /dev/null
+++ b/Task/Averages-Mode/GAP/averages-mode.gap
@@ -0,0 +1,9 @@
+mode := function(v)
+ local c, m;
+ c := Collected(SortedList(v));
+ m := Maximum(List(c, x -> x[2]));
+ return List(Filtered(c, x -> x[2] = m), y -> y[1]);
+end;
+
+mode([ 7, 5, 6, 1, 5, 5, 7, 12, 17, 6, 6, 5, 12, 3, 6 ]);
+# [ 5, 6 ]
diff --git a/Task/Averages-Mode/Groovy/averages-mode-1.groovy b/Task/Averages-Mode/Groovy/averages-mode-1.groovy
new file mode 100644
index 0000000000..e7a8618daa
--- /dev/null
+++ b/Task/Averages-Mode/Groovy/averages-mode-1.groovy
@@ -0,0 +1,9 @@
+def mode(Iterable col) {
+ assert col
+ def m = [:]
+ col.each {
+ m[it] = m[it] == null ? 1 : m[it] + 1
+ }
+ def keys = m.keySet().sort { -m[it] }
+ keys.findAll { m[it] == m[keys[0]] }
+}
diff --git a/Task/Averages-Mode/Groovy/averages-mode-2.groovy b/Task/Averages-Mode/Groovy/averages-mode-2.groovy
new file mode 100644
index 0000000000..a2628ca797
--- /dev/null
+++ b/Task/Averages-Mode/Groovy/averages-mode-2.groovy
@@ -0,0 +1,6 @@
+def random = new Random()
+def sourceList = [ 'Lamp', 42.0, java.awt.Color.RED, new Date(), ~/pattern/]
+(0..10).each {
+ def a = (0..10).collect { sourceList[random.nextInt(5)] }
+ println "${mode(a)} == mode(${a})"
+}
diff --git a/Task/Averages-Mode/Icon/averages-mode.icon b/Task/Averages-Mode/Icon/averages-mode.icon
new file mode 100644
index 0000000000..3d0f91a583
--- /dev/null
+++ b/Task/Averages-Mode/Icon/averages-mode.icon
@@ -0,0 +1,14 @@
+procedure main(args)
+ every write(!mode(args))
+end
+
+procedure mode(A)
+ hist := table(0)
+ every hist[!A] +:= 1
+ hist := sort(hist, 2)
+ modeCnt := hist[*hist][2]
+ every modeP := hist[*hist to 1 by -1] do {
+ if modeCnt = modeP[2] then suspend modeP[1]
+ else fail
+ }
+end
diff --git a/Task/Averages-Mode/J/averages-mode.j b/Task/Averages-Mode/J/averages-mode.j
new file mode 100644
index 0000000000..059ecec48f
--- /dev/null
+++ b/Task/Averages-Mode/J/averages-mode.j
@@ -0,0 +1 @@
+mode=: ~. #~ ( = >./ )@( #/.~ )
diff --git a/Task/Averages-Mode/K/averages-mode.k b/Task/Averages-Mode/K/averages-mode.k
new file mode 100644
index 0000000000..44ce50c413
--- /dev/null
+++ b/Task/Averages-Mode/K/averages-mode.k
@@ -0,0 +1,3 @@
+ mode: {(?x)@&n=|/n:#:'=x}
+ mode 1 1 1 1 2 2 2 3 3 3 3 4 4 3 2 4 4 4
+3 4
diff --git a/Task/Averages-Mode/MUMPS/averages-mode.mumps b/Task/Averages-Mode/MUMPS/averages-mode.mumps
new file mode 100644
index 0000000000..93394a8d5f
--- /dev/null
+++ b/Task/Averages-Mode/MUMPS/averages-mode.mumps
@@ -0,0 +1,15 @@
+MODE(X)
+ ;X is assumed to be a list of numbers separated by "^"
+ ;I is a loop index
+ ;L is the length of X
+ ;Y is a new array
+ ;ML is the list of modes
+ ;LOC is a placeholder to shorten the statement
+ Q:'$DATA(X) "No data"
+ Q:X="" "Empty Set"
+ NEW Y,I,L,LOC
+ SET L=$LENGTH(X,"^"),ML=""
+ FOR I=1:1:L SET LOC=+$P(X,"^",I),Y(LOC)=$S($DATA(Y(LOC)):Y(LOC)+1,1:1)
+ SET I="",I=$O(Y(I)),ML=I ;Prime the pump, rather than test for no data
+ FOR S I=$O(Y(I)) Q:I="" S ML=$SELECT(Y($P(ML,"^"))>Y(I):ML,Y($P(ML,"^"))= geometricMean (items)) &&
+ (geometricMean (items) >= harmonicMean (items)))
+ echo ("relation holds")
+ else
+ echo ("relation failed")
+ }
+}
diff --git a/Task/Averages-Pythagorean-means/GAP/averages-pythagorean-means.gap b/Task/Averages-Pythagorean-means/GAP/averages-pythagorean-means.gap
new file mode 100644
index 0000000000..baaa5d87a8
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/GAP/averages-pythagorean-means.gap
@@ -0,0 +1,18 @@
+# The first two work with rationals or with floats
+# (but bear in mind that support of floating point is very poor in GAP)
+mean := v -> Sum(v) / Length(v);
+harmean := v -> Length(v) / Sum(v, Inverse);
+geomean := v -> EXP_FLOAT(Sum(v, LOG_FLOAT) / Length(v));
+
+mean([1 .. 10]);
+# 11/2
+harmean([1 .. 10]);
+# 25200/7381
+
+v := List([1..10], FLOAT_INT);;
+mean(v);
+# 5.5
+harmean(v);
+# 3.41417
+geomean(v);
+# 4.52873
diff --git a/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-1.groovy b/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-1.groovy
new file mode 100644
index 0000000000..305b61c7ab
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-1.groovy
@@ -0,0 +1,23 @@
+def arithMean = { list ->
+ list == null \
+ ? null \
+ : list.empty \
+ ? 0 \
+ : list.sum() / list.size()
+}
+
+def geomMean = { list ->
+ list == null \
+ ? null \
+ : list.empty \
+ ? 1 \
+ : list.inject(1) { prod, item -> prod*item } ** (1 / list.size())
+}
+
+def harmMean = { list ->
+ list == null \
+ ? null \
+ : list.empty \
+ ? 0 \
+ : list.size() / list.collect { 1.0/it }.sum()
+}
diff --git a/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-2.groovy b/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-2.groovy
new file mode 100644
index 0000000000..42997701a8
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Groovy/averages-pythagorean-means-2.groovy
@@ -0,0 +1,12 @@
+def list = 1..10
+def A = arithMean(list)
+def G = geomMean(list)
+assert A >= G
+def H = harmMean(list)
+assert G >= H
+println """
+list: ${list}
+ A: ${A}
+ G: ${G}
+ H: ${H}
+"""
diff --git a/Task/Averages-Pythagorean-means/HicEst/averages-pythagorean-means.hicest b/Task/Averages-Pythagorean-means/HicEst/averages-pythagorean-means.hicest
new file mode 100644
index 0000000000..81cb6f20a1
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/HicEst/averages-pythagorean-means.hicest
@@ -0,0 +1,10 @@
+AGH = ALIAS( A, G, H ) ! named vector elements
+AGH = (0, 1, 0)
+DO i = 1, 10
+ A = A + i
+ G = G * i
+ H = H + 1/i
+ENDDO
+AGH = (A/10, G^0.1, 10/H)
+
+WRITE(ClipBoard, Name) AGH, "Result = " // (A>=G) * (G>=H)
diff --git a/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-1.icon b/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-1.icon
new file mode 100644
index 0000000000..9ac231b655
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-1.icon
@@ -0,0 +1,11 @@
+link numbers # for a/g/h means
+
+procedure main()
+every put(x := [], 1 to 10)
+writes("x := [ "); every writes(!x," "); write("]")
+
+write("Arithmetic mean:", a := amean!x)
+write("Geometric mean:",g := gmean!x)
+write("Harmonic mean:", h := hmean!x)
+write(" a >= g >= h is ", if a >= g >= h then "true" else "false")
+end
diff --git a/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-2.icon b/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-2.icon
new file mode 100644
index 0000000000..e9f48cf569
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Icon/averages-pythagorean-means-2.icon
@@ -0,0 +1,30 @@
+procedure amean(L[]) #: arithmetic mean
+ local m
+ if *L = 0 then fail
+ m := 0.0
+ every m +:= !L
+ return m / *L
+end
+
+procedure gmean(L[]) #: geometric mean
+ local m
+ if *L = 0 then fail
+ m := 1.0
+ every m *:= !L
+ m := abs(m)
+ if m > 0.0 then
+ return exp (log(m) / *L)
+ else
+ fail
+end
+
+procedure hmean(L[]) #: harmonic mean
+ local m, r
+ if *L = 0 then fail
+ m := 0.0
+ every r := !L do {
+ if r = 0.0 then fail
+ else m +:= 1.0 / r
+ }
+ return *L / m
+end
diff --git a/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-1.j b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-1.j
new file mode 100644
index 0000000000..992439a006
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-1.j
@@ -0,0 +1,3 @@
+amean=: +/ % #
+gmean=: # %: */
+hmean=: amean&.:%
diff --git a/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-2.j b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-2.j
new file mode 100644
index 0000000000..08b14ddf25
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-2.j
@@ -0,0 +1,3 @@
+ (amean , gmean , hmean) >: i. 10
+5.5 4.528729 3.414172
+ assert 2 >:/\ (amean , gmean , hmean) >: i. 10 NB. check amean >= gmean and gmean >= hmean
diff --git a/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-3.j b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-3.j
new file mode 100644
index 0000000000..47e710c21d
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/J/averages-pythagorean-means-3.j
@@ -0,0 +1 @@
+gmean=:amean&.:^.
diff --git a/Task/Averages-Pythagorean-means/Liberty-BASIC/averages-pythagorean-means.liberty b/Task/Averages-Pythagorean-means/Liberty-BASIC/averages-pythagorean-means.liberty
new file mode 100644
index 0000000000..4dc7a78913
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Liberty-BASIC/averages-pythagorean-means.liberty
@@ -0,0 +1,25 @@
+for i = 1 to 10
+ a = a + i
+next
+ArithmeticMean = a/10
+
+b = 1
+for i = 1 to 10
+ b = b * i
+next
+GeometricMean = b ^ (1/10)
+
+for i = 1 to 10
+ c = c + (1/i)
+next
+HarmonicMean = 10/c
+
+print "ArithmeticMean: ";ArithmeticMean
+print "Geometric Mean: ";GeometricMean
+print "Harmonic Mean: ";HarmonicMean
+
+if (ArithmeticMean>=GeometricMean) and (GeometricMean>=HarmonicMean) then
+print "True"
+else
+print "False"
+end if
diff --git a/Task/Averages-Pythagorean-means/Logo/averages-pythagorean-means.logo b/Task/Averages-Pythagorean-means/Logo/averages-pythagorean-means.logo
new file mode 100644
index 0000000000..a4620b4fd6
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Logo/averages-pythagorean-means.logo
@@ -0,0 +1,23 @@
+to compute_means :count
+ local "sum
+ make "sum 0
+ local "product
+ make "product 1
+ local "reciprocal_sum
+ make "reciprocal_sum 0
+
+ repeat :count [
+ make "sum sum :sum repcount
+ make "product product :product repcount
+ make "reciprocal_sum sum :reciprocal_sum (quotient repcount)
+ ]
+
+ output (sentence (quotient :sum :count) (power :product (quotient :count))
+ (quotient :count :reciprocal_sum))
+end
+
+make "means compute_means 10
+print sentence [Arithmetic mean is] item 1 :means
+print sentence [Geometric mean is] item 2 :means
+print sentence [Harmonic mean is] item 3 :means
+bye
diff --git a/Task/Averages-Pythagorean-means/MUMPS/averages-pythagorean-means.mumps b/Task/Averages-Pythagorean-means/MUMPS/averages-pythagorean-means.mumps
new file mode 100644
index 0000000000..bb4b7fbb9c
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/MUMPS/averages-pythagorean-means.mumps
@@ -0,0 +1,22 @@
+Pyth(n) New a,ii,g,h,x
+ For ii=1:1:n set x(ii)=ii
+ ;
+ ; Average
+ Set a=0 For ii=1:1:n Set a=a+x(ii)
+ Set a=a/n
+ ;
+ ; Geometric
+ Set g=1 For ii=1:1:n Set g=g*x(ii)
+ Set g=g**(1/n)
+ ;
+ ; Harmonic
+ Set h=0 For ii=1:1:n Set h=1/x(ii)+h
+ Set h=n/h
+ ;
+ Write !,"Pythagorean means for 1..",n,":",!
+ Write "Average = ",a," >= Geometric ",g," >= harmonic ",h,!
+ Quit
+Do Pyth(10)
+
+Pythagorean means for 1..10:
+Average = 5.5 >= Geometric 4.528728688116178495 >= harmonic 3.414171521474055006
diff --git a/Task/Averages-Pythagorean-means/Mathematica/averages-pythagorean-means.mathematica b/Task/Averages-Pythagorean-means/Mathematica/averages-pythagorean-means.mathematica
new file mode 100644
index 0000000000..a504967f59
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Mathematica/averages-pythagorean-means.mathematica
@@ -0,0 +1,2 @@
+Print["{Arithmetic Mean, Geometric Mean, Harmonic Mean} = ",
+ N@Through[{Mean, GeometricMean, HarmonicMean}[Range@10]]]
diff --git a/Task/Averages-Pythagorean-means/Maxima/averages-pythagorean-means.maxima b/Task/Averages-Pythagorean-means/Maxima/averages-pythagorean-means.maxima
new file mode 100644
index 0000000000..475a3797fc
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Maxima/averages-pythagorean-means.maxima
@@ -0,0 +1,6 @@
+/* built-in */
+L: makelist(i, i, 1, 10)$
+
+mean(L), numer; /* 5.5 */
+geometric_mean(L), numer; /* 4.528728688116765 */
+harmonic_mean(L), numer; /* 3.414171521474055 */
diff --git a/Task/Averages-Root-mean-square/Factor/averages-root-mean-square.factor b/Task/Averages-Root-mean-square/Factor/averages-root-mean-square.factor
new file mode 100644
index 0000000000..028a2c349d
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Factor/averages-root-mean-square.factor
@@ -0,0 +1,2 @@
+: root-mean-square ( seq -- mean )
+ [ [ sq ] map-sum ] [ length ] bi / sqrt ;
diff --git a/Task/Averages-Root-mean-square/Fantom/averages-root-mean-square.fantom b/Task/Averages-Root-mean-square/Fantom/averages-root-mean-square.fantom
new file mode 100644
index 0000000000..ec261baa07
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Fantom/averages-root-mean-square.fantom
@@ -0,0 +1,16 @@
+class Main
+{
+ static Float averageRms (Float[] nums)
+ {
+ if (nums.size == 0) return 0.0f
+ Float sum := 0f
+ nums.each { sum += it * it }
+ return (sum / nums.size.toFloat).sqrt
+ }
+
+ public static Void main ()
+ {
+ a := [1f,2f,3f,4f,5f,6f,7f,8f,9f,10f]
+ echo ("RMS Average of $a is: " + averageRms(a))
+ }
+}
diff --git a/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-1.groovy b/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-1.groovy
new file mode 100644
index 0000000000..8866c292bd
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-1.groovy
@@ -0,0 +1,7 @@
+def quadMean = { list ->
+ list == null \
+ ? null \
+ : list.empty \
+ ? 0 \
+ : ((list.collect { it*it }.sum()) / list.size()) ** 0.5
+}
diff --git a/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-2.groovy b/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-2.groovy
new file mode 100644
index 0000000000..8ec806ff67
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Groovy/averages-root-mean-square-2.groovy
@@ -0,0 +1,6 @@
+def list = 1..10
+def Q = quadMean(list)
+println """
+list: ${list}
+ Q: ${Q}
+"""
diff --git a/Task/Averages-Root-mean-square/HicEst/averages-root-mean-square.hicest b/Task/Averages-Root-mean-square/HicEst/averages-root-mean-square.hicest
new file mode 100644
index 0000000000..14e7478988
--- /dev/null
+++ b/Task/Averages-Root-mean-square/HicEst/averages-root-mean-square.hicest
@@ -0,0 +1,5 @@
+sum = 0
+DO i = 1, 10
+ sum = sum + i^2
+ENDDO
+WRITE(ClipBoard) "RMS(1..10) = ", (sum/10)^0.5
diff --git a/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-1.icon b/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-1.icon
new file mode 100644
index 0000000000..fe15d53b85
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-1.icon
@@ -0,0 +1,5 @@
+procedure main()
+every put(x := [], 1 to 10)
+writes("x := [ "); every writes(!x," "); write("]")
+write("Quadratic mean:",q := qmean!x)
+end
diff --git a/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-2.icon b/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-2.icon
new file mode 100644
index 0000000000..2d993863a0
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Icon/averages-root-mean-square-2.icon
@@ -0,0 +1,6 @@
+procedure qmean(L[]) #: quadratic mean
+ local m
+ if *L = 0 then fail
+ every (m := 0.0) +:= !L^2
+ return sqrt(m / *L)
+end
diff --git a/Task/Averages-Root-mean-square/Io/averages-root-mean-square.io b/Task/Averages-Root-mean-square/Io/averages-root-mean-square.io
new file mode 100644
index 0000000000..b43545a014
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Io/averages-root-mean-square.io
@@ -0,0 +1,3 @@
+rms := method (figs, (figs map(** 2) reduce(+) / figs size) sqrt)
+
+rms( Range 1 to(10) asList ) println
diff --git a/Task/Averages-Root-mean-square/J/averages-root-mean-square-1.j b/Task/Averages-Root-mean-square/J/averages-root-mean-square-1.j
new file mode 100644
index 0000000000..e02db1451b
--- /dev/null
+++ b/Task/Averages-Root-mean-square/J/averages-root-mean-square-1.j
@@ -0,0 +1 @@
+rms=: (+/ % #)&.:*:
diff --git a/Task/Averages-Root-mean-square/J/averages-root-mean-square-2.j b/Task/Averages-Root-mean-square/J/averages-root-mean-square-2.j
new file mode 100644
index 0000000000..6ec5f367ea
--- /dev/null
+++ b/Task/Averages-Root-mean-square/J/averages-root-mean-square-2.j
@@ -0,0 +1,2 @@
+ rms 1 + i. 10
+6.20484
diff --git a/Task/Averages-Root-mean-square/Liberty-BASIC/averages-root-mean-square.liberty b/Task/Averages-Root-mean-square/Liberty-BASIC/averages-root-mean-square.liberty
new file mode 100644
index 0000000000..1200d70531
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Liberty-BASIC/averages-root-mean-square.liberty
@@ -0,0 +1,26 @@
+' [RC] Averages/Root mean square
+
+ SourceList$ ="1 2 3 4 5 6 7 8 9 10"
+
+ ' If saved as an array we'd have to have a flag for last data.
+ ' LB has the very useful word$() to read from delimited strings.
+ ' The default delimiter is a space character, " ".
+
+ SumOfSquares =0
+ n =0 ' This holds index to number, and counts number of data.
+ data$ ="666" ' temporary dummy to enter the loop.
+
+ while data$ <>"" ' we loop until no data left.
+ data$ =word$( SourceList$, n +1) ' first data, as a string
+ NewVal =val( data$) ' convert string to number
+ SumOfSquares =SumOfSquares +NewVal^2 ' add to existing sum of squares
+ n =n +1 ' increment number of data items found
+ wend
+
+ n =n -1
+
+ print "Supplied data was "; SourceList$
+ print "This contained "; n; " numbers."
+ print "R.M.S. value is "; ( SumOfSquares /n)^0.5
+
+ end
diff --git a/Task/Averages-Root-mean-square/Logo/averages-root-mean-square.logo b/Task/Averages-Root-mean-square/Logo/averages-root-mean-square.logo
new file mode 100644
index 0000000000..cd6f3be3bb
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Logo/averages-root-mean-square.logo
@@ -0,0 +1,5 @@
+to rms :v
+ output sqrt quotient (apply "sum map [? * ?] :v) count :v
+end
+
+show rms iseq 1 10
diff --git a/Task/Averages-Root-mean-square/Mathematica/averages-root-mean-square.mathematica b/Task/Averages-Root-mean-square/Mathematica/averages-root-mean-square.mathematica
new file mode 100644
index 0000000000..18c372a3fa
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Mathematica/averages-root-mean-square.mathematica
@@ -0,0 +1 @@
+RootMeanSquare@Range[10]
diff --git a/Task/Averages-Root-mean-square/Maxima/averages-root-mean-square.maxima b/Task/Averages-Root-mean-square/Maxima/averages-root-mean-square.maxima
new file mode 100644
index 0000000000..a635ce583f
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Maxima/averages-root-mean-square.maxima
@@ -0,0 +1,5 @@
+L: makelist(i, i, 1, 10)$
+
+rms(L) := sqrt(lsum(x^2, x, L)/length(L))$
+
+rms(L), numer; /* 6.204836822995429 */
diff --git a/Task/Averages-Simple-moving-average/Fantom/averages-simple-moving-average.fantom b/Task/Averages-Simple-moving-average/Fantom/averages-simple-moving-average.fantom
new file mode 100644
index 0000000000..c0d4717891
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Fantom/averages-simple-moving-average.fantom
@@ -0,0 +1,45 @@
+class MovingAverage
+{
+ Int period
+ Int[] stream
+
+ new make (Int period)
+ {
+ this.period = period
+ stream = [,]
+ }
+
+ // add number to end of stream and remove numbers from start if
+ // stream is larger than period
+ public Void addNumber (Int number)
+ {
+ stream.add (number)
+ while (stream.size > period)
+ {
+ stream.removeAt (0)
+ }
+ }
+
+ // compute average of numbers in stream
+ public Float average ()
+ {
+ if (stream.isEmpty)
+ return 0.0f
+ else
+ 1.0f * (Int)(stream.reduce(0, |a,b| { (Int) a + b })) / stream.size
+ }
+}
+
+class Main
+{
+ public static Void main ()
+ { // test by adding random numbers and printing average after each number
+ av := MovingAverage (5)
+
+ 10.times |i|
+ {
+ echo ("After $i numbers list is ${av.stream} average is ${av.average}")
+ av.addNumber (Int.random(0..100))
+ }
+ }
+}
diff --git a/Task/Averages-Simple-moving-average/GAP/averages-simple-moving-average.gap b/Task/Averages-Simple-moving-average/GAP/averages-simple-moving-average.gap
new file mode 100644
index 0000000000..fca65c5ae8
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/GAP/averages-simple-moving-average.gap
@@ -0,0 +1,27 @@
+MovingAverage := function(n)
+ local sma, buffer, pos, sum, len;
+ buffer := List([1 .. n], i -> 0);
+ pos := 0;
+ len := 0;
+ sum := 0;
+ sma := function(x)
+ pos := RemInt(pos, n) + 1;
+ sum := sum + x - buffer[pos];
+ buffer[pos] := x;
+ len := Minimum(len + 1, n);
+ return sum/len;
+ end;
+ return sma;
+end;
+
+f := MovingAverage(3);
+f(1); # 1
+f(2); # 3/2
+f(3); # 2
+f(4); # 3
+f(5); # 4
+f(5); # 14/3
+f(4); # 14/3
+f(3); # 4
+f(2); # 3
+f(1); # 2
diff --git a/Task/Averages-Simple-moving-average/Groovy/averages-simple-moving-average.groovy b/Task/Averages-Simple-moving-average/Groovy/averages-simple-moving-average.groovy
new file mode 100644
index 0000000000..6dff757820
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Groovy/averages-simple-moving-average.groovy
@@ -0,0 +1,15 @@
+def simple_moving_average = { size ->
+ def nums = []
+ double total = 0.0
+ return { newElement ->
+ nums += newElement
+ oldestElement = nums.size() > size ? nums.remove(0) : 0
+ total += newElement - oldestElement
+ total / nums.size()
+ }
+}
+
+ma5 = simple_moving_average(5)
+
+(1..5).each{ printf( "%1.1f ", ma5(it)) }
+(5..1).each{ printf( "%1.1f ", ma5(it)) }
diff --git a/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-1.hicest b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-1.hicest
new file mode 100644
index 0000000000..ae51600497
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-1.hicest
@@ -0,0 +1,26 @@
+REAL :: n=10, nums(n)
+
+nums = (1,2,3,4,5, 5,4,3,2,1)
+DO i = 1, n
+ WRITE() "num=", i, "SMA3=", SMA(3,nums(i)), "SMA5=",SMA(5,nums(i))
+ENDDO
+
+END ! of "main"
+
+FUNCTION SMA(period, num) ! maxID independent streams
+ REAL :: maxID=10, now(maxID), Periods(maxID), Offsets(maxID), Pool(1000)
+
+ ID = INDEX(Periods, period)
+ IF( ID == 0) THEN ! initialization
+ IDs = IDs + 1
+ ID = IDs
+ Offsets(ID) = SUM(Periods) + 1
+ Periods(ID) = period
+ ENDIF
+
+ now(ID) = now(ID) + 1
+ ALIAS(Pool,Offsets(ID), Past,Periods(ID)) ! renames relevant part of data pool
+ Past = Past($+1) ! shift left
+ Past(Periods(ID)) = num
+ SMA = SUM(Past) / MIN( now(ID), Periods(ID) )
+ END
diff --git a/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-2.hicest b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-2.hicest
new file mode 100644
index 0000000000..cf45eddb0b
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-2.hicest
@@ -0,0 +1,18 @@
+procedure main(A)
+ sma := buildSMA(3) # Use better name than "I".
+ every write(sma(!A))
+end
+
+procedure buildSMA(P)
+ local stream
+ c := create {
+ stream := []
+ while n := (avg@&source)[1] do {
+ put(stream, n)
+ if *stream > P then pop(stream)
+ every (avg := 0.0) +:= !stream
+ avg := avg/*stream
+ }
+ }
+ return (@c, c)
+end
diff --git a/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-3.hicest b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-3.hicest
new file mode 100644
index 0000000000..297f9475cd
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/HicEst/averages-simple-moving-average-3.hicest
@@ -0,0 +1,14 @@
+import Utils
+
+procedure main(A)
+ sma1 := closure(SMA,[],3)
+ sma2 := closure(SMA,[],4)
+ every every n := !A do write(left(sma1(n),20), sma2(n))
+end
+
+procedure SMA(stream,P,n)
+ put(stream, n)
+ if *stream > P then pop(stream)
+ every (avg := 0.0) +:= !stream
+ return avg / *stream
+end
diff --git a/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-1.j b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-1.j
new file mode 100644
index 0000000000..85e9d8445f
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-1.j
@@ -0,0 +1,2 @@
+ 5 (+/%#)\ 1 2 3 4 5 5 4 3 2 1 NB. not a solution for this task
+3 3.8 4.2 4.2 3.8 3
diff --git a/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-2.j b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-2.j
new file mode 100644
index 0000000000..3012ebd22e
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-2.j
@@ -0,0 +1 @@
+ lex =: 1 :'(a[n__a=.m#_.[a=.18!:3$~0)&(4 :''(+/%#)(#~1-128!:5)n__x=.1|.!.y n__x'')'
diff --git a/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-3.j b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-3.j
new file mode 100644
index 0000000000..b999b13ced
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-3.j
@@ -0,0 +1,3 @@
+ sma =: 5 lex
+ sma&> 1 2 3 4 5 5 4 3 2 1
+1 1.5 2 2.5 3 3.8 4.2 4.2 3.8 3
diff --git a/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-4.j b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-4.j
new file mode 100644
index 0000000000..bb23309b6d
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/J/averages-simple-moving-average-4.j
@@ -0,0 +1,9 @@
+avg=: +/ % #
+SEQ=:''
+moveAvg=:4 :0"0
+ SEQ=:SEQ,y
+ avg ({.~ x -@<. #) SEQ
+)
+
+ 5 moveAvg 1 2 3 4 5 5 4 3 2 1
+1 1.5 2 2.5 3 3.8 4.2 4.2 3.8 3
diff --git a/Task/Averages-Simple-moving-average/Liberty-BASIC/averages-simple-moving-average.liberty b/Task/Averages-Simple-moving-average/Liberty-BASIC/averages-simple-moving-average.liberty
new file mode 100644
index 0000000000..27fd659310
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Liberty-BASIC/averages-simple-moving-average.liberty
@@ -0,0 +1,68 @@
+ dim v$( 100) ' Each array term stores a particular SMA of period p in p*10 bytes
+
+ nomainwin
+
+ WindowWidth =1080
+ WindowHeight = 780
+
+ graphicbox #w.gb1, 20, 20, 1000, 700
+
+ open "Running averages to smooth data" for window as #w
+
+ #w "trapclose quit"
+
+ #w.gb1 "down"
+
+ old.x = 0
+ old.y.orig =500 ' black
+ old.y.3.SMA =350 ' red
+ old.y.20.SMA =300 ' green
+
+ for i =0 to 999 step 1
+ scan
+ v =1.1 +sin( i /1000 *2 *3.14159265) + 0.2 *rnd( 1) ' sin wave with added random noise
+ x =i /6.28318 *1000
+ y.orig =500 -v /2.5 *500
+
+ #w.gb1 "color black ; down ; line "; i-1; " "; old.y.orig; " "; i; " "; y.orig; " ; up"
+
+ y.3.SMA =500 -SMA( 1, v, 3) /2.5 *500 ' SMA given ID of 1 is to do 3-term running average
+ #w.gb1 "color red ; down ; line "; i-1; " "; old.y.3.SMA +50; " "; i; " "; y.3.SMA +50; " ; up"
+
+ y.20.SMA =500 -SMA( 2, v, 20) /2.5 *500 ' SMA given ID of 2 is to do 20-term running average
+ #w.gb1 "color green ; down ; line "; i-1; " "; old.y.20.SMA +100; " "; i; " "; y.20.SMA +100; " ; up"
+
+ 'print "Supplied with "; v; ", so SMAs are now "; using( "###.###", SMA( 1, v, 3)); " over 3 terms or "; using( "###.###", SMA( 2, v, 5)) ; " over 5 terms." ' ID, latest data, period
+
+ old.y.orig =y.orig
+ old.y.3.SMA =y.3.SMA
+ old.y.20.SMA =y.20.SMA
+ next i
+
+ wait
+
+sub quit j$
+ close #w
+ end
+end sub
+
+
+
+function SMA( ID, Number, Period)
+ v$( ID) =right$( " " +str$( Number), 10) +v$( ID) ' add new number at left, lose last number on right
+ v$( ID) =left$( v$( ID), Period *10)
+ 'print "{"; v$( ID); "}",
+
+ k =0 ' number of terms read
+ total =0 ' sum of terms read
+
+ do
+ p$ =mid$( v$( ID), 1 +k *10, 10)
+ if p$ ="" then exit do
+ vv =val( p$)
+ total =total +vv
+ k =k +1
+ loop until p$ =""
+
+ if k (MAData[[2]] = r), #[[-r ;; -1]], #] &@
+ Append[MAData[[1]], x]]]
diff --git a/Task/Averages-Simple-moving-average/Mercury/averages-simple-moving-average.mercury b/Task/Averages-Simple-moving-average/Mercury/averages-simple-moving-average.mercury
new file mode 100644
index 0000000000..a5309c3315
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Mercury/averages-simple-moving-average.mercury
@@ -0,0 +1,10 @@
+ % state(period, list of floats from [newest, ..., oldest])
+:- type state ---> state(int, list(float)).
+
+:- func init(int) = state.
+init(Period) = state(Period, []).
+
+:- pred sma(float::in, float::out, state::in, state::out) is det.
+sma(N, Average, state(P, L0), state(P, L)) :-
+ take_upto(P, [N|L0], L),
+ Average = foldl((+), L, 0.0) / float(length(L)).
diff --git a/Task/Balanced-brackets/Factor/balanced-brackets.factor b/Task/Balanced-brackets/Factor/balanced-brackets.factor
new file mode 100644
index 0000000000..aba286a551
--- /dev/null
+++ b/Task/Balanced-brackets/Factor/balanced-brackets.factor
@@ -0,0 +1,22 @@
+USING: io formatting locals kernel math sequences unicode.case ;
+IN: balanced-brackets
+
+:: balanced ( str -- )
+ 0 :> counter!
+ 1 :> ok!
+ str
+ [ dup length 0 > ]
+ [ 1 cut swap
+ "[" = [ counter 1 + counter! ] [ counter 1 - counter! ] if
+ counter 0 < [ 0 ok! ] when
+ ]
+ while
+ drop
+ ok 0 =
+ [ "NO" ]
+ [ counter 0 > [ "NO" ] [ "YES" ] if ]
+ if
+ print ;
+
+readln
+balanced
diff --git a/Task/Balanced-brackets/Fantom/balanced-brackets.fantom b/Task/Balanced-brackets/Fantom/balanced-brackets.fantom
new file mode 100644
index 0000000000..aaf68c715a
--- /dev/null
+++ b/Task/Balanced-brackets/Fantom/balanced-brackets.fantom
@@ -0,0 +1,39 @@
+class Main
+{
+ static Bool matchingBrackets (Str[] brackets)
+ {
+ Int opened := 0
+ Int i := 0
+ while (i < brackets.size)
+ {
+ if (brackets[i] == "[")
+ opened += 1
+ else
+ opened -= 1
+ if (opened < 0) return false
+ i += 1
+ }
+ return true
+ }
+
+ public static Void main (Str[] args)
+ {
+ if (args.size == 1 && Int.fromStr(args[0], 10, false) != null)
+ {
+ n := Int.fromStr(args[0])
+ Str[] brackets := [,]
+ 20.times
+ {
+ brackets = [,]
+ // create a random set of brackets
+ n.times { brackets.addAll (["[", "]"]) }
+ n.times { brackets.swap(Int.random(0..<2*n), Int.random(0..<2*n)) }
+ // report if matching or not
+ if (matchingBrackets(brackets))
+ echo (brackets.join(" ") + " Matching")
+ else
+ echo (brackets.join(" ") + " not matching")
+ }
+ }
+ }
+}
diff --git a/Task/Balanced-brackets/GAP/balanced-brackets.gap b/Task/Balanced-brackets/GAP/balanced-brackets.gap
new file mode 100644
index 0000000000..4a4d7f5b17
--- /dev/null
+++ b/Task/Balanced-brackets/GAP/balanced-brackets.gap
@@ -0,0 +1,36 @@
+Balanced := function(L)
+ local c, r;
+ r := 0;
+ for c in L do
+ if c = ']' then
+ r := r - 1;
+ if r < 0 then
+ return false;
+ fi;
+ elif c = '[' then
+ r := r + 1;
+ fi;
+ od;
+ return r = 0;
+end;
+
+Balanced("");
+# true
+
+Balanced("[");
+# false
+
+Balanced("]");
+# false
+
+Balanced("[]");
+# true
+
+Balanced("][");
+# false
+
+Balanced("[[][]]");
+# true
+
+Balanced("[[[]][]]]");
+# false
diff --git a/Task/Balanced-brackets/Groovy/balanced-brackets-1.groovy b/Task/Balanced-brackets/Groovy/balanced-brackets-1.groovy
new file mode 100644
index 0000000000..9a469ec0f0
--- /dev/null
+++ b/Task/Balanced-brackets/Groovy/balanced-brackets-1.groovy
@@ -0,0 +1,21 @@
+def random = new Random()
+
+def factorial = { (it > 1) ? (2..it).inject(1) { i, j -> i*j } : 1 }
+
+def makePermutation;
+makePermutation = { string, i ->
+ def n = string.size()
+ if (n < 2) return string
+ def fact = factorial(n-1)
+ assert i < fact*n
+
+ def index = i.intdiv(fact)
+ string[index] + makePermutation(string[0..
+ if (n == 0) return ''
+ def base = '['*n + ']'*n
+ def p = random.nextInt(factorial(n*2))
+ makePermutation(base, p)
+}
diff --git a/Task/Balanced-brackets/Groovy/balanced-brackets-2.groovy b/Task/Balanced-brackets/Groovy/balanced-brackets-2.groovy
new file mode 100644
index 0000000000..9c18f4280f
--- /dev/null
+++ b/Task/Balanced-brackets/Groovy/balanced-brackets-2.groovy
@@ -0,0 +1,11 @@
+boolean balancedBrackets(String brackets, int depth=0) {
+ if (brackets == null || brackets.empty) return depth == 0
+ switch (brackets[0]) {
+ case '[':
+ return brackets.size() > 1 && balancedBrackets(brackets[1..-1], depth + 1)
+ case ']':
+ return depth > 0 && (brackets.size() == 1 || balancedBrackets(brackets[1..-1], depth - 1))
+ default:
+ return brackets.size() == 1 ? depth == 0 : balancedBrackets(brackets[1..-1], depth)
+ }
+}
diff --git a/Task/Balanced-brackets/Groovy/balanced-brackets-3.groovy b/Task/Balanced-brackets/Groovy/balanced-brackets-3.groovy
new file mode 100644
index 0000000000..9489cd460c
--- /dev/null
+++ b/Task/Balanced-brackets/Groovy/balanced-brackets-3.groovy
@@ -0,0 +1,13 @@
+Set brackets = []
+(0..100).each {
+ (0..8).each { r ->
+ brackets << randomBrackets(r)
+ }
+}
+
+brackets.sort { a, b ->
+ a.size() <=> b.size() ?: a <=> b
+} .each {
+ def bal = balancedBrackets(it) ? "balanced: " : "unbalanced: "
+ println "${bal} ${it}"
+}
diff --git a/Task/Balanced-brackets/Icon/balanced-brackets.icon b/Task/Balanced-brackets/Icon/balanced-brackets.icon
new file mode 100644
index 0000000000..133cb9b25a
--- /dev/null
+++ b/Task/Balanced-brackets/Icon/balanced-brackets.icon
@@ -0,0 +1,15 @@
+procedure main(arglist)
+every s := genbs(!arglist) do
+ write(image(s), if isbalanced(s) then " is balanced." else " is unbalanced")
+end
+
+procedure isbalanced(s) # test if a string is balanced re: []
+return (s || " ") ? (bal(,'[',']') = *s+1)
+end
+
+procedure genbs(i) # generate strings of i pairs of []
+s := ""
+every 1 to i do s ||:= "[]" # generate i pairs
+every !s := ?s # shuffle
+return s
+end
diff --git a/Task/Balanced-brackets/J/balanced-brackets-1.j b/Task/Balanced-brackets/J/balanced-brackets-1.j
new file mode 100644
index 0000000000..7da00fec3d
--- /dev/null
+++ b/Task/Balanced-brackets/J/balanced-brackets-1.j
@@ -0,0 +1,3 @@
+bracketDepth =: '[]' -&(+/\)/@:(=/) ]
+checkBalanced =: _1 -.@e. bracketDepth
+genBracketPairs =: (?~@# { ])@#"0 1&'[]' NB. bracket pairs in arbitrary order
diff --git a/Task/Balanced-brackets/J/balanced-brackets-2.j b/Task/Balanced-brackets/J/balanced-brackets-2.j
new file mode 100644
index 0000000000..8cb613b3d3
--- /dev/null
+++ b/Task/Balanced-brackets/J/balanced-brackets-2.j
@@ -0,0 +1,11 @@
+ (,&' ' , ('bad';'OK') {::~ checkBalanced)"1 genBracketPairs i. 10
+ OK
+][ bad
+][[] bad
+[[[]]] OK
+[][[]][] OK
+[][[[][]]] OK
+[]][]][]][[[ bad
+[[]][[][][]][] OK
+]]]][[][][[[[]][ bad
+[]]][][][[[[]][[]] bad
diff --git a/Task/Balanced-brackets/Liberty-BASIC/balanced-brackets.liberty b/Task/Balanced-brackets/Liberty-BASIC/balanced-brackets.liberty
new file mode 100644
index 0000000000..8795ff98a0
--- /dev/null
+++ b/Task/Balanced-brackets/Liberty-BASIC/balanced-brackets.liberty
@@ -0,0 +1,62 @@
+print "Supplied examples"
+for i =1 to 7
+ read test$
+ print "The string '"; test$; "' is "; validString$( test$)
+next i
+print
+data "", "[]", "][","[][]","][][","[[][]]","[]][[]"
+
+print "Random generated examples"
+for example =1 to 10
+ test$ =generate$( int( 1 +10 *rnd(1)))
+ print "The string '"; test$; "' is "; validString$( test$)
+next example
+end
+
+function validString$( in$)
+ if left$( in$, 1) <>"[" and len( test$) <>0 then
+ validString$ ="not OK. Opens wrongly."
+ exit function
+ end if
+ paired =0
+ for i =1 to len( in$)
+ c$ =mid$( in$, i, 1)
+ if c$ ="[" then paired =paired +1
+ if c$ ="]" then paired =paired -1
+ if paired <0 then
+ exit for
+ end if
+ next i
+ if ( lBr =rBr) and ( paired >=0) then validString$ ="OK." else validString$ ="not OK. Unbalanced."
+end function
+
+function generate$( N)
+ lBr =0
+ rBr =0
+ ' choose at random until N of one type generated
+ while ( lBr use StringTools in
+> IsBalanced( "", "[", "]" );
+> IsBalanced( "[", "[", "]" );
+> IsBalanced( "]", "[", "]" );
+> IsBalanced( "[]", "[", "]" );
+> IsBalanced( "][", "[", "]" );
+> IsBalanced( "[][]", "[", "]" );
+> IsBalanced( "[[][]]", "[", "]" );
+> IsBalanced( "[[[]][]]]", "[", "]" );
+> s := Random( 20, "[]" );
+> IsBalanced( s, "[", "]" )
+> end use;
+ true
+
+ false
+
+ false
+
+ true
+
+ false
+
+ true
+
+ true
+
+ false
+
+ s := "[[]][[[[[[[[[]][][]]"
+
+ false
diff --git a/Task/Balanced-brackets/Maple/balanced-brackets-2.maple b/Task/Balanced-brackets/Maple/balanced-brackets-2.maple
new file mode 100644
index 0000000000..ff523ac8a7
--- /dev/null
+++ b/Task/Balanced-brackets/Maple/balanced-brackets-2.maple
@@ -0,0 +1,2 @@
+> StringTools:-IsBalanced( "[()()]", "[(", "])" );
+ true
diff --git a/Task/Balanced-brackets/Mathematica/balanced-brackets.mathematica b/Task/Balanced-brackets/Mathematica/balanced-brackets.mathematica
new file mode 100644
index 0000000000..2765a2d874
--- /dev/null
+++ b/Task/Balanced-brackets/Mathematica/balanced-brackets.mathematica
@@ -0,0 +1,13 @@
+(* Generate open/close events. *)
+gen[n_] := RandomSample[Table[{1, -1}, {n}] // Flatten]
+
+(* Check balance. *)
+check[lst_] := And @@ (# >= 0 & /@ Accumulate[lst])
+
+(* Do task for string with n opening and n closing brackets. *)
+doString[n_] := (
+ lst = gen[n];
+ str = StringJoin[lst /. {1 -> "[", -1 -> "]"}];
+ Print[str <> If[match[lst, 0],
+ " is balanced.",
+ " is not balanced."]])
diff --git a/Task/Balanced-brackets/Maxima/balanced-brackets.maxima b/Task/Balanced-brackets/Maxima/balanced-brackets.maxima
new file mode 100644
index 0000000000..8b41b6cc3c
--- /dev/null
+++ b/Task/Balanced-brackets/Maxima/balanced-brackets.maxima
@@ -0,0 +1,31 @@
+brack(s) := block(
+ [n: slength(s), r: 0, c],
+ catch(
+ for i thru n do (
+ if cequal(c: charat(s, i), "]") then (if (r: r - 1) < 0 then throw(false))
+ elseif cequal(c, "[") then r: r + 1
+ ),
+ is(r = 0)
+ )
+)$
+
+brack("");
+true
+
+brack("[");
+false
+
+brack("]");
+false
+
+brack("[]");
+true
+
+brack("][");
+false
+
+brack("[[][]]");
+true
+
+brack("[[[]][]]]");
+false
diff --git a/Task/Balanced-ternary/J/balanced-ternary-1.j b/Task/Balanced-ternary/J/balanced-ternary-1.j
new file mode 100644
index 0000000000..0b273d7166
--- /dev/null
+++ b/Task/Balanced-ternary/J/balanced-ternary-1.j
@@ -0,0 +1,12 @@
+trigits=: 1+3 <.@^. 2 * 1&>.@|
+trinOfN=: |.@((_1 + ] #: #.&1@] + [) #&3@trigits) :. nOfTrin
+nOfTrin=: p.&3 :. trinOfN
+trinOfStr=: 0 1 _1 {~ '0+-'&i.@|. :. strOfTrin
+strOfTrin=: {&'0+-'@|. :. trinOfStr
+
+carry=: +//.@:(trinOfN"0)^:_
+trimLead0=: (}.~ i.&1@:~:&0)&.|.
+
+add=: carry@(+/@,:)
+neg=: -
+mul=: trimLead0@carry@(+//.@(*/))
diff --git a/Task/Balanced-ternary/J/balanced-ternary-2.j b/Task/Balanced-ternary/J/balanced-ternary-2.j
new file mode 100644
index 0000000000..cd16cd1bbd
--- /dev/null
+++ b/Task/Balanced-ternary/J/balanced-ternary-2.j
@@ -0,0 +1,3 @@
+a=: trinOfStr '+-0++0+'
+b=: trinOfN -436
+c=: trinOfStr '+-++-'
diff --git a/Task/Balanced-ternary/J/balanced-ternary-3.j b/Task/Balanced-ternary/J/balanced-ternary-3.j
new file mode 100644
index 0000000000..203fa83ad9
--- /dev/null
+++ b/Task/Balanced-ternary/J/balanced-ternary-3.j
@@ -0,0 +1,7 @@
+ nOfTrin&> a;b;c
+523 _436 65
+
+ strOfTrin a mul b (add -) c
+----0+--0++0
+ nOfTrin a mul b (add -) c
+_262023
diff --git a/Task/Balanced-ternary/Mathematica/balanced-ternary-1.mathematica b/Task/Balanced-ternary/Mathematica/balanced-ternary-1.mathematica
new file mode 100644
index 0000000000..9d053ddc9f
--- /dev/null
+++ b/Task/Balanced-ternary/Mathematica/balanced-ternary-1.mathematica
@@ -0,0 +1,22 @@
+frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}],
+ 3] &;
+tobt = If[Quotient[#, 3, -1] == 0,
+ "", #0@Quotient[#, 3, -1]] <> (Mod[#,
+ 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &;
+btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &;
+btadd = StringReplace[
+ StringJoin[
+ Fold[Sort@{#1[[1]],
+ Sequence @@ #2} /. {{x_, x_, x_} :> {x,
+ "0" <> #1[[2]]}, {"-", "+", x_} | {x_, "-", "+"} | {x_,
+ "0", "0"} :> {"0", x <> #1[[2]]}, {"+", "+", "0"} -> {"+",
+ "-" <> #1[[2]]}, {"-", "-", "0"} -> {"-",
+ "+" <> #1[[2]]}} &, {"0", ""},
+ Reverse@Transpose@PadLeft[Characters /@ {#1, #2}] /. {0 ->
+ "0"}]], StartOfString ~~ "0" .. ~~ x__ :> x] &;
+btsubtract = btadd[#1, btnegate@#2] &;
+btmultiply =
+ btadd[Switch[StringTake[#2, -1], "0", "0", "+", #1, "-",
+ btnegate@#1],
+ If[StringLength@#2 == 1,
+ "0", #0[#1, StringDrop[#2, -1]] <> "0"]] &;
diff --git a/Task/Balanced-ternary/Mathematica/balanced-ternary-2.mathematica b/Task/Balanced-ternary/Mathematica/balanced-ternary-2.mathematica
new file mode 100644
index 0000000000..0319fc510f
--- /dev/null
+++ b/Task/Balanced-ternary/Mathematica/balanced-ternary-2.mathematica
@@ -0,0 +1,4 @@
+frombt[a = "+-0++0+"]
+b = tobt@-436
+frombt[c = "+-++-"]
+btmultiply[a, btsubtract[b, c]]
diff --git a/Task/Best-shuffle/Groovy/best-shuffle.groovy b/Task/Best-shuffle/Groovy/best-shuffle.groovy
new file mode 100644
index 0000000000..29af197e7b
--- /dev/null
+++ b/Task/Best-shuffle/Groovy/best-shuffle.groovy
@@ -0,0 +1,29 @@
+def shuffle(text) {
+ def shuffled = (text as List)
+ for (sourceIndex in 0..
+ if (character == shuffled[index]) {
+ score++
+ }
+ }
+ score
+}
+
+["abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"].each { text ->
+ def result = shuffle(text)
+ println "${result.original}, ${result.shuffled}, (${result.score})"
+}
diff --git a/Task/Best-shuffle/Icon/best-shuffle-1.icon b/Task/Best-shuffle/Icon/best-shuffle-1.icon
new file mode 100644
index 0000000000..a1774a8dc2
--- /dev/null
+++ b/Task/Best-shuffle/Icon/best-shuffle-1.icon
@@ -0,0 +1 @@
+# every !t :=: ?t # Uncomment to get a random best shuffling
diff --git a/Task/Best-shuffle/Icon/best-shuffle-2.icon b/Task/Best-shuffle/Icon/best-shuffle-2.icon
new file mode 100644
index 0000000000..887300f924
--- /dev/null
+++ b/Task/Best-shuffle/Icon/best-shuffle-2.icon
@@ -0,0 +1,18 @@
+procedure main(args)
+ while scram := bestShuffle(line := read()) do
+ write(line," -> ",scram," (",unchanged(line,scram),")")
+end
+
+procedure bestShuffle(s)
+ t := s
+ # every !t :=: ?t # Uncomment to get a random best shuffling
+ every i := 1 to *t do
+ every j := (1 to i-1) | (i+1 to *t) do
+ if (t[i] ~== s[j]) & (s[i] ~== t[j]) then break t[i] :=: t[j]
+ return t
+end
+
+procedure unchanged(s1,s2) # Number of unchanged elements
+ every (count := 0) +:= (s1[i := 1 to *s1] == s2[i], 1)
+ return count
+end
diff --git a/Task/Best-shuffle/J/best-shuffle-1.j b/Task/Best-shuffle/J/best-shuffle-1.j
new file mode 100644
index 0000000000..a43f1ac15c
--- /dev/null
+++ b/Task/Best-shuffle/J/best-shuffle-1.j
@@ -0,0 +1,9 @@
+bestShuf =: verb define
+ yy=. <@({~ ?~@#)@I.@= y
+ y C.~ (;yy) ./#@> yy
+)
+
+fmtBest=:3 :0
+ b=. bestShuf y
+ y,', ',b,' (',')',~":+/b=y
+)
diff --git a/Task/Best-shuffle/J/best-shuffle-2.j b/Task/Best-shuffle/J/best-shuffle-2.j
new file mode 100644
index 0000000000..55e73c7172
--- /dev/null
+++ b/Task/Best-shuffle/J/best-shuffle-2.j
@@ -0,0 +1,7 @@
+ fmtBest&>;:'abracadabra seesaw elk grrrrrr up a'
+abracadabra, bdacararaab (0)
+seesaw, eawess (0)
+elk, lke (0)
+grrrrrr, rrrrrrg (5)
+up, pu (0)
+a, a (1)
diff --git a/Task/Best-shuffle/Liberty-BASIC/best-shuffle.liberty b/Task/Best-shuffle/Liberty-BASIC/best-shuffle.liberty
new file mode 100644
index 0000000000..384d6308ce
--- /dev/null
+++ b/Task/Best-shuffle/Liberty-BASIC/best-shuffle.liberty
@@ -0,0 +1,26 @@
+'see Run BASIC solution
+list$ = "abracadabra seesaw pop grrrrrr up a"
+
+while word$(list$,ii + 1," ") <> ""
+ ii = ii + 1
+ w$ = word$(list$,ii," ")
+ bs$ = bestShuffle$(w$)
+ count = 0
+ for i = 1 to len(w$)
+ if mid$(w$,i,1) = mid$(bs$,i,1) then count = count + 1
+ next i
+ print w$;" ";bs$;" ";count
+wend
+
+function bestShuffle$(s1$)
+ s2$ = s1$
+ for i = 1 to len(s2$)
+ for j = 1 to len(s2$)
+ if (i <> j) and (mid$(s2$,i,1) <> mid$(s1$,j,1)) and (mid$(s2$,j,1) <> mid$(s1$,i,1)) then
+ if j < i then i1 = j:j1 = i else i1 = i:j1 = j
+ s2$ = left$(s2$,i1-1) + mid$(s2$,j1,1) + mid$(s2$,i1+1,(j1-i1)-1) + mid$(s2$,i1,1) + mid$(s2$,j1+1)
+ end if
+ next j
+ next i
+bestShuffle$ = s2$
+end function
diff --git a/Task/Best-shuffle/Mathematica/best-shuffle.mathematica b/Task/Best-shuffle/Mathematica/best-shuffle.mathematica
new file mode 100644
index 0000000000..042aa5b0f8
--- /dev/null
+++ b/Task/Best-shuffle/Mathematica/best-shuffle.mathematica
@@ -0,0 +1,5 @@
+BestShuffle[data_] :=
+ Flatten[{data,First[SortBy[
+ List[#, StringLength[data]-HammingDistance[#,data]] & /@ StringJoin /@ Permutations[StringSplit[data, ""]], Last]]}]
+
+Print[#[[1]], "," #[[2]], ",(", #[[3]], ")"] & /@ BestShuffle /@ {"abracadabra","seesaw","elk","grrrrrr","up","a"}
diff --git a/Task/Binary-search/Factor/binary-search.factor b/Task/Binary-search/Factor/binary-search.factor
new file mode 100644
index 0000000000..9854fd98f4
--- /dev/null
+++ b/Task/Binary-search/Factor/binary-search.factor
@@ -0,0 +1,4 @@
+USING: binary-search kernel math.order ;
+
+: binary-search ( seq elt -- index/f )
+ [ [ <=> ] curry search ] keep = [ drop f ] unless ;
diff --git a/Task/Binary-search/GAP/binary-search.gap b/Task/Binary-search/GAP/binary-search.gap
new file mode 100644
index 0000000000..1af13f88ce
--- /dev/null
+++ b/Task/Binary-search/GAP/binary-search.gap
@@ -0,0 +1,23 @@
+Find := function(v, x)
+ local low, high, mid;
+ low := 1;
+ high := Length(v);
+ while low <= high do
+ mid := QuoInt(low + high, 2);
+ if v[mid] > x then
+ high := mid - 1;
+ elif v[mid] < x then
+ low := mid + 1;
+ else
+ return mid;
+ fi;
+ od;
+ return fail;
+end;
+
+u := [1..10]*7;
+# [ 7, 14, 21, 28, 35, 42, 49, 56, 63, 70 ]
+Find(u, 34);
+# fail
+Find(u, 35);
+# 5
diff --git a/Task/Binary-search/Groovy/binary-search-1.groovy b/Task/Binary-search/Groovy/binary-search-1.groovy
new file mode 100644
index 0000000000..18ef3aceb8
--- /dev/null
+++ b/Task/Binary-search/Groovy/binary-search-1.groovy
@@ -0,0 +1,12 @@
+def binSearchR
+binSearchR = { a, target, offset=0 ->
+ def n = a.size()
+ def m = n.intdiv(2)
+ a.empty \
+ ? ["insertion point": offset] \
+ : a[m] > target \
+ ? binSearchR(a[0..
+ def a = aList
+ def offset = 0
+ while (!a.empty) {
+ def n = a.size()
+ def m = n.intdiv(2)
+ if(a[m] > target) {
+ a = a[0.. assert si < source[i+1] }
+
+println "${source}"
+1.upto(5) {
+ target = random.nextInt(10) + (it - 2) * 10
+ print "Trial #${it}. Looking for: ${target}"
+ def answers = [binSearchR, binSearchI].collect { search ->
+ search(source, target)
+ }
+ assert answers[0] == answers[1]
+ println """
+ Answer: ${answers[0]}, : ${source[answers[0].values().iterator().next()]}"""
+}
diff --git a/Task/Binary-search/HicEst/binary-search-1.hicest b/Task/Binary-search/HicEst/binary-search-1.hicest
new file mode 100644
index 0000000000..bafdb08664
--- /dev/null
+++ b/Task/Binary-search/HicEst/binary-search-1.hicest
@@ -0,0 +1,32 @@
+REAL :: n=10, array(n)
+
+ array = NINT( RAN(n) )
+ SORT(Vector=array, Sorted=array)
+ x = NINT( RAN(n) )
+
+ idx = binarySearch( array, x )
+ WRITE(ClipBoard) x, "has position ", idx, "in ", array
+ END
+
+FUNCTION binarySearch(A, value)
+ REAL :: A(1), value
+
+ low = 1
+ high = LEN(A)
+ DO i = 1, high
+ IF( low > high) THEN
+ binarySearch = 0
+ RETURN
+ ELSE
+ mid = INT( (low + high) / 2 )
+ IF( A(mid) > value) THEN
+ high = mid - 1
+ ELSEIF( A(mid) < value ) THEN
+ low = mid + 1
+ ELSE
+ binarySearch = mid
+ RETURN
+ ENDIF
+ ENDIF
+ ENDDO
+ END
diff --git a/Task/Binary-search/HicEst/binary-search-2.hicest b/Task/Binary-search/HicEst/binary-search-2.hicest
new file mode 100644
index 0000000000..002ecf6522
--- /dev/null
+++ b/Task/Binary-search/HicEst/binary-search-2.hicest
@@ -0,0 +1,2 @@
+7 has position 9 in 0 0 1 2 3 3 4 6 7 8
+5 has position 0 in 0 0 1 2 3 3 4 6 7 8
diff --git a/Task/Binary-search/Icon/binary-search-1.icon b/Task/Binary-search/Icon/binary-search-1.icon
new file mode 100644
index 0000000000..1ee1e97b0a
--- /dev/null
+++ b/Task/Binary-search/Icon/binary-search-1.icon
@@ -0,0 +1,11 @@
+procedure binsearch(A, target)
+ if *A = 0 then fail
+ mid := *A/2 + 1
+ if target > A[mid] then {
+ return mid + binsearch(A[(mid+1):0], target)
+ }
+ else if target < A[mid] then {
+ return binsearch(A[1+:(mid-1)], target)
+ }
+ return mid
+end
diff --git a/Task/Binary-search/Icon/binary-search-2.icon b/Task/Binary-search/Icon/binary-search-2.icon
new file mode 100644
index 0000000000..396b43a091
--- /dev/null
+++ b/Task/Binary-search/Icon/binary-search-2.icon
@@ -0,0 +1,13 @@
+procedure main(args)
+ target := integer(!args) | 3
+ every put(A := [], 1 to 18 by 2)
+
+ outList("Searching", A)
+ write(target," is ",("at "||binsearch(A, target)) | "not found")
+end
+
+procedure outList(prefix, A)
+ writes(prefix,": ")
+ every writes(!A," ")
+ write()
+end
diff --git a/Task/Binary-search/J/binary-search-1.j b/Task/Binary-search/J/binary-search-1.j
new file mode 100644
index 0000000000..7536594a82
--- /dev/null
+++ b/Task/Binary-search/J/binary-search-1.j
@@ -0,0 +1 @@
+bs=. i. 'Not Found'"_^:(-.@-:) I.
diff --git a/Task/Binary-search/J/binary-search-2.j b/Task/Binary-search/J/binary-search-2.j
new file mode 100644
index 0000000000..3c7eb3aa71
--- /dev/null
+++ b/Task/Binary-search/J/binary-search-2.j
@@ -0,0 +1,4 @@
+ 2 3 5 6 8 10 11 15 19 20 bs 11
+6
+ 2 3 5 6 8 10 11 15 19 20 bs 12
+Not Found
diff --git a/Task/Binary-search/J/binary-search-3.j b/Task/Binary-search/J/binary-search-3.j
new file mode 100644
index 0000000000..2c3d764d3e
--- /dev/null
+++ b/Task/Binary-search/J/binary-search-3.j
@@ -0,0 +1,13 @@
+'X Y L H M'=. i.5 NB. Setting mnemonics for boxes
+f=. &({::) NB. Fetching the contents of a box
+o=. @: NB. Composing verbs (functions)
+
+boxes=. ; , a: $~ 3: NB. Appending 3 (empty) boxes to the inputs
+LowHigh=. (0 ; # o (X f)) (L,H)} ] NB. Setting the low and high bounds
+midpoint=. < o (<. o (2 %~ L f + H f)) M} ] NB. Updating the midpoint
+case=. >: o * o (Y f - M f { X f) NB. Less=0, equal=1, or greater=2
+
+squeeze=. (< o (_1 + M f) H} ])`(< o _: L} ])`(< o (1 + M f) L} ])@.case
+return=. (M f) o ((<@:('Not Found'"_) M} ]) ^: (_ ~: L f))
+
+bs=. return o (squeeze o midpoint ^: (L f <: H f) ^:_) o LowHigh o boxes
diff --git a/Task/Binary-search/J/binary-search-4.j b/Task/Binary-search/J/binary-search-4.j
new file mode 100644
index 0000000000..c2bbee104e
--- /dev/null
+++ b/Task/Binary-search/J/binary-search-4.j
@@ -0,0 +1,11 @@
+'X Y L H M'=. i.5 NB. Setting mnemonics for boxes
+f=. &({::) NB. Fetching the contents of a box
+o=. @: NB. Composing verbs (functions)
+
+boxes=. a: ,~ ; NB. Appending 1 (empty) box to the inputs
+midpoint=. < o (<. o (2 %~ L f + H f)) M} ] NB. Updating the midpoint
+case=. >: o * o (Y f - M f { X f) NB. Less=0, equal=1, or greater=2
+
+recur=. (X f bs Y f ; L f ; (_1 + M f))`(M f)`(X f bs Y f ; (1 + M f) ; H f)@.case
+
+bs=. (recur o midpoint`('Not Found'"_) @. (H f < L f) o boxes) :: ([ bs ] ; 0 ; (<: o # o [))
diff --git a/Task/Binary-search/Liberty-BASIC/binary-search.liberty b/Task/Binary-search/Liberty-BASIC/binary-search.liberty
new file mode 100644
index 0000000000..a1cd3a10ce
--- /dev/null
+++ b/Task/Binary-search/Liberty-BASIC/binary-search.liberty
@@ -0,0 +1,19 @@
+dim theArray(100)
+for i = 1 to 100
+ theArray(i) = i
+next i
+
+print binarySearch(80,30,90)
+
+wait
+
+FUNCTION binarySearch(val, lo, hi)
+ IF hi < lo THEN
+ binarySearch = 0
+ ELSE
+ middle = int((hi + lo) / 2):print middle
+ if val < theArray(middle) then binarySearch = binarySearch(val, lo, middle-1)
+ if val > theArray(middle) then binarySearch = binarySearch(val, middle+1, hi)
+ if val = theArray(middle) then binarySearch = middle
+ END IF
+END FUNCTION
diff --git a/Task/Binary-search/Logo/binary-search.logo b/Task/Binary-search/Logo/binary-search.logo
new file mode 100644
index 0000000000..111197b615
--- /dev/null
+++ b/Task/Binary-search/Logo/binary-search.logo
@@ -0,0 +1,7 @@
+to bsearch :value :a :lower :upper
+ if :upper < :lower [output []]
+ localmake "mid int (:lower + :upper) / 2
+ if item :mid :a > :value [output bsearch :value :a :lower :mid-1]
+ if item :mid :a < :value [output bsearch :value :a :mid+1 :upper]
+ output :mid
+end
diff --git a/Task/Binary-search/M4/binary-search.m4 b/Task/Binary-search/M4/binary-search.m4
new file mode 100644
index 0000000000..0307132de6
--- /dev/null
+++ b/Task/Binary-search/M4/binary-search.m4
@@ -0,0 +1,10 @@
+define(`notfound',`-1')dnl
+define(`midsearch',`ifelse(defn($1[$4]),$2,$4,
+`ifelse(eval(defn($1[$4])>$2),1,`binarysearch($1,$2,$3,decr($4))',`binarysearch($1,$2,incr($4),$5)')')')dnl
+define(`binarysearch',`ifelse(eval($4<$3),1,notfound,`midsearch($1,$2,$3,eval(($3+$4)/2),$4)')')dnl
+dnl
+define(`setrange',`ifelse(`$3',`',$2,`define($1[$2],$3)`'setrange($1,incr($2),shift(shift(shift($@))))')')dnl
+define(`asize',decr(setrange(`a',1,1,3,5,7,11,13,17,19,23,29)))dnl
+dnl
+binarysearch(`a',5,1,asize)
+binarysearch(`a',8,1,asize)
diff --git a/Task/Binary-search/MAXScript/binary-search-1.max b/Task/Binary-search/MAXScript/binary-search-1.max
new file mode 100644
index 0000000000..d6f0642326
--- /dev/null
+++ b/Task/Binary-search/MAXScript/binary-search-1.max
@@ -0,0 +1,25 @@
+fn binarySearchIterative arr value =
+(
+ lower = 1
+ upper = arr.count
+ while lower <= upper do
+ (
+ mid = (lower + upper) / 2
+ if arr[mid] > value then
+ (
+ upper = mid - 1
+ )
+ else if arr[mid] < value then
+ (
+ lower = mid + 1
+ )
+ else
+ (
+ return mid
+ )
+ )
+ -1
+)
+
+arr = #(1, 3, 4, 5, 6, 7, 8, 9, 10)
+result = binarySearchIterative arr 6
diff --git a/Task/Binary-search/MAXScript/binary-search-2.max b/Task/Binary-search/MAXScript/binary-search-2.max
new file mode 100644
index 0000000000..26bcdb630a
--- /dev/null
+++ b/Task/Binary-search/MAXScript/binary-search-2.max
@@ -0,0 +1,30 @@
+fn binarySearchRecursive arr value lower upper =
+(
+ if lower == upper then
+ (
+ if arr[lower] == value then
+ (
+ return lower
+ )
+ else
+ (
+ return -1
+ )
+ )
+ mid = (lower + upper) / 2
+ if arr[mid] > value then
+ (
+ return binarySearchRecursive arr value lower (mid-1)
+ )
+ else if arr[mid] < value then
+ (
+ return binarySearchRecursive arr value (mid+1) upper
+ )
+ else
+ (
+ return mid
+ )
+)
+
+arr = #(1, 3, 4, 5, 6, 7, 8, 9, 10)
+result = binarySearchRecursive arr 6 1 arr.count
diff --git a/Task/Binary-search/Maple/binary-search-1.maple b/Task/Binary-search/Maple/binary-search-1.maple
new file mode 100644
index 0000000000..047901a3ad
--- /dev/null
+++ b/Task/Binary-search/Maple/binary-search-1.maple
@@ -0,0 +1,15 @@
+BinarySearch := proc( A, value, low, high )
+ description "recursive binary search";
+ if high < low then
+ FAIL
+ else
+ local mid := iquo( high + low, 2 );
+ if A[ mid ] > value then
+ thisproc( A, value, low, mid - 1 )
+ elif A[ mid ] < value then
+ thisproc( A, value, mid + 1, high )
+ else
+ mid
+ end if
+ end if
+end proc:
diff --git a/Task/Binary-search/Maple/binary-search-2.maple b/Task/Binary-search/Maple/binary-search-2.maple
new file mode 100644
index 0000000000..a58eb8ecf1
--- /dev/null
+++ b/Task/Binary-search/Maple/binary-search-2.maple
@@ -0,0 +1,17 @@
+BinarySearch := proc( A, value )
+ description "iterative binary search";
+ local low, high;
+
+ low, high := ( lowerbound, upperbound )( A );
+ while low <= high do
+ local mid := iquo( low + high, 2 );
+ if A[ mid ] > value then
+ high := mid - 1
+ elif A[ mid ] < value then
+ low := mid + 1
+ else
+ return mid
+ end if
+ end do;
+ FAIL
+end proc:
diff --git a/Task/Binary-search/Maple/binary-search-3.maple b/Task/Binary-search/Maple/binary-search-3.maple
new file mode 100644
index 0000000000..58927c806f
--- /dev/null
+++ b/Task/Binary-search/Maple/binary-search-3.maple
@@ -0,0 +1,17 @@
+> N := 10:
+> P := [seq]( ithprime( i ), i = 1 .. N ):
+> BinarySearch( P, 12, 1, N ); # recursive version
+ FAIL
+
+> BinarySearch( P, 13, 1, N ); # recursive version
+ 6
+
+> BinarySearch( Array( P ), 13, 1, N ); # make P into an array
+ 6
+
+> PP := Array( -2 .. 7, P ): # check it works if the array is not 1-based.
+> BinarySearch( PP, 13 ); # iterative version
+ 3
+
+> PP[ 3 ];
+ 13
diff --git a/Task/Binary-search/Mathematica/binary-search-1.mathematica b/Task/Binary-search/Mathematica/binary-search-1.mathematica
new file mode 100644
index 0000000000..cbe24b4be1
--- /dev/null
+++ b/Task/Binary-search/Mathematica/binary-search-1.mathematica
@@ -0,0 +1,9 @@
+BinarySearchRecursive[x_List, val_, lo_, hi_] :=
+ Module[{mid = lo + Round@((hi - lo)/2)},
+ If[hi < lo, Return[-1]];
+ Return[
+ Which[x[[mid]] > val, BinarySearchRecursive[x, val, lo, mid - 1],
+ x[[mid]] < val, BinarySearchRecursive[x, val, mid + 1, hi],
+ True, mid]
+ ];
+ ]
diff --git a/Task/Binary-search/Mathematica/binary-search-2.mathematica b/Task/Binary-search/Mathematica/binary-search-2.mathematica
new file mode 100644
index 0000000000..a702abb515
--- /dev/null
+++ b/Task/Binary-search/Mathematica/binary-search-2.mathematica
@@ -0,0 +1,10 @@
+BinarySearch[x_List, val_] := Module[{lo = 1, hi = Length@x, mid},
+ While[lo <= hi,
+ mid = lo + Round@((hi - lo)/2);
+ Which[x[[mid]] > val, hi = mid - 1,
+ x[[mid]] < val, lo = mid + 1,
+ True, Return[mid]
+ ];
+ ];
+ Return[-1];
+ ]
diff --git a/Task/Binary-search/Maxima/binary-search.maxima b/Task/Binary-search/Maxima/binary-search.maxima
new file mode 100644
index 0000000000..5077c0b4ff
--- /dev/null
+++ b/Task/Binary-search/Maxima/binary-search.maxima
@@ -0,0 +1,20 @@
+find(L, n) := block([i: 1, j: length(L), k, p],
+ if n < L[i] or n > L[j] then 0 else (
+ while j - i > 0 do (
+ k: quotient(i + j, 2),
+ p: L[k],
+ if n < p then j: k - 1 elseif n > p then i: k + 1 else i: j: k
+ ),
+ if n = L[i] then i else 0
+ )
+)$
+
+".."(a, b) := if a < b then makelist(i, i, a, b) else makelist(i, i, a, b, -1)$
+infix("..")$
+
+a: sublist(1 .. 1000, primep)$
+
+find(a, 27);
+0
+find(a, 421);
+82
diff --git a/Task/Binary-strings/Factor/binary-strings-1.factor b/Task/Binary-strings/Factor/binary-strings-1.factor
new file mode 100644
index 0000000000..feb1923c98
--- /dev/null
+++ b/Task/Binary-strings/Factor/binary-strings-1.factor
@@ -0,0 +1 @@
+"Hello, byte-array!" utf8 encode .
diff --git a/Task/Binary-strings/Factor/binary-strings-2.factor b/Task/Binary-strings/Factor/binary-strings-2.factor
new file mode 100644
index 0000000000..4710103e11
--- /dev/null
+++ b/Task/Binary-strings/Factor/binary-strings-2.factor
@@ -0,0 +1 @@
+B{ 147 250 150 123 } shift-jis decode .
diff --git a/Task/Binary-strings/Icon/binary-strings-1.icon b/Task/Binary-strings/Icon/binary-strings-1.icon
new file mode 100644
index 0000000000..a7df2a4e61
--- /dev/null
+++ b/Task/Binary-strings/Icon/binary-strings-1.icon
@@ -0,0 +1,14 @@
+s := "\x00" # strings can contain any value, even nulls
+s := "abc" # create a string
+s := &null # destroy a string (well sbsnfon it for garbage collection)
+v := s # assignment
+s == t # expression s equals t
+s << t # expression s less than t
+s <<= t # expression s less than or equal to t
+v := s # strings are immutable, no copying or cloning are needed
+s == "" # equal empty string
+*s = 0 # string length is zero
+s ||:= "a" # append a byte "a" to s via concatenation
+t := s[2+:3] # t is set to position 2 for 3 characters
+s := replace(s,s2,s3) # IPL replace function
+s := s1 || s2 # concatenation (joining) of strings
diff --git a/Task/Binary-strings/Icon/binary-strings-2.icon b/Task/Binary-strings/Icon/binary-strings-2.icon
new file mode 100644
index 0000000000..e3febbd622
--- /dev/null
+++ b/Task/Binary-strings/Icon/binary-strings-2.icon
@@ -0,0 +1,16 @@
+procedure replace(s1, s2, s3) #: string replacement
+ local result, i
+
+ result := ""
+ i := *s2
+ if i = 0 then fail # would loop on empty string
+
+ s1 ? {
+ while result ||:= tab(find(s2)) do {
+ result ||:= s3
+ move(i)
+ }
+ return result || tab(0)
+ }
+
+end
diff --git a/Task/Binary-strings/J/binary-strings-1.j b/Task/Binary-strings/J/binary-strings-1.j
new file mode 100644
index 0000000000..2cf9eff1ad
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-1.j
@@ -0,0 +1 @@
+ name=: ''
diff --git a/Task/Binary-strings/J/binary-strings-10.j b/Task/Binary-strings/J/binary-strings-10.j
new file mode 100644
index 0000000000..920fe6ff0c
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-10.j
@@ -0,0 +1 @@
+ 'string1','string2'
diff --git a/Task/Binary-strings/J/binary-strings-11.j b/Task/Binary-strings/J/binary-strings-11.j
new file mode 100644
index 0000000000..ebb4d15b6b
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-11.j
@@ -0,0 +1 @@
+ n{a.
diff --git a/Task/Binary-strings/J/binary-strings-12.j b/Task/Binary-strings/J/binary-strings-12.j
new file mode 100644
index 0000000000..17de57e58c
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-12.j
@@ -0,0 +1 @@
+1 0 255{a.
diff --git a/Task/Binary-strings/J/binary-strings-2.j b/Task/Binary-strings/J/binary-strings-2.j
new file mode 100644
index 0000000000..0b409b1194
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-2.j
@@ -0,0 +1 @@
+ name=: 0
diff --git a/Task/Binary-strings/J/binary-strings-3.j b/Task/Binary-strings/J/binary-strings-3.j
new file mode 100644
index 0000000000..64a963be69
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-3.j
@@ -0,0 +1 @@
+ name=: 'value'
diff --git a/Task/Binary-strings/J/binary-strings-4.j b/Task/Binary-strings/J/binary-strings-4.j
new file mode 100644
index 0000000000..09c0411dd0
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-4.j
@@ -0,0 +1 @@
+ name1 -: name2
diff --git a/Task/Binary-strings/J/binary-strings-5.j b/Task/Binary-strings/J/binary-strings-5.j
new file mode 100644
index 0000000000..1f067bf642
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-5.j
@@ -0,0 +1,2 @@
+ name1= 'example'
+ name2= name1
diff --git a/Task/Binary-strings/J/binary-strings-6.j b/Task/Binary-strings/J/binary-strings-6.j
new file mode 100644
index 0000000000..d505f8f30c
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-6.j
@@ -0,0 +1 @@
+ 0=#string
diff --git a/Task/Binary-strings/J/binary-strings-7.j b/Task/Binary-strings/J/binary-strings-7.j
new file mode 100644
index 0000000000..bdf506b37c
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-7.j
@@ -0,0 +1,3 @@
+ string=: 'example'
+ byte=: DEL
+ string=: string,byte
diff --git a/Task/Binary-strings/J/binary-strings-8.j b/Task/Binary-strings/J/binary-strings-8.j
new file mode 100644
index 0000000000..2d96c64e7d
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-8.j
@@ -0,0 +1 @@
+ 3{.5}.'The quick brown fox runs...'
diff --git a/Task/Binary-strings/J/binary-strings-9.j b/Task/Binary-strings/J/binary-strings-9.j
new file mode 100644
index 0000000000..fcb5c7ec59
--- /dev/null
+++ b/Task/Binary-strings/J/binary-strings-9.j
@@ -0,0 +1,2 @@
+require 'strings'
+'The quick brown fox runs...' rplc ' ';' !!! '
diff --git a/Task/Binary-strings/Liberty-BASIC/binary-strings.liberty b/Task/Binary-strings/Liberty-BASIC/binary-strings.liberty
new file mode 100644
index 0000000000..9973ad7efb
--- /dev/null
+++ b/Task/Binary-strings/Liberty-BASIC/binary-strings.liberty
@@ -0,0 +1,33 @@
+'string creation
+s$ = "Hello, world!"
+
+'string destruction - not needed because of garbage collection
+s$ = ""
+
+'string comparison
+s$ = "Hello, world!"
+If s$ = "Hello, world!" then print "Equal Strings"
+
+'string copying
+a$ = s$
+
+'check If empty
+If s$ = "" then print "Empty String"
+
+'append a byte
+s$ = s$ + Chr$(33)
+
+'extract a substring
+a$ = Mid$(s$, 1, 5)
+
+'replace bytes
+a$ = "Hello, world!"
+for i = 1 to len(a$)
+ if mid$(a$,i,1)="l" then
+ a$=left$(a$,i-1)+"L"+mid$(a$,i+1)
+ end if
+next
+print a$
+
+'join strings
+s$ = "Good" + "bye" + " for now."
diff --git a/Task/Binary-strings/Mathematica/binary-strings.mathematica b/Task/Binary-strings/Mathematica/binary-strings.mathematica
new file mode 100644
index 0000000000..9f39cf71f6
--- /dev/null
+++ b/Task/Binary-strings/Mathematica/binary-strings.mathematica
@@ -0,0 +1,19 @@
+(* String creation and destruction *) BinaryString = {}; BinaryString = . ;
+(* String assignment *) BinaryString1 = {12,56,82,65} , BinaryString2 = {83,12,56,65}
+-> {12,56,82,65}
+-> {83,12,56,65}
+(* String comparison *) BinaryString1 === BinaryString2
+-> False
+(* String cloning and copying *) BinaryString3 = BinaryString1
+-> {12,56,82,65}
+(* Check if a string is empty *) BinaryString3 === {}
+-> False
+(* Append a byte to a string *) AppendTo[BinaryString3, 22]
+-> {12,56,82,65,22}
+(* Extract a substring from a string *) Take[BinaryString3, {2, 5}]
+-> {56,82,65,22}
+(* Replace every occurrence of a byte (or a string) in a string with another string *)
+BinaryString3 /. {22 -> Sequence[33, 44]}
+-> {12,56,82,65,33,44}
+(* Join strings *) BinaryString4 = Join[BinaryString1 , BinaryString2]
+-> {12,56,82,65,83,12,56,65}
diff --git a/Task/Bitmap-B-zier-curves-Cubic/Factor/bitmap-b-zier-curves-cubic.factor b/Task/Bitmap-B-zier-curves-Cubic/Factor/bitmap-b-zier-curves-cubic.factor
new file mode 100644
index 0000000000..f44ccbcfe4
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/Factor/bitmap-b-zier-curves-cubic.factor
@@ -0,0 +1,25 @@
+USING: arrays kernel locals math math.functions
+ rosettacode.raster.storage sequences ;
+IN: rosettacode.raster.line
+
+! this gives a function
+:: (cubic-bezier) ( P0 P1 P2 P3 -- bezier )
+ [ :> x
+ 1 x - 3 ^ P0 n*v
+ 1 x - sq 3 * x * P1 n*v
+ 1 x - 3 * x sq * P2 n*v
+ x 3 ^ P3 n*v
+ v+ v+ v+ ] ; inline
+! gives an interval of x from 0 to 1 to map the bezier function
+: t-interval ( x -- interval )
+ [ iota ] keep 1 - [ / ] curry map ;
+! turns a list of points into the list of lines between them
+: points-to-lines ( seq -- seq )
+ dup rest [ 2array ] 2map ;
+: draw-lines ( {R,G,B} points image -- )
+ [ [ first2 ] dip draw-line ] curry with each ;
+:: bezier-lines ( {R,G,B} P0 P1 P2 P3 image -- )
+ ! 100 is an arbitrary value.. could be given as a parameter..
+ 100 t-interval P0 P1 P2 P3 (cubic-bezier) map
+ points-to-lines
+ {R,G,B} swap image draw-lines ;
diff --git a/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-1.j b/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-1.j
new file mode 100644
index 0000000000..05e51d8ae5
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-1.j
@@ -0,0 +1,21 @@
+require 'numeric'
+
+bik=: 2 : '((*&(u!v))@(^&u * ^&(v-u)@-.))'
+basiscoeffs=: <: 4 : 'x bik y t. i.>:y'"0~ i.
+linearcomb=: basiscoeffs@#@[
+evalBernstein=: ([ +/ .* linearcomb) p. ] NB. evaluate Bernstein Polynomial (general)
+
+NB.*getBezierPoints v Returns points for bezier curve given control points (y)
+NB. eg: getBezierPoints controlpoints
+NB. y is: y0 x0, y1 x1, y2 x2 ...
+getBezierPoints=: monad define
+ ctrlpts=. (/: {:"1) _2]\ y NB. sort ctrlpts for increasing x
+ xvals=. ({: ,~ {. + +:@:i.@<.@-:@-~/) ({:"1) 0 _1{ctrlpts
+ tvals=. ((] - {.) % ({: - {.)) xvals
+ xvals ,.~ ({."1 ctrlpts) evalBernstein tvals
+)
+
+NB.*drawBezier v Draws bezier curve defined by (x) on image (y)
+NB. eg: (42 40 10 30 186 269 26 187;255 0 0) drawBezier myimg
+NB. x is: 2-item list of boxed (controlpoints) ; (color)
+drawBezier=: (1&{:: ;~ 2 ]\ [: roundint@getBezierPoints"1 (0&{::))@[ drawLines ]
diff --git a/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-2.j b/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-2.j
new file mode 100644
index 0000000000..96673198c7
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/J/bitmap-b-zier-curves-cubic-2.j
@@ -0,0 +1,5 @@
+myimg=: 0 0 255 makeRGB 300 300
+]randomctrlpts=: ,3 2 ?@$ }:$ myimg NB. 3 control points - quadratic
+]randomctrlpts=: ,4 2 ?@$ }:$ myimg NB. 4 control points - cubic
+myimg=: ((2 ,.~ _2]\randomctrlpts);255 0 255) drawCircles myimg NB. draw control points
+viewRGB (randomctrlpts; 255 255 0) drawBezier myimg NB. display image with bezier line
diff --git a/Task/Bitmap-B-zier-curves-Cubic/Mathematica/bitmap-b-zier-curves-cubic.mathematica b/Task/Bitmap-B-zier-curves-Cubic/Mathematica/bitmap-b-zier-curves-cubic.mathematica
new file mode 100644
index 0000000000..f3e76dbb45
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/Mathematica/bitmap-b-zier-curves-cubic.mathematica
@@ -0,0 +1,2 @@
+points= {{0, 0}, {1, 1}, {2, -1}, {3, 0}};
+Graphics[{BSplineCurve[points], Green, Line[points], Red, Point[points]}]
diff --git a/Task/Bitmap-B-zier-curves-Quadratic/Factor/bitmap-b-zier-curves-quadratic.factor b/Task/Bitmap-B-zier-curves-Quadratic/Factor/bitmap-b-zier-curves-quadratic.factor
new file mode 100644
index 0000000000..ed75352884
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Quadratic/Factor/bitmap-b-zier-curves-quadratic.factor
@@ -0,0 +1,23 @@
+USING: arrays kernel locals math math.functions
+ rosettacode.raster.storage sequences ;
+IN: rosettacode.raster.line
+
+! This gives a function
+:: (quadratic-bezier) ( P0 P1 P2 -- bezier )
+ [ :> x
+ 1 x - sq P0 n*v
+ 2 1 x - x * * P1 n*v
+ x sq P2 n*v
+ v+ v+ ] ; inline
+
+! Same code from the cubic bezier task
+: t-interval ( x -- interval )
+ [ iota ] keep 1 - [ / ] curry map ;
+: points-to-lines ( seq -- seq )
+ dup rest [ 2array ] 2map ;
+: draw-lines ( {R,G,B} points image -- )
+ [ [ first2 ] dip draw-line ] curry with each ;
+:: bezier-lines ( {R,G,B} P0 P1 P2 image -- )
+ 100 t-interval P0 P1 P2 (quadratic-bezier) map
+ points-to-lines
+ {R,G,B} swap image draw-lines ;
diff --git a/Task/Bitmap-B-zier-curves-Quadratic/Mathematica/bitmap-b-zier-curves-quadratic.mathematica b/Task/Bitmap-B-zier-curves-Quadratic/Mathematica/bitmap-b-zier-curves-quadratic.mathematica
new file mode 100644
index 0000000000..7561cfebf6
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Quadratic/Mathematica/bitmap-b-zier-curves-quadratic.mathematica
@@ -0,0 +1,2 @@
+pts = {{0, 0}, {1, -1}, {2, 1}};
+Graphics[{BSplineCurve[pts], Green, Line[pts], Red, Point[pts]}]
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Factor/bitmap-bresenhams-line-algorithm.factor b/Task/Bitmap-Bresenhams-line-algorithm/Factor/bitmap-bresenhams-line-algorithm.factor
new file mode 100644
index 0000000000..86c977fefc
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Factor/bitmap-bresenhams-line-algorithm.factor
@@ -0,0 +1,37 @@
+USING: accessors arrays kernel locals math math.functions
+math.ranges math.vectors rosettacode.raster.display
+rosettacode.raster.storage sequences ui.gadgets ;
+IN: rosettacode.raster.line
+
+:: line-points ( pt1 pt2 -- points )
+ pt1 first2 :> y0! :> x0!
+ pt2 first2 :> y1! :> x1!
+ y1 y0 - abs x1 x0 - abs > :> steep
+ steep [
+ y0 x0 y0! x0!
+ y1 x1 y1! x1!
+ ] when
+ x0 x1 > [
+ x0 x1 x0! x1!
+ y0 y1 y0! y1!
+ ] when
+ x1 x0 - :> deltax
+ y1 y0 - abs :> deltay
+ 0 :> current-error!
+ deltay deltax / abs :> deltaerr
+ 0 :> ystep!
+ y0 :> y!
+ y0 y1 < [ 1 ystep! ] [ -1 ystep! ] if
+ x0 x1 1 [
+ y steep [ swap ] when 2array
+ current-error deltaerr + current-error!
+ current-error 0.5 >= [
+ ystep y + y!
+ current-error 1 - current-error!
+ ] when
+ ] { } map-as ;
+
+! Needs rosettacode.raster.storage for the set-pixel function and to create the image
+: draw-line ( {R,G,B} pt1 pt2 image -- )
+ [ line-points ] dip
+ [ set-pixel ] curry with each ;
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-1.j b/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-1.j
new file mode 100644
index 0000000000..cac6b93173
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-1.j
@@ -0,0 +1,16 @@
+thru=: <./ + -~ i.@+ _1 ^ > NB. integers from x through y
+
+NB.*getBresenhamLine v Returns points for a line given start and end points
+NB. y is: y0 x0 ,: y1 x1
+getBresenhamLine=: monad define
+ steep=. ([: |@-~/) y
+ points=. |."1^:steep y
+ slope=. %~/ -~/ points
+ ypts=. thru/ {."1 points
+ xpts=. ({: + 0.5 <.@:+ slope * ypts - {.) {.points
+ |."1^:steep ypts,.xpts
+)
+
+NB.*drawLines v Draws lines (x) on image (y)
+NB. x is: 2-item list (start and end points) ; (color)
+drawLines=: (1&{:: ;~ [: ; [: <@getBresenhamLine"2 (0&{::))@[ setPixels ]
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-2.j b/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-2.j
new file mode 100644
index 0000000000..3f469c1c25
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/J/bitmap-bresenhams-line-algorithm-2.j
@@ -0,0 +1,9 @@
+ myimg=: 0 255 0 makeRGB 20 32 NB. 32 by 20 green image
+ myimg=: ((1 1 ,: 5 11) ; 255 0 0 ) drawLines myimg NB. draw red line from xy point 1 1 to 11 5
+
+NB. Works for lists of 2 by 2 arrays each defining a line's start and end point.
+ Diamond=: _2]\ _2]\ 9 5 5 15 , 5 15 9 25 , 9 25 13 15 , 13 15 9 5
+ Square =: _2]\ _2]\ 5 5 5 25 , 5 25 13 25 , 13 25 13 5 , 13 5 5 5
+ viewRGB myimg=: (Diamond;255 0 0) drawLines myimg NB. draw 4 red lines to form a diamond
+ viewRGB myimg=: (Square;0 0 255) drawLines myimg NB. draw 4 blue lines to form a square
+ viewRGB (Diamond;255 0 0) drawLines (Square;0 0 255) drawLines myimg
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/MAXScript/bitmap-bresenhams-line-algorithm.max b/Task/Bitmap-Bresenhams-line-algorithm/MAXScript/bitmap-bresenhams-line-algorithm.max
new file mode 100644
index 0000000000..9be76aa763
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/MAXScript/bitmap-bresenhams-line-algorithm.max
@@ -0,0 +1,52 @@
+fn plot img coord steep col =
+(
+ if steep then
+ (
+ swap coord[1] coord[2]
+ )
+ setPixels img coord col
+)
+
+fn drawLine img start end col =
+(
+ local steep = (abs (end.y - start.y)) > (abs (end.x - start.x))
+
+ if steep then
+ (
+ swap start.x start.y
+ swap end.x end.y
+ )
+
+ if start.x > end.x then
+ (
+ swap start.x end.x
+ swap start.y end.y
+ )
+
+ local deltaX = end.x - start.x
+ local deltaY = abs (end.y - start.y)
+ local error = deltaX / 2.0
+ local yStep = -1
+ local y = start.y
+
+ if start.y < end.y then
+ (
+ yStep = 1
+ )
+
+ for x in start.x to end.x do
+ (
+ plot img [x, y] steep col
+ error -= deltaY
+ if error < 0 then
+ (
+ y += yStep
+ error += deltaX
+ )
+ )
+ img
+)
+
+myBitmap = bitmap 512 512 color:(color 0 0 0)
+myBitmap = drawLine myBitmap [0, 511] [511, 0] #((color 255 255 255))
+display myBitmap
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Maple/bitmap-bresenhams-line-algorithm.maple b/Task/Bitmap-Bresenhams-line-algorithm/Maple/bitmap-bresenhams-line-algorithm.maple
new file mode 100644
index 0000000000..0dd7c22112
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Maple/bitmap-bresenhams-line-algorithm.maple
@@ -0,0 +1,36 @@
+SegmentBresenham := proc (img, x0, y0, x1, y1)
+ local deltax, deltay, x, y, ystep, steep, err, img2, x02, y02, x12, y12;
+ x02, x12, y02, y12 := y0, y1, x0, x1;
+ steep := abs(x12 - x02) < abs(y12 - y02);
+ img2 := copy(img);
+ if steep then
+ x02, y02 := y02, x02;
+ x12, y12 := y12, x12;
+ end if;
+ if x12 < x02 then
+ x02, x12 := x12, x02;
+ y02, y12 := y12, y02;
+ end if;
+ deltax := x12 - x02;
+ deltay := abs(y12 - y02);
+ err := deltax / 2;
+ y := y02;
+ if y02 < y12 then
+ ystep := 1
+ else
+ ystep := -1
+ end if;
+ for x from x02 to x12 do
+ if steep then
+ img2[y, x] := 0
+ else
+ img2[x, y] := 0
+ end if;
+ err := err - deltay;
+ if err < 0 then
+ y := y + ystep;
+ err := err + deltax
+ end if;
+ end do;
+ return img2;
+end proc:
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Mathematica/bitmap-bresenhams-line-algorithm.mathematica b/Task/Bitmap-Bresenhams-line-algorithm/Mathematica/bitmap-bresenhams-line-algorithm.mathematica
new file mode 100644
index 0000000000..45acb3c039
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Mathematica/bitmap-bresenhams-line-algorithm.mathematica
@@ -0,0 +1 @@
+Rasterize[ Style[Graphics[Line[{{0, 0}, {20, 10}}]], Antialiasing -> False]]
diff --git a/Task/Bitmap-Flood-fill/HicEst/bitmap-flood-fill.hicest b/Task/Bitmap-Flood-fill/HicEst/bitmap-flood-fill.hicest
new file mode 100644
index 0000000000..ebe5b537be
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/HicEst/bitmap-flood-fill.hicest
@@ -0,0 +1,8 @@
+WINDOW(WINdowhandle=wh, BaCkcolor=0, TItle="Rosetta test image")
+
+WRITE(WIN=wh, DeCoRation="EL=14, BC=14") ! color 14 == bright yellow
+
+RGB(128, 100, 0, 25) ! define color nr 25 as 128/255 red, 100/255 green, 0 blue
+WRITE(WIN=wh, DeCoRation="L=1/4, R=1/2, T=1/4, B=1/2, EL=25, BC=25")
+
+WINDOW(Kill=wh)
diff --git a/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-1.j b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-1.j
new file mode 100644
index 0000000000..59463165bd
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-1.j
@@ -0,0 +1,10 @@
+NB. finds and labels contiguous areas with the same numbers
+NB. ref: http://www.jsoftware.com/pipermail/general/2005-August/023886.html
+findcontig=: (|."1@|:@:>. (* * 1&(|.!.0)))^:4^:_@(* >:@i.@$)
+
+NB.*getFloodpoints v Returns points to fill given starting point (x) and image (y)
+getFloodpoints=: [: 4&$.@$. [ (] = getPixels) [: findcontig ] -:"1 getPixels
+
+NB.*floodFill v Floods area, defined by point and color (x), of image (y)
+NB. x is: 2-item list of (y x) ; (color)
+floodFill=: (1&({::)@[ ;~ 0&({::)@[ getFloodpoints ]) setPixels ]
diff --git a/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-2.j b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-2.j
new file mode 100644
index 0000000000..cfb69c60d0
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-2.j
@@ -0,0 +1,9 @@
+'white blue yellow black orange red'=: 255 255 255,0 0 255,255 255 0,0 0 0,255 165 0,:255 0 0
+myimg=: white makeRGB 50 70
+lines=: (_2]\^:2) 0 0 25 0 , 25 0 25 35 , 25 35 0 35 , 0 35 0 0
+myimg=: (lines;blue) drawLines myimg
+myimg=: (3 3; yellow) floodFill myimg
+myimg=: ((35 25 24 ,: 35 25 10);black) drawCircles myimg
+myimg=: (5 34;orange) floodFill myimg
+myimg=: (5 36;red) floodFill myimg
+viewRGB myimg
diff --git a/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-3.j b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-3.j
new file mode 100644
index 0000000000..8cbbfbfc4b
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/J/bitmap-flood-fill-3.j
@@ -0,0 +1,7 @@
+NB. ref: http://www.jsoftware.com/pipermail/general/2005-August/024174.html
+eq=:[:}:"1 [:($$[:([:+/\1:,}:~:}.),) ,&_"1 NB. equal numbers for atoms of y connected in first direction
+eq_nd=: i.@#@$(<"0@[([:, |:^:_1"0 _)&> [:EQ&.> <@|:"0 _)] NB. n-dimensional eq, gives an #@$,*/@$ shaped matrix
+repl=: (i.~{.){ {:@] NB. replaces x by applying replace table y
+cnnct=: [: |:@({."1<.//.]) [: ; <@(,.<./)/.~
+
+findcontig_nd=: 3 : '($y)${. ([:({.,~}:) ([ repl cnnct)/\.)^:([:+./@(~:/)2&{.)^:_ (,{.) eq_nd (i.~ ~.@,) y'
diff --git a/Task/Bitmap-Flood-fill/Liberty-BASIC/bitmap-flood-fill.liberty b/Task/Bitmap-Flood-fill/Liberty-BASIC/bitmap-flood-fill.liberty
new file mode 100644
index 0000000000..f6d7a41dcb
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/Liberty-BASIC/bitmap-flood-fill.liberty
@@ -0,0 +1,89 @@
+'This example requires the Windows API
+NoMainWin
+WindowWidth = 267.5
+WindowHeight = 292.5
+UpperLeftX=int((DisplayWidth-WindowWidth)/2)
+UpperLeftY=int((DisplayHeight-WindowHeight)/2)
+
+Global hDC : hDC = GetDC(0)
+Struct point, x As long, y As long
+Struct RGB, Red As long, Green As long, Blue As long
+Struct rect, left As long, top As long, right As long, bottom As long
+
+StyleBits #main.gbox, 0, _WS_BORDER, 0, 0
+GraphicBox #main.gbox, 2.5, 2.5, 253, 252
+
+Open "Flood Fill - Click a Color" For Window As #main
+Print #main, "TrapClose quit"
+Print #main.gbox, "Down; Fill Black; Place 125 125; BackColor White; " _
+ + "CircleFilled 115; Place 105 105; BackColor Black; CircleFilled 50; Flush"
+Print #main.gbox, "When leftButtonUp gBoxClick"
+Print #main.gbox, "Size 1"
+Wait
+
+ Sub quit handle$
+ Call ReleaseDC 0, hDC
+ Close #main
+ End
+ End Sub
+
+
+ Sub gBoxClick handle$, MouseX, MouseY
+ result = GetCursorPos()
+ targetRGB = GetPixel(hDC, point.x.struct, point.y.struct)
+ ColorDialog "", replacementColor$
+ If replacementColor$ = "" Then Exit Sub
+ Print #main.gbox, "Color " + Word$(replacementColor$, 1) + " " + Word$(replacementColor$, 2) + " " + Word$(replacementColor$, 3)
+ result = FloodFill(MouseX, MouseY, targetRGB)
+ Print #main.gbox, "DelSegment FloodFill"
+ Print #main.gbox, "GetBMP FloodFill 0 0 500 500; CLS; DrawBMP FloodFill 0 0; Flush FloodFill"
+ Notice "Complete!"
+ UnLoadBMP "FloodFill"
+ End Sub
+
+ Sub ReleaseDC hWnd, hDC
+ CallDLL #user32,"ReleaseDC", hWnd As uLong, hDC As uLong, ret As Long
+ End Sub
+
+ Function GetDC(hWnd)
+ CallDLL #user32, "GetDC", hWnd As uLong, GetDC As uLong
+ End Function
+
+ Function GetCursorPos()
+ CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong
+ End Function
+
+ Function GetPixel(hDC, x, y)
+ CallDLL #gdi32, "GetPixel", hDC As uLong, x As long, y As long, GetPixel As long
+ End Function
+
+ Function getLongRGB(RGB.Blue)
+ getLongRGB = (RGB.Blue * (256 * 256))
+ End Function
+
+ Function GetWindowRect(hWnd)
+ 'Get ClientRectangle
+ CallDLL #user32, "GetWindowRect", hWnd As ulong, rect As struct, GetWindowRect As ulong
+ End Function
+
+ Function FloodFill(mouseXX, mouseYY, targetColor)
+ Scan
+ result = GetWindowRect(Hwnd(#main.gbox))
+ X = Int(mouseXX + rect.left.struct)
+ Y = Int(mouseYY + rect.top.struct)
+ If (GetPixel(hDC, X, Y) <> targetColor) Then
+ Exit Function
+ Else
+ CLS
+ Print str$(mouseXX) + " " + str$(mouseYY)
+ Print #main.gbox, "Set " + str$(mouseXX) + " " + str$(mouseYY)
+ End If
+ If (mouseXX > 0) And (mouseXX < 253) Then
+ result = FloodFill((mouseXX - 1), mouseYY, targetColor)
+ result = FloodFill((mouseXX + 1), mouseYY, targetColor)
+ End If
+ If (mouseYY > 0) And (mouseYY < 252) Then
+ result = FloodFill(mouseXX, (mouseYY + 1), targetColor)
+ result = FloodFill(mouseXX, (mouseYY - 1), targetColor)
+ End If
+ End Function
diff --git a/Task/Bitmap-Flood-fill/Mathematica/bitmap-flood-fill.mathematica b/Task/Bitmap-Flood-fill/Mathematica/bitmap-flood-fill.mathematica
new file mode 100644
index 0000000000..3d57098663
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/Mathematica/bitmap-flood-fill.mathematica
@@ -0,0 +1,9 @@
+createMask[img_, pos_, tol_] :=
+ RegionBinarize[img, Image[SparseArray[pos -> 1, ImageDimensions[img]]], tol];
+floodFill[img_Image, pos_List, tol_Real, color_List] :=
+ ImageCompose[
+ SetAlphaChannel[ImageSubtract[img, createMask[img, pos, tol]], 1],
+ SetAlphaChannel[Image[ConstantArray[color, ImageDimensions[img]]],
+ Dilation[createMask[img, pos, tol],1]
+ ]
+ ]
diff --git a/Task/Bitmap-Histogram/J/bitmap-histogram-1.j b/Task/Bitmap-Histogram/J/bitmap-histogram-1.j
new file mode 100644
index 0000000000..da86fc76a0
--- /dev/null
+++ b/Task/Bitmap-Histogram/J/bitmap-histogram-1.j
@@ -0,0 +1,3 @@
+getImgHist=: ([: /:~ ~. ,. #/.~)@,
+medianHist=: {."1 {~ [: (+/\ I. -:@(+/)) {:"1
+toBW=: 255 * medianHist@getImgHist < toGray
diff --git a/Task/Bitmap-Histogram/J/bitmap-histogram-2.j b/Task/Bitmap-Histogram/J/bitmap-histogram-2.j
new file mode 100644
index 0000000000..43df88cc6e
--- /dev/null
+++ b/Task/Bitmap-Histogram/J/bitmap-histogram-2.j
@@ -0,0 +1,3 @@
+ require 'media/platimg'
+ 'Lenna100.ppm' writeppm~ 256#.inv readimg 'Lenna100.jpg'
+786447
diff --git a/Task/Bitmap-Histogram/J/bitmap-histogram-3.j b/Task/Bitmap-Histogram/J/bitmap-histogram-3.j
new file mode 100644
index 0000000000..09ddcff031
--- /dev/null
+++ b/Task/Bitmap-Histogram/J/bitmap-histogram-3.j
@@ -0,0 +1,2 @@
+ 'Lenna100BW.ppm' writeppm~ toColor toBW readppm 'Lenna100.ppm'
+786447
diff --git a/Task/Bitmap-Histogram/Mathematica/bitmap-histogram.mathematica b/Task/Bitmap-Histogram/Mathematica/bitmap-histogram.mathematica
new file mode 100644
index 0000000000..174d9757ec
--- /dev/null
+++ b/Task/Bitmap-Histogram/Mathematica/bitmap-histogram.mathematica
@@ -0,0 +1 @@
+ImageLevels[img];
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-1.j b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-1.j
new file mode 100644
index 0000000000..561b38974b
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-1.j
@@ -0,0 +1,24 @@
+NB.*getBresenhamCircle v Returns points for a circle given center and radius
+NB. y is: y0 x0 radius
+getBresenhamCircle=: monad define
+ 'y0 x0 radius'=. y
+ x=. 0
+ y=. radius
+ f=. -. radius
+ pts=. 0 2$0
+ while. x <: y do.
+ pts=. pts , y , x
+ if. f >: 0 do.
+ y=. <:y
+ f=. f + _2 * y
+ end.
+ x=. >:x
+ f =. f + >: 2 * x
+ end.
+ offsets=. (,|."1) (1 _1 {~ #: i.4) *"1"1 _ pts
+ ~.,/ (y0,x0) +"1 offsets
+)
+
+NB.*drawCircles v Draws circle(s) (x) on image (y)
+NB. x is: 2-item list of boxed (y0 x0 radius) ; (color)
+drawCircles=: (1&{:: ;~ [: ; [: <@getBresenhamCircle"1 (0&{::))@[ setPixels ]
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-2.j b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-2.j
new file mode 100644
index 0000000000..808c667e6a
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-2.j
@@ -0,0 +1,3 @@
+myimg=: 0 255 0 makeRGB 25 25 NB. 25 by 25 green image
+myimg=: (12 12 12 ; 255 0 0) drawCircles myimg NB. draw red circle with radius 12
+viewRGB ((12 12 9 ,: 12 12 6) ; 0 0 255) drawCircles myimg NB. draw two more concentric circles
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-3.j b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-3.j
new file mode 100644
index 0000000000..8bdb1805d4
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/J/bitmap-midpoint-circle-algorithm-3.j
@@ -0,0 +1,35 @@
+import java.awt.Color;
+
+public class MidPointCircle {
+ private BasicBitmapStorage image;
+
+ public MidPointCircle(final int imageWidth, final int imageHeight) {
+ this.image = new BasicBitmapStorage(imageWidth, imageHeight);
+ }
+
+ private void drawCircle(final int centerX, final int centerY, final int radius) {
+ int d = (5 - r * 4)/4;
+ int x = 0;
+ int y = radius;
+ Color circleColor = Color.white;
+
+ do {
+ image.setPixel(centerX + x, centerY + y, circleColor);
+ image.setPixel(centerX + x, centerY - y, circleColor);
+ image.setPixel(centerX - x, centerY + y, circleColor);
+ image.setPixel(centerX - x, centerY - y, circleColor);
+ image.setPixel(centerX + y, centerY + x, circleColor);
+ image.setPixel(centerX + y, centerY - x, circleColor);
+ image.setPixel(centerX - y, centerY + x, circleColor);
+ image.setPixel(centerX - y, centerY - x, circleColor);
+ if (d < 0) {
+ d += 2 * x + 1;
+ } else {
+ d += 2 * (x - y) + 1;
+ y--;
+ }
+ x++;
+ } while (x <= y);
+
+ }
+}
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-1.mathematica b/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-1.mathematica
new file mode 100644
index 0000000000..ae98bc9522
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-1.mathematica
@@ -0,0 +1,10 @@
+SetAttributes[drawcircle, HoldFirst];
+drawcircle[img_, {x0_, y0_}, r_, color_: White] :=
+ Module[{f = 1 - r, ddfx = 1, ddfy = -2 r, x = 0, y = r,
+ pixels = {{0, r}, {0, -r}, {r, 0}, {-r, 0}}},
+ While[x < y,
+ If[f >= 0, y--; ddfy += 2; f += ddfy];
+ x++; ddfx += 2; f += ddfx;
+ pixels = Join[pixels, {{x, y}, {x, -y}, {-x, y}, {-x, -y},
+ {y, x}, {y, -x}, {-y, x}, {-y, -x}}]];
+ img = ReplacePixelValue[img, {x0, y0} + # -> color & /@ pixels]]
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-2.mathematica b/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-2.mathematica
new file mode 100644
index 0000000000..65ee9d5244
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Mathematica/bitmap-midpoint-circle-algorithm-2.mathematica
@@ -0,0 +1,2 @@
+img = ExampleData[{"TestImage", "Lena"}];
+drawcircle[img, {250, 250}, 100]
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-1.mod3 b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-1.mod3
new file mode 100644
index 0000000000..fb2eba24f9
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-1.mod3
@@ -0,0 +1,11 @@
+INTERFACE Circle;
+
+IMPORT Bitmap;
+
+PROCEDURE Draw(
+ img: Bitmap.T;
+ center: Bitmap.Point;
+ radius: CARDINAL;
+ color: Bitmap.Pixel);
+
+END Circle.
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-2.mod3 b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-2.mod3
new file mode 100644
index 0000000000..f28a134e43
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-2.mod3
@@ -0,0 +1,41 @@
+MODULE Circle;
+
+IMPORT Bitmap;
+
+PROCEDURE Draw(
+ img: Bitmap.T;
+ center: Bitmap.Point;
+ radius: CARDINAL;
+ color: Bitmap.Pixel) =
+ VAR f := 1 - radius;
+ ddfx := 0;
+ ddfy := - 2 * radius;
+ x := 0;
+ y := radius;
+ BEGIN
+ Bitmap.SetPixel(img, Bitmap.Point{center.x, center.y + radius}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x, center.y - radius}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x + radius, center.y}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x - radius, center.y}, color);
+ WHILE x < y DO
+ IF f >= 0 THEN
+ y := y - 1;
+ ddfy := ddfy + 2;
+ f := f + ddfy;
+ END;
+ x := x + 1;
+ ddfx := ddfx + 2;
+ f := f + ddfx + 1;
+ Bitmap.SetPixel(img, Bitmap.Point{center.x + x, center.y + y}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x - x, center.y + y}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x + x, center.y - y}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x - x, center.y - y}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x + y, center.y + x}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x - y, center.y + x}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x + y, center.y - x}, color);
+ Bitmap.SetPixel(img, Bitmap.Point{center.x - y, center.y - x}, color);
+ END;
+ END Draw;
+
+BEGIN
+END Circle.
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-3.mod3 b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-3.mod3
new file mode 100644
index 0000000000..05d3184085
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-3.mod3
@@ -0,0 +1,12 @@
+MODULE Main;
+
+IMPORT Circle, Bitmap, PPM;
+
+VAR testpic: Bitmap.T;
+
+BEGIN
+ testpic := Bitmap.NewImage(32, 32);
+ Bitmap.Fill(testpic, Bitmap.White);
+ Circle.Draw(testpic, Bitmap.Point{16, 16}, 10, Bitmap.Black);
+ PPM.Create("testpic.ppm", testpic);
+END Main.
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-4.mod3 b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-4.mod3
new file mode 100644
index 0000000000..ab00f34686
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Modula-3/bitmap-midpoint-circle-algorithm-4.mod3
@@ -0,0 +1,27 @@
+let raster_circle ~img ~color ~c:(x0, y0) ~r =
+ let plot = put_pixel img color in
+ let x = 0
+ and y = r
+ and m = 5 - 4 * r
+ in
+ let rec loop x y m =
+ plot (x0 + x) (y0 + y);
+ plot (x0 + y) (y0 + x);
+ plot (x0 - x) (y0 + y);
+ plot (x0 - y) (y0 + x);
+ plot (x0 + x) (y0 - y);
+ plot (x0 + y) (y0 - x);
+ plot (x0 - x) (y0 - y);
+ plot (x0 - y) (y0 - x);
+ let y, m =
+ if m > 0
+ then (y - 1), (m - 8 * y)
+ else y, m
+ in
+ if x <= y then
+ let x = x + 1 in
+ let m = m + 8 * x + 4 in
+ loop x y m
+ in
+ loop x y m
+;;
diff --git a/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-1.j b/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-1.j
new file mode 100644
index 0000000000..e04637b490
--- /dev/null
+++ b/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-1.j
@@ -0,0 +1,10 @@
+require 'files'
+
+readppm=: monad define
+ dat=. fread y NB. read from file
+ msk=. 1 ,~ (*. 3 >: +/\) (LF&=@}: *. '#'&~:@}.) dat NB. mark field ends
+ 't wbyh maxval dat'=. msk <;._2 dat NB. parse
+ 'wbyh maxval'=. 2 1([ {. [: _99&". (LF,' ')&charsub)&.> wbyh;maxval NB. convert to numeric
+ if. (_99 0 +./@e. wbyh,maxval) +. 'P6' -.@-: 2{.t do. _1 return. end.
+ (a. i. dat) makeRGB |.wbyh NB. convert to basic bitmap format
+)
diff --git a/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-2.j b/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-2.j
new file mode 100644
index 0000000000..6409582834
--- /dev/null
+++ b/Task/Bitmap-Read-a-PPM-file/J/bitmap-read-a-ppm-file-2.j
@@ -0,0 +1,3 @@
+myimg=: readppm jpath '~temp/myimg.ppm'
+myimgGray=: toColor toGray myimg
+myimgGray writeppm jpath '~temp/myimgGray.ppm'
diff --git a/Task/Bitmap-Read-a-PPM-file/Mathematica/bitmap-read-a-ppm-file.mathematica b/Task/Bitmap-Read-a-PPM-file/Mathematica/bitmap-read-a-ppm-file.mathematica
new file mode 100644
index 0000000000..40a8e6149c
--- /dev/null
+++ b/Task/Bitmap-Read-a-PPM-file/Mathematica/bitmap-read-a-ppm-file.mathematica
@@ -0,0 +1 @@
+Import["file.ppm","PPM"]
diff --git a/Task/Bitmap-Write-a-PPM-file/GAP/bitmap-write-a-ppm-file.gap b/Task/Bitmap-Write-a-PPM-file/GAP/bitmap-write-a-ppm-file.gap
new file mode 100644
index 0000000000..0506cea8c6
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/GAP/bitmap-write-a-ppm-file.gap
@@ -0,0 +1,51 @@
+# Dirty implementation
+# Only P3 format, an image is a list of 3 matrices (r, g, b)
+# Max color is always 255
+WriteImage := function(name, img)
+ local f, r, g, b, i, j, maxcolor, nrow, ncol, dim;
+ f := OutputTextFile(name, false);
+ r := img[1];
+ g := img[2];
+ b := img[3];
+ dim := DimensionsMat(r);
+ nrow := dim[1];
+ ncol := dim[2];
+ maxcolor := 255;
+ WriteLine(f, "P3");
+ WriteLine(f, Concatenation(String(ncol), " ", String(nrow), " ", String(maxcolor)));
+ for i in [1 .. nrow] do
+ for j in [1 .. ncol] do
+ WriteLine(f, Concatenation(String(r[i][j]), " ", String(g[i][j]), " ", String(b[i][j])));
+ od;
+ od;
+ CloseStream(f);
+end;
+
+PutPixel := function(img, i, j, color)
+ img[1][i][j] := color[1];
+ img[2][i][j] := color[2];
+ img[3][i][j] := color[3];
+end;
+
+GetPixel := function(img, i, j)
+ return [img[1][i][j], img[2][i][j], img[3][i][j]];
+end;
+
+NewImage := function(nrow, ncol, color)
+ local r, g, b;
+ r := color[1] + NullMat(nrow, ncol);
+ g := color[2] + NullMat(nrow, ncol);
+ b := color[3] + NullMat(nrow, ncol);
+ return [r, g, b];
+end;
+
+# Reproducing the example from Wikipedia
+black := [ 0, 0, 0 ];
+g := NewImage(2, 3, black);
+PutPixel(g, 1, 1, [255, 0, 0]);
+PutPixel(g, 1, 2, [0, 255, 0]);
+PutPixel(g, 1, 3, [0, 0, 255]);
+PutPixel(g, 2, 1, [255, 255, 0]);
+PutPixel(g, 2, 2, [255, 255, 255]);
+PutPixel(g, 2, 3, [0, 0, 0]);
+WriteImage("example.ppm", g);
diff --git a/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-1.j b/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-1.j
new file mode 100644
index 0000000000..d41ac6e5e9
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-1.j
@@ -0,0 +1,7 @@
+require 'files'
+
+NB. ($x) is height, width, colors per pixel
+writeppm=:dyad define
+ header=. 'P6',LF,(":1 0{$x),LF,'255',LF
+ (header,,x{a.) fwrite y
+)
diff --git a/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-2.j b/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-2.j
new file mode 100644
index 0000000000..d7b33df89e
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/J/bitmap-write-a-ppm-file-2.j
@@ -0,0 +1,4 @@
+ NB. create 10 by 10 block of magenta pixels in top right quadrant of a 300 wide by 600 high green image
+ myimg=: ((145 + pixellist) ; 255 0 255) setPixels 0 255 0 makeRGB 600 200
+ myimg writeppm jpath '~temp/myimg.ppm'
+360015
diff --git a/Task/Bitmap-Write-a-PPM-file/Mathematica/bitmap-write-a-ppm-file.mathematica b/Task/Bitmap-Write-a-PPM-file/Mathematica/bitmap-write-a-ppm-file.mathematica
new file mode 100644
index 0000000000..bc6c31dfae
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Mathematica/bitmap-write-a-ppm-file.mathematica
@@ -0,0 +1 @@
+Export["file.ppm",image,"PPM"]
diff --git a/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-1.mod3 b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-1.mod3
new file mode 100644
index 0000000000..048127b861
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-1.mod3
@@ -0,0 +1,7 @@
+INTERFACE PPM;
+
+IMPORT Bitmap, Pathname;
+
+PROCEDURE Create(imgfile: Pathname.T; img: Bitmap.T);
+
+END PPM.
diff --git a/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-2.mod3 b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-2.mod3
new file mode 100644
index 0000000000..65389b44d4
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-2.mod3
@@ -0,0 +1,30 @@
+MODULE PPM;
+
+IMPORT Bitmap, Wr, FileWr, Pathname;
+FROM Fmt IMPORT F, Int;
+
+<*FATAL ANY*>
+
+VAR imgfilewr: FileWr.T;
+
+PROCEDURE Create(imgfile: Pathname.T; img: Bitmap.T) =
+ VAR height := LAST(img^);
+ width := LAST(img[0]);
+ color: Bitmap.Pixel;
+ BEGIN
+ imgfilewr := FileWr.Open(imgfile);
+ Wr.PutText(imgfilewr, F("P6\n%s %s\n255\n", Int(height + 1), Int(width + 1)));
+ FOR i := 0 TO height DO
+ FOR j := 0 TO width DO
+ color := img[i,j];
+ Wr.PutChar(imgfilewr, VAL(color.R, CHAR));
+ Wr.PutChar(imgfilewr, VAL(color.G, CHAR));
+ Wr.PutChar(imgfilewr, VAL(color.B, CHAR));
+ END;
+ END;
+ Wr.PutChar(imgfilewr, '\n');
+ Wr.Flush(imgfilewr);
+ END Create;
+
+BEGIN
+END PPM.
diff --git a/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-3.mod3 b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-3.mod3
new file mode 100644
index 0000000000..2bfe07248e
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Modula-3/bitmap-write-a-ppm-file-3.mod3
@@ -0,0 +1,14 @@
+let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) =
+ let width = Bigarray.Array2.dim1 r_channel
+ and height = Bigarray.Array2.dim2 r_channel in
+ Printf.fprintf oc "P6\n%d %d\n255\n" width height;
+ for y = 0 to pred height do
+ for x = 0 to pred width do
+ output_char oc (char_of_int r_channel.{x,y});
+ output_char oc (char_of_int g_channel.{x,y});
+ output_char oc (char_of_int b_channel.{x,y});
+ done;
+ done;
+ output_char oc '\n';
+ flush oc;
+;;
diff --git a/Task/Bitmap/Factor/bitmap.factor b/Task/Bitmap/Factor/bitmap.factor
new file mode 100644
index 0000000000..a6be11f3ce
--- /dev/null
+++ b/Task/Bitmap/Factor/bitmap.factor
@@ -0,0 +1,25 @@
+USING: arrays fry kernel math.matrices sequences ;
+IN: rosettacode.raster.storage
+
+! Various utilities
+: meach ( matrix quot -- ) [ each ] curry each ; inline
+: meach-index ( matrix quot -- )
+ [ swap 2array ] prepose
+ [ curry each-index ] curry each-index ; inline
+: mmap ( matrix quot -- matrix' ) [ map ] curry map ; inline
+: mmap! ( matrix quot -- matrix' ) [ map! ] curry map! ; inline
+: mmap-index ( matrix quot -- matrix' )
+ [ swap 2array ] prepose
+ [ curry map-index ] curry map-index ; inline
+
+: matrix-dim ( matrix -- i j ) [ length ] [ first length ] bi ;
+: set-Mi,j ( elt {i,j} matrix -- ) [ first2 swap ] dip nth set-nth ;
+: Mi,j ( {i,j} matrix -- elt ) [ first2 swap ] dip nth nth ;
+
+! The storage functions
+: ( width height -- image )
+ zero-matrix [ drop { 0 0 0 } ] mmap ;
+: fill-image ( {R,G,B} image -- image )
+ swap '[ drop _ ] mmap! ;
+: set-pixel ( {R,G,B} {i,j} image -- ) set-Mi,j ; inline
+: get-pixel ( {i,j} image -- pixel ) Mi,j ; inline
diff --git a/Task/Bitmap/Icon/bitmap.icon b/Task/Bitmap/Icon/bitmap.icon
new file mode 100644
index 0000000000..263a59bffb
--- /dev/null
+++ b/Task/Bitmap/Icon/bitmap.icon
@@ -0,0 +1,15 @@
+procedure makebitmap(width,height)
+ return open("bitmap", "g", "canvas=hidden",
+ "size="||width||","||height)
+end
+procedure fillimage(w,color)
+ Fg(w,color)
+ FillRectangle(w)
+end
+procedure setpixel(w,x,y,color)
+ Fg(w,color)
+ DrawPixel(x,y)
+end
+procedure getpixel(w,x,y)
+ return Pixel(w,x,y)
+end
diff --git a/Task/Bitmap/J/bitmap-1.j b/Task/Bitmap/J/bitmap-1.j
new file mode 100644
index 0000000000..244349c6a9
--- /dev/null
+++ b/Task/Bitmap/J/bitmap-1.j
@@ -0,0 +1,4 @@
+makeRGB=: 0&$: : (($,)~ ,&3)
+fillRGB=: makeRGB }:@$
+setPixels=: (1&{::@[)`(<"1@(0&{::@[))`]}
+getPixels=: <"1@[ { ]
diff --git a/Task/Bitmap/J/bitmap-2.j b/Task/Bitmap/J/bitmap-2.j
new file mode 100644
index 0000000000..de25a9f397
--- /dev/null
+++ b/Task/Bitmap/J/bitmap-2.j
@@ -0,0 +1,15 @@
+ myimg=: makeRGB 5 8 NB. create a bitmap with height 5 and width 8 (black)
+ myimg=: 255 makeRGB 5 8 NB. create a white bitmap with height 5 and width 8
+ myimg=: 0 255 0 makeRGB 5 8 NB. create a green bitmap with height 5 and width 8
+ myimg=: 0 0 255 fillRGB myimg NB. fill myimg with blue
+ colors=: 0 255 {~ #: i.8 NB. black,blue,green,cyan,red,magenta,yellow,white
+ myimg=: colors fillRGB myimg NB. fill myimg with vertical stripes of colors
+ 2 4 getPixels myimg NB. get the pixel color from point (2, 4)
+255 0 0
+
+ myimg=: (2 4 ; 255 255 255) setPixels myimg NB. set pixel at point (2, 4) to white
+ 2 4 getPixels myimg NB. get the pixel color from point (2, 4)
+255 255 255
+
+ }:$ myimg NB. get height and width of the image
+5 8
diff --git a/Task/Bitmap/J/bitmap-3.j b/Task/Bitmap/J/bitmap-3.j
new file mode 100644
index 0000000000..96fb0c1333
--- /dev/null
+++ b/Task/Bitmap/J/bitmap-3.j
@@ -0,0 +1,7 @@
+pixellist=: ,"0/~ i. 10 NB. row and column indices for 10 by 10 block of pixels
+
+NB. create 10 by 10 block of magenta pixels in the middle of a 300 by 300 green image
+myimg=: ((145 + pixellist) ; 255 0 255) setPixels 0 255 0 makeRGB 300 300
+
+NB. get pixel color for 10x10 block offset from magenta block
+subimg=: (140 + pixellist) getPixels myimg
diff --git a/Task/Bitmap/J/bitmap-4.j b/Task/Bitmap/J/bitmap-4.j
new file mode 100644
index 0000000000..855893b16b
--- /dev/null
+++ b/Task/Bitmap/J/bitmap-4.j
@@ -0,0 +1,4 @@
+require 'viewmat'
+viewRGB=: [: viewrgb 256.
+
+viewRGB myimg
diff --git a/Task/Bitmap/KonsolScript/bitmap.konso b/Task/Bitmap/KonsolScript/bitmap.konso
new file mode 100644
index 0000000000..ded4313572
--- /dev/null
+++ b/Task/Bitmap/KonsolScript/bitmap.konso
@@ -0,0 +1,13 @@
+function main() {
+ Var:Number shape;
+
+ Image:New(50, 50, shape)
+ Draw:RectFill(0, 0, 50, 50, 0xFF0000, shape) //one to fill an image with a plain RED color
+
+ Draw:Pixel(30, 30, 0x0000FF, shape) //set a given pixel at (30,30) with a BLUE color
+
+ while (B1 == false) {
+ Image:Blit(10, 10, shape, screen)
+ Screen:Render()
+ }
+}
diff --git a/Task/Bitmap/MAXScript/bitmap-1.max b/Task/Bitmap/MAXScript/bitmap-1.max
new file mode 100644
index 0000000000..cfb2559667
--- /dev/null
+++ b/Task/Bitmap/MAXScript/bitmap-1.max
@@ -0,0 +1 @@
+local myBitmap = bitmap 512 512
diff --git a/Task/Bitmap/MAXScript/bitmap-2.max b/Task/Bitmap/MAXScript/bitmap-2.max
new file mode 100644
index 0000000000..93aa37ee59
--- /dev/null
+++ b/Task/Bitmap/MAXScript/bitmap-2.max
@@ -0,0 +1 @@
+local myBitmap = bitmap 512 512 color:(color 128 128 128)
diff --git a/Task/Bitmap/MAXScript/bitmap-3.max b/Task/Bitmap/MAXScript/bitmap-3.max
new file mode 100644
index 0000000000..f2c1f75c5b
--- /dev/null
+++ b/Task/Bitmap/MAXScript/bitmap-3.max
@@ -0,0 +1 @@
+setPixels myBitmap [256, 256] #((color 255 255 255))
diff --git a/Task/Bitmap/MAXScript/bitmap-4.max b/Task/Bitmap/MAXScript/bitmap-4.max
new file mode 100644
index 0000000000..6ead9d046f
--- /dev/null
+++ b/Task/Bitmap/MAXScript/bitmap-4.max
@@ -0,0 +1 @@
+local myPixel = getPixels myBitmap [256, 256] 1
diff --git a/Task/Bitmap/Mathematica/bitmap-1.mathematica b/Task/Bitmap/Mathematica/bitmap-1.mathematica
new file mode 100644
index 0000000000..4094414a26
--- /dev/null
+++ b/Task/Bitmap/Mathematica/bitmap-1.mathematica
@@ -0,0 +1,3 @@
+img = Image[ConstantArray[{1, 0, 0}, {1000, 1000}]];
+img = ReplacePart[img, {1, 1, 1} -> {0, 0, 1}];
+ImageValue[img, {1, 1}]
diff --git a/Task/Bitmap/Mathematica/bitmap-2.mathematica b/Task/Bitmap/Mathematica/bitmap-2.mathematica
new file mode 100644
index 0000000000..fff2af1753
--- /dev/null
+++ b/Task/Bitmap/Mathematica/bitmap-2.mathematica
@@ -0,0 +1,3 @@
+img = Image[ConstantArray[{1, 0, 0}, {1000, 1000}]];
+img = ReplacePixelValue[img, {1, 1} -> {0, 0, 1}];
+ImageValue[img, {1, 1}]
diff --git a/Task/Bitmap/Modula-3/bitmap-1.mod3 b/Task/Bitmap/Modula-3/bitmap-1.mod3
new file mode 100644
index 0000000000..c94c60f747
--- /dev/null
+++ b/Task/Bitmap/Modula-3/bitmap-1.mod3
@@ -0,0 +1,24 @@
+INTERFACE Bitmap;
+
+TYPE UByte = BITS 8 FOR [0 .. 16_FF];
+ Pixel = RECORD R, G, B: UByte; END;
+ Point = RECORD x, y: UByte; END;
+ T = REF ARRAY OF ARRAY OF Pixel;
+
+CONST
+ Black = Pixel{0, 0, 0};
+ White = Pixel{255, 255, 255};
+ Red = Pixel{255, 0, 0};
+ Green = Pixel{0, 255, 0};
+ Blue = Pixel{0, 0, 255};
+ Yellow = Pixel{255, 255, 0};
+
+EXCEPTION BadImage;
+ BadColor;
+
+PROCEDURE NewImage(height, width: UByte): T RAISES {BadImage};
+PROCEDURE Fill(VAR pic: T; color: Pixel);
+PROCEDURE GetPixel(VAR pic: T; point: Point): Pixel RAISES {BadColor};
+PROCEDURE SetPixel(VAR pic: T; point: Point; color: Pixel);
+
+END Bitmap.
diff --git a/Task/Bitmap/Modula-3/bitmap-2.mod3 b/Task/Bitmap/Modula-3/bitmap-2.mod3
new file mode 100644
index 0000000000..d248a371b5
--- /dev/null
+++ b/Task/Bitmap/Modula-3/bitmap-2.mod3
@@ -0,0 +1,48 @@
+MODULE Bitmap;
+
+PROCEDURE NewImage(height, width: UByte): T RAISES {BadImage} =
+ (* To make things easier, limit image size to also
+ be UByte (0 to 255), and to have equal dimensions. *)
+ BEGIN
+ IF height # width THEN
+ RAISE BadImage;
+ END;
+ RETURN NEW(T, height, width);
+ END NewImage;
+
+PROCEDURE Fill(VAR pic: T; color: Pixel) =
+ BEGIN
+ FOR i := FIRST(pic^) TO LAST(pic^) DO
+ FOR j := FIRST(pic[0]) TO LAST(pic[0]) DO
+ pic[i,j] := color;
+ END;
+ END;
+ END Fill;
+
+PROCEDURE GetPixel(VAR pic: T; point: Point): Pixel RAISES {BadColor} =
+ VAR pixel := pic[point.x, point.y];
+ BEGIN
+ IF pixel = White THEN
+ RETURN White;
+ ELSIF pixel = Black THEN
+ RETURN Black;
+ ELSIF pixel = Red THEN
+ RETURN Red;
+ ELSIF pixel = Green THEN
+ RETURN Green;
+ ELSIF pixel = Blue THEN
+ RETURN Blue;
+ ELSIF pixel = Yellow THEN
+ RETURN Yellow;
+ ELSE
+ RAISE BadColor;
+ END;
+ END GetPixel;
+
+PROCEDURE SetPixel(VAR pic: T; point: Point; color: Pixel) =
+ BEGIN
+ pic[point.x, point.y] := color;
+ END SetPixel;
+
+BEGIN
+END Bitmap.
diff --git a/Task/Bitwise-IO/J/bitwise-io-1.j b/Task/Bitwise-IO/J/bitwise-io-1.j
new file mode 100644
index 0000000000..503539b89c
--- /dev/null
+++ b/Task/Bitwise-IO/J/bitwise-io-1.j
@@ -0,0 +1,2 @@
+bitReader =: a. {~ _7 #.\ ({.~ <.&.(%&7)@#)
+bitWriter =: , @ ((7$2) & #: @ (a.&i.)), 0 $~ 8 | #
diff --git a/Task/Bitwise-IO/J/bitwise-io-2.j b/Task/Bitwise-IO/J/bitwise-io-2.j
new file mode 100644
index 0000000000..725533f6a7
--- /dev/null
+++ b/Task/Bitwise-IO/J/bitwise-io-2.j
@@ -0,0 +1,4 @@
+text=: 'This text is used to illustrate the Rosetta Code task about ''bit oriented IO''.'
+
+ bitReader bitWriter text
+This text is used to illustrate the Rosetta Code task about 'bit oriented IO'.
diff --git a/Task/Bitwise-IO/J/bitwise-io-3.j b/Task/Bitwise-IO/J/bitwise-io-3.j
new file mode 100644
index 0000000000..67593675f7
--- /dev/null
+++ b/Task/Bitwise-IO/J/bitwise-io-3.j
@@ -0,0 +1,2 @@
+ # text
+78
diff --git a/Task/Bitwise-IO/J/bitwise-io-4.j b/Task/Bitwise-IO/J/bitwise-io-4.j
new file mode 100644
index 0000000000..75069957fd
--- /dev/null
+++ b/Task/Bitwise-IO/J/bitwise-io-4.j
@@ -0,0 +1,2 @@
+ %&8 # bitWriter text
+69
diff --git a/Task/Bitwise-operations/FALSE/bitwise-operations.false b/Task/Bitwise-operations/FALSE/bitwise-operations.false
new file mode 100644
index 0000000000..60eb178825
--- /dev/null
+++ b/Task/Bitwise-operations/FALSE/bitwise-operations.false
@@ -0,0 +1,6 @@
+10 3
+\$@$@$@$@\ { 3 copies }
+"a & b = "&."
+a | b = "|."
+~a = "%~."
+"
diff --git a/Task/Bitwise-operations/Factor/bitwise-operations-1.factor b/Task/Bitwise-operations/Factor/bitwise-operations-1.factor
new file mode 100644
index 0000000000..0552a501e1
--- /dev/null
+++ b/Task/Bitwise-operations/Factor/bitwise-operations-1.factor
@@ -0,0 +1,9 @@
+"a=" "b=" [ write readln string>number ] bi@
+{
+ [ bitand "a AND b: " write . ]
+ [ bitor "a OR b: " write . ]
+ [ bitxor "a XOR b: " write . ]
+ [ drop bitnot "NOT a: " write . ]
+ [ abs shift "a asl b: " write . ]
+ [ neg shift "a asr b: " write . ]
+} 2cleave
diff --git a/Task/Bitwise-operations/Factor/bitwise-operations-2.factor b/Task/Bitwise-operations/Factor/bitwise-operations-2.factor
new file mode 100644
index 0000000000..7b85c05e2a
--- /dev/null
+++ b/Task/Bitwise-operations/Factor/bitwise-operations-2.factor
@@ -0,0 +1,8 @@
+a=255
+b=5
+a AND b: 5
+a OR b: 255
+a XOR b: 250
+NOT a: -256
+a asl b: 8160
+a asr b: 7
diff --git a/Task/Bitwise-operations/Groovy/bitwise-operations-1.groovy b/Task/Bitwise-operations/Groovy/bitwise-operations-1.groovy
new file mode 100644
index 0000000000..c401b7b534
--- /dev/null
+++ b/Task/Bitwise-operations/Groovy/bitwise-operations-1.groovy
@@ -0,0 +1,11 @@
+def bitwise = { a, b ->
+ println """
+a & b = ${a} & ${b} = ${a & b}
+a | b = ${a} | ${b} = ${a | b}
+a ^ b = ${a} ^ ${b} = ${a ^ b}
+~ a = ~ ${a} = ${~ a}
+a << b = ${a} << ${b} = ${a << b}
+a >> b = ${a} >> ${b} = ${a >> b} arithmetic (sign-preserving) shift
+a >>> b = ${a} >>> ${b} = ${a >>> b} logical (zero-filling) shift
+"""
+}
diff --git a/Task/Bitwise-operations/Groovy/bitwise-operations-2.groovy b/Task/Bitwise-operations/Groovy/bitwise-operations-2.groovy
new file mode 100644
index 0000000000..284cb236c1
--- /dev/null
+++ b/Task/Bitwise-operations/Groovy/bitwise-operations-2.groovy
@@ -0,0 +1 @@
+bitwise(-15,3)
diff --git a/Task/Bitwise-operations/HicEst/bitwise-operations.hicest b/Task/Bitwise-operations/HicEst/bitwise-operations.hicest
new file mode 100644
index 0000000000..8df74498dc
--- /dev/null
+++ b/Task/Bitwise-operations/HicEst/bitwise-operations.hicest
@@ -0,0 +1,4 @@
+i = IAND(k, j)
+i = IOR( k, j)
+i = IEOR(k, j)
+i = NOT( k )
diff --git a/Task/Bitwise-operations/Icon/bitwise-operations.icon b/Task/Bitwise-operations/Icon/bitwise-operations.icon
new file mode 100644
index 0000000000..4bcace1afa
--- /dev/null
+++ b/Task/Bitwise-operations/Icon/bitwise-operations.icon
@@ -0,0 +1,21 @@
+procedure main()
+bitdemo(255,2)
+bitdemo(-15,3)
+end
+
+procedure bitdemo(i,i2)
+ write()
+ demowrite("i",i)
+ demowrite("i2",i2)
+ demowrite("complement i",icom(i))
+ demowrite("i or i2",ior(i,i2))
+ demowrite("i and i2",iand(i,i2))
+ demowrite("i xor i2",ixor(i,i2))
+ demowrite("i shift " || i2,ishift(i,i2))
+ demowrite("i shift -" || i2,ishift(i,-i2))
+ return
+end
+
+procedure demowrite(vs,v)
+return write(vs, ": ", v, " = ", int2bit(v),"b")
+end
diff --git a/Task/Bitwise-operations/Inform-6/bitwise-operations.inf b/Task/Bitwise-operations/Inform-6/bitwise-operations.inf
new file mode 100644
index 0000000000..b263032bed
--- /dev/null
+++ b/Task/Bitwise-operations/Inform-6/bitwise-operations.inf
@@ -0,0 +1,15 @@
+[ bitwise a b temp;
+ print "a and b: ", a & b, "^";
+ print "a or b: ", a | b, "^";
+ print "not a: ", ~a, "^";
+ @art_shift a b -> temp;
+ print "a << b (arithmetic): ", temp, "^";
+ temp = -b;
+ @art_shift a temp -> temp;
+ print "a >> b (arithmetic): ", temp, "^";
+ @log_shift a b -> temp;
+ print "a << b (logical): ", temp, "^";
+ temp = -b;
+ @log_shift a temp -> temp;
+ print "a >> b (logical): ", temp, "^";
+];
diff --git a/Task/Bitwise-operations/J/bitwise-operations-1.j b/Task/Bitwise-operations/J/bitwise-operations-1.j
new file mode 100644
index 0000000000..1bea4160e4
--- /dev/null
+++ b/Task/Bitwise-operations/J/bitwise-operations-1.j
@@ -0,0 +1,9 @@
+bAND=: 17 b. NB. 16+#.0 0 0 1
+bOR=: 23 b. NB. 16+#.0 1 1 1
+bXOR=: 22 b. NB. 16+#.0 1 1 0
+b1NOT=: 28 b. NB. 16+#.1 1 0 0
+bLshift=: 33 b.~ NB. see http://www.jsoftware.com/help/release/bdot.htm
+bRshift=: 33 b.~ -
+bRAshift=: 34 b.~ -
+bLrot=: 32 b.~
+bRrot=: 32 b.~ -
diff --git a/Task/Bitwise-operations/J/bitwise-operations-2.j b/Task/Bitwise-operations/J/bitwise-operations-2.j
new file mode 100644
index 0000000000..f3a2a2bf1f
--- /dev/null
+++ b/Task/Bitwise-operations/J/bitwise-operations-2.j
@@ -0,0 +1,4 @@
+bitwise=: 1 :0
+:
+ smoutput (((":x),"1' ',.(>u),.' '),"1":y),"1' => ',"1'.X'{~#:x u`:0 y
+)
diff --git a/Task/Bitwise-operations/J/bitwise-operations-3.j b/Task/Bitwise-operations/J/bitwise-operations-3.j
new file mode 100644
index 0000000000..b4c247be5a
--- /dev/null
+++ b/Task/Bitwise-operations/J/bitwise-operations-3.j
@@ -0,0 +1,10 @@
+ 254 bAND`bOR`bXOR`b1NOT`bLshift`bRshift`bRAshift`bLrot`bRrot bitwise 3
+254 bAND 3 => ............................X.
+254 bOR 3 => ......................XXXXXXXX
+254 bXOR 3 => ......................XXXXXX.X
+254 b1NOT 3 => XXXXXXXXXXXXXXXXXXXXXX.......X
+254 bLshift 3 => ...................XXXXXXX....
+254 bRshift 3 => .........................XXXXX
+254 bRAshift 3 => .........................XXXXX
+254 bLrot 3 => ...................XXXXXXX....
+254 bRrot 3 => .........................XXXXX
diff --git a/Task/Bitwise-operations/J/bitwise-operations-4.j b/Task/Bitwise-operations/J/bitwise-operations-4.j
new file mode 100644
index 0000000000..75eaf55d7a
--- /dev/null
+++ b/Task/Bitwise-operations/J/bitwise-operations-4.j
@@ -0,0 +1,2 @@
+bXOR/ 3333 5555 7777 9999
+8664
diff --git a/Task/Bitwise-operations/LLVM/bitwise-operations.llvm b/Task/Bitwise-operations/LLVM/bitwise-operations.llvm
new file mode 100644
index 0000000000..a0ebcf1310
--- /dev/null
+++ b/Task/Bitwise-operations/LLVM/bitwise-operations.llvm
@@ -0,0 +1,60 @@
+; ModuleID = 'test.o'
+;e means little endian
+;p: { pointer size : pointer abi : preferred alignment for pointers }
+;i same for integers
+;v is for vectors
+;f for floats
+;a for aggregate types
+;s for stack objects
+;n: {size:size:size...}, best integer sizes
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+;this was compiled with mingw32; thus it must be linked to an ABI compatible c library
+target triple = "i386-mingw32"
+
+@.str = private constant [13 x i8] c"a and b: %d\0A\00", align 1 ; <[13 x i8]*> [#uses=1]
+@.str1 = private constant [12 x i8] c"a or b: %d\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
+@.str2 = private constant [13 x i8] c"a xor b: %d\0A\00", align 1 ; <[13 x i8]*> [#uses=1]
+@.str3 = private constant [11 x i8] c"not a: %d\0A\00", align 1 ; <[11 x i8]*> [#uses=1]
+@.str4 = private constant [12 x i8] c"a << n: %d\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
+@.str5 = private constant [12 x i8] c"a >> n: %d\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
+@.str6 = private constant [12 x i8] c"c >> b: %d\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
+
+;A function that will do many bitwise opreations to two integer arguments, %a and %b
+define void @bitwise(i32 %a, i32 %b) nounwind {
+;entry block
+entry:
+ ;Register to store (a & b)
+ %0 = and i32 %b, %a ; [#uses=1]
+ ;print the results
+ %1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0), i32 %0) nounwind ; [#uses=0]
+ ;Register to store (a | b)
+ %2 = or i32 %b, %a ; [#uses=1]
+ ;print the results
+ %3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str1, i32 0, i32 0), i32 %2) nounwind ; [#uses=0]
+ ;Register to store (a ^ b)
+ %4 = xor i32 %b, %a ; [#uses=1]
+ ;print the results
+ %5 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str2, i32 0, i32 0), i32 %4) nounwind ; [#uses=0]
+ ;Register to store (~a)
+ %not = xor i32 %a, -1 ; [#uses=1]
+ ;print the results
+ %6 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str3, i32 0, i32 0), i32 %not) nounwind ; [#uses=0]
+ ;Register to store (a << b)
+ %7 = shl i32 %a, %b ; [#uses=1]
+ ;print the results
+ %8 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str4, i32 0, i32 0), i32 %7) nounwind ; [#uses=0]
+ ;Register to store (a >> b) (a is signed)
+ %9 = ashr i32 %a, %b ; [#uses=1]
+ ;print the results
+ %10 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str5, i32 0, i32 0), i32 %9) nounwind ; [#uses=0]
+ ;Register to store (c >> b), where c is unsiged (eg. logical right shift)
+ %11 = lshr i32 %a, %b ; [#uses=1]
+ ;print the results
+ %12 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str6, i32 0, i32 0), i32 %11) nounwind ; [#uses=0]
+
+ ;terminator instruction
+ ret void
+}
+
+;Declare external fuctions
+declare i32 @printf(i8* nocapture, ...) nounwind
diff --git a/Task/Bitwise-operations/LSE64/bitwise-operations.lse64 b/Task/Bitwise-operations/LSE64/bitwise-operations.lse64
new file mode 100644
index 0000000000..12f0b98d52
--- /dev/null
+++ b/Task/Bitwise-operations/LSE64/bitwise-operations.lse64
@@ -0,0 +1,11 @@
+over : 2 pick
+2dup : over over
+
+bitwise : \
+ " A=" ,t over ,h sp " B=" ,t dup ,h nl \
+ " A and B=" ,t 2dup & ,h nl \
+ " A or B=" ,t 2dup | ,h nl \
+ " A xor B=" ,t over ^ ,h nl \
+ " not A=" ,t ~ ,h nl
+
+\ a \ 7 bitwise # hex literals
diff --git a/Task/Bitwise-operations/Liberty-BASIC/bitwise-operations.liberty b/Task/Bitwise-operations/Liberty-BASIC/bitwise-operations.liberty
new file mode 100644
index 0000000000..254b28300b
--- /dev/null
+++ b/Task/Bitwise-operations/Liberty-BASIC/bitwise-operations.liberty
@@ -0,0 +1,46 @@
+' bitwise operations on byte-sized variables
+
+v =int( 256 *rnd( 1))
+
+s = 1
+
+print "Shift ="; s; " place."
+print
+print "Number as dec. = "; v; " & as 8-bits byte = ", dec2Bin$( v)
+print "NOT as dec. = "; bitInvert( v), dec2Bin$( bitInvert( v))
+print "Shifted left as dec. = "; shiftLeft( v, s), dec2Bin$( shiftLeft( v, s))
+print "Shifted right as dec. = "; shiftRight( v, s), dec2Bin$( shiftRight( v, s))
+print "Rotated left as dec. = "; rotateLeft( v, s), dec2Bin$( rotateLeft( v, s))
+print "Rotated right as dec. = "; rotateRight( v, s), dec2Bin$( rotateRight( v, s))
+
+end
+
+function shiftLeft( b, n)
+ shiftLeft =( b *2^n) and 255
+end function
+
+function shiftRight( b, n)
+ shiftRight =int(b /2^n)
+end function
+
+function rotateLeft( b, n)
+ rotateLeft = (( 2^n *b) mod 256) or ( b >127)
+end function
+
+function rotateRight( b, n)
+ rotateRight = (128*( b and 1)) or int( b /2)
+end function
+
+function bitInvert( b)
+ bitInvert =b xor 255
+end function
+
+function dec2Bin$( num) ' Given an integer decimal 0 <--> 255, returns binary equivalent as a string
+ n =num
+ dec2Bin$ =""
+ while ( num >0)
+ dec2Bin$ =str$( num mod 2) +dec2Bin$
+ num =int( num /2)
+ wend
+ dec2Bin$ =right$( "00000000" +dec2Bin$, 8)
+end function
diff --git a/Task/Bitwise-operations/Logo/bitwise-operations-1.logo b/Task/Bitwise-operations/Logo/bitwise-operations-1.logo
new file mode 100644
index 0000000000..4c12099854
--- /dev/null
+++ b/Task/Bitwise-operations/Logo/bitwise-operations-1.logo
@@ -0,0 +1,11 @@
+to bitwise :a :b
+ (print [a and b:] BitAnd :a :b)
+ (print [a or b:] BitOr :a :b)
+ (print [a xor b:] BitXor :a :b)
+ (print [not a:] BitNot :a)
+ ; shifts are to the left if positive, to the right if negative
+ (print [a lshift b:] LShift :a :b)
+ (print [a lshift -b:] LShift :a minus :b)
+ (print [-a ashift -b:] AShift minus :a minus :b)
+end
+bitwise 255 5
diff --git a/Task/Bitwise-operations/Logo/bitwise-operations-2.logo b/Task/Bitwise-operations/Logo/bitwise-operations-2.logo
new file mode 100644
index 0000000000..bc103389ba
--- /dev/null
+++ b/Task/Bitwise-operations/Logo/bitwise-operations-2.logo
@@ -0,0 +1,7 @@
+a and b: 5
+a or b: 255
+a xor b: 250
+not a: -256
+a lshift b: 8160
+a lshift -b: 7
+-a ashift -b: -8
diff --git a/Task/Bitwise-operations/MAXScript/bitwise-operations.max b/Task/Bitwise-operations/MAXScript/bitwise-operations.max
new file mode 100644
index 0000000000..1ad2cbb99c
--- /dev/null
+++ b/Task/Bitwise-operations/MAXScript/bitwise-operations.max
@@ -0,0 +1,11 @@
+fn bitwise a b =
+(
+ format "a and b: %\n" (bit.and a b)
+ format "a or b: %\n" (bit.or a b)
+ format "a xor b: %\n" (bit.xor a b)
+ format "not a: %\n" (bit.not a)
+ format "Left shift a: %\n" (bit.shift a b)
+ format "Right shift a: %\n" (bit.shift a -b)
+)
+
+bitwise 255 170
diff --git a/Task/Bitwise-operations/ML-I/bitwise-operations.ml b/Task/Bitwise-operations/ML-I/bitwise-operations.ml
new file mode 100644
index 0000000000..79fb822cc2
--- /dev/null
+++ b/Task/Bitwise-operations/ML-I/bitwise-operations.ml
@@ -0,0 +1,15 @@
+MCSKIP "WITH" NL
+"" Bitwise operations
+"" assumes macros on input stream 1, terminal on stream 2
+MCSKIP MT,<>
+MCINS %.
+MCDEF SL SPACES NL AS
+MCSKIP SL WITH *
+MCSET S1=1
+*MCSET S10=2
diff --git a/Task/Bitwise-operations/Mathematica/bitwise-operations-1.mathematica b/Task/Bitwise-operations/Mathematica/bitwise-operations-1.mathematica
new file mode 100644
index 0000000000..82d71a93b9
--- /dev/null
+++ b/Task/Bitwise-operations/Mathematica/bitwise-operations-1.mathematica
@@ -0,0 +1,18 @@
+(*and xor and or*)
+BitAnd[integer1, integer2]
+BitXor[integer1, integer2]
+BitOr[integer1, integer2]
+
+(*logical not*)
+BitNot[integer1]
+
+(*left and right shift*)
+BitShiftLeft[integer1]
+BitShiftRight[integer1]
+
+(*rotate digits left and right*)
+FromDigits[RotateLeft[IntegerDigits[integer1, 2]], 2]
+FromDigits[RotateRight[IntegerDigits[integer1, 2]], 2]
+
+(*right arithmetic shift*)
+FromDigits[Prepend[Most[#], #[[1]]], 2] &[IntegerDigits[integer1, 2]]
diff --git a/Task/Bitwise-operations/Mathematica/bitwise-operations-2.mathematica b/Task/Bitwise-operations/Mathematica/bitwise-operations-2.mathematica
new file mode 100644
index 0000000000..7e9f7e7abe
--- /dev/null
+++ b/Task/Bitwise-operations/Mathematica/bitwise-operations-2.mathematica
@@ -0,0 +1 @@
+BitXor[3333, 5555, 7777, 9999]
diff --git a/Task/Bitwise-operations/Mathematica/bitwise-operations-3.mathematica b/Task/Bitwise-operations/Mathematica/bitwise-operations-3.mathematica
new file mode 100644
index 0000000000..4a972457c2
--- /dev/null
+++ b/Task/Bitwise-operations/Mathematica/bitwise-operations-3.mathematica
@@ -0,0 +1 @@
+8664
diff --git a/Task/Bitwise-operations/Maxima/bitwise-operations.maxima b/Task/Bitwise-operations/Maxima/bitwise-operations.maxima
new file mode 100644
index 0000000000..1dc4a8d5c8
--- /dev/null
+++ b/Task/Bitwise-operations/Maxima/bitwise-operations.maxima
@@ -0,0 +1,23 @@
+load(functs)$
+
+a: 3661$
+b: 2541$
+
+logor(a, b);
+/* 4077 */
+
+logand(a, b);
+/* 2125 */
+
+logxor(a, b);
+/* 1952 */
+
+/* NOT(x) is simply -x - 1
+-a - 1;
+/* -3662 */
+
+logor(a, -a - 1);
+/* -1 */
+
+logand(a, -a - 1);
+/* 0 */
diff --git a/Task/Bitwise-operations/Modula-3/bitwise-operations.mod3 b/Task/Bitwise-operations/Modula-3/bitwise-operations.mod3
new file mode 100644
index 0000000000..9062038047
--- /dev/null
+++ b/Task/Bitwise-operations/Modula-3/bitwise-operations.mod3
@@ -0,0 +1,22 @@
+MODULE Bitwise EXPORTS Main;
+
+IMPORT IO, Fmt, Word;
+
+VAR c: Word.T;
+
+PROCEDURE Bitwise(a, b: INTEGER) =
+ BEGIN
+ IO.Put("a AND b: " & Fmt.Int(Word.And(a, b)) & "\n");
+ IO.Put("a OR b: " & Fmt.Int(Word.Or(a, b)) & "\n");
+ IO.Put("a XOR b: " & Fmt.Int(Word.Xor(a, b)) & "\n");
+ IO.Put("NOT a: " & Fmt.Int(Word.Not(a)) & "\n");
+ c := a;
+ IO.Put("c LeftShift b: " & Fmt.Unsigned(Word.LeftShift(c, b)) & "\n");
+ IO.Put("c RightShift b: " & Fmt.Unsigned(Word.RightShift(c, b)) & "\n");
+ IO.Put("c LeftRotate b: " & Fmt.Unsigned(Word.LeftRotate(c, b)) & "\n");
+ IO.Put("c RightRotate b: " & Fmt.Unsigned(Word.RightRotate(c, b)) & "\n");
+ END Bitwise;
+
+BEGIN
+ Bitwise(255, 5);
+END Bitwise.
diff --git a/Task/Boolean-values/GAP/boolean-values.gap b/Task/Boolean-values/GAP/boolean-values.gap
new file mode 100644
index 0000000000..5d63c7b9b3
--- /dev/null
+++ b/Task/Boolean-values/GAP/boolean-values.gap
@@ -0,0 +1,13 @@
+1 < 2;
+# true
+
+2 < 1;
+# false
+
+# GAP has also the value fail, which cannot be used as a boolean but may be used i$
+
+1 = fail;
+# false
+
+fail = fail;
+# true
diff --git a/Task/Boolean-values/Inform-7/boolean-values-1.inf b/Task/Boolean-values/Inform-7/boolean-values-1.inf
new file mode 100644
index 0000000000..b8fb3a2853
--- /dev/null
+++ b/Task/Boolean-values/Inform-7/boolean-values-1.inf
@@ -0,0 +1 @@
+let B be whether or not 123 is greater than 100;
diff --git a/Task/Boolean-values/Inform-7/boolean-values-2.inf b/Task/Boolean-values/Inform-7/boolean-values-2.inf
new file mode 100644
index 0000000000..d1a3553f78
--- /dev/null
+++ b/Task/Boolean-values/Inform-7/boolean-values-2.inf
@@ -0,0 +1 @@
+if B is true, say "123 is greater than 100."
diff --git a/Task/Boolean-values/Inform-7/boolean-values-3.inf b/Task/Boolean-values/Inform-7/boolean-values-3.inf
new file mode 100644
index 0000000000..2e0f1f2997
--- /dev/null
+++ b/Task/Boolean-values/Inform-7/boolean-values-3.inf
@@ -0,0 +1,9 @@
+To decide whether the CPU is working correctly:
+ if 123 is greater than 100, decide yes;
+ otherwise decide no.
+
+When play begins:
+ [convert to truth state...]
+ let B be whether or not the CPU is working correctly;
+ [...or use as a condition]
+ if the CPU is working correctly, say "Whew."
diff --git a/Task/Boolean-values/Julia/boolean-values.julia b/Task/Boolean-values/Julia/boolean-values.julia
new file mode 100644
index 0000000000..7649afa690
--- /dev/null
+++ b/Task/Boolean-values/Julia/boolean-values.julia
@@ -0,0 +1,4 @@
+#Boolean and conditional expressions only accept 'true' or 'false'
+
+#Convert a number or numeric array to boolean
+bool(x)
diff --git a/Task/Boolean-values/Logo/boolean-values-1.logo b/Task/Boolean-values/Logo/boolean-values-1.logo
new file mode 100644
index 0000000000..de1416082f
--- /dev/null
+++ b/Task/Boolean-values/Logo/boolean-values-1.logo
@@ -0,0 +1,4 @@
+print 1 < 0 ; false
+print 1 > 0 ; true
+if "true [print "yes] ; yes
+if not "false [print "no] ; no
diff --git a/Task/Boolean-values/Logo/boolean-values-2.logo b/Task/Boolean-values/Logo/boolean-values-2.logo
new file mode 100644
index 0000000000..9eec1918e6
--- /dev/null
+++ b/Task/Boolean-values/Logo/boolean-values-2.logo
@@ -0,0 +1,3 @@
+if equal? 0 ln 1 [print "zero]
+if empty? [] [print "empty] ; empty list
+if empty? "|| [print "empty] ; empty word
diff --git a/Task/Boolean-values/Maxima/boolean-values.maxima b/Task/Boolean-values/Maxima/boolean-values.maxima
new file mode 100644
index 0000000000..f05417912e
--- /dev/null
+++ b/Task/Boolean-values/Maxima/boolean-values.maxima
@@ -0,0 +1,11 @@
+is(1 < 2);
+/* true */
+
+is(2 < 1);
+/* false */
+
+not true;
+/* false */
+
+not false;
+/* true */
diff --git a/Task/Boolean-values/Mirah/boolean-values.mirah b/Task/Boolean-values/Mirah/boolean-values.mirah
new file mode 100644
index 0000000000..2dcb5fd511
--- /dev/null
+++ b/Task/Boolean-values/Mirah/boolean-values.mirah
@@ -0,0 +1,28 @@
+import java.util.ArrayList
+import java.util.HashMap
+
+# booleans
+puts 'true is true' if true
+puts 'false is false' if (!false)
+
+# lists treated as booleans
+x = ArrayList.new
+puts "empty array is true" if x
+x.add("an element")
+puts "full array is true" if x
+puts "isEmpty() is false" if !x.isEmpty()
+
+# maps treated as booleans
+map = HashMap.new
+puts "empty map is true" if map
+map.put('a', '1')
+puts "full map is true" if map
+puts "size() is 0 is false" if !(map.size() == 0)
+
+# these things do not compile
+# value = nil # ==> cannot assign nil to Boolean value
+# puts 'nil is false' if false == nil # ==> cannot compare boolean to nil
+# puts '0 is false' if (0 == false) # ==> cannot compare int to false
+
+#puts 'TRUE is true' if TRUE # ==> TRUE does not exist
+#puts 'FALSE is false' if !FALSE # ==> FALSE does not exist
diff --git a/Task/Boolean-values/Modula-2/boolean-values.mod2 b/Task/Boolean-values/Modula-2/boolean-values.mod2
new file mode 100644
index 0000000000..6f16f773f8
--- /dev/null
+++ b/Task/Boolean-values/Modula-2/boolean-values.mod2
@@ -0,0 +1,17 @@
+MODULE boo;
+
+IMPORT InOut;
+
+VAR result, done : BOOLEAN;
+ A, B : INTEGER;
+
+BEGIN
+ result := (1 = 2);
+ result := NOT result;
+ done := FALSE;
+ REPEAT
+ InOut.ReadInt (A);
+ InOut.ReadInt (B);
+ done := A > B
+ UNTIL done
+END boo.
diff --git a/Task/Boolean-values/Modula-3/boolean-values.mod3 b/Task/Boolean-values/Modula-3/boolean-values.mod3
new file mode 100644
index 0000000000..6b261e3c9d
--- /dev/null
+++ b/Task/Boolean-values/Modula-3/boolean-values.mod3
@@ -0,0 +1 @@
+TYPE BOOLEAN = {FALSE, TRUE}
diff --git a/Task/Box-the-compass/Groovy/box-the-compass.groovy b/Task/Box-the-compass/Groovy/box-the-compass.groovy
new file mode 100644
index 0000000000..ec1ea1e998
--- /dev/null
+++ b/Task/Box-the-compass/Groovy/box-the-compass.groovy
@@ -0,0 +1,22 @@
+def asCompassPoint(angle) {
+ def cardinalDirections = ["north", "east", "south", "west"]
+
+ int index = Math.floor(angle / 11.25 + 0.5)
+ int cardinalIndex = (index / 8)
+
+ def c1 = cardinalDirections[cardinalIndex % 4]
+ def c2 = cardinalDirections[(cardinalIndex + 1) % 4]
+ def c3 = (cardinalIndex == 0 || cardinalIndex == 2) ? "$c1$c2" : "$c2$c1"
+
+ def point = [
+ "$c1", "$c1 by $c2", "$c1-$c3", "$c3 by $c1", "$c3", "$c3 by $c2", "$c2-$c3", "$c2 by $c1"
+ ][index % 8]
+ point.substring(0, 1).toUpperCase() + point.substring(1)
+}
+Number.metaClass.asCompassPoint = { asCompassPoint(delegate) }
+
+[0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75,
+ 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5,
+ 354.37, 354.38].eachWithIndex { angle, index ->
+ println "${(index % 32) + 1}".padRight(3) + "${angle.asCompassPoint().padLeft(20)} $angle\u00b0"
+}
diff --git a/Task/Box-the-compass/Icon/box-the-compass.icon b/Task/Box-the-compass/Icon/box-the-compass.icon
new file mode 100644
index 0000000000..c1f1f16e6a
--- /dev/null
+++ b/Task/Box-the-compass/Icon/box-the-compass.icon
@@ -0,0 +1,26 @@
+link strings,numbers
+
+procedure main()
+
+every heading := 11.25 * (i := 0 to 32) do {
+ case i%3 of {
+ 1: heading +:= 5.62
+ 2: heading -:= 5.62
+ }
+ write(right(i+1,3)," ",left(direction(heading),20)," ",fix(heading,,7,2))
+ }
+end
+
+procedure direction(d) # compass heading given +/- degrees
+static dirs
+initial {
+ every put(dirs := [],
+ replacem(!["N","NbE","N-NE","NEbN","NE","NEbE","E-NE","EbN",
+ "E","EbS","E-SE","SEbE","SE","SEbS","S-SE","SbE",
+ "S","SbW","S-SW","SWbS","SW","SWbW","W-SW","WbS",
+ "W","WbN","W-NW","NWbW","NW","NWbN","N-NW","NbW"],
+ "N","north","E","east","W","west","S","south","b"," by "))
+ }
+
+ return dirs[round(((((d%360)+360)%360)/11.25)%32 + 1)]
+end
diff --git a/Task/Box-the-compass/J/box-the-compass-1.j b/Task/Box-the-compass/J/box-the-compass-1.j
new file mode 100644
index 0000000000..5b8dfa04f2
--- /dev/null
+++ b/Task/Box-the-compass/J/box-the-compass-1.j
@@ -0,0 +1,8 @@
+require'strings'
+subs=: 'N,north,S,south,E,east,W,west,b, by ,'
+dirs=: subs (toupper@{., }.)@rplc~L:1 0&(<;._2) 0 :0 -. ' ',LF
+ N,NbE,N-NE,NEbN,NE,NEbE,E-NE,EbN,E,EbS,E-SE,SEbE,SE,SEbS,S-SE,SbE,
+ S,SbW,S-SW,SWbS,SW,SWbW,W-SW,WbS,W,WbN,W-NW,NWbW,NW,NWbN,N-NW,NbW,
+)
+indice=: 32 | 0.5 <.@+ %&11.25
+deg2pnt=: dirs {~ indice
diff --git a/Task/Box-the-compass/J/box-the-compass-2.j b/Task/Box-the-compass/J/box-the-compass-2.j
new file mode 100644
index 0000000000..4f085db567
--- /dev/null
+++ b/Task/Box-the-compass/J/box-the-compass-2.j
@@ -0,0 +1,6 @@
+ i.10
+0 1 2 3 4 5 6 7 8 9
+ deg2pnt i.10
+┌─────┬─────┬─────┬─────┬─────┬─────┬─────────────┬─────────────┬─────────────┬─────────────┐
+│North│North│North│North│North│North│North by east│North by east│North by east│North by east│
+└─────┴─────┴─────┴─────┴─────┴─────┴─────────────┴─────────────┴─────────────┴─────────────┘
diff --git a/Task/Box-the-compass/J/box-the-compass-3.j b/Task/Box-the-compass/J/box-the-compass-3.j
new file mode 100644
index 0000000000..ffa5077b81
--- /dev/null
+++ b/Task/Box-the-compass/J/box-the-compass-3.j
@@ -0,0 +1,34 @@
+ (":@>:@indice,.' ',.>@deg2pnt,.' ',.":@,.)(*&11.25 + 5.62 * 0 1 _1 {~ 3&|) i.33
+1 North 0
+2 North by east 16.87
+3 North-northeast 16.88
+4 Northeast by north 33.75
+5 Northeast 50.62
+6 Northeast by east 50.63
+7 East-northeast 67.5
+8 East by north 84.37
+9 East 84.38
+10 East by south 101.25
+11 East-southeast 118.12
+12 Southeast by east 118.13
+13 Southeast 135
+14 Southeast by south 151.87
+15 South-southeast 151.88
+16 South by east 168.75
+17 South 185.62
+18 South by west 185.63
+19 South-southwest 202.5
+20 Southwest by south 219.37
+21 Southwest 219.38
+22 Southwest by west 236.25
+23 West-southwest 253.12
+24 West by south 253.13
+25 West 270
+26 West by north 286.87
+27 West-northwest 286.88
+28 Northwest by west 303.75
+29 Northwest 320.62
+30 Northwest by north 320.63
+31 North-northwest 337.5
+32 North by west 354.37
+1 North 354.38
diff --git a/Task/Box-the-compass/K/box-the-compass-1.k b/Task/Box-the-compass/K/box-the-compass-1.k
new file mode 100644
index 0000000000..c637148ee0
--- /dev/null
+++ b/Task/Box-the-compass/K/box-the-compass-1.k
@@ -0,0 +1,16 @@
+ d:("N;Nbe;N-ne;Nebn;Ne;Nebe;E-ne;Ebn;")
+ d,:("E;Ebs;E-se;Sebe;Se;Sebs;S-se;Sbe;")
+ d,:("S;Sbw;S-sw;Swbs;Sw;Swbw;W-sw;Wbs;")
+ d,:("W;Wbn;W-nw;Nwbw;Nw;Nwbn;N-nw;Nbw;N")
+
+ split:{1_'(&x=y)_ x:y,x}
+ dd:split[d;";"]
+
+ / lookup table
+ s1:"NEWSnewsb-"
+ s2:("North";"East";"West";"South";"north";"east";"west";"south";" by ";"-")
+ c:.({`$x}'s1),'{`$x}'s2 / create the dictionary
+ cc:{,/{$c[`$$x]}'x} / lookup function
+
+ / calculate the degrees
+ f:{m:x!3;(11.25*x)+:[1=m;+5.62;2=m;-5.62;0]}
diff --git a/Task/Box-the-compass/K/box-the-compass-2.k b/Task/Box-the-compass/K/box-the-compass-2.k
new file mode 100644
index 0000000000..42eb8efc38
--- /dev/null
+++ b/Task/Box-the-compass/K/box-the-compass-2.k
@@ -0,0 +1,34 @@
+ `0:{((2$(1+x!32))," ",(-19$cc@dd[x]),(6.2$f@x))}'!#dd
+ 1 North 0.00
+ 2 North by east 16.87
+ 3 North-northeast 16.88
+ 4 Northeast by north 33.75
+ 5 Northeast 50.62
+ 6 Northeast by east 50.63
+ 7 East-northeast 67.50
+ 8 East by north 84.37
+ 9 East 84.38
+10 East by south 101.25
+11 East-southeast 118.12
+12 Southeast by east 118.13
+13 Southeast 135.00
+14 Southeast by south 151.87
+15 South-southeast 151.88
+16 South by east 168.75
+17 South 185.62
+18 South by west 185.63
+19 South-southwest 202.50
+20 Southwest by south 219.37
+21 Southwest 219.38
+22 Southwest by west 236.25
+23 West-southwest 253.12
+24 West by south 253.13
+25 West 270.00
+26 West by north 286.87
+27 West-northwest 286.88
+28 Northwest by west 303.75
+29 Northwest 320.62
+30 Northwest by north 320.63
+31 North-northwest 337.50
+32 North by west 354.37
+ 1 North 354.38
diff --git a/Task/Box-the-compass/Liberty-BASIC/box-the-compass.liberty b/Task/Box-the-compass/Liberty-BASIC/box-the-compass.liberty
new file mode 100644
index 0000000000..97ff2cbf48
--- /dev/null
+++ b/Task/Box-the-compass/Liberty-BASIC/box-the-compass.liberty
@@ -0,0 +1,34 @@
+dim point$( 32)
+
+for i =1 to 32
+ read d$: point$( i) =d$
+next i
+
+for i = 0 to 32
+ heading = i *11.25
+ if ( i mod 3) =1 then
+ heading = heading +5.62
+ else
+ if ( i mod 3) =2 then heading = heading -5.62
+ end if
+ ind = i mod 32 +1
+ print ind, compasspoint$( heading), heading
+next i
+
+end
+
+function compasspoint$( h)
+ x = h /11.25 +1.5
+ if (x >=33.0) then x =x -32.0
+ compasspoint$ = point$( int( x))
+end function
+
+data "North ", "North by east ", "North-northeast "
+data "Northeast by north", "Northeast ", "Northeast by east ", "East-northeast "
+data "East by north ", "East ", "East by south ", "East-southeast "
+data "Southeast by east ", "Southeast ", "Southeast by south", "South-southeast "
+data "South by east ", "South ", "South by west ", "South-southwest "
+data "Southwest by south", "Southwest ", "Southwest by west ", "West-southwest "
+data "West by south ", "West ", "West by north ", "West-northwest "
+data "Northwest by west ", "Northwest ", "Northwest by north", "North-northwest "
+data "North by west
diff --git a/Task/Box-the-compass/Logo/box-the-compass.logo b/Task/Box-the-compass/Logo/box-the-compass.logo
new file mode 100644
index 0000000000..2222e56bb1
--- /dev/null
+++ b/Task/Box-the-compass/Logo/box-the-compass.logo
@@ -0,0 +1,64 @@
+; List of abbreviated compass point labels
+make "compass_points [ N NbE N-NE NEbN NE NEbE E-NE EbN
+ E EbS E-SE SEbE SE SEbS S-SE SbE
+ S SbW S-SW SWbS SW SWbW W-SW WbS
+ W WbN W-NW NWbW NW NWbN N-NW NbW ]
+
+; List of angles to test
+make "test_angles [ 0.00 16.87 16.88 33.75 50.62 50.63 67.50
+ 84.37 84.38 101.25 118.12 118.13 135.00 151.87
+ 151.88 168.75 185.62 185.63 202.50 219.37 219.38
+ 236.25 253.12 253.13 270.00 286.87 286.88 303.75
+ 320.62 320.63 337.50 354.37 354.38 ]
+
+; make comparisons case-sensitive
+make "caseignoredp "false
+
+; String utilities: search and replace
+to replace_in :src :from :to
+ output map [ ifelse equalp ? :from [:to] [?] ] :src
+end
+
+; pad with spaces
+to pad :string :length
+ output cascade [lessp :length count ?] [word ? "\ ] :string
+end
+
+; capitalize first letter
+to capitalize :string
+ output word (uppercase first :string) butfirst :string
+end
+
+; convert compass point abbreviation to full text of label
+to expand_point :abbr
+ foreach [[N north] [E east] [S south] [W west] [b \ by\ ]] [
+ make "abbr replace_in :abbr (first ?) (last ?)
+ ]
+ output capitalize :abbr
+end
+
+; modulus function that returns 1..N instead of 0..N-1
+to adjusted_modulo :n :d
+ output sum 1 modulo (difference :n 1) :d
+end
+
+; convert a compass angle from degrees into a box index (1..32)
+to compass_point :degrees
+ make "degrees modulo :degrees 360
+ output adjusted_modulo (sum 1 int quotient (sum :degrees 5.625) 11.25) 32
+end
+
+; Now output the table of test data
+print (sentence (pad "Degrees 7) "\| (pad "Closest\ Point 18) "\| "Index )
+foreach :test_angles [
+ local "index
+ make "index compass_point ?
+ local "abbr
+ make "abbr item :index :compass_points
+ local "label
+ make "label expand_point :abbr
+ print (sentence (form ? 7 2) "\| (pad :label 18) "\| (form :index 2 0) )
+]
+
+; and exit
+bye
diff --git a/Task/Box-the-compass/MUMPS/box-the-compass.mumps b/Task/Box-the-compass/MUMPS/box-the-compass.mumps
new file mode 100644
index 0000000000..ed71bc4008
--- /dev/null
+++ b/Task/Box-the-compass/MUMPS/box-the-compass.mumps
@@ -0,0 +1,34 @@
+BOXING(DEGREE)
+ ;This takes in a degree heading, nominally from 0 to 360, and returns the compass point name.
+ QUIT:((DEGREE<0)||(DEGREE>360)) "land lubber can't read a compass"
+ NEW DIRS,UNP,UNPACK,SEP,DIR,DOS,D,DS,I,F
+ SET DIRS="N^NbE^N-NE^NEbN^NE^NEbE^E-NE^EbN^E^EbS^E-SE^SEbE^SE^SEbS^S-SE^SbE^"
+ SET DIRS=DIRS_"S^SbW^S-SW^SWbS^SW^SWbW^W-SW^WbS^W^WbN^W-NW^NWbW^NW^NWbN^N-NW^NbW"
+ SET UNP="NESWb"
+ SET UNPACK="north^east^south^west^ by "
+ SET SEP=360/$LENGTH(DIRS,"^")
+ SET DIR=(DEGREE/SEP)+1.5
+ SET DIR=$SELECT((DIR>33):DIR-32,1:DIR)
+ SET DOS=$NUMBER(DIR-.5,0)
+ SET D=$PIECE(DIRS,"^",DIR)
+ SET DS=""
+ FOR I=1:1:$LENGTH(D) DO
+ . SET F=$FIND(UNP,$EXTRACT(D,I)) SET DS=DS_$SELECT((F>0):$PIECE(UNPACK,"^",F-1),1:$E(D,I))
+ KILL DIRS,UNP,UNPACK,SEP,DIR,D,I,F
+ QUIT DOS_"^"_DS
+
+BOXWRITE
+ NEW POINTS,UP,LO,DIR,P,X
+ SET POINTS="0.0,16.87,16.88,33.75,50.62,50.63,67.5,84.37,84.38,101.25,118.12,118.13,135.0,151.87,"
+ SET POINTS=POINTS_"151.88,168.75,185.62,185.63,202.5,219.37,219.38,236.25,253.12,253.13,270.0,286.87,"
+ SET POINTS=POINTS_"286.88,303.75,320.62,320.63,337.5,354.37,354.38"
+ SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ SET LO="abcdefghijklmnopqrstuvwxyz"
+ FOR P=1:1:$LENGTH(POINTS,",") DO
+ . SET X=$$BOXING($PIECE(POINTS,",",P))
+ . ;Capitalize the initial letter of the direction
+ . SET DIR=$PIECE(X,"^",2)
+ . SET DIR=$TRANSLATE($EXTRACT(DIR,1),LO,UP)_$EXTRACT(DIR,2,$LENGTH(DIR))
+ . WRITE $PIECE(X,"^"),?5,DIR,?40,$JUSTIFY($PIECE(POINTS,",",P),10,2),!
+ KILL POINTS,UP,LO,DIR,P,X
+ QUIT
diff --git a/Task/Box-the-compass/Mathematica/box-the-compass.mathematica b/Task/Box-the-compass/Mathematica/box-the-compass.mathematica
new file mode 100644
index 0000000000..9a210ed4dc
--- /dev/null
+++ b/Task/Box-the-compass/Mathematica/box-the-compass.mathematica
@@ -0,0 +1,2 @@
+Map[List[Part[#,1], dirs[[Part[#,1]]], ToString@Part[#,2]<>"°"]&,
+ Map[{Floor[Mod[ #+5.625 , 360]/11.25]+1,#}&,input] ]//TableForm
diff --git a/Task/Break-OO-privacy/Factor/break-oo-privacy-1.factor b/Task/Break-OO-privacy/Factor/break-oo-privacy-1.factor
new file mode 100644
index 0000000000..a0a2c89760
--- /dev/null
+++ b/Task/Break-OO-privacy/Factor/break-oo-privacy-1.factor
@@ -0,0 +1,3 @@
+( scratchpad ) USING: sets sets.private ;
+( scratchpad ) { 1 2 3 } { 1 2 4 } sequence/tester count .
+2
diff --git a/Task/Break-OO-privacy/Factor/break-oo-privacy-2.factor b/Task/Break-OO-privacy/Factor/break-oo-privacy-2.factor
new file mode 100644
index 0000000000..90c941cc96
--- /dev/null
+++ b/Task/Break-OO-privacy/Factor/break-oo-privacy-2.factor
@@ -0,0 +1,3 @@
+( scratchpad ) USE: sets
+( scratchpad ) { 1 2 3 } { 1 2 4 } intersect length .
+2
diff --git a/Task/Break-OO-privacy/Factor/break-oo-privacy-3.factor b/Task/Break-OO-privacy/Factor/break-oo-privacy-3.factor
new file mode 100644
index 0000000000..1f5f38b3c2
--- /dev/null
+++ b/Task/Break-OO-privacy/Factor/break-oo-privacy-3.factor
@@ -0,0 +1,17 @@
+link printf
+
+procedure main()
+ (x := foo(1,2,3)).print() # create and show a foo
+ printf("Fieldnames of foo x : ") # show fieldnames
+ every printf(" %i",fieldnames(x)) # __s (self), __m (methods), vars
+ printf("\n")
+ printf("var 1 of foo x = %i\n", x.var1) # read var1 from outside x
+ x.var1 := -1 # change var1 from outside x
+ x.print() # show we changed it
+end
+
+class foo(var1,var2,var3) # class with no set/read methods
+ method print()
+ printf("foo var1=%i, var2=%i, var3=%i\n",var1,var2,var3)
+ end
+end
diff --git a/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-1.j b/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-1.j
new file mode 100644
index 0000000000..6545509746
--- /dev/null
+++ b/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-1.j
@@ -0,0 +1,18 @@
+require'misc'
+
+poss=:1+~.4{."1 (i.!9)A.i.9
+fmt=: ' ' -.~ ":
+
+play=:3 :0
+ while.1<#poss=.poss do.
+ smoutput'guessing ',fmt guess=.({~ ?@#)poss
+ bc=.+/\_".prompt 'how many bull and cows? '
+ poss=.poss #~({.bc)=guess+/@:="1 poss
+ poss=.poss #~({:bc)=guess+/@e."1 poss
+ end.
+ if.#poss do.
+ 'the answer is ',fmt,poss
+ else.
+ 'no valid possibilities'
+ end.
+)
diff --git a/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-2.j b/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-2.j
new file mode 100644
index 0000000000..5c47d29349
--- /dev/null
+++ b/Task/Bulls-and-cows-Player/J/bulls-and-cows-player-2.j
@@ -0,0 +1,10 @@
+ play''
+guessing 7461
+how many bull and cows? 0 1
+guessing 3215
+how many bull and cows? 0 3
+guessing 2357
+how many bull and cows? 2 0
+guessing 1359
+how many bull and cows? 3 0
+the answer is 1358
diff --git a/Task/Bulls-and-cows-Player/Liberty-BASIC/bulls-and-cows-player.liberty b/Task/Bulls-and-cows-Player/Liberty-BASIC/bulls-and-cows-player.liberty
new file mode 100644
index 0000000000..49a92f7b2e
--- /dev/null
+++ b/Task/Bulls-and-cows-Player/Liberty-BASIC/bulls-and-cows-player.liberty
@@ -0,0 +1,99 @@
+guesses =0
+
+do while len( secret$) <4 ' zero not allowed <<<<<<<<<
+ n$ =chr$( int( rnd( 1) *9) +49)
+ if not( instr( secret$, n$)) then secret$ =secret$ +n$
+loop
+
+print " Secretly, my opponent just chose a number. But she didn't tell anyone! "; secret$; "."
+print " I can however be given a score for my guesses."
+
+for i =1234 to 9876 ' <<<<<<<<<
+ if check( str$( i)) =0 then available$ =available$ +" " +str$( i): k =k +1
+next i
+
+available$ =trim$( available$) ' remove the surplus, leading space
+
+print
+print "Currently holding "; k; " possible numbers. "
+
+while 1
+ guess$ =word$( available$, 1 +int( k *rnd( 1)), " ")
+ print
+ print "Computer guessed "; guess$; " & got ";
+
+ bulls =0
+ cows =0
+ guesses =guesses +1
+
+ r$ =score$( guess$, secret$)
+
+ bulls =val( word$( r$, 1, ","))
+ cows =val( word$( r$, 2, ","))
+
+ print bulls; " bull(s), and "; cows; " cow(s), .... ";
+
+ if guess$ =secret$ then
+ print "Computer won after "; guesses; " guesses!";
+ secs =( time$( "seconds") -now +86400) mod 86400
+ print " That took "; secs; " seconds. ENDED!"
+ print
+ print " Now scroll right to see original choice and check!"
+ exit while
+ end if
+
+ print " so possible numbers are now only..."
+ kk =0
+ new$ =""
+
+ for j =1 to k
+ bullsT =0
+ cowsT =0
+
+ possible$ =word$( available$, j, " ")
+
+ r$ =score$( guess$, possible$)
+
+ bullsT =val( word$( r$, 1, ","))
+ cowsT =val( word$( r$, 2, ","))
+
+ if ( bullsT =bulls) and ( cowsT =cows) then
+ new$ =new$ +" " +possible$ ' keep those with same score
+ kk =kk +1
+ print possible$; " ";
+ if ( kk mod 20) =0 then print
+ end if
+
+ scan
+ next j
+
+ available$ =trim$( new$)
+ k =kk
+
+ scan
+wend
+
+end
+
+function score$( a$, b$) ' return as a csv string the number of bulls & cows.
+ bulls = 0: cows = 0
+ for i = 1 to 4
+ c$ = mid$( a$, i, 1)
+ if mid$( b$, i, 1) = c$ then
+ bulls = bulls + 1
+ else
+ if instr( b$, c$) <>0 and instr( b$, c$) <>i then cows = cows + 1
+ end if
+ next i
+ score$ =str$( bulls); ","; str$( cows)
+end function
+
+function check( i$)
+ check =0 ' zero flags available: 1 means not available
+ for i =1 to 3
+ for j =i +1 to 4
+ if mid$( i$, i, 1) =mid$( i$, j, 1) then check =1
+ next j
+ next i
+ if instr( i$, "0") then check =1
+end function
diff --git a/Task/Bulls-and-cows-Player/Mathematica/bulls-and-cows-player.mathematica b/Task/Bulls-and-cows-Player/Mathematica/bulls-and-cows-player.mathematica
new file mode 100644
index 0000000000..cfda7f31ad
--- /dev/null
+++ b/Task/Bulls-and-cows-Player/Mathematica/bulls-and-cows-player.mathematica
@@ -0,0 +1,14 @@
+bullCow={Count[#1-#2,0],Length[#1\[Intersection]#2]-Count[#1-#2,0]}&;
+Module[{r,input,candidates=Permutations[Range[9],{4}]},
+While[True,
+ r=InputString[];
+ If[r===$Canceled,Break[],
+ input=ToExpression/@StringSplit@r;
+ If[Length@input!=3,Print["Input the guess, number of bulls, number of cows, delimited by space."],
+ candidates=Select[candidates,bullCow[ToCharacterCode@StringJoin[ToString/@#],ToCharacterCode@ToString@input[[1]]]==input[[2;;3]]&];
+ candidates=SortBy[candidates,{-3,-1}.bullCow[ToCharacterCode@StringJoin[ToString/@#],ToCharacterCode@ToString@input[[1]]]&];
+ If[candidates==={},Print["No more candidates."];Break[]];
+ If[Length@candidates==1,Print["Must be: "<>StringJoin[ToString/@candidates[[1]]]];Break[]];
+ Print[ToString@Length@candidates<>" candidates remaining."];
+ Print["Can try "<>StringJoin[ToString/@First@candidates]<>"."];
+ ]]]]
diff --git a/Task/Bulls-and-cows/Factor/bulls-and-cows.factor b/Task/Bulls-and-cows/Factor/bulls-and-cows.factor
new file mode 100644
index 0000000000..8c23f8d6dc
--- /dev/null
+++ b/Task/Bulls-and-cows/Factor/bulls-and-cows.factor
@@ -0,0 +1,64 @@
+USING: accessors assocs combinators fry grouping hashtables kernel
+ locals math math.parser math.ranges random sequences strings
+ io ascii ;
+
+IN: bullsncows
+
+TUPLE: score bulls cows ;
+: ( -- score ) 0 0 score boa ;
+
+TUPLE: cow ;
+: ( -- cow ) cow new ;
+
+TUPLE: bull ;
+: ( -- bull ) bull new ;
+
+: inc-bulls ( score -- score ) dup bulls>> 1 + >>bulls ;
+: inc-cows ( score -- score ) dup cows>> 1 + >>cows ;
+
+: random-nums ( -- seq ) 9 [1,b] 4 sample ;
+
+: add-digits ( seq -- n ) 0 [ swap 10 * + ] reduce number>string ;
+
+: new-number ( -- n narr ) random-nums dup add-digits ;
+
+: narr>nhash ( narr -- nhash ) { 1 2 3 4 } swap zip ;
+
+: num>hash ( n -- hash )
+ [ 1string string>number ] { } map-as narr>nhash ;
+
+:: cow-or-bull ( n g -- arr )
+ {
+ { [ n first g at n second = ] [ ] }
+ { [ n second g value? ] [ ] }
+ [ f ]
+ } cond ;
+
+: add-to-score ( arr -- score )
+ [ bull? [ inc-bulls ] [ inc-cows ] if ] reduce ;
+
+: check-win ( score -- ? ) bulls>> 4 = ;
+
+: sum-score ( n g -- score ? )
+ '[ _ cow-or-bull ] map sift add-to-score dup check-win ;
+
+: print-sum ( score -- str )
+ dup bulls>> number>string "Bulls: " swap append swap cows>> number>string
+ " Cows: " swap 3append "\n" append ;
+
+: (validate-readln) ( str -- ? ) dup length 4 = not swap [ letter? ] all? or ;
+
+: validate-readln ( -- str )
+ readln dup (validate-readln)
+ [ "Invalid input.\nPlease enter a valid 4 digit number: "
+ write flush drop validate-readln ]
+ when ;
+
+: win ( -- ) "\nYou've won! Good job. You're so smart." print flush ;
+
+: main-loop ( x -- )
+ "Enter a 4 digit number: " write flush validate-readln num>hash swap
+ [ sum-score swap print-sum print flush ] keep swap not
+ [ main-loop ] [ drop win ] if ;
+
+: main ( -- ) new-number drop narr>nhash main-loop ;
diff --git a/Task/Bulls-and-cows/Fan/bulls-and-cows.fan b/Task/Bulls-and-cows/Fan/bulls-and-cows.fan
new file mode 100644
index 0000000000..51a650ab8d
--- /dev/null
+++ b/Task/Bulls-and-cows/Fan/bulls-and-cows.fan
@@ -0,0 +1,50 @@
+**
+** Bulls and cows. A game pre-dating, and similar to, Mastermind.
+**
+class BullsAndCows
+{
+
+ Void main()
+ {
+ digits := [1,2,3,4,5,6,7,8,9]
+ size := 4
+ chosen := [,]
+ size.times { chosen.add(digits.removeAt(Int.random(0..= '1' && ch <= '9' && !guess.contains(ch)) guess.add(ch-'0') }
+ if (guess.size == 4)
+ break // input loop
+ echo("Oops, try again. You need to enter $size unique digits from 1 to 9")
+ }
+ if (guess.all |v, i->Bool| { return v == chosen[i] })
+ {
+ echo("\nCongratulations! You guessed correctly in $guesses guesses")
+ break // game loop
+ }
+ bulls := 0
+ cows := 0
+ (0 ..< size).each |i|
+ {
+ if (guess[i] == chosen[i])
+ bulls += 1
+ else if (chosen.contains(guess[i]))
+ cows += 1
+ }
+ echo("\n $bulls Bulls\n $cows Cows")
+ }
+ }
+}
diff --git a/Task/Bulls-and-cows/Icon/bulls-and-cows.icon b/Task/Bulls-and-cows/Icon/bulls-and-cows.icon
new file mode 100644
index 0000000000..51533e7eb6
--- /dev/null
+++ b/Task/Bulls-and-cows/Icon/bulls-and-cows.icon
@@ -0,0 +1,24 @@
+procedure main()
+ digits := "123456789"
+ every !digits :=: ?digits
+ num := digits[1+:4]
+ repeat if score(num, getGuess(num)) then break
+ write("Good job.")
+end
+
+procedure getGuess(num)
+ repeat {
+ writes("Enter a guess: ")
+ guess := read() | stop("Quitter!")
+ if *(guess ** '123456789') == *num then return guess
+ write("Malformed guess: ",guess,". Try again.")
+ }
+end
+
+procedure score(num, guess)
+ bulls := 0
+ cows := *(num ** guess)
+ every (num[i := 1 to *num] == guess[i], bulls +:= 1, cows -:= 1)
+ write("\t",bulls," bulls and ",cows," cows")
+ return (bulls = *num)
+end
diff --git a/Task/Bulls-and-cows/J/bulls-and-cows-1.j b/Task/Bulls-and-cows/J/bulls-and-cows-1.j
new file mode 100644
index 0000000000..de0d1d72bb
--- /dev/null
+++ b/Task/Bulls-and-cows/J/bulls-and-cows-1.j
@@ -0,0 +1,24 @@
+require 'misc'
+
+plural=: conjunction define
+ (":m),' ',n,'s'#~1~:m
+)
+
+bullcow=:monad define
+ number=. 1+4?9
+ whilst. -.guess-:number do.
+ guess=. 0 "."0 prompt 'Guess my number: '
+ if. (4~:#guess)+.(4~:#~.guess)+.0 e.guess e.1+i.9 do.
+ if. 0=#guess do.
+ smoutput 'Giving up.'
+ return.
+ end.
+ smoutput 'Guesses must be four different non-zero digits'
+ continue.
+ end.
+ bulls=. +/guess=number
+ cows=. (+/guess e.number)-bulls
+ smoutput bulls plural 'bull',' and ',cows plural 'cow','.'
+ end.
+ smoutput 'you win'
+)
diff --git a/Task/Bulls-and-cows/J/bulls-and-cows-2.j b/Task/Bulls-and-cows/J/bulls-and-cows-2.j
new file mode 100644
index 0000000000..2d74b0eb9a
--- /dev/null
+++ b/Task/Bulls-and-cows/J/bulls-and-cows-2.j
@@ -0,0 +1,16 @@
+ bullcow''
+Guess my number: 1234
+0 bulls and 1 cow.
+Guess my number: 5678
+3 bulls and 0 cows.
+Guess my number: 2349
+0 bulls and 0 cows.
+Guess my number: 1567
+0 bulls and 3 cows.
+Guess my number: 6178
+3 bulls and 0 cows.
+Guess my number: 6157
+1 bull and 2 cows.
+Guess my number: 5178
+4 bulls and 0 cows.
+you win
diff --git a/Task/Bulls-and-cows/Julia/bulls-and-cows.julia b/Task/Bulls-and-cows/Julia/bulls-and-cows.julia
new file mode 100644
index 0000000000..adbc927e0a
--- /dev/null
+++ b/Task/Bulls-and-cows/Julia/bulls-and-cows.julia
@@ -0,0 +1,22 @@
+function cowsbulls()
+ print("Welcome to Cows & Bulls! I've picked a 4 digit number, go ahead and type your guess.\n
+ You get one bull for every right number in the right position.\n
+ You get one cow for every right number in the wrong position.\n
+ Enter 'n' to pick a new number and 'q' to quit.\n>")
+ new_number() = string(rand(1:9))*string(rand(1:9))*string(rand(1:9))*string(rand(1:9))
+ answer = new_number()
+ while true
+ input = chomp(readline(STDIN))
+ input == "q" && break
+ input == "n" && begin answer = new_number(); print("\nLet's try again, go ahead and guess\n>"); continue end
+ !ismatch(r"^[1-9]{4}$",string(input)) && begin print("Invalid guess: Please enter a 4-digit number\n"); continue end
+ if input == answer
+ print("\nYou're right! Good guessing!\nEnter 'n' for a new number or 'q' to quit\n>")
+ continue
+ else
+ bulls = sum(answer.data .== input.data)
+ cows = sum([answer[x] != input[x] && contains(input.data,answer[x]) for x = 1:4])
+ print("\nNot quite! Your guess is worth:\n$bulls Bulls\n$cows Cows\nPlease guess again\n\n>")
+ end
+ end
+end
diff --git a/Task/Bulls-and-cows/Liberty-BASIC/bulls-and-cows.liberty b/Task/Bulls-and-cows/Liberty-BASIC/bulls-and-cows.liberty
new file mode 100644
index 0000000000..b9f5b34516
--- /dev/null
+++ b/Task/Bulls-and-cows/Liberty-BASIC/bulls-and-cows.liberty
@@ -0,0 +1,61 @@
+ do while len( secret$) <4
+ c$ =chr$( int( rnd( 1) *9) +49)
+ if not( instr( secret$, c$)) then secret$ =secret$ +c$
+ loop
+
+ print " Secret number has been guessed.... "; secret$
+
+ guesses = 0
+
+[loop]
+ print " Your guess ";
+ input " "; guess$
+
+ guesses = guesses +1
+
+ r$ =score$( guess$, secret$)
+
+ bulls =val( word$( r$, 1, ","))
+ cows =val( word$( r$, 2, ","))
+
+ print " Result: "; bulls; " bulls, and "; cows; " cows"
+ print
+
+ if guess$ =secret$ then
+ print " You won after "; guesses; " guesses!"
+ print " You guessed it in "; guesses
+ print " Thanks for playing!"
+ wait
+ end if
+
+ goto [loop]
+
+end ' _____________________________________________________________
+
+function check( i$) ' check =0 if no digit repeats, else =1
+ check =0
+ for i =1 to 3
+ for j =i +1 to 4
+ if mid$( i$, i, 1) =mid$( i$, j, 1) then check =1
+ next j
+ next i
+end function
+
+function score$( a$, b$) ' return as a csv string the number of bulls & cows.
+ bulls = 0: cows = 0
+ for i = 1 to 4
+ c$ = mid$( a$, i, 1)
+ if mid$( b$, i, 1) = c$ then
+ bulls = bulls + 1
+ else
+ if instr( b$, c$) <>0 and instr( b$, c$) <>i then
+ cows = cows + 1
+ end if
+ end if
+ next i
+ score$ =str$( bulls); ","; str$( cows)
+end function
+
+[quit]
+close #w
+end
diff --git a/Task/Bulls-and-cows/Logo/bulls-and-cows.logo b/Task/Bulls-and-cows/Logo/bulls-and-cows.logo
new file mode 100644
index 0000000000..25edf2483e
--- /dev/null
+++ b/Task/Bulls-and-cows/Logo/bulls-and-cows.logo
@@ -0,0 +1,19 @@
+to ok? :n
+ output (and [number? :n] [4 = count :n] [4 = count remdup :n] [not member? 0 :n])
+end
+
+to init
+ do.until [make "hidden random 10000] [ok? :hidden]
+end
+
+to guess :n
+ if not ok? :n [print [Bad guess! (4 unique digits, 1-9)] stop]
+ localmake "bulls 0
+ localmake "cows 0
+ foreach :n [cond [
+ [[? = item # :hidden] make "bulls 1 + :bulls]
+ [[member? ? :hidden] make "cows 1 + :cows ]
+ ]]
+ (print :bulls "bulls, :cows "cows)
+ if :bulls = 4 [print [You guessed it!]]
+end
diff --git a/Task/Bulls-and-cows/MUMPS/bulls-and-cows.mumps b/Task/Bulls-and-cows/MUMPS/bulls-and-cows.mumps
new file mode 100644
index 0000000000..0de561f541
--- /dev/null
+++ b/Task/Bulls-and-cows/MUMPS/bulls-and-cows.mumps
@@ -0,0 +1,65 @@
+BullCow New bull,cow,guess,guessed,ii,number,pos,x
+ Set number="",x=1234567890
+ For ii=1:1:4 Do
+ . Set pos=$Random($Length(x))+1
+ . Set number=number_$Extract(x,pos)
+ . Set $Extract(x,pos)=""
+ . Quit
+ Write !,"The computer has selected a number that consists"
+ Write !,"of four different digits."
+ Write !!,"As you are guessing the number, ""bulls"" and ""cows"""
+ Write !,"will be awarded: a ""bull"" for each digit that is"
+ Write !,"placed in the correct position, and a ""cow"" for each"
+ Write !,"digit that occurs in the number, but in a different place.",!
+ Write !,"For a guess, enter 4 digits."
+ Write !,"Any other input is interpreted as ""I give up"".",!
+ Set guessed=0 For Do Quit:guessed
+ . Write !,"Your guess: " Read guess If guess'?4n Set guessed=-1 Quit
+ . Set (bull,cow)=0,x=guess
+ . For ii=4:-1:1 If $Extract(x,ii)=$Extract(number,ii) Do
+ . . Set bull=bull+1,$Extract(x,ii)=""
+ . . Quit
+ . For ii=1:1:$Length(x) Set:number[$Extract(x,ii) cow=cow+1
+ . Write !,"You guessed ",guess,". That earns you "
+ . If 'bull,'cow Write "neither bulls nor cows..." Quit
+ . If bull Write bull," bull" Write:bull>1 "s"
+ . If cow Write:bull " and " Write cow," cow" Write:cow>1 "s"
+ . Write "."
+ . If bull=4 Set guessed=1 Write !,"That's a perfect score."
+ . Quit
+ If guessed<0 Write !!,"The number was ",number,".",!
+ Quit
+Do BullCow
+
+The computer has selected a number that consists
+of four different digits.
+
+As you are guessing the number, "bulls" and "cows"
+will be awarded: a "bull" for each digit that is
+placed in the correct position, and a "cow" for each
+digit that occurs in the number, but in a different place.
+
+For a guess, enter 4 digits.
+Any other input is interpreted as "I give up".
+
+Your guess: 1234
+You guessed 1234. That earns you 1 cow.
+Your guess: 5678
+You guessed 5678. That earns you 1 cow.
+Your guess: 9815
+You guessed 9815. That earns you 1 cow.
+Your guess: 9824
+You guessed 9824. That earns you 2 cows.
+Your guess: 9037
+You guessed 9037. That earns you 1 bull and 2 cows.
+Your guess: 9048
+You guessed 2789. That earns you 1 bull and 2 cows.
+Your guess: 2079
+You guessed 2079. That earns you 1 bull and 3 cows.
+Your guess: 2709
+You guessed 2709. That earns you 2 bulls and 2 cows.
+Your guess: 0729
+You guessed 0729. That earns you 4 cows.
+Your guess: 2907
+You guessed 2907. That earns you 4 bulls.
+That's a perfect score.
diff --git a/Task/Bulls-and-cows/Mathematica/bulls-and-cows.mathematica b/Task/Bulls-and-cows/Mathematica/bulls-and-cows.mathematica
new file mode 100644
index 0000000000..4eb601dc33
--- /dev/null
+++ b/Task/Bulls-and-cows/Mathematica/bulls-and-cows.mathematica
@@ -0,0 +1,12 @@
+digits=Last@FixedPointList[If[Length@Union@#==4,#,Table[Random[Integer,{1,9}],{4}]]&,{}]
+codes=ToCharacterCode[StringJoin[ToString/@digits]];
+Module[{r,bulls,cows},
+ While[True,
+ r=InputString[];
+ If[r===$Canceled,Break[],
+ With[{userCodes=ToCharacterCode@r},
+ If[userCodes===codes,Print[r<>": You got it!"];Break[],
+ If[Length@userCodes==Length@codes,
+ bulls=Count[userCodes-codes,0];cows=Length@Intersection[codes,userCodes]-bulls;
+ Print[r<>": "<>ToString[bulls]<>"bull(s), "<>ToString@cows<>"cow(s)."],
+ Print["Guess four digits."]]]]]]]
diff --git a/Task/CRC-32/Icon/crc-32.icon b/Task/CRC-32/Icon/crc-32.icon
new file mode 100644
index 0000000000..9d4cee5f2b
--- /dev/null
+++ b/Task/CRC-32/Icon/crc-32.icon
@@ -0,0 +1,33 @@
+link hexcvt,printf
+
+procedure main()
+ s := "The quick brown fox jumps over the lazy dog"
+ a := "414FA339"
+ printf("crc(%i)=%s - implementation is %s\n",
+ s,r := crc32(s),if r == a then "correct" else "in error")
+end
+
+procedure crc32(s) #: return crc-32 (ISO 3309, ITU-T V.42, Gzip, PNG) of s
+static crcL,mask
+initial {
+ crcL := list(256) # crc table
+ p := [0,1,2,4,5,7,8,10,11,12,16,22,23,26] # polynomial terms
+ mask := 2^32-1 # word size mask
+ every (poly := 0) := ior(poly,ishift(1,31-p[1 to *p]))
+ every c := n := 0 to *crcL-1 do { # table
+ every 1 to 8 do
+ c := iand(mask,
+ if iand(c,1) = 1 then
+ ixor(poly,ishift(c,-1))
+ else
+ ishift(c,-1)
+ )
+ crcL[n+1] := c
+ }
+ }
+
+ crc := ixor(0,mask) # invert bits
+ every crc := iand(mask,
+ ixor(crcL[iand(255,ixor(crc,ord(!s)))+1],ishift(crc,-8)))
+ return hexstring(ixor(crc,mask)) # return hexstring
+end
diff --git a/Task/CRC-32/J/crc-32-1.j b/Task/CRC-32/J/crc-32-1.j
new file mode 100644
index 0000000000..3b091dd93f
--- /dev/null
+++ b/Task/CRC-32/J/crc-32-1.j
@@ -0,0 +1,2 @@
+ ((i.32) e. 32 26 23 22 16 12 11 10 8 7 5 4 2 1 0) 128!:3 'The quick brown fox jumps over the lazy dog'
+_3199229127
diff --git a/Task/CRC-32/J/crc-32-2.j b/Task/CRC-32/J/crc-32-2.j
new file mode 100644
index 0000000000..a6e7be888e
--- /dev/null
+++ b/Task/CRC-32/J/crc-32-2.j
@@ -0,0 +1,5 @@
+ (2^32x)|((i.32) e. 32 26 23 22 16 12 11 10 8 7 5 4 2 1 0) 128!:3 'The quick brown fox jumps over the lazy dog'
+1095738169
+ require'convert'
+ hfd (2^32x)|((i.32) e. 32 26 23 22 16 12 11 10 8 7 5 4 2 1 0) 128!:3 'The quick brown fox jumps over the lazy dog'
+414FA339
diff --git a/Task/CRC-32/Mathematica/crc-32.mathematica b/Task/CRC-32/Mathematica/crc-32.mathematica
new file mode 100644
index 0000000000..a3a1c7c150
--- /dev/null
+++ b/Task/CRC-32/Mathematica/crc-32.mathematica
@@ -0,0 +1,2 @@
+IntegerString[Hash["The quick brown fox jumps over the lazy dog", "CRC32"], 16, 8]
+-> "414fa339"
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-1.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-1.groovy
new file mode 100644
index 0000000000..40cb9c49d2
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-1.groovy
@@ -0,0 +1,38 @@
+def formatCell = { cell ->
+ "${cell.replaceAll('&','&').replaceAll('<','<')} | "
+}
+
+def formatRow = { row ->
+ """${row.split(',').collect { cell -> formatCell(cell) }.join('')}
+"""
+}
+
+def formatTable = { csv, header=false ->
+ def rows = csv.split('\n').collect { row -> formatRow(row) }
+ header \
+ ? """
+
+
+${rows[0]}
+
+${rows[1..-1].join('')}
+
+""" \
+ : """
+
+"""
+}
+
+def formatPage = { title, csv, header=false ->
+"""
+
+${title}
+
+
+${formatTable(csv, header)}
+"""
+}
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-2.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-2.groovy
new file mode 100644
index 0000000000..c562694945
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-2.groovy
@@ -0,0 +1,17 @@
+def csv = '''Character,Speech
+The multitude,The messiah! Show us the messiah!
+Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!
+The multitude,Who are you?
+Brians mother,I'm his mother; that's who!
+The multitude,Behold his mother! Behold his mother!'''
+
+println 'Basic:'
+println '-----------------------------------------'
+println (formatPage('Basic', csv))
+println '-----------------------------------------'
+println()
+println()
+println 'Extra Credit:'
+println '-----------------------------------------'
+println (formatPage('Extra Credit', csv, true))
+println '-----------------------------------------'
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-3.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-3.groovy
new file mode 100644
index 0000000000..e9fdd43036
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-3.groovy
@@ -0,0 +1,19 @@
+
+
+Basic
+
+
+
+
+| Character | Speech |
+| The multitude | The messiah! Show us the messiah! |
+| Brians mother | <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+| The multitude | Who are you? |
+| Brians mother | I'm his mother; that's who! |
+| The multitude | Behold his mother! Behold his mother! |
+
+
+
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-4.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-4.groovy
new file mode 100644
index 0000000000..c89ed30454
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-4.groovy
@@ -0,0 +1,23 @@
+
+
+Extra Credit
+
+
+
+
+
+| Character | Speech |
+
+
+| The multitude | The messiah! Show us the messiah! |
+| Brians mother | <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+| The multitude | Who are you? |
+| Brians mother | I'm his mother; that's who! |
+| The multitude | Behold his mother! Behold his mother! |
+
+
+
+
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-5.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-5.groovy
new file mode 100644
index 0000000000..37214a2aff
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-5.groovy
@@ -0,0 +1,30 @@
+import groovy.xml.MarkupBuilder
+
+def formatRow = { doc, row ->
+ doc.tr { row.each { cell -> td { mkp.yield(cell) } } }
+}
+
+def formatPage = { titleString, csv, header=false ->
+ def writer = new StringWriter()
+ def doc = new MarkupBuilder(writer)
+ def rows = csv.split('\n').collect { row -> row.split(',') }
+ doc.html {
+ head {
+ title (titleString)
+ style (type:"text/css") {
+ mkp.yield('''
+ td {background-color:#ddddff; }
+ thead td {background-color:#ddffdd; text-align:center; }
+ ''')
+ }
+ }
+ body {
+ table {
+ header && thead { formatRow(doc, rows[0]) }
+ header && tbody { rows[1..-1].each { formatRow(doc, it) } }
+ header || rows.each { formatRow(doc, it) }
+ }
+ }
+ }
+ writer.toString()
+}
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-6.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-6.groovy
new file mode 100644
index 0000000000..a3708ec0b6
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-6.groovy
@@ -0,0 +1,37 @@
+
+
+ Basic
+
+
+
+
+
+ | Character |
+ Speech |
+
+
+ | The multitude |
+ The messiah! Show us the messiah! |
+
+
+ | Brians mother |
+ <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+
+
+ | The multitude |
+ Who are you? |
+
+
+ | Brians mother |
+ I'm his mother; that's who! |
+
+
+ | The multitude |
+ Behold his mother! Behold his mother! |
+
+
+
+
diff --git a/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-7.groovy b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-7.groovy
new file mode 100644
index 0000000000..55f4ec3dad
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Groovy/csv-to-html-translation-7.groovy
@@ -0,0 +1,41 @@
+
+
+ Extra Credit
+
+
+
+
+
+
+ | Character |
+ Speech |
+
+
+
+
+ | The multitude |
+ The messiah! Show us the messiah! |
+
+
+ | Brians mother |
+ <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+
+
+ | The multitude |
+ Who are you? |
+
+
+ | Brians mother |
+ I'm his mother; that's who! |
+
+
+ | The multitude |
+ Behold his mother! Behold his mother! |
+
+
+
+
+
diff --git a/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-1.icon b/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-1.icon
new file mode 100644
index 0000000000..de2097aa01
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-1.icon
@@ -0,0 +1,20 @@
+procedure main(arglist)
+ pchar := &letters ++ &digits ++ '!?;. ' # printable chars
+
+ write("")
+ firstHead := (!arglist == "-heading")
+ tHead := write
+ while row := trim(read()) do {
+ if \firstHead then write(" ") else tHead(" ")
+ writes(" | ")
+ while *row > 0 do
+ row ?:= ( (=",",writes(" | ")) |
+ writes( tab(many(pchar)) |
+ ("" || ord(move(1))) ), tab(0))
+ write(" |
")
+ if (\firstHead) := &null then write(" \n ")
+ tHead := 1
+ }
+ write(" ")
+ write("
")
+end
diff --git a/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-2.icon b/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-2.icon
new file mode 100644
index 0000000000..b5121b90fa
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Icon/csv-to-html-translation-2.icon
@@ -0,0 +1,12 @@
+
+
+ | Character | Speech |
+
+
+ | The multitude | The messiah! Show us the messiah! |
+ | Brians mother | <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+ | The multitude | Who are you? |
+ | Brians mother | I'm his mother; that's who! |
+ | The multitude | Behold his mother! Behold his mother! |
+
+
diff --git a/Task/CSV-to-HTML-translation/J/csv-to-html-translation-1.j b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-1.j
new file mode 100644
index 0000000000..cd549a0cc0
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-1.j
@@ -0,0 +1,22 @@
+require 'strings tables/csv'
+encodeHTML=: ('&';'&';'<';'<';'>';'>')&stringreplace
+
+tag=: adverb define
+ 'starttag endtag'=.m
+ (,&.>/)"1 (starttag , ,&endtag) L:0 y
+)
+
+markupCells=: ('';' | ') tag
+markupHdrCells=: ('';' | ') tag
+markupRows=: ('';'
',LF) tag
+markupTable=: (('') tag
+
+makeHTMLtablefromCSV=: verb define
+ 0 makeHTMLtablefromCSV y NB. default left arg is 0 (no header row)
+:
+ t=. fixcsv encodeHTML y
+ if. x do. t=. (markupHdrCells@{. , markupCells@}.) t
+ else. t=. markupCells t
+ end.
+ ;markupTable markupRows t
+)
diff --git a/Task/CSV-to-HTML-translation/J/csv-to-html-translation-2.j b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-2.j
new file mode 100644
index 0000000000..b747720b05
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-2.j
@@ -0,0 +1,2 @@
+tag=: adverb def '[: (,&.>/)"1 m&(0&{::@[ , 1&{::@[ ,~ ]) L:0@]'
+makeHTMLtablefromCSV6=: 0&$: : ([: ; markupTable@markupRows@([ markupCells`(markupHdrCells@{. , markupCells@}.)@.[ fixcsv@encodeHTML))
diff --git a/Task/CSV-to-HTML-translation/J/csv-to-html-translation-3.j b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-3.j
new file mode 100644
index 0000000000..ff296d8923
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-3.j
@@ -0,0 +1,9 @@
+ CSVstrng=: noun define
+Character,Speech
+The multitude,The messiah! Show us the messiah!
+Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!
+The multitude,Who are you?
+Brians mother,I'm his mother; that's who!
+The multitude,Behold his mother! Behold his mother!
+)
+ 1 makeHTMLtablefromCSV CSVstrng
diff --git a/Task/CSV-to-HTML-translation/J/csv-to-html-translation-4.j b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-4.j
new file mode 100644
index 0000000000..d3a53464a6
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/J/csv-to-html-translation-4.j
@@ -0,0 +1,8 @@
+
+| Character | Speech |
+| The multitude | The messiah! Show us the messiah! |
+| Brians mother | <angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> |
+| The multitude | Who are you? |
+| Brians mother | I'm his mother; that's who! |
+| The multitude | Behold his mother! Behold his mother! |
+
diff --git a/Task/CSV-to-HTML-translation/Liberty-BASIC/csv-to-html-translation.liberty b/Task/CSV-to-HTML-translation/Liberty-BASIC/csv-to-html-translation.liberty
new file mode 100644
index 0000000000..e66696be80
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Liberty-BASIC/csv-to-html-translation.liberty
@@ -0,0 +1,36 @@
+ newline$ ="|"
+ ' No escape behaviour, so can't refer to '/n'.
+ ' Generally imported csv would have separator CR LF; easily converted first if needed
+
+ csv$ ="Character,Speech" +newline$+_
+ "The multitude,The messiah! Show us the messiah!" +newline$+_
+ "Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!" +newline$+_
+ "The multitude,Who are you?" +newline$+_
+ "Brians mother,I'm his mother; that's who!" +newline$+_
+ "The multitude,Behold his mother! Behold his mother!"
+
+ print ""
+ print ""
+ print ""
+ print ""
+ print "CSV to HTML translation
"
+ print ""
+ print "| "
+
+ for i =1 to len( csv$)
+ c$ =mid$( csv$, i, 1)
+ select case c$
+ case "|": print " |
": print "| "
+ case ",": print " | ";
+ case "<": print "&"+"lt;";
+ case ">": print "&"+"gt;";
+ case "&": print "&"+"amp;";
+ case else: print c$;
+ end select
+ next i
+
+ print " |
"
+ print "
"
+ print ""
+ print ""
+ end
diff --git a/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-1.ml b/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-1.ml
new file mode 100644
index 0000000000..d45c856aaf
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-1.ml
@@ -0,0 +1,54 @@
+MCSKIP "WITH" NL
+"" CSV to HTML
+"" assumes macros on input stream 1, terminal on stream 2
+MCSKIP MT,[]
+MCSKIP SL WITH ~
+MCINS %.
+"" C1=th before header output, td afterwards
+MCCVAR 1,2
+MCSET C1=[th]
+"" HTML escapes
+MCDEF < AS [[<]]
+MCDEF > AS [[>]]
+MCDEF & AS [[&]]
+"" Main line processing
+MCDEF SL N1 OPT , N1 OR NL ALL
+AS [[ ]
+MCSET T2=1
+%L1.MCGO L2 IF T2 GR T1
+ [<]%C1.[>]%AT2.[]%C1.[>]
+MCSET T2=T2+1
+MCGO L1
+%L2.[
]
+MCSET C1=[td]
+]
+[
+
+
+HTML converted from CSV
+
+
+
+
+
+]
+MCSET S1=1
+~MCSET S10=2
+~MCSET S1=0
+[
+
+
+]
diff --git a/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-2.ml b/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-2.ml
new file mode 100644
index 0000000000..d9be3e3ca5
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/ML-I/csv-to-html-translation-2.ml
@@ -0,0 +1,51 @@
+
+
+
+HTML converted from CSV
+
+
+
+
+
+
+
+ | Character |
+ Speech |
+
+
+ | The multitude |
+ The messiah! Show us the messiah! |
+
+
+ | Brians mother |
+ <angry>Now you listen here! He's not the messiah; he's a
+ very naughty boy! Now go away!</angry> |
+
+
+ | The multitude |
+ Who are you? |
+
+
+ | Brians mother |
+ I'm his mother; that's who! |
+
+
+ | The multitude |
+ Behold his mother! Behold his mother! |
+
+
+
+
diff --git a/Task/CSV-to-HTML-translation/Mathematica/csv-to-html-translation.mathematica b/Task/CSV-to-HTML-translation/Mathematica/csv-to-html-translation.mathematica
new file mode 100644
index 0000000000..c8c23ec897
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Mathematica/csv-to-html-translation.mathematica
@@ -0,0 +1,36 @@
+a="Character,Speech
+The multitude,The messiah! Show us the messiah!
+Brians mother,Now you listen here! He's not the messiah;he's a very naughty boy! Now go away!
+The multitude,Who are you?
+Brians mother,I'm his mother;that's who!
+The multitude,Behold his mother! Behold his mother!";
+(*Naive*)
+StringJoin["\n",Map[StringJoin["| ",#," |
\n"]&,
+StringSplit[StringReplace[a,{","->"","<"->"<",">"->">"}],"\n"]]
+," |
"]
+(*Extra*)
+StringJoin["\n",StringJoin["| ",#," |
\n"]&[
+StringSplit[StringReplace[a,{","->"","<"->"<",">"->">"}],"\n"]//First]
+,Map[StringJoin[" | | ",#," |
\n"]&,
+StringSplit[StringReplace[a,{","->"","<"->"<",">"->">"}],"\n"]//Rest]
+," |
"]
+
+Output:
+
+
+| Character | Speech |
+| The multitude | The messiah! Show us the messiah! |
+| Brians mother | <angry>Now you listen here! He's not the messiah;he's a very naughty boy! Now go away!</angry> |
+| The multitude | Who are you? |
+| Brians mother | I'm his mother;that's who! |
+| The multitude | Behold his mother! Behold his mother! |
+
+
+
+| Character | Speech |
+| The multitude | The messiah! Show us the messiah! |
+| Brians mother | <angry>Now you listen here! He's not the messiah;he's a very naughty boy! Now go away!</angry> |
+| The multitude | Who are you? |
+| Brians mother | I'm his mother;that's who! |
+| The multitude | Behold his mother! Behold his mother! |
+
diff --git a/Task/Caesar-cipher/Fantom/caesar-cipher.fantom b/Task/Caesar-cipher/Fantom/caesar-cipher.fantom
new file mode 100644
index 0000000000..560f941e15
--- /dev/null
+++ b/Task/Caesar-cipher/Fantom/caesar-cipher.fantom
@@ -0,0 +1,52 @@
+class Main
+{
+ static Int shift (Int char, Int key)
+ {
+ newChar := char + key
+ if (char >= 'a' && char <= 'z')
+ {
+ if (newChar - 'a' < 0) { newChar += 26 }
+ if (newChar - 'a' >= 26) { newChar -= 26 }
+ }
+ else if (char >= 'A' && char <= 'Z')
+ {
+ if (newChar - 'A' < 0) { newChar += 26 }
+ if (newChar - 'A' >= 26) { newChar -= 26 }
+ }
+ else // not alphabetic, so keep as is
+ {
+ newChar = char
+ }
+ return newChar
+ }
+
+ static Str shiftStr (Str msg, Int key)
+ {
+ res := StrBuf()
+ msg.each { res.addChar (shift(it, key)) }
+ return res.toStr
+ }
+
+ static Str encode (Str msg, Int key)
+ {
+ return shiftStr (msg, key)
+ }
+
+ static Str decode (Str msg, Int key)
+ {
+ return shiftStr (msg, -key)
+ }
+
+ static Void main (Str[] args)
+ {
+ if (args.size == 2)
+ {
+ msg := args[0]
+ key := Int(args[1])
+
+ echo ("$msg with key $key")
+ echo ("Encode: ${encode(msg, key)}")
+ echo ("Decode: ${decode(encode(msg, key), key)}")
+ }
+ }
+}
diff --git a/Task/Caesar-cipher/GAP/caesar-cipher.gap b/Task/Caesar-cipher/GAP/caesar-cipher.gap
new file mode 100644
index 0000000000..0a3b660ca3
--- /dev/null
+++ b/Task/Caesar-cipher/GAP/caesar-cipher.gap
@@ -0,0 +1,26 @@
+CaesarCipher := function(s, n)
+ local r, c, i, lower, upper;
+ lower := "abcdefghijklmnopqrstuvwxyz";
+ upper := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ r := "";
+ for c in s do
+ i := Position(lower, c);
+ if i <> fail then
+ Add(r, lower[RemInt(i + n - 1, 26) + 1]);
+ else
+ i := Position(upper, c);
+ if i <> fail then
+ Add(r, upper[RemInt(i + n - 1, 26) + 1]);
+ else
+ Add(r, c);
+ fi;
+ fi;
+ od;
+ return r;
+end;
+
+CaesarCipher("IBM", 25);
+# "HAL"
+
+CaesarCipher("Vgg cphvi wzdibn vmz wjmi amzz viy zlpvg di ydbidot viy mdbcon.", 5);
+# "All human beings are born free and equal in dignity and rights."
diff --git a/Task/Caesar-cipher/Groovy/caesar-cipher.groovy b/Task/Caesar-cipher/Groovy/caesar-cipher.groovy
new file mode 100644
index 0000000000..d444b882b4
--- /dev/null
+++ b/Task/Caesar-cipher/Groovy/caesar-cipher.groovy
@@ -0,0 +1,24 @@
+def caeserEncode(int cipherKey, String text) {
+ def builder = new StringBuilder()
+ text.each { character ->
+ int ch = character[0] as char
+ switch(ch) {
+ case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
+ case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
+ }
+ builder.append(ch as char)
+ }
+ builder.toString()
+}
+def caeserDecode(int cipherKey, String text) { caeserEncode(26 - cipherKey, text) }
+
+def plainText = "The Quick Brown Fox jumped over the lazy dog"
+def cipherKey = 12
+def cipherText = caeserEncode(cipherKey, plainText)
+def decodedText = caeserDecode(cipherKey, cipherText)
+
+println "plainText: $plainText"
+println "cypherText($cipherKey): $cipherText"
+println "decodedText($cipherKey): $decodedText"
+
+assert plainText == decodedText
diff --git a/Task/Caesar-cipher/Icon/caesar-cipher.icon b/Task/Caesar-cipher/Icon/caesar-cipher.icon
new file mode 100644
index 0000000000..83ac0ef86d
--- /dev/null
+++ b/Task/Caesar-cipher/Icon/caesar-cipher.icon
@@ -0,0 +1,16 @@
+procedure main()
+ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
+dtext := caesar(ctext,,"decrypt")
+write("Plain text = ",image(ptext))
+write("Encphered text = ",image(ctext))
+write("Decphered text = ",image(dtext))
+end
+
+procedure caesar(text,k,mode) #: mono-alphabetic shift cipher
+/k := 3
+k := (((k % *&lcase) + *&lcase) % *&lcase) + 1
+case mode of {
+ &null|"e"|"encrypt": return map(text,&lcase,(&lcase||&lcase)[k+:*&lcase])
+ "d"|"decrypt" : return map(text,(&lcase||&lcase)[k+:*&lcase],&lcase)
+ }
+end
diff --git a/Task/Caesar-cipher/J/caesar-cipher-1.j b/Task/Caesar-cipher/J/caesar-cipher-1.j
new file mode 100644
index 0000000000..0d21093fa9
--- /dev/null
+++ b/Task/Caesar-cipher/J/caesar-cipher-1.j
@@ -0,0 +1,2 @@
+cndx=: [: , 65 97 +/ 26 | (i.26)&+
+caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
diff --git a/Task/Caesar-cipher/J/caesar-cipher-2.j b/Task/Caesar-cipher/J/caesar-cipher-2.j
new file mode 100644
index 0000000000..a9078850b4
--- /dev/null
+++ b/Task/Caesar-cipher/J/caesar-cipher-2.j
@@ -0,0 +1,2 @@
+ 2 caesar 'This simple "monoalphabetic substitution cipher" provides almost no security, ...'
+Vjku ukorng "oqpqcnrjcdgvke uwduvkvwvkqp ekrjgt" rtqxkfgu cnoquv pq ugewtkva, ...
diff --git a/Task/Caesar-cipher/J/caesar-cipher-3.j b/Task/Caesar-cipher/J/caesar-cipher-3.j
new file mode 100644
index 0000000000..f981e1192f
--- /dev/null
+++ b/Task/Caesar-cipher/J/caesar-cipher-3.j
@@ -0,0 +1 @@
+CAESAR=:1 :'(26|m&+)&.((26{.64}.a.)&i.)'
diff --git a/Task/Caesar-cipher/J/caesar-cipher-4.j b/Task/Caesar-cipher/J/caesar-cipher-4.j
new file mode 100644
index 0000000000..eb37e971c7
--- /dev/null
+++ b/Task/Caesar-cipher/J/caesar-cipher-4.j
@@ -0,0 +1,2 @@
+ 20 CAESAR 'HI'
+BC
diff --git a/Task/Caesar-cipher/Liberty-BASIC/caesar-cipher.liberty b/Task/Caesar-cipher/Liberty-BASIC/caesar-cipher.liberty
new file mode 100644
index 0000000000..2f8a11c1d3
--- /dev/null
+++ b/Task/Caesar-cipher/Liberty-BASIC/caesar-cipher.liberty
@@ -0,0 +1,24 @@
+key = 7
+
+Print "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+
+'Encrypt the text
+Print CaesarCypher$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", key)
+
+'Decrypt the text by changing the key to (26 - key)
+Print CaesarCypher$(CaesarCypher$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", key), (26 - key))
+
+Function CaesarCypher$(string$, key)
+ If (key < 0) Or (key > 25) Then _
+ CaesarCypher$ = "Key is Ouside of Bounds" : Exit Function
+ For i = 1 To Len(string$)
+ rotate = Asc(Mid$(string$, i, 1))
+ rotate = (rotate + key)
+ If Asc(Mid$(string$, i, 1)) > Asc("Z") Then
+ If rotate > Asc("z") Then rotate = (Asc("a") + (rotate - Asc("z")) - 1)
+ Else
+ If rotate > Asc("Z") Then rotate = (Asc("A") + (rotate - Asc("Z")) - 1)
+ End If
+ CaesarCypher$ = (CaesarCypher$ + Chr$(rotate))
+ Next i
+End Function
diff --git a/Task/Caesar-cipher/Logo/caesar-cipher.logo b/Task/Caesar-cipher/Logo/caesar-cipher.logo
new file mode 100644
index 0000000000..815cde4bfb
--- /dev/null
+++ b/Task/Caesar-cipher/Logo/caesar-cipher.logo
@@ -0,0 +1,34 @@
+; some useful constants
+make "lower_a ascii "a
+make "lower_z ascii "z
+make "upper_a ascii "A
+make "upper_z ascii "Z
+
+; encipher a single character
+to encipher_char :char :key
+ local "code make "code ascii :char
+ local "base make "base 0
+ ifelse [and (:code >= :lower_a) (:code <= :lower_z)] [make "base :lower_a] [
+ if [and (:code >= :upper_a) (:code <= :upper_z)] [make "base :upper_a] ]
+ ifelse [:base > 0] [
+ output char (:base + (modulo ( :code - :base + :key ) 26 ))
+ ] [
+ output :char
+ ]
+end
+
+; encipher a whole string
+to caesar_cipher :string :key
+ output map [encipher_char ? :key] :string
+end
+
+; Demo
+make "plaintext "|The five boxing wizards jump quickly|
+make "key 3
+make "ciphertext caesar_cipher :plaintext :key
+make "recovered caesar_cipher :ciphertext -:key
+
+print sentence "| Original:| :plaintext
+print sentence "|Encrypted:| :ciphertext
+print sentence "|Recovered:| :recovered
+bye
diff --git a/Task/Caesar-cipher/Maple/caesar-cipher.maple b/Task/Caesar-cipher/Maple/caesar-cipher.maple
new file mode 100644
index 0000000000..66a7fc27fa
--- /dev/null
+++ b/Task/Caesar-cipher/Maple/caesar-cipher.maple
@@ -0,0 +1,5 @@
+> StringTools:-Encode( "The five boxing wizards jump quickly", encoding = alpharot[3] );
+ "Wkh ilyh eralqj zlcdugv mxps txlfnob"
+
+> StringTools:-Encode( %, encoding = alpharot[ 23 ] );
+ "The five boxing wizards jump quickly"
diff --git a/Task/Caesar-cipher/Mathematica/caesar-cipher.mathematica b/Task/Caesar-cipher/Mathematica/caesar-cipher.mathematica
new file mode 100644
index 0000000000..14d801fb45
--- /dev/null
+++ b/Task/Caesar-cipher/Mathematica/caesar-cipher.mathematica
@@ -0,0 +1 @@
+cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,3]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
diff --git a/Task/Calendar-for-real-programmers/GUISS/calendar-for-real-programmers.guiss b/Task/Calendar-for-real-programmers/GUISS/calendar-for-real-programmers.guiss
new file mode 100644
index 0000000000..04f2638ee1
--- /dev/null
+++ b/Task/Calendar-for-real-programmers/GUISS/calendar-for-real-programmers.guiss
@@ -0,0 +1 @@
+RIGHTCLICK:CLOCK,ADJUST DATE AND TIME,BUTTON:CANCEL
diff --git a/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-1.icon b/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-1.icon
new file mode 100644
index 0000000000..8d97ab5b6b
--- /dev/null
+++ b/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-1.icon
@@ -0,0 +1,48 @@
+$include "REALIZE.ICN"
+
+LINK DATETIME
+$define ISLEAPYEAR IsLeapYear
+$define JULIAN julian
+
+PROCEDURE MAIN(A)
+PRINTCALENDAR(\A$<1$>|1969)
+END
+
+PROCEDURE PRINTCALENDAR(YEAR)
+ COLS := 3
+ MONS := $<$>
+ "JANUARY FEBRUARY MARCH APRIL MAY JUNE " ||
+ "JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER " ?
+ WHILE PUT(MONS, TAB(FIND(" "))) DO MOVE(1)
+
+ WRITE(CENTER("$",COLS * 24 + 4))
+ WRITE(CENTER(YEAR,COLS * 24 + 4), CHAR(10))
+
+ M := LIST(COLS)
+ EVERY MON := 0 TO 9 BY COLS DO $(
+ WRITES(" ")
+ EVERY I := 1 TO COLS DO {
+ WRITES(CENTER(MONS$,24))
+ M$ := CREATE CALENDARFORMATWEEK(1969,MON + I)
+ $)
+ WRITE()
+ EVERY 1 TO 7 DO $(
+ EVERY C := 1 TO COLS DO $(
+ WRITES(" ")
+ EVERY 1 TO 7 DO WRITES(RIGHT(@M$,3))
+ $)
+ WRITE()
+ $)
+ $)
+END
+
+PROCEDURE CALENDARFORMATWEEK(YEAR,M)
+STATIC D
+INITIAL D := $<31,28,31,30,31,30,31,31,30,31,30,31$>
+
+EVERY SUSPEND "SU"|"MO"|"TU"|"WE"|"TH"|"FR"|"SA"
+EVERY 1 TO (DAY := (JULIAN(M,1,YEAR)+1)%7) DO SUSPEND ""
+EVERY SUSPEND 1 TO D$ DO DAY +:= 1
+IF M = 2 & ISLEAPYEAR(YEAR) THEN SUSPEND (DAY +:= 1, 29)
+EVERY DAY TO (6*7) DO SUSPEND ""
+END
diff --git a/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-2.icon b/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-2.icon
new file mode 100644
index 0000000000..7d0c1f509e
--- /dev/null
+++ b/Task/Calendar-for-real-programmers/Icon/calendar-for-real-programmers-2.icon
@@ -0,0 +1,25 @@
+$define PROCEDURE procedure
+$define END end
+$define WRITE write
+$define WRITES writes
+$define SUSPEND suspend
+$define DO do
+$define TO to
+$define EVERY every
+$define LIST list
+$define WHILE while
+$define MAIN main
+$define PUT put
+$define TAB tab
+$define MOVE move
+$define CHAR move
+$define CENTER center
+$define RIGHT right
+$define FIND find
+$define STATIC static
+$define INITIAL initial
+$define CREATE create
+$define LINK link
+$define IF if
+$define THEN then
+$define BY by
diff --git a/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-1.j b/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-1.j
new file mode 100644
index 0000000000..aaf2698c08
--- /dev/null
+++ b/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-1.j
@@ -0,0 +1,10 @@
+B=: + 4 100 400 -/@:<.@:%~ <:
+M=: 28+ 3, (10$5$3 2),~ 0 ~:/@:= 4 100 400 | ]
+R=: (7 -@| B+ 0, +/\@}:@M) |."0 1 (0,#\#~41) (]&:>: *"1 >/)~ M
+H=. _3(_11&{.)\'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'
+H=. 'SU MO TU WE TH FR SA',:"1~H
+C=: H <@,"(2) 12 6 21 }."1@($,) (' ',3 ":,.#\#~31) {~ R
+D=: 0 ": -@<.@%&21@+&1@[ ]\ C@]
+L=: |."0 1~ +/ .(*./\@:=)"1&' '
+E=: (|."0 1~ _2 <.@%~ +/ .(*./\.@:=)"1&' ')@:({."1) L
+F=: 0 _1 }. 0 1 }. (2+[) E '[INSERT SNOOPY HERE]', ":@], D
diff --git a/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-2.j b/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-2.j
new file mode 100644
index 0000000000..d0ed499ec5
--- /dev/null
+++ b/Task/Calendar-for-real-programmers/J/calendar-for-real-programmers-2.j
@@ -0,0 +1,22 @@
+ 132 F 1969
+ [INSERT SNOOPY HERE]
+ 1969
+ ┌────────────────────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┐
+ │ JAN │ FEB │ MAR │ APR │ MAY │ JUN │
+ │SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│
+ │ 1 2 3 4│ 1│ 1│ 1 2 3 4 5│ 1 2 3│ 1 2 3 4 5 6 7│
+ │ 5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 2 3 4 5 6 7 8│ 6 7 8 9 10 11 12│ 4 5 6 7 8 9 10│ 8 9 10 11 12 13 14│
+ │12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│ 9 10 11 12 13 14 15│13 14 15 16 17 18 19│11 12 13 14 15 16 17│15 16 17 18 19 20 21│
+ │19 20 21 22 23 24 25│16 17 18 19 20 21 22│16 17 18 19 20 21 22│20 21 22 23 24 25 26│18 19 20 21 22 23 24│22 23 24 25 26 27 28│
+ │26 27 28 29 30 31 │23 24 25 26 27 28 │23 24 25 26 27 28 29│27 28 29 30 │25 26 27 28 29 30 31│29 30 │
+ │ │ │30 31 │ │ │ │
+ ├────────────────────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┤
+ │ JUL │ AUG │ SEP │ OCT │ NOV │ DEC │
+ │SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│SU MO TU WE TH FR SA│
+ │ 1 2 3 4 5│ 1 2│ 1 2 3 4 5 6│ 1 2 3 4│ 1│ 1 2 3 4 5 6│
+ │ 6 7 8 9 10 11 12│ 3 4 5 6 7 8 9│ 7 8 9 10 11 12 13│ 5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 7 8 9 10 11 12 13│
+ │13 14 15 16 17 18 19│10 11 12 13 14 15 16│14 15 16 17 18 19 20│12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│14 15 16 17 18 19 20│
+ │20 21 22 23 24 25 26│17 18 19 20 21 22 23│21 22 23 24 25 26 27│19 20 21 22 23 24 25│16 17 18 19 20 21 22│21 22 23 24 25 26 27│
+ │27 28 29 30 31 │24 25 26 27 28 29 30│28 29 30 │26 27 28 29 30 31 │23 24 25 26 27 28 29│28 29 30 31 │
+ │ │31 │ │ │30 │ │
+ └────────────────────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┘
diff --git a/Task/Calendar/Icon/calendar.icon b/Task/Calendar/Icon/calendar.icon
new file mode 100644
index 0000000000..b4849be329
--- /dev/null
+++ b/Task/Calendar/Icon/calendar.icon
@@ -0,0 +1,44 @@
+procedure main(A)
+printCalendar(\A[1]|1969)
+end
+
+procedure printCalendar(year) #: Print a 3 column x 80 char calendar
+ cols := 3 # fixed width
+ mons := [] # table of months
+ "January February March April May June " ||
+ "July August September October November December " ?
+ while put(mons, tab(find(" "))) do move(1)
+
+ write(center("[Snoopy Picture]",cols * 24 + 4)) # mandatory ..
+ write(center(year,cols * 24 + 4), "\n") # ... headers
+
+ M := list(cols) # coexpr container
+ every mon := 0 to 9 by cols do { # go through months by cols
+ writes(" ")
+ every i := 1 to cols do {
+ writes(center(mons[mon+i],24)) # header months
+ M[i] := create CalendarFormatWeek(1969,mon + i) # formatting coexpr
+ }
+ write()
+ every 1 to 7 do { # 1 to max rows
+ every c := 1 to cols do { # for each column
+ writes(" ")
+ every 1 to 7 do writes(right(@M[c],3)) # each row day element
+ }
+ write()
+ }
+ }
+end
+
+link datetime
+
+procedure CalendarFormatWeek(year,m) #: Format Week for Calendar
+static D
+initial D := [31,28,31,30,31,30,31,31,30,31,30,31]
+
+every suspend "Su"|"Mo"|"Tu"|"We"|"Th"|"Fr"|"Sa" # header
+every 1 to (d := (julian(m,1,year)+1)%7) do suspend "" # lead day alignment
+every suspend 1 to D[m] do d +:= 1 # days
+if m = 2 & IsLeapYear(year) then suspend (d +:= 1, 29) # LY adjustment
+every d to (6*7) do suspend "" # trailer alignment
+end
diff --git a/Task/Calendar/J/calendar-1.j b/Task/Calendar/J/calendar-1.j
new file mode 100644
index 0000000000..7f1092f381
--- /dev/null
+++ b/Task/Calendar/J/calendar-1.j
@@ -0,0 +1,5 @@
+require 'dates format' NB. J6.x
+require 'dates general/misc/format' NB. J7.x
+calBody=: (1 1 }. _1 _1 }. ":)@(-@(<.@%&22)@[ ]\ calendar@])
+calTitle=: (<: - 22&|)@[ center '[Insert Snoopy here]' , '' ,:~ ":@]
+formatCalendar=: calTitle , calBody
diff --git a/Task/Calendar/J/calendar-2.j b/Task/Calendar/J/calendar-2.j
new file mode 100644
index 0000000000..db9154cac3
--- /dev/null
+++ b/Task/Calendar/J/calendar-2.j
@@ -0,0 +1,39 @@
+ 80 formatCalendar 1969
+ [Insert Snoopy here]
+ 1969
+
+ Jan │ Feb │ Mar
+ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
+ 1 2 3 4│ 1│ 1
+ 5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 2 3 4 5 6 7 8
+ 12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│ 9 10 11 12 13 14 15
+ 19 20 21 22 23 24 25│ 16 17 18 19 20 21 22│ 16 17 18 19 20 21 22
+ 26 27 28 29 30 31 │ 23 24 25 26 27 28 │ 23 24 25 26 27 28 29
+ │ │ 30 31
+─────────────────────┼─────────────────────┼─────────────────────
+ Apr │ May │ Jun
+ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5│ 1 2 3│ 1 2 3 4 5 6 7
+ 6 7 8 9 10 11 12│ 4 5 6 7 8 9 10│ 8 9 10 11 12 13 14
+ 13 14 15 16 17 18 19│ 11 12 13 14 15 16 17│ 15 16 17 18 19 20 21
+ 20 21 22 23 24 25 26│ 18 19 20 21 22 23 24│ 22 23 24 25 26 27 28
+ 27 28 29 30 │ 25 26 27 28 29 30 31│ 29 30
+ │ │
+─────────────────────┼─────────────────────┼─────────────────────
+ Jul │ Aug │ Sep
+ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5│ 1 2│ 1 2 3 4 5 6
+ 6 7 8 9 10 11 12│ 3 4 5 6 7 8 9│ 7 8 9 10 11 12 13
+ 13 14 15 16 17 18 19│ 10 11 12 13 14 15 16│ 14 15 16 17 18 19 20
+ 20 21 22 23 24 25 26│ 17 18 19 20 21 22 23│ 21 22 23 24 25 26 27
+ 27 28 29 30 31 │ 24 25 26 27 28 29 30│ 28 29 30
+ │ 31 │
+─────────────────────┼─────────────────────┼─────────────────────
+ Oct │ Nov │ Dec
+ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa│ Su Mo Tu We Th Fr Sa
+ 1 2 3 4│ 1│ 1 2 3 4 5 6
+ 5 6 7 8 9 10 11│ 2 3 4 5 6 7 8│ 7 8 9 10 11 12 13
+ 12 13 14 15 16 17 18│ 9 10 11 12 13 14 15│ 14 15 16 17 18 19 20
+ 19 20 21 22 23 24 25│ 16 17 18 19 20 21 22│ 21 22 23 24 25 26 27
+ 26 27 28 29 30 31 │ 23 24 25 26 27 28 29│ 28 29 30 31
+ │ 30 │
diff --git a/Task/Calendar/Mathematica/calendar-1.mathematica b/Task/Calendar/Mathematica/calendar-1.mathematica
new file mode 100644
index 0000000000..7d272ca4ef
--- /dev/null
+++ b/Task/Calendar/Mathematica/calendar-1.mathematica
@@ -0,0 +1 @@
+Needs["Calendar`"];
diff --git a/Task/Calendar/Mathematica/calendar-2.mathematica b/Task/Calendar/Mathematica/calendar-2.mathematica
new file mode 100644
index 0000000000..f278478a34
--- /dev/null
+++ b/Task/Calendar/Mathematica/calendar-2.mathematica
@@ -0,0 +1,23 @@
+monthlyCalendar[y_, m_] :=
+ Module[{
+ days = {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday},
+ months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"},
+ d1, shortDays, offset, daysInMonth},
+
+ d1 = DayOfWeek[{y, m, 1}];
+
+ daysInMonth[year_, month_] := DaysBetween[{year, month, 1}, {If[month == 12, year + 1, year], If[month == 12, 1, month + 1], 1}];
+
+ shortDays = (StringTake[ToString[#], 3] & /@ days);
+
+ offset = d1 /. Thread[days -> Range[0, 6]];
+
+ Grid[
+ Prepend[
+ Prepend[
+ Partition[
+ PadRight[PadLeft[Range[daysInMonth[y, m]], daysInMonth[y, m] + offset, ""],
+ 36, "" ],
+ 7],
+ shortDays],
+ {months[[m]], SpanFromLeft}]]]
diff --git a/Task/Calendar/Mathematica/calendar-3.mathematica b/Task/Calendar/Mathematica/calendar-3.mathematica
new file mode 100644
index 0000000000..7e2d18a6b4
--- /dev/null
+++ b/Task/Calendar/Mathematica/calendar-3.mathematica
@@ -0,0 +1 @@
+ yearlyCalendar[y_] := Grid[Partition[Table[monthlyCalendar[y, k], {k, 12}], 3], Spacings -> {4, 2}];
diff --git a/Task/Call-a-foreign-language-function/Factor/call-a-foreign-language-function.factor b/Task/Call-a-foreign-language-function/Factor/call-a-foreign-language-function.factor
new file mode 100644
index 0000000000..5f8315feba
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Factor/call-a-foreign-language-function.factor
@@ -0,0 +1,4 @@
+FUNCTION: char* strdup ( c-string s ) ;
+
+: my-strdup ( str -- str' )
+ strdup [ utf8 alien>string ] [ (free) ] bi ;
diff --git a/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-1.j b/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-1.j
new file mode 100644
index 0000000000..5103d0709b
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-1.j
@@ -0,0 +1,4 @@
+require 'dll'
+strdup=: 'msvcrt.dll _strdup >x *' cd <
+free=: 'msvcrt.dll free n x' cd <
+getstr=: free ] memr@,&0 _1
diff --git a/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-2.j b/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-2.j
new file mode 100644
index 0000000000..fbcf3b1575
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/J/call-a-foreign-language-function-2.j
@@ -0,0 +1,2 @@
+ getstr@strdup 'Hello World!'
+Hello World!
diff --git a/Task/Call-a-foreign-language-function/Lisaac/call-a-foreign-language-function.lisaac b/Task/Call-a-foreign-language-function/Lisaac/call-a-foreign-language-function.lisaac
new file mode 100644
index 0000000000..4cdbb77375
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Lisaac/call-a-foreign-language-function.lisaac
@@ -0,0 +1,24 @@
+Section Header
+
++ name := TEST_C_INTERFACE;
+
+// this will be inserted in front of the program
+- external := `#include `;
+
+Section Public
+
+- main <- (
+ + s : STRING_CONSTANT;
+ + p : NATIVE_ARRAY[CHARACTER];
+
+ s := "Hello World!";
+ p := s.to_external;
+ // this will be inserted in-place
+ // use `expr`:type to tell Lisaac what's the type of the external expression
+ p := `strdup(@p)` : NATIVE_ARRAY[CHARACTER];
+ s.print;
+ '='.print;
+ p.println;
+ // this will also be inserted in-place, expression type disregarded
+ `free(@p)`;
+);
diff --git a/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-1.maple b/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-1.maple
new file mode 100644
index 0000000000..b75e5ececf
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-1.maple
@@ -0,0 +1,3 @@
+> strdup := define_external( strdup, s::string, RETURN::string, LIB = "/lib/libc.so.6" ):
+> strdup( "foo" );
+ "foo"
diff --git a/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-2.maple b/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-2.maple
new file mode 100644
index 0000000000..a664cb6b88
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Maple/call-a-foreign-language-function-2.maple
@@ -0,0 +1,11 @@
+> csin := define_external( sin, s::float[8], RETURN::float[8], LIB = "libm.so" );
+csin := proc(s::numeric)
+option call_external, define_external(sin, s::float[8],
+RETURN::float[8], LIB = "libm.so");
+ call_external(
+ Array(1..8, [...], datatype = integer[4], readonly), false,
+ args)
+end proc
+
+> csin( evalf( Pi / 2 ) );
+ 1.
diff --git a/Task/Call-a-foreign-language-function/Mathematica/call-a-foreign-language-function.mathematica b/Task/Call-a-foreign-language-function/Mathematica/call-a-foreign-language-function.mathematica
new file mode 100644
index 0000000000..0389652b94
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Mathematica/call-a-foreign-language-function.mathematica
@@ -0,0 +1,3 @@
+Needs["NETLink`"];
+externalstrdup = DefineDLLFunction["_strdup", "msvcrt.dll", "string", {"string"}];
+Print["Duplicate: ", externalstrdup["Hello world!"]]
diff --git a/Task/Call-a-foreign-language-function/Maxima/call-a-foreign-language-function.maxima b/Task/Call-a-foreign-language-function/Maxima/call-a-foreign-language-function.maxima
new file mode 100644
index 0000000000..bb447464f0
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Maxima/call-a-foreign-language-function.maxima
@@ -0,0 +1,9 @@
+/* Maxima is written in Lisp and can call Lisp functions.
+Use load("funcs.lisp"), or inside Maxima: */
+
+to_lisp();
+> (defun $f (a b) (+ a b))
+> (to-maxima)
+
+f(5, 6);
+11
diff --git a/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-1.mod2 b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-1.mod2
new file mode 100644
index 0000000000..3214018c8c
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-1.mod2
@@ -0,0 +1,68 @@
+#include
+
+int Initialize (void)
+{
+ if ( vga_init () == 0 )
+ return 1;
+ else
+ return 0;
+}
+
+void SetMode (int newmode)
+{
+ vga_setmode (newmode);
+}
+
+int GetMode (void)
+{
+ return vga_getcurrentmode ();
+}
+
+int MaxWidth (void)
+{
+ return vga_getxdim ();
+}
+
+int MaxHeight (void)
+{
+ return vga_getydim ();
+}
+
+void Clear (void)
+{
+ vga_clear ();
+}
+void SetColour (int colour)
+{
+ vga_setcolor (colour);
+}
+
+void SetEGAcolour (int colour)
+{
+ vga_setegacolor (colour);
+}
+
+void SetRGB (int red, int green, int blue)
+{
+ vga_setrgbcolor (red, green, blue);
+}
+
+void DrawLine (int x0, int y0, int dx, int dy)
+{
+ vga_drawline (x0, y0, x0 + dx, y0 + dy);
+}
+
+void Plot (int x, int y)
+{
+ vga_drawpixel (x, y);
+}
+
+int ThisColour (int x, int y)
+{
+ return vga_getpixel (x, y);
+}
+
+void GetKey (char *ch)
+{
+ *ch = vga_getkey ();
+}
diff --git a/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-2.mod2 b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-2.mod2
new file mode 100644
index 0000000000..5fa5e84169
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-2.mod2
@@ -0,0 +1,32 @@
+FOREIGN MODULE Vga;
+
+TYPE EGAcolour = (black, blue, green, cyan, red, pink, brown, white,
+ GREY, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE);
+
+PROCEDURE Initialize () : BOOLEAN;
+
+PROCEDURE MaxWidth () : CARDINAL;
+
+PROCEDURE MaxHeight () : CARDINAL;
+
+PROCEDURE Clear;
+
+PROCEDURE SetColour (colour : CARDINAL);
+
+PROCEDURE SetEGAcolour (colour : CARDINAL);
+
+PROCEDURE SetRGB (red, green, blue : CARDINAL);
+
+PROCEDURE DrawLine (x0, y0, dx, dy : CARDINAL);
+
+PROCEDURE Plot (x, y : CARDINAL);
+
+PROCEDURE ThisColour (x, y : CARDINAL) : CARDINAL;
+
+PROCEDURE SetMode (newmode : CARDINAL);
+
+PROCEDURE GetMode () : CARDINAL;
+
+PROCEDURE GetKey (VAR ch : CHAR);
+
+END Vga.
diff --git a/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-3.mod2 b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-3.mod2
new file mode 100644
index 0000000000..5859c74aea
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Modula-2/call-a-foreign-language-function-3.mod2
@@ -0,0 +1,33 @@
+MODULE svg01;
+
+FROM InOut IMPORT Read, Write, WriteBf, WriteString;
+
+IMPORT Vga;
+
+VAR OldMode, x, y : CARDINAL;
+ ch : CHAR;
+
+BEGIN
+ IF Vga.Initialize () = FALSE THEN
+ WriteString ('Could not start SVGAlib libraries. Aborting...');
+ WriteBf;
+ HALT
+ END;
+ OldMode := Vga.GetMode ();
+ Vga.SetMode (4);
+ Vga.SetColour (14);
+ Vga.Clear ();
+ Vga.SetColour (10);
+ FOR y := 125 TO 175 DO
+ FOR x := 100 TO 500 DO
+ Vga.Plot (x, y)
+ END
+ END;
+ LOOP
+ Read (ch);
+ IF ch = 'X' THEN EXIT END
+ END;
+ Vga.SetMode (OldMode);
+ Write (ch);
+ WriteBf;
+END svg01.
diff --git a/Task/Call-a-foreign-language-function/Modula-3/call-a-foreign-language-function.mod3 b/Task/Call-a-foreign-language-function/Modula-3/call-a-foreign-language-function.mod3
new file mode 100644
index 0000000000..7ae82eaa38
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Modula-3/call-a-foreign-language-function.mod3
@@ -0,0 +1,17 @@
+UNSAFE MODULE Foreign EXPORTS Main;
+
+IMPORT IO, Ctypes, Cstring, M3toC;
+
+VAR string1, string2: Ctypes.const_char_star;
+
+BEGIN
+ string1 := M3toC.CopyTtoS("Foobar");
+ string2 := M3toC.CopyTtoS("Foobar2");
+ IF Cstring.strcmp(string1, string2) = 0 THEN
+ IO.Put("string1 = string2\n");
+ ELSE
+ IO.Put("string1 # string2\n");
+ END;
+ M3toC.FreeCopiedS(string1);
+ M3toC.FreeCopiedS(string2);
+END Foreign.
diff --git a/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-1.j b/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-1.j
new file mode 100644
index 0000000000..b947111963
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-1.j
@@ -0,0 +1,12 @@
+require 'dll'
+strdup=: 'msvcrt.dll _strdup >x *' cd <
+free=: 'msvcrt.dll free n x' cd <
+getstr=: free ] memr@,&0 _1
+
+DupStr=:verb define
+ try.
+ getstr@strdup y
+ catch.
+ y
+ end.
+)
diff --git a/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-2.j b/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-2.j
new file mode 100644
index 0000000000..e5010535ca
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/J/call-a-function-in-a-shared-library-2.j
@@ -0,0 +1,4 @@
+ DupStr 'hello'
+hello
+ getstr@strdup ::] 'hello'
+hello
diff --git a/Task/Call-a-function-in-a-shared-library/Julia/call-a-function-in-a-shared-library.julia b/Task/Call-a-function-in-a-shared-library/Julia/call-a-function-in-a-shared-library.julia
new file mode 100644
index 0000000000..26dc8e2edf
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Julia/call-a-function-in-a-shared-library.julia
@@ -0,0 +1,3 @@
+#ccall((symbol, library), RetType, (ArgType1, ...), ArgVar1, ...)
+ ccall( (:GetDoubleClickTime, "User32"), stdcall,
+ Uint, (), )
diff --git a/Task/Call-a-function-in-a-shared-library/Maple/call-a-function-in-a-shared-library.maple b/Task/Call-a-function-in-a-shared-library/Maple/call-a-function-in-a-shared-library.maple
new file mode 100644
index 0000000000..5df034b229
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Maple/call-a-function-in-a-shared-library.maple
@@ -0,0 +1,3 @@
+> cfloor := define_external( floor, s::float[8], RETURN::float[8], LIB = "libm.so" ):
+> cfloor( 2.3 );
+ 2.
diff --git a/Task/Call-a-function-in-a-shared-library/Mathematica/call-a-function-in-a-shared-library.mathematica b/Task/Call-a-function-in-a-shared-library/Mathematica/call-a-function-in-a-shared-library.mathematica
new file mode 100644
index 0000000000..0d0c8137b6
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Mathematica/call-a-function-in-a-shared-library.mathematica
@@ -0,0 +1,4 @@
+Needs["NETLink`"];
+externalFloor = DefineDLLFunction["floor", "msvcrt.dll", "double", { "double" }];
+externalFloor[4.2]
+-> 4.
diff --git a/Task/Call-a-function/Icon/call-a-function.icon b/Task/Call-a-function/Icon/call-a-function.icon
new file mode 100644
index 0000000000..fc6a950b19
--- /dev/null
+++ b/Task/Call-a-function/Icon/call-a-function.icon
@@ -0,0 +1,30 @@
+procedure main() # demonstrate and describe function calling syntax and semantics
+
+ # normal procedure/function calling
+
+ f() # no arguments, also command context
+ f(x) # fixed number of arguments
+ f(x,h,w) # variable number of arguments (varargs)
+ y := f(x) # Obtaining the returned value of a function
+
+ # procedures as first class values and string invocation
+
+ f!L # Alternate calling syntax using a list as args
+ (if \x then f else g)() # call (f or g)()
+ f := write # assign a procedure
+ f("Write is now called") # ... and call it
+ "f"() # string invocation, procedure
+ "-"(1) # string invocation, operator
+
+ # Co-expressions
+
+ f{e1,e2} # parallel evaluation co-expression call
+ # equivalent to f([create e1, create e2])
+ expr @ coexp # transmission of a single value to a coexpression
+ [e1,e2]@coexp # ... of multiple values (list) to a coexpression
+ coexp(e1,e2) # ... same as above but only in Unicon
+
+ # Other
+
+ f("x:=",1,"y:=",2) # named parameters (user defined)
+end
diff --git a/Task/Call-a-function/J/call-a-function-1.j b/Task/Call-a-function/J/call-a-function-1.j
new file mode 100644
index 0000000000..fd26c1754e
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-1.j
@@ -0,0 +1,2 @@
+ verb noun
+ noun verb noun
diff --git a/Task/Call-a-function/J/call-a-function-10.j b/Task/Call-a-function/J/call-a-function-10.j
new file mode 100644
index 0000000000..09aa7a6682
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-10.j
@@ -0,0 +1 @@
+f 1; 2; 3; 4; <5
diff --git a/Task/Call-a-function/J/call-a-function-11.j b/Task/Call-a-function/J/call-a-function-11.j
new file mode 100644
index 0000000000..2551b65839
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-11.j
@@ -0,0 +1 @@
+f 1; 2; 3; 4; 5
diff --git a/Task/Call-a-function/J/call-a-function-12.j b/Task/Call-a-function/J/call-a-function-12.j
new file mode 100644
index 0000000000..7e307cf5d8
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-12.j
@@ -0,0 +1 @@
+f 'george';'tom';'howard'
diff --git a/Task/Call-a-function/J/call-a-function-13.j b/Task/Call-a-function/J/call-a-function-13.j
new file mode 100644
index 0000000000..93d23d9679
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-13.j
@@ -0,0 +1 @@
+1 2 3 f 'george';'tom';'howard'
diff --git a/Task/Call-a-function/J/call-a-function-14.j b/Task/Call-a-function/J/call-a-function-14.j
new file mode 100644
index 0000000000..bc53d50b41
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-14.j
@@ -0,0 +1,6 @@
+ obj=: conew'blank'
+ george__obj=: 1
+ tom__obj=: 2
+ howard__obj=: 3
+ f obj
+ coerase obj
diff --git a/Task/Call-a-function/J/call-a-function-15.j b/Task/Call-a-function/J/call-a-function-15.j
new file mode 100644
index 0000000000..8a9430dad5
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-15.j
@@ -0,0 +1 @@
+f 'george';1;'tom';2;'howard';3
diff --git a/Task/Call-a-function/J/call-a-function-16.j b/Task/Call-a-function/J/call-a-function-16.j
new file mode 100644
index 0000000000..4b9617c803
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-16.j
@@ -0,0 +1 @@
+f ('george';1),('tom';2),:(howard';3)
diff --git a/Task/Call-a-function/J/call-a-function-17.j b/Task/Call-a-function/J/call-a-function-17.j
new file mode 100644
index 0000000000..9696a507fa
--- /dev/null
+++ b/Task/Call-a-function/J/call-a-function-17.j
@@ -0,0 +1 @@
+f ('george';1);('tom';2);True]
diff --git a/Task/Call-a-function/Mathematica/call-a-function-4.mathematica b/Task/Call-a-function/Mathematica/call-a-function-4.mathematica
new file mode 100644
index 0000000000..23bf5e3405
--- /dev/null
+++ b/Task/Call-a-function/Mathematica/call-a-function-4.mathematica
@@ -0,0 +1,2 @@
+f[1,Option1->True]
+f[1,Option1->True,Option2->False]
diff --git a/Task/Call-a-function/Mathematica/call-a-function-5.mathematica b/Task/Call-a-function/Mathematica/call-a-function-5.mathematica
new file mode 100644
index 0000000000..ea30a8d2d6
--- /dev/null
+++ b/Task/Call-a-function/Mathematica/call-a-function-5.mathematica
@@ -0,0 +1 @@
+f[Option1->True,Option2->False]
diff --git a/Task/Call-a-function/Mathematica/call-a-function-6.mathematica b/Task/Call-a-function/Mathematica/call-a-function-6.mathematica
new file mode 100644
index 0000000000..a13c8d7589
--- /dev/null
+++ b/Task/Call-a-function/Mathematica/call-a-function-6.mathematica
@@ -0,0 +1 @@
+f[1,2];f[2,3]
diff --git a/Task/Call-a-function/Mathematica/call-a-function-7.mathematica b/Task/Call-a-function/Mathematica/call-a-function-7.mathematica
new file mode 100644
index 0000000000..cef5752d25
--- /dev/null
+++ b/Task/Call-a-function/Mathematica/call-a-function-7.mathematica
@@ -0,0 +1 @@
+(#^2)&[3];
diff --git a/Task/Call-an-object-method/J/call-an-object-method-1.j b/Task/Call-an-object-method/J/call-an-object-method-1.j
new file mode 100644
index 0000000000..25264b58d0
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-1.j
@@ -0,0 +1 @@
+methodName_className_ parameters
diff --git a/Task/Call-an-object-method/J/call-an-object-method-2.j b/Task/Call-an-object-method/J/call-an-object-method-2.j
new file mode 100644
index 0000000000..6068f2f45c
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-2.j
@@ -0,0 +1 @@
+objectReference=:'' conew 'className'
diff --git a/Task/Call-an-object-method/J/call-an-object-method-3.j b/Task/Call-an-object-method/J/call-an-object-method-3.j
new file mode 100644
index 0000000000..43cbebdd8d
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-3.j
@@ -0,0 +1 @@
+methodName__objectReference parameters
diff --git a/Task/Call-an-object-method/J/call-an-object-method-4.j b/Task/Call-an-object-method/J/call-an-object-method-4.j
new file mode 100644
index 0000000000..d349a7c4ed
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-4.j
@@ -0,0 +1 @@
+parameters methodName_className_ parameters
diff --git a/Task/Call-an-object-method/J/call-an-object-method-5.j b/Task/Call-an-object-method/J/call-an-object-method-5.j
new file mode 100644
index 0000000000..69e51d8163
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-5.j
@@ -0,0 +1 @@
+parameters methodName__objectReference parameters
diff --git a/Task/Call-an-object-method/J/call-an-object-method-6.j b/Task/Call-an-object-method/J/call-an-object-method-6.j
new file mode 100644
index 0000000000..7b010f8be3
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-6.j
@@ -0,0 +1,2 @@
+classReference=: <'className'
+methodName__classReference parameters
diff --git a/Task/Call-an-object-method/J/call-an-object-method-7.j b/Task/Call-an-object-method/J/call-an-object-method-7.j
new file mode 100644
index 0000000000..5f2ba0916d
--- /dev/null
+++ b/Task/Call-an-object-method/J/call-an-object-method-7.j
@@ -0,0 +1 @@
+methodName_123_ parameters
diff --git a/Task/Carmichael-3-strong-pseudoprimes/Mathematica/carmichael-3-strong-pseudoprimes.mathematica b/Task/Carmichael-3-strong-pseudoprimes/Mathematica/carmichael-3-strong-pseudoprimes.mathematica
new file mode 100644
index 0000000000..eb92dfbed5
--- /dev/null
+++ b/Task/Carmichael-3-strong-pseudoprimes/Mathematica/carmichael-3-strong-pseudoprimes.mathematica
@@ -0,0 +1,8 @@
+Cases[Cases[
+ Cases[Table[{p1, h3, d}, {p1, Array[Prime, PrimePi@61]}, {h3, 2,
+ p1 - 1}, {d, 1, h3 + p1 - 1}], {p1_Integer, h3_, d_} /;
+ PrimeQ[1 + (p1 - 1) (h3 + p1)/d] &&
+ Divisible[p1^2 + d, h3] :> {p1, 1 + (p1 - 1) (h3 + p1)/d, h3},
+ Infinity], {p1_, p2_, h3_} /; PrimeQ[1 + Floor[p1 p2/h3]] :> {p1,
+ p2, 1 + Floor[p1 p2/h3]}], {p1_, p2_, p3_} /;
+ Mod[p2 p3, p1 - 1] == 1 :> Print[p1, "*", p2, "*", p3]]
diff --git a/Task/Case-sensitivity-of-identifiers/Frink/case-sensitivity-of-identifiers.frink b/Task/Case-sensitivity-of-identifiers/Frink/case-sensitivity-of-identifiers.frink
new file mode 100644
index 0000000000..50e4e0d000
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Frink/case-sensitivity-of-identifiers.frink
@@ -0,0 +1,4 @@
+dog = "Benjamin"
+Dog = "Samba"
+DOG = "Bernie"
+println["There are three dogs named $dog, $Dog and $DOG"]
diff --git a/Task/Case-sensitivity-of-identifiers/GAP/case-sensitivity-of-identifiers.gap b/Task/Case-sensitivity-of-identifiers/GAP/case-sensitivity-of-identifiers.gap
new file mode 100644
index 0000000000..7e954c4513
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/GAP/case-sensitivity-of-identifiers.gap
@@ -0,0 +1,15 @@
+# GAP is case sensitive
+ThreeDogs := function()
+ local dog, Dog, DOG;
+ dog := "Benjamin";
+ Dog := "Samba";
+ DOG := "Bernie";
+ if dog = DOG then
+ Print("There is just one dog named ", dog, "\n");
+ else
+ Print("The three dogs are named ", dog, ", ", Dog, " and ", DOG, "\n");
+ fi;
+end;
+
+ThreeDogs();
+# The three dogs are named Benjamin, Samba and Bernie
diff --git a/Task/Case-sensitivity-of-identifiers/Groovy/case-sensitivity-of-identifiers.groovy b/Task/Case-sensitivity-of-identifiers/Groovy/case-sensitivity-of-identifiers.groovy
new file mode 100644
index 0000000000..04d6374ef7
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Groovy/case-sensitivity-of-identifiers.groovy
@@ -0,0 +1,2 @@
+def dog = "Benjamin", Dog = "Samba", DOG = "Bernie"
+println (dog == DOG ? "There is one dog named ${dog}" : "There are three dogs named ${dog}, ${Dog} and ${DOG}.")
diff --git a/Task/Case-sensitivity-of-identifiers/Icon/case-sensitivity-of-identifiers.icon b/Task/Case-sensitivity-of-identifiers/Icon/case-sensitivity-of-identifiers.icon
new file mode 100644
index 0000000000..a1e9047292
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Icon/case-sensitivity-of-identifiers.icon
@@ -0,0 +1,12 @@
+procedure main()
+
+ dog := "Benjamin"
+ Dog := "Samba"
+ DOG := "Bernie"
+
+ if dog == DOG then
+ write("There is just one dog named ", dog,".")
+ else
+ write("The three dogs are named ", dog, ", ", Dog, " and ", DOG, ".")
+
+end
diff --git a/Task/Case-sensitivity-of-identifiers/J/case-sensitivity-of-identifiers.j b/Task/Case-sensitivity-of-identifiers/J/case-sensitivity-of-identifiers.j
new file mode 100644
index 0000000000..c2fd75e09a
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/J/case-sensitivity-of-identifiers.j
@@ -0,0 +1,6 @@
+ NB. These variables are all different
+ dog=: 'Benjamin'
+ Dog=: 'Samba'
+ DOG=: 'Bernie'
+ 'The three dogs are named ',dog,', ',Dog,', and ',DOG
+The three dogs are named Benjamin, Samba, and Bernie
diff --git a/Task/Case-sensitivity-of-identifiers/K/case-sensitivity-of-identifiers.k b/Task/Case-sensitivity-of-identifiers/K/case-sensitivity-of-identifiers.k
new file mode 100644
index 0000000000..ba3bc48d8b
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/K/case-sensitivity-of-identifiers.k
@@ -0,0 +1,5 @@
+ dog: "Benjamin"
+ Dog: "Samba"
+ DOG: "Bernie"
+ "There are three dogs named ",dog,", ",Dog," and ",DOG
+"There are three dogs named Benjamin, Samba and Bernie"
diff --git a/Task/Case-sensitivity-of-identifiers/Liberty-BASIC/case-sensitivity-of-identifiers.liberty b/Task/Case-sensitivity-of-identifiers/Liberty-BASIC/case-sensitivity-of-identifiers.liberty
new file mode 100644
index 0000000000..06b5e159f2
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Liberty-BASIC/case-sensitivity-of-identifiers.liberty
@@ -0,0 +1,6 @@
+dog$ = "Benjamin"
+Dog$ = "Samba"
+DOG$ = "Bernie"
+print "The three dogs are "; dog$; ", "; Dog$; " and "; DOG$; "."
+
+end
diff --git a/Task/Case-sensitivity-of-identifiers/Maple/case-sensitivity-of-identifiers.maple b/Task/Case-sensitivity-of-identifiers/Maple/case-sensitivity-of-identifiers.maple
new file mode 100644
index 0000000000..d26efb6283
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Maple/case-sensitivity-of-identifiers.maple
@@ -0,0 +1,9 @@
+> dog, Dog, DOG := "Benjamin", "Samba", "Bernie":
+> if nops( { dog, Dog, DOG } ) = 3 then
+> printf( "There are three dogs named %s, %s and %s.\n", dog, Dog, DOG )
+> elif nops( { dog, Dog, DOG } ) = 2 then
+> printf( "WTF? There are two dogs named %s and %s.\n", op( { dog, Dog, DOG } ) )
+> else
+> printf( "There is one dog named %s.\n", dog )
+> end if:
+There are three dogs named Benjamin, Samba and Bernie.
diff --git a/Task/Case-sensitivity-of-identifiers/Mathematica/case-sensitivity-of-identifiers.mathematica b/Task/Case-sensitivity-of-identifiers/Mathematica/case-sensitivity-of-identifiers.mathematica
new file mode 100644
index 0000000000..954120cce4
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Mathematica/case-sensitivity-of-identifiers.mathematica
@@ -0,0 +1,4 @@
+dog = "Benjamin"; Dog = "Samba"; DOG = "Bernie";
+"The three dogs are named "<> dog <>", "<> Dog <>" and "<> DOG
+
+-> "The three dogs are named Benjamin, Samba and Bernie"
diff --git a/Task/Case-sensitivity-of-identifiers/Maxima/case-sensitivity-of-identifiers.maxima b/Task/Case-sensitivity-of-identifiers/Maxima/case-sensitivity-of-identifiers.maxima
new file mode 100644
index 0000000000..0a778ede45
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Maxima/case-sensitivity-of-identifiers.maxima
@@ -0,0 +1,6 @@
+/* Maxima is case sensitive */
+a: 1$
+A: 2$
+
+is(a = A);
+false
diff --git a/Task/Case-sensitivity-of-identifiers/Modula-2/case-sensitivity-of-identifiers.mod2 b/Task/Case-sensitivity-of-identifiers/Modula-2/case-sensitivity-of-identifiers.mod2
new file mode 100644
index 0000000000..6e45e3c6a2
--- /dev/null
+++ b/Task/Case-sensitivity-of-identifiers/Modula-2/case-sensitivity-of-identifiers.mod2
@@ -0,0 +1,14 @@
+MODULE dog;
+
+IMPORT InOut;
+
+TYPE String = ARRAY [0..31] OF CHAR;
+
+VAR dog, Dog, DOG : String;
+
+(* No compiler error, so the rest is simple *)
+
+BEGIN
+ InOut.WriteString ("Three happy dogs.");
+ InOut.WriteLn
+END dog.
diff --git a/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-1.j b/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-1.j
new file mode 100644
index 0000000000..be30044099
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-1.j
@@ -0,0 +1,23 @@
+avg=: +/ % #
+
+havePoints=: e."1/~ i.@#
+
+catmullclark=:3 :0
+ 'mesh points'=. y
+ face_point=. avg"2 mesh{points
+ point_face=. |: mesh havePoints points
+ avg_face_points=. point_face avg@#"1 2 face_point
+ edges=. ~.,/ meshEdges=. mesh /:~@,"+1|."1 mesh
+ edge_face=. *./"2 edges e."0 1/ mesh
+ edge_center=. avg"2 edges{points
+ edge_point=. (0.5*edge_center) + 0.25 * edge_face +/ .* face_point
+ point_edge=. |: edges havePoints points
+ avg_mid_edges=. point_edge avg@#"1 2 edge_center
+ n=. +/"1 point_edge
+ 'm3 m2 m1'=. (2,1,:n-3)%"1 n
+ new_coords=. (m1 * points) + (m2 * avg_face_points) + (m3 * avg_mid_edges)
+ pts=. face_point,edge_point,new_coords
+ c0=. (#edge_point)+ e0=. #face_point
+ msh=. (,c0+mesh),.(,e0+edges i. meshEdges),.((#i.)~/$mesh),.,e0+_1|."1 edges i. meshEdges
+ msh;pts
+)
diff --git a/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-2.j b/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-2.j
new file mode 100644
index 0000000000..143f44bf4f
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/J/catmull-clark-subdivision-surface-2.j
@@ -0,0 +1,33 @@
+NB.cube
+points=: _1+2*#:i.8
+mesh=: 1 A."1 I.(,1-|.)8&$@#&0 1">4 2 1
+
+ catmullclark mesh;points
+┌──────────┬─────────────────────────────┐
+│22 6 0 9│ 1 0 0│
+│23 7 0 6│ 0 1 0│
+│25 8 0 7│ 0 0 1│
+│24 9 0 8│ 0 0 _1│
+│20 10 1 12│ 0 _1 0│
+│21 11 1 10│ _1 0 0│
+│25 8 1 11│ 0.75 _0.75 0│
+│24 12 1 8│ 0.75 0 0.75│
+│19 13 2 14│ 0.75 0.75 0│
+│21 11 2 13│ 0.75 0 _0.75│
+│25 7 2 11│ _0.75 0.75 0│
+│23 14 2 7│ 0 0.75 0.75│
+│18 15 3 16│ 0 0.75 _0.75│
+│20 12 3 15│ _0.75 0 0.75│
+│24 9 3 12│ 0 _0.75 0.75│
+│22 16 3 9│ _0.75 0 _0.75│
+│18 17 4 16│ 0 _0.75 _0.75│
+│19 14 4 17│ _0.75 _0.75 0│
+│23 6 4 14│_0.555556 _0.555556 _0.555556│
+│22 16 4 6│_0.555556 _0.555556 0.555556│
+│18 17 5 15│_0.555556 0.555556 _0.555556│
+│19 13 5 17│_0.555556 0.555556 0.555556│
+│21 10 5 13│ 0.555556 _0.555556 _0.555556│
+│20 15 5 10│ 0.555556 _0.555556 0.555556│
+│ │ 0.555556 0.555556 _0.555556│
+│ │ 0.555556 0.555556 0.555556│
+└──────────┴─────────────────────────────┘
diff --git a/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-1.mathematica b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-1.mathematica
new file mode 100644
index 0000000000..dc8f24786c
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-1.mathematica
@@ -0,0 +1,6 @@
+subSetQ[large_,small_] := MemberQ[large,small]
+subSetQ[large_,small_List] := And@@(MemberQ[large,#]&/@small)
+
+containing[groupList_,item_]:= Flatten[Position[groupList,group_/;subSetQ[group,item]]]
+
+ReplaceFace[face_]:=Transpose[Prepend[Transpose[{#[[1]],face,#[[2]]}&/@Transpose[Partition[face,2,1,1]//{#,RotateRight[#]}&]],face]]
diff --git a/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-2.mathematica b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-2.mathematica
new file mode 100644
index 0000000000..72c0bc9bb0
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-2.mathematica
@@ -0,0 +1,28 @@
+CatMullClark[{Points_,faces_}]:=Block[{avgFacePoints,avgEdgePoints,updatedPoints,newEdgePoints,newPoints,edges,newFaces,weights,pointUpdate,edgeUpdate,newIndex},
+edges = DeleteDuplicates[Flatten[Partition[#,2,1,-1]&/@faces,1],Sort[#1]==Sort[#2]&];
+avgFacePoints=Mean[Points[[#]]] &/@ faces;
+avgEdgePoints=Mean[Points[[#]]] &/@ edges;
+
+weights[vertex_]:= Count[faces,vertex,2]//{(#-3),1,2}/#&;
+pointUpdate[vertex_]:=
+ If[Length[faces~containing~vertex]!=Length[edges~containing~vertex],
+ Mean[avgEdgePoints[[Select[edges~containing~vertex,holeQ[edges[[#]],faces]&]]]],
+ Total[weights[vertex]{ Points[[vertex]], Mean[avgFacePoints[[faces~containing~vertex]]], Mean[avgEdgePoints[[edges~containing~vertex]]]}]
+ ];
+
+edgeUpdate[edge_]:=
+ If[Length[faces~containing~edge]==1,
+ Mean[Points[[edge]]],
+ Mean[Points[[Flatten[{edge, faces[[faces~containing~edge]]}]]]]
+ ];
+
+updatedPoints = pointUpdate/@Range[1,Length[Points]];
+newEdgePoints = edgeUpdate/@edges;
+newPoints = Join[updatedPoints,avgFacePoints,newEdgePoints];
+
+newIndex[edge_/;Length[edge]==2] := Length[Points]+Length[faces]+Position[Sort/@edges,Sort@edge][[1,1]]
+newIndex[face_] := Length[Points]+Position[faces,face][[1,1]]
+
+newFaces = Flatten[Map[newIndex[#,{Points,edges,faces}]&,ReplaceFace/@faces,{-2}],1];
+{newPoints,newFaces}
+]
diff --git a/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-3.mathematica b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-3.mathematica
new file mode 100644
index 0000000000..210fb79ace
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-3.mathematica
@@ -0,0 +1,5 @@
+{points,faces}=PolyhedronData["Cube",{"VertexCoordinates","FaceIndices"}];
+
+Function[iteration,
+Graphics3D[(Polygon[iteration[[1]][[#]]]&/@iteration[[2]])]
+]/@NestList[CatMullClark,{points,faces},3]//GraphicsRow
diff --git a/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-4.mathematica b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-4.mathematica
new file mode 100644
index 0000000000..0241ab04a7
--- /dev/null
+++ b/Task/Catmull-Clark-subdivision-surface/Mathematica/catmull-clark-subdivision-surface-4.mathematica
@@ -0,0 +1,4 @@
+faces = Delete[faces, 6];
+Function[iteration, Graphics3D[
+ (Polygon[iteration[[1]][[#]]] & /@ iteration[[2]])
+ ]] /@ NestList[CatMullClark, {points, faces}, 3] // GraphicsRow
diff --git a/Task/Character-codes/FALSE/character-codes.false b/Task/Character-codes/FALSE/character-codes.false
new file mode 100644
index 0000000000..ca97865226
--- /dev/null
+++ b/Task/Character-codes/FALSE/character-codes.false
@@ -0,0 +1,2 @@
+'A."
+"65,
diff --git a/Task/Character-codes/Factor/character-codes.factor b/Task/Character-codes/Factor/character-codes.factor
new file mode 100644
index 0000000000..73c6c08fe2
--- /dev/null
+++ b/Task/Character-codes/Factor/character-codes.factor
@@ -0,0 +1,4 @@
+CHAR: katakana-letter-a .
+"ア" first .
+
+12450 1string print
diff --git a/Task/Character-codes/Fantom/character-codes.fantom b/Task/Character-codes/Fantom/character-codes.fantom
new file mode 100644
index 0000000000..d8d06ba5ae
--- /dev/null
+++ b/Task/Character-codes/Fantom/character-codes.fantom
@@ -0,0 +1,4 @@
+fansh> 97.toChar
+a
+fansh> 'a'.toInt
+97
diff --git a/Task/Character-codes/Frink/character-codes.frink b/Task/Character-codes/Frink/character-codes.frink
new file mode 100644
index 0000000000..449dd3f3ea
--- /dev/null
+++ b/Task/Character-codes/Frink/character-codes.frink
@@ -0,0 +1,4 @@
+println[char["a"]] // prints 97
+println[char[97]] // prints a
+println[char["Frink rules!"]] // prints [70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]
+println[[70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]] // prints "Frink rules!"
diff --git a/Task/Character-codes/GAP/character-codes.gap b/Task/Character-codes/GAP/character-codes.gap
new file mode 100644
index 0000000000..92d6697132
--- /dev/null
+++ b/Task/Character-codes/GAP/character-codes.gap
@@ -0,0 +1,5 @@
+# Code must be in 0 .. 255.
+CHAR_INT(65);
+# 'A'
+INT_CHAR('Z');
+# 90
diff --git a/Task/Character-codes/Golfscript/character-codes-1.golf b/Task/Character-codes/Golfscript/character-codes-1.golf
new file mode 100644
index 0000000000..6b0e1344f0
--- /dev/null
+++ b/Task/Character-codes/Golfscript/character-codes-1.golf
@@ -0,0 +1 @@
+97[]+''+p
diff --git a/Task/Character-codes/Golfscript/character-codes-2.golf b/Task/Character-codes/Golfscript/character-codes-2.golf
new file mode 100644
index 0000000000..41e090c06d
--- /dev/null
+++ b/Task/Character-codes/Golfscript/character-codes-2.golf
@@ -0,0 +1,4 @@
+'a')\;p
+'a'(\;p
+'a'0=p
+'a'{}/p
diff --git a/Task/Character-codes/Groovy/character-codes.groovy b/Task/Character-codes/Groovy/character-codes.groovy
new file mode 100644
index 0000000000..c22918d54f
--- /dev/null
+++ b/Task/Character-codes/Groovy/character-codes.groovy
@@ -0,0 +1,2 @@
+printf ("%d\n", ('a' as char) as int)
+printf ("%c\n", 97)
diff --git a/Task/Character-codes/HicEst/character-codes.hicest b/Task/Character-codes/HicEst/character-codes.hicest
new file mode 100644
index 0000000000..19db4fde36
--- /dev/null
+++ b/Task/Character-codes/HicEst/character-codes.hicest
@@ -0,0 +1 @@
+WRITE(Messagebox) ICHAR('a'), CHAR(97)
diff --git a/Task/Character-codes/Icon/character-codes.icon b/Task/Character-codes/Icon/character-codes.icon
new file mode 100644
index 0000000000..9f881a0aa6
--- /dev/null
+++ b/Task/Character-codes/Icon/character-codes.icon
@@ -0,0 +1,6 @@
+procedure main(arglist)
+if *arglist > 0 then L := arglist else L := [97, "a"]
+
+every x := !L do
+ write(x, " ==> ", char(integer(x)) | ord(x) ) # char produces a character, ord produces a number
+end
diff --git a/Task/Character-codes/J/character-codes.j b/Task/Character-codes/J/character-codes.j
new file mode 100644
index 0000000000..064f5ef3da
--- /dev/null
+++ b/Task/Character-codes/J/character-codes.j
@@ -0,0 +1,5 @@
+ 4 u: 97 98 99 9786
+abc☺
+
+ 3 u: 7 u: 'abc☺'
+97 98 99 9786
diff --git a/Task/Character-codes/Joy/character-codes.joy b/Task/Character-codes/Joy/character-codes.joy
new file mode 100644
index 0000000000..1eb1a274d7
--- /dev/null
+++ b/Task/Character-codes/Joy/character-codes.joy
@@ -0,0 +1,2 @@
+'a ord.
+97 chr.
diff --git a/Task/Character-codes/K/character-codes.k b/Task/Character-codes/K/character-codes.k
new file mode 100644
index 0000000000..038c6a31d1
--- /dev/null
+++ b/Task/Character-codes/K/character-codes.k
@@ -0,0 +1,5 @@
+ _ic "abcABC"
+97 98 99 65 66 67
+
+ _ci 97 98 99 65 66 67
+"abcABC"
diff --git a/Task/Character-codes/Lang5/character-codes.lang5 b/Task/Character-codes/Lang5/character-codes.lang5
new file mode 100644
index 0000000000..a9a0bb8f3e
--- /dev/null
+++ b/Task/Character-codes/Lang5/character-codes.lang5
@@ -0,0 +1,9 @@
+: CHAR "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[" comb
+ '\\ comb -1 remove append "]^_`abcdefghijklmnopqrstuvwxyz{|}~" comb append ;
+: CODE 95 iota 33 + ; : comb "" split ;
+: extract' rot 1 compress index subscript expand drop ;
+: chr CHAR CODE extract' ;
+: ord CODE CHAR extract' ;
+
+'a ord . # 97
+97 chr . # a
diff --git a/Task/Character-codes/Liberty-BASIC/character-codes.liberty b/Task/Character-codes/Liberty-BASIC/character-codes.liberty
new file mode 100644
index 0000000000..3ebf3475c1
--- /dev/null
+++ b/Task/Character-codes/Liberty-BASIC/character-codes.liberty
@@ -0,0 +1,4 @@
+charCode = 97
+char$ = "a"
+print chr$(charCode) 'prints a
+print asc(char$) 'prints 97
diff --git a/Task/Character-codes/Logo/character-codes.logo b/Task/Character-codes/Logo/character-codes.logo
new file mode 100644
index 0000000000..bc6c1e7510
--- /dev/null
+++ b/Task/Character-codes/Logo/character-codes.logo
@@ -0,0 +1,2 @@
+print ascii "a ; 97
+print char 97 ; a
diff --git a/Task/Character-codes/Logtalk/character-codes-1.logtalk b/Task/Character-codes/Logtalk/character-codes-1.logtalk
new file mode 100644
index 0000000000..fd84256b1b
--- /dev/null
+++ b/Task/Character-codes/Logtalk/character-codes-1.logtalk
@@ -0,0 +1,4 @@
+|?- char_code(Char, 97), write(Char).
+a
+Char = a
+yes
diff --git a/Task/Character-codes/Logtalk/character-codes-2.logtalk b/Task/Character-codes/Logtalk/character-codes-2.logtalk
new file mode 100644
index 0000000000..fbdc238cf8
--- /dev/null
+++ b/Task/Character-codes/Logtalk/character-codes-2.logtalk
@@ -0,0 +1,4 @@
+|?- char_code(a, Code), write(Code).
+97
+Code = 97
+yes
diff --git a/Task/Character-codes/MUMPS/character-codes.mumps b/Task/Character-codes/MUMPS/character-codes.mumps
new file mode 100644
index 0000000000..f1f441a7ff
--- /dev/null
+++ b/Task/Character-codes/MUMPS/character-codes.mumps
@@ -0,0 +1,2 @@
+WRITE $ASCII("M")
+WRITE $CHAR(77)
diff --git a/Task/Character-codes/Maple/character-codes-1.maple b/Task/Character-codes/Maple/character-codes-1.maple
new file mode 100644
index 0000000000..a844d92e90
--- /dev/null
+++ b/Task/Character-codes/Maple/character-codes-1.maple
@@ -0,0 +1,4 @@
+> use StringTools in Ord( "A" ); Char( 65 ) end;
+ 65
+
+ "A"
diff --git a/Task/Character-codes/Maple/character-codes-2.maple b/Task/Character-codes/Maple/character-codes-2.maple
new file mode 100644
index 0000000000..eedea18401
--- /dev/null
+++ b/Task/Character-codes/Maple/character-codes-2.maple
@@ -0,0 +1,5 @@
+> convert( "A", bytes );
+ [65]
+
+> convert( [65], bytes );
+ "A"
diff --git a/Task/Character-codes/Mathematica/character-codes.mathematica b/Task/Character-codes/Mathematica/character-codes.mathematica
new file mode 100644
index 0000000000..e3a1286418
--- /dev/null
+++ b/Task/Character-codes/Mathematica/character-codes.mathematica
@@ -0,0 +1,2 @@
+ToCharacterCode["abcd"]
+FromCharacterCode[{97}]
diff --git a/Task/Character-codes/Maxima/character-codes.maxima b/Task/Character-codes/Maxima/character-codes.maxima
new file mode 100644
index 0000000000..8f274aadd4
--- /dev/null
+++ b/Task/Character-codes/Maxima/character-codes.maxima
@@ -0,0 +1,5 @@
+ascii(65);
+"A"
+
+cint("A");
+65
diff --git a/Task/Character-codes/Metafont/character-codes.metafont b/Task/Character-codes/Metafont/character-codes.metafont
new file mode 100644
index 0000000000..28db2339a2
--- /dev/null
+++ b/Task/Character-codes/Metafont/character-codes.metafont
@@ -0,0 +1,14 @@
+message "enter a letter: ";
+string a;
+a := readstring;
+message decimal (ASCII a); % writes the decimal number of the first character
+ % of the string a
+message "enter a number: ";
+num := scantokens readstring;
+message char num; % num can be anything between 0 and 255; what will be seen
+ % on output depends on the encoding used by the "terminal"; e.g.
+ % any code beyond 127 when UTF-8 encoding is in use will give
+ % a bad encoding; e.g. to see correctly an "è", we should write
+message char10; % (this add a newline...)
+message char hex"c3" & char hex"a8"; % since C3 A8 is the UTF-8 encoding for "è"
+end
diff --git a/Task/Character-codes/Modula-2/character-codes-1.mod2 b/Task/Character-codes/Modula-2/character-codes-1.mod2
new file mode 100644
index 0000000000..b07f06e1e5
--- /dev/null
+++ b/Task/Character-codes/Modula-2/character-codes-1.mod2
@@ -0,0 +1,18 @@
+MODULE asc;
+
+IMPORT InOut;
+
+VAR letter : CHAR;
+ ascii : CARDINAL;
+
+BEGIN
+ letter := 'a';
+ InOut.Write (letter);
+ ascii := ORD (letter);
+ InOut.Write (11C); (* ASCII TAB *)
+ InOut.WriteCard (ascii, 8);
+ ascii := ascii - ORD ('0');
+ InOut.Write (11C); (* ASCII TAB *)
+ InOut.Write (CHR (ascii));
+ InOut.WriteLn
+END asc.
diff --git a/Task/Character-codes/Modula-2/character-codes-2.mod2 b/Task/Character-codes/Modula-2/character-codes-2.mod2
new file mode 100644
index 0000000000..d05d98e118
--- /dev/null
+++ b/Task/Character-codes/Modula-2/character-codes-2.mod2
@@ -0,0 +1,2 @@
+jan@Beryllium:~/modula/rosetta$ ./asc
+a 97 1
diff --git a/Task/Character-codes/Modula-3/character-codes.mod3 b/Task/Character-codes/Modula-3/character-codes.mod3
new file mode 100644
index 0000000000..de0a765e3d
--- /dev/null
+++ b/Task/Character-codes/Modula-3/character-codes.mod3
@@ -0,0 +1,2 @@
+ORD('a') (* Returns 97 *)
+VAL(97, CHAR); (* Returns 'a' *)
diff --git a/Task/Character-matching/Fantom/character-matching.fantom b/Task/Character-matching/Fantom/character-matching.fantom
new file mode 100644
index 0000000000..73e5577501
--- /dev/null
+++ b/Task/Character-matching/Fantom/character-matching.fantom
@@ -0,0 +1,22 @@
+class Main
+{
+ public static Void main ()
+ {
+ string := "Fantom Language"
+ echo ("String is: " + string)
+ echo ("does string start with 'Fantom'? " + string.startsWith("Fantom"))
+ echo ("does string start with 'Language'? " + string.startsWith("Language"))
+ echo ("does string contain 'age'? " + string.contains("age"))
+ echo ("does string contain 'page'? " + string.contains("page"))
+ echo ("does string end with 'Fantom'? " + string.endsWith("Fantom"))
+ echo ("does string end with 'Language'? " + string.endsWith("Language"))
+
+ echo ("Location of 'age' is: " + string.index("age"))
+ posn := string.index ("an")
+ echo ("First location of 'an' is: " + posn)
+ posn = string.index ("an", posn+1)
+ echo ("Second location of 'an' is: " + posn)
+ posn = string.index ("an", posn+1)
+ if (posn == null) echo ("No third location of 'an'")
+ }
+}
diff --git a/Task/Character-matching/GML/character-matching.gml b/Task/Character-matching/GML/character-matching.gml
new file mode 100644
index 0000000000..28fe7f7a2c
--- /dev/null
+++ b/Task/Character-matching/GML/character-matching.gml
@@ -0,0 +1,35 @@
+#define charMatch
+{
+ first = "qwertyuiop";
+
+ // Determining if the first string starts with second string
+ second = "qwerty";
+ if (string_pos(second, first) > 0) {
+ show_message("'" + first + "' starts with '" + second + "'");
+ } else {
+ show_message("'" + first + "' does not start with '" + second + "'");
+ }
+
+ second = "wert"
+ // Determining if the first string contains the second string at any location
+ // Print the location of the match for part 2
+ if (string_pos(second, first) > 0) {
+ show_message("'" + first + "' contains '" + second + "' at position " + string(x));
+ } else {
+ show_message("'" + first + "' does not contain '" + second + "'");
+ }
+ // Handle multiple occurrences of a string for part 2.
+ x = string_count(second, first);
+ show_message("'" + first + "' contains " + string(x) + " instances of '" + second + "'");
+
+// Determining if the first string ends with the second string
+ second = "random garbage"
+ temp = string_copy(first,
+ (string_length(first) - string_length(second)) + 1,
+ string_length(second));
+ if (temp == second) {
+ show_message("'" + first + "' ends with '" + second + "'");
+ } else {
+ show_message("'" + first + "' does not end with '" + second + "'");
+ }
+}
diff --git a/Task/Character-matching/J/character-matching-1.j b/Task/Character-matching/J/character-matching-1.j
new file mode 100644
index 0000000000..8a82f86763
--- /dev/null
+++ b/Task/Character-matching/J/character-matching-1.j
@@ -0,0 +1,3 @@
+startswith=: ] -: ({.~ #)
+contains=: +./@:E.~
+endswith=: ] -: ({.~ -@#)
diff --git a/Task/Character-matching/J/character-matching-2.j b/Task/Character-matching/J/character-matching-2.j
new file mode 100644
index 0000000000..4430d9ff95
--- /dev/null
+++ b/Task/Character-matching/J/character-matching-2.j
@@ -0,0 +1,18 @@
+ 'abcd' startswith 'ab'
+1
+ 'abcd' startswith 'cd'
+0
+ 'abcd' endswith 'ab'
+0
+ 'abcd' endswith 'cd'
+1
+ 'abcd' contains 'bb'
+0
+ 'abcd' contains 'ab'
+1
+ 'abcd' contains 'bc'
+1
+ 'abab' contains 'ab'
+1
+ 'abab' I.@E.~ 'ab' NB. find starting indicies
+0 2
diff --git a/Task/Character-matching/J/character-matching-3.j b/Task/Character-matching/J/character-matching-3.j
new file mode 100644
index 0000000000..22a6835cf1
--- /dev/null
+++ b/Task/Character-matching/J/character-matching-3.j
@@ -0,0 +1,6 @@
+ 0 1 2 3 startswith 0 1 NB. integer
+1
+ 4.2 5.1 1.3 9 3 contains 1.3 4.2 NB. floating point
+0
+ 4.2 5.1 1.3 4.2 9 3 contains 1.3 4.2
+1
diff --git a/Task/Character-matching/Julia/character-matching.julia b/Task/Character-matching/Julia/character-matching.julia
new file mode 100644
index 0000000000..24e8098397
--- /dev/null
+++ b/Task/Character-matching/Julia/character-matching.julia
@@ -0,0 +1,9 @@
+begins_with("abcd","ab") #returns true
+search("abcd","ab") #returns 1:2, indices range where string was found
+ends_with("abcd","zn") #returns false
+ismatch(r"ab","abcd") #returns true where 1st arg is regex string
+julia>for r in each_match(r"ab","abab")
+ println(r.offset)
+end
+1
+3
diff --git a/Task/Character-matching/K/character-matching-1.k b/Task/Character-matching/K/character-matching-1.k
new file mode 100644
index 0000000000..285ca7a5d4
--- /dev/null
+++ b/Task/Character-matching/K/character-matching-1.k
@@ -0,0 +1,3 @@
+startswith: {:[0<#p:_ss[x;y];~*p;0]}
+endswith: {0=(-#y)+(#x)-*_ss[x;y]}
+contains: {0<#_ss[x;y]}
diff --git a/Task/Character-matching/K/character-matching-2.k b/Task/Character-matching/K/character-matching-2.k
new file mode 100644
index 0000000000..4144f53050
--- /dev/null
+++ b/Task/Character-matching/K/character-matching-2.k
@@ -0,0 +1,14 @@
+ startswith["abcd";"ab"]
+1
+ startswith["abcd";"bc"]
+0
+ endswith["abcd";"cd"]
+1
+ endswith["abcd";"bc"]
+0
+ contains["abcdef";"cde"]
+1
+ contains["abcdef";"bdef"]
+0
+ _ss["abcdabceabc";"abc"] / location of matches
+0 4 8
diff --git a/Task/Character-matching/Lang5/character-matching.lang5 b/Task/Character-matching/Lang5/character-matching.lang5
new file mode 100644
index 0000000000..4190c4f84a
--- /dev/null
+++ b/Task/Character-matching/Lang5/character-matching.lang5
@@ -0,0 +1,20 @@
+: 2array 2 compress ; : bi* '_ set dip _ execute ; : bi@ dup bi* ;
+: comb "" split ; : concat "" join ; : dip swap '_ set execute _ ;
+: first 0 extract swap drop ; : flip comb reverse concat ;
+
+: contains
+ swap 'comb bi@ length do # create a matrix.
+ 1 - "dup 1 1 compress rotate" dip dup 0 == if break then
+ loop drop length compress swap drop
+ "length 1 -" bi@ rot 0 0 "'2array dip" '2array bi* swap 2array slice reverse
+ : concat.(*) concat ;
+ 'concat "'concat. apply" bi* eq 1 1 compress index collapse
+ length if expand drop else drop 0 then ; # r: position.
+: end-with 'flip bi@ start-with ;
+: start-with 'comb bi@ length rot swap iota subscript 'concat bi@ eq ;
+
+"rosettacode" "rosetta" start-with . # 1
+"rosettacode" "taco" contains . # 5
+"rosettacode" "ocat" contains . # 0
+"rosettacode" "edoc" end-with . # 0
+"rosettacode" "code" contains . # 7
diff --git a/Task/Character-matching/Liberty-BASIC/character-matching.liberty b/Task/Character-matching/Liberty-BASIC/character-matching.liberty
new file mode 100644
index 0000000000..b5afe2af9b
--- /dev/null
+++ b/Task/Character-matching/Liberty-BASIC/character-matching.liberty
@@ -0,0 +1,30 @@
+'1---Determining if the first string starts with second string
+st1$="first string"
+st2$="first"
+if left$(st1$,len(st2$))=st2$ then
+ print "First string starts with second string."
+end if
+
+'2---Determining if the first string contains the second string at any location
+'2.1---Print the location of the match for part 2
+st1$="Mississippi"
+st2$="i"
+if instr(st1$,st2$) then
+ print "First string contains second string."
+ print "Second string is at location ";instr(st1$,st2$)
+end if
+
+'2.2---Handle multiple occurrences of a string for part 2.
+pos=instr(st1$,st2$)
+while pos
+ count=count+1
+ pos=instr(st1$,st2$,pos+len(st2$))
+wend
+print "Number of times second string appears in first string is ";count
+
+'3---Determining if the first string ends with the second string
+st1$="first string"
+st2$="string"
+if right$(st1$,len(st2$))=st2$ then
+ print "First string ends with second string."
+end if
diff --git a/Task/Character-matching/Logo/character-matching.logo b/Task/Character-matching/Logo/character-matching.logo
new file mode 100644
index 0000000000..1dab1574ef
--- /dev/null
+++ b/Task/Character-matching/Logo/character-matching.logo
@@ -0,0 +1,17 @@
+to starts.with? :sub :thing
+ if empty? :sub [output "true]
+ if empty? :thing [output "false]
+ if not equal? first :sub first :thing [output "false]
+ output starts.with? butfirst :sub butfirst :thing
+end
+
+to ends.with? :sub :thing
+ if empty? :sub [output "true]
+ if empty? :thing [output "false]
+ if not equal? last :sub last :thing [output "false]
+ output ends.with? butlast :sub butlast :thing
+end
+
+show starts.with? "dog "doghouse ; true
+show ends.with? "house "doghouse ; true
+show substring? "gho "doghouse ; true (built-in)
diff --git a/Task/Character-matching/Maple/character-matching.maple b/Task/Character-matching/Maple/character-matching.maple
new file mode 100644
index 0000000000..2e99af2261
--- /dev/null
+++ b/Task/Character-matching/Maple/character-matching.maple
@@ -0,0 +1,31 @@
+> with( StringTools ): # bind package exports at the top-level
+> s := "dzrIemaWWIMidXYZwGiqkOOn":
+> s[1..4]; # pick a prefix
+ "dzrI"
+
+> IsPrefix( s[ 1 .. 4 ], s ); # check it
+ true
+
+> s[ -4 .. -1 ]; # pick a suffix
+ "kOOn"
+
+> IsSuffix( s[ -4 .. -1 ], s ); # check it
+ true
+
+> p := Search( "XYZ", s ); # find a substring
+ p := 14
+
+> s[ p .. p + 2 ]; # check
+ "XYZ"
+
+> SearchAll( [ "WWI", "XYZ" ], s ); # search for multiple patterns
+ [8, 1], [14, 2]
+
+> to 3 do s := cat( s, s ) end: length( s ); # build a longer string by repeated doubling
+ 192
+
+> p := SearchAll( "XYZ", s ); # find all occurrences
+ p := 14, 38, 62, 86, 110, 134, 158, 182
+
+> {seq}( s[ i .. i + 2 ], i = p ); # check them
+ {"XYZ"}
diff --git a/Task/Character-matching/Mathematica/character-matching.mathematica b/Task/Character-matching/Mathematica/character-matching.mathematica
new file mode 100644
index 0000000000..16048b8c66
--- /dev/null
+++ b/Task/Character-matching/Mathematica/character-matching.mathematica
@@ -0,0 +1,5 @@
+StartWith[x_, y_] := MemberQ[Flatten[StringPosition[x, y]], 1]
+EndWith[x_, y_] := MemberQ[Flatten[StringPosition[x, y]], StringLength[x]]
+StartWith["XYZaaabXYZaaaaXYZXYZ", "XYZ"]
+EndWith["XYZaaabXYZaaaaXYZXYZ", "XYZ"]
+StringPosition["XYZaaabXYZaaaaXYZXYZ", "XYZ"]
diff --git a/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-1.j b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-1.j
new file mode 100644
index 0000000000..73030c6eaf
--- /dev/null
+++ b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-1.j
@@ -0,0 +1 @@
+ machin =: 1r4p1 = [: +/ ({. * _3 o. %/@:}.)"1@:x:
diff --git a/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-2.j b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-2.j
new file mode 100644
index 0000000000..7d0ebf4aee
--- /dev/null
+++ b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-2.j
@@ -0,0 +1,68 @@
+ R =: <@:(0&".);._2 ];._2 noun define
+ 1 1 2
+ 1 1 3
+------------
+ 2 1 3
+ 1 1 7
+------------
+ 4 1 5
+ _1 1 239
+------------
+ 5 1 7
+ 2 3 79
+------------
+ 5 29 278
+ 7 3 79
+------------
+ 1 1 2
+ 1 1 5
+ 1 1 8
+------------
+ 4 1 5
+ _1 1 70
+ 1 1 99
+------------
+ 5 1 7
+ 4 1 53
+ 2 1 4443
+------------
+ 6 1 8
+ 2 1 57
+ 1 1 239
+------------
+ 8 1 10
+ _1 1 239
+ _4 1 515
+------------
+ 12 1 18
+ 8 1 57
+ _5 1 239
+------------
+ 16 1 21
+ 3 1 239
+ 4 3 1042
+------------
+ 22 1 28
+ 2 1 443
+ _5 1 1393
+_10 1 11018
+------------
+ 22 1 38
+ 17 7 601
+ 10 7 8149
+------------
+ 44 1 57
+ 7 1 239
+_12 1 682
+ 24 1 12943
+------------
+ 88 1 172
+ 51 1 239
+ 32 1 682
+ 44 1 5357
+ 68 1 12943
+------------
+)
+
+ machin&> R
+1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
diff --git a/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-3.j b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-3.j
new file mode 100644
index 0000000000..348281c239
--- /dev/null
+++ b/Task/Check-Machin-like-formulas/J/check-machin-like-formulas-3.j
@@ -0,0 +1,9 @@
+ counterExample=. 12944 (<_1;_1)} >{:R
+ counterExample NB. Same as final test case with 12943 incremented to 12944
+88 1 172
+51 1 239
+32 1 682
+44 1 5357
+68 1 12944
+ machin counterExample
+0
diff --git a/Task/Check-Machin-like-formulas/Mathematica/check-machin-like-formulas.mathematica b/Task/Check-Machin-like-formulas/Mathematica/check-machin-like-formulas.mathematica
new file mode 100644
index 0000000000..82d93de08b
--- /dev/null
+++ b/Task/Check-Machin-like-formulas/Mathematica/check-machin-like-formulas.mathematica
@@ -0,0 +1,21 @@
+Tan[ArcTan[1/2] + ArcTan[1/3]] == 1
+Tan[2 ArcTan[1/3] + ArcTan[1/7]] == 1
+Tan[4 ArcTan[1/5] - ArcTan[1/239]] == 1
+Tan[5 ArcTan[1/7] + 2 ArcTan[3/79]] == 1
+Tan[5 ArcTan[29/278] + 7 ArcTan[3/79]] == 1
+Tan[ArcTan[1/2] + ArcTan[1/5] + ArcTan[1/8]] == 1
+Tan[4 ArcTan[1/5] - ArcTan[1/70] + ArcTan[1/99]] == 1
+Tan[5 ArcTan[1/7] + 4 ArcTan[1/53] + 2 ArcTan[1/4443]] == 1
+Tan[6 ArcTan[1/8] + 2 ArcTan[1/57] + ArcTan[1/239]] == 1
+Tan[8 ArcTan[1/10] - ArcTan[1/239] - 4 ArcTan[1/515]] == 1
+Tan[12 ArcTan[1/18] + 8 ArcTan[1/57] - 5 ArcTan[1/239]] == 1
+Tan[16 ArcTan[1/21] + 3 ArcTan[1/239] + 4 ArcTan[3/1042]] == 1
+Tan[22 ArcTan[1/28] + 2 ArcTan[1/443] - 5 ArcTan[1/1393] -
+ 10 ArcTan[1/11018]] == 1
+Tan[22 ArcTan[1/38] + 17 ArcTan[7/601] + 10 ArcTan[7/8149]] == 1
+Tan[44 ArcTan[1/57] + 7 ArcTan[1/239] - 12 ArcTan[1/682] +
+ 24 ArcTan[1/12943]] == 1
+Tan[88 ArcTan[1/172] + 51 ArcTan[1/239] + 32 ArcTan[1/682] +
+ 44 ArcTan[1/5357] + 68 ArcTan[1/12943]] == 1
+Tan[88 ArcTan[1/172] + 51 ArcTan[1/239] + 32 ArcTan[1/682] +
+ 44 ArcTan[1/5357] + 68 ArcTan[1/12944]] == 1
diff --git a/Task/Check-Machin-like-formulas/Maxima/check-machin-like-formulas.maxima b/Task/Check-Machin-like-formulas/Maxima/check-machin-like-formulas.maxima
new file mode 100644
index 0000000000..df06789ca8
--- /dev/null
+++ b/Task/Check-Machin-like-formulas/Maxima/check-machin-like-formulas.maxima
@@ -0,0 +1,18 @@
+trigexpand:true$
+is(tan(atan(1/2)+atan(1/3))=1);
+is(tan(2*atan(1/3)+atan(1/7))=1);
+is(tan(4*atan(1/5)-atan(1/239))=1);
+is(tan(5*atan(1/7)+2*atan(3/79))=1);
+is(tan(5*atan(29/278)+7*atan(3/79))=1);
+is(tan(atan(1/2)+atan(1/5)+atan(1/8))=1);
+is(tan(4*atan(1/5)-atan(1/70)+atan(1/99))=1);
+is(tan(5*atan(1/7)+4*atan(1/53)+2*atan(1/4443))=1);
+is(tan(6*atan(1/8)+2*atan(1/57)+atan(1/239))=1);
+is(tan(8*atan(1/10)-atan(1/239)-4*atan(1/515))=1);
+is(tan(12*atan(1/18)+8*atan(1/57)-5*atan(1/239))=1);
+is(tan(16*atan(1/21)+3*atan(1/239)+4*atan(3/1042))=1);
+is(tan(22*atan(1/28)+2*atan(1/443)-5*atan(1/1393)-10*atan(1/11018))=1);
+is(tan(22*atan(1/38)+17*atan(7/601)+10*atan(7/8149))=1);
+is(tan(44*atan(1/57)+7*atan(1/239)-12*atan(1/682)+24*atan(1/12943))=1);
+is(tan(88*atan(1/172)+51*atan(1/239)+32*atan(1/682)+44*atan(1/5357)+68*atan(1/12943))=1);
+is(tan(88*atan(1/172)+51*atan(1/239)+32*atan(1/682)+44*atan(1/5357)+68*atan(1/12944))=1);
diff --git a/Task/Check-that-file-exists/Factor/check-that-file-exists.factor b/Task/Check-that-file-exists/Factor/check-that-file-exists.factor
new file mode 100644
index 0000000000..79763e1d65
--- /dev/null
+++ b/Task/Check-that-file-exists/Factor/check-that-file-exists.factor
@@ -0,0 +1,4 @@
+: print-exists? ( path -- )
+ [ write ": " write ] [ exists? "exists." "doesn't exist." ? print ] bi ;
+
+{ "input.txt" "/input.txt" "docs" "/docs" } [ print-exists? ] each
diff --git a/Task/Check-that-file-exists/GAP/check-that-file-exists.gap b/Task/Check-that-file-exists/GAP/check-that-file-exists.gap
new file mode 100644
index 0000000000..f1df7217b8
--- /dev/null
+++ b/Task/Check-that-file-exists/GAP/check-that-file-exists.gap
@@ -0,0 +1,4 @@
+IsExistingFile("input.txt");
+IsDirectoryPath("docs");
+IsExistingFile("/input.txt");
+IsDirectoryPath("/docs");
diff --git a/Task/Check-that-file-exists/Groovy/check-that-file-exists.groovy b/Task/Check-that-file-exists/Groovy/check-that-file-exists.groovy
new file mode 100644
index 0000000000..39ba67e3b2
--- /dev/null
+++ b/Task/Check-that-file-exists/Groovy/check-that-file-exists.groovy
@@ -0,0 +1,4 @@
+println new File('input.txt').exists()
+println new File('/input.txt').exists()
+println new File('docs').exists()
+println new File('/docs').exists()
diff --git a/Task/Check-that-file-exists/HicEst/check-that-file-exists.hicest b/Task/Check-that-file-exists/HicEst/check-that-file-exists.hicest
new file mode 100644
index 0000000000..23a78f5ea0
--- /dev/null
+++ b/Task/Check-that-file-exists/HicEst/check-that-file-exists.hicest
@@ -0,0 +1,4 @@
+ OPEN(FIle= 'input.txt', OLD, IOStat=ios, ERror=99)
+ OPEN(FIle='C:\input.txt', OLD, IOStat=ios, ERror=99)
+! ...
+99 WRITE(Messagebox='!') 'File does not exist. Error message ', ios
diff --git a/Task/Check-that-file-exists/Icon/check-that-file-exists.icon b/Task/Check-that-file-exists/Icon/check-that-file-exists.icon
new file mode 100644
index 0000000000..7476af5a75
--- /dev/null
+++ b/Task/Check-that-file-exists/Icon/check-that-file-exists.icon
@@ -0,0 +1,4 @@
+every dir := !["./","/"] do {
+ write("file ", f := dir || "input.txt", if stat(f) then " exists." else " doesn't exist.")
+ write("directory ", f := dir || "docs", if stat(f) then " exists." else " doesn't exist.")
+ }
diff --git a/Task/Check-that-file-exists/J/check-that-file-exists.j b/Task/Check-that-file-exists/J/check-that-file-exists.j
new file mode 100644
index 0000000000..7ffd6954b7
--- /dev/null
+++ b/Task/Check-that-file-exists/J/check-that-file-exists.j
@@ -0,0 +1,6 @@
+require 'files'
+fexist 'input.txt'
+fexist '/input.txt'
+direxist=: 2 = ftype
+direxist 'docs'
+direxist '/docs'
diff --git a/Task/Check-that-file-exists/Liberty-BASIC/check-that-file-exists.liberty b/Task/Check-that-file-exists/Liberty-BASIC/check-that-file-exists.liberty
new file mode 100644
index 0000000000..d270a2b8b9
--- /dev/null
+++ b/Task/Check-that-file-exists/Liberty-BASIC/check-that-file-exists.liberty
@@ -0,0 +1,29 @@
+'fileExists.bas - Show how to determine if a file exists
+dim info$(10,10)
+input "Type a file path (ie. c:\windows\somefile.txt)?"; fpath$
+if fileExists(fpath$) then
+ print fpath$; " exists!"
+else
+ print fpath$; " doesn't exist!"
+end if
+end
+
+'return a true if the file in fullPath$ exists, else return false
+function fileExists(fullPath$)
+ files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
+ fileExists = val(info$(0, 0)) > 0
+end function
+
+'return just the directory path from a full file path
+function pathOnly$(fullPath$)
+ pathOnly$ = fullPath$
+ while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
+ pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
+ wend
+end function
+
+'return just the filename from a full file path
+function filenameOnly$(fullPath$)
+ pathLength = len(pathOnly$(fullPath$))
+ filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
+end function
diff --git a/Task/Check-that-file-exists/Logo/check-that-file-exists-1.logo b/Task/Check-that-file-exists/Logo/check-that-file-exists-1.logo
new file mode 100644
index 0000000000..4c74054f6f
--- /dev/null
+++ b/Task/Check-that-file-exists/Logo/check-that-file-exists-1.logo
@@ -0,0 +1,4 @@
+show file? "input.txt
+show file? "/input.txt
+show file? "docs
+show file? "/docs
diff --git a/Task/Check-that-file-exists/Logo/check-that-file-exists-2.logo b/Task/Check-that-file-exists/Logo/check-that-file-exists-2.logo
new file mode 100644
index 0000000000..926f40edf2
--- /dev/null
+++ b/Task/Check-that-file-exists/Logo/check-that-file-exists-2.logo
@@ -0,0 +1,2 @@
+setprefix "/
+show file? "input.txt
diff --git a/Task/Check-that-file-exists/MAXScript/check-that-file-exists.max b/Task/Check-that-file-exists/MAXScript/check-that-file-exists.max
new file mode 100644
index 0000000000..320af0bd63
--- /dev/null
+++ b/Task/Check-that-file-exists/MAXScript/check-that-file-exists.max
@@ -0,0 +1,6 @@
+-- Here
+doesFileExist "input.txt"
+(getDirectories "docs").count == 1
+-- Root
+doesFileExist "\input.txt"
+(getDirectories "C:\docs").count == 1
diff --git a/Task/Check-that-file-exists/Mathematica/check-that-file-exists.mathematica b/Task/Check-that-file-exists/Mathematica/check-that-file-exists.mathematica
new file mode 100644
index 0000000000..15d804a5c7
--- /dev/null
+++ b/Task/Check-that-file-exists/Mathematica/check-that-file-exists.mathematica
@@ -0,0 +1,6 @@
+wd = NotebookDirectory[];
+FileExistsQ[wd <> "input.txt"]
+DirectoryQ[wd <> "docs"]
+
+FileExistsQ["/" <> "input.txt"]
+DirectoryQ["/" <> "docs"]
diff --git a/Task/Check-that-file-exists/Modula-3/check-that-file-exists.mod3 b/Task/Check-that-file-exists/Modula-3/check-that-file-exists.mod3
new file mode 100644
index 0000000000..e2162cd4ce
--- /dev/null
+++ b/Task/Check-that-file-exists/Modula-3/check-that-file-exists.mod3
@@ -0,0 +1,21 @@
+MODULE FileTest EXPORTS Main;
+
+IMPORT IO, Fmt, FS, File, OSError, Pathname;
+
+PROCEDURE FileExists(file: Pathname.T): BOOLEAN =
+ VAR status: File.Status;
+ BEGIN
+ TRY
+ status := FS.Status(file);
+ RETURN TRUE;
+ EXCEPT
+ | OSError.E => RETURN FALSE;
+ END;
+ END FileExists;
+
+BEGIN
+ IO.Put(Fmt.Bool(FileExists("input.txt")) & "\n");
+ IO.Put(Fmt.Bool(FileExists("/input.txt")) & "\n");
+ IO.Put(Fmt.Bool(FileExists("docs/")) & "\n");
+ IO.Put(Fmt.Bool(FileExists("/docs")) & "\n");
+END FileTest.
diff --git a/Task/Cholesky-decomposition/Fantom/cholesky-decomposition.fantom b/Task/Cholesky-decomposition/Fantom/cholesky-decomposition.fantom
new file mode 100644
index 0000000000..902c7f9a6d
--- /dev/null
+++ b/Task/Cholesky-decomposition/Fantom/cholesky-decomposition.fantom
@@ -0,0 +1,55 @@
+**
+** Cholesky decomposition
+**
+
+class Main
+{
+ // create an array of Floats, initialised to 0.0
+ Float[][] makeArray (Int i, Int j)
+ {
+ Float[][] result := [,]
+ i.times { result.add ([,]) }
+ i.times |Int x|
+ {
+ j.times
+ {
+ result[x].add(0f)
+ }
+ }
+ return result
+ }
+
+ // perform the Cholesky decomposition
+ Float[][] cholesky (Float[][] array)
+ {
+ m := array.size
+ Float[][] l := makeArray (m, m)
+ m.times |Int i|
+ {
+ (i+1).times |Int k|
+ {
+ Float sum := (0.. Float|
+ {
+ a + l[i][j] * l[k][j]
+ }
+ if (i == k)
+ l[i][k] = (array[i][i]-sum).sqrt
+ else
+ l[i][k] = (1.0f / l[k][k]) * (array[i][k] - sum)
+ }
+ }
+ return l
+ }
+
+ Void runTest (Float[][] array)
+ {
+ echo (array)
+ echo (cholesky (array))
+ }
+
+ Void main ()
+ {
+ runTest ([[25f,15f,-5f],[15f,18f,0f],[-5f,0f,11f]])
+ runTest ([[18f,22f,54f,42f],[22f,70f,86f,62f],[54f,86f,174f,134f],[42f,62f,134f,106f]])
+ }
+}
diff --git a/Task/Cholesky-decomposition/Icon/cholesky-decomposition.icon b/Task/Cholesky-decomposition/Icon/cholesky-decomposition.icon
new file mode 100644
index 0000000000..5553cf421c
--- /dev/null
+++ b/Task/Cholesky-decomposition/Icon/cholesky-decomposition.icon
@@ -0,0 +1,41 @@
+procedure cholesky (array)
+ result := make_square_array (*array)
+ every (i := 1 to *array) do {
+ every (k := 1 to i) do {
+ sum := 0
+ every (j := 1 to (k-1)) do {
+ sum +:= result[i][j] * result[k][j]
+ }
+ if (i = k)
+ then result[i][k] := sqrt(array[i][i] - sum)
+ else result[i][k] := 1.0 / result[k][k] * (array[i][k] - sum)
+ }
+ }
+ return result
+end
+
+procedure make_square_array (n)
+ result := []
+ every (1 to n) do push (result, list(n, 0))
+ return result
+end
+
+procedure print_array (array)
+ every (row := !array) do {
+ every writes (!row || " ")
+ write ()
+ }
+end
+
+procedure do_cholesky (array)
+ write ("Input:")
+ print_array (array)
+ result := cholesky (array)
+ write ("Result:")
+ print_array (result)
+end
+
+procedure main ()
+ do_cholesky ([[25,15,-5],[15,18,0],[-5,0,11]])
+ do_cholesky ([[18,22,54,42],[22,70,86,62],[54,86,174,134],[42,62,134,106]])
+end
diff --git a/Task/Cholesky-decomposition/J/cholesky-decomposition-1.j b/Task/Cholesky-decomposition/J/cholesky-decomposition-1.j
new file mode 100644
index 0000000000..9d58d5f3cf
--- /dev/null
+++ b/Task/Cholesky-decomposition/J/cholesky-decomposition-1.j
@@ -0,0 +1,16 @@
+mp=: +/ . * NB. matrix product
+h =: +@|: NB. conjugate transpose
+
+cholesky=: 3 : 0
+ n=. #A=. y
+ if. 1>:n do.
+ assert. (A=|A)>0=A NB. check for positive definite
+ %:A
+ else.
+ p=. >.n%2 [ q=. <.n%2
+ X=. (p,p) {.A [ Y=. (p,-q){.A [ Z=. (-q,q){.A
+ L0=. cholesky X
+ L1=. cholesky Z-(T=.(h Y) mp %.X) mp Y
+ L0,(T mp L0),.L1
+ end.
+)
diff --git a/Task/Cholesky-decomposition/J/cholesky-decomposition-2.j b/Task/Cholesky-decomposition/J/cholesky-decomposition-2.j
new file mode 100644
index 0000000000..55e266518b
--- /dev/null
+++ b/Task/Cholesky-decomposition/J/cholesky-decomposition-2.j
@@ -0,0 +1,11 @@
+ eg1=: 25 15 _5 , 15 18 0 ,: _5 0 11
+ eg2=: 18 22 54 42 , 22 70 86 62 , 54 86 174 134 ,: 42 62 134 106
+ cholesky eg1
+ 5 0 0
+ 3 3 0
+_1 1 3
+ cholesky eg2
+4.24264 0 0 0
+5.18545 6.56591 0 0
+12.7279 3.04604 1.64974 0
+9.89949 1.62455 1.84971 1.39262
diff --git a/Task/Cholesky-decomposition/Maple/cholesky-decomposition.maple b/Task/Cholesky-decomposition/Maple/cholesky-decomposition.maple
new file mode 100644
index 0000000000..6ecb49c6bf
--- /dev/null
+++ b/Task/Cholesky-decomposition/Maple/cholesky-decomposition.maple
@@ -0,0 +1,52 @@
+> A := << 25, 15, -5; 15, 18, 0; -5, 0, 11 >>;
+ [25 15 -5]
+ [ ]
+ A := [15 18 0]
+ [ ]
+ [-5 0 11]
+
+> B := << 18, 22, 54, 42; 22, 70, 86, 62; 54, 86, 174, 134; 42, 62, 134, 106>>;
+ [18 22 54 42]
+ [ ]
+ [22 70 86 62]
+ B := [ ]
+ [54 86 174 134]
+ [ ]
+ [42 62 134 106]
+
+> use LinearAlgebra in
+> LUDecomposition( A, method = Cholesky );
+> LUDecomposition( B, method = Cholesky );
+> evalf( % );
+> end use;
+ [ 5 0 0]
+ [ ]
+ [ 3 3 0]
+ [ ]
+ [-1 1 3]
+
+ [ 1/2 ]
+ [3 2 0 0 0 ]
+ [ ]
+ [ 1/2 1/2 ]
+ [11 2 2 97 ]
+ [------- ------- 0 0 ]
+ [ 3 3 ]
+ [ ]
+ [ 1/2 1/2 ]
+ [ 1/2 30 97 2 6402 ]
+ [9 2 -------- --------- 0 ]
+ [ 97 97 ]
+ [ ]
+ [ 1/2 1/2 1/2]
+ [ 1/2 16 97 74 6402 8 33 ]
+ [7 2 -------- ---------- -------]
+ [ 97 3201 33 ]
+
+ [4.242640686 0. 0. 0. ]
+ [ ]
+ [5.185449728 6.565905202 0. 0. ]
+ [ ]
+ [12.72792206 3.046038495 1.649742248 0. ]
+ [ ]
+ [9.899494934 1.624553864 1.849711006 1.392621248]
diff --git a/Task/Cholesky-decomposition/Mathematica/cholesky-decomposition.mathematica b/Task/Cholesky-decomposition/Mathematica/cholesky-decomposition.mathematica
new file mode 100644
index 0000000000..fb97144b7b
--- /dev/null
+++ b/Task/Cholesky-decomposition/Mathematica/cholesky-decomposition.mathematica
@@ -0,0 +1 @@
+CholeskyDecomposition[{{25, 15, -5}, {15, 18, 0}, {-5, 0, 11}}]
diff --git a/Task/Cholesky-decomposition/Maxima/cholesky-decomposition.maxima b/Task/Cholesky-decomposition/Maxima/cholesky-decomposition.maxima
new file mode 100644
index 0000000000..3253017048
--- /dev/null
+++ b/Task/Cholesky-decomposition/Maxima/cholesky-decomposition.maxima
@@ -0,0 +1,12 @@
+/* Cholesky decomposition is built-in */
+
+a: hilbert_matrix(4)$
+
+b: cholesky(a);
+/* matrix([1, 0, 0, 0 ],
+ [1/2, 1/(2*sqrt(3)), 0, 0 ],
+ [1/3, 1/(2*sqrt(3)), 1/(6*sqrt(5)), 0 ],
+ [1/4, 3^(3/2)/20, 1/(4*sqrt(5)), 1/(20*sqrt(7))]) */
+
+b . transpose(b) - a;
+matrix([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0])
diff --git a/Task/Classes/Factor/classes.factor b/Task/Classes/Factor/classes.factor
new file mode 100644
index 0000000000..a373351d6d
--- /dev/null
+++ b/Task/Classes/Factor/classes.factor
@@ -0,0 +1,8 @@
+TUPLE: my-class foo bar baz ;
+M: my-class quux foo>> 20 + ;
+C: my-class
+10 20 30 quux ! result: 30
+TUPLE: my-child-class < my-class quxx ;
+C: my-child-class
+M: my-child-class foobar 20 >>quux ;
+20 20 30 foobar quux ! result: 30
diff --git a/Task/Classes/Falcon/classes-1.falcon b/Task/Classes/Falcon/classes-1.falcon
new file mode 100644
index 0000000000..1b16918650
--- /dev/null
+++ b/Task/Classes/Falcon/classes-1.falcon
@@ -0,0 +1,6 @@
+class class_name[ ( param_list ) ] [ from inh1[, inh2, ..., inhN] ]
+ [ static block ]
+ [ properties declaration ]
+ [init block]
+ [method list]
+end
diff --git a/Task/Classes/Falcon/classes-2.falcon b/Task/Classes/Falcon/classes-2.falcon
new file mode 100644
index 0000000000..ec546e63d9
--- /dev/null
+++ b/Task/Classes/Falcon/classes-2.falcon
@@ -0,0 +1,15 @@
+class mailbox( max_msg )
+
+ capacity = max_msg * 10
+ name = nil
+ messages = []
+
+ init
+ printl( "Box now ready for ", self.capacity, " messages." )
+ end
+
+ function slot_left()
+ return self.capacity - len( self.messages )
+ end
+
+end
diff --git a/Task/Classes/Falcon/classes-3.falcon b/Task/Classes/Falcon/classes-3.falcon
new file mode 100644
index 0000000000..0d04d2ddce
--- /dev/null
+++ b/Task/Classes/Falcon/classes-3.falcon
@@ -0,0 +1,2 @@
+m = mailbox( 10 )
+// Ouputs: Box now ready for 100 messages.
diff --git a/Task/Classes/Fancy/classes.fancy b/Task/Classes/Fancy/classes.fancy
new file mode 100644
index 0000000000..283f045fcf
--- /dev/null
+++ b/Task/Classes/Fancy/classes.fancy
@@ -0,0 +1,26 @@
+class MyClass {
+ read_slot: 'instance_var # creates getter method for @instance_var
+ @@class_var = []
+
+ def initialize {
+ # 'initialize' is the constructor method invoked during 'MyClass.new' by convention
+ @instance_var = 0
+ }
+
+ def some_method {
+ @instance_var = 1
+ @another_instance_var = "foo"
+ }
+
+ # define class methods: define a singleton method on the class object
+ def self class_method {
+ # ...
+ }
+
+ # you can also name the class object itself
+ def MyClass class_method {
+ # ...
+ }
+}
+
+myclass = MyClass new
diff --git a/Task/Classes/Fantom/classes.fantom b/Task/Classes/Fantom/classes.fantom
new file mode 100644
index 0000000000..6d981525e1
--- /dev/null
+++ b/Task/Classes/Fantom/classes.fantom
@@ -0,0 +1,27 @@
+class MyClass
+{
+ // an instance variable
+ Int x
+
+ // a constructor, providing default value for instance variable
+ new make (Int x := 1)
+ {
+ this.x = x
+ }
+
+ // a method, return double the number x
+ public Int double ()
+ {
+ return 2 * x
+ }
+}
+
+class Main
+{
+ public static Void main ()
+ {
+ a := MyClass (2) // instantiates the class, with x = 2
+ b := MyClass() // instantiates the class, x defaults to 1
+ c := MyClass { x = 3 } // instantiates the class, sets x to 3
+ }
+}
diff --git a/Task/Classes/Groovy/classes-1.groovy b/Task/Classes/Groovy/classes-1.groovy
new file mode 100644
index 0000000000..058c687831
--- /dev/null
+++ b/Task/Classes/Groovy/classes-1.groovy
@@ -0,0 +1,15 @@
+/** Ye olde classe declaration */
+class Stuff {
+ /** Heare bee anne instance variable declared */
+ def guts
+
+ /** This constuctor converts bits into Stuff */
+ Stuff(injectedGuts) {
+ guts = injectedGuts
+ }
+
+ /** Brethren and sistren, let us flangulate with this fine flangulating method */
+ def flangulate() {
+ println "This stuff is flangulating its guts: ${guts}"
+ }
+}
diff --git a/Task/Classes/Groovy/classes-2.groovy b/Task/Classes/Groovy/classes-2.groovy
new file mode 100644
index 0000000000..1eafd50c7d
--- /dev/null
+++ b/Task/Classes/Groovy/classes-2.groovy
@@ -0,0 +1,16 @@
+def stuff = new Stuff('''
+I have made mistakes in the past.
+I have made mistakes in the future.
+ -- Vice President Dan Quayle
+''')
+
+stuff.flangulate()
+
+stuff.guts = '''
+Our enemies are innovative and resourceful, and so are we.
+They never stop thinking about new ways to harm our country and our people,
+and neither do we.
+ -- President George W. Bush
+'''
+
+stuff.flangulate()
diff --git a/Task/Classes/J/classes-1.j b/Task/Classes/J/classes-1.j
new file mode 100644
index 0000000000..e0bb86c4b1
--- /dev/null
+++ b/Task/Classes/J/classes-1.j
@@ -0,0 +1,11 @@
+coclass 'exampleClass'
+
+exampleMethod=: monad define
+ 1+exampleInstanceVariable
+)
+
+create=: monad define
+ 'this is the constructor'
+)
+
+exampleInstanceVariable=: 0
diff --git a/Task/Classes/J/classes-2.j b/Task/Classes/J/classes-2.j
new file mode 100644
index 0000000000..0b49b9b16f
--- /dev/null
+++ b/Task/Classes/J/classes-2.j
@@ -0,0 +1 @@
+ exampleObject=: conew 'exampleClass'
diff --git a/Task/Classes/Lisaac/classes.lisaac b/Task/Classes/Lisaac/classes.lisaac
new file mode 100644
index 0000000000..1768b8ef03
--- /dev/null
+++ b/Task/Classes/Lisaac/classes.lisaac
@@ -0,0 +1,24 @@
+Section Header
+
++ name := SAMPLE;
+
+Section Inherit
+
+- parent : OBJECT := OBJECT;
+
+Section Private
+
++ variable : INTEGER <- 0;
+
+Section Public
+
+- some_method <- (
+ variable := 1;
+);
+
+- main <- (
+ + sample : SAMPLE;
+
+ sample := SAMPLE.clone;
+ sample.some_method;
+);
diff --git a/Task/Classes/Logtalk/classes-1.logtalk b/Task/Classes/Logtalk/classes-1.logtalk
new file mode 100644
index 0000000000..f78977faa1
--- /dev/null
+++ b/Task/Classes/Logtalk/classes-1.logtalk
@@ -0,0 +1,20 @@
+:- object(metaclass,
+ instantiates(metaclass)).
+
+ :- public(new/2).
+ new(Instance, Value) :-
+ self(Class),
+ create_object(Instance, [instantiates(Class)], [], [state(Value)]).
+
+:- end_object.
+
+:- object(class,
+ instantiates(metaclass)).
+
+ :- public(method/1).
+ method(Value) :-
+ ::state(Value).
+
+ :- private(state/1).
+
+:- end_object.
diff --git a/Task/Classes/Logtalk/classes-2.logtalk b/Task/Classes/Logtalk/classes-2.logtalk
new file mode 100644
index 0000000000..a2191f6743
--- /dev/null
+++ b/Task/Classes/Logtalk/classes-2.logtalk
@@ -0,0 +1,7 @@
+| ?- class::new(Instance, 1).
+Instance = o1
+yes
+
+| ?- o1::method(Value).
+Value = 1
+yes
diff --git a/Task/Closest-pair-problem/Fantom/closest-pair-problem.fantom b/Task/Closest-pair-problem/Fantom/closest-pair-problem.fantom
new file mode 100644
index 0000000000..871285a259
--- /dev/null
+++ b/Task/Closest-pair-problem/Fantom/closest-pair-problem.fantom
@@ -0,0 +1,118 @@
+class Point
+{
+ Float x
+ Float y
+
+ // create a random point
+ new make (Float x := Float.random * 10, Float y := Float.random * 10)
+ {
+ this.x = x
+ this.y = y
+ }
+
+ Float distance (Point p)
+ {
+ ((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)).sqrt
+ }
+
+ override Str toStr () { "($x, $y)" }
+}
+
+class Main
+{
+ // use brute force approach
+ static Point[] findClosestPair1 (Point[] points)
+ {
+ if (points.size < 2) return points // list too small
+ Point[] closestPair := [points[0], points[1]]
+ Float closestDistance := points[0].distance(points[1])
+
+ (1.. Int| { a.x <=> b.x }
+ bestLeft := findClosestPair2 (points[0..(points.size/2)])
+ bestRight := findClosestPair2 (points[(points.size/2)..-1])
+
+ Float minDistance
+ Point[] closePoints := [,]
+ if (bestLeft[0].distance(bestLeft[1]) < bestRight[0].distance(bestRight[1]))
+ {
+ minDistance = bestLeft[0].distance(bestLeft[1])
+ closePoints = bestLeft
+ }
+ else
+ {
+ minDistance = bestRight[0].distance(bestRight[1])
+ closePoints = bestRight
+ }
+ yPoints := points.findAll |Point p -> Bool|
+ {
+ (points.last.x - p.x).abs < minDistance
+ }.sort |Point a, Point b -> Int| { a.y <=> b.y }
+
+ closestPair := [,]
+ closestDist := Float.posInf
+
+ for (Int i := 0; i < yPoints.size - 1; ++i)
+ {
+ for (Int j := (i+1); j < yPoints.size; ++j)
+ {
+ if ((yPoints[j].y - yPoints[i].y) >= minDistance)
+ {
+ break
+ }
+ else
+ {
+ dist := yPoints[i].distance (yPoints[j])
+ if (dist < closestDist)
+ {
+ closestDist = dist
+ closestPair = [yPoints[i], yPoints[j]]
+ }
+ }
+ }
+ }
+ if (closestDist < minDistance)
+ return closestPair
+ else
+ return closePoints
+ }
+
+ public static Void main (Str[] args)
+ {
+ Int numPoints := 10 // default value, in case a number not given on command line
+ if ((args.size > 0) && (args[0].toInt(10, false) != null))
+ {
+ numPoints = args[0].toInt(10, false)
+ }
+
+ Point[] points := [,]
+ numPoints.times { points.add (Point()) }
+
+ Int t1 := Duration.now.toMillis
+ echo (findClosestPair1(points.dup))
+ Int t2 := Duration.now.toMillis
+ echo ("Time taken: ${(t2-t1)}ms")
+ echo (findClosestPair2(points.dup))
+ Int t3 := Duration.now.toMillis
+ echo ("Time taken: ${(t3-t2)}ms")
+ }
+}
diff --git a/Task/Closest-pair-problem/Groovy/closest-pair-problem-1.groovy b/Task/Closest-pair-problem/Groovy/closest-pair-problem-1.groovy
new file mode 100644
index 0000000000..5dd4258372
--- /dev/null
+++ b/Task/Closest-pair-problem/Groovy/closest-pair-problem-1.groovy
@@ -0,0 +1,6 @@
+class Point {
+ final Number x, y
+ Point(Number x = 0, Number y = 0) { this.x = x; this.y = y }
+ Number distance(Point that) { ((this.x - that.x)**2 + (this.y - that.y)**2)**0.5 }
+ String toString() { "{x:${x}, y:${y}}" }
+}
diff --git a/Task/Closest-pair-problem/Groovy/closest-pair-problem-2.groovy b/Task/Closest-pair-problem/Groovy/closest-pair-problem-2.groovy
new file mode 100644
index 0000000000..69b2cca908
--- /dev/null
+++ b/Task/Closest-pair-problem/Groovy/closest-pair-problem-2.groovy
@@ -0,0 +1,23 @@
+def bruteClosest(Collection pointCol) {
+ assert pointCol
+ List l = pointCol
+ int n = l.size()
+ assert n > 1
+ if (n == 2) return [distance:l[0].distance(l[1]), points:[l[0],l[1]]]
+ def answer = [distance: Double.POSITIVE_INFINITY]
+ (0..<(n-1)).each { i ->
+ ((i+1)..
+ (l[i].x - l[j].x).abs() < answer.distance &&
+ (l[i].y - l[j].y).abs() < answer.distance
+ }.each { j ->
+ if ((l[i].x - l[j].x).abs() < answer.distance &&
+ (l[i].y - l[j].y).abs() < answer.distance) {
+ def dist = l[i].distance(l[j])
+ if (dist < answer.distance) {
+ answer = [distance:dist, points:[l[i],l[j]]]
+ }
+ }
+ }
+ }
+ answer
+}
diff --git a/Task/Closest-pair-problem/Groovy/closest-pair-problem-3.groovy b/Task/Closest-pair-problem/Groovy/closest-pair-problem-3.groovy
new file mode 100644
index 0000000000..b75b7c250c
--- /dev/null
+++ b/Task/Closest-pair-problem/Groovy/closest-pair-problem-3.groovy
@@ -0,0 +1,48 @@
+def elegantClosest(Collection pointCol) {
+ assert pointCol
+ List xList = (pointCol as List).sort { it.x }
+ List yList = xList.clone().sort { it.y }
+ reductionClosest(xList, xList)
+}
+
+def reductionClosest(List xPoints, List yPoints) {
+// assert xPoints && yPoints
+// assert (xPoints as Set) == (yPoints as Set)
+ int n = xPoints.size()
+ if (n < 10) return bruteClosest(xPoints)
+
+ int nMid = Math.ceil(n/2)
+ List xLeft = xPoints[0.. xMid }
+ if (xRight[0].x == xMid) {
+ yLeft = xLeft.collect{ it }.sort { it.y }
+ yRight = xRight.collect{ it }.sort { it.y }
+ }
+
+ Map aLeft = reductionClosest(xLeft, yLeft)
+ Map aRight = reductionClosest(xRight, yRight)
+ Map aMin = aRight.distance < aLeft.distance ? aRight : aLeft
+ List yMid = yPoints.findAll { (xMid - it.x).abs() < aMin.distance }
+ int nyMid = yMid.size()
+ if (nyMid < 2) return aMin
+
+ Map answer = aMin
+ (0..<(nyMid-1)).each { i ->
+ ((i+1)..
+ (yMid[j].x - yMid[i].x).abs() < aMin.distance &&
+ (yMid[j].y - yMid[i].y).abs() < aMin.distance &&
+ yMid[j].distance(yMid[i]) < aMin.distance
+ }.each { k ->
+ if ((yMid[k].x - yMid[i].x).abs() < answer.distance && (yMid[k].y - yMid[i].y).abs() < answer.distance) {
+ def ikDist = yMid[i].distance(yMid[k])
+ if ( ikDist < answer.distance) {
+ answer = [distance:ikDist, points:[yMid[i],yMid[k]]]
+ }
+ }
+ }
+ }
+ answer
+}
diff --git a/Task/Closest-pair-problem/Groovy/closest-pair-problem-4.groovy b/Task/Closest-pair-problem/Groovy/closest-pair-problem-4.groovy
new file mode 100644
index 0000000000..303aa82c2f
--- /dev/null
+++ b/Task/Closest-pair-problem/Groovy/closest-pair-problem-4.groovy
@@ -0,0 +1,28 @@
+def random = new Random()
+
+(1..4).each {
+def point10 = (0..<(10**it)).collect { new Point(random.nextInt(1000001) - 500000,random.nextInt(1000001) - 500000) }
+
+def startE = System.currentTimeMillis()
+def closestE = elegantClosest(point10)
+def elapsedE = System.currentTimeMillis() - startE
+println """
+${10**it} POINTS
+-----------------------------------------
+Elegant reduction:
+elapsed: ${elapsedE/1000} s
+closest: ${closestE}
+"""
+
+
+def startB = System.currentTimeMillis()
+def closestB = bruteClosest(point10)
+def elapsedB = System.currentTimeMillis() - startB
+println """Brute force:
+elapsed: ${elapsedB/1000} s
+closest: ${closestB}
+
+Speedup ratio (B/E): ${elapsedB/elapsedE}
+=========================================
+"""
+}
diff --git a/Task/Closest-pair-problem/Icon/closest-pair-problem.icon b/Task/Closest-pair-problem/Icon/closest-pair-problem.icon
new file mode 100644
index 0000000000..8ac7543736
--- /dev/null
+++ b/Task/Closest-pair-problem/Icon/closest-pair-problem.icon
@@ -0,0 +1,25 @@
+record point(x,y)
+
+procedure main()
+ minDist := 0
+ minPair := &null
+ every (points := [],p1 := readPoint()) do {
+ if *points == 1 then minDist := dSquared(p1,points[1])
+ every minDist >=:= dSquared(p1,p2 := !points) do minPair := [p1,p2]
+ push(points, p1)
+ }
+
+ if \minPair then {
+ write("(",minPair[1].x,",",minPair[1].y,") -> ",
+ "(",minPair[2].x,",",minPair[2].y,")")
+ }
+ else write("One or fewer points!")
+end
+
+procedure readPoint() # Skips lines that don't have two numbers on them
+ suspend !&input ? point(numeric(tab(upto(', '))), numeric((move(1),tab(0))))
+end
+
+procedure dSquared(p1,p2) # Compute the square of the distance
+ return (p2.x-p1.x)^2 + (p2.y-p1.y)^2 # (sufficient for closeness)
+end
diff --git a/Task/Closest-pair-problem/J/closest-pair-problem-1.j b/Task/Closest-pair-problem/J/closest-pair-problem-1.j
new file mode 100644
index 0000000000..cf1d000445
--- /dev/null
+++ b/Task/Closest-pair-problem/J/closest-pair-problem-1.j
@@ -0,0 +1,4 @@
+vecl =: +/"1&.:*: NB. length of each of vectors
+dist =: <@:vecl@:({: -"1 }:)\ NB. calculate all distances among vectors
+minpair=: ({~ > {.@($ #: I.@,)@:= <./@;)dist NB. find one pair of the closest points
+closestpairbf =: (; vecl@:-/)@minpair NB. the pair and their distance
diff --git a/Task/Closest-pair-problem/J/closest-pair-problem-2.j b/Task/Closest-pair-problem/J/closest-pair-problem-2.j
new file mode 100644
index 0000000000..11986327ce
--- /dev/null
+++ b/Task/Closest-pair-problem/J/closest-pair-problem-2.j
@@ -0,0 +1,17 @@
+ ]pts=:10 2 ?@$ 0
+0.654682 0.925557
+0.409382 0.619391
+0.891663 0.888594
+0.716629 0.9962
+0.477721 0.946355
+0.925092 0.81822
+0.624291 0.142924
+0.211332 0.221507
+0.293786 0.691701
+0.839186 0.72826
+
+ closestpairbf pts
++-----------------+---------+
+|0.891663 0.888594|0.0779104|
+|0.925092 0.81822| |
++-----------------+---------+
diff --git a/Task/Closest-pair-problem/J/closest-pair-problem-3.j b/Task/Closest-pair-problem/J/closest-pair-problem-3.j
new file mode 100644
index 0000000000..4364003115
--- /dev/null
+++ b/Task/Closest-pair-problem/J/closest-pair-problem-3.j
@@ -0,0 +1,17 @@
+ ]pts=:10 4 ?@$ 0
+0.559164 0.482993 0.876 0.429769
+0.217911 0.729463 0.97227 0.132175
+0.479206 0.169165 0.495302 0.362738
+0.316673 0.797519 0.745821 0.0598321
+0.662585 0.726389 0.658895 0.653457
+0.965094 0.664519 0.084712 0.20671
+0.840877 0.591713 0.630206 0.99119
+0.221416 0.114238 0.0991282 0.174741
+0.946262 0.505672 0.776017 0.307362
+0.262482 0.540054 0.707342 0.465234
+
+ closestpairbf pts
++------------------------------------+--------+
+|0.217911 0.729463 0.97227 0.132175|0.708555|
+|0.316673 0.797519 0.745821 0.0598321| |
++------------------------------------+--------+
diff --git a/Task/Closest-pair-problem/Liberty-BASIC/closest-pair-problem.liberty b/Task/Closest-pair-problem/Liberty-BASIC/closest-pair-problem.liberty
new file mode 100644
index 0000000000..36e88a47d5
--- /dev/null
+++ b/Task/Closest-pair-problem/Liberty-BASIC/closest-pair-problem.liberty
@@ -0,0 +1,41 @@
+N =10
+
+dim x( N), y( N)
+
+firstPt =0
+secondPt =0
+
+for i =1 to N
+ read f: x( i) =f
+ read f: y( i) =f
+next i
+
+minDistance =1E6
+
+for i =1 to N -1
+ for j =i +1 to N
+ dxSq =( x( i) -x( j))^2
+ dySq =( y( i) -y( j))^2
+ D =abs( ( dxSq +dySq)^0.5)
+ if D []
+a[0]: 1 # => [1]
+a[3]: 2 # => [1, nil, nil, 2]
+
+# creating an array with the constructor
+a = Array new # => []
diff --git a/Task/Collections/Fancy/collections-2.fancy b/Task/Collections/Fancy/collections-2.fancy
new file mode 100644
index 0000000000..0c9081c43a
--- /dev/null
+++ b/Task/Collections/Fancy/collections-2.fancy
@@ -0,0 +1,9 @@
+# creating an empty hash
+
+h = <[]> # => <[]>
+h["a"]: 1 # => <["a" => 1]>
+h["test"]: 2.4 # => <["a" => 1, "test" => 2.4]>
+h[3]: "Hello" # => <["a" => 1, "test" => 2.4, 3 => "Hello"]>
+
+# creating a hash with the constructor
+h = Hash new # => <[]>
diff --git a/Task/Collections/Groovy/collections-1.groovy b/Task/Collections/Groovy/collections-1.groovy
new file mode 100644
index 0000000000..2cdc9b5c2c
--- /dev/null
+++ b/Task/Collections/Groovy/collections-1.groovy
@@ -0,0 +1,21 @@
+def emptyList = []
+assert emptyList.isEmpty() : "These are not the items you're looking for"
+assert emptyList.size() == 0 : "Empty list has size 0"
+assert ! emptyList : "Empty list evaluates as boolean 'false'"
+
+def initializedList = [ 1, "b", java.awt.Color.BLUE ]
+assert initializedList.size() == 3
+assert initializedList : "Non-empty list evaluates as boolean 'true'"
+assert initializedList[2] == java.awt.Color.BLUE : "referencing a single element (zero-based indexing)"
+assert initializedList[-1] == java.awt.Color.BLUE : "referencing a single element (reverse indexing of last element)"
+
+def combinedList = initializedList + [ "more stuff", "even more stuff" ]
+assert combinedList.size() == 5
+assert combinedList[1..3] == ["b", java.awt.Color.BLUE, "more stuff"] : "referencing a range of elements"
+
+combinedList << "even more stuff"
+assert combinedList.size() == 6
+assert combinedList[-1..-3] == \
+ ["even more stuff", "even more stuff", "more stuff"] \
+ : "reverse referencing last 3 elements"
+println ([combinedList: combinedList])
diff --git a/Task/Collections/Groovy/collections-2.groovy b/Task/Collections/Groovy/collections-2.groovy
new file mode 100644
index 0000000000..4b2a548527
--- /dev/null
+++ b/Task/Collections/Groovy/collections-2.groovy
@@ -0,0 +1,24 @@
+def emptyMap = [:]
+assert emptyMap.isEmpty() : "These are not the items you're looking for"
+assert emptyMap.size() == 0 : "Empty map has size 0"
+assert ! emptyMap : "Empty map evaluates as boolean 'false'"
+
+def initializedMap = [ count: 1, initial: "B", eyes: java.awt.Color.BLUE ]
+assert initializedMap.size() == 3
+assert initializedMap : "Non-empty map evaluates as boolean 'true'"
+assert initializedMap["eyes"] == java.awt.Color.BLUE : "referencing a single element (array syntax)"
+assert initializedMap.eyes == java.awt.Color.BLUE : "referencing a single element (member syntax)"
+assert initializedMap.height == null : \
+ "references to non-existant keys generally evaluate to null (implementation dependent)"
+
+def combinedMap = initializedMap \
+ + [hair: java.awt.Color.BLACK, birthdate: Date.parse("yyyy-MM-dd", "1960-05-17") ]
+assert combinedMap.size() == 5
+
+combinedMap["weight"] = 185 // array syntax
+combinedMap.lastName = "Smith" // member syntax
+combinedMap << [firstName: "Joe"] // entry syntax
+assert combinedMap.size() == 8
+assert combinedMap.keySet().containsAll(
+ ["lastName", "count", "eyes", "hair", "weight", "initial", "firstName", "birthdate"])
+println ([combinedMap: combinedMap])
diff --git a/Task/Collections/Groovy/collections-3.groovy b/Task/Collections/Groovy/collections-3.groovy
new file mode 100644
index 0000000000..0e3efc4284
--- /dev/null
+++ b/Task/Collections/Groovy/collections-3.groovy
@@ -0,0 +1,16 @@
+def emptySet = new HashSet()
+assert emptySet.isEmpty() : "These are not the items you're looking for"
+assert emptySet.size() == 0 : "Empty set has size 0"
+assert ! emptySet : "Empty set evaluates as boolean 'false'"
+
+def initializedSet = new HashSet([ 1, "b", java.awt.Color.BLUE ])
+assert initializedSet.size() == 3
+assert initializedSet : "Non-empty list evaluates as boolean 'true'"
+//assert initializedSet[2] == java.awt.Color.BLUE // SYNTAX ERROR!!! No indexing of set elements!
+
+def combinedSet = initializedSet + new HashSet([ "more stuff", "even more stuff" ])
+assert combinedSet.size() == 5
+
+combinedSet << "even more stuff"
+assert combinedSet.size() == 5 : "No duplicate elements allowed!"
+println ([combinedSet: combinedSet])
diff --git a/Task/Collections/Icon/collections-1.icon b/Task/Collections/Icon/collections-1.icon
new file mode 100644
index 0000000000..84baf2e7cf
--- /dev/null
+++ b/Task/Collections/Icon/collections-1.icon
@@ -0,0 +1,8 @@
+# Creation of collections:
+ s := "abccd" # string, an ordered collection of characters, immutable
+ c := 'abcd' # cset, an unordered collection of characters, immutable
+ S := set() # set, an unordered collection of unique values, mutable, contents may be of any type
+ T := table() # table, an associative array of values accessed via unordered keys, mutable, contents may be of any type
+ L := [] # list, an ordered collection of values indexed by position 1..n or as stack/queue, mutable, contents may be of any type
+ record constructorname(field1,field2,fieldetc) # record, a collection of values stored in named fields, mutable, contents may be of any type (declare outside procedures)
+ R := constructorname() # record (creation)
diff --git a/Task/Collections/Icon/collections-2.icon b/Task/Collections/Icon/collections-2.icon
new file mode 100644
index 0000000000..a0e1c3d42c
--- /dev/null
+++ b/Task/Collections/Icon/collections-2.icon
@@ -0,0 +1,6 @@
+ s ||:= "xyz" # concatenation
+ c ++:= 'xyz' # union
+ insert(S,"abc") # insert
+ T["abc"] := "xyz" # insert create/overwrite
+ put(L,1) # put (extend), also push
+ R.field1 := "xyz" # overwrite
diff --git a/Task/Collections/Icon/collections-3.icon b/Task/Collections/Icon/collections-3.icon
new file mode 100644
index 0000000000..4e9dc69bb2
--- /dev/null
+++ b/Task/Collections/Icon/collections-3.icon
@@ -0,0 +1,4 @@
+ S := S ++ S2 # union of two sets or two csets
+ S ++:= S2 # augmented assignment
+ L := L ||| L2 # list concatenation
+ L |||:= L2 # augmented assignment
diff --git a/Task/Collections/J/collections.j b/Task/Collections/J/collections.j
new file mode 100644
index 0000000000..55197c3073
--- /dev/null
+++ b/Task/Collections/J/collections.j
@@ -0,0 +1,87 @@
+ c =: 0 10 20 30 40 NB. A collection
+
+ c, 50 NB. Append 50 to the collection
+0 10 20 30 40 50
+ _20 _10 , c NB. Prepend _20 _10 to the collection
+_20 _10 0 10 20 30 40
+
+ ,~ c NB. Self-append
+0 10 20 30 40 0 10 20 30 40
+ ,:~ c NB. Duplicate
+0 10 20 30 40
+0 10 20 30 40
+
+ 30 e. c NB. Is 30 in the collection?
+1
+ 30 i.~c NB. Where?
+3
+ 30 80 e. c NB. Don't change anything to test multiple values -- collections are native.
+1 0
+
+ 2 1 4 2 { c NB. From the collection, give me items two, one, four, and two again.
+20 10 40 20
+
+ |.c NB. Reverse the collection
+40 30 20 10 0
+ 1+c NB. Increment the collection
+1 11 21 31 41
+ c%10 NB. Decimate the collection (divide by 10)
+0 1 2 3 4
+
+ {. c NB. Give me the first item
+0
+ {: c NB. And the last
+40
+ 3{.c NB. Give me the first 3 items
+0 10 20
+ 3}.c NB. Throw away the first 3 items
+30 40
+ _3{.c NB. Give me the last 3 items
+20 30 40
+ _3}.c NB. (Guess)
+0 10
+
+ keys_map_ =: 'one';'two';'three'
+ vals_map_ =: 'alpha';'beta';'gamma'
+ lookup_map_ =: a:& $: : (dyad def ' (keys i. y) { vals,x')&boxopen
+ exists_map_ =: verb def 'y e. keys'&boxopen
+
+ exists_map_ 'bad key'
+0
+ exists_map_ 'two';'bad key'
+1 0
+
+ lookup_map_ 'one'
++-----+
+|alpha|
++-----+
+ lookup_map_ 'three';'one';'two';'one'
++-----+-----+----+-----+
+|gamma|alpha|beta|alpha|
++-----+-----+----+-----+
+ lookup_map_ 'bad key'
+++
+||
+++
+ 'some other default' lookup_map_ 'bad key'
++------------------+
+|some other default|
++------------------+
+ 'some other default' lookup_map_ 'two';'bad key'
++----+------------------+
+|beta|some other default|
++----+------------------+
+
+ +/ c NB. Sum of collection
+100
+ */ c NB. Product of collection
+0
+
+ i.5 NB. Generate the first 5 nonnegative integers
+0 1 2 3 4
+ 10*i.5 NB. Looks familiar
+0 10 20 30 40
+ c = 10*i.5 NB. Test each for equality
+1 1 1 1 1
+ c -: 10 i.5 NB. Test for identicality
+1
diff --git a/Task/Collections/Lisaac/collections-1.lisaac b/Task/Collections/Lisaac/collections-1.lisaac
new file mode 100644
index 0000000000..be127104e9
--- /dev/null
+++ b/Task/Collections/Lisaac/collections-1.lisaac
@@ -0,0 +1,4 @@
++ vector : ARRAY[INTEGER];
+vector := ARRAY[INTEGER].create_with_capacity 32 lower 0;
+vector.add_last 1;
+vector.add_last 2;
diff --git a/Task/Collections/Lisaac/collections-2.lisaac b/Task/Collections/Lisaac/collections-2.lisaac
new file mode 100644
index 0000000000..5a7ec89708
--- /dev/null
+++ b/Task/Collections/Lisaac/collections-2.lisaac
@@ -0,0 +1,4 @@
++ set : HASHED_SET[INTEGER];
+set := HASHED_SET[INTEGER].create;
+set.add 1;
+set.add 2;
diff --git a/Task/Collections/Lisaac/collections-3.lisaac b/Task/Collections/Lisaac/collections-3.lisaac
new file mode 100644
index 0000000000..8fac868ebc
--- /dev/null
+++ b/Task/Collections/Lisaac/collections-3.lisaac
@@ -0,0 +1,4 @@
++ list : LINKED_LIST[INTEGER];
+list := LINKED_LIST[INTEGER].create;
+list.add_last 1;
+list.add_last 2;
diff --git a/Task/Collections/Lisaac/collections-4.lisaac b/Task/Collections/Lisaac/collections-4.lisaac
new file mode 100644
index 0000000000..ae30ba168c
--- /dev/null
+++ b/Task/Collections/Lisaac/collections-4.lisaac
@@ -0,0 +1,4 @@
++ dict : HASHED_DICTIONARY[INTEGER/*value*/, STRING_CONSTANT/*key*/];
+dict := HASHED_DICTIONARY[INTEGER, STRING_CONSTANT].create;
+dict.put 1 to "one";
+dict.put 2 to "two";
diff --git a/Task/Collections/Mathematica/collections.mathematica b/Task/Collections/Mathematica/collections.mathematica
new file mode 100644
index 0000000000..906d13f0e9
--- /dev/null
+++ b/Task/Collections/Mathematica/collections.mathematica
@@ -0,0 +1,13 @@
+Lst = {3, 4, 5, 6}
+->{3, 4, 5, 6}
+
+PrependTo[ Lst, 2]
+->{2, 3, 4, 5, 6}
+PrependTo[ Lst, 1]
+->{1, 2, 3, 4, 5, 6}
+
+Lst
+->{1, 2, 3, 4, 5, 6}
+
+Insert[ Lst, X, 4]
+->{1, 2, 3, X, 4, 5, 6}
diff --git a/Task/Color-of-a-screen-pixel/Icon/color-of-a-screen-pixel.icon b/Task/Color-of-a-screen-pixel/Icon/color-of-a-screen-pixel.icon
new file mode 100644
index 0000000000..7eaffa5249
--- /dev/null
+++ b/Task/Color-of-a-screen-pixel/Icon/color-of-a-screen-pixel.icon
@@ -0,0 +1,24 @@
+link graphics,printf
+
+procedure main()
+
+ WOpen("canvas=hidden") # hide for query
+ height := WAttrib("displayheight") - 45 # adjust for ...
+ width := WAttrib("displaywidth") - 20 # ... window 7 borders
+ WClose(&window)
+
+ W := WOpen("size="||width||","||height,"bg=black") |
+ stop("Unable to open window")
+
+ every 1 to 10 do { # generate some random rectangles within the frame
+ x := ?width
+ y := ?(height-100)
+ WAttrib("fg="||?["red","green","blue","purple","yellow"])
+ FillRectangle(x,x+50,y,y+50)
+ }
+
+ while Event() do
+ printf("x=%d,y=%d pixel=%s\n",&x,&y,Pixel(&x,&y,&x,&y))
+
+ WDone(W) # q to exit
+end
diff --git a/Task/Color-of-a-screen-pixel/Liberty-BASIC/color-of-a-screen-pixel.liberty b/Task/Color-of-a-screen-pixel/Liberty-BASIC/color-of-a-screen-pixel.liberty
new file mode 100644
index 0000000000..3f0dfba47a
--- /dev/null
+++ b/Task/Color-of-a-screen-pixel/Liberty-BASIC/color-of-a-screen-pixel.liberty
@@ -0,0 +1,25 @@
+'This example requires the Windows API
+Struct point, x As long, y As long
+
+hDC = GetDC(0)
+result = GetCursorPos()
+Print GetPixel(hDC, point.x.struct, point.y.struct)
+Call ReleaseDC 0, hDC
+End
+
+
+ Sub ReleaseDC hWnd, hDC
+ CallDLL #user32,"ReleaseDC", hWnd As uLong, hDC As uLong, ret As Long
+ End Sub
+
+ Function GetDC(hWnd)
+ CallDLL #user32, "GetDC", hWnd As uLong, GetDC As uLong
+ End Function
+
+ Function GetCursorPos()
+ CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong
+ End Function
+
+ Function GetPixel(hDC, x, y)
+ CallDLL #gdi32, "GetPixel", hDC As uLong, x As long, y As long, GetPixel As long
+ End Function
diff --git a/Task/Color-of-a-screen-pixel/Locomotive-Basic/color-of-a-screen-pixel.bas b/Task/Color-of-a-screen-pixel/Locomotive-Basic/color-of-a-screen-pixel.bas
new file mode 100644
index 0000000000..f5bb546012
--- /dev/null
+++ b/Task/Color-of-a-screen-pixel/Locomotive-Basic/color-of-a-screen-pixel.bas
@@ -0,0 +1,3 @@
+10 x=320:y=200
+20 color=TEST(x,y)
+30 PRINT "Pen color at"; x; y; "is"; color
diff --git a/Task/Color-quantization/J/color-quantization-1.j b/Task/Color-quantization/J/color-quantization-1.j
new file mode 100644
index 0000000000..95309cfc30
--- /dev/null
+++ b/Task/Color-quantization/J/color-quantization-1.j
@@ -0,0 +1,10 @@
+kmcL=:4 :0
+ C=. /:~ 256 #.inv ,y NB. colors
+ G=. x (i.@] <.@* %) #C NB. groups (initial)
+ Q=. _ NB. quantized list of colors (initial
+ whilst.-. Q-:&<.&(x&*)Q0 do.
+ Q0=. Q
+ Q=. /:~C (+/ % #)/.~ G
+ G=. (i. <./)"1 C +/&.:*: .- |:Q
+ end.Q
+)
diff --git a/Task/Color-quantization/J/color-quantization-2.j b/Task/Color-quantization/J/color-quantization-2.j
new file mode 100644
index 0000000000..d60dfd966b
--- /dev/null
+++ b/Task/Color-quantization/J/color-quantization-2.j
@@ -0,0 +1,17 @@
+ 16 kmcL img
+7.52532 22.3347 0.650468
+8.20129 54.4678 0.0326828
+33.1132 69.8148 0.622265
+54.2232 125.682 2.67713
+56.7064 99.5008 3.04013
+61.2135 136.42 4.2015
+68.1246 140.576 6.37512
+74.6006 143.606 7.57854
+78.9101 150.792 10.2563
+89.5873 148.621 14.6202
+98.9523 154.005 25.7583
+114.957 159.697 47.6423
+145.816 178.136 33.8845
+164.969 199.742 67.0467
+179.849 207.594 109.973
+209.229 221.18 204.513
diff --git a/Task/Color-quantization/Mathematica/color-quantization.mathematica b/Task/Color-quantization/Mathematica/color-quantization.mathematica
new file mode 100644
index 0000000000..1ea435b5c2
--- /dev/null
+++ b/Task/Color-quantization/Mathematica/color-quantization.mathematica
@@ -0,0 +1 @@
+ColorQuantize[Import["http://rosettacode.org/mw/images/3/3f/Quantum_frog.png"],16,Dithering->False]
diff --git a/Task/Colour-bars-Display/Icon/colour-bars-display-1.icon b/Task/Colour-bars-Display/Icon/colour-bars-display-1.icon
new file mode 100644
index 0000000000..f4f008a77e
--- /dev/null
+++ b/Task/Colour-bars-Display/Icon/colour-bars-display-1.icon
@@ -0,0 +1,37 @@
+link graphics,printf
+
+procedure main() # generalized colour bars
+ DrawTestCard(Simple_TestCard())
+ WDone()
+end
+
+procedure DrawTestCard(TC)
+ size := sprintf("size=%d,%d",TC.width,TC.height)
+ &window := TC.window := open(TC.id,"g","bg=black",size) |
+ stop("Unable to open window")
+
+ every R := TC.bands[r := 1 to *TC.bands -1] do
+ every C := R.bars[c := 1 to *R.bars - 1] do {
+ Fg(R.bars[c].colour)
+ FillRectangle( C.left, R.top,
+ R.bars[c+1].left-C.left, TC.bands[r+1].top-R.top )
+ }
+ return TC
+end
+
+record testcard(window,id,width,height,bands)
+record band(top,bars)
+record bar(left,colour)
+
+procedure Simple_TestCard() #: return structure simple testcard
+ return testcard(,"Simple Test Card",width := 800,height := 600,
+ [ band( 1, [ bar( 1, "black"),
+ bar(114, "red"),
+ bar(228, "green"),
+ bar(342, "blue"),
+ bar(456, "magenta"),
+ bar(570, "cyan"),
+ bar(684, "yellow"),
+ bar(width) ] ),
+ band(height) ])
+end
diff --git a/Task/Colour-bars-Display/Icon/colour-bars-display-2.icon b/Task/Colour-bars-Display/Icon/colour-bars-display-2.icon
new file mode 100644
index 0000000000..09462701ab
--- /dev/null
+++ b/Task/Colour-bars-Display/Icon/colour-bars-display-2.icon
@@ -0,0 +1,29 @@
+procedure SMPTE_TestCard() #: return structure with 480i(ish) testcard
+ return testcard(,"SMPTE TV Test Card",width := 672,height := 504,
+ [ band( 1, [ bar( 1, "#c0c0c0"),
+ bar( 95, "#c0c000"),
+ bar(191, "#00c0c0"),
+ bar(288, "#00c000"),
+ bar(383, "#c000c0"),
+ bar(480, "#c00000"),
+ bar(575, "#0000c0"),
+ bar(width) ] ),
+ band(335, [ bar( 1, "#0000c0"),
+ bar( 95, "#131313"),
+ bar(191, "#c000c0"),
+ bar(288, "#131313"),
+ bar(383, "#00c0c0"),
+ bar(480, "#131313"),
+ bar(575, "#c0c0c0"),
+ bar(width) ] ),
+ band(378, [ bar( 1, "#00214c"),
+ bar(120, "#ffffff"),
+ bar(240, "#32006a"),
+ bar(360, "#131313"),
+ bar(480, "#090909"),
+ bar(512, "#131313"),
+ bar(544, "#1d1d1d"),
+ bar(576, "#131313"),
+ bar(width) ] ),
+ band(height) ])
+end
diff --git a/Task/Colour-bars-Display/J/colour-bars-display.j b/Task/Colour-bars-Display/J/colour-bars-display.j
new file mode 100644
index 0000000000..c37705b5f3
--- /dev/null
+++ b/Task/Colour-bars-Display/J/colour-bars-display.j
@@ -0,0 +1,4 @@
+ load 'viewmat'
+ size=: 2{.".wd'qm' NB. J6
+ size=: getscreenwh_jgtk_ '' NB. J7
+ 'rgb'viewmat (|.size){. (>.&.(%&160)|.size)$ 20# 256#.255*#:i.8
diff --git a/Task/Colour-bars-Display/Liberty-BASIC/colour-bars-display.liberty b/Task/Colour-bars-Display/Liberty-BASIC/colour-bars-display.liberty
new file mode 100644
index 0000000000..528e576b26
--- /dev/null
+++ b/Task/Colour-bars-Display/Liberty-BASIC/colour-bars-display.liberty
@@ -0,0 +1,20 @@
+nomainwin
+colors$="black red green blue pink cyan yellow white"
+WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
+UpperLeftX=1:UpperLeftY=1
+barWidth=DisplayWidth/8
+graphicbox #main.g, 0,0,DisplayWidth,DisplayHeight
+open "" for window_popup as #main
+#main "trapclose [quit]"
+#main.g "down; setfocus; when characterInput [quit]"
+#main.g "when leftButtonUp [quit]"
+#main.g "size ";barWidth
+
+for x = barWidth/2 to DisplayWidth step barWidth
+ i=i+1
+ if i>8 then i=1
+ col$=word$(colors$,i)
+ #main.g "color ";col$;"; line ";x;" 0 ";x;" ";DisplayHeight
+next
+wait
+[quit] close #main:end
diff --git a/Task/Colour-bars-Display/Locomotive-Basic/colour-bars-display.bas b/Task/Colour-bars-Display/Locomotive-Basic/colour-bars-display.bas
new file mode 100644
index 0000000000..22c2f0c6e0
--- /dev/null
+++ b/Task/Colour-bars-Display/Locomotive-Basic/colour-bars-display.bas
@@ -0,0 +1,7 @@
+10 MODE 0:BORDER 23
+20 FOR x=0 TO 15
+30 ORIGIN x*40,0
+40 GRAPHICS PEN x
+50 FOR z=0 TO 39 STEP 4:MOVE z,0:DRAW z,400:NEXT
+60 NEXT
+70 CALL &bb06 ' wait for key press
diff --git a/Task/Colour-bars-Display/Mathematica/colour-bars-display.mathematica b/Task/Colour-bars-Display/Mathematica/colour-bars-display.mathematica
new file mode 100644
index 0000000000..8c4a27899b
--- /dev/null
+++ b/Task/Colour-bars-Display/Mathematica/colour-bars-display.mathematica
@@ -0,0 +1,3 @@
+ArrayPlot[
+ ConstantArray[{Black, Red, Green, Blue, Magenta, Cyan, Yellow,
+ White}, 5]]
diff --git a/Task/Colour-pinstripe-Display/Icon/colour-pinstripe-display.icon b/Task/Colour-pinstripe-Display/Icon/colour-pinstripe-display.icon
new file mode 100644
index 0000000000..b996b1838e
--- /dev/null
+++ b/Task/Colour-pinstripe-Display/Icon/colour-pinstripe-display.icon
@@ -0,0 +1,30 @@
+link graphics,numbers,printf
+
+procedure main() # pinstripe
+
+ &window := open("Colour Pinstripe","g","bg=black") |
+ stop("Unable to open window")
+
+ WAttrib("canvas=hidden")
+ WAttrib(sprintf("size=%d,%d",WAttrib("displaywidth"),WAttrib("displayheight")))
+ WAttrib("canvas=maximal")
+
+ Colours := ["black", "red", "green", "blue", "magenta", "cyan", "yellow", "white"]
+ height := WAttrib("height")
+ width := WAttrib("width")
+
+ maxbands := 4 # bands to draw
+ bandheight := height / maxbands # height of each band
+ every bands := 1 to maxbands do { # for each band
+ top := 1 + bandheight * (bands-1) # .. top of band
+ every c := 1 to width do {
+ colour := Colours[ceil((c+0.)/bands)%*Colours+1]
+ if colour == "black" then next # skip black
+ else {
+ Fg(colour)
+ DrawLine(c,top,c,top+bandheight-1)
+ }
+ }
+ }
+ WDone()
+end
diff --git a/Task/Colour-pinstripe-Display/J/colour-pinstripe-display.j b/Task/Colour-pinstripe-Display/J/colour-pinstripe-display.j
new file mode 100644
index 0000000000..630ecf63e7
--- /dev/null
+++ b/Task/Colour-pinstripe-Display/J/colour-pinstripe-display.j
@@ -0,0 +1,4 @@
+ load 'viewmat'
+ size=. 2{.".wd'qm' NB. J6
+ size=. getscreenwh_jgtk_ '' NB. J7
+ 'rgb'viewmat (4<.@%~{:size)# ({.size) $&> 1 2 3 4#&.> <256#.255*#:i.8
diff --git a/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-1.icon b/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-1.icon
new file mode 100644
index 0000000000..bfcac4de34
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-1.icon
@@ -0,0 +1,17 @@
+# generate all combinations of length n from list L,
+# including repetitions
+procedure combinations_repetitions (L, n)
+ if n = 0
+ then suspend [] # if reach 0, then return an empty list
+ else if *L > 0
+ then {
+ # keep the first element
+ item := L[1]
+ # get all of length n in remaining list
+ every suspend (combinations_repetitions (L[2:0], n))
+ # get all of length n-1 in remaining list
+ # and add kept element to make list of size n
+ every i := combinations_repetitions (L, n-1) do
+ suspend [item] ||| i
+ }
+end
diff --git a/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-2.icon b/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-2.icon
new file mode 100644
index 0000000000..b107fbb764
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Icon/combinations-with-repetitions-2.icon
@@ -0,0 +1,16 @@
+# convenience function
+procedure write_list (l)
+ every (writes (!l || " "))
+ write ()
+end
+
+# testing routine
+procedure main ()
+ # display all combinations for 2 of iced/jam/plain
+ every write_list (combinations_repetitions(["iced", "jam", "plain"], 2))
+ # get a count for number of ways to select 3 items from 10
+ every push(num_list := [], 1 to 10)
+ count := 0
+ every combinations_repetitions(num_list, 3) do count +:= 1
+ write ("There are " || count || " possible combinations of 3 from 10")
+end
diff --git a/Task/Combinations-with-repetitions/J/combinations-with-repetitions-1.j b/Task/Combinations-with-repetitions/J/combinations-with-repetitions-1.j
new file mode 100644
index 0000000000..c802208e9f
--- /dev/null
+++ b/Task/Combinations-with-repetitions/J/combinations-with-repetitions-1.j
@@ -0,0 +1 @@
+rcomb=: >@~.@:(/:~&.>)@,@{@# <
diff --git a/Task/Combinations-with-repetitions/J/combinations-with-repetitions-2.j b/Task/Combinations-with-repetitions/J/combinations-with-repetitions-2.j
new file mode 100644
index 0000000000..73927e7224
--- /dev/null
+++ b/Task/Combinations-with-repetitions/J/combinations-with-repetitions-2.j
@@ -0,0 +1,16 @@
+ 2 rcomb ;:'iced jam plain'
+┌─────┬─────┐
+│iced │iced │
+├─────┼─────┤
+│iced │jam │
+├─────┼─────┤
+│iced │plain│
+├─────┼─────┤
+│jam │jam │
+├─────┼─────┤
+│jam │plain│
+├─────┼─────┤
+│plain│plain│
+└─────┴─────┘
+ #3 rcomb i.10 NB. ways to choose 3 items from 10 with replacement
+220
diff --git a/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-1.mathematica b/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-1.mathematica
new file mode 100644
index 0000000000..917fa12836
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-1.mathematica
@@ -0,0 +1,8 @@
+DeleteDuplicates[Tuples[{"iced", "jam", "plain"}, 2],Sort[#1] == Sort[#2] &]
+->{{"iced", "iced"}, {"iced", "jam"}, {"iced", "plain"}, {"jam", "jam"}, {"jam", "plain"}, {"plain", "plain"}}
+
+Combi[x_, y_] := Binomial[(x + y) - 1, y]
+Combi[3, 2]
+-> 6
+Combi[10, 3]
+->220
diff --git a/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-2.mathematica b/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-2.mathematica
new file mode 100644
index 0000000000..eb278e4532
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Mathematica/combinations-with-repetitions-2.mathematica
@@ -0,0 +1,14 @@
+CombinWithRep[S_List, k_] := Module[{occupation, assignment},
+ occupation =
+ Flatten[Permutations /@
+ IntegerPartitions[k, {Length[S]}, Range[0, k]], 1];
+ assignment =
+ Flatten[Table[ConstantArray[z, {#[[z]]}], {z, Length[#]}]] & /@
+ occupation;
+ Thread[S[[#]]] & /@ assignment
+ ]
+
+In[2]:= CombinWithRep[{"iced", "jam", "plain"}, 2]
+
+Out[2]= {{"iced", "iced"}, {"jam", "jam"}, {"plain",
+ "plain"}, {"iced", "jam"}, {"iced", "plain"}, {"jam", "plain"}}
diff --git a/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-1.mercury b/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-1.mercury
new file mode 100644
index 0000000000..d08594a16b
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-1.mercury
@@ -0,0 +1,32 @@
+:- module comb.
+:- interface.
+:- import_module list, int, bag.
+
+:- pred choose(list(T)::in, int::in, bag(T)::out) is nondet.
+:- pred choose_all(list(T)::in, int::in, list(list(T))::out) is det.
+:- pred count_choices(list(T)::in, int::in, int::out) is det.
+
+:- implementation.
+:- import_module solutions.
+
+choose(L, N, R) :- choose(L, N, bag.init, R).
+
+:- pred choose(list(T)::in, int::in, bag(T)::in, bag(T)::out) is nondet.
+choose(L, N, !R) :-
+ ( N = 0 ->
+ true
+ ;
+ member(X, L),
+ bag.insert(!.R, X, !:R),
+ choose(L, N - 1, !R)
+ ).
+
+choose_all(L, N, R) :-
+ solutions(choose(L, N), R0),
+ list.map(bag.to_list, R0, R).
+
+count_choices(L, N, Count) :-
+ aggregate(choose(L, N), count, 0, Count).
+
+:- pred count(T::in, int::in, int::out) is det.
+count(_, N0, N) :- N0 + 1 = N.
diff --git a/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-2.mercury b/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-2.mercury
new file mode 100644
index 0000000000..c94c6b0e11
--- /dev/null
+++ b/Task/Combinations-with-repetitions/Mercury/combinations-with-repetitions-2.mercury
@@ -0,0 +1,18 @@
+:- module comb_ex.
+:- interface.
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+:- implementation.
+:- import_module comb, list, string.
+
+:- type doughtnuts
+ ---> iced ; jam ; plain
+ ; glazed ; chocolate ; cream_filled ; mystery
+ ; cubed ; cream_covered ; explosive.
+
+main(!IO) :-
+ choose_all([iced, jam, plain], 2, L),
+ count_choices([iced, jam, plain, glazed, chocolate, cream_filled,
+ mystery, cubed, cream_covered, explosive], 3, N),
+ io.write(L, !IO), io.nl(!IO),
+ io.write_string(from_int(N) ++ " choices.\n", !IO).
diff --git a/Task/Combinations/Factor/combinations-1.factor b/Task/Combinations/Factor/combinations-1.factor
new file mode 100644
index 0000000000..6ac37abc9a
--- /dev/null
+++ b/Task/Combinations/Factor/combinations-1.factor
@@ -0,0 +1,3 @@
+USING: math.combinatorics prettyprint ;
+
+5 iota 3 all-combinations .
diff --git a/Task/Combinations/Factor/combinations-2.factor b/Task/Combinations/Factor/combinations-2.factor
new file mode 100644
index 0000000000..5f76255b34
--- /dev/null
+++ b/Task/Combinations/Factor/combinations-2.factor
@@ -0,0 +1 @@
+{ "a" "b" "c" } 2 all-combinations .
diff --git a/Task/Combinations/GAP/combinations.gap b/Task/Combinations/GAP/combinations.gap
new file mode 100644
index 0000000000..c34163ec91
--- /dev/null
+++ b/Task/Combinations/GAP/combinations.gap
@@ -0,0 +1,6 @@
+# Built-in
+Combinations([1 .. n], m);
+
+Combinations([1 .. 5], 3);
+# [ [ 1, 2, 3 ], [ 1, 2, 4 ], [ 1, 2, 5 ], [ 1, 3, 4 ], [ 1, 3, 5 ],
+# [ 1, 4, 5 ], [ 2, 3, 4 ], [ 2, 3, 5 ], [ 2, 4, 5 ], [ 3, 4, 5 ] ]
diff --git a/Task/Combinations/Groovy/combinations-1.groovy b/Task/Combinations/Groovy/combinations-1.groovy
new file mode 100644
index 0000000000..625851b1b8
--- /dev/null
+++ b/Task/Combinations/Groovy/combinations-1.groovy
@@ -0,0 +1,10 @@
+def comb
+comb = { m, list ->
+ def n = list.size()
+ m == 0 ?
+ [[]] :
+ (0..(n-m)).inject([]) { newlist, k ->
+ def sublist = (k+1 == n) ? [] : list[(k+1).. println "Choose ${i}:"; comb(i, csny).each { println it }; println() }
diff --git a/Task/Combinations/Groovy/combinations-3.groovy b/Task/Combinations/Groovy/combinations-3.groovy
new file mode 100644
index 0000000000..db26605440
--- /dev/null
+++ b/Task/Combinations/Groovy/combinations-3.groovy
@@ -0,0 +1 @@
+def comb0 = { m, n -> comb(m, (0.. println "Choose ${i}:"; comb0(i, 5).each { println it }; println() }
diff --git a/Task/Combinations/Groovy/combinations-5.groovy b/Task/Combinations/Groovy/combinations-5.groovy
new file mode 100644
index 0000000000..8e4cc48f84
--- /dev/null
+++ b/Task/Combinations/Groovy/combinations-5.groovy
@@ -0,0 +1 @@
+def comb1 = { m, n -> comb(m, (1..n)) }
diff --git a/Task/Combinations/Groovy/combinations-6.groovy b/Task/Combinations/Groovy/combinations-6.groovy
new file mode 100644
index 0000000000..3e7fceb0ef
--- /dev/null
+++ b/Task/Combinations/Groovy/combinations-6.groovy
@@ -0,0 +1,2 @@
+println "Choose out of 5 (one-based):"
+(0..3).each { i -> println "Choose ${i}:"; comb1(i, 5).each { println it }; println() }
diff --git a/Task/Combinations/Icon/combinations-1.icon b/Task/Combinations/Icon/combinations-1.icon
new file mode 100644
index 0000000000..3bdb870f55
--- /dev/null
+++ b/Task/Combinations/Icon/combinations-1.icon
@@ -0,0 +1,20 @@
+procedure main()
+return combinations(3,5,0)
+end
+
+procedure combinations(m,n,z) # demonstrate combinations
+/z := 1
+
+write(m," combinations of ",n," integers starting from ",z)
+every put(L := [], z to n - 1 + z by 1) # generate list of n items from z
+write("Intial list\n",list2string(L))
+write("Combinations:")
+every write(list2string(lcomb(L,m)))
+end
+
+procedure list2string(L) # helper function
+every (s := "[") ||:= " " || (!L|"]")
+return s
+end
+
+link lists
diff --git a/Task/Combinations/Icon/combinations-2.icon b/Task/Combinations/Icon/combinations-2.icon
new file mode 100644
index 0000000000..1e819bd876
--- /dev/null
+++ b/Task/Combinations/Icon/combinations-2.icon
@@ -0,0 +1,8 @@
+procedure lcomb(L,i) #: list combinations
+ local j
+
+ if i < 1 then fail
+ suspend if i = 1 then [!L]
+ else [L[j := 1 to *L - i + 1]] ||| lcomb(L[j + 1:0],i - 1)
+
+end
diff --git a/Task/Combinations/J/combinations-1.j b/Task/Combinations/J/combinations-1.j
new file mode 100644
index 0000000000..5755d528dc
--- /dev/null
+++ b/Task/Combinations/J/combinations-1.j
@@ -0,0 +1,5 @@
+comb1=: dyad define
+ c=. 1 {.~ - d=. 1+y-x
+ z=. i.1 0
+ for_j. (d-1+y)+/&i.d do. z=. (c#j) ,. z{~;(-c){.&.><i.{.c=. +/\.c end.
+)
diff --git a/Task/Combinations/J/combinations-2.j b/Task/Combinations/J/combinations-2.j
new file mode 100644
index 0000000000..016ce8d83e
--- /dev/null
+++ b/Task/Combinations/J/combinations-2.j
@@ -0,0 +1,3 @@
+comb=: dyad define M.
+ if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x comb&.<: y),1+x comb y-1 end.
+)
diff --git a/Task/Combinations/Julia/combinations.julia b/Task/Combinations/Julia/combinations.julia
new file mode 100644
index 0000000000..9b5980a997
--- /dev/null
+++ b/Task/Combinations/Julia/combinations.julia
@@ -0,0 +1,13 @@
+julia> for i in @task combinations(1:5,3)
+println(i)
+end
+[1, 2, 3]
+[1, 2, 4]
+[1, 3, 4]
+[2, 3, 4]
+[1, 2, 5]
+[1, 3, 5]
+[2, 3, 5]
+[1, 4, 5]
+[2, 4, 5]
+[3, 4, 5]
diff --git a/Task/Combinations/Logo/combinations.logo b/Task/Combinations/Logo/combinations.logo
new file mode 100644
index 0000000000..b7409800c6
--- /dev/null
+++ b/Task/Combinations/Logo/combinations.logo
@@ -0,0 +1,7 @@
+to comb :n :list
+ if :n = 0 [output [[]]]
+ if empty? :list [output []]
+ output sentence map [sentence first :list ?] comb :n-1 bf :list ~
+ comb :n bf :list
+end
+print comb 3 [0 1 2 3 4]
diff --git a/Task/Combinations/M4/combinations.m4 b/Task/Combinations/M4/combinations.m4
new file mode 100644
index 0000000000..b5bda8ad47
--- /dev/null
+++ b/Task/Combinations/M4/combinations.m4
@@ -0,0 +1,26 @@
+divert(-1)
+define(`set',`define(`$1[$2]',`$3')')
+define(`get',`defn(`$1[$2]')')
+define(`setrange',`ifelse(`$3',`',$2,`define($1[$2],$3)`'setrange($1,
+ incr($2),shift(shift(shift($@))))')')
+define(`for',
+ `ifelse($#,0,``$0'',
+ `ifelse(eval($2<=$3),1,
+ `pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')
+define(`show',
+ `for(`k',0,decr($1),`get(a,k) ')')
+
+define(`chklim',
+ `ifelse(get(`a',$3),eval($2-($1-$3)),
+ `chklim($1,$2,decr($3))',
+ `set(`a',$3,incr(get(`a',$3)))`'for(`k',incr($3),decr($2),
+ `set(`a',k,incr(get(`a',decr(k))))')`'nextcomb($1,$2)')')
+define(`nextcomb',
+ `show($1)
+ifelse(eval(get(`a',0)<$2-$1),1,
+ `chklim($1,$2,decr($1))')')
+define(`comb',
+ `for(`j',0,decr($1),`set(`a',j,j)')`'nextcomb($1,$2)')
+divert
+
+comb(3,5)
diff --git a/Task/Combinations/Mathematica/combinations.mathematica b/Task/Combinations/Mathematica/combinations.mathematica
new file mode 100644
index 0000000000..7fc1036719
--- /dev/null
+++ b/Task/Combinations/Mathematica/combinations.mathematica
@@ -0,0 +1 @@
+combinations[n_Integer, m_Integer]/;m>= 0:=Union[Sort /@ Permutations[Range[0, n - 1], {m}]]
diff --git a/Task/Combinations/Maxima/combinations.maxima b/Task/Combinations/Maxima/combinations.maxima
new file mode 100644
index 0000000000..ffed0247d7
--- /dev/null
+++ b/Task/Combinations/Maxima/combinations.maxima
@@ -0,0 +1,26 @@
+next_comb(n, p, a) := block(
+ [a: copylist(a), i: p],
+ if a[1] + p = n + 1 then return(und),
+ while a[i] - i >= n - p do i: i - 1,
+ a[i]: a[i] + 1,
+ for j from i + 1 thru p do a[j]: a[j - 1] + 1,
+ a
+)$
+
+combinations(n, p) := block(
+ [a: makelist(i, i, 1, p), v: [ ]],
+ while a # 'und do (v: endcons(a, v), a: next_comb(n, p, a)),
+ v
+)$
+
+combinations(5, 3);
+/* [[1, 2, 3],
+ [1, 2, 4],
+ [1, 2, 5],
+ [1, 3, 4],
+ [1, 3, 5],
+ [1, 4, 5],
+ [2, 3, 4],
+ [2, 3, 5],
+ [2, 4, 5],
+ [3, 4, 5]] */
diff --git a/Task/Command-line-arguments/Fancy/command-line-arguments.fancy b/Task/Command-line-arguments/Fancy/command-line-arguments.fancy
new file mode 100644
index 0000000000..eff0d1ea82
--- /dev/null
+++ b/Task/Command-line-arguments/Fancy/command-line-arguments.fancy
@@ -0,0 +1,3 @@
+ARGV each: |a| {
+ a println # print each given command line argument
+}
diff --git a/Task/Command-line-arguments/Fantom/command-line-arguments.fantom b/Task/Command-line-arguments/Fantom/command-line-arguments.fantom
new file mode 100644
index 0000000000..e95045e0d0
--- /dev/null
+++ b/Task/Command-line-arguments/Fantom/command-line-arguments.fantom
@@ -0,0 +1,7 @@
+class Main
+{
+ public static Void main (Str[] args)
+ {
+ echo ("command-line args are: " + args)
+ }
+}
diff --git a/Task/Command-line-arguments/Gambas/command-line-arguments.gambas b/Task/Command-line-arguments/Gambas/command-line-arguments.gambas
new file mode 100644
index 0000000000..b460d3a57d
--- /dev/null
+++ b/Task/Command-line-arguments/Gambas/command-line-arguments.gambas
@@ -0,0 +1,10 @@
+PUBLIC SUB main()
+ DIM l AS Integer
+ DIM numparms AS Integer
+ DIM parm AS String
+ numparms = Application.Args.Count
+ FOR l = 0 TO numparms - 1
+ parm = Application.Args[l]
+ PRINT l; " : "; parm
+ NEXT
+END SUB
diff --git a/Task/Command-line-arguments/Groovy/command-line-arguments.groovy b/Task/Command-line-arguments/Groovy/command-line-arguments.groovy
new file mode 100644
index 0000000000..f2004b3ac1
--- /dev/null
+++ b/Task/Command-line-arguments/Groovy/command-line-arguments.groovy
@@ -0,0 +1 @@
+println args
diff --git a/Task/Command-line-arguments/HicEst/command-line-arguments.hicest b/Task/Command-line-arguments/HicEst/command-line-arguments.hicest
new file mode 100644
index 0000000000..1ee6bc4225
--- /dev/null
+++ b/Task/Command-line-arguments/HicEst/command-line-arguments.hicest
@@ -0,0 +1,4 @@
+DO i = 2, 100 ! 1 is HicEst.exe
+ EDIT(Text=$CMD_LINE, SePaRators='-"', ITeM=i, IF ' ', EXit, ENDIF, Parse=cmd, GetPosition=position)
+ IF(position > 0) WRITE(Messagebox) cmd
+ENDDO
diff --git a/Task/Command-line-arguments/Icon/command-line-arguments.icon b/Task/Command-line-arguments/Icon/command-line-arguments.icon
new file mode 100644
index 0000000000..e18462784c
--- /dev/null
+++ b/Task/Command-line-arguments/Icon/command-line-arguments.icon
@@ -0,0 +1,3 @@
+procedure main(arglist)
+every write(!arglist)
+end
diff --git a/Task/Command-line-arguments/Io/command-line-arguments.io b/Task/Command-line-arguments/Io/command-line-arguments.io
new file mode 100644
index 0000000000..3538f36955
--- /dev/null
+++ b/Task/Command-line-arguments/Io/command-line-arguments.io
@@ -0,0 +1 @@
+System args foreach(a, a println)
diff --git a/Task/Command-line-arguments/Ioke/command-line-arguments.ioke b/Task/Command-line-arguments/Ioke/command-line-arguments.ioke
new file mode 100644
index 0000000000..584bfac4a3
--- /dev/null
+++ b/Task/Command-line-arguments/Ioke/command-line-arguments.ioke
@@ -0,0 +1 @@
+System programArguments each(println)
diff --git a/Task/Command-line-arguments/J/command-line-arguments.j b/Task/Command-line-arguments/J/command-line-arguments.j
new file mode 100644
index 0000000000..1a017718e8
--- /dev/null
+++ b/Task/Command-line-arguments/J/command-line-arguments.j
@@ -0,0 +1 @@
+ ARGV
diff --git a/Task/Command-line-arguments/LSE64/command-line-arguments.lse64 b/Task/Command-line-arguments/LSE64/command-line-arguments.lse64
new file mode 100644
index 0000000000..2b9743be0d
--- /dev/null
+++ b/Task/Command-line-arguments/LSE64/command-line-arguments.lse64
@@ -0,0 +1,4 @@
+argc , nl # number of arguments (including command itself)
+0 # argument
+dup arg dup 0 = || ,t 1 + repeat
+drop
diff --git a/Task/Command-line-arguments/Liberty-BASIC/command-line-arguments.liberty b/Task/Command-line-arguments/Liberty-BASIC/command-line-arguments.liberty
new file mode 100644
index 0000000000..c68a5bf031
--- /dev/null
+++ b/Task/Command-line-arguments/Liberty-BASIC/command-line-arguments.liberty
@@ -0,0 +1 @@
+print CommandLine$
diff --git a/Task/Command-line-arguments/Logo/command-line-arguments.logo b/Task/Command-line-arguments/Logo/command-line-arguments.logo
new file mode 100644
index 0000000000..10c99d5970
--- /dev/null
+++ b/Task/Command-line-arguments/Logo/command-line-arguments.logo
@@ -0,0 +1,2 @@
+show :COMMAND.LINE
+[arg1 arg2 arg3]
diff --git a/Task/Command-line-arguments/MMIX/command-line-arguments.mmix b/Task/Command-line-arguments/MMIX/command-line-arguments.mmix
new file mode 100644
index 0000000000..bf64a426ad
--- /dev/null
+++ b/Task/Command-line-arguments/MMIX/command-line-arguments.mmix
@@ -0,0 +1,23 @@
+argv IS $1
+argc IS $0
+i IS $2
+
+ LOC #100
+Main LOC @
+ SETL i,1 % i = 1
+Loop CMP $3,argc,2 % argc < 2 ?
+ BN $3,1F % then jump to end
+ XOR $255,$255,$255 % clear $255
+ 8ADDU $255,i,argv % i*8 + argv
+ LDOU $255,$255,0 % argv[i]
+ TRAP 0,Fputs,StdOut % write the argument
+ GETA $255,NewLine % add a newline
+ TRAP 0,Fputs,StdOut
+ INCL i,1 % increment index
+ SUB argc,argc,1 % argc--
+ BP argc,Loop % argc > 0? then Loop
+1H LOC @
+ XOR $255,$255,$255 % exit(0)
+ TRAP 0,Halt,0
+
+NewLine BYTE #a,0
diff --git a/Task/Command-line-arguments/Mathematica/command-line-arguments.mathematica b/Task/Command-line-arguments/Mathematica/command-line-arguments.mathematica
new file mode 100644
index 0000000000..e6f4c0c899
--- /dev/null
+++ b/Task/Command-line-arguments/Mathematica/command-line-arguments.mathematica
@@ -0,0 +1,2 @@
+#!/usr/local/bin/MathematicaScript -script
+$CommandLine
diff --git a/Task/Command-line-arguments/Mercury/command-line-arguments.mercury b/Task/Command-line-arguments/Mercury/command-line-arguments.mercury
new file mode 100644
index 0000000000..167de9ac61
--- /dev/null
+++ b/Task/Command-line-arguments/Mercury/command-line-arguments.mercury
@@ -0,0 +1,19 @@
+:- module cmd_line_args.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int, list, string.
+
+main(!IO) :-
+ io.progname("", ProgName, !IO),
+ io.format("This program is named %s.\n", [s(ProgName)], !IO),
+ io.command_line_arguments(Args, !IO),
+ list.foldl2(print_arg, Args, 1, _, !IO).
+
+:- pred print_arg(string::in, int::in, int::out, io::di, io::uo) is det.
+
+print_arg(Arg, ArgNum, ArgNum + 1, !IO) :-
+ io.format("the argument #%d is %s\n", [i(ArgNum), s(Arg)], !IO).
diff --git a/Task/Command-line-arguments/Modula-2/command-line-arguments-1.mod2 b/Task/Command-line-arguments/Modula-2/command-line-arguments-1.mod2
new file mode 100644
index 0000000000..fe8af63038
--- /dev/null
+++ b/Task/Command-line-arguments/Modula-2/command-line-arguments-1.mod2
@@ -0,0 +1,20 @@
+MODULE try;
+
+FROM Arguments IMPORT GetArgs, ArgTable, GetEnv;
+FROM InOut IMPORT WriteCard, WriteLn, WriteString;
+
+VAR count, item : SHORTCARD;
+ storage : ArgTable;
+
+BEGIN
+ GetArgs (count, storage);
+ WriteString ('Count ='); WriteCard (count, 4); WriteLn;
+ item := 0;
+ REPEAT
+ WriteCard (item, 4);
+ WriteString (' : ');
+ WriteString (storage^ [item]^);
+ WriteLn;
+ INC (item)
+ UNTIL item = count
+END try.
diff --git a/Task/Command-line-arguments/Modula-2/command-line-arguments-2.mod2 b/Task/Command-line-arguments/Modula-2/command-line-arguments-2.mod2
new file mode 100644
index 0000000000..34e6014e63
--- /dev/null
+++ b/Task/Command-line-arguments/Modula-2/command-line-arguments-2.mod2
@@ -0,0 +1,8 @@
+jan@Beryllium:~/modula/test$ try jantje zag eens pruimen hangen
+Count = 6
+ 0 : try
+ 1 : jantje
+ 2 : zag
+ 3 : eens
+ 4 : pruimen
+ 5 : hangen
diff --git a/Task/Command-line-arguments/Modula-3/command-line-arguments.mod3 b/Task/Command-line-arguments/Modula-3/command-line-arguments.mod3
new file mode 100644
index 0000000000..07f3df499c
--- /dev/null
+++ b/Task/Command-line-arguments/Modula-3/command-line-arguments.mod3
@@ -0,0 +1,12 @@
+MODULE Args EXPORTS Main;
+
+IMPORT IO, Params;
+
+BEGIN
+ IO.Put(Params.Get(0) & "\n");
+ IF Params.Count > 1 THEN
+ FOR i := 1 TO Params.Count - 1 DO
+ IO.Put(Params.Get(i) & "\n");
+ END;
+ END;
+END Args.
diff --git a/Task/Comments/FALSE/comments.false b/Task/Comments/FALSE/comments.false
new file mode 100644
index 0000000000..1c0ae8d18e
--- /dev/null
+++ b/Task/Comments/FALSE/comments.false
@@ -0,0 +1 @@
+{comments are in curly braces}
diff --git a/Task/Comments/Factor/comments.factor b/Task/Comments/Factor/comments.factor
new file mode 100644
index 0000000000..12f3ced380
--- /dev/null
+++ b/Task/Comments/Factor/comments.factor
@@ -0,0 +1,3 @@
+! Comments starts with "! "
+#! Or with "#! "
+! and last until the end of the line
diff --git a/Task/Comments/Falcon/comments.falcon b/Task/Comments/Falcon/comments.falcon
new file mode 100644
index 0000000000..998d2522ca
--- /dev/null
+++ b/Task/Comments/Falcon/comments.falcon
@@ -0,0 +1,6 @@
+/* Start comment block
+ My Life Story
+ */
+
+// set up my bank account total
+bank_account_total = 1000000 // Wish this was the case
diff --git a/Task/Comments/Fancy/comments.fancy b/Task/Comments/Fancy/comments.fancy
new file mode 100644
index 0000000000..be74ba2c8e
--- /dev/null
+++ b/Task/Comments/Fancy/comments.fancy
@@ -0,0 +1,2 @@
+# Comments starts with "#"
+# and last until the end of the line
diff --git a/Task/Comments/Fish/comments.fish b/Task/Comments/Fish/comments.fish
new file mode 100644
index 0000000000..bd71f9906e
--- /dev/null
+++ b/Task/Comments/Fish/comments.fish
@@ -0,0 +1,4 @@
+v This is the Fish version of the Integer sequence task
+>0>:n1+v all comments here
+ ^o" "< still here
+And of course here :)
diff --git a/Task/Comments/GAP/comments.gap b/Task/Comments/GAP/comments.gap
new file mode 100644
index 0000000000..4797a0076f
--- /dev/null
+++ b/Task/Comments/GAP/comments.gap
@@ -0,0 +1 @@
+# Comment (till end of line)
diff --git a/Task/Comments/GML/comments-1.gml b/Task/Comments/GML/comments-1.gml
new file mode 100644
index 0000000000..fc919b4afc
--- /dev/null
+++ b/Task/Comments/GML/comments-1.gml
@@ -0,0 +1 @@
+ // comment starts with "//" and continues to the end of the line
diff --git a/Task/Comments/GML/comments-2.gml b/Task/Comments/GML/comments-2.gml
new file mode 100644
index 0000000000..494f9ac58a
--- /dev/null
+++ b/Task/Comments/GML/comments-2.gml
@@ -0,0 +1,6 @@
+ /* a multi-line comment starts with slash-asterisk and,
+ends with asterisk-slash.
+also note:
+ * A multi-line comment is ignored inside a string
+ * A multi-line comment can be ended inside a line
+*/
diff --git a/Task/Comments/GW-BASIC/comments.bas b/Task/Comments/GW-BASIC/comments.bas
new file mode 100644
index 0000000000..de95f49486
--- /dev/null
+++ b/Task/Comments/GW-BASIC/comments.bas
@@ -0,0 +1,2 @@
+100 REM Standard BASIC comments begin with "REM" (remark) and extend to the end of the line
+110 PRINT "this is code": REM comment after statement
diff --git a/Task/Comments/Gambas/comments.gambas b/Task/Comments/Gambas/comments.gambas
new file mode 100644
index 0000000000..4559cac6e7
--- /dev/null
+++ b/Task/Comments/Gambas/comments.gambas
@@ -0,0 +1,2 @@
+ ' This whole line is a comment and is ignored by the gambas interpreter
+ print "Hello" ' Comments after an apostrophe are ignored
diff --git a/Task/Comments/Gema/comments.gema b/Task/Comments/Gema/comments.gema
new file mode 100644
index 0000000000..434fe0003e
--- /dev/null
+++ b/Task/Comments/Gema/comments.gema
@@ -0,0 +1 @@
+! comment starts with "!" and continues to end of line
diff --git a/Task/Comments/Golfscript/comments.golf b/Task/Comments/Golfscript/comments.golf
new file mode 100644
index 0000000000..f487027b61
--- /dev/null
+++ b/Task/Comments/Golfscript/comments.golf
@@ -0,0 +1 @@
+# end of line comment
diff --git a/Task/Comments/Haxe/comments.haxe b/Task/Comments/Haxe/comments.haxe
new file mode 100644
index 0000000000..3cf6cd4fb6
--- /dev/null
+++ b/Task/Comments/Haxe/comments.haxe
@@ -0,0 +1,7 @@
+// Single line commment.
+
+/*
+ Multiple
+ line
+ comment.
+*/
diff --git a/Task/Comments/HicEst/comments.hicest b/Task/Comments/HicEst/comments.hicest
new file mode 100644
index 0000000000..b9a7677b30
--- /dev/null
+++ b/Task/Comments/HicEst/comments.hicest
@@ -0,0 +1 @@
+! a comment starts with a "!" and ends at the end of the line
diff --git a/Task/Comments/IDL/comments.idl b/Task/Comments/IDL/comments.idl
new file mode 100644
index 0000000000..d51f7f7c57
--- /dev/null
+++ b/Task/Comments/IDL/comments.idl
@@ -0,0 +1,2 @@
+; The following computes the factorial of a number "n"
+fact = product(indgen( n )+1) ; where n should be an integer
diff --git a/Task/Comments/Icon/comments.icon b/Task/Comments/Icon/comments.icon
new file mode 100644
index 0000000000..9d90fccbe0
--- /dev/null
+++ b/Task/Comments/Icon/comments.icon
@@ -0,0 +1,3 @@
+# This is a comment
+
+procedure x(y,z) #: This is a comment and an IPL meta-comment for a procedure
diff --git a/Task/Comments/Inform-7/comments.inf b/Task/Comments/Inform-7/comments.inf
new file mode 100644
index 0000000000..b5704205d3
--- /dev/null
+++ b/Task/Comments/Inform-7/comments.inf
@@ -0,0 +1,6 @@
+[This is a single-line comment.]
+
+[This is a
+multi-line comment.]
+
+[Comments can [be nested].]
diff --git a/Task/Comments/Io/comments.io b/Task/Comments/Io/comments.io
new file mode 100644
index 0000000000..094d180fbd
--- /dev/null
+++ b/Task/Comments/Io/comments.io
@@ -0,0 +1,6 @@
+# Single-line comment
+
+// Single-line comment
+
+/* Multi-line
+ comment */
diff --git a/Task/Comments/J/comments.j b/Task/Comments/J/comments.j
new file mode 100644
index 0000000000..a0f2046039
--- /dev/null
+++ b/Task/Comments/J/comments.j
@@ -0,0 +1,11 @@
+NB. Text that follows 'NB.' has no effect on execution.
+
+0 : 0
+Multi-line comments may be placed in strings,
+like this.
+)
+
+Note 'example'
+Another way to record multi-line comments as text is to use 'Note', which is actually
+a simple program that makes it clearer when defined text is used only to provide comment.
+)
diff --git a/Task/Comments/JCL/comments.jcl b/Task/Comments/JCL/comments.jcl
new file mode 100644
index 0000000000..fae5a32144
--- /dev/null
+++ b/Task/Comments/JCL/comments.jcl
@@ -0,0 +1 @@
+//* This is a comment line (//* in columns 1-3)
diff --git a/Task/Comments/Joy/comments.joy b/Task/Comments/Joy/comments.joy
new file mode 100644
index 0000000000..d332b70d13
--- /dev/null
+++ b/Task/Comments/Joy/comments.joy
@@ -0,0 +1,4 @@
+# this is a single line comment
+
+(* this is a
+multi-line comment *)
diff --git a/Task/Comments/K/comments.k b/Task/Comments/K/comments.k
new file mode 100644
index 0000000000..8df7ff27f1
--- /dev/null
+++ b/Task/Comments/K/comments.k
@@ -0,0 +1,2 @@
+ / this is a comment
+ 2+2 / as is this
diff --git a/Task/Comments/KonsolScript/comments.konso b/Task/Comments/KonsolScript/comments.konso
new file mode 100644
index 0000000000..8347c20545
--- /dev/null
+++ b/Task/Comments/KonsolScript/comments.konso
@@ -0,0 +1,8 @@
+//This is a comment.
+//This is another comment.
+
+/* This is a comment too. */
+
+/* This is a
+multi-line
+comment */
diff --git a/Task/Comments/LSE64/comments-1.lse64 b/Task/Comments/LSE64/comments-1.lse64
new file mode 100644
index 0000000000..22685dcacc
--- /dev/null
+++ b/Task/Comments/LSE64/comments-1.lse64
@@ -0,0 +1 @@
+# single line comment (space after # is required)
diff --git a/Task/Comments/LSE64/comments-2.lse64 b/Task/Comments/LSE64/comments-2.lse64
new file mode 100644
index 0000000000..74affcf9e0
--- /dev/null
+++ b/Task/Comments/LSE64/comments-2.lse64
@@ -0,0 +1 @@
+# arg1 arg2 '''yields''' result|''nothing''
diff --git a/Task/Comments/Lang5/comments.lang5 b/Task/Comments/Lang5/comments.lang5
new file mode 100644
index 0000000000..a10b5ddae7
--- /dev/null
+++ b/Task/Comments/Lang5/comments.lang5
@@ -0,0 +1 @@
+# This is a comment.
diff --git a/Task/Comments/Liberty-BASIC/comments.liberty b/Task/Comments/Liberty-BASIC/comments.liberty
new file mode 100644
index 0000000000..11bd5365b7
--- /dev/null
+++ b/Task/Comments/Liberty-BASIC/comments.liberty
@@ -0,0 +1,5 @@
+'This is a comment
+REM This is a comment
+
+print "This has a comment on the end of the line." 'This is a comment
+print "This also has a comment on the end of the line." : REM This is a comment
diff --git a/Task/Comments/Lilypond/comments.lilypond b/Task/Comments/Lilypond/comments.lilypond
new file mode 100644
index 0000000000..f809e72197
--- /dev/null
+++ b/Task/Comments/Lilypond/comments.lilypond
@@ -0,0 +1,4 @@
+% This is a comment
+
+%{ This is a comment
+spanning several lines %}
diff --git a/Task/Comments/Logo/comments.logo b/Task/Comments/Logo/comments.logo
new file mode 100644
index 0000000000..65a82907f4
--- /dev/null
+++ b/Task/Comments/Logo/comments.logo
@@ -0,0 +1 @@
+; comments come after a semicolon, and last until the end of the line
diff --git a/Task/Comments/Logtalk/comments-1.logtalk b/Task/Comments/Logtalk/comments-1.logtalk
new file mode 100644
index 0000000000..37bfc87be7
--- /dev/null
+++ b/Task/Comments/Logtalk/comments-1.logtalk
@@ -0,0 +1 @@
+% single-line comment; extends to the end of the line
diff --git a/Task/Comments/Logtalk/comments-2.logtalk b/Task/Comments/Logtalk/comments-2.logtalk
new file mode 100644
index 0000000000..c59c49f34c
--- /dev/null
+++ b/Task/Comments/Logtalk/comments-2.logtalk
@@ -0,0 +1,2 @@
+/* multi-line
+comment */
diff --git a/Task/Comments/LotusScript/comments-1.lotus b/Task/Comments/LotusScript/comments-1.lotus
new file mode 100644
index 0000000000..48fac3547a
--- /dev/null
+++ b/Task/Comments/LotusScript/comments-1.lotus
@@ -0,0 +1 @@
+' This is a comment
diff --git a/Task/Comments/LotusScript/comments-2.lotus b/Task/Comments/LotusScript/comments-2.lotus
new file mode 100644
index 0000000000..3c123d13fe
--- /dev/null
+++ b/Task/Comments/LotusScript/comments-2.lotus
@@ -0,0 +1,4 @@
+%REM
+This is a multi-
+line comment.
+%END REM
diff --git a/Task/Comments/M4/comments.m4 b/Task/Comments/M4/comments.m4
new file mode 100644
index 0000000000..70f4a12a49
--- /dev/null
+++ b/Task/Comments/M4/comments.m4
@@ -0,0 +1,6 @@
+eval(2*3) # eval(2*3) "#" and text after it aren't processed but passed along
+dnl this text completely disappears, including the new line
+divert(-1)
+Everything diverted to -1 is processed but the output is discarded.
+A comment could take this form as long as no macro names are used.
+divert
diff --git a/Task/Comments/MAXScript/comments.max b/Task/Comments/MAXScript/comments.max
new file mode 100644
index 0000000000..c93fc18b05
--- /dev/null
+++ b/Task/Comments/MAXScript/comments.max
@@ -0,0 +1,4 @@
+-- Two dashes precede a single line comment
+
+/* This is a
+ multi-line comment */
diff --git a/Task/Comments/MBS/comments.mbs b/Task/Comments/MBS/comments.mbs
new file mode 100644
index 0000000000..878da6fca9
--- /dev/null
+++ b/Task/Comments/MBS/comments.mbs
@@ -0,0 +1,6 @@
+! A pling in a line starts a comment
+
+INT n:=5 ! Comments can appear at the end of a line
+
+/* A comment block can also be defined using climbstar and starclimb symbols.
+ This allows comments to be stretched across several lines */
diff --git a/Task/Comments/MOO/comments.moo b/Task/Comments/MOO/comments.moo
new file mode 100644
index 0000000000..405f496280
--- /dev/null
+++ b/Task/Comments/MOO/comments.moo
@@ -0,0 +1,3 @@
+"String literals are technically the only long-term comment format";
+// Some compilers will, however, compile // one-liners to string literals as well (and vice-versa)
+/* Classical C-style comments are removed entirely during compile */
diff --git a/Task/Comments/Mathematica/comments-1.mathematica b/Task/Comments/Mathematica/comments-1.mathematica
new file mode 100644
index 0000000000..79b05713c8
--- /dev/null
+++ b/Task/Comments/Mathematica/comments-1.mathematica
@@ -0,0 +1 @@
+(*this is a comment*)
diff --git a/Task/Comments/Mathematica/comments-2.mathematica b/Task/Comments/Mathematica/comments-2.mathematica
new file mode 100644
index 0000000000..0760828c1e
--- /dev/null
+++ b/Task/Comments/Mathematica/comments-2.mathematica
@@ -0,0 +1 @@
+If[a(*number 1*)<(* is smaller than number 2*) b, True (*return value (*bool true*)*), False (*return bool false*)]
diff --git a/Task/Comments/Mathematica/comments-3.mathematica b/Task/Comments/Mathematica/comments-3.mathematica
new file mode 100644
index 0000000000..cd33ee8ed0
--- /dev/null
+++ b/Task/Comments/Mathematica/comments-3.mathematica
@@ -0,0 +1 @@
+If[a < b, True, False]
diff --git a/Task/Comments/Maxima/comments.maxima b/Task/Comments/Maxima/comments.maxima
new file mode 100644
index 0000000000..1d3b796e75
--- /dev/null
+++ b/Task/Comments/Maxima/comments.maxima
@@ -0,0 +1,3 @@
+/* Comment
+ /* Nested comment */
+*/
diff --git a/Task/Comments/Metafont/comments.metafont b/Task/Comments/Metafont/comments.metafont
new file mode 100644
index 0000000000..22f2f93e2b
--- /dev/null
+++ b/Task/Comments/Metafont/comments.metafont
@@ -0,0 +1 @@
+% this is "to-end-of-line" comment
diff --git a/Task/Comments/Mirah/comments.mirah b/Task/Comments/Mirah/comments.mirah
new file mode 100644
index 0000000000..bc40df7391
--- /dev/null
+++ b/Task/Comments/Mirah/comments.mirah
@@ -0,0 +1,4 @@
+puts 'code' # I am a comment
+/* This is
+ * a multiple
+ * line comment */
diff --git a/Task/Comments/Modula-2/comments.mod2 b/Task/Comments/Modula-2/comments.mod2
new file mode 100644
index 0000000000..0d7a59997a
--- /dev/null
+++ b/Task/Comments/Modula-2/comments.mod2
@@ -0,0 +1,3 @@
+(* Comments (* can nest *)
+ and they can span multiple lines.
+ *)
diff --git a/Task/Comments/Modula-3/comments.mod3 b/Task/Comments/Modula-3/comments.mod3
new file mode 100644
index 0000000000..0d7a59997a
--- /dev/null
+++ b/Task/Comments/Modula-3/comments.mod3
@@ -0,0 +1,3 @@
+(* Comments (* can nest *)
+ and they can span multiple lines.
+ *)
diff --git a/Task/Compare-sorting-algorithms-performance/J/compare-sorting-algorithms-performance.j b/Task/Compare-sorting-algorithms-performance/J/compare-sorting-algorithms-performance.j
new file mode 100644
index 0000000000..c1be09b47d
--- /dev/null
+++ b/Task/Compare-sorting-algorithms-performance/J/compare-sorting-algorithms-performance.j
@@ -0,0 +1,82 @@
+NB. extracts from other rosetta code projects
+ts=: 6!:2, 7!:2@]
+radix =: 3 : 0
+256 radix y
+:
+a=. #{. z =. x #.^:_1 y
+e=. (-a) {."0 b =. i.x
+x#.1{::(<:@[;([: ; (b, {"1) <@}./. e,]))&>/^:a [ z;~a-1
+NB. , ([: ; (b, {:"1) <@(}:"1@:}.)/. e,])^:(#{.z) y,.z
+)
+bubble=: (([ (<. , >.) {.@]) , }.@])/^:_
+insertion=:((>: # ]) , [ , < #])/
+sel=: 1 : 'x # ['
+quick=: 3 : 0
+ if. 1 >: #y do. y
+ else.
+ e=. y{~?#y
+ (quick y sel e
+ end.
+)
+gaps =: [: }: 1 (1+3*])^:(> {:)^:a:~ #
+insert =: (I.~ {. ]) , [ , ] }.~ I.~
+gapinss =: #@] {. ,@|:@(] insert//.~ #@] $ i.@[)
+shell =: [: ; gapinss &.>/@(< ,~ ]&.>@gaps)
+builtin =: /:~
+
+
+
+NB. characterization of the sorting algorithms.
+
+sorts =: bubble`insertion`shell`quick`radix`builtin
+generators =: #&1`(i.@-)`(?.~) NB. data generators
+
+round =: [: <. 1r2&+
+
+ll =: (<_1 0)&{ NB. verb to extract lower left which holds ln data length
+lc =: (<_1 1)&{ NB. verb to fetch lower center which holds most recent time
+
+NB. maximum_time characterize ln_start_size
+NB. characterize returns a rank 4 matrix with successive indexes for
+NB. algorithm, input arrangement, max number of tests in group, length time space
+characterize =: 4 : 0
+ max_time =. x
+ start =. 1 3{.<:y
+ for_sort. sorts do.
+ for_generator. generators do. NB. limit time and paging prevention
+ t =: }. (, (, [: ts 'sort@.0 (generator@.0)' , ":@round@^)@>:@ll) ^: ((lc < max_time"_) *. ll < 17"_) ^:_ start
+ if. generator -: {.generators do.
+ g =. ,:t
+ else.
+ g =. g,t
+ end.
+ end.
+ if. sort -: {.sorts do.
+ s =. ,:g
+ else.
+ s =. s,g
+ end.
+ end.
+)
+
+NB. character cell graphics
+
+NB. From j phrases 10E. Approximation
+d3=: 1&,.@[ %.~ ] NB. a and b such that y is approx. a + b*x
+
+NB. domain and range 0 to 14.
+D=:14
+
+plot =: 1 : '(=/ round@(u&.(*&(D%<:y))))i.y' NB. function plot size
+points =: 4 : '1(<"1|:|.round y*D%~<:x)}0$~2#x' NB. size points x,:y
+
+show =: [: |. [: '0'&~:@{:} ' ' ,: ":
+
+plt =: 3 : 0
+30 plt y NB. default size 30
+:
+n =. >:i.-# experiments =. <@(#~"1 (0&<)@{.)"2 y
+pts =. n +./ .*x&points@>experiments
+coef =. d3/@>experiments
+(_*pts) + n +./ .*1 0 2|:coef&(p."1) plot x
+)
diff --git a/Task/Compile-time-calculation/Factor/compile-time-calculation.factor b/Task/Compile-time-calculation/Factor/compile-time-calculation.factor
new file mode 100644
index 0000000000..85b631f648
--- /dev/null
+++ b/Task/Compile-time-calculation/Factor/compile-time-calculation.factor
@@ -0,0 +1,3 @@
+: factorial ( n -- n! ) [1,b] product ;
+
+CONSTANT: 10-factorial $[ 10 factorial ]
diff --git a/Task/Compile-time-calculation/J/compile-time-calculation-1.j b/Task/Compile-time-calculation/J/compile-time-calculation-1.j
new file mode 100644
index 0000000000..aad18c3e60
--- /dev/null
+++ b/Task/Compile-time-calculation/J/compile-time-calculation-1.j
@@ -0,0 +1 @@
+pf10=: smoutput bind (!10)
diff --git a/Task/Compile-time-calculation/J/compile-time-calculation-2.j b/Task/Compile-time-calculation/J/compile-time-calculation-2.j
new file mode 100644
index 0000000000..5abfcc3d20
--- /dev/null
+++ b/Task/Compile-time-calculation/J/compile-time-calculation-2.j
@@ -0,0 +1,26 @@
+ 9!:3]1 2 4 5 6
+
+ pf10
+┌───────────────────────────────────────┐
+│┌─┬───────────────────────────────────┐│
+││@│┌────────┬────────────────────────┐││
+││ ││smoutput│┌─┬────────────────────┐│││
+││ ││ ││"│┌────────────┬─────┐││││
+││ ││ ││ ││┌─┬────────┐│┌─┬─┐│││││
+││ ││ ││ │││0│3.6288e6│││0│_││││││
+││ ││ ││ ││└─┴────────┘│└─┴─┘│││││
+││ ││ ││ │└────────────┴─────┘││││
+││ ││ │└─┴────────────────────┘│││
+││ │└────────┴────────────────────────┘││
+│└─┴───────────────────────────────────┘│
+└───────────────────────────────────────┘
+┌────────┬─┬──────────────┐
+│smoutput│@│┌────────┬─┬─┐│
+│ │ ││3.6288e6│"│_││
+│ │ │└────────┴─┴─┘│
+└────────┴─┴──────────────┘
+ ┌─ smoutput
+── @ ─┤ ┌─ 3628800
+ └─ " ──────┴─ _
+smoutput@(3628800"_)
+smoutput@(3628800"_)
diff --git a/Task/Compile-time-calculation/J/compile-time-calculation-3.j b/Task/Compile-time-calculation/J/compile-time-calculation-3.j
new file mode 100644
index 0000000000..3fae49a28a
--- /dev/null
+++ b/Task/Compile-time-calculation/J/compile-time-calculation-3.j
@@ -0,0 +1,2 @@
+ pf10 ''
+3628800
diff --git a/Task/Compile-time-calculation/Mathematica/compile-time-calculation-1.mathematica b/Task/Compile-time-calculation/Mathematica/compile-time-calculation-1.mathematica
new file mode 100644
index 0000000000..655a7dddbd
--- /dev/null
+++ b/Task/Compile-time-calculation/Mathematica/compile-time-calculation-1.mathematica
@@ -0,0 +1 @@
+f = Compile[{}, 10!]
diff --git a/Task/Compile-time-calculation/Mathematica/compile-time-calculation-2.mathematica b/Task/Compile-time-calculation/Mathematica/compile-time-calculation-2.mathematica
new file mode 100644
index 0000000000..42d4223086
--- /dev/null
+++ b/Task/Compile-time-calculation/Mathematica/compile-time-calculation-2.mathematica
@@ -0,0 +1 @@
+f[]
diff --git a/Task/Compound-data-type/Factor/compound-data-type.factor b/Task/Compound-data-type/Factor/compound-data-type.factor
new file mode 100644
index 0000000000..1c82487da3
--- /dev/null
+++ b/Task/Compound-data-type/Factor/compound-data-type.factor
@@ -0,0 +1 @@
+TUPLE: point x y ;
diff --git a/Task/Compound-data-type/Fantom/compound-data-type.fantom b/Task/Compound-data-type/Fantom/compound-data-type.fantom
new file mode 100644
index 0000000000..9baceff117
--- /dev/null
+++ b/Task/Compound-data-type/Fantom/compound-data-type.fantom
@@ -0,0 +1,20 @@
+// define a class to contain the two fields
+// accessors to get/set the field values are automatically generated
+class Point
+{
+ Int x
+ Int y
+}
+
+class Main
+{
+ public static Void main ()
+ {
+ // empty constructor, so x,y set to 0
+ point1 := Point()
+ // constructor uses with-block, to initialise values
+ point2 := Point { x = 1; y = 2}
+ echo ("Point 1 = (" + point1.x + ", " + point1.y + ")")
+ echo ("Point 2 = (" + point2.x + ", " + point2.y + ")")
+ }
+}
diff --git a/Task/Compound-data-type/Groovy/compound-data-type-1.groovy b/Task/Compound-data-type/Groovy/compound-data-type-1.groovy
new file mode 100644
index 0000000000..51cf083c92
--- /dev/null
+++ b/Task/Compound-data-type/Groovy/compound-data-type-1.groovy
@@ -0,0 +1,8 @@
+class Point {
+ int x
+ int y
+
+ // Default values make this a 0-, 1-, and 2-argument constructor
+ Point(int x = 0, int y = 0) { this.x = x; this.y = y }
+ String toString() { "{x:${x}, y:${y}}" }
+}
diff --git a/Task/Compound-data-type/Groovy/compound-data-type-2.groovy b/Task/Compound-data-type/Groovy/compound-data-type-2.groovy
new file mode 100644
index 0000000000..64fe97860c
--- /dev/null
+++ b/Task/Compound-data-type/Groovy/compound-data-type-2.groovy
@@ -0,0 +1,17 @@
+// Default Construction with explicit property setting:
+def p0 = new Point()
+assert 0 == p0.x
+assert 0 == p0.y
+p0.x = 36
+p0.y = -2
+assert 36 == p0.x
+assert -2 == p0.y
+
+// Direct Construction:
+def p1 = new Point(36, -2)
+assert 36 == p1.x
+assert -2 == p1.y
+
+def p2 = new Point(36)
+assert 36 == p2.x
+assert 0 == p2.y
diff --git a/Task/Compound-data-type/Groovy/compound-data-type-3.groovy b/Task/Compound-data-type/Groovy/compound-data-type-3.groovy
new file mode 100644
index 0000000000..8a79aa5a96
--- /dev/null
+++ b/Task/Compound-data-type/Groovy/compound-data-type-3.groovy
@@ -0,0 +1,19 @@
+// Explicit coersion from list with "as" keyword
+def p4 = [36, -2] as Point
+assert 36 == p4.x
+assert -2 == p4.y
+
+// Explicit coersion from list with Java/C-style casting
+p4 = (Point) [36, -2]
+println p4
+assert 36 == p4.x
+assert -2 == p4.y
+
+// Implicit coercion from list (by type of variable)
+Point p6 = [36, -2]
+assert 36 == p6.x
+assert -2 == p6.y
+
+Point p8 = [36]
+assert 36 == p8.x
+assert 0 == p8.y
diff --git a/Task/Compound-data-type/Groovy/compound-data-type-4.groovy b/Task/Compound-data-type/Groovy/compound-data-type-4.groovy
new file mode 100644
index 0000000000..0a0f22ee13
--- /dev/null
+++ b/Task/Compound-data-type/Groovy/compound-data-type-4.groovy
@@ -0,0 +1,31 @@
+// Direct map-based construction
+def p3 = new Point([x: 36, y: -2])
+assert 36 == p3.x
+assert -2 == p3.y
+
+// Direct map-entry-based construction
+p3 = new Point(x: 36, y: -2)
+assert 36 == p3.x
+assert -2 == p3.y
+
+p3 = new Point(x: 36)
+assert 36 == p3.x
+assert 0 == p3.y
+
+p3 = new Point(y: -2)
+assert 0 == p3.x
+assert -2 == p3.y
+
+// Explicit coercion from map with "as" keyword
+def p5 = [x: 36, y: -2] as Point
+assert 36 == p5.x
+assert -2 == p5.y
+
+// Implicit coercion from map (by type of variable)
+Point p7 = [x: 36, y: -2]
+assert 36 == p7.x
+assert -2 == p7.y
+
+Point p9 = [y:-2]
+assert 0 == p9.x
+assert -2 == p9.y
diff --git a/Task/Compound-data-type/IDL/compound-data-type.idl b/Task/Compound-data-type/IDL/compound-data-type.idl
new file mode 100644
index 0000000000..162cbd1b39
--- /dev/null
+++ b/Task/Compound-data-type/IDL/compound-data-type.idl
@@ -0,0 +1,4 @@
+point = {x: 6 , y: 0 }
+point.y = 7
+print, point
+;=> { 6 7}
diff --git a/Task/Compound-data-type/Icon/compound-data-type.icon b/Task/Compound-data-type/Icon/compound-data-type.icon
new file mode 100644
index 0000000000..f5f68325e1
--- /dev/null
+++ b/Task/Compound-data-type/Icon/compound-data-type.icon
@@ -0,0 +1 @@
+record Point(x,y)
diff --git a/Task/Compound-data-type/J/compound-data-type.j b/Task/Compound-data-type/J/compound-data-type.j
new file mode 100644
index 0000000000..9bc10cf7f3
--- /dev/null
+++ b/Task/Compound-data-type/J/compound-data-type.j
@@ -0,0 +1,17 @@
+ NB. Create a "Point" class
+ coclass'Point'
+
+ NB. Define its constuctor
+ create =: 3 : 0
+ 'X Y' =: y
+ )
+
+ NB. Instantiate an instance (i.e. an object)
+ cocurrent 'base'
+ P =: 10 20 conew 'Point'
+
+ NB. Interrogate its members
+ X__P
+10
+ Y__P
+20
diff --git a/Task/Compound-data-type/KonsolScript/compound-data-type-1.konso b/Task/Compound-data-type/KonsolScript/compound-data-type-1.konso
new file mode 100644
index 0000000000..4db542b67d
--- /dev/null
+++ b/Task/Compound-data-type/KonsolScript/compound-data-type-1.konso
@@ -0,0 +1,5 @@
+Var:Create(
+ Point,
+ Number x,
+ Number y
+)
diff --git a/Task/Compound-data-type/KonsolScript/compound-data-type-2.konso b/Task/Compound-data-type/KonsolScript/compound-data-type-2.konso
new file mode 100644
index 0000000000..c4ea24d186
--- /dev/null
+++ b/Task/Compound-data-type/KonsolScript/compound-data-type-2.konso
@@ -0,0 +1,3 @@
+function main() {
+ Var:Point point;
+}
diff --git a/Task/Compound-data-type/Logo/compound-data-type-1.logo b/Task/Compound-data-type/Logo/compound-data-type-1.logo
new file mode 100644
index 0000000000..a1d8c30384
--- /dev/null
+++ b/Task/Compound-data-type/Logo/compound-data-type-1.logo
@@ -0,0 +1,2 @@
+setpos [100 100] setpos [100 0] setpos [0 0]
+show pos ; [0 0]
diff --git a/Task/Compound-data-type/Logo/compound-data-type-2.logo b/Task/Compound-data-type/Logo/compound-data-type-2.logo
new file mode 100644
index 0000000000..da3fa5cafd
--- /dev/null
+++ b/Task/Compound-data-type/Logo/compound-data-type-2.logo
@@ -0,0 +1 @@
+until [(first mousepos) < 0] [ifelse button? [pendown] [penup] setpos mousepos]
diff --git a/Task/Compound-data-type/MAXScript/compound-data-type-1.max b/Task/Compound-data-type/MAXScript/compound-data-type-1.max
new file mode 100644
index 0000000000..96cab4abe3
--- /dev/null
+++ b/Task/Compound-data-type/MAXScript/compound-data-type-1.max
@@ -0,0 +1,2 @@
+struct myPoint (x, y)
+newPoint = myPoint x:3 y:4
diff --git a/Task/Compound-data-type/MAXScript/compound-data-type-2.max b/Task/Compound-data-type/MAXScript/compound-data-type-2.max
new file mode 100644
index 0000000000..d07fa36e59
--- /dev/null
+++ b/Task/Compound-data-type/MAXScript/compound-data-type-2.max
@@ -0,0 +1 @@
+newPoint = Point2 3 4
diff --git a/Task/Compound-data-type/Mathematica/compound-data-type-1.mathematica b/Task/Compound-data-type/Mathematica/compound-data-type-1.mathematica
new file mode 100644
index 0000000000..5c8b4dade6
--- /dev/null
+++ b/Task/Compound-data-type/Mathematica/compound-data-type-1.mathematica
@@ -0,0 +1,11 @@
+In[1]:= a = point[2, 3]
+
+Out[1]= point[2, 3]
+
+In[2]:= a[[2]]
+
+Out[2]= 3
+
+In[3]:= a[[2]] = 4; a
+
+Out[3]= point[2, 4]
diff --git a/Task/Compound-data-type/Mathematica/compound-data-type-2.mathematica b/Task/Compound-data-type/Mathematica/compound-data-type-2.mathematica
new file mode 100644
index 0000000000..67812439a7
--- /dev/null
+++ b/Task/Compound-data-type/Mathematica/compound-data-type-2.mathematica
@@ -0,0 +1 @@
+p[x] = 2; p[y] = 3;
diff --git a/Task/Compound-data-type/Maxima/compound-data-type.maxima b/Task/Compound-data-type/Maxima/compound-data-type.maxima
new file mode 100644
index 0000000000..b6f7961f2e
--- /dev/null
+++ b/Task/Compound-data-type/Maxima/compound-data-type.maxima
@@ -0,0 +1,7 @@
+defstruct(point(x, y))$
+
+p: new(point)$
+
+q: point(1, 2)$
+
+p@x: 5$
diff --git a/Task/Compound-data-type/Modula-2/compound-data-type-1.mod2 b/Task/Compound-data-type/Modula-2/compound-data-type-1.mod2
new file mode 100644
index 0000000000..0860a0cb2f
--- /dev/null
+++ b/Task/Compound-data-type/Modula-2/compound-data-type-1.mod2
@@ -0,0 +1,3 @@
+TYPE Point = RECORD
+ x, y : INTEGER
+END;
diff --git a/Task/Compound-data-type/Modula-2/compound-data-type-2.mod2 b/Task/Compound-data-type/Modula-2/compound-data-type-2.mod2
new file mode 100644
index 0000000000..0117a77ba2
--- /dev/null
+++ b/Task/Compound-data-type/Modula-2/compound-data-type-2.mod2
@@ -0,0 +1,4 @@
+VAR point : Point;
+...
+point.x := 12;
+point.y := 7;
diff --git a/Task/Compound-data-type/Modula-3/compound-data-type.mod3 b/Task/Compound-data-type/Modula-3/compound-data-type.mod3
new file mode 100644
index 0000000000..56bb7ebb4e
--- /dev/null
+++ b/Task/Compound-data-type/Modula-3/compound-data-type.mod3
@@ -0,0 +1,3 @@
+TYPE Point = RECORD
+ x, y: INTEGER;
+END;
diff --git a/Task/Concurrent-computing/Factor/concurrent-computing.factor b/Task/Concurrent-computing/Factor/concurrent-computing.factor
new file mode 100644
index 0000000000..cf15d509c8
--- /dev/null
+++ b/Task/Concurrent-computing/Factor/concurrent-computing.factor
@@ -0,0 +1,3 @@
+USE: concurrency.combinators
+
+{ "Enjoy" "Rosetta" "Code" } [ print ] parallel-each
diff --git a/Task/Concurrent-computing/Groovy/concurrent-computing.groovy b/Task/Concurrent-computing/Groovy/concurrent-computing.groovy
new file mode 100644
index 0000000000..76b54180a4
--- /dev/null
+++ b/Task/Concurrent-computing/Groovy/concurrent-computing.groovy
@@ -0,0 +1,6 @@
+'Enjoy Rosetta Code'.tokenize().collect { w ->
+ Thread.start {
+ Thread.sleep(1000 * Math.random() as int)
+ println w
+ }
+}.each { it.join() }
diff --git a/Task/Concurrent-computing/J/concurrent-computing.j b/Task/Concurrent-computing/J/concurrent-computing.j
new file mode 100644
index 0000000000..932095a532
--- /dev/null
+++ b/Task/Concurrent-computing/J/concurrent-computing.j
@@ -0,0 +1,4 @@
+ smoutput&>({~?~@#);:'Enjoy Rosetta Code'
+Rosetta
+Code
+Enjoy
diff --git a/Task/Concurrent-computing/Logtalk/concurrent-computing.logtalk b/Task/Concurrent-computing/Logtalk/concurrent-computing.logtalk
new file mode 100644
index 0000000000..cc04369b9b
--- /dev/null
+++ b/Task/Concurrent-computing/Logtalk/concurrent-computing.logtalk
@@ -0,0 +1,12 @@
+:- object(concurrency).
+
+ :- initialization(output).
+
+ output :-
+ threaded((
+ write('Enjoy'),
+ write('Rosetta'),
+ write('Code')
+ )).
+
+:- end_object.
diff --git a/Task/Concurrent-computing/Mathematica/concurrent-computing.mathematica b/Task/Concurrent-computing/Mathematica/concurrent-computing.mathematica
new file mode 100644
index 0000000000..b1a90d4158
--- /dev/null
+++ b/Task/Concurrent-computing/Mathematica/concurrent-computing.mathematica
@@ -0,0 +1,5 @@
+ParallelDo[
+ Pause[RandomReal[]];
+ Print[s],
+ {s, {"Enjoy", "Rosetta", "Code"}}
+]
diff --git a/Task/Concurrent-computing/Mercury/concurrent-computing.mercury b/Task/Concurrent-computing/Mercury/concurrent-computing.mercury
new file mode 100644
index 0000000000..2400b99a03
--- /dev/null
+++ b/Task/Concurrent-computing/Mercury/concurrent-computing.mercury
@@ -0,0 +1,13 @@
+:- module concurrent_computing.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is cc_multi.
+
+:- implementation.
+:- import_module thread.
+
+main(!IO) :-
+ spawn(io.print_cc("Enjoy\n"), !IO),
+ spawn(io.print_cc("Rosetta\n"), !IO),
+ spawn(io.print_cc("Code\n"), !IO).
diff --git a/Task/Conditional-structures/FALSE/conditional-structures-1.false b/Task/Conditional-structures/FALSE/conditional-structures-1.false
new file mode 100644
index 0000000000..d18123f72c
--- /dev/null
+++ b/Task/Conditional-structures/FALSE/conditional-structures-1.false
@@ -0,0 +1 @@
+condition[body]?
diff --git a/Task/Conditional-structures/FALSE/conditional-structures-2.false b/Task/Conditional-structures/FALSE/conditional-structures-2.false
new file mode 100644
index 0000000000..c437b9f357
--- /dev/null
+++ b/Task/Conditional-structures/FALSE/conditional-structures-2.false
@@ -0,0 +1 @@
+$[\true\]?~[false]?
diff --git a/Task/Conditional-structures/FALSE/conditional-structures-3.false b/Task/Conditional-structures/FALSE/conditional-structures-3.false
new file mode 100644
index 0000000000..2304333227
--- /dev/null
+++ b/Task/Conditional-structures/FALSE/conditional-structures-3.false
@@ -0,0 +1 @@
+$[%true0~]?~[false]?
diff --git a/Task/Conditional-structures/Factor/conditional-structures-1.factor b/Task/Conditional-structures/Factor/conditional-structures-1.factor
new file mode 100644
index 0000000000..d551e88f91
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-1.factor
@@ -0,0 +1 @@
+t 1 2 ? ! returns 1
diff --git a/Task/Conditional-structures/Factor/conditional-structures-2.factor b/Task/Conditional-structures/Factor/conditional-structures-2.factor
new file mode 100644
index 0000000000..564d30be9b
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-2.factor
@@ -0,0 +1 @@
+t [ 1 ] [ 2 ] if ! returns 1
diff --git a/Task/Conditional-structures/Factor/conditional-structures-3.factor b/Task/Conditional-structures/Factor/conditional-structures-3.factor
new file mode 100644
index 0000000000..21458db5d3
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-3.factor
@@ -0,0 +1 @@
+{ { [ t ] [ 1 ] } { [ f ] [ 2 ] } } cond ! returns 1
diff --git a/Task/Conditional-structures/Factor/conditional-structures-4.factor b/Task/Conditional-structures/Factor/conditional-structures-4.factor
new file mode 100644
index 0000000000..0fce3acbeb
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-4.factor
@@ -0,0 +1 @@
+t { { t [ 1 ] } { f [ 2 ] } } case ! returns 1
diff --git a/Task/Conditional-structures/Factor/conditional-structures-5.factor b/Task/Conditional-structures/Factor/conditional-structures-5.factor
new file mode 100644
index 0000000000..06e0135053
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-5.factor
@@ -0,0 +1 @@
+t [ "1" print ] when ! prints 1
diff --git a/Task/Conditional-structures/Factor/conditional-structures-6.factor b/Task/Conditional-structures/Factor/conditional-structures-6.factor
new file mode 100644
index 0000000000..85c52f6ccb
--- /dev/null
+++ b/Task/Conditional-structures/Factor/conditional-structures-6.factor
@@ -0,0 +1 @@
+f [ "1" print ] unless ! prints 1
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-1.fancy b/Task/Conditional-structures/Fancy/conditional-structures-1.fancy
new file mode 100644
index 0000000000..c07dfc1d99
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-1.fancy
@@ -0,0 +1,3 @@
+if: (x < y) then: {
+ "x < y!" println # will only execute this block if x < y
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-2.fancy b/Task/Conditional-structures/Fancy/conditional-structures-2.fancy
new file mode 100644
index 0000000000..07119e65e7
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-2.fancy
@@ -0,0 +1,5 @@
+if: (x < y) then: {
+ "x < y!" println # will only execute this block if x < y
+} else: {
+ "x not < y!" println
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-3.fancy b/Task/Conditional-structures/Fancy/conditional-structures-3.fancy
new file mode 100644
index 0000000000..6318f88735
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-3.fancy
@@ -0,0 +1,3 @@
+x < y if_true: {
+ "x < y!" println # will only execute this block if x < y
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-4.fancy b/Task/Conditional-structures/Fancy/conditional-structures-4.fancy
new file mode 100644
index 0000000000..c7f5934db8
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-4.fancy
@@ -0,0 +1,3 @@
+x < y if_false: {
+ "x not < y!" println # will only execute this block if x >= y
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-5.fancy b/Task/Conditional-structures/Fancy/conditional-structures-5.fancy
new file mode 100644
index 0000000000..b35da98721
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-5.fancy
@@ -0,0 +1,5 @@
+x < y if_true: {
+ "x < y!" println
+} else: {
+ "x >= y!" println
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-6.fancy b/Task/Conditional-structures/Fancy/conditional-structures-6.fancy
new file mode 100644
index 0000000000..0e5adc6243
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-6.fancy
@@ -0,0 +1,5 @@
+x < y if_false: {
+ "x >= y!"
+} else: {
+ "x < y!" println
+}
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-7.fancy b/Task/Conditional-structures/Fancy/conditional-structures-7.fancy
new file mode 100644
index 0000000000..0a73f64e57
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-7.fancy
@@ -0,0 +1 @@
+{ "x < y!" println } if: (x < y) # analog, but postfix
diff --git a/Task/Conditional-structures/Fancy/conditional-structures-8.fancy b/Task/Conditional-structures/Fancy/conditional-structures-8.fancy
new file mode 100644
index 0000000000..47812cef28
--- /dev/null
+++ b/Task/Conditional-structures/Fancy/conditional-structures-8.fancy
@@ -0,0 +1 @@
+{ "x not < y!" } unless: (x < y) # same here
diff --git a/Task/Conditional-structures/HicEst/conditional-structures.hicest b/Task/Conditional-structures/HicEst/conditional-structures.hicest
new file mode 100644
index 0000000000..10cee02518
--- /dev/null
+++ b/Task/Conditional-structures/HicEst/conditional-structures.hicest
@@ -0,0 +1,11 @@
+IF( a > 5 ) WRITE(Messagebox) a ! single line IF
+
+IF( a >= b ) THEN
+ WRITE(Text=some_string) a, b
+ ELSEIF(some_string > "?") THEN
+ WRITE(ClipBoard) some_string
+ ELSEIF( nonzero ) THEN
+ WRITE(WINdowhandle=nnn) some_string
+ ELSE
+ WRITE(StatusBar) a, b, some_string
+ENDIF
diff --git a/Task/Conditional-structures/IDL/conditional-structures-1.idl b/Task/Conditional-structures/IDL/conditional-structures-1.idl
new file mode 100644
index 0000000000..0bd89278e3
--- /dev/null
+++ b/Task/Conditional-structures/IDL/conditional-structures-1.idl
@@ -0,0 +1 @@
+if a eq 5 then print, "a equals five" [else print, "a is something else"]
diff --git a/Task/Conditional-structures/IDL/conditional-structures-2.idl b/Task/Conditional-structures/IDL/conditional-structures-2.idl
new file mode 100644
index 0000000000..e9ecd5df39
--- /dev/null
+++ b/Task/Conditional-structures/IDL/conditional-structures-2.idl
@@ -0,0 +1,5 @@
+if a eq 5 then begin
+ ... some code here ...
+endif [else begin
+ ... some other code here ...
+endelse]
diff --git a/Task/Conditional-structures/IDL/conditional-structures-3.idl b/Task/Conditional-structures/IDL/conditional-structures-3.idl
new file mode 100644
index 0000000000..176ddc885c
--- /dev/null
+++ b/Task/Conditional-structures/IDL/conditional-structures-3.idl
@@ -0,0 +1,5 @@
+case of
+ (choice-1):
+ [(choice-2): [...]]
+ [else: ]
+endcase
diff --git a/Task/Conditional-structures/IDL/conditional-structures-4.idl b/Task/Conditional-structures/IDL/conditional-structures-4.idl
new file mode 100644
index 0000000000..4b8fff707c
--- /dev/null
+++ b/Task/Conditional-structures/IDL/conditional-structures-4.idl
@@ -0,0 +1,5 @@
+switch of
+ (choice-1):
+ [(choice-2): [...]]
+ [else: ]
+endswitch
diff --git a/Task/Conditional-structures/IDL/conditional-structures-5.idl b/Task/Conditional-structures/IDL/conditional-structures-5.idl
new file mode 100644
index 0000000000..ee8d192d30
--- /dev/null
+++ b/Task/Conditional-structures/IDL/conditional-structures-5.idl
@@ -0,0 +1 @@
+on_error label
diff --git a/Task/Conditional-structures/Icon/conditional-structures-1.icon b/Task/Conditional-structures/Icon/conditional-structures-1.icon
new file mode 100644
index 0000000000..315bcb979e
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-1.icon
@@ -0,0 +1,4 @@
+if expr0 then
+ expr1
+else
+ expr2
diff --git a/Task/Conditional-structures/Icon/conditional-structures-10.icon b/Task/Conditional-structures/Icon/conditional-structures-10.icon
new file mode 100644
index 0000000000..61444d632d
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-10.icon
@@ -0,0 +1 @@
+ expr0(expr1, expr2, expr3)
diff --git a/Task/Conditional-structures/Icon/conditional-structures-11.icon b/Task/Conditional-structures/Icon/conditional-structures-11.icon
new file mode 100644
index 0000000000..810018e83a
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-11.icon
@@ -0,0 +1 @@
+ 2(expr1, expr2, expr3)
diff --git a/Task/Conditional-structures/Icon/conditional-structures-12.icon b/Task/Conditional-structures/Icon/conditional-structures-12.icon
new file mode 100644
index 0000000000..2fc23cf8e7
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-12.icon
@@ -0,0 +1 @@
+ f(expr1)(g(expr2)(expr3,expr4,expr5))
diff --git a/Task/Conditional-structures/Icon/conditional-structures-2.icon b/Task/Conditional-structures/Icon/conditional-structures-2.icon
new file mode 100644
index 0000000000..661c8793c1
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-2.icon
@@ -0,0 +1,5 @@
+case expr0 of {
+ expr1 : expr2
+ expr3 : expr4
+ default: expr5
+ }
diff --git a/Task/Conditional-structures/Icon/conditional-structures-3.icon b/Task/Conditional-structures/Icon/conditional-structures-3.icon
new file mode 100644
index 0000000000..9776f687f8
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-3.icon
@@ -0,0 +1,5 @@
+case x of {
+ f(x) | g(x) : expr2
+ s(x) & t(x) : expr4
+ default: expr5
+ }
diff --git a/Task/Conditional-structures/Icon/conditional-structures-4.icon b/Task/Conditional-structures/Icon/conditional-structures-4.icon
new file mode 100644
index 0000000000..18e721e477
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-4.icon
@@ -0,0 +1,5 @@
+{
+ expr1
+ expr2
+ expr3
+}
diff --git a/Task/Conditional-structures/Icon/conditional-structures-5.icon b/Task/Conditional-structures/Icon/conditional-structures-5.icon
new file mode 100644
index 0000000000..b4c390a9a6
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-5.icon
@@ -0,0 +1 @@
+{expr1; expr2; expr3}
diff --git a/Task/Conditional-structures/Icon/conditional-structures-6.icon b/Task/Conditional-structures/Icon/conditional-structures-6.icon
new file mode 100644
index 0000000000..48ec3fa570
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-6.icon
@@ -0,0 +1 @@
+write({1;2;3;4})
diff --git a/Task/Conditional-structures/Icon/conditional-structures-7.icon b/Task/Conditional-structures/Icon/conditional-structures-7.icon
new file mode 100644
index 0000000000..78c9c1c07b
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-7.icon
@@ -0,0 +1 @@
+ expr1 | expr2 | expr3
diff --git a/Task/Conditional-structures/Icon/conditional-structures-8.icon b/Task/Conditional-structures/Icon/conditional-structures-8.icon
new file mode 100644
index 0000000000..011a38eddc
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-8.icon
@@ -0,0 +1 @@
+ expr1 & expr2 & expr3
diff --git a/Task/Conditional-structures/Icon/conditional-structures-9.icon b/Task/Conditional-structures/Icon/conditional-structures-9.icon
new file mode 100644
index 0000000000..8944919ea0
--- /dev/null
+++ b/Task/Conditional-structures/Icon/conditional-structures-9.icon
@@ -0,0 +1 @@
+ (expr1, expr2, expr3)
diff --git a/Task/Conditional-structures/Inform-7/conditional-structures-1.inf b/Task/Conditional-structures/Inform-7/conditional-structures-1.inf
new file mode 100644
index 0000000000..5534bef94b
--- /dev/null
+++ b/Task/Conditional-structures/Inform-7/conditional-structures-1.inf
@@ -0,0 +1,14 @@
+[short form]
+if N is 1, say "one.";
+otherwise say "not one.";
+
+[block form]
+if N is 1:
+ say "one.";
+otherwise if N is 2:
+ say "two.";
+otherwise:
+ say "not one or two.";
+
+[short and long forms can be negated with "unless"]
+unless N is 1, say "not one."
diff --git a/Task/Conditional-structures/Inform-7/conditional-structures-2.inf b/Task/Conditional-structures/Inform-7/conditional-structures-2.inf
new file mode 100644
index 0000000000..5c4a292551
--- /dev/null
+++ b/Task/Conditional-structures/Inform-7/conditional-structures-2.inf
@@ -0,0 +1,4 @@
+if N is:
+ -- 1: say "one.";
+ -- 2: say "two.";
+ -- otherwise: say "not one or two.";
diff --git a/Task/Conditional-structures/Inform-7/conditional-structures-3.inf b/Task/Conditional-structures/Inform-7/conditional-structures-3.inf
new file mode 100644
index 0000000000..230658b62e
--- /dev/null
+++ b/Task/Conditional-structures/Inform-7/conditional-structures-3.inf
@@ -0,0 +1,2 @@
+say "[if N is 1]one[otherwise if N is 2]two[otherwise]three[end if].";
+say "[unless N is odd]even.[end if]";
diff --git a/Task/Conditional-structures/Inform-7/conditional-structures-4.inf b/Task/Conditional-structures/Inform-7/conditional-structures-4.inf
new file mode 100644
index 0000000000..e99c08e692
--- /dev/null
+++ b/Task/Conditional-structures/Inform-7/conditional-structures-4.inf
@@ -0,0 +1,8 @@
+[a different color every time]
+say "[one of]red[or]blue[or]green[at random].";
+
+["one" the first time it's printed, "two" the second time, then "three or more" subsequently]
+say "[one of]one[or]two[or]three or more[stopping]";
+
+[only appears once]
+say "[first time]Hello world![only]";
diff --git a/Task/Conditional-structures/Inform-7/conditional-structures-5.inf b/Task/Conditional-structures/Inform-7/conditional-structures-5.inf
new file mode 100644
index 0000000000..4fdba2cbba
--- /dev/null
+++ b/Task/Conditional-structures/Inform-7/conditional-structures-5.inf
@@ -0,0 +1,13 @@
+Number Factory is a room.
+
+Number handling is a number based rulebook with default success.
+
+Number handling for 1: say "one."
+Number handling for 2: say "two."
+Number handling for an even number (called N): say "[N in words] (which is even)."
+Last number handling rule: say "other."
+
+When play begins:
+ follow the number handling rules for 2;
+ follow the number handling rules for 4;
+ follow the number handling rules for 5.
diff --git a/Task/Conditional-structures/LSE64/conditional-structures-1.lse64 b/Task/Conditional-structures/LSE64/conditional-structures-1.lse64
new file mode 100644
index 0000000000..6c068be228
--- /dev/null
+++ b/Task/Conditional-structures/LSE64/conditional-structures-1.lse64
@@ -0,0 +1,5 @@
+t : " true" ,t
+f : " false" ,t
+true if t
+false ifnot f
+true ifelse t f
diff --git a/Task/Conditional-structures/LSE64/conditional-structures-2.lse64 b/Task/Conditional-structures/LSE64/conditional-structures-2.lse64
new file mode 100644
index 0000000000..351597e559
--- /dev/null
+++ b/Task/Conditional-structures/LSE64/conditional-structures-2.lse64
@@ -0,0 +1,3 @@
+onetwo : drop " Neither one nor two" ,t # default declared first
+onetwo : dup 2 = then " Two" ,t
+onetwo : dup 1 = then " One" ,t
diff --git a/Task/Conditional-structures/LSE64/conditional-structures-3.lse64 b/Task/Conditional-structures/LSE64/conditional-structures-3.lse64
new file mode 100644
index 0000000000..8dda5c5fb3
--- /dev/null
+++ b/Task/Conditional-structures/LSE64/conditional-structures-3.lse64
@@ -0,0 +1 @@
+dup 0 = || ,t # avoid printing a null string
diff --git a/Task/Conditional-structures/Lisaac/conditional-structures-1.lisaac b/Task/Conditional-structures/Lisaac/conditional-structures-1.lisaac
new file mode 100644
index 0000000000..cc53300c14
--- /dev/null
+++ b/Task/Conditional-structures/Lisaac/conditional-structures-1.lisaac
@@ -0,0 +1,13 @@
++ n : INTEGER;
+
+n := 3;
+
+(n = 2).if {
+ IO.put_string "n is 2\n";
+}.elseif {n = 3} then {
+ IO.put_string "n is 3\n";
+}.elseif {n = 4} then {
+ IO.put_string "n is 4\n";
+} else {
+ IO.put_string "n is none of the above\n";
+};
diff --git a/Task/Conditional-structures/Lisaac/conditional-structures-2.lisaac b/Task/Conditional-structures/Lisaac/conditional-structures-2.lisaac
new file mode 100644
index 0000000000..339f89d6b2
--- /dev/null
+++ b/Task/Conditional-structures/Lisaac/conditional-structures-2.lisaac
@@ -0,0 +1,2 @@
+(n = 2).if_true { "n is 2\n".print; };
+(n = 2).if_false { "n is not 2\n".print; };
diff --git a/Task/Conditional-structures/Lisaac/conditional-structures-3.lisaac b/Task/Conditional-structures/Lisaac/conditional-structures-3.lisaac
new file mode 100644
index 0000000000..777635fdd5
--- /dev/null
+++ b/Task/Conditional-structures/Lisaac/conditional-structures-3.lisaac
@@ -0,0 +1,13 @@
++ n : INTEGER;
+
+n := 3;
+n
+.when 2 then {
+ "n is 2\n".print;
+}
+.when 3 then {
+ "n is 3\n".print;
+}
+.when 4 then {
+ "n is 4\n".print;
+};
diff --git a/Task/Conditional-structures/Logo/conditional-structures-1.logo b/Task/Conditional-structures/Logo/conditional-structures-1.logo
new file mode 100644
index 0000000000..cb54ac95c8
--- /dev/null
+++ b/Task/Conditional-structures/Logo/conditional-structures-1.logo
@@ -0,0 +1,3 @@
+if :x < 0 [make "x 0 - :x]
+
+ifelse emptyp :list [print [empty]] [print :list]
diff --git a/Task/Conditional-structures/Logo/conditional-structures-2.logo b/Task/Conditional-structures/Logo/conditional-structures-2.logo
new file mode 100644
index 0000000000..f13f7cc664
--- /dev/null
+++ b/Task/Conditional-structures/Logo/conditional-structures-2.logo
@@ -0,0 +1,5 @@
+to vowel? :letter
+output case :letter [ [[a e i o u] "true] [else "false] ]
+end
+show vowel? "e
+show vowel? "x
diff --git a/Task/Conditional-structures/Logo/conditional-structures-3.logo b/Task/Conditional-structures/Logo/conditional-structures-3.logo
new file mode 100644
index 0000000000..da29283aaa
--- /dev/null
+++ b/Task/Conditional-structures/Logo/conditional-structures-3.logo
@@ -0,0 +1,2 @@
+true
+false
diff --git a/Task/Conditional-structures/Logo/conditional-structures-4.logo b/Task/Conditional-structures/Logo/conditional-structures-4.logo
new file mode 100644
index 0000000000..4c42abbf09
--- /dev/null
+++ b/Task/Conditional-structures/Logo/conditional-structures-4.logo
@@ -0,0 +1,5 @@
+to mytest :arg1 :arg2
+test :arg1 = :arg2
+iftrue [print [Arguments are equal]]
+iffalse [print [Arguments are not equal]]
+end
diff --git a/Task/Conditional-structures/MAXScript/conditional-structures-1.max b/Task/Conditional-structures/MAXScript/conditional-structures-1.max
new file mode 100644
index 0000000000..addf133ee6
--- /dev/null
+++ b/Task/Conditional-structures/MAXScript/conditional-structures-1.max
@@ -0,0 +1,12 @@
+if x == 1 then
+(
+ print "one"
+)
+else if x == 2 then
+(
+ print "two"
+)
+else
+(
+ print "Neither one or two"
+)
diff --git a/Task/Conditional-structures/MAXScript/conditional-structures-2.max b/Task/Conditional-structures/MAXScript/conditional-structures-2.max
new file mode 100644
index 0000000000..f3174ac975
--- /dev/null
+++ b/Task/Conditional-structures/MAXScript/conditional-structures-2.max
@@ -0,0 +1,6 @@
+case x of
+(
+ 1: (print "one")
+ 2: (print "two")
+ default: (print "Neither one or two")
+)
diff --git a/Task/Conditional-structures/MAXScript/conditional-structures-3.max b/Task/Conditional-structures/MAXScript/conditional-structures-3.max
new file mode 100644
index 0000000000..f3610e1c47
--- /dev/null
+++ b/Task/Conditional-structures/MAXScript/conditional-structures-3.max
@@ -0,0 +1,6 @@
+case of
+(
+ (x == 1): (print "one")
+ (x == 2): (print "two")
+ default: (print "Neither one or two")
+)
diff --git a/Task/Conditional-structures/MBS/conditional-structures.mbs b/Task/Conditional-structures/MBS/conditional-structures.mbs
new file mode 100644
index 0000000000..e25ebe33ca
--- /dev/null
+++ b/Task/Conditional-structures/MBS/conditional-structures.mbs
@@ -0,0 +1,7 @@
+INT x;
+x:=0;
+IF x = 1 THEN
+ ! Do something
+ELSE
+ ! Do something else
+ENDIF;
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-1.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-1.mumps
new file mode 100644
index 0000000000..e773cd1eac
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-1.mumps
@@ -0,0 +1 @@
+ IF A list-of-MUMPS-commands
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-2.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-2.mumps
new file mode 100644
index 0000000000..7b43c98cb7
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-2.mumps
@@ -0,0 +1,2 @@
+ IF T DO SUBROUTINE
+ ELSE DO SOMETHING
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-3.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-3.mumps
new file mode 100644
index 0000000000..dfec47cce2
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-3.mumps
@@ -0,0 +1,2 @@
+ IF T DO SUBROUTINE IF 1
+ ELSE DO SOMETHING
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-4.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-4.mumps
new file mode 100644
index 0000000000..3b345928a0
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-4.mumps
@@ -0,0 +1,3 @@
+ IF T DO
+ . DO SUBROUTINE
+ ELSE DO SOMETHING
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-5.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-5.mumps
new file mode 100644
index 0000000000..ce4aa1594a
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-5.mumps
@@ -0,0 +1 @@
+ WRITE $SELECT(1=2:"Unequal",1=3:"More unequal",1:"Who cares?")
diff --git a/Task/Conditional-structures/MUMPS/conditional-structures-6.mumps b/Task/Conditional-structures/MUMPS/conditional-structures-6.mumps
new file mode 100644
index 0000000000..c662ea395c
--- /dev/null
+++ b/Task/Conditional-structures/MUMPS/conditional-structures-6.mumps
@@ -0,0 +1,4 @@
+ SET:(1=1) SKY="Blue"
+ GOTO:ReallyGo LABEL
+ QUIT:LoopDone
+ WRITE:NotLastInSet ","
diff --git a/Task/Conditional-structures/Make/conditional-structures-1.make b/Task/Conditional-structures/Make/conditional-structures-1.make
new file mode 100644
index 0000000000..84ab06a32c
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-1.make
@@ -0,0 +1,12 @@
+# make -f do.mk C=mycond if
+C=0
+
+if:
+ -@expr $(C) >/dev/null && make -f do.mk true; exit 0
+ -@expr $(C) >/dev/null || make -f do.mk false; exit 0
+
+true:
+ @echo "was true."
+
+false:
+ @echo "was false."
diff --git a/Task/Conditional-structures/Make/conditional-structures-2.make b/Task/Conditional-structures/Make/conditional-structures-2.make
new file mode 100644
index 0000000000..57e6462eed
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-2.make
@@ -0,0 +1,5 @@
+make -f do.mk if C=0
+> was false.
+
+make -f do.mk if C=1
+> was true.
diff --git a/Task/Conditional-structures/Make/conditional-structures-3.make b/Task/Conditional-structures/Make/conditional-structures-3.make
new file mode 100644
index 0000000000..e87b3afb66
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-3.make
@@ -0,0 +1,11 @@
+C=0
+
+if: true false
+
+true:
+ @expr $(C) >/dev/null && exit 0 || exit 1
+ @echo "was true."
+
+false:
+ @expr $(C) >/dev/null && exit 1 || exit 0
+ @echo "was false."
diff --git a/Task/Conditional-structures/Make/conditional-structures-4.make b/Task/Conditional-structures/Make/conditional-structures-4.make
new file mode 100644
index 0000000000..d87192fa9d
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-4.make
@@ -0,0 +1,6 @@
+|make -f do.mk -s -k C=1
+was true.
+*** Error code 1
+|make -f do.mk -s -k C=0
+*** Error code 1
+was false.
diff --git a/Task/Conditional-structures/Make/conditional-structures-5.make b/Task/Conditional-structures/Make/conditional-structures-5.make
new file mode 100644
index 0000000000..ad82c600a1
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-5.make
@@ -0,0 +1,11 @@
+A=
+B=
+
+ifeq "$(A)" "1"
+ B=true
+else
+ B=false
+endif
+
+do:
+ @echo $(A) .. $(B)
diff --git a/Task/Conditional-structures/Make/conditional-structures-6.make b/Task/Conditional-structures/Make/conditional-structures-6.make
new file mode 100644
index 0000000000..95fcb38128
--- /dev/null
+++ b/Task/Conditional-structures/Make/conditional-structures-6.make
@@ -0,0 +1,4 @@
+|gmake -f if.mk A=1
+1 .. true
+|gmake -f if.mk A=0
+0 .. false
diff --git a/Task/Conditional-structures/Maxima/conditional-structures.maxima b/Task/Conditional-structures/Maxima/conditional-structures.maxima
new file mode 100644
index 0000000000..9339f42b8d
--- /dev/null
+++ b/Task/Conditional-structures/Maxima/conditional-structures.maxima
@@ -0,0 +1 @@
+if test1 then (...) elseif test2 then (...) else (...);
diff --git a/Task/Conditional-structures/Metafont/conditional-structures-1.metafont b/Task/Conditional-structures/Metafont/conditional-structures-1.metafont
new file mode 100644
index 0000000000..5a4c8079b9
--- /dev/null
+++ b/Task/Conditional-structures/Metafont/conditional-structures-1.metafont
@@ -0,0 +1,8 @@
+if conditionA:
+ % do something
+elseif conditionB:
+ % do something
+% more elseif, if needed...
+else:
+ % do this
+fi;
diff --git a/Task/Conditional-structures/Metafont/conditional-structures-2.metafont b/Task/Conditional-structures/Metafont/conditional-structures-2.metafont
new file mode 100644
index 0000000000..f9ef001fa7
--- /dev/null
+++ b/Task/Conditional-structures/Metafont/conditional-structures-2.metafont
@@ -0,0 +1 @@
+b := if a > 5: 3 + else: 2 - fi c;
diff --git a/Task/Conditional-structures/Modula-2/conditional-structures-1.mod2 b/Task/Conditional-structures/Modula-2/conditional-structures-1.mod2
new file mode 100644
index 0000000000..5b65096d0c
--- /dev/null
+++ b/Task/Conditional-structures/Modula-2/conditional-structures-1.mod2
@@ -0,0 +1,9 @@
+IF i = 1 THEN
+ InOut.WriteString('One')
+ELSIF i = 2 THEN
+ InOut.WriteString('Two')
+ELSIF i = 3 THEN
+ InOut.WriteString('Three')
+ELSE
+ InOut.WriteString('Other')
+END;
diff --git a/Task/Conditional-structures/Modula-2/conditional-structures-2.mod2 b/Task/Conditional-structures/Modula-2/conditional-structures-2.mod2
new file mode 100644
index 0000000000..349089c2d1
--- /dev/null
+++ b/Task/Conditional-structures/Modula-2/conditional-structures-2.mod2
@@ -0,0 +1,7 @@
+CASE i OF
+ 1 : InOut.WriteString('One')
+| 2 : InOut.WriteString('Two')
+| 3 : InOut.WriteString('Three')
+ELSE
+ InOut.WriteString('Other')
+END
diff --git a/Task/Conditional-structures/Modula-3/conditional-structures-1.mod3 b/Task/Conditional-structures/Modula-3/conditional-structures-1.mod3
new file mode 100644
index 0000000000..7bf15e2981
--- /dev/null
+++ b/Task/Conditional-structures/Modula-3/conditional-structures-1.mod3
@@ -0,0 +1,5 @@
+IF Foo = TRUE THEN
+ Bar();
+ELSE
+ Baz();
+END;
diff --git a/Task/Conditional-structures/Modula-3/conditional-structures-2.mod3 b/Task/Conditional-structures/Modula-3/conditional-structures-2.mod3
new file mode 100644
index 0000000000..8e3101b0d5
--- /dev/null
+++ b/Task/Conditional-structures/Modula-3/conditional-structures-2.mod3
@@ -0,0 +1,9 @@
+IF Foo = "foo" THEN
+ Bar();
+ELSIF Foo = "bar" THEN
+ Baz();
+ELSIF Foo = "foobar" THEN
+ Quux();
+ELSE
+ Zeepf();
+END;
diff --git a/Task/Conditional-structures/Modula-3/conditional-structures-3.mod3 b/Task/Conditional-structures/Modula-3/conditional-structures-3.mod3
new file mode 100644
index 0000000000..b7aa81e036
--- /dev/null
+++ b/Task/Conditional-structures/Modula-3/conditional-structures-3.mod3
@@ -0,0 +1,7 @@
+CASE Foo OF
+| 1 => IO.Put("One\n");
+| 2 => IO.Put("Two\n");
+| 3 => IO.Put("Three\n");
+ELSE
+ IO.Put("Something\n");
+END;
diff --git a/Task/Conditional-structures/Modula-3/conditional-structures-4.mod3 b/Task/Conditional-structures/Modula-3/conditional-structures-4.mod3
new file mode 100644
index 0000000000..07ccee8771
--- /dev/null
+++ b/Task/Conditional-structures/Modula-3/conditional-structures-4.mod3
@@ -0,0 +1,7 @@
+TYPECASE ref OF
+| NULL => IO.Put("Null\n");
+| CHAR => IO.Put("Char\n");
+| INTEGER => IO.Put("Integer\n");
+ELSE
+ IO.Put("Something\n");
+END;
diff --git a/Task/Constrained-genericity/J/constrained-genericity-1.j b/Task/Constrained-genericity/J/constrained-genericity-1.j
new file mode 100644
index 0000000000..f9dd1babe2
--- /dev/null
+++ b/Task/Constrained-genericity/J/constrained-genericity-1.j
@@ -0,0 +1,14 @@
+coclass'Connoisseur'
+isEdible=:3 :0
+ 0 outside then inside :=: outside
+
+wsize := integer(2.2*outside)
+wsize <:= 150
+center := wsize/2
+
+WOpen("size="||wsize||","||wsize,"bg=black","fg=white") | stop("Unable to open window")
+
+until(points -:= 1) <= 0 do {
+ x := ?(2*outside)-outside # random x
+ y := ?(2*outside)-outside # and y
+ if (inside <= integer(sqrt(x^2+y^2)) ) <= outside then
+ DrawPoint(x + center,y + center)
+ }
+WDone()
+
+end
diff --git a/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-1.j b/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-1.j
new file mode 100644
index 0000000000..f37293aa98
--- /dev/null
+++ b/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-1.j
@@ -0,0 +1 @@
+gen=: ({~ 100?#)bind((#~ 1=99 225 I.+/"1@:*:),/,"0/~i:15)
diff --git a/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-2.j b/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-2.j
new file mode 100644
index 0000000000..e3389b53b8
--- /dev/null
+++ b/Task/Constrained-random-points-on-a-circle/J/constrained-random-points-on-a-circle-2.j
@@ -0,0 +1,31 @@
+ '*' (<"1]15+gen '')} 31 31$' '
+
+ *
+ *
+ * * * * * *
+ * * * * *
+ * ***
+ ** * * **
+ * **
+ * **
+ * * * *
+ * * **
+ * ** **
+ ** * ***
+ * ** * *
+ ** *
+ * ** *
+ ** *
+ * ** *
+ * *
+ * *
+ * *
+ ** *
+ * **
+ *
+ * * * *
+ * ** * * *
+ * *
+ **
+ * * *
+ ** *
diff --git a/Task/Constrained-random-points-on-a-circle/Liberty-BASIC/constrained-random-points-on-a-circle.liberty b/Task/Constrained-random-points-on-a-circle/Liberty-BASIC/constrained-random-points-on-a-circle.liberty
new file mode 100644
index 0000000000..333018c9f3
--- /dev/null
+++ b/Task/Constrained-random-points-on-a-circle/Liberty-BASIC/constrained-random-points-on-a-circle.liberty
@@ -0,0 +1,30 @@
+' RC Constrained Random Points on a Circle
+
+nomainwin
+
+WindowWidth =400
+WindowHeight =430
+
+open "Constrained Random Points on a Circle" for graphics_nsb as #w
+
+#w "trapclose [quit]"
+#w "down ; size 7 ; color red ; fill black"
+
+for i =1 to 1000
+ do
+ x =int( 30 *rnd( 1)) -15
+ y =int( 30 *rnd( 1)) -15
+ loop until IsInRange( x, y) =1
+ #w "set "; 200 +10 *x; " "; 200 - 10 *y
+next
+
+wait
+
+function IsInRange( x, y)
+ z =sqr( x*x +y*y)
+ if 10 <=z and z <=15 then IsInRange =1 else IsInRange =0
+end function
+
+[quit]
+close #w
+end
diff --git a/Task/Constrained-random-points-on-a-circle/Locomotive-Basic/constrained-random-points-on-a-circle.bas b/Task/Constrained-random-points-on-a-circle/Locomotive-Basic/constrained-random-points-on-a-circle.bas
new file mode 100644
index 0000000000..7482071e6d
--- /dev/null
+++ b/Task/Constrained-random-points-on-a-circle/Locomotive-Basic/constrained-random-points-on-a-circle.bas
@@ -0,0 +1,9 @@
+10 MODE 1:RANDOMIZE TIME
+20 FOR J=1 TO 100
+30 X=INT(RND*30-15)
+40 Y=INT(RND*30-15)
+50 D=X*X+Y*Y
+60 IF D<100 OR D>225 THEN GOTO 40
+70 PLOT 320+10*X,200+10*Y:LOCATE 1,1:PRINT J
+80 NEXT
+90 CALL &BB06 ' wait for key press
diff --git a/Task/Constrained-random-points-on-a-circle/Mathematica/constrained-random-points-on-a-circle.mathematica b/Task/Constrained-random-points-on-a-circle/Mathematica/constrained-random-points-on-a-circle.mathematica
new file mode 100644
index 0000000000..0155b4fe6b
--- /dev/null
+++ b/Task/Constrained-random-points-on-a-circle/Mathematica/constrained-random-points-on-a-circle.mathematica
@@ -0,0 +1,3 @@
+sample = Take[Cases[RandomInteger[{-15, 15}, {500, 2}], {x_, y_} /; 10 <= Sqrt[x^2 + y^2] <= 15], 100];
+
+Show[{RegionPlot[10 <= Sqrt[x^2 + y^2] <= 15, {x, -16, 16}, {y, -16, 16}, Axes -> True], ListPlot[sample]}]
diff --git a/Task/Continued-fraction-Arithmetic-Construct-from-rational-number/Mathematica/continued-fraction-arithmetic-construct-from-rational-number.mathematica b/Task/Continued-fraction-Arithmetic-Construct-from-rational-number/Mathematica/continued-fraction-arithmetic-construct-from-rational-number.mathematica
new file mode 100644
index 0000000000..1db019587a
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-Construct-from-rational-number/Mathematica/continued-fraction-arithmetic-construct-from-rational-number.mathematica
@@ -0,0 +1,10 @@
+ContinuedFraction[1/2]
+ContinuedFraction[3]
+ContinuedFraction[23/8]
+ContinuedFraction[13/11]
+ContinuedFraction[22/7]
+ContinuedFraction[-151/77]
+ContinuedFraction[14142/10000]
+ContinuedFraction[141421/100000]
+ContinuedFraction[1414214/1000000]
+ContinuedFraction[14142136/10000000]
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/0DESCRIPTION b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/0DESCRIPTION
new file mode 100644
index 0000000000..b340488f7a
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/0DESCRIPTION
@@ -0,0 +1,41 @@
+This task investigates mathmatical operations that can be performed on a single continued fraction. This requires only a baby version of NG:
+:
+I may perform perform the following operations:
+:Input the next term of N1
+:Output a term of the continued fraction resulting from the operation.
+
+I output a term if the integer parts of and are equal. Otherwise I input a term from N. If I need a term from N but N has no more terms I inject .
+
+When I input a term t my internal state: is transposed thus
+
+When I output a term t my internal state: is transposed thus
+
+When I need a term t but there are no more my internal state: is transposed thus
+
+I am done when b1 and b are zero.
+
+Demonstrate your solution by calculating:
+:[1;5,2] + 1/2
+:[3;7] + 1/2
+:[3;7] divided by 4
+Using a generator for (e.g., from [[Continued fraction]]) calculate . You are now at the starting line for using Continued Fractions to implement [[Arithmetic-geometric mean]] without ulps and epsilons.
+
+The first step in implementing [[Arithmetic-geometric mean]] is to calculate do this now to cross the starting line and begin the race.
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.cpp
new file mode 100644
index 0000000000..959b0d4a00
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.cpp
@@ -0,0 +1,48 @@
+/* Interface for all matrixNG classes
+ Nigel Galloway, February 10th., 2013.
+*/
+class matrixNG {
+ private:
+ virtual void consumeTerm(){}
+ virtual void consumeTerm(int n){}
+ virtual const bool needTerm(){}
+ protected: int cfn = 0, thisTerm;
+ bool haveTerm = false;
+ friend class NG;
+};
+/* Implement the babyNG matrix
+ Nigel Galloway, February 10th., 2013.
+*/
+class NG_4 : public matrixNG {
+ private: int a1, a, b1, b, t;
+ const bool needTerm() {
+ if (b1==0 and b==0) return false;
+ if (b1==0 or b==0) return true; else thisTerm = a/b;
+ if (thisTerm==(int)(a1/b1)){
+ t=a; a=b; b=t-b*thisTerm; t=a1; a1=b1; b1=t-b1*thisTerm;
+ haveTerm=true; return false;
+ }
+ return true;
+ }
+ void consumeTerm(){a=a1; b=b1;}
+ void consumeTerm(int n){t=a; a=a1; a1=t+a1*n; t=b; b=b1; b1=t+b1*n;}
+ public:
+ NG_4(int a1, int a, int b1, int b): a1(a1), a(a), b1(b1), b(b){}
+};
+/* Implement a Continued Fraction which returns the result of an arithmetic operation on
+ 1 or more Continued Fractions (Currently 1 or 2).
+ Nigel Galloway, February 10th., 2013.
+*/
+class NG : public ContinuedFraction {
+ private:
+ matrixNG* ng;
+ ContinuedFraction* n[2];
+ public:
+ NG(NG_4* ng, ContinuedFraction* n1): ng(ng){n[0] = n1;}
+ NG(NG_8* ng, ContinuedFraction* n1, ContinuedFraction* n2): ng(ng){n[0] = n1; n[1] = n2;}
+ const int nextTerm() {ng->haveTerm = false; return ng->thisTerm;}
+ const bool moreTerms(){
+ while(ng->needTerm()) if(n[ng->cfn]->moreTerms()) ng->consumeTerm(n[ng->cfn]->nextTerm()); else ng->consumeTerm();
+ return ng->haveTerm;
+ }
+};
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.cpp
new file mode 100644
index 0000000000..92efe9aad1
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.cpp
@@ -0,0 +1,7 @@
+int main() {
+ NG_4 a1(2,1,0,2);
+ r2cf n1(13,11);
+ for(NG n(&a1, &n1); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.cpp
new file mode 100644
index 0000000000..a61cbb03ee
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.cpp
@@ -0,0 +1,7 @@
+int main() {
+ NG_4 a2(7,0,0,22);
+ r2cf n2(22,7);
+ for(NG n(&a2, &n2); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.cpp
new file mode 100644
index 0000000000..7fdd5c4895
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.cpp
@@ -0,0 +1,7 @@
+int main() {
+ NG_4 a3(2,1,0,2);
+ r2cf n3(22,7);
+ for(NG n(&a3, &n3); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-5.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-5.cpp
new file mode 100644
index 0000000000..2bbf9f7773
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-5.cpp
@@ -0,0 +1,7 @@
+int main() {
+ NG_4 a4(1,0,0,4);
+ r2cf n4(22,7);
+ for(NG n(&a4, &n4); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-6.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-6.cpp
new file mode 100644
index 0000000000..5db15ac3c3
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-6.cpp
@@ -0,0 +1,10 @@
+int main() {
+ NG_4 a5(0,1,1,0);
+ SQRT2 n5;
+ int i = 0;
+ for(NG n(&a5, &n5); n.moreTerms() and i++ < 20; std::cout << n.nextTerm() << " ");
+ std::cout << "..." << std::endl;
+ for(r2cf cf(10000000, 14142136); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-7.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-7.cpp
new file mode 100644
index 0000000000..142d7f771d
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-7.cpp
@@ -0,0 +1,10 @@
+int main() {
+ int i = 0;
+ NG_4 a6(1,1,0,2);
+ SQRT2 n6;
+ for(NG n(&a6, &n6); n.moreTerms() and i++ < 20; std::cout << n.nextTerm() << " ");
+ std::cout << "..." << std::endl;
+ for(r2cf cf(24142136, 20000000); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.rb b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.rb
new file mode 100644
index 0000000000..eb2389dc7c
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.rb
@@ -0,0 +1,29 @@
+=begin
+ I define a class to implement baby NG
+ Nigel Galloway February 6th., 2013
+=end
+class NG
+ def initialize(a1, a, b1, b)
+ @a1 = a1; @a = a; @b1 = b1; @b = b;
+ end
+ def ingress(n)
+ t=@a; @a=@a1; @a1=t + @a1 * n; t=@b; @b=@b1; @b1=t + @b1 * n;
+ end
+ def needterm?
+ return true if @b1 == 0 or @b == 0
+ return true unless @a/@b == @a1/@b1
+ return false
+ end
+ def egress
+ n = @a/@b
+ t=@a; @a=@b; @b=t - @b * n; t=@a1; @a1=@b1; @b1=t - @b1 * n;
+ return n
+ end
+ def egress_done
+ if needterm? then @a=@a1; @b=@b1 end
+ return egress
+ end
+ def done?
+ if @b1 == 0 and @b == 0 then return true else return false end
+ end
+end
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.rb b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.rb
new file mode 100644
index 0000000000..6c93599a81
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.rb
@@ -0,0 +1,3 @@
+op = NG.new(2,1,0,2)
+r2cf(13,11) {|n| if op.needterm? then op.ingress(n) else print "#{op.egress} "; op.ingress(n) end}
+while not op.done? do print "#{op.egress_done} " end
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.rb b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.rb
new file mode 100644
index 0000000000..24ac7eb6c5
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-3.rb
@@ -0,0 +1,3 @@
+op = NG.new(2,1,0,2)
+r2cf(22,7) {|n| if op.needterm? then op.ingress(n) else print "#{op.egress} "; op.ingress(n) end}
+while not op.done? do print "#{op.egress_done} " end
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.rb b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.rb
new file mode 100644
index 0000000000..c6556761ea
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Ruby/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-4.rb
@@ -0,0 +1,3 @@
+op = NG.new(1,0,0,4)
+r2cf(22,7) {|n| if op.needterm? then op.ingress(n) else print "#{op.egress} "; op.ingress(n) end}
+while not op.done? do print "#{op.egress_done} " end
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.tcl b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.tcl
new file mode 100644
index 0000000000..472d3b0ded
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-1.tcl
@@ -0,0 +1,50 @@
+# The single-operand version of the NG operator, using our little generator framework
+oo::class create NG1 {
+ superclass Generator
+
+ variable a1 a b1 b cf
+ constructor args {
+ next
+ lassign $args a1 a b1 b
+ }
+ method Ingress n {
+ lassign [list [expr {$a + $a1*$n}] $a1 [expr {$b + $b1*$n}] $b1] \
+ a1 a b1 b
+ }
+ method NeedTerm? {} {
+ expr {$b1 == 0 || $b == 0 || $a/$b != $a1/$b1}
+ }
+ method Egress {} {
+ set n [expr {$a/$b}]
+ lassign [list $b1 $b [expr {$a1 - $b1*$n}] [expr {$a - $b*$n}]] \
+ a1 a b1 b
+ return $n
+ }
+ method EgressDone {} {
+ if {[my NeedTerm?]} {
+ set a $a1
+ set b $b1
+ }
+ tailcall my Egress
+ }
+ method Done? {} {
+ expr {$b1 == 0 && $b == 0}
+ }
+
+ method operand {N} {
+ set cf $N
+ return [self]
+ }
+ method Produce {} {
+ while 1 {
+ set n [$cf]
+ if {![my NeedTerm?]} {
+ yield [my Egress]
+ }
+ my Ingress $n
+ }
+ while {![my Done?]} {
+ yield [my EgressDone]
+ }
+ }
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.tcl b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.tcl
new file mode 100644
index 0000000000..966e9d0ec7
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n-2.tcl
@@ -0,0 +1,29 @@
+# The square root of 2 as a continued fraction in the framework
+oo::class create Root2 {
+ superclass Generator
+ method apply {} {
+ yield 1
+ while {[self] ne ""} {
+ yield 2
+ }
+ }
+}
+
+set op [[NG1 new 2 1 0 2] operand [R2CF new 13/11]]
+printcf "\[1;5,2\] + 1/2" $op
+
+set op [[NG1 new 7 0 0 22] operand [R2CF new 22/7]]
+printcf "\[3;7\] * 7/22" $op
+
+set op [[NG1 new 2 1 0 2] operand [R2CF new 22/7]]
+printcf "\[3;7\] + 1/2" $op
+
+set op [[NG1 new 1 0 0 4] operand [R2CF new 22/7]]
+printcf "\[3;7\] / 4" $op
+
+set op [[NG1 new 0 1 1 0] operand [Root2 new]]
+printcf "1/\u221a2" $op 20
+
+set op [[NG1 new 1 1 0 2] operand [Root2 new]]
+printcf "(1+\u221a2)/2" $op 20
+printcf "approx val" [R2CF new 24142136 20000000]
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/0DESCRIPTION b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/0DESCRIPTION
new file mode 100644
index 0000000000..6901180101
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/0DESCRIPTION
@@ -0,0 +1,59 @@
+This task performs the basic mathematical functions on 2 continued fractions. This requires the full version of matrix NG:
+:
+I may perform perform the following operations:
+:Input the next term of continued fraction N1
+:Input the next term of continued fraction N2
+:Output a term of the continued fraction resulting from the operation.
+
+I output a term if the integer parts of and and and are equal. Otherwise I input a term from continued fraction N1 or continued fraction N2. If I need a term from N but N has no more terms I inject .
+
+When I input a term t from continued fraction N1 I change my internal state:
+: is transposed thus
+
+When I need a term from exhausted continued fraction N1 I change my internal state:
+: is transposed thus
+
+When I input a term t from continued fraction N2 I change my internal state:
+: is transposed thus
+
+When I need a term from exhausted continued fraction N2 I change my internal state:
+: is transposed thus
+
+When I output a term t I change my internal state:
+: is transposed thus
+
+When I need to choose to input from N1 or N2 I act:
+: if b and b2 are zero I choose N1
+: if b is zero I choose N2
+: if b2 is zero I choose N2
+: if abs( is greater than abs( I choose N1
+: otherwise I choose N2
+
+When performing arithmetic operation on two potentially infinite continued fractions it is possible to generate a rational number. eg * should produce 2. This will require either that I determine that my internal state is approaching infinity, or limiting the number of terms I am willing to input without producing any output.
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/1META.yaml b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/1META.yaml
new file mode 100644
index 0000000000..1e81690bbc
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/1META.yaml
@@ -0,0 +1,2 @@
+---
+note: Matrices
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.cpp
new file mode 100644
index 0000000000..af0c45b771
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.cpp
@@ -0,0 +1,29 @@
+/* Implement matrix NG
+ Nigel Galloway, February 12., 2013
+*/
+class NG_8 : public matrixNG {
+ private: int a12, a1, a2, a, b12, b1, b2, b, t;
+ double ab, a1b1, a2b2, a12b12;
+ const int chooseCFN(){return fabs(a1b1-ab) > fabs(a2b2-ab)? 0 : 1;}
+ const bool needTerm() {
+ if (b1==0 and b==0 and b2==0 and b12==0) return false;
+ if (b==0){cfn = b2==0? 0:1; return true;} else ab = ((double)a)/b;
+ if (b2==0){cfn = 1; return true;} else a2b2 = ((double)a2)/b2;
+ if (b1==0){cfn = 0; return true;} else a1b1 = ((double)a1)/b1;
+ if (b12==0){cfn = chooseCFN(); return true;} else a12b12 = ((double)a12)/b12;
+ thisTerm = (int)ab;
+ if (thisTerm==(int)a1b1 and thisTerm==(int)a2b2 and thisTerm==(int)a12b12){
+ t=a; a=b; b=t-b*thisTerm; t=a1; a1=b1; b1=t-b1*thisTerm; t=a2; a2=b2; b2=t-b2*thisTerm; t=a12; a12=b12; b12=t-b12*thisTerm;
+ haveTerm = true; return false;
+ }
+ cfn = chooseCFN();
+ return true;
+ }
+ void consumeTerm(){if(cfn==0){a=a1; a2=a12; b=b1; b2=b12;} else{a=a2; a1=a12; b=b2; b1=b12;}}
+ void consumeTerm(int n){
+ if(cfn==0){t=a; a=a1; a1=t+a1*n; t=a2; a2=a12; a12=t+a12*n; t=b; b=b1; b1=t+b1*n; t=b2; b2=b12; b12=t+b12*n;}
+ else{t=a; a=a2; a2=t+a2*n; t=a1; a1=a12; a12=t+a12*n; t=b; b=b2; b2=t+b2*n; t=b1; b1=b12; b12=t+b12*n;}
+ }
+ public:
+ NG_8(int a12, int a1, int a2, int a, int b12, int b1, int b2, int b): a12(a12), a1(a1), a2(a2), a(a), b12(b12), b1(b1), b2(b2), b(b){
+}};
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.cpp
new file mode 100644
index 0000000000..81a4368335
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.cpp
@@ -0,0 +1,13 @@
+int main() {
+ NG_8 a(0,1,1,0,0,0,0,1);
+ r2cf n2(22,7);
+ r2cf n1(1,2);
+ for(NG n(&a, &n1, &n2); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+
+ NG_4 a3(2,1,0,2);
+ r2cf n3(22,7);
+ for(NG n(&a3, &n3); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-3.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-3.cpp
new file mode 100644
index 0000000000..d5415ded47
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-3.cpp
@@ -0,0 +1,12 @@
+int main() {
+ NG_8 b(1,0,0,0,0,0,0,1);
+ r2cf b1(13,11);
+ r2cf b2(22,7);
+ for(NG n(&b, &b1, &b2); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ for(NG n(&a, &b2, &b1); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ for(r2cf cf(286,77); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-4.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-4.cpp
new file mode 100644
index 0000000000..a17b50ed3f
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-4.cpp
@@ -0,0 +1,10 @@
+int main() {
+ NG_8 c(0,1,-1,0,0,0,0,1);
+ r2cf c1(13,11);
+ r2cf c2(22,7);
+ for(NG n(&c, &c1, &c2); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ for(r2cf cf(-151,77); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-5.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-5.cpp
new file mode 100644
index 0000000000..88f73675f3
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-5.cpp
@@ -0,0 +1,8 @@
+int main() {
+ NG_8 d(0,1,0,0,0,0,1,0);
+ r2cf d1(22*22,7*7);
+ r2cf d2(22,7);
+ for(NG n(&d, &d1, &d2); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-6.cpp b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-6.cpp
new file mode 100644
index 0000000000..53cc109416
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/C++/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-6.cpp
@@ -0,0 +1,20 @@
+int main() {
+ r2cf a1(2,7);
+ r2cf a2(13,11);
+ NG_8 na(0,1,1,0,0,0,0,1);
+ NG A(&na, &a1, &a2); //[0;3,2] + [1;5,2]
+ r2cf b1(2,7);
+ r2cf b2(13,11);
+ NG_8 nb(0,1,-1,0,0,0,0,1);
+ NG B(&nb, &b1, &b2); //[0;3,2] - [1;5,2]
+ NG_8 nc(1,0,0,0,0,0,0,1); //A*B
+ for(NG n(&nc, &A, &B); n.moreTerms(); std::cout << n.nextTerm() << " ");
+ std::cout << std::endl;
+ for(r2cf cf(2,7); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ for(r2cf cf(13,11); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ for(r2cf cf(-7797,5929); cf.moreTerms(); std::cout << cf.nextTerm() << " ");
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.tcl b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.tcl
new file mode 100644
index 0000000000..cb40e68678
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-1.tcl
@@ -0,0 +1,101 @@
+oo::class create NG2 {
+ variable a b a1 b1 a2 b2 a12 b12 cf1 cf2
+ superclass Generator
+ constructor {args} {
+ lassign $args a12 a1 a2 a b12 b1 b2 b
+ next
+ }
+ method operands {N1 N2} {
+ set cf1 $N1
+ set cf2 $N2
+ return [self]
+ }
+
+ method Ingress1 t {
+ lassign [list [expr {$a2+$a12*$t}] [expr {$a+$a1*$t}] $a12 $a1 \
+ [expr {$b2+$b12*$t}] [expr {$b+$b1*$t}] $b12 $b1] \
+ a12 a1 a2 a b12 b1 b2 b
+ }
+ method Exhaust1 {} {
+ lassign [list $a12 $a1 $a12 $a1 $b12 $b1 $b12 $b1] \
+ a12 a1 a2 a b12 b1 b2 b
+ }
+ method Ingress2 t {
+ lassign [list [expr {$a1+$a12*$t}] $a12 [expr {$a+$a2*$t}] $a2 \
+ [expr {$b1+$b12*$t}] $b12 [expr {$b+$b2*$t}] $b2] \
+ a12 a1 a2 a b12 b1 b2 b
+ }
+ method Exhaust2 {} {
+ lassign [list $a12 $a12 $a2 $a2 $b12 $b12 $b2 $b2] \
+ a12 a1 a2 a b12 b1 b2 b
+ }
+ method Egress {} {
+ set t [expr {$a/$b}]
+ lassign [list $b12 $b1 $b2 $b \
+ [expr {$a12 - $b12*$t}] [expr {$a1 - $b1*$t}] \
+ [expr {$a2 - $b2*$t}] [expr {$a - $b*$t}]] \
+ a12 a1 a2 a b12 b1 b2 b
+ return $t
+ }
+
+ method DoIngress1 {} {
+ try {tailcall my Ingress1 [$cf1]} on break {} {}
+ oo::objdefine [self] forward DoIngress1 my Exhaust1
+ set cf1 ""
+ tailcall my Exhaust1
+ }
+ method DoIngress2 {} {
+ try {tailcall my Ingress2 [$cf2]} on break {} {}
+ oo::objdefine [self] forward DoIngress2 my Exhaust2
+ set cf2 ""
+ tailcall my Exhaust2
+ }
+ method Ingress {} {
+ if {$b==0} {
+ if {$b2 == 0} {
+ tailcall my DoIngress1
+ } else {
+ tailcall my DoIngress2
+ }
+ }
+ if {!$b2} {
+ tailcall my DoIngress2
+ }
+ if {!$b1} {
+ tailcall my DoIngress1
+ }
+ if {[my FirstSource?]} {
+ tailcall my DoIngress1
+ } else {
+ tailcall my DoIngress2
+ }
+ }
+
+ method FirstSource? {} {
+ expr {abs($a1*$b*$b2 - $a*$b1*$b2) > abs($a2*$b*$b1 - $a*$b1*$b2)}
+ }
+ method NeedTerm? {} {
+ expr {
+ ($b*$b1*$b2*$b12==0) ||
+ !($a/$b == $a1/$b1 && $a/$b == $a2/$b2 && $a/$b == $a12/$b12)
+ }
+ }
+ method Done? {} {
+ expr {$b==0 && $b1==0 && $b2==0 && $b12==0}
+ }
+
+ method Produce {} {
+ # Until we've drained both continued fractions...
+ while {$cf1 ne "" || $cf2 ne ""} {
+ if {[my NeedTerm?]} {
+ my Ingress
+ } else {
+ yield [my Egress]
+ }
+ }
+ # Drain our internal state
+ while {![my Done?]} {
+ yield [my Egress]
+ }
+ }
+}
diff --git a/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.tcl b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.tcl
new file mode 100644
index 0000000000..1638d7b354
--- /dev/null
+++ b/Task/Continued-fraction-Arithmetic-G-matrix-NG,-Contined-Fraction-N1,-Contined-Fraction-N2/Tcl/continued-fraction-arithmetic-g-matrix-ng,-contined-fraction-n1,-contined-fraction-n2-2.tcl
@@ -0,0 +1,16 @@
+set op [[NG2 new 0 1 1 0 0 0 0 1] operands [R2CF new 1/2] [R2CF new 22/7]]
+printcf "\[3;7\] + \[0;2\]" $op
+
+set op [[NG2 new 1 0 0 0 0 0 0 1] operands [R2CF new 13/11] [R2CF new 22/7]]
+printcf "\[1:5,2\] * \[3;7\]" $op
+
+set op [[NG2 new 0 1 -1 0 0 0 0 1] operands [R2CF new 13/11] [R2CF new 22/7]]
+printcf "\[1:5,2\] - \[3;7\]" $op
+
+set op [[NG2 new 0 1 0 0 0 0 1 0] operands [R2CF new 484/49] [R2CF new 22/7]]
+printcf "div test" $op
+
+set op1 [[NG2 new 0 1 1 0 0 0 0 1] operands [R2CF new 2/7] [R2CF new 13/11]]
+set op2 [[NG2 new 0 1 -1 0 0 0 0 1] operands [R2CF new 2/7] [R2CF new 13/11]]
+set op3 [[NG2 new 1 0 0 0 0 0 0 1] operands $op1 $op2]
+printcf "layered test" $op3
diff --git a/Task/Continued-fraction/Factor/continued-fraction.factor b/Task/Continued-fraction/Factor/continued-fraction.factor
new file mode 100644
index 0000000000..f138694017
--- /dev/null
+++ b/Task/Continued-fraction/Factor/continued-fraction.factor
@@ -0,0 +1,63 @@
+USING: arrays combinators io kernel locals math math.functions
+ math.ranges prettyprint sequences ;
+IN: rosetta.cfrac
+
+! Every continued fraction must implement these two words.
+GENERIC: cfrac-a ( n cfrac -- a )
+GENERIC: cfrac-b ( n cfrac -- b )
+
+! square root of 2
+SINGLETON: sqrt2
+M: sqrt2 cfrac-a
+ ! If n is 1, then a_n is 1, else a_n is 2.
+ drop { { 1 [ 1 ] } [ drop 2 ] } case ;
+M: sqrt2 cfrac-b
+ ! Always b_n is 1.
+ 2drop 1 ;
+
+! Napier's constant
+SINGLETON: napier
+M: napier cfrac-a
+ ! If n is 1, then a_n is 2, else a_n is n - 1.
+ drop { { 1 [ 2 ] } [ 1 - ] } case ;
+M: napier cfrac-b
+ ! If n is 1, then b_n is 1, else b_n is n - 1.
+ drop { { 1 [ 1 ] } [ 1 - ] } case ;
+
+SINGLETON: pi
+M: pi cfrac-a
+ ! If n is 1, then a_n is 3, else a_n is 6.
+ drop { { 1 [ 3 ] } [ drop 6 ] } case ;
+M: pi cfrac-b
+ ! Always b_n is (n * 2 - 1)^2.
+ drop 2 * 1 - 2 ^ ;
+
+:: cfrac-estimate ( cfrac terms -- number )
+ terms cfrac cfrac-a ! top = last a_n
+ terms 1 - 1 [a,b] [ :> n
+ n cfrac cfrac-b swap / ! top = b_n / top
+ n cfrac cfrac-a + ! top = top + a_n
+ ] each ;
+
+:: decimalize ( rational prec -- string )
+ rational 1 /mod ! split whole, fractional parts
+ prec 10^ * ! multiply fraction by 10 ^ prec
+ [ >integer unparse ] bi@ ! convert digits to strings
+ :> fraction
+ "." ! push decimal point
+ prec fraction length -
+ dup 0 < [ drop 0 ] when
+ "0" concat ! push padding zeros
+ fraction 4array concat ;
+
+
+
+MAIN: main
diff --git a/Task/Continued-fraction/J/continued-fraction.j b/Task/Continued-fraction/J/continued-fraction.j
new file mode 100644
index 0000000000..dc7a471be6
--- /dev/null
+++ b/Task/Continued-fraction/J/continued-fraction.j
@@ -0,0 +1,14 @@
+ cfrac=: +`% / NB. Evaluate a list as a continued fraction
+
+ sqrt2=: cfrac 1 1,200$2 1x
+ pi=:cfrac 3, , ,&6"0 *:<:+:>:i.100x
+ e=: cfrac 2 1, , ,~"0 >:i.100x
+
+ NB. translate from fraction to decimal string
+ NB. translated from factor
+ dec =: (-@:[ (}.,'.',{.) ":@:<.@:(* 10x&^)~)"0
+
+ 100 10 100 dec sqrt2, pi, e
+1.4142135623730950488016887242096980785696718753769480731766797379907324784621205551109457595775322165
+3.1415924109
+2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
diff --git a/Task/Continued-fraction/Mathematica/continued-fraction.mathematica b/Task/Continued-fraction/Mathematica/continued-fraction.mathematica
new file mode 100644
index 0000000000..445b31e0e5
--- /dev/null
+++ b/Task/Continued-fraction/Mathematica/continued-fraction.mathematica
@@ -0,0 +1,6 @@
+sqrt2=Function[n,{1,Transpose@{Array[2&,n],Array[1&,n]}}];
+napier=Function[n,{2,Transpose@{Range[n],Prepend[Range[n-1],1]}}];
+pi=Function[n,{3,Transpose@{Array[6&,n],Array[(2#-1)^2&,n]}}];
+approx=Function[l,
+ N[Divide@@First@Fold[{{#2.#[[;;,1]],#2.#[[;;,2]]},#[[1]]}&,{{l[[2,1,1]]l[[1]]+l[[2,1,2]],l[[2,1,1]]},{l[[1]],1}},l[[2,2;;]]],10]];
+r2=approx/@{sqrt2@#,napier@#,pi@#}&@10000;r2//TableForm
diff --git a/Task/Continued-fraction/Maxima/continued-fraction.maxima b/Task/Continued-fraction/Maxima/continued-fraction.maxima
new file mode 100644
index 0000000000..219b38da6f
--- /dev/null
+++ b/Task/Continued-fraction/Maxima/continued-fraction.maxima
@@ -0,0 +1,23 @@
+cfeval(x) := block([a, b, n, z], a: x[1], b: x[2], n: length(a), z: 0,
+ for i from n step -1 thru 2 do z: b[i]/(a[i] + z), a[1] + z)$
+
+cf_sqrt2(n) := [cons(1, makelist(2, i, 2, n)), cons(0, makelist(1, i, 2, n))]$
+
+cf_e(n) := [cons(2, makelist(i, i, 1, n - 1)), append([0, 1], makelist(i, i, 1, n - 2))]$
+
+cf_pi(n) := [cons(3, makelist(6, i, 2, n)), cons(0, makelist((2*i - 1)^2, i, 1, n - 1))]$
+
+cfeval(cf_sqrt2(20)), numer; /* 1.414213562373097 */
+% - sqrt(2), numer; /* 1.3322676295501878*10^-15 */
+
+cfeval(cf_e(20)), numer; /* 2.718281828459046 */
+% - %e, numer; /* 4.4408920985006262*10^-16 */
+
+cfeval(cf_pi(20)), numer; /* 3.141623806667839 */
+% - %pi, numer; /* 3.115307804568701*10^-5 */
+
+
+/* convergence is much slower for pi */
+fpprec: 20$
+x: cfeval(cf_pi(10000))$
+bfloat(x - %pi); /* 2.4999999900104930006b-13 */
diff --git a/Task/Conways-Game-of-Life/Icon/conways-game-of-life.icon b/Task/Conways-Game-of-Life/Icon/conways-game-of-life.icon
new file mode 100644
index 0000000000..23ef3fe8d1
--- /dev/null
+++ b/Task/Conways-Game-of-Life/Icon/conways-game-of-life.icon
@@ -0,0 +1,79 @@
+global limit
+
+procedure main(args)
+ n := args[1] | 50 # default is a 50x50 grid
+ limit := args[2] | &null # optional limit to number of generations
+ write("Enter the starting pattern, end with EOF")
+ grid := getInitialGrid(n)
+ play(grid)
+end
+
+# This procedure reads in the initial pattern, inserting it
+# into an nXn grid of cells. The nXn grid also gets a
+# new border of empty cells, which just makes the test simpler
+# for determining what do with a cell on each generation.
+# It would be better to let the user move the cursor and click
+# on cells to create/delete living cells, but this version
+# assumes a simple ASCII terminal.
+procedure getInitialGrid(n)
+ static notBlank, allStars
+ initial {
+ notBlank := ~' '
+ allStars := repl("*",*notBlank)
+ }
+
+ g := [] # store as an array of strings
+
+ put(g,repl(" ",n))
+ while r := read() do { # read in rows of grid
+ r := left(r,n) # force each to length n
+ put(g," "||map(r,notBlank,allStars)||" ") # and making any life a '*'
+ }
+ while *g ~= (n+2) do
+ put(g,repl(" ",n))
+
+ return g
+end
+
+# Simple-minded procedure to 'play' Life from a starting grid.
+procedure play(grid)
+ while not allDone(grid) do {
+ display(grid)
+ grid := onePlay(grid)
+ }
+end
+
+# Display the grid
+procedure display(g)
+ write(repl("-",*g[1]))
+ every write(!g)
+ write(repl("-",*g[1]))
+end
+
+# Compute one generation of Life from the current one.
+procedure onePlay(g)
+ ng := []
+ every put(ng, !g) # new generation starts as copy of old
+ every ng[r := 2 to *g-1][c := 2 to *g-1] := case sum(g,r,c) of {
+ 3: "*" # cell lives (or is born)
+ 2: g[r][c] # cell unchanged
+ default: " " # cell dead
+ }
+ return ng
+end
+
+# Return the number of living cells surrounding the current cell.
+procedure sum(g,r,c)
+ cnt := 0
+ every (i := -1 to 1, j := -1 to 1) do
+ if ((i ~= 0) | (j ~= 0)) & (g[r+i][c+j] == "*") then cnt +:= 1
+ return cnt
+end
+
+# Check to see if all the cells have died or we've exceeded the
+# number of allowed generations.
+procedure allDone(g)
+ static count
+ initial count := 0
+ return ((count +:= 1) > \limit) | (trim(!g) == " ")
+end
diff --git a/Task/Conways-Game-of-Life/J/conways-game-of-life-1.j b/Task/Conways-Game-of-Life/J/conways-game-of-life-1.j
new file mode 100644
index 0000000000..0139cad871
--- /dev/null
+++ b/Task/Conways-Game-of-Life/J/conways-game-of-life-1.j
@@ -0,0 +1,2 @@
+pad=: 0,0,~0,.0,.~]
+life=: (_3 _3 (+/ e. 3+0,4&{)@,;._3 ])@pad
diff --git a/Task/Conways-Game-of-Life/J/conways-game-of-life-2.j b/Task/Conways-Game-of-Life/J/conways-game-of-life-2.j
new file mode 100644
index 0000000000..b54d2de8fb
--- /dev/null
+++ b/Task/Conways-Game-of-Life/J/conways-game-of-life-2.j
@@ -0,0 +1,12 @@
+ life^:0 1 2 #:0 7 0
+0 0 0
+1 1 1
+0 0 0
+
+0 1 0
+0 1 0
+0 1 0
+
+0 0 0
+1 1 1
+0 0 0
diff --git a/Task/Conways-Game-of-Life/JAMES-II-Rule-based-Cellular-Automata/conways-game-of-life.james b/Task/Conways-Game-of-Life/JAMES-II-Rule-based-Cellular-Automata/conways-game-of-life.james
new file mode 100644
index 0000000000..babc5b3ac2
--- /dev/null
+++ b/Task/Conways-Game-of-Life/JAMES-II-Rule-based-Cellular-Automata/conways-game-of-life.james
@@ -0,0 +1,25 @@
+@caversion 1;
+
+dimensions 2;
+
+//using Moore neighborhood
+neighborhood moore;
+
+//available states
+state DEAD, ALIVE;
+
+/*
+ if current state is ALIVE and the
+ neighborhood does not contain 2 or
+ 3 ALIVE states the cell changes to
+ DEAD
+*/
+rule{ALIVE}:!ALIVE{2,3}->DEAD;
+
+/*
+ if current state is DEAD and there
+ are exactly 3 ALIVE cells in the
+ neighborhood the cell changes to
+ ALIVE
+*/
+rule{DEAD}:ALIVE{3}->ALIVE;
diff --git a/Task/Conways-Game-of-Life/Liberty-BASIC/conways-game-of-life.liberty b/Task/Conways-Game-of-Life/Liberty-BASIC/conways-game-of-life.liberty
new file mode 100644
index 0000000000..e1f236d310
--- /dev/null
+++ b/Task/Conways-Game-of-Life/Liberty-BASIC/conways-game-of-life.liberty
@@ -0,0 +1,68 @@
+ nomainwin
+
+ gridX = 20
+ gridY = gridX
+
+ mult =500 /gridX
+ pointSize =360 /gridX
+
+ dim old( gridX +1, gridY +1), new( gridX +1, gridY +1)
+
+'Set blinker:
+ old( 16, 16) =1: old( 16, 17) =1 : old( 16, 18) =1
+
+'Set glider:
+ old( 5, 7) =1: old( 6, 7) =1: old( 7, 7) =1
+ old( 7, 6) =1: old( 6, 5) =1
+
+ WindowWidth =570
+ WindowHeight =600
+
+ open "Conway's 'Game of Life'." for graphics_nsb_nf as #w
+
+ #w "trapclose [quit]"
+ #w "down ; size "; pointSize
+ #w "fill black"
+
+'Draw initial grid
+ for x = 1 to gridX
+ for y = 1 to gridY
+ '#w "color "; int( old( x, y) *256); " 0 255"
+ if old( x, y) <>0 then #w "color red" else #w "color darkgray"
+ #w "set "; x *mult +20; " "; y *mult +20
+ next y
+ next x
+' ______________________________________________________________________________
+'Run
+ do
+ for x =1 to gridX
+ for y =1 to gridY
+ 'find number of live Moore neighbours
+ neighbours =old( x -1, y -1) +old( x, y -1) +old( x +1, y -1)+_
+ old( x -1, y) +old( x +1, y )+_
+ old( x -1, y +1) +old( x, y +1) +old( x +1, y +1)
+ was =old( x, y)
+ if was =0 then
+ if neighbours =3 then N =1 else N =0
+ else
+ if neighbours =3 or neighbours =2 then N =1 else N =0
+ end if
+ new( x, y) = N
+ '#w "color "; int( N /8 *256); " 0 255"
+ if N <>0 then #w "color red" else #w "color darkgray"
+ #w "set "; x *mult +20; " "; y *mult +20
+ next y
+ next x
+ scan
+'swap
+ for x =1 to gridX
+ for y =1 to gridY
+ old( x, y) =new( x, y)
+ next y
+ next x
+'Re-run until interrupted...
+ loop until FALSE
+'User shutdown received
+ [quit]
+ close #w
+ end
diff --git a/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-1.mathematica b/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-1.mathematica
new file mode 100644
index 0000000000..5f31fbd403
--- /dev/null
+++ b/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-1.mathematica
@@ -0,0 +1 @@
+CellularAutomaton[{224,{2,{{2,2,2},{2,1,2},{2,2,2}}},{1,1}}, startconfiguration, steps];
diff --git a/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-2.mathematica b/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-2.mathematica
new file mode 100644
index 0000000000..b7e062b0ab
--- /dev/null
+++ b/Task/Conways-Game-of-Life/Mathematica/conways-game-of-life-2.mathematica
@@ -0,0 +1,2 @@
+results=CellularAutomaton[{224,{2,{{2,2,2},{2,1,2},{2,2,2}}},{1,1}},{{{0,1,0},{0,0,1},{1,1,1}},0},8];
+ Do[Print[i-1];Print[Grid[results[[i]]/.{1->"#",0->"."}]];,{i,1,Length[results]}]
diff --git a/Task/Conways-Game-of-Life/Maxima/conways-game-of-life.maxima b/Task/Conways-Game-of-Life/Maxima/conways-game-of-life.maxima
new file mode 100644
index 0000000000..7dc2f7f852
--- /dev/null
+++ b/Task/Conways-Game-of-Life/Maxima/conways-game-of-life.maxima
@@ -0,0 +1,53 @@
+life(A) := block(
+ [p, q, B: zerofor(A), s],
+ [p, q]: matrix_size(A),
+ for i thru p do (
+ for j thru q do (
+ s: 0,
+ if j > 1 then s: s + A[i, j - 1],
+ if j < q then s: s + A[i, j + 1],
+ if i > 1 then (
+ s: s + A[i - 1, j],
+ if j > 1 then s: s + A[i - 1, j - 1],
+ if j < q then s: s + A[i - 1, j + 1]
+ ),
+ if i < p then (
+ s: s + A[i + 1, j],
+ if j > 1 then s: s + A[i + 1, j - 1],
+ if j < q then s: s + A[i + 1, j + 1]
+ ),
+ B[i, j]: charfun(s = 3 or (s = 2 and A[i, j] = 1))
+ )
+ ),
+ B
+)$
+
+
+/* a glider */
+
+L: matrix([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
+ [0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])$
+
+gen(A, n) := block(thru n do A: life(A), A)$
+
+gen(L, 4);
+matrix([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
+ [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
diff --git a/Task/Count-in-factors/Groovy/count-in-factors.groovy b/Task/Count-in-factors/Groovy/count-in-factors.groovy
new file mode 100644
index 0000000000..ee4d819091
--- /dev/null
+++ b/Task/Count-in-factors/Groovy/count-in-factors.groovy
@@ -0,0 +1,22 @@
+def factors(number) {
+ if (number == 1) {
+ return [1]
+ }
+ def factors = []
+ BigInteger value = number
+ BigInteger possibleFactor = 2
+ while (possibleFactor <= value) {
+ if (value % possibleFactor == 0) {
+ factors << possibleFactor
+ value /= possibleFactor
+ } else {
+ possibleFactor++
+ }
+ }
+ factors
+}
+Number.metaClass.factors = { factors(delegate) }
+
+((1..10) + (6351..6359)).each { number ->
+ println "$number = ${number.factors().join(' x ')}"
+}
diff --git a/Task/Count-in-factors/Icon/count-in-factors.icon b/Task/Count-in-factors/Icon/count-in-factors.icon
new file mode 100644
index 0000000000..3fb3e2b410
--- /dev/null
+++ b/Task/Count-in-factors/Icon/count-in-factors.icon
@@ -0,0 +1,9 @@
+procedure main()
+write("Press ^C to terminate")
+every f := [i:= 1] | factors(i := seq(2)) do {
+ writes(i," : [")
+ every writes(" ",!f|"]\n")
+ }
+end
+
+link factors
diff --git a/Task/Count-in-factors/J/count-in-factors-1.j b/Task/Count-in-factors/J/count-in-factors-1.j
new file mode 100644
index 0000000000..7f74386238
--- /dev/null
+++ b/Task/Count-in-factors/J/count-in-factors-1.j
@@ -0,0 +1 @@
+q:
diff --git a/Task/Count-in-factors/J/count-in-factors-2.j b/Task/Count-in-factors/J/count-in-factors-2.j
new file mode 100644
index 0000000000..199dcaf91a
--- /dev/null
+++ b/Task/Count-in-factors/J/count-in-factors-2.j
@@ -0,0 +1,12 @@
+ ('1 : 1',":&> ,"1 ': ',"1 ":@q:) 2+i.10
+1 : 1
+2 : 2
+3 : 3
+4 : 2 2
+5 : 5
+6 : 2 3
+7 : 7
+8 : 2 2 2
+9 : 3 3
+10: 2 5
+11: 11
diff --git a/Task/Count-in-factors/Liberty-BASIC/count-in-factors.liberty b/Task/Count-in-factors/Liberty-BASIC/count-in-factors.liberty
new file mode 100644
index 0000000000..7cf493db5d
--- /dev/null
+++ b/Task/Count-in-factors/Liberty-BASIC/count-in-factors.liberty
@@ -0,0 +1,18 @@
+'see Run BASIC solution
+for i = 1000 to 1016
+ print i;" = "; factorial$(i)
+next
+wait
+function factorial$(num)
+ if num = 1 then factorial$ = "1"
+ fct = 2
+ while fct <= num
+ if (num mod fct) = 0 then
+ factorial$ = factorial$ ; x$ ; fct
+ x$ = " x "
+ num = num / fct
+ else
+ fct = fct + 1
+ end if
+ wend
+end function
diff --git a/Task/Count-in-factors/Mathematica/count-in-factors.mathematica b/Task/Count-in-factors/Mathematica/count-in-factors.mathematica
new file mode 100644
index 0000000000..b184f7b1c6
--- /dev/null
+++ b/Task/Count-in-factors/Mathematica/count-in-factors.mathematica
@@ -0,0 +1,4 @@
+n = 2;
+While[n < 100,
+ Print[Row[Riffle[Flatten[Map[Apply[ConstantArray, #] &, FactorInteger[n]]],"*"]]];
+ n++]
diff --git a/Task/Count-in-octal/Groovy/count-in-octal-1.groovy b/Task/Count-in-octal/Groovy/count-in-octal-1.groovy
new file mode 100644
index 0000000000..45210b75d6
--- /dev/null
+++ b/Task/Count-in-octal/Groovy/count-in-octal-1.groovy
@@ -0,0 +1,4 @@
+println 'decimal octal'
+for (def i = 0; i <= Integer.MAX_VALUE; i++) {
+ printf ('%7d %#5o\n', i, i)
+}
diff --git a/Task/Count-in-octal/Groovy/count-in-octal-2.groovy b/Task/Count-in-octal/Groovy/count-in-octal-2.groovy
new file mode 100644
index 0000000000..573489584c
--- /dev/null
+++ b/Task/Count-in-octal/Groovy/count-in-octal-2.groovy
@@ -0,0 +1,4 @@
+println 'decimal octal'
+for (def i = 0g; true; i += 1g) {
+ printf ('%7d %#5o\n', i, i)
+}
diff --git a/Task/Count-in-octal/Icon/count-in-octal.icon b/Task/Count-in-octal/Icon/count-in-octal.icon
new file mode 100644
index 0000000000..9ab94f5fef
--- /dev/null
+++ b/Task/Count-in-octal/Icon/count-in-octal.icon
@@ -0,0 +1,6 @@
+link convert # To get exbase10 method
+
+procedure main()
+ limit := 8r37777777777
+ every write(exbase10(seq(0)\limit, 8))
+end
diff --git a/Task/Count-in-octal/J/count-in-octal-1.j b/Task/Count-in-octal/J/count-in-octal-1.j
new file mode 100644
index 0000000000..eb8ce278bd
--- /dev/null
+++ b/Task/Count-in-octal/J/count-in-octal-1.j
@@ -0,0 +1,2 @@
+ disp=.[:smoutput [:,@:(":"0) 8.^:_1
+ (>:[disp)^:_ ]0
diff --git a/Task/Count-in-octal/J/count-in-octal-2.j b/Task/Count-in-octal/J/count-in-octal-2.j
new file mode 100644
index 0000000000..b152c2449f
--- /dev/null
+++ b/Task/Count-in-octal/J/count-in-octal-2.j
@@ -0,0 +1,12 @@
+ (>:[disp)^:_ ]0
+0
+1
+2
+3
+4
+5
+6
+7
+10
+11
+...
diff --git a/Task/Count-in-octal/LOLCODE/count-in-octal.lol b/Task/Count-in-octal/LOLCODE/count-in-octal.lol
new file mode 100644
index 0000000000..54f56c2578
--- /dev/null
+++ b/Task/Count-in-octal/LOLCODE/count-in-octal.lol
@@ -0,0 +1,19 @@
+HAI 1.3
+
+HOW IZ I octal YR num
+ I HAS A digit, I HAS A oct ITZ ""
+ IM IN YR octalizer
+ digit R MOD OF num AN 8
+ oct R SMOOSH digit oct MKAY
+ num R QUOSHUNT OF num AN 8
+ NOT num, O RLY?
+ YA RLY, FOUND YR oct
+ OIC
+ IM OUTTA YR octalizer
+IF U SAY SO
+
+IM IN YR printer UPPIN YR num
+ VISIBLE I IZ octal YR num MKAY
+IM OUTTA YR printer
+
+KTHXBYE
diff --git a/Task/Count-in-octal/Lang5/count-in-octal.lang5 b/Task/Count-in-octal/Lang5/count-in-octal.lang5
new file mode 100644
index 0000000000..2a4f95659a
--- /dev/null
+++ b/Task/Count-in-octal/Lang5/count-in-octal.lang5
@@ -0,0 +1,2 @@
+'%4o '__number_format set
+0 do dup 1 compress . "\n" . 1 + loop
diff --git a/Task/Count-in-octal/Liberty-BASIC/count-in-octal-1.liberty b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-1.liberty
new file mode 100644
index 0000000000..c3544e0fa5
--- /dev/null
+++ b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-1.liberty
@@ -0,0 +1,26 @@
+ 'the method used here uses the base-conversion from RC Non-decimal radices/Convert
+ 'to terminate hit
+
+ global alphanum$
+ alphanum$ ="01234567"
+
+ i =0
+
+ while 1
+ print toBase$( 8, i)
+ i =i +1
+ wend
+
+ end
+
+ function toBase$( base, number) ' Convert decimal variable to number string.
+ maxIntegerBitSize =len( str$( number))
+ toBase$ =""
+ for i =10 to 1 step -1
+ remainder =number mod base
+ toBase$ =mid$( alphanum$, remainder +1, 1) +toBase$
+ number =int( number /base)
+ if number <1 then exit for
+ next i
+ toBase$ =right$( " " +toBase$, 10)
+ end function
diff --git a/Task/Count-in-octal/Liberty-BASIC/count-in-octal-2.liberty b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-2.liberty
new file mode 100644
index 0000000000..6c7dacb227
--- /dev/null
+++ b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-2.liberty
@@ -0,0 +1,30 @@
+ op$ = "00000000000000000000"
+L =len( op$)
+
+while 1
+ started =0
+
+ for i =1 to L
+ m$ =mid$( op$, i, 1)
+ if started =0 and m$ ="0" then print " "; else print m$;: started =1
+ next i
+ print
+
+ for i =L to 1 step -1
+ p$ =mid$( op$, i, 1)
+ if p$ =" " then v =0 else v =val( p$)
+ incDigit = v +carry
+ if i =L then incDigit =incDigit +1
+ if incDigit >=8 then
+ replDigit =incDigit -8
+ carry =1
+ else
+ replDigit =incDigit
+ carry =0
+ end if
+ op$ =left$( op$, i -1) +chr$( 48 +replDigit) +right$( op$, L -i)
+ next i
+
+wend
+
+end
diff --git a/Task/Count-in-octal/Liberty-BASIC/count-in-octal-3.liberty b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-3.liberty
new file mode 100644
index 0000000000..a011f10852
--- /dev/null
+++ b/Task/Count-in-octal/Liberty-BASIC/count-in-octal-3.liberty
@@ -0,0 +1,16 @@
+ i = 0
+while 1
+ call CountOctal 0, i, i > 0
+ i = i + 1
+wend
+
+sub CountOctal value, depth, startValue
+ value = value * 10
+ for i = startValue to 7
+ if depth > 0 then
+ call CountOctal value + i, depth - 1, 0
+ else
+ print value + i
+ end if
+ next i
+end sub
diff --git a/Task/Count-in-octal/Logo/count-in-octal.logo b/Task/Count-in-octal/Logo/count-in-octal.logo
new file mode 100644
index 0000000000..7e790bbc5d
--- /dev/null
+++ b/Task/Count-in-octal/Logo/count-in-octal.logo
@@ -0,0 +1,22 @@
+to increment_octal :n
+ ifelse [empty? :n] [
+ output 1
+ ] [
+ local "last
+ make "last last :n
+ local "butlast
+ make "butlast butlast :n
+ make "last sum :last 1
+ ifelse [:last < 8] [
+ output word :butlast :last
+ ] [
+ output word (increment_octal :butlast) 0
+ ]
+ ]
+end
+
+make "oct 0
+while ["true] [
+ print :oct
+ make "oct increment_octal :oct
+]
diff --git a/Task/Count-in-octal/Mathematica/count-in-octal.mathematica b/Task/Count-in-octal/Mathematica/count-in-octal.mathematica
new file mode 100644
index 0000000000..38328341fe
--- /dev/null
+++ b/Task/Count-in-octal/Mathematica/count-in-octal.mathematica
@@ -0,0 +1,2 @@
+x=0;
+While[True,Print[BaseForm[x,8];x++]
diff --git a/Task/Count-in-octal/Mercury/count-in-octal.mercury b/Task/Count-in-octal/Mercury/count-in-octal.mercury
new file mode 100644
index 0000000000..0810986095
--- /dev/null
+++ b/Task/Count-in-octal/Mercury/count-in-octal.mercury
@@ -0,0 +1,17 @@
+:- module count_in_octal.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int, list, string.
+
+main(!IO) :-
+ count_in_octal(0, !IO).
+
+:- pred count_in_octal(int::in, io::di, io::uo) is det.
+
+count_in_octal(N, !IO) :-
+ io.format("%o\n", [i(N)], !IO),
+ count_in_octal(N + 1, !IO).
diff --git a/Task/Count-in-octal/Modula-2/count-in-octal.mod2 b/Task/Count-in-octal/Modula-2/count-in-octal.mod2
new file mode 100644
index 0000000000..8c2ceb1f63
--- /dev/null
+++ b/Task/Count-in-octal/Modula-2/count-in-octal.mod2
@@ -0,0 +1,13 @@
+MODULE octal;
+
+IMPORT InOut;
+
+VAR num : CARDINAL;
+
+BEGIN
+ num := 0;
+ REPEAT
+ InOut.WriteOct (num, 12); InOut.WriteLn;
+ INC (num)
+ UNTIL num = 0
+END octal.
diff --git a/Task/Count-occurrences-of-a-substring/Groovy/count-occurrences-of-a-substring.groovy b/Task/Count-occurrences-of-a-substring/Groovy/count-occurrences-of-a-substring.groovy
new file mode 100644
index 0000000000..5ae41f0329
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Groovy/count-occurrences-of-a-substring.groovy
@@ -0,0 +1,4 @@
+println (('the three truths' =~ /th/).count)
+println (('ababababab' =~ /abab/).count)
+println (('abaabba*bbaba*bbab' =~ /a*b/).count)
+println (('abaabba*bbaba*bbab' =~ /a\*b/).count)
diff --git a/Task/Count-occurrences-of-a-substring/Icon/count-occurrences-of-a-substring.icon b/Task/Count-occurrences-of-a-substring/Icon/count-occurrences-of-a-substring.icon
new file mode 100644
index 0000000000..2c51d91dab
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Icon/count-occurrences-of-a-substring.icon
@@ -0,0 +1,14 @@
+procedure main()
+every A := ![ ["the three truths","th"], ["ababababab","abab"] ] do
+ write("The string ",image(A[2])," occurs as a non-overlapping substring ",
+ countSubstring!A , " times in ",image(A[1]))
+end
+
+procedure countSubstring(s1,s2) #: return count of non-overlapping substrings
+c := 0
+s1 ? while tab(find(s2)) do {
+ move(*s2)
+ c +:= 1
+ }
+return c
+end
diff --git a/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-1.j b/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-1.j
new file mode 100644
index 0000000000..82095eb7b6
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-1.j
@@ -0,0 +1,2 @@
+require'strings'
+countss=: #@] %~ #@[ - [ #@rplc '';~]
diff --git a/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-2.j b/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-2.j
new file mode 100644
index 0000000000..12fef71a04
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/J/count-occurrences-of-a-substring-2.j
@@ -0,0 +1,4 @@
+ 'the three truths' countss 'th'
+3
+ 'ababababab' countss 'abab'
+2
diff --git a/Task/Count-occurrences-of-a-substring/K/count-occurrences-of-a-substring.k b/Task/Count-occurrences-of-a-substring/K/count-occurrences-of-a-substring.k
new file mode 100644
index 0000000000..1941158fe4
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/K/count-occurrences-of-a-substring.k
@@ -0,0 +1,11 @@
+ "the three truths" _ss "th"
+0 4 13
+
+ #"the three truths" _ss "th"
+3
+
+ "ababababab" _ss "abab"
+0 4
+
+ #"ababababab" _ss "abab"
+2
diff --git a/Task/Count-occurrences-of-a-substring/Liberty-BASIC/count-occurrences-of-a-substring.liberty b/Task/Count-occurrences-of-a-substring/Liberty-BASIC/count-occurrences-of-a-substring.liberty
new file mode 100644
index 0000000000..7f628ed59b
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Liberty-BASIC/count-occurrences-of-a-substring.liberty
@@ -0,0 +1,13 @@
+print countSubstring( "the three truths", "th")
+print countSubstring( "ababababab", "abab")
+end
+
+function countSubstring( a$, s$)
+ c =0
+ la =len( a$)
+ ls =len( s$)
+ for i =1 to la -ls
+ if mid$( a$, i, ls) =s$ then c =c +1: i =i +ls -1
+ next i
+ countSubstring =c
+end function
diff --git a/Task/Count-occurrences-of-a-substring/Mathematica/count-occurrences-of-a-substring.mathematica b/Task/Count-occurrences-of-a-substring/Mathematica/count-occurrences-of-a-substring.mathematica
new file mode 100644
index 0000000000..56076e675f
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Mathematica/count-occurrences-of-a-substring.mathematica
@@ -0,0 +1,4 @@
+StringPosition["the three truths","th",Overlaps->False]//Length
+3
+StringPosition["ababababab","abab",Overlaps->False]//Length
+2
diff --git a/Task/Count-occurrences-of-a-substring/Maxima/count-occurrences-of-a-substring.maxima b/Task/Count-occurrences-of-a-substring/Maxima/count-occurrences-of-a-substring.maxima
new file mode 100644
index 0000000000..f59cf2789c
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Maxima/count-occurrences-of-a-substring.maxima
@@ -0,0 +1,8 @@
+scount(e, s) := block(
+ [n: 0, k: 1],
+ while integerp(k: ssearch(e, s, k)) do (n: n + 1, k: k + 1),
+ n
+)$
+
+scount("na", "banana");
+2
diff --git a/Task/Count-occurrences-of-a-substring/Mirah/count-occurrences-of-a-substring.mirah b/Task/Count-occurrences-of-a-substring/Mirah/count-occurrences-of-a-substring.mirah
new file mode 100644
index 0000000000..104e5ee29b
--- /dev/null
+++ b/Task/Count-occurrences-of-a-substring/Mirah/count-occurrences-of-a-substring.mirah
@@ -0,0 +1,38 @@
+import java.util.regex.Pattern
+import java.util.regex.Matcher
+
+#The "remove and count the difference" method
+def count_substring(pattern:string, source:string)
+ (source.length() - source.replace(pattern, "").length()) / pattern.length()
+end
+
+puts count_substring("th", "the three truths") # ==> 3
+puts count_substring("abab", "ababababab") # ==> 2
+puts count_substring("a*b", "abaabba*bbaba*bbab") # ==> 2
+
+
+# The "split and count" method
+def count_substring2(pattern:string, source:string)
+ # the result of split() will contain one more element than the delimiter
+ # the "-1" second argument makes it not discard trailing empty strings
+ source.split(Pattern.quote(pattern), -1).length - 1
+end
+
+puts count_substring2("th", "the three truths") # ==> 3
+puts count_substring2("abab", "ababababab") # ==> 2
+puts count_substring2("a*b", "abaabba*bbaba*bbab") # ==> 2
+
+
+# This method does a match and counts how many times it matches
+def count_substring3(pattern:string, source:string)
+ result = 0
+ Matcher m = Pattern.compile(Pattern.quote(pattern)).matcher(source);
+ while (m.find())
+ result = result + 1
+ end
+ result
+end
+
+puts count_substring3("th", "the three truths") # ==> 3
+puts count_substring3("abab", "ababababab") # ==> 2
+puts count_substring3("a*b", "abaabba*bbaba*bbab") # ==> 2
diff --git a/Task/Count-the-coins/Factor/count-the-coins.factor b/Task/Count-the-coins/Factor/count-the-coins.factor
new file mode 100644
index 0000000000..1c21c57005
--- /dev/null
+++ b/Task/Count-the-coins/Factor/count-the-coins.factor
@@ -0,0 +1,36 @@
+USING: combinators kernel locals math math.ranges sequences sets sorting ;
+IN: rosetta.coins
+
+ types
+ {
+ ! End condition: 1 way to make 0 cents.
+ { [ cents zero? ] [ 1 ] }
+ ! End condition: 0 ways to make money without any coins.
+ { [ types zero? ] [ 0 ] }
+ ! Optimization: At most 1 way to use 1 type of coin.
+ { [ types 1 number= ] [
+ cents coins first mod zero? [ 1 ] [ 0 ] if
+ ] }
+ ! Find all ways to use the first type of coin.
+ [
+ ! f = first type, r = other types of coins.
+ coins unclip-slice :> f :> r
+ ! Loop for 0, f, 2*f, 3*f, ..., cents.
+ 0 cents f [
+ ! Recursively count how many ways to make remaining cents
+ ! with other types of coins.
+ cents swap - r recursive-count
+ ] [ + ] map-reduce ! Sum the counts.
+ ]
+ } cond ;
+PRIVATE>
+
+! How many ways can we make the given amount of cents
+! with the given set of coins?
+: make-change ( cents coins -- ways )
+ members [ ] inv-sort-with ! Sort coins in descending order.
+ recursive-count ;
diff --git a/Task/Count-the-coins/Groovy/count-the-coins-1.groovy b/Task/Count-the-coins/Groovy/count-the-coins-1.groovy
new file mode 100644
index 0000000000..2a93130823
--- /dev/null
+++ b/Task/Count-the-coins/Groovy/count-the-coins-1.groovy
@@ -0,0 +1,13 @@
+def ccR
+ccR = { BigInteger tot, List coins ->
+ BigInteger n = coins.size()
+ switch ([tot:tot, coins:coins]) {
+ case { it.tot == 0 } :
+ return 1g
+ case { it.tot < 0 || coins == [] } :
+ return 0g
+ default:
+ return ccR(tot, coins[1.. coins ->
+ List ways = [0g] * (tot+1)
+ ways[0] = 1g
+ coins.each { BigInteger coin ->
+ (coin..tot).each { j ->
+ ways[j] += ways[j-coin]
+ }
+ }
+ ways[tot]
+}
diff --git a/Task/Count-the-coins/Groovy/count-the-coins-3.groovy b/Task/Count-the-coins/Groovy/count-the-coins-3.groovy
new file mode 100644
index 0000000000..fee8aef35d
--- /dev/null
+++ b/Task/Count-the-coins/Groovy/count-the-coins-3.groovy
@@ -0,0 +1,14 @@
+println '\nBase:'
+[iterative: ccI, recursive: ccR].each { label, cc ->
+ print "${label} "
+ def start = System.currentTimeMillis()
+ def ways = cc(100g, [25g, 10g, 5g, 1g])
+ def elapsed = System.currentTimeMillis() - start
+ println ("answer: ${ways} elapsed: ${elapsed}ms")
+}
+
+print '\nExtra Credit:\niterative '
+def start = System.currentTimeMillis()
+def ways = ccI(1000g * 100, [100g, 50g, 25g, 10g, 5g, 1g])
+def elapsed = System.currentTimeMillis() - start
+println ("answer: ${ways} elapsed: ${elapsed}ms")
diff --git a/Task/Count-the-coins/Icon/count-the-coins-1.icon b/Task/Count-the-coins/Icon/count-the-coins-1.icon
new file mode 100644
index 0000000000..270f6aa8ca
--- /dev/null
+++ b/Task/Count-the-coins/Icon/count-the-coins-1.icon
@@ -0,0 +1,19 @@
+procedure main()
+
+ US_coins := [1, 5, 10, 25]
+ US_allcoins := [1,5,10,25,50,100]
+ EU_coins := [1, 2, 5, 10, 20, 50, 100, 200]
+ CDN_coins := [1,5,10,25,100,200]
+ CDN_allcoins := [1,5,10,25,50,100,200]
+
+ every trans := ![ [15,US_coins],
+ [100,US_coins],
+ [1000*100,US_allcoins]
+ ] do
+ printf("There are %i ways to count change for %i using %s coins.\n",CountCoins!trans,trans[1],ShowList(trans[2]))
+end
+
+procedure ShowList(L) # helper list to string
+every (s := "[ ") ||:= !L || " "
+return s || "]"
+end
diff --git a/Task/Count-the-coins/Icon/count-the-coins-2.icon b/Task/Count-the-coins/Icon/count-the-coins-2.icon
new file mode 100644
index 0000000000..5333ad76f1
--- /dev/null
+++ b/Task/Count-the-coins/Icon/count-the-coins-2.icon
@@ -0,0 +1,19 @@
+procedure CountCoins(amt,coins) # very slow, recurse by coin value
+local count
+static S
+
+if type(coins) == "list" then {
+ S := sort(set(coins))
+ if *S < 1 then runerr(205,coins)
+ return CountCoins(amt)
+ }
+else {
+ /coins := 1
+ if value := S[coins] then {
+ every (count := 0) +:= CountCoins(amt - (0 to amt by value), coins + 1)
+ return count
+ }
+ else
+ return (amt ~= 0) | 1
+ }
+end
diff --git a/Task/Count-the-coins/J/count-the-coins-1.j b/Task/Count-the-coins/J/count-the-coins-1.j
new file mode 100644
index 0000000000..e0484fe62c
--- /dev/null
+++ b/Task/Count-the-coins/J/count-the-coins-1.j
@@ -0,0 +1,4 @@
+merge=: ({:"1 (+/@:({."1),{:@{:)/. ])@;
+count=: {.@] <@,. {:@] - [ * [ i.@>:@<.@%~ {:@]
+init=: (1 ,. ,.)^:(0=#@$)
+nsplits=: 0 { [: +/ [: (merge@:(count"1) init)/ }.@/:~@~.@,
diff --git a/Task/Count-the-coins/J/count-the-coins-2.j b/Task/Count-the-coins/J/count-the-coins-2.j
new file mode 100644
index 0000000000..1094bcd1c7
--- /dev/null
+++ b/Task/Count-the-coins/J/count-the-coins-2.j
@@ -0,0 +1,2 @@
+ 100 nsplits 1 5 10 25
+242
diff --git a/Task/Count-the-coins/J/count-the-coins-3.j b/Task/Count-the-coins/J/count-the-coins-3.j
new file mode 100644
index 0000000000..c354a45443
--- /dev/null
+++ b/Task/Count-the-coins/J/count-the-coins-3.j
@@ -0,0 +1,2 @@
+ 100000 nsplits 1 5 10 25 50 100
+13398445413854501
diff --git a/Task/Count-the-coins/Mathematica/count-the-coins.mathematica b/Task/Count-the-coins/Mathematica/count-the-coins.mathematica
new file mode 100644
index 0000000000..e0f43c353c
--- /dev/null
+++ b/Task/Count-the-coins/Mathematica/count-the-coins.mathematica
@@ -0,0 +1,8 @@
+CountCoins[amount_, coinlist_] := ( ways = ConstantArray[1, amount];
+Do[For[j = coin, j <= amount, j++,
+ If[ j - coin == 0,
+ ways[[j]] ++,
+ ways[[j]] += ways[[j - coin]]
+]]
+, {coin, coinlist}];
+ways[[amount]])
diff --git a/Task/Count-the-coins/Mercury/count-the-coins.mercury b/Task/Count-the-coins/Mercury/count-the-coins.mercury
new file mode 100644
index 0000000000..dcdd60187b
--- /dev/null
+++ b/Task/Count-the-coins/Mercury/count-the-coins.mercury
@@ -0,0 +1,48 @@
+:- module coins.
+:- interface.
+:- import_module int, io.
+:- type coin ---> quarter; dime; nickel; penny.
+:- type purse ---> purse(int, int, int, int).
+
+:- pred sum_to(int::in, purse::out) is nondet.
+
+:- pred main(io::di, io::uo) is det.
+:- implementation.
+:- import_module solutions, list, string.
+
+:- func value(coin) = int.
+value(quarter) = 25.
+value(dime) = 10.
+value(nickel) = 5.
+value(penny) = 1.
+
+:- pred supply(coin::in, int::in, int::out) is multi.
+supply(C, Target, N) :- upto(Target div value(C), N).
+
+:- pred upto(int::in, int::out) is multi.
+upto(N, R) :- ( nondet_int_in_range(0, N, R0) -> R = R0 ; R = 0 ).
+
+sum_to(To, Purse) :-
+ Purse = purse(Q, D, N, P),
+ sum(Purse) = To,
+ supply(quarter, To, Q),
+ supply(dime, To, D),
+ supply(nickel, To, N),
+ supply(penny, To, P).
+
+:- func sum(purse) = int.
+sum(purse(Q, D, N, P)) =
+ value(quarter) * Q + value(dime) * D +
+ value(nickel) * N + value(penny) * P.
+
+main(!IO) :-
+ solutions(sum_to(100), L),
+ show(L, !IO),
+ io.format("There are %d ways to make change for a dollar.\n",
+ [i(length(L))], !IO).
+
+:- pred show(list(purse)::in, io::di, io::uo) is det.
+show([], !IO).
+show([P|T], !IO) :-
+ io.write(P, !IO), io.nl(!IO),
+ show(T, !IO).
diff --git a/Task/Create-a-file-on-magnetic-tape/JCL/create-a-file-on-magnetic-tape.jcl b/Task/Create-a-file-on-magnetic-tape/JCL/create-a-file-on-magnetic-tape.jcl
new file mode 100644
index 0000000000..b3e0378768
--- /dev/null
+++ b/Task/Create-a-file-on-magnetic-tape/JCL/create-a-file-on-magnetic-tape.jcl
@@ -0,0 +1,9 @@
+// EXEC PGM=IEBGENER
+//* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE"
+//* may vary depending on site-specific esoteric name assignment
+//SYSPRINT DD SYSOUT=*
+//SYSIN DD DUMMY
+//SYSUT2 DD UNIT=TAPE,DSN=TAPE.FILE,DISP=(,CATLG)
+//SYSUT1 DD *
+DATA TO BE WRITTEN TO TAPE
+/*
diff --git a/Task/Create-a-file/Factor/create-a-file.factor b/Task/Create-a-file/Factor/create-a-file.factor
new file mode 100644
index 0000000000..9ed1c648e9
--- /dev/null
+++ b/Task/Create-a-file/Factor/create-a-file.factor
@@ -0,0 +1,4 @@
+USE: io.directories
+
+"output.txt" "/output.txt" [ touch-file ] bi@
+"docs" "/docs" [ make-directory ] bi@
diff --git a/Task/Create-a-file/Fancy/create-a-file.fancy b/Task/Create-a-file/Fancy/create-a-file.fancy
new file mode 100644
index 0000000000..b753f7b7a3
--- /dev/null
+++ b/Task/Create-a-file/Fancy/create-a-file.fancy
@@ -0,0 +1,8 @@
+["/", "./"] each: |dir| {
+ # create '/docs', then './docs'
+ Directory create: (dir ++ "docs")
+ # create files /output.txt, then ./output.txt
+ File open: (dir ++ "output.txt") modes: ['write] with: |f| {
+ f writeln: "hello, world!"
+ }
+}
diff --git a/Task/Create-a-file/Groovy/create-a-file.groovy b/Task/Create-a-file/Groovy/create-a-file.groovy
new file mode 100644
index 0000000000..b927d2e577
--- /dev/null
+++ b/Task/Create-a-file/Groovy/create-a-file.groovy
@@ -0,0 +1,4 @@
+new File("output.txt").createNewFile()
+new File(File.separator + "output.txt").createNewFile()
+new File("docs").mkdir()
+new File(File.separator + "docs").mkdir()
diff --git a/Task/Create-a-file/HicEst/create-a-file.hicest b/Task/Create-a-file/HicEst/create-a-file.hicest
new file mode 100644
index 0000000000..5e62a8856c
--- /dev/null
+++ b/Task/Create-a-file/HicEst/create-a-file.hicest
@@ -0,0 +1,5 @@
+SYSTEM(DIR="\docs") ! create argument if not existent, make it current
+OPEN(FILE="output.txt", "NEW") ! in current directory
+
+SYSTEM(DIR="C:\docs") ! create C:\docs if not existent, make it current
+OPEN(FILE="output.txt", "NEW") ! in C:\docs
diff --git a/Task/Create-a-file/Icon/create-a-file.icon b/Task/Create-a-file/Icon/create-a-file.icon
new file mode 100644
index 0000000000..8d5608d594
--- /dev/null
+++ b/Task/Create-a-file/Icon/create-a-file.icon
@@ -0,0 +1,4 @@
+every dir := !["./","/"] do {
+ close(open(f := dir || "input.txt","w")) |stop("failure for open ",f)
+ mkdir(f := dir || "docs") |stop("failure for mkdir ",f)
+ }
diff --git a/Task/Create-a-file/J/create-a-file-1.j b/Task/Create-a-file/J/create-a-file-1.j
new file mode 100644
index 0000000000..c805293ee2
--- /dev/null
+++ b/Task/Create-a-file/J/create-a-file-1.j
@@ -0,0 +1,2 @@
+'' 1!:2 <'/output.txt' NB. write an empty file
+ 1!:5 <'/docs' NB. create a directory
diff --git a/Task/Create-a-file/J/create-a-file-2.j b/Task/Create-a-file/J/create-a-file-2.j
new file mode 100644
index 0000000000..d268ceb2a8
--- /dev/null
+++ b/Task/Create-a-file/J/create-a-file-2.j
@@ -0,0 +1,7 @@
+require 'files'
+NB. create two empty files named /output.txt and output.txt
+'' fwrite '/output.txt' ; 'output.txt'
+
+require 'general/dirutils' NB. addon package
+NB. create two directories: /docs and docs:
+dircreate '/docs' ; 'docs'
diff --git a/Task/Create-a-file/JCL/create-a-file.jcl b/Task/Create-a-file/JCL/create-a-file.jcl
new file mode 100644
index 0000000000..3f75e7f5ce
--- /dev/null
+++ b/Task/Create-a-file/JCL/create-a-file.jcl
@@ -0,0 +1,5 @@
+// EXEC PGM=IEFBR14
+//* CREATE EMPTY FILE NAMED "OUTPUT.TXT" (file names upper case only)
+//ANYNAME DD UNIT=SYSDA,SPACE=(0,0),DSN=OUTPUT.TXT,DISP=(,CATLG)
+//* CREATE DIRECTORY (PARTITIONED DATA SET) NAMED "DOCS"
+//ANYNAME DD UNIT=SYSDA,SPACE=(TRK,(1,1)),DSN=DOCS,DISP=(,CATLG)
diff --git a/Task/Create-a-file/K/create-a-file.k b/Task/Create-a-file/K/create-a-file.k
new file mode 100644
index 0000000000..a8efd2da06
--- /dev/null
+++ b/Task/Create-a-file/K/create-a-file.k
@@ -0,0 +1,4 @@
+ "output.txt" 1: ""
+ "/output.txt" 1: ""
+ \ mkdir docs
+ \ mkdir /docs
diff --git a/Task/Create-a-file/Liberty-BASIC/create-a-file.liberty b/Task/Create-a-file/Liberty-BASIC/create-a-file.liberty
new file mode 100644
index 0000000000..db42780481
--- /dev/null
+++ b/Task/Create-a-file/Liberty-BASIC/create-a-file.liberty
@@ -0,0 +1,12 @@
+nomainwin
+
+open "output.txt" for output as #f
+close #f
+
+result = mkdir( "F:\RC")
+if result <>0 then notice "Directory not created!": end
+
+open "F:\RC\output.txt" for output as #f
+close #f
+
+end
diff --git a/Task/Create-a-file/MAXScript/create-a-file.max b/Task/Create-a-file/MAXScript/create-a-file.max
new file mode 100644
index 0000000000..f850a38579
--- /dev/null
+++ b/Task/Create-a-file/MAXScript/create-a-file.max
@@ -0,0 +1,8 @@
+-- Here
+f = createFile "output.txt"
+close f
+makeDir (sysInfo.currentDir + "\docs")
+-- System root
+f = createFile "\output.txt"
+close f
+makeDir ("c:\docs")
diff --git a/Task/Create-a-file/Mathematica/create-a-file.mathematica b/Task/Create-a-file/Mathematica/create-a-file.mathematica
new file mode 100644
index 0000000000..9dbefdf7e2
--- /dev/null
+++ b/Task/Create-a-file/Mathematica/create-a-file.mathematica
@@ -0,0 +1,11 @@
+SetDirectory@NotebookDirectory[];
+t = OpenWrite["output.txt"]
+Close[t]
+s = OpenWrite[First@FileNameSplit[$InstallationDirectory] <> "\\output.txt"]
+Close[s]
+
+(*In root directory*)
+CreateDirectory["\\docs"]
+(*In current operating directory*)
+CreateDirectory[Directory[]<>"\\docs"]
+(* "<>" is shorthand for "StringJoin[left,right]" *)
diff --git a/Task/Create-a-file/Maxima/create-a-file.maxima b/Task/Create-a-file/Maxima/create-a-file.maxima
new file mode 100644
index 0000000000..ce0dc73d27
--- /dev/null
+++ b/Task/Create-a-file/Maxima/create-a-file.maxima
@@ -0,0 +1,9 @@
+f: openw("/output.txt");
+close(f);
+
+f: openw("output.txt");
+close(f);
+
+/* Maxima has no function to create directories, but one can use the underlying Lisp system */
+
+:lisp (mapcar #'ensure-directories-exist '("docs/" "/docs/"))
diff --git a/Task/Create-a-file/Mirah/create-a-file.mirah b/Task/Create-a-file/Mirah/create-a-file.mirah
new file mode 100644
index 0000000000..d158ec62e8
--- /dev/null
+++ b/Task/Create-a-file/Mirah/create-a-file.mirah
@@ -0,0 +1,5 @@
+import java.io.File
+
+File.new('output.txt').createNewFile()
+File.new('docs').mkdir()
+File.new("docs#{File.separator}output.txt").createNewFile()
diff --git a/Task/Create-a-file/Modula-3/create-a-file.mod3 b/Task/Create-a-file/Modula-3/create-a-file.mod3
new file mode 100644
index 0000000000..83ef3ada0b
--- /dev/null
+++ b/Task/Create-a-file/Modula-3/create-a-file.mod3
@@ -0,0 +1,18 @@
+MODULE FileCreation EXPORTS Main;
+
+IMPORT FS, File, OSError, IO, Stdio;
+
+VAR file: File.T;
+
+BEGIN
+ TRY
+ file := FS.OpenFile("output.txt");
+ file.close();
+ FS.CreateDirectory("docs");
+ file := FS.OpenFile("/output.txt");
+ file.close();
+ FS.CreateDirectory("/docs");
+ EXCEPT
+ | OSError.E => IO.Put("Error creating file or directory.\n", Stdio.stderr);
+ END;
+END FileCreation.
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Factor/create-a-two-dimensional-array-at-runtime.factor b/Task/Create-a-two-dimensional-array-at-runtime/Factor/create-a-two-dimensional-array-at-runtime.factor
new file mode 100644
index 0000000000..b57cf62ea1
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Factor/create-a-two-dimensional-array-at-runtime.factor
@@ -0,0 +1,14 @@
+USING: io kernel math.matrices math.parser prettyprint
+sequences ;
+IN: rosettacode.runtime2darray
+
+: set-Mi,j ( elt {i,j} matrix -- )
+[ first2 swap ] dip nth set-nth ;
+: Mi,j ( {i,j} matrix -- elt )
+[ first2 swap ] dip nth nth ;
+
+: example ( -- )
+readln readln [ string>number ] bi@ zero-matrix ! create the array
+[ [ 42 { 0 0 } ] dip set-Mi,j ] ! set the { 0 0 } element to 42
+[ [ { 0 0 } ] dip Mi,j . ] ! read the { 0 0 } element
+bi ;
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/GAP/create-a-two-dimensional-array-at-runtime.gap b/Task/Create-a-two-dimensional-array-at-runtime/GAP/create-a-two-dimensional-array-at-runtime.gap
new file mode 100644
index 0000000000..89bd294f5d
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/GAP/create-a-two-dimensional-array-at-runtime.gap
@@ -0,0 +1,15 @@
+# Creating an array of 0
+a := NullMat(2, 2);
+# [ [ 0, 0 ], [ 0, 0 ] ]
+
+# Some assignments
+a[1][1] := 4;
+a[1][2] := 5;
+a[2][1] := 3;
+a[2][2] := 4;
+
+a
+# [ [ 4, 5 ], [ 3, 4 ] ]
+
+Determinant(a);
+# 1
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Groovy/create-a-two-dimensional-array-at-runtime-1.groovy b/Task/Create-a-two-dimensional-array-at-runtime/Groovy/create-a-two-dimensional-array-at-runtime-1.groovy
new file mode 100644
index 0000000000..c7ee3ab15f
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Groovy/create-a-two-dimensional-array-at-runtime-1.groovy
@@ -0,0 +1,3 @@
+def make2d = { nrows, ncols ->
+ (0..
+ def nrows = dim[0] as int
+ def ncols = dim[1] as int
+
+ def a2d = make2d(nrows, ncols)
+
+ def row = r.nextInt(nrows)
+ def col = r.nextInt(ncols)
+ def val = r.nextInt(nrows*ncols)
+
+ a2d[row][col] = val
+
+ println "a2d[${row}][${col}] == ${a2d[row][col]}"
+
+ a2d.each { println it }
+ println()
+}
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/HicEst/create-a-two-dimensional-array-at-runtime.hicest b/Task/Create-a-two-dimensional-array-at-runtime/HicEst/create-a-two-dimensional-array-at-runtime.hicest
new file mode 100644
index 0000000000..a9e90f1b52
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/HicEst/create-a-two-dimensional-array-at-runtime.hicest
@@ -0,0 +1,7 @@
+REAL :: array(1)
+
+DLG(NameEdit=rows, NameEdit=cols, Button='OK', TItle='Enter array dimensions')
+
+ALLOCATE(array, cols, rows)
+array(1,1) = 1.234
+WRITE(Messagebox, Name) array(1,1)
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/IDL/create-a-two-dimensional-array-at-runtime.idl b/Task/Create-a-two-dimensional-array-at-runtime/IDL/create-a-two-dimensional-array-at-runtime.idl
new file mode 100644
index 0000000000..a86ddbc7b4
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/IDL/create-a-two-dimensional-array-at-runtime.idl
@@ -0,0 +1,9 @@
+read, x, prompt='Enter x size:'
+read, y, prompt='Enter y size:'
+d = fltarr(x,y)
+
+d[3,4] = 5.6
+print,d[3,4]
+;==> outputs 5.6
+
+delvar, d
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Icon/create-a-two-dimensional-array-at-runtime.icon b/Task/Create-a-two-dimensional-array-at-runtime/Icon/create-a-two-dimensional-array-at-runtime.icon
new file mode 100644
index 0000000000..9ec9b251c5
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Icon/create-a-two-dimensional-array-at-runtime.icon
@@ -0,0 +1,13 @@
+procedure main(args)
+ nr := integer(args[1]) | 3 # Default to 3x3
+ nc := integer(args[2]) | 3
+
+ A := list(nr)
+ every !A := list(nc)
+
+ x := ?nr # Select a random element
+ y := ?nc
+
+ A[x][y] := &pi
+ write("A[",x,"][",y,"] -> ",A[x][y])
+end
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-1.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-1.j
new file mode 100644
index 0000000000..21f8814cfe
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-1.j
@@ -0,0 +1,2 @@
+ array1=:i. 3 4 NB. a 3 by 4 array with arbitrary values
+ array2=: 5 6 $ 2 NB. a 5 by 6 array where every value is the number 2
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-2.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-2.j
new file mode 100644
index 0000000000..be10ae8265
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-2.j
@@ -0,0 +1 @@
+ array1=: 99 (<0 0)} array1
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-3.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-3.j
new file mode 100644
index 0000000000..83d56c37de
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-3.j
@@ -0,0 +1 @@
+ (<0 0) { array1
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-4.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-4.j
new file mode 100644
index 0000000000..05d5cd4db4
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-4.j
@@ -0,0 +1 @@
+ array1=: 0
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-5.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-5.j
new file mode 100644
index 0000000000..298c97038a
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-5.j
@@ -0,0 +1 @@
+ erase'array1'
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-6.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-6.j
new file mode 100644
index 0000000000..21eeece7ff
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-6.j
@@ -0,0 +1,9 @@
+task=: verb define
+ assert. y -: 0 0 + , y NB. error except when 2 dimensions are specified
+ INIT=. 0 NB. array will be populated with this value
+ NEW=. 1 NB. we will later update one location with this value
+ ARRAY=. y $ INIT NB. here, we create our 2-dimensional array
+ INDEX=. < ? $ ARRAY NB. pick an arbitrary location within our array
+ ARRAY=. NEW INDEX} ARRAY NB. use our new value at that location
+ INDEX { ARRAY NB. and return the value from that location
+)
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-7.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-7.j
new file mode 100644
index 0000000000..e031098f90
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-7.j
@@ -0,0 +1,2 @@
+ task 99 99
+1
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-8.j b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-8.j
new file mode 100644
index 0000000000..66373a1116
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/J/create-a-two-dimensional-array-at-runtime-8.j
@@ -0,0 +1,3 @@
+'init new' =. ' ';'x' NB. literals
+'init new' =. 1r2;2r3 NB. fractions
+'init new' =. a: ; <<'Rosetta' NB. boxes
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Liberty-BASIC/create-a-two-dimensional-array-at-runtime.liberty b/Task/Create-a-two-dimensional-array-at-runtime/Liberty-BASIC/create-a-two-dimensional-array-at-runtime.liberty
new file mode 100644
index 0000000000..c7df5e9a3c
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Liberty-BASIC/create-a-two-dimensional-array-at-runtime.liberty
@@ -0,0 +1,9 @@
+input "Enter first array dimension "; a
+input "Enter second array dimension "; b
+
+dim array( a, b)
+
+array( 1, 1) = 123.456
+print array( 1, 1)
+
+end
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Logo/create-a-two-dimensional-array-at-runtime.logo b/Task/Create-a-two-dimensional-array-at-runtime/Logo/create-a-two-dimensional-array-at-runtime.logo
new file mode 100644
index 0000000000..1d32f5ec12
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Logo/create-a-two-dimensional-array-at-runtime.logo
@@ -0,0 +1,3 @@
+make "a2 mdarray [5 5]
+mdsetitem [1 1] :a2 0 ; by default, arrays are indexed starting at 1
+print mditem [1 1] :a2 ; 0
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/MAXScript/create-a-two-dimensional-array-at-runtime.max b/Task/Create-a-two-dimensional-array-at-runtime/MAXScript/create-a-two-dimensional-array-at-runtime.max
new file mode 100644
index 0000000000..b1d94a2982
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/MAXScript/create-a-two-dimensional-array-at-runtime.max
@@ -0,0 +1,11 @@
+a = getKBValue prompt:"Enter first dimension:"
+b = getKBValue prompt:"Enter second dimension:"
+arr1 = #()
+arr2 = #()
+arr2[b] = undefined
+for i in 1 to a do
+(
+ append arr1 (deepCopy arr2)
+)
+arr1[a][b] = 1
+print arr1[a][b]
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/MUMPS/create-a-two-dimensional-array-at-runtime.mumps b/Task/Create-a-two-dimensional-array-at-runtime/MUMPS/create-a-two-dimensional-array-at-runtime.mumps
new file mode 100644
index 0000000000..8e3c9dcb34
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/MUMPS/create-a-two-dimensional-array-at-runtime.mumps
@@ -0,0 +1,11 @@
+ARA2D
+ NEW X,Y,A,I,J
+REARA
+ WRITE !,"Please enter two positive integers"
+ READ:10 !,"First: ",X
+ READ:10 !,"Second: ",Y
+ GOTO:(X\1'=X)!(X<0)!(Y\1'=Y)!(Y<0) REARA
+ FOR I=1:1:X FOR J=1:1:Y SET A(I,J)=I+J
+ WRITE !,"The corner of X and Y is ",A(X,Y)
+ KILL X,Y,A,I,J
+ QUIT
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Maple/create-a-two-dimensional-array-at-runtime.maple b/Task/Create-a-two-dimensional-array-at-runtime/Maple/create-a-two-dimensional-array-at-runtime.maple
new file mode 100644
index 0000000000..30ea4b7e1a
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Maple/create-a-two-dimensional-array-at-runtime.maple
@@ -0,0 +1,12 @@
+> a := Array( 1 .. 3, 1 .. 4 ): # initialised to 0s
+> a[1,1] := 1: # assign an element
+> a[2,3] := 4: # assign an element
+> a; # display the array
+ [1 0 0 0]
+ [ ]
+ [0 0 4 0]
+ [ ]
+ [0 0 0 0]
+
+> a := 'a': # unassign the name
+> gc(); # force a garbage collection; may or may not actually collect the array, but it will be eventually
diff --git a/Task/Create-a-two-dimensional-array-at-runtime/Mathematica/create-a-two-dimensional-array-at-runtime.mathematica b/Task/Create-a-two-dimensional-array-at-runtime/Mathematica/create-a-two-dimensional-array-at-runtime.mathematica
new file mode 100644
index 0000000000..b933a187fe
--- /dev/null
+++ b/Task/Create-a-two-dimensional-array-at-runtime/Mathematica/create-a-two-dimensional-array-at-runtime.mathematica
@@ -0,0 +1,4 @@
+arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
+ array[[1,1]]=RandomReal[];
+ array[[1,1]]
+]
diff --git a/Task/Create-an-HTML-table/Groovy/create-an-html-table.groovy b/Task/Create-an-HTML-table/Groovy/create-an-html-table.groovy
new file mode 100644
index 0000000000..b52afc6126
--- /dev/null
+++ b/Task/Create-an-HTML-table/Groovy/create-an-html-table.groovy
@@ -0,0 +1,20 @@
+import groovy.xml.MarkupBuilder
+
+def createTable(columns, rowCount) {
+ def writer = new StringWriter()
+ new MarkupBuilder(writer).table(style: 'border:1px solid;text-align:center;') {
+ tr {
+ th()
+ columns.each { title -> th(title)}
+ }
+ (1..rowCount).each { row ->
+ tr {
+ td(row)
+ columns.each { td((Math.random() * 9999) as int ) }
+ }
+ }
+ }
+ writer.toString()
+}
+
+println createTable(['X', 'Y', 'Z'], 3)
diff --git a/Task/Create-an-HTML-table/Icon/create-an-html-table-1.icon b/Task/Create-an-HTML-table/Icon/create-an-html-table-1.icon
new file mode 100644
index 0000000000..f461f0883f
--- /dev/null
+++ b/Task/Create-an-HTML-table/Icon/create-an-html-table-1.icon
@@ -0,0 +1,10 @@
+procedure main()
+printf("\n | X | Y | Z | ")
+every r := 1 to 4 do {
+ printf("
\n | %d | ",r)
+ every 1 to 3 do printf("%d | ",?9999) # random 4 digit numbers per cell
+ }
+printf("
\n
\n")
+end
+
+link printf
diff --git a/Task/Create-an-HTML-table/Icon/create-an-html-table-2.icon b/Task/Create-an-HTML-table/Icon/create-an-html-table-2.icon
new file mode 100644
index 0000000000..173b2e0f55
--- /dev/null
+++ b/Task/Create-an-HTML-table/Icon/create-an-html-table-2.icon
@@ -0,0 +1,7 @@
+
+ | X | Y | Z |
+ | 1 | 3129 | 3294 | 7013 |
+ | 2 | 5045 | 169 | 5761 |
+ | 3 | 7001 | 963 | 4183 |
+ | 4 | 1695 | 1158 | 1240 |
+
diff --git a/Task/Create-an-HTML-table/J/create-an-html-table-1.j b/Task/Create-an-HTML-table/J/create-an-html-table-1.j
new file mode 100644
index 0000000000..f12aa9c044
--- /dev/null
+++ b/Task/Create-an-HTML-table/J/create-an-html-table-1.j
@@ -0,0 +1,10 @@
+ele=:4 :0
+ nm=. x-.LF
+ lf=. x-.nm
+ ;('<',nm,'>') ,L:0 y ,L:0 '',nm,'>',lf
+)
+
+hTbl=:4 :0
+ rows=. 'td' <@ele"1 ":&.>y
+ 'table' ele ('tr',LF) <@ele ('th' ele x); rows
+)
diff --git a/Task/Create-an-HTML-table/J/create-an-html-table-2.j b/Task/Create-an-HTML-table/J/create-an-html-table-2.j
new file mode 100644
index 0000000000..9632196d7a
--- /dev/null
+++ b/Task/Create-an-HTML-table/J/create-an-html-table-2.j
@@ -0,0 +1,8 @@
+ ('';;:'X Y Z') hTbl ":&.>(i.5),.i.5 3
+ | X | Y | Z |
+| 0 | 0 | 1 | 2 |
+| 1 | 3 | 4 | 5 |
+| 2 | 6 | 7 | 8 |
+| 3 | 9 | 10 | 11 |
+| 4 | 12 | 13 | 14 |
+
diff --git a/Task/Create-an-HTML-table/J/create-an-html-table-3.j b/Task/Create-an-HTML-table/J/create-an-html-table-3.j
new file mode 100644
index 0000000000..a1f527d92b
--- /dev/null
+++ b/Task/Create-an-HTML-table/J/create-an-html-table-3.j
@@ -0,0 +1 @@
+jhtml ('';;:'X Y Z') hTbl ":&.>(i.5),.i.5 3
diff --git a/Task/Create-an-HTML-table/Liberty-BASIC/create-an-html-table.liberty b/Task/Create-an-HTML-table/Liberty-BASIC/create-an-html-table.liberty
new file mode 100644
index 0000000000..337a16b085
--- /dev/null
+++ b/Task/Create-an-HTML-table/Liberty-BASIC/create-an-html-table.liberty
@@ -0,0 +1,40 @@
+ nomainwin
+
+ quote$ =chr$( 34)
+
+ html$ =""
+
+ html$ =html$ +" | | X | Y | Z | "
+
+ for i =1 to 4
+ d1$ =str$( i)
+ d2$ =str$( int( 10000 *rnd( 1)))
+ d3$ =str$( int( 10000 *rnd( 1)))
+ d4$ =str$( int( 10000 *rnd( 1)))
+ html$ =html$ +" | "; d1$; " | " +d2$ +" | " +d3$ +" | " +d4$ +" |
"
+ next i
+
+ html$ =html$ +"
"
+
+ html$ =html$ +""
+
+ open "table.html" for output as #o
+ #o html$;
+ close #o
+
+ address$ ="table.html"
+ run "explorer.exe "; address$
+
+ timer 5000, [on]
+ wait
+ [on]
+ timer 0
+
+ kill "table.html"
+
+ wait
+
+sub quit w$
+ close #w$
+ end
+end sub
diff --git a/Task/Create-an-HTML-table/Mathematica/create-an-html-table.mathematica b/Task/Create-an-HTML-table/Mathematica/create-an-html-table.mathematica
new file mode 100644
index 0000000000..d92eebe26a
--- /dev/null
+++ b/Task/Create-an-HTML-table/Mathematica/create-an-html-table.mathematica
@@ -0,0 +1,4 @@
+x := RandomInteger[10];
+Print["", "\n"," | X | Y | Z |
"]
+Scan[Print["| ", #, " | ", x, " | ", x, " | "," |
"] & , Range[3]]
+Print["
"]
diff --git a/Task/Create-an-HTML-table/Modula-2/create-an-html-table.mod2 b/Task/Create-an-HTML-table/Modula-2/create-an-html-table.mod2
new file mode 100644
index 0000000000..9a769af1d4
--- /dev/null
+++ b/Task/Create-an-HTML-table/Modula-2/create-an-html-table.mod2
@@ -0,0 +1,47 @@
+MODULE testCGI;
+
+FROM InOut IMPORT WriteCard, WriteLn, WriteString, WriteBf;
+FROM Arguments IMPORT ArgTable, GetEnv;
+FROM Strings IMPORT Assign, Length, String;
+
+VAR EnvVars : ArgTable;
+
+PROCEDURE ReadEnvVar;
+
+VAR Value : String;
+ i : CARDINAL;
+
+BEGIN
+ WriteString ('');
+ WriteString ('| Index | Length | Content |
');
+ i := 0;
+ LOOP
+ IF EnvVars^ [i] = NIL THEN EXIT END;
+ Assign (Value, EnvVars^ [i]^);
+ WriteString ('| ');
+ WriteCard (i, 2);
+ WriteString (' | ');
+ WriteCard (Length (Value), 3);
+ WriteString (' | '); WriteString (Value);
+ WriteString (" |
");
+ WriteLn;
+ INC (i)
+ END;
+ WriteString("
");
+END ReadEnvVar;
+
+BEGIN
+ GetEnv (EnvVars);
+ WriteString ('Content-type:text/html');
+ WriteLn;
+ WriteLn;
+ WriteString ('');
+ WriteString ('CGI with the Mocka Modula-2 compiler');
+ WriteString ('');
+ WriteLn;
+ WriteString ('CGI environment passed along by your browser
');
+ ReadEnvVar;
+ WriteString ('');
+ WriteLn;
+ WriteBf
+END testCGI.
diff --git a/Task/Cut-a-rectangle/J/cut-a-rectangle-1.j b/Task/Cut-a-rectangle/J/cut-a-rectangle-1.j
new file mode 100644
index 0000000000..a8e8a46ad9
--- /dev/null
+++ b/Task/Cut-a-rectangle/J/cut-a-rectangle-1.j
@@ -0,0 +1,7 @@
+init=: - {. 1: NB. initial state: 1 square choosen
+prop=: < {:,~2 ~:/\ ] NB. propagate: neighboring squares (vertically)
+poss=: I.@,@(prop +. prop"1 +. prop&.|. +. prop&.|."1)
+keep=: poss -. <:@#@, - I.@, NB. symmetrically valid possibilities
+N=: <:@-:@#@, NB. how many neighbors to add
+step=: [: ~.@; <@(((= i.@$) +. ])"0 _~ keep)"2
+all=: step^:N@init
diff --git a/Task/Cut-a-rectangle/J/cut-a-rectangle-2.j b/Task/Cut-a-rectangle/J/cut-a-rectangle-2.j
new file mode 100644
index 0000000000..43b89f64d4
--- /dev/null
+++ b/Task/Cut-a-rectangle/J/cut-a-rectangle-2.j
@@ -0,0 +1,25 @@
+ '.#' <"2@:{~ all 3 4
+┌────┬────┬────┬────┬────┬────┬────┬────┬────┐
+│.###│.###│..##│...#│...#│....│....│....│....│
+│.#.#│..##│..##│..##│.#.#│..##│.#.#│#.#.│##..│
+│...#│...#│..##│.###│.###│####│####│####│####│
+└────┴────┴────┴────┴────┴────┴────┴────┴────┘
+ $ all 4 5
+39 4 5
+ 3 13$ '.#' <"2@:{~ all 4 5
+┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
+│.####│.####│.####│.####│.####│.####│..###│..###│..###│..###│..###│...##│...##│
+│.####│.##.#│.#..#│..###│...##│....#│.####│.##.#│..###│...##│....#│.####│..###│
+│....#│.#..#│.##.#│...##│..###│.####│....#│.#..#│...##│..###│.####│....#│...##│
+│....#│....#│....#│....#│....#│....#│...##│...##│...##│...##│...##│..###│..###│
+├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+│...##│...##│...##│....#│....#│....#│....#│....#│....#│.....│.....│.....│.....│
+│...##│....#│.#..#│.####│..###│...##│....#│.#..#│.##.#│.####│..###│...##│....#│
+│..###│.####│.##.#│....#│...##│..###│.####│.##.#│.#..#│....#│...##│..###│.####│
+│..###│..###│..###│.####│.####│.####│.####│.####│.####│#####│#####│#####│#####│
+├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│
+│.#..#│.##.#│..##.│...#.│.....│.#...│.##..│#.##.│#..#.│#....│##...│###..│####.│
+│.##.#│.#..#│#..##│#.###│#####│###.#│##..#│#..#.│#.##.│####.│###..│##...│#....│
+│#####│#####│#####│#####│#####│#####│#####│#####│#####│#####│#####│#####│#####│
+└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
diff --git a/Task/Date-format/Factor/date-format.factor b/Task/Date-format/Factor/date-format.factor
new file mode 100644
index 0000000000..d78e43924f
--- /dev/null
+++ b/Task/Date-format/Factor/date-format.factor
@@ -0,0 +1,4 @@
+USING: formatting calendar io ;
+
+now "%Y-%m-%d" strftime print
+now "%A, %B %d, %Y" strftime print
diff --git a/Task/Date-format/Fantom/date-format.fantom b/Task/Date-format/Fantom/date-format.fantom
new file mode 100644
index 0000000000..8c7bd34c37
--- /dev/null
+++ b/Task/Date-format/Fantom/date-format.fantom
@@ -0,0 +1,4 @@
+fansh> Date.today.toLocale("YYYY-MM-DD")
+2011-02-24
+fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY")
+Thursday, February 24, 2011
diff --git a/Task/Date-format/Frink/date-format.frink b/Task/Date-format/Frink/date-format.frink
new file mode 100644
index 0000000000..5c91979897
--- /dev/null
+++ b/Task/Date-format/Frink/date-format.frink
@@ -0,0 +1,2 @@
+println[now[] -> ### yyyy-MM-dd ###]
+println[now[] -> ### EEEE, MMMM d, yyyy ###]
diff --git a/Task/Date-format/Groovy/date-format-1.groovy b/Task/Date-format/Groovy/date-format-1.groovy
new file mode 100644
index 0000000000..df94b023ab
--- /dev/null
+++ b/Task/Date-format/Groovy/date-format-1.groovy
@@ -0,0 +1,2 @@
+def isoFormat = { date -> date.format("yyyy-MM-dd") }
+def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }
diff --git a/Task/Date-format/Groovy/date-format-2.groovy b/Task/Date-format/Groovy/date-format-2.groovy
new file mode 100644
index 0000000000..4db9b6176e
--- /dev/null
+++ b/Task/Date-format/Groovy/date-format-2.groovy
@@ -0,0 +1,3 @@
+def now = new Date()
+println isoFormat(now)
+println longFormat(now)
diff --git a/Task/Date-format/HicEst/date-format-1.hicest b/Task/Date-format/HicEst/date-format-1.hicest
new file mode 100644
index 0000000000..a6a2d0fa4b
--- /dev/null
+++ b/Task/Date-format/HicEst/date-format-1.hicest
@@ -0,0 +1,13 @@
+ CHARACTER string*40
+
+ WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13
+
+ ! the U-format to write date and time uses ',' to separate additional output formats
+ ! we therefore use ';' in this example and change it to ',' below:
+ WRITE(Text=string,Format='UWWWWWWWWW; MM DD; CCYY') 0 ! string = "Saturday ; 03 13; 2010"
+ READ(Text=string) month ! first numeric value = 3 (no literal month name available)
+ EDIT(Text='January,February,March,April,May,June,July,August,September,October,November,December', ITeM=month, Parse=cMonth) ! cMonth = "March"
+ ! change now string = "Saturday ; 03 13; 2010" to "Saturday, March 13, 2010":
+ EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',')
+
+ END
diff --git a/Task/Date-format/HicEst/date-format-2.hicest b/Task/Date-format/HicEst/date-format-2.hicest
new file mode 100644
index 0000000000..8065d906fd
--- /dev/null
+++ b/Task/Date-format/HicEst/date-format-2.hicest
@@ -0,0 +1,4 @@
+procedure main()
+write(map(&date,"/","-"))
+write(&dateline ? tab(find(&date[1:5])+4))
+end
diff --git a/Task/Date-format/J/date-format-1.j b/Task/Date-format/J/date-format-1.j
new file mode 100644
index 0000000000..1f26762e9b
--- /dev/null
+++ b/Task/Date-format/J/date-format-1.j
@@ -0,0 +1,2 @@
+ 6!:0 'YYYY-MM-DD'
+2010-08-19
diff --git a/Task/Date-format/J/date-format-2.j b/Task/Date-format/J/date-format-2.j
new file mode 100644
index 0000000000..490aafef8f
--- /dev/null
+++ b/Task/Date-format/J/date-format-2.j
@@ -0,0 +1,6 @@
+require 'dates system/packages/misc/datefmt.ijs'
+days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
+fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.]
+
+ fmtDate 6!:0 ''
+Thursday, August 19, 2010
diff --git a/Task/Date-format/Joy/date-format.joy b/Task/Date-format/Joy/date-format.joy
new file mode 100644
index 0000000000..337328869c
--- /dev/null
+++ b/Task/Date-format/Joy/date-format.joy
@@ -0,0 +1,9 @@
+DEFINE weekdays == [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
+ months == [ "January" "February" "March" "April" "May" "June" "July" "August"
+ "September" "October" "November" "December" ].
+
+time localtime [ [0 at 'd 4 4 format] ["-"] [1 at 'd 2 2 format] ["-"] [2 at 'd 2 2 format] ]
+[i] map [putchars] step '\n putch pop.
+
+time localtime [ [8 at pred weekdays of] [", "] [1 at pred months of] [" "] [2 at 'd 1 1 format]
+[", "] [0 at 'd 4 4 format] ] [i] map [putchars] step '\n putch pop.
diff --git a/Task/Date-format/Liberty-BASIC/date-format.liberty b/Task/Date-format/Liberty-BASIC/date-format.liberty
new file mode 100644
index 0000000000..bddf99b4f1
--- /dev/null
+++ b/Task/Date-format/Liberty-BASIC/date-format.liberty
@@ -0,0 +1,23 @@
+'Display the current date in the formats of "2007-11-10"
+d$=date$("yyyy/mm/dd")
+print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/")
+
+'and "Sunday, November 10, 2007".
+day$(0)="Tuesday"
+day$(1)="Wednesday"
+day$(2)="Thursday"
+day$(3)="Friday"
+day$(4)="Saturday"
+day$(5)="Sunday"
+day$(6)="Monday"
+theDay = date$("days") mod 7
+print day$(theDay);", ";date$()
+
+' month in full
+year=val(word$(d$,1,"/"))
+month=val(word$(d$,2,"/"))
+day=val(word$(d$,3,"/"))
+weekDay$="Tuesday Wednesday Thursday Friday Saturday Sunday Monday"
+monthLong$="January February March April May June July August September October November December"
+
+print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year
diff --git a/Task/Date-format/MUMPS/date-format-1.mumps b/Task/Date-format/MUMPS/date-format-1.mumps
new file mode 100644
index 0000000000..5010e2a68e
--- /dev/null
+++ b/Task/Date-format/MUMPS/date-format-1.mumps
@@ -0,0 +1,4 @@
+DTZ
+ WRITE !,"Date format 3: ",$ZDATE($H,3)
+ WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9)
+ QUIT
diff --git a/Task/Date-format/MUMPS/date-format-2.mumps b/Task/Date-format/MUMPS/date-format-2.mumps
new file mode 100644
index 0000000000..22f68bb234
--- /dev/null
+++ b/Task/Date-format/MUMPS/date-format-2.mumps
@@ -0,0 +1,21 @@
+DTM(H)
+ ;You can pass an integer, but the default is to use today's value
+ SET:$DATA(H)=0 H=$HOROLOG
+ NEW Y,YR,RD,MC,MO,DA,MN,DN,DOW
+ SET MN="January,February,March,April,May,June,July,August,September,October,November,December"
+ SET DN="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
+ SET MC="31,28,31,30,31,30,31,31,30,31,30,31"
+ SET Y=+H\365.25 ;This shouldn't be an approximation in production code
+ SET YR=Y+1841 ;Y is the offset from the epoch in years
+ SET RD=((+H-(Y*365.25))+1)\1 ;How far are we into the year?
+ SET $P(MC,",",2)=$S(((YR#4=0)&(YR#100'=0))!((YR#100=0)&(YR#400=0))=0:28,1:29) ;leap year correction
+ SET MO=1,RE=RD FOR QUIT:RE<=$P(MC,",",MO) SET RE=RE-$P(MC,",",MO),MO=MO+1
+ SET DA=RE+1
+ SET DOW=(H#7)+5 ;Fencepost issue - the first piece is 1
+ ;add padding as needed
+ SET:$L(MO)<2 MO="0"_MO
+ SET:$L(DA)<2 DA="0"_DA
+ WRITE !,YR,"-",MO,"-",DA
+ WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR
+ KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW
+ QUIT
diff --git a/Task/Date-format/Mathematica/date-format.mathematica b/Task/Date-format/Mathematica/date-format.mathematica
new file mode 100644
index 0000000000..56c945edf3
--- /dev/null
+++ b/Task/Date-format/Mathematica/date-format.mathematica
@@ -0,0 +1,2 @@
+DateString[{"Year", "-", "Month", "-", "Day"}]
+DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]
diff --git a/Task/Date-manipulation/Fantom/date-manipulation.fantom b/Task/Date-manipulation/Fantom/date-manipulation.fantom
new file mode 100644
index 0000000000..b6ba781dc8
--- /dev/null
+++ b/Task/Date-manipulation/Fantom/date-manipulation.fantom
@@ -0,0 +1,7 @@
+fansh> d := DateTime.fromLocale("March 7 2009 7:30pm EST", "MMMM D YYYY h:mmaa zzz")
+fansh> d
+2009-03-07T19:30:00-05:00 EST
+fansh> d + 12hr
+2009-03-08T07:30:00-05:00 EST
+fansh> (d+12hr).toTimeZone(TimeZone("London")) // the extra credit!
+2009-03-08T12:30:00Z London
diff --git a/Task/Date-manipulation/Frink/date-manipulation.frink b/Task/Date-manipulation/Frink/date-manipulation.frink
new file mode 100644
index 0000000000..c15753b6bd
--- /dev/null
+++ b/Task/Date-manipulation/Frink/date-manipulation.frink
@@ -0,0 +1,4 @@
+### MMM dd yyyy h:mma ###
+d = parseDate["March 7 2009 7:30pm EST"]
+println[d + 12 hours -> Eastern]
+println[d + 12 hours -> Switzerland] // Extra credit
diff --git a/Task/Date-manipulation/Groovy/date-manipulation.groovy b/Task/Date-manipulation/Groovy/date-manipulation.groovy
new file mode 100644
index 0000000000..8732a3f6cc
--- /dev/null
+++ b/Task/Date-manipulation/Groovy/date-manipulation.groovy
@@ -0,0 +1,12 @@
+import org.joda.time.*
+import java.text.*
+
+def dateString = 'March 7 2009 7:30pm EST'
+
+def sdf = new SimpleDateFormat('MMMM d yyyy h:mma zzz')
+
+DateTime dt = new DateTime(sdf.parse(dateString))
+
+println (dt)
+println (dt.plusHours(12))
+println (dt.plusHours(12).withZone(DateTimeZone.UTC))
diff --git a/Task/Date-manipulation/HicEst/date-manipulation.hicest b/Task/Date-manipulation/HicEst/date-manipulation.hicest
new file mode 100644
index 0000000000..ddac7e219f
--- /dev/null
+++ b/Task/Date-manipulation/HicEst/date-manipulation.hicest
@@ -0,0 +1,10 @@
+ CHARACTER date="March 7 2009 7:30pm EST", am_pm, result*20
+
+ EDIT(Text=date, Parse=cMonth, GetPosition=next)
+ month = 1 + EDIT(Text='January,February,March,April,May,June,July,August,September,October,November,December', Right=cMonth, Count=',' )
+ READ(Text=date(next:)) day, year, hour, minute, am_pm
+ hour = hour + 12*(am_pm == 'p')
+ TIME(MOnth=month, Day=day, Year=year, Hour=hour, MInute=minute, TO, Excel=xls_day)
+ WRITE(Text=result, Format="UWWW CCYY-MM-DD HH:mm") xls_day + 0.5
+ ! result = "Sun 2009-03-08 07:30"
+ END
diff --git a/Task/Date-manipulation/Icon/date-manipulation.icon b/Task/Date-manipulation/Icon/date-manipulation.icon
new file mode 100644
index 0000000000..9eb2d6774c
--- /dev/null
+++ b/Task/Date-manipulation/Icon/date-manipulation.icon
@@ -0,0 +1,66 @@
+link datetime
+
+procedure main()
+write("input = ",s := "March 7 2009 7:30pm EST" )
+write("+12 hours = ",SecToTZDateLine(s := TZDateLineToSec(s) + 12*3600,"EST"))
+write(" = ",SecToTZDateLine(s,"UTC"))
+write(" = ",SecToTZDateLine(s,"NST"))
+end
+
+procedure SecToTZDateLine(s,tz) #: returns dateline + time zone given seconds
+return NormalizedDate(SecToDateLine(s+\(_TZdata("table")[\tz|"UTC"]))||" "|| tz)
+end
+
+procedure TZDateLineToSec(s) #: returns seconds given dateline (and time zone)
+ return (
+ NormalizedDate(s) ? (
+ d := tab(find("am"|"pm")+2),tab(many('\t ,')),
+ tz := \_TZdata("table")[tab(0)]
+ ),
+ DateLineToSec(d) - tz)
+end
+
+procedure NormalizedDate(s) #: returns a consistent dateline
+static D,M
+initial {
+ D := ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]
+ M := ["January","February","March","April","May","June",
+ "July","August","September","October","November","December"]
+ }
+
+map(s) ? { # parse and build consistent dateline
+ ds := 1(x := !D, =map(x)) | "" # Weekday
+ ds ||:= 1(", ", tab(many('\t ,')|&pos))
+ ds ||:= 1(x := !M, =map(x)) | fail # Month
+ ds ||:= 1(" ", tab(many('\t ,')|&pos))
+ ds ||:= tab(many(&digits)) | fail # day
+ ds ||:= 1(", ", tab(many('\t ,'))) | fail
+ ds ||:= tab(many(&digits)) | fail # year
+ ds ||:= 1(" ", tab(many('\t ,'))) | fail
+ ds ||:= tab(many(&digits))||(=":"||tab(many(&digits))|&null) | fail # time
+ ds ||:= 1(" ", tab(many('\t ,')|&pos))
+ ds ||:= =("am"|"pm") | fail # halfday
+ ds ||:= 1(" ", tab(many('\t ,')|&pos))
+ tz := map(=!_TZdata("list"),&lcase,&ucase)
+ }
+
+if ds[1] == "," then
+ ds := SecToDateLine(DateLineToSec("Sunday"||ds)) # get IPL to fix weekday
+
+return ds ||:= " " || \tz|"UTC"
+end
+
+procedure _TZdata(x) #: internal return TZ data (demo version incomplete)
+static TZ,AZ
+initial {
+ TZ := table()
+ AZ := []
+ "UTC/0;ACDT/+10.5;CET/1;EST/-5;NPT/+5.75;NST/-3.5;PST/-8;" ?
+ while ( a := tab(find("/")), move(1), o := tab(find(";")), move(1) ) do {
+ TZ[map(a)] := TZ[a] := integer(3600*o)
+ put(AZ,a,map(a))
+ }
+ every TZ[&null|""] := TZ["UTC"]
+ }
+return case x of { "list" : AZ ; "table" : TZ }
+end
diff --git a/Task/Date-manipulation/Mathematica/date-manipulation.mathematica b/Task/Date-manipulation/Mathematica/date-manipulation.mathematica
new file mode 100644
index 0000000000..b9813d3f9b
--- /dev/null
+++ b/Task/Date-manipulation/Mathematica/date-manipulation.mathematica
@@ -0,0 +1,2 @@
+dstr = "March 7 2009 7:30pm EST";
+DateString[DatePlus[dstr, {12, "Hour"}], {"DayName", " ", "MonthName", " ", "Day", " ", "Year", " ", "Hour24", ":", "Minute", "AMPM"}]
diff --git a/Task/Day-of-the-week/Factor/day-of-the-week.factor b/Task/Day-of-the-week/Factor/day-of-the-week.factor
new file mode 100644
index 0000000000..7924c94913
--- /dev/null
+++ b/Task/Day-of-the-week/Factor/day-of-the-week.factor
@@ -0,0 +1,2 @@
+USING: calendar math.ranges prettyprint sequences ;
+2008 2121 [a,b] [ 12 25 sunday? ] filter .
diff --git a/Task/Day-of-the-week/GAP/day-of-the-week.gap b/Task/Day-of-the-week/GAP/day-of-the-week.gap
new file mode 100644
index 0000000000..b76532ba80
--- /dev/null
+++ b/Task/Day-of-the-week/GAP/day-of-the-week.gap
@@ -0,0 +1,13 @@
+xmas := function(a, b)
+ local y, v;
+ v := [ ];
+ for y in [a .. b] do
+ if WeekDay([25, 12, y]) = "Sun" then
+ Add(v, y);
+ fi;
+ od;
+ return v;
+end;
+
+xmas(2008, 2121);
+# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]
diff --git a/Task/Day-of-the-week/Groovy/day-of-the-week-1.groovy b/Task/Day-of-the-week/Groovy/day-of-the-week-1.groovy
new file mode 100644
index 0000000000..fb76159c14
--- /dev/null
+++ b/Task/Day-of-the-week/Groovy/day-of-the-week-1.groovy
@@ -0,0 +1 @@
+def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }
diff --git a/Task/Day-of-the-week/Groovy/day-of-the-week-2.groovy b/Task/Day-of-the-week/Groovy/day-of-the-week-2.groovy
new file mode 100644
index 0000000000..c183491436
--- /dev/null
+++ b/Task/Day-of-the-week/Groovy/day-of-the-week-2.groovy
@@ -0,0 +1 @@
+println yuletide(2008, 2121)
diff --git a/Task/Day-of-the-week/HicEst/day-of-the-week-1.hicest b/Task/Day-of-the-week/HicEst/day-of-the-week-1.hicest
new file mode 100644
index 0000000000..65b9f405d8
--- /dev/null
+++ b/Task/Day-of-the-week/HicEst/day-of-the-week-1.hicest
@@ -0,0 +1,6 @@
+DO year = 1, 1000000
+ TIME(Year=year, MOnth=12, Day=25, TO, WeekDay=weekday)
+ IF( weekday == 7) WRITE(StatusBar) year
+ENDDO
+
+END
diff --git a/Task/Day-of-the-week/HicEst/day-of-the-week-2.hicest b/Task/Day-of-the-week/HicEst/day-of-the-week-2.hicest
new file mode 100644
index 0000000000..2325d59a6f
--- /dev/null
+++ b/Task/Day-of-the-week/HicEst/day-of-the-week-2.hicest
@@ -0,0 +1,6 @@
+link datetime
+
+procedure main()
+writes("December 25th is a Sunday in: ")
+every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ")
+end
diff --git a/Task/Day-of-the-week/HicEst/day-of-the-week-3.hicest b/Task/Day-of-the-week/HicEst/day-of-the-week-3.hicest
new file mode 100644
index 0000000000..a001c8431e
--- /dev/null
+++ b/Task/Day-of-the-week/HicEst/day-of-the-week-3.hicest
@@ -0,0 +1,43 @@
+procedure dayoweek(day, month, year) #: day of the week
+ static d_code, c_code, m_code, ml_code, y, C, M, Y
+
+ initial {
+ d_code := ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
+
+ c_code := table()
+ c_code[16] := c_code[20] := 0
+ c_code[17] := c_code[21] := 6
+ c_code[18] := c_code[22] := 4
+ c_code[19] := c_code[23] := 2
+
+ m_code := table()
+ m_code[1] := m_code["January"] := 1
+ m_code[2] := m_code["February"] := 4
+ m_code[3] := m_code["March"] := 4
+ m_code[4] := m_code["April"] := 0
+ m_code[5] := m_code["May"] := 2
+ m_code[6] := m_code["June"] := 5
+ m_code[7] := m_code["July"] := 0
+ m_code[8] := m_code["August"] := 3
+ m_code[9] := m_code["September"] := 6
+ m_code[10] := m_code["October"] := 1
+ m_code[11] := m_code["November"] := 4
+ m_code[12] := m_code["December"] := 6
+
+ ml_code := copy(m_code)
+ ml_code[1] := ml_code["January"] := 0
+ ml_code[2] := ml_code["February"] := 3
+ }
+
+ if year < 1600 then stop("*** can't compute day of week that far back")
+ if year > 2299 then stop("*** can't compute day of week that far ahead")
+
+ C := c_code[(year / 100) + 1]
+ y := year % 100
+ Y := (y / 12) + (y % 12) + ((y % 12) / 4)
+ month := integer(month)
+ M := if (year % 4) = 0 then ml_code[month] else m_code[month]
+
+ return d_code[(C + Y + M + day) % 7 + 1]
+
+end
diff --git a/Task/Day-of-the-week/J/day-of-the-week.j b/Task/Day-of-the-week/J/day-of-the-week.j
new file mode 100644
index 0000000000..adfc6e0480
--- /dev/null
+++ b/Task/Day-of-the-week/J/day-of-the-week.j
@@ -0,0 +1,4 @@
+ load 'dates' NB. provides verb 'weekday'
+ xmasSunday=: #~ 0 = [: weekday 12 25 ,~"1 0 ] NB. returns years where 25 Dec is a Sunday
+ xmasSunday 2008 + i.114 NB. check years from 2008 to 2121
+2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
diff --git a/Task/Day-of-the-week/K/day-of-the-week.k b/Task/Day-of-the-week/K/day-of-the-week.k
new file mode 100644
index 0000000000..ac0f409d1d
--- /dev/null
+++ b/Task/Day-of-the-week/K/day-of-the-week.k
@@ -0,0 +1,3 @@
+ wd:{(__jd x)!7} / Julian day count, Sun=6
+ y@&6={wd 1225+x*10000}'y:2008+!114
+2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
diff --git a/Task/Day-of-the-week/Liberty-BASIC/day-of-the-week.liberty b/Task/Day-of-the-week/Liberty-BASIC/day-of-the-week.liberty
new file mode 100644
index 0000000000..c113f000de
--- /dev/null
+++ b/Task/Day-of-the-week/Liberty-BASIC/day-of-the-week.liberty
@@ -0,0 +1,14 @@
+ count = 0
+ for year = 2008 to 2121
+ dateString$="12/25/";year
+ dayNumber=date$(dateString$)
+
+ if dayNumber mod 7 = 5 then
+ count = count + 1
+ print dateString$
+ end if
+
+ next year
+
+ print count; " years when Christmas Day falls on a Sunday"
+ end
diff --git a/Task/Day-of-the-week/M4/day-of-the-week.m4 b/Task/Day-of-the-week/M4/day-of-the-week.m4
new file mode 100644
index 0000000000..2d8e4499d6
--- /dev/null
+++ b/Task/Day-of-the-week/M4/day-of-the-week.m4
@@ -0,0 +1,19 @@
+divert(-1)
+
+define(`for',
+ `ifelse($#,0,``$0'',
+ `ifelse(eval($2<=$3),1,
+ `pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')
+
+dnl julian day number corresponding to December 25th of given year
+define(`julianxmas',
+ `define(`yrssince0',eval($1+4712))`'define(`noOfLpYrs',
+ eval((yrssince0+3)/4))`'define(`jd',
+ eval(365*yrssince0+noOfLpYrs-10-($1-1501)/100+($1-1201)/400+334+25-1))`'
+ ifelse(eval($1%4==0 && ($1%100!=0 || $1%400==0)),1,
+ `define(`jd',incr(jd))')`'jd')
+
+divert
+
+for(`yr',2008,2121,
+ `ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')
diff --git a/Task/Day-of-the-week/MUMPS/day-of-the-week.mumps b/Task/Day-of-the-week/MUMPS/day-of-the-week.mumps
new file mode 100644
index 0000000000..d0bfdc7eca
--- /dev/null
+++ b/Task/Day-of-the-week/MUMPS/day-of-the-week.mumps
@@ -0,0 +1,19 @@
+DOWHOLIDAY
+ ;In what years between 2008 and 2121 will December 25 be a Sunday?
+ ;Uses the VA's public domain routine %DTC (Part of the Kernel) named here DIDTC
+ NEW BDT,EDT,CHECK,CHKFOR,LIST,I,X,Y
+ ;BDT - the beginning year to check
+ ;EDT - the end year to check
+ ;BDT and EDT are year offsets from the epoch date 1/1/1700
+ ;CHECK - the month and day to look at
+ ;CHKFOR - what day of the week to look for
+ ;LIST - list of years in which the condition is true
+ ;I - the year currently being checked
+ ;X - the date in an "internal" format, for input to DOW^DIDTC
+ ;Y - the output from DOW^DIDTC
+ SET BDT=308,EDT=421,CHECK="1225",CHKFOR=0,LIST=""
+ FOR I=BDT:1:EDT SET X=I_CHECK D DOW^DIDTC SET:(Y=0) LIST=$SELECT($LENGTH(LIST):LIST_", ",1:"")_(I+1700)
+ IF $LENGTH(LIST)=0 WRITE !,"There are no years that have Christmas on a Sunday in the given range."
+ IF $LENGTH(LIST) WRITE !,"The following years have Christmas on a Sunday: ",LIST
+ KILL BDT,EDT,CHECK,CHKFOR,LIST,I,X,Y
+ QUIT
diff --git a/Task/Day-of-the-week/Mathematica/day-of-the-week-1.mathematica b/Task/Day-of-the-week/Mathematica/day-of-the-week-1.mathematica
new file mode 100644
index 0000000000..6f7cc398ed
--- /dev/null
+++ b/Task/Day-of-the-week/Mathematica/day-of-the-week-1.mathematica
@@ -0,0 +1 @@
+Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
diff --git a/Task/Day-of-the-week/Mathematica/day-of-the-week-2.mathematica b/Task/Day-of-the-week/Mathematica/day-of-the-week-2.mathematica
new file mode 100644
index 0000000000..1a16992c7e
--- /dev/null
+++ b/Task/Day-of-the-week/Mathematica/day-of-the-week-2.mathematica
@@ -0,0 +1 @@
+{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}
diff --git a/Task/Day-of-the-week/Maxima/day-of-the-week.maxima b/Task/Day-of-the-week/Maxima/day-of-the-week.maxima
new file mode 100644
index 0000000000..1bf7ef38eb
--- /dev/null
+++ b/Task/Day-of-the-week/Maxima/day-of-the-week.maxima
@@ -0,0 +1,10 @@
+weekday(year, month, day) := block([m: month, y: year, k],
+ if m < 3 then (m: m + 12, y: y - 1),
+ k: 1 + remainder(day + quotient((m + 1)*26, 10) + y + quotient(y, 4)
+ + 6*quotient(y, 100) + quotient(y, 400) + 5, 7),
+ ['monday, 'tuesday, 'wednesday, 'thurdsday, 'friday, 'saturday, 'sunday][k]
+)$
+
+sublist(makelist(i, i, 2008, 2121),
+ lambda([y], weekday(y, 12, 25) = 'sunday));
+/* [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] */
diff --git a/Task/Day-of-the-week/Modula-3/day-of-the-week.mod3 b/Task/Day-of-the-week/Modula-3/day-of-the-week.mod3
new file mode 100644
index 0000000000..b4b07289ff
--- /dev/null
+++ b/Task/Day-of-the-week/Modula-3/day-of-the-week.mod3
@@ -0,0 +1,28 @@
+MODULE Yule EXPORTS Main;
+
+IMPORT IO, Fmt, Date, Time;
+
+VAR date: Date.T;
+ time: Time.T;
+
+BEGIN
+ FOR year := 2008 TO 2121 DO
+ date.day := 25;
+ date.month := Date.Month.Dec;
+ date.year := year;
+
+ TRY
+ time := Date.ToTime(date);
+ EXCEPT
+ | Date.Error =>
+ IO.Put(Fmt.Int(year) & " is the last year we can specify\n");
+ EXIT;
+ END;
+
+ date := Date.FromTime(time);
+
+ IF date.weekDay = Date.WeekDay.Sun THEN
+ IO.Put("25th of December " & Fmt.Int(year) & " is Sunday\n");
+ END;
+ END;
+END Yule.
diff --git a/Task/Deal-cards-for-FreeCell/Icon/deal-cards-for-freecell.icon b/Task/Deal-cards-for-FreeCell/Icon/deal-cards-for-freecell.icon
new file mode 100644
index 0000000000..d28a98afc5
--- /dev/null
+++ b/Task/Deal-cards-for-FreeCell/Icon/deal-cards-for-freecell.icon
@@ -0,0 +1,43 @@
+procedure main(A) # freecelldealer
+ freecelldealer(\A[1] | &null) # seed from command line
+end
+
+procedure newDeck() #: return a new unshuffled deck
+ every D := list(52) & i := 0 & r := !"A23456789TJQK" & s := !"CDHS" do
+ D[i +:= 1] := r || s # initial deck AC AD ... KS
+ return D
+end
+
+procedure freecelldealer(gamenum) #: deal a freecell hand
+ /gamenum := 11982
+ return showHand(freecellshuffle(newDeck(),gamenum))
+end
+
+procedure showHand(D) #: show a freecell hand
+ write("Hand:\n")
+ every writes(" ",(1 to 8) | "\n")
+ every writes(" ",D[i := 1 to *D]) do
+ if i%8 = 0 then write()
+ write("\n")
+ return D
+end
+
+procedure freecellshuffle(D,gamenum) #: freecell shuffle
+
+ srand_freecell(gamenum) # seed random number generator
+ D2 := []
+ until *D = 0 do { # repeat until all dealt
+ D[r := rand_freecell() % *D + 1] :=: D[*D] # swap random & last cards
+ put(D2,pull(D)) # remove dealt card from list
+ }
+ return D2
+end
+
+procedure srand_freecell(x) #: seed random
+static seed
+ return seed := \x | \seed | 0 # parm or seed or zero if none
+end
+
+procedure rand_freecell() #: lcrng
+ return ishift(srand_freecell((214013 * srand_freecell() + 2531011) % 2147483648),-16)
+end
diff --git a/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-1.j b/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-1.j
new file mode 100644
index 0000000000..9082d4fcd7
--- /dev/null
+++ b/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-1.j
@@ -0,0 +1,12 @@
+deck=: ,/ 'A23456789TJQK' ,"0/ 7 u: '♣♦♥♠'
+
+srnd=: 3 :'SEED=:{.y,11982'
+srnd ''
+seed=: do bind 'SEED'
+rnd=: (2^16) <.@%~ (2^31) srnd@| 2531011 + 214013 * seed
+
+pairs=: <@<@~.@(<: , (| rnd))@>:@i.@-@# NB. indices to swap, for shuffle
+swaps=: [: > C.&.>/@|.@; NB. implement the specified shuffle
+deal=: |.@(swaps pairs) bind deck
+
+show=: (,"2)@:(_8 ]\ ' '&,.)
diff --git a/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-2.j b/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-2.j
new file mode 100644
index 0000000000..4bfba78d0d
--- /dev/null
+++ b/Task/Deal-cards-for-FreeCell/J/deal-cards-for-freecell-2.j
@@ -0,0 +1,16 @@
+ show deal srnd 1
+ J♦ 2♦ 9♥ J♣ 5♦ 7♥ 7♣ 5♥
+ K♦ K♣ 9♠ 5♠ A♦ Q♣ K♥ 3♥
+ 2♠ K♠ 9♦ Q♦ J♠ A♠ A♥ 3♣
+ 4♣ 5♣ T♠ Q♥ 4♥ A♣ 4♦ 7♠
+ 3♠ T♦ 4♠ T♥ 8♥ 2♣ J♥ 7♦
+ 6♦ 8♠ 8♦ Q♠ 6♣ 3♦ 8♣ T♣
+ 6♠ 9♣ 2♥ 6♥
+ show deal srnd 617
+ 7♦ A♦ 5♣ 3♠ 5♠ 8♣ 2♦ A♥
+ T♦ 7♠ Q♦ A♣ 6♦ 8♥ A♠ K♥
+ T♥ Q♣ 3♥ 9♦ 6♠ 8♦ 3♦ T♣
+ K♦ 5♥ 9♠ 3♣ 8♠ 7♥ 4♦ J♠
+ 4♣ Q♠ 9♣ 9♥ 7♣ 6♥ 2♣ 2♠
+ 4♠ T♠ 2♥ 5♦ J♣ 6♣ J♥ Q♥
+ J♦ K♠ K♣ 4♥
diff --git a/Task/Death-Star/J/death-star-1.j b/Task/Death-Star/J/death-star-1.j
new file mode 100644
index 0000000000..ed24367538
--- /dev/null
+++ b/Task/Death-Star/J/death-star-1.j
@@ -0,0 +1,39 @@
+mag =: +/&.:*:"1
+norm=: %"1 0 mag
+dot =: +/@:*"1
+
+NB. (pos;posr;neg;negr) getvec (x,y)
+getvec =: 4 :0 "1
+ pt =. y
+ 'pos posr neg negr' =. x
+ if. (dot~ pt-}:pos) > *:posr do.
+ 0 0 0
+ else.
+ zb =. ({:pos) (-,+) posr -&.:*: pt mag@:- }:pos
+ if. (dot~ pt-}:neg) > *:negr do.
+ (pt,{:zb) - pos
+ else.
+ zs =. ({:neg) (-,+) negr -&.:*: pt mag@:- }:neg
+ if. zs >&{. zb do. (pt,{:zb) - pos
+ elseif. zs >&{: zb do. 0 0 0
+ elseif. ({.zs) < ({:zb) do. neg - (pt,{.zs)
+ elseif. do. (pt,{.zb) - pos end.
+ end.
+ end.
+)
+
+
+NB. (k;ambient;light) draw_sphere (pos;posr;neg;negr)
+draw_sphere =: 4 :0
+ 'pos posr neg negr' =. y
+ 'k ambient light' =. x
+ vec=. norm y getvec ,"0// (2{.pos) +/ i: 200 j.~ 0.5+posr
+
+ b=. (mag vec) * ambient + k * 0>. light dot vec
+)
+
+togray =: 256#. 255 255 255 <.@*"1 0 (%>./@,)
+
+env=.(2; 0.5; (norm _50 30 50))
+sph=. 20 20 0; 20; 1 1 _6; 20
+'rgb' viewmat togray env draw_sphere sph
diff --git a/Task/Death-Star/J/death-star-2.j b/Task/Death-Star/J/death-star-2.j
new file mode 100644
index 0000000000..f46325be75
--- /dev/null
+++ b/Task/Death-Star/J/death-star-2.j
@@ -0,0 +1,54 @@
+load'graphics/viewmat'
+
+resolution=: 8
+spheres=: 3 1 #"1 ] 0 1,_1 1,:0.3 0.6 NB. spheres x y z r
+
+
+coordinates=: (% <:)~ (,"1 0~"0 3 ,"0"1 0~)@:i:
+length=: +/ &.: *:
+centers=: _ 3&{.
+radii=: _ _1&{.
+
+NB. resolution SlicePittedSphere spheres generates a binary array, 1 in the geometric object
+SlicePittedSphere=: (0 { {. > [: +./ }.)@:(radii@[ >:"0 3 ((length@:-"1"_ 1 centers)~ coordinates))~
+
+spanTo=: conjunction def '(m<:y)*.y<:n' NB. algebraic similarity, m <= y <= n
+
+tessellate=: ] ];._3"3~ 3 # [ NB. All cubical edge length x subarrays of array y
+
+NB. Define "faces" as those points with 9 to 18 inclusive "solid" neighbors.
+detectFace=: (9 spanTo 18) @: (+/@:,"3) @: (3&tessellate)
+
+NB. arrange faces in ANSYS brick face order
+ThickFaces=: ((|:"3 , (, |:"2))(,: |."1)3 3 3$2j1#1) /: 'SENWDU' i. 'DUEWSN'
+ThinFaces=: ((|:"3 , (, |:"2))(,: |."1)3 3 3$1j2#1) /: 'SENWDU' i. 'DUEWSN'
+
+FACES=:ThickFaces NB. 6 below comes from #Faces
+
+NORMALS=: 2 tessellate FACES
+
+matchNormals=: [: +/@,"6 NORMALS ="6"6 _ (2 tessellate 3 tessellate ])
+
+bestFit=: (i.>./)"1&.|:
+
+topFace=: detectFace i:"1 1:
+
+choose=: 4 : 'x}y'
+
+viewmat resolution (topFace choose (,&(#FACES))@:bestFit@matchNormals)@SlicePittedSphere spheres
+
+
+ <"_1 ThickFaces NB. display the 6 cubes with reference faces
+┌─────┬─────┬─────┬─────┬─────┬─────┐
+│1 1 1│1 1 0│0 0 0│0 1 1│1 1 1│0 0 0│
+│1 1 1│1 1 0│1 1 1│0 1 1│1 1 1│0 0 0│
+│0 0 0│1 1 0│1 1 1│0 1 1│1 1 1│0 0 0│
+│ │ │ │ │ │ │
+│1 1 1│1 1 0│0 0 0│0 1 1│1 1 1│1 1 1│
+│1 1 1│1 1 0│1 1 1│0 1 1│1 1 1│1 1 1│
+│0 0 0│1 1 0│1 1 1│0 1 1│1 1 1│1 1 1│
+│ │ │ │ │ │ │
+│1 1 1│1 1 0│0 0 0│0 1 1│0 0 0│1 1 1│
+│1 1 1│1 1 0│1 1 1│0 1 1│0 0 0│1 1 1│
+│0 0 0│1 1 0│1 1 1│0 1 1│0 0 0│1 1 1│
+└─────┴─────┴─────┴─────┴─────┴─────┘
diff --git a/Task/Death-Star/LSL/death-star.lsl b/Task/Death-Star/LSL/death-star.lsl
new file mode 100644
index 0000000000..32c8084e3e
--- /dev/null
+++ b/Task/Death-Star/LSL/death-star.lsl
@@ -0,0 +1,14 @@
+default {
+ state_entry() {
+ llSetPrimitiveParams([PRIM_NAME, "RosettaCode DeathStar"]);
+ llSetPrimitiveParams([PRIM_DESC, llGetObjectName()]);
+ llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_SPHERE, PRIM_HOLE_CIRCLE, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <0.12, 1.0, 0.0>]);
+ llSetPrimitiveParams([PRIM_ROTATION, <-0.586217, 0.395411, -0.586217, 0.395411>]);
+ llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, TEXTURE_BLANK, ZERO_VECTOR, ZERO_VECTOR, 0.0]);
+ llSetPrimitiveParams([PRIM_TEXT, llGetObjectName(), <1.0, 1.0, 1.0>, 1.0]);
+ llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <0.5, 0.5, 0.5>, 1.0]);
+ llSetPrimitiveParams([PRIM_BUMP_SHINY, ALL_SIDES, PRIM_SHINY_HIGH, PRIM_BUMP_NONE]);
+ llSetPrimitiveParams([PRIM_SIZE, <10.0, 10.0, 10.0>]);
+ llSetPrimitiveParams([PRIM_OMEGA, <0.0, 0.0, 1.0>, 1.0, 1.0]);
+ }
+}
diff --git a/Task/Death-Star/Mathematica/death-star.mathematica b/Task/Death-Star/Mathematica/death-star.mathematica
new file mode 100644
index 0000000000..aef1d1bce1
--- /dev/null
+++ b/Task/Death-Star/Mathematica/death-star.mathematica
@@ -0,0 +1,3 @@
+RegionPlot3D[x^2 + y^2 + z^2 < 1 && (x + 1.7)^2 + y^2 + z^2 > 1,
+{x, -1, 1}, {y, -1, 1}, {z, -1, 1},
+Boxed -> False, Mesh -> False, Axes -> False, Background -> Black, PlotPoints -> 100]
diff --git a/Task/Deconvolution-1D/J/deconvolution-1d-1.j b/Task/Deconvolution-1D/J/deconvolution-1d-1.j
new file mode 100644
index 0000000000..ba6dc4b4da
--- /dev/null
+++ b/Task/Deconvolution-1D/J/deconvolution-1d-1.j
@@ -0,0 +1,2 @@
+Ai=: (i.@] =/ i.@[ -/ i.@>:@-)
+divide=: [ +/ .*~ [:%.&.x: ] +/ .* Ai
diff --git a/Task/Deconvolution-1D/J/deconvolution-1d-2.j b/Task/Deconvolution-1D/J/deconvolution-1d-2.j
new file mode 100644
index 0000000000..4f2e7f5036
--- /dev/null
+++ b/Task/Deconvolution-1D/J/deconvolution-1d-2.j
@@ -0,0 +1,3 @@
+h=: _8 _9 _3 _1 _6 7
+f=: _3 _6 _1 8 _6 3 _1 _9 _9 3 _2 5 2 _2 _7 _1
+g=: 24 75 71 _34 3 22 _45 23 245 25 52 25 _67 _96 96 31 55 36 29
diff --git a/Task/Deconvolution-1D/J/deconvolution-1d-3.j b/Task/Deconvolution-1D/J/deconvolution-1d-3.j
new file mode 100644
index 0000000000..3eddb462fa
--- /dev/null
+++ b/Task/Deconvolution-1D/J/deconvolution-1d-3.j
@@ -0,0 +1,4 @@
+ g divide f
+_8 _9 _3 _1 _6 7
+ g divide h
+_3 _6 _1 8 _6 3 _1 _9 _9 3 _2 5 2 _2 _7 _1
diff --git a/Task/Deconvolution-1D/J/deconvolution-1d-4.j b/Task/Deconvolution-1D/J/deconvolution-1d-4.j
new file mode 100644
index 0000000000..176e6bce7d
--- /dev/null
+++ b/Task/Deconvolution-1D/J/deconvolution-1d-4.j
@@ -0,0 +1 @@
+divide=: [ +/ .*~ [:%. ] +/ .* Ai
diff --git a/Task/Deconvolution-1D/Mathematica/deconvolution-1d.mathematica b/Task/Deconvolution-1D/Mathematica/deconvolution-1d.mathematica
new file mode 100644
index 0000000000..972f3b6bab
--- /dev/null
+++ b/Task/Deconvolution-1D/Mathematica/deconvolution-1d.mathematica
@@ -0,0 +1,5 @@
+deconv[f_List, g_List] :=
+ Module[{A =
+ SparseArray[
+ Table[Band[{n, 1}] -> f[[n]], {n, 1, Length[f]}], {Length[g], Length[f] - 1}]},
+ Take[LinearSolve[A, g], Length[g] - Length[f] + 1]]
diff --git a/Task/Deconvolution-2D+/J/deconvolution-2d+-1.j b/Task/Deconvolution-2D+/J/deconvolution-2d+-1.j
new file mode 100644
index 0000000000..0042fa668b
--- /dev/null
+++ b/Task/Deconvolution-2D+/J/deconvolution-2d+-1.j
@@ -0,0 +1,9 @@
+deconv3 =: 4 : 0
+ sz =. x >:@-&$ y NB. shape of z
+ poi =. ,<"1 ($y) ,"0/&(,@i.) sz NB. pair of indexes
+ t=. /: sc=: , <@(+"1)/&(#: ,@i.)/ ($y),:sz NB. order of ,y
+ T0=. (<"0,x) ,:~ (]/:"1 {.)&.> (<, y) ({:@] ,: ({"1~ {.))&.> sc <@|:@:>/.&(t&{) poi NB. set of boxed equations
+ T1=. (,x),.~(<0 #~ */sz) (({:@])`({.@])`[})&> {.T0 NB. set of linear equations
+ sz $ 1e_8 round ({:"1 %. }:"1) T1
+)
+round=: [ * <.@%~
diff --git a/Task/Deconvolution-2D+/J/deconvolution-2d+-2.j b/Task/Deconvolution-2D+/J/deconvolution-2d+-2.j
new file mode 100644
index 0000000000..2334c251d7
--- /dev/null
+++ b/Task/Deconvolution-2D+/J/deconvolution-2d+-2.j
@@ -0,0 +1,57 @@
+h1=: _8 2 _9 _2 9 _8 _2
+f1=: 6 _9 _7 _5
+g1=: _48 84 _16 95 125 _70 7 29 54 10
+
+h2=: ".;._2]0 :0
+ _8 1 _7 _2 _9 4
+ 4 5 _5 2 7 _1
+ _6 _3 _3 _6 9 5
+)
+
+f2=: ".;._2]0 :0
+ _5 2 _2 _6 _7
+ 9 7 _6 5 _7
+ 1 _1 9 2 _7
+ 5 9 _9 2 _5
+ _8 5 _2 8 5
+)
+
+g2=: ".;._2]0 :0
+ 40 _21 53 42 105 1 87 60 39 _28
+ _92 _64 19 _167 _71 _47 128 _109 40 _21
+ 58 85 _93 37 101 _14 5 37 _76 _56
+ _90 _135 60 _125 68 53 223 4 _36 _48
+ 78 16 7 _199 156 _162 29 28 _103 _10
+ _62 _89 69 _61 66 193 _61 71 _8 _30
+ 48 _6 21 _9 _150 _22 _56 32 85 25
+)
+
+h3=: ".;._1;._2]0 :0
+/ _6 _8 _5 9/ _7 9 _6 _8/ 2 _7 9 8
+/ 7 4 4 _6/ 9 9 4 _4/ _3 7 _2 _3
+)
+
+f3=: ".;._1;._2]0 :0
+/ _9 5 _8/ 3 5 1
+/ _1 _7 2/ _5 _6 6
+/ 8 5 8/_2 _6 _4
+)
+
+g3=: ".;._2;._1]0 :0
+/ 54 42 53 _42 85 _72
+ 45 _170 94 _36 48 73
+ _39 65 _112 _16 _78 _72
+ 6 _11 _6 62 49 8
+/ _57 49 _23 52 _135 66
+ _23 127 _58 _5 _118 64
+ 87 _16 121 23 _41 _12
+ _19 29 35 _148 _11 45
+/ _55 _147 _146 _31 55 60
+ _88 _45 _28 46 _26 _144
+ _12 _107 _34 150 249 66
+ 11 _15 _34 27 _78 _50
+/ 56 67 108 4 2 _48
+ 58 67 89 32 32 _8
+ _42 _31 _103 _30 _23 _8
+ 6 4 _26 _10 26 12
+)
diff --git a/Task/Deconvolution-2D+/J/deconvolution-2d+-3.j b/Task/Deconvolution-2D+/J/deconvolution-2d+-3.j
new file mode 100644
index 0000000000..8601c56391
--- /dev/null
+++ b/Task/Deconvolution-2D+/J/deconvolution-2d+-3.j
@@ -0,0 +1,6 @@
+ h1 -: g1 deconv3 f1
+1
+ h2 -: g2 deconv3 f2
+1
+ h3 -: g3 deconv3 f3 NB. -: checks for matching structure and data
+1
diff --git a/Task/Deconvolution-2D+/Mathematica/deconvolution-2d+.mathematica b/Task/Deconvolution-2D+/Mathematica/deconvolution-2d+.mathematica
new file mode 100644
index 0000000000..d723568d9e
--- /dev/null
+++ b/Task/Deconvolution-2D+/Mathematica/deconvolution-2d+.mathematica
@@ -0,0 +1,14 @@
+Round[ListDeconvolve[{6, -9, -7, -5}, {-48, 84, -16, 95, 125, -70, 7, 29, 54, 10}, Method -> "Wiener"]]
+
+Round[ListDeconvolve[{{-5, 2, -2, -6, -7}, {9, 7, -6, 5, -7}, {1, -1, 9, 2, -7}, {5, 9, -9, 2, -5}, {-8, 5, -2, 8, 5}},
+{{40, -21, 53, 42, 105, 1, 87, 60, 39, -28}, {-92, -64, 19, -167, -71, -47, 128, -109, 40, -21},
+{58, 85, -93, 37, 101, -14, 5, 37, -76, -56}, {-90, -135, 60, -125, 68, 53, 223, 4, -36, -48},
+{78, 16, 7, -199, 156, -162, 29, 28, -103, -10}, {-62, -89, 69, -61, 66, 193, -61, 71, -8, -30},
+{48, -6, 21, -9, -150, -22, -56, 32, 85, 25}}, Method -> "Wiener"]]
+
+Round[ListDeconvolve [{{{-9, 5, -8}, {3, 5, 1}}, {{-1, -7, 2}, {-5, -6, 6}}, {{8, 5, 8}, {-2, -6, -4}}},
+{{{54, 42, 53, -42, 85, -72}, {45, -170, 94, -36, 48, 73}, {-39, 65, -112, -16, -78, -72},
+{6, -11, -6, 62, 49, 8}}, {{-57, 49, -23, 52, -135, 66}, {-23, 127, -58, -5, -118, 64}, {87, -16, 121, 23, -41, -12},
+{-19, 29, 35, -148, -11, 45}}, {{-55, -147, -146, -31, 55, 60}, {-88, -45, -28, 46, -26, -144},
+{-12, -107, -34, 150, 249, 66}, {11, -15, -34, 27, -78, -50}}, {{56, 67, 108, 4, 2, -48}, {58, 67, 89, 32, 32, -8},
+{-42, -31, -103, -30, -23, -8}, {6, 4, -26, -10, 26, 12}}}, Method -> "Wiener"]]
diff --git a/Task/Deepcopy/Icon/deepcopy-1.icon b/Task/Deepcopy/Icon/deepcopy-1.icon
new file mode 100644
index 0000000000..110f5ee4d7
--- /dev/null
+++ b/Task/Deepcopy/Icon/deepcopy-1.icon
@@ -0,0 +1,24 @@
+procedure deepcopy(A, cache) #: return a deepcopy of A
+ local k
+
+ /cache := table() # used to handle multireferenced objects
+ if \cache[A] then return cache[A]
+
+ case type(A) of {
+ "table"|"list": {
+ cache[A] := copy(A)
+ every cache[A][k := key(A)] := deepcopy(A[k], cache)
+ }
+ "set": {
+ cache[A] := set()
+ every insert(cache[A], deepcopy(!A, cache))
+ }
+ default: { # records and objects (encoded as records)
+ cache[A] := copy(A)
+ if match("record ",image(A)) then {
+ every cache[A][k := key(A)] := deepcopy(A[k], cache)
+ }
+ }
+ }
+ return .cache[A]
+end
diff --git a/Task/Deepcopy/Icon/deepcopy-2.icon b/Task/Deepcopy/Icon/deepcopy-2.icon
new file mode 100644
index 0000000000..8cc89244ce
--- /dev/null
+++ b/Task/Deepcopy/Icon/deepcopy-2.icon
@@ -0,0 +1,54 @@
+link printf,ximage
+
+procedure main()
+
+ knot := makeknot() # create a structure with loops
+ knota := knot # copy by assignment (reference)
+ knotc := copy(knot) # built-in copy (shallow)
+ knotdc := deepcopy(knot) # deep copy
+
+
+ showdeep("knota (assignment) vs. knot",knota,knot)
+ showdeep("knotc (copy) vs. knot",knotc,knot)
+ showdeep("knotdc (deepcopy) vs. knot",knotdc,knot)
+
+ xdump("knot (original)",knot)
+ xdump("knota (assignment)",knota)
+ xdump("knotc (copy)",knotc)
+ xdump("knotdc (deepcopy)",knotdc)
+end
+
+record rec1(a,b,c) # record for example
+
+class Class1(a1,a2) # class - looks like a record under the covers
+ method one()
+ self.a1 := 1
+ return
+ end
+initially
+ self.a1 := 0
+end
+
+
+procedure makeknot() #: return a homogeneous structure with loops
+ L := [9,8,7]
+ T := table()
+ T["a"] := 1
+ R := rec1(T)
+ S := set(R)
+ C := Class1()
+ C.one()
+ T["knot"] := [L,R,S,C]
+ put(L,R,S,T,C)
+ return L
+end
+
+procedure showdeep(tag,XC,X) #: demo to show (non-)equivalence of list elements
+ printf("Analysis of copy depth for %s:\n",tag)
+ showequiv(XC,X)
+ every showequiv(XC[i := 1 to *X],X[i])
+end
+
+procedure showequiv(x,y) #: show (non-)equivalence of two values
+ return printf(" %i %s %i\n",x,if x === y then "===" else "~===",y)
+end
diff --git a/Task/Deepcopy/J/deepcopy.j b/Task/Deepcopy/J/deepcopy.j
new file mode 100644
index 0000000000..9e1a922c65
--- /dev/null
+++ b/Task/Deepcopy/J/deepcopy.j
@@ -0,0 +1,6 @@
+ a=:b=: 2 2 2 2 2 NB. two copies of the same array
+ b=: 3 (2)} b NB. modify one of the arrays
+ b
+2 2 3 2 2
+ a
+2 2 2 2 2
diff --git a/Task/Define-a-primitive-data-type/Modula-3/define-a-primitive-data-type.mod3 b/Task/Define-a-primitive-data-type/Modula-3/define-a-primitive-data-type.mod3
new file mode 100644
index 0000000000..e5a323c0e6
--- /dev/null
+++ b/Task/Define-a-primitive-data-type/Modula-3/define-a-primitive-data-type.mod3
@@ -0,0 +1 @@
+TYPE MyInt = [1..10];
diff --git a/Task/Delegates/J/delegates-1.j b/Task/Delegates/J/delegates-1.j
new file mode 100644
index 0000000000..5bdf5b7038
--- /dev/null
+++ b/Task/Delegates/J/delegates-1.j
@@ -0,0 +1,13 @@
+coclass 'delegator'
+ operation=:3 :'thing__delegate ::thing y'
+ thing=: 'default implementation'"_
+ setDelegate=:3 :'delegate=:y' NB. result is the reference to our new delegate
+ delegate=:<'delegator'
+
+coclass 'delegatee1'
+
+coclass 'delegatee2'
+ thing=: 'delegate implementation'"_
+
+NB. set context in case this script was used interactively, instead of being loaded
+cocurrent 'base'
diff --git a/Task/Delegates/J/delegates-2.j b/Task/Delegates/J/delegates-2.j
new file mode 100644
index 0000000000..dc736634be
--- /dev/null
+++ b/Task/Delegates/J/delegates-2.j
@@ -0,0 +1,15 @@
+ obj=:conew'delegator'
+ operation__obj''
+default implementation
+ setDelegate__obj conew'delegatee1'
+┌─┐
+│4│
+└─┘
+ operation__obj''
+default implementation
+ setDelegate__obj conew'delegatee2'
+┌─┐
+│5│
+└─┘
+ operation__obj''
+delegate implementation
diff --git a/Task/Delegates/Logtalk/delegates.logtalk b/Task/Delegates/Logtalk/delegates.logtalk
new file mode 100644
index 0000000000..8077ca26fe
--- /dev/null
+++ b/Task/Delegates/Logtalk/delegates.logtalk
@@ -0,0 +1,76 @@
+% define a category for holding the interface
+% and implementation for delegator objects
+
+:- category(delegator).
+
+ :- public(delegate/1).
+ :- public(set_delegate/1).
+
+ :- private(delegate_/1).
+ :- dynamic(delegate_/1).
+
+ delegate(Delegate) :-
+ ::delegate_(Delegate).
+
+ set_delegate(Delegate) :-
+ ::retractall(delegate_(Delegate)),
+ ::assertz(delegate_(Delegate)).
+
+:- end_category.
+
+% define a simpler delegator object, with a
+% method, operation/1, for testing delegation
+
+:- object(a_delegator,
+ imports(delegator)).
+
+ :- public(operation/1).
+
+ operation(String) :-
+ ( ::delegate(Delegate), Delegate::current_predicate(thing/1) ->
+ % a delegate is defined that understands the method thing/1
+ Delegate::thing(String)
+ ; % otherwise just use the default implementation
+ String = 'default implementation'
+ ).
+
+:- end_object.
+
+% define an interface for delegate objects
+
+:- protocol(delegate).
+
+ :- public(thing/1).
+
+:- end_protocol.
+
+% define a simple delegate
+
+:- object(a_delegate,
+ implements(delegate)).
+
+ thing('delegate implementation').
+
+:- end_object.
+
+% define a simple object that doesn't implement the "delegate" interface
+
+:- object(an_object).
+
+:- end_object.
+
+% test the delegation solution when this file is compiled and loaded
+
+:- initialization((
+ % without a delegate:
+ a_delegator::operation(String1),
+ String1 == 'default implementation',
+ % with a delegate that does not implement thing/1:
+ a_delegator::set_delegate(an_object),
+ a_delegator::operation(String2),
+ String2 == 'default implementation',
+ % with a delegate that implements thing/1:
+ a_delegator::set_delegate(a_delegate),
+ a_delegator::operation(String3),
+ String3 == 'delegate implementation'
+)).
diff --git a/Task/Delete-a-file/Factor/delete-a-file.factor b/Task/Delete-a-file/Factor/delete-a-file.factor
new file mode 100644
index 0000000000..bdfc231694
--- /dev/null
+++ b/Task/Delete-a-file/Factor/delete-a-file.factor
@@ -0,0 +1,2 @@
+"docs" "/docs" [ delete-tree ] bi@
+"input.txt" "/input.txt" [ delete-file ] bi@
diff --git a/Task/Delete-a-file/GAP/delete-a-file.gap b/Task/Delete-a-file/GAP/delete-a-file.gap
new file mode 100644
index 0000000000..b536263ffa
--- /dev/null
+++ b/Task/Delete-a-file/GAP/delete-a-file.gap
@@ -0,0 +1,5 @@
+# Apparently GAP can only remove a file, not a directory
+RemoveFile("input.txt");
+# true
+RemoveFile("docs");
+# fail
diff --git a/Task/Delete-a-file/HicEst/delete-a-file.hicest b/Task/Delete-a-file/HicEst/delete-a-file.hicest
new file mode 100644
index 0000000000..9bdf93639b
--- /dev/null
+++ b/Task/Delete-a-file/HicEst/delete-a-file.hicest
@@ -0,0 +1,7 @@
+SYSTEM(DIR="docs") ! create docs in current directory (if not existent), make it current
+OPEN (FILE="input.txt", "NEW") ! in current directory = docs
+WRITE(FIle="input.txt", DELETE=1) ! no command to DELETE a DIRECTORY in HicEst
+
+SYSTEM(DIR="C:\docs") ! create C:\docs (if not existent), make it current
+OPEN (FILE="input.txt", "NEW") ! in current directory = C:\docs
+WRITE(FIle="input.txt", DELETE=1)
diff --git a/Task/Delete-a-file/Icon/delete-a-file.icon b/Task/Delete-a-file/Icon/delete-a-file.icon
new file mode 100644
index 0000000000..c980e6050c
--- /dev/null
+++ b/Task/Delete-a-file/Icon/delete-a-file.icon
@@ -0,0 +1,4 @@
+every dir := !["./","/"] do {
+ remove(f := dir || "input.txt") |stop("failure for file remove ",f)
+ rmdir(f := dir || "docs") |stop("failure for directory remove ",f)
+ }
diff --git a/Task/Delete-a-file/Io/delete-a-file-1.io b/Task/Delete-a-file/Io/delete-a-file-1.io
new file mode 100644
index 0000000000..079f7fa2b1
--- /dev/null
+++ b/Task/Delete-a-file/Io/delete-a-file-1.io
@@ -0,0 +1,5 @@
+Directory fileNamed("input.txt") remove
+Directory directoryNamed("docs") remove
+RootDir := Directory clone setPath("/")
+RootDir fileNamed("input.txt") remove
+RootDir directoryNamed("docs") remove
diff --git a/Task/Delete-a-file/Io/delete-a-file-2.io b/Task/Delete-a-file/Io/delete-a-file-2.io
new file mode 100644
index 0000000000..1aad7ca195
--- /dev/null
+++ b/Task/Delete-a-file/Io/delete-a-file-2.io
@@ -0,0 +1,4 @@
+File with("input.txt") remove
+Directory with("docs") remove
+File with("/input.txt") remove
+Directory with("/docs") remove
diff --git a/Task/Delete-a-file/J/delete-a-file-1.j b/Task/Delete-a-file/J/delete-a-file-1.j
new file mode 100644
index 0000000000..cf0a40f9dc
--- /dev/null
+++ b/Task/Delete-a-file/J/delete-a-file-1.j
@@ -0,0 +1,8 @@
+ load 'files'
+ ferase 'input.txt'
+ ferase '\input.txt'
+ ferase 'docs'
+ ferase '\docs'
+
+NB. Or all at once...
+ ferase 'input.txt';'/input.txt';'docs';'/docs'
diff --git a/Task/Delete-a-file/J/delete-a-file-2.j b/Task/Delete-a-file/J/delete-a-file-2.j
new file mode 100644
index 0000000000..cf77b4e82e
--- /dev/null
+++ b/Task/Delete-a-file/J/delete-a-file-2.j
@@ -0,0 +1,4 @@
+NB. =========================================================
+NB.*ferase v erases a file
+NB. Returns 1 if successful, otherwise _1
+ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen
diff --git a/Task/Delete-a-file/J/delete-a-file-3.j b/Task/Delete-a-file/J/delete-a-file-3.j
new file mode 100644
index 0000000000..0b793894e6
--- /dev/null
+++ b/Task/Delete-a-file/J/delete-a-file-3.j
@@ -0,0 +1,4 @@
+1!:55 <'input.txt'
+1!:55 <'\input.txt'
+1!:55 <'docs'
+1!:55 <'\docs'
diff --git a/Task/Delete-a-file/Liberty-BASIC/delete-a-file.liberty b/Task/Delete-a-file/Liberty-BASIC/delete-a-file.liberty
new file mode 100644
index 0000000000..11c37c510b
--- /dev/null
+++ b/Task/Delete-a-file/Liberty-BASIC/delete-a-file.liberty
@@ -0,0 +1,10 @@
+' show where we are
+print DefaultDir$
+
+' in here
+kill "input.txt"
+result=rmdir("Docs")
+
+' from root
+kill "\input.txt"
+result=rmdir("\Docs")
diff --git a/Task/Delete-a-file/Locomotive-Basic/delete-a-file.bas b/Task/Delete-a-file/Locomotive-Basic/delete-a-file.bas
new file mode 100644
index 0000000000..9ba71ac0c6
--- /dev/null
+++ b/Task/Delete-a-file/Locomotive-Basic/delete-a-file.bas
@@ -0,0 +1 @@
+|era,"input.txt"
diff --git a/Task/Delete-a-file/Logo/delete-a-file.logo b/Task/Delete-a-file/Logo/delete-a-file.logo
new file mode 100644
index 0000000000..f9d83460fb
--- /dev/null
+++ b/Task/Delete-a-file/Logo/delete-a-file.logo
@@ -0,0 +1,2 @@
+erasefile "input.txt
+erasefile "/input.txt
diff --git a/Task/Delete-a-file/MAXScript/delete-a-file.max b/Task/Delete-a-file/MAXScript/delete-a-file.max
new file mode 100644
index 0000000000..6a789cb514
--- /dev/null
+++ b/Task/Delete-a-file/MAXScript/delete-a-file.max
@@ -0,0 +1,4 @@
+-- Here
+deleteFile "input.txt"
+-- Root
+deleteFile "\input.txt"
diff --git a/Task/Delete-a-file/Mathematica/delete-a-file.mathematica b/Task/Delete-a-file/Mathematica/delete-a-file.mathematica
new file mode 100644
index 0000000000..89524c78e6
--- /dev/null
+++ b/Task/Delete-a-file/Mathematica/delete-a-file.mathematica
@@ -0,0 +1,5 @@
+wd = NotebookDirectory[];
+DeleteFile[wd <> "input.txt"]
+DeleteFile["/" <> "input.txt"]
+DeleteDirectory[wd <> "docs"]
+DeleteDirectory["/" <> "docs"]
diff --git a/Task/Detect-division-by-zero/Factor/detect-division-by-zero.factor b/Task/Detect-division-by-zero/Factor/detect-division-by-zero.factor
new file mode 100644
index 0000000000..234cb179d0
--- /dev/null
+++ b/Task/Detect-division-by-zero/Factor/detect-division-by-zero.factor
@@ -0,0 +1,4 @@
+USE: math.floats.env
+
+: try-div ( a b -- )
+ '[ { +fp-zero-divide+ } [ _ _ /f . ] with-fp-traps ] try ;
diff --git a/Task/Detect-division-by-zero/Fancy/detect-division-by-zero.fancy b/Task/Detect-division-by-zero/Fancy/detect-division-by-zero.fancy
new file mode 100644
index 0000000000..615b5fce20
--- /dev/null
+++ b/Task/Detect-division-by-zero/Fancy/detect-division-by-zero.fancy
@@ -0,0 +1,7 @@
+def divide: x by: y {
+ try {
+ x / y
+ } catch DivisionByZeroError => e {
+ e message println # prints error message
+ }
+}
diff --git a/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-1.groovy b/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-1.groovy
new file mode 100644
index 0000000000..cc9cd9a3bb
--- /dev/null
+++ b/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-1.groovy
@@ -0,0 +1,4 @@
+def dividesByZero = { double n, double d ->
+ assert ! n.infinite : 'Algorithm fails if the numerator is already infinite.'
+ (n/d).infinite || (n/d).naN
+}
diff --git a/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-2.groovy b/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-2.groovy
new file mode 100644
index 0000000000..3e7595ba4d
--- /dev/null
+++ b/Task/Detect-division-by-zero/Groovy/detect-division-by-zero-2.groovy
@@ -0,0 +1,5 @@
+((3d)..(0d)).each { i ->
+ ((2d)..(0d)).each { j ->
+ println "${i}/${j} divides by zero? " + dividesByZero(i,j)
+ }
+}
diff --git a/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-1.hicest b/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-1.hicest
new file mode 100644
index 0000000000..0c98afd64b
--- /dev/null
+++ b/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-1.hicest
@@ -0,0 +1,7 @@
+FUNCTION zero_divide(num, denom)
+ XEQ( num// "/" // denom, *99) ! on error jump to label 99
+ zero_divide = 0 ! division OK
+ RETURN
+
+ 99 zero_divide = 1
+END
diff --git a/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-2.hicest b/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-2.hicest
new file mode 100644
index 0000000000..fb87ed3c36
--- /dev/null
+++ b/Task/Detect-division-by-zero/HicEst/detect-division-by-zero-2.hicest
@@ -0,0 +1,2 @@
+zero_divide(0, 1) returns 0 (false)
+zero_divide( 1, 3-2-1 ) returns 1 (true)
diff --git a/Task/Detect-division-by-zero/IDL/detect-division-by-zero.idl b/Task/Detect-division-by-zero/IDL/detect-division-by-zero.idl
new file mode 100644
index 0000000000..5af8d25f34
--- /dev/null
+++ b/Task/Detect-division-by-zero/IDL/detect-division-by-zero.idl
@@ -0,0 +1 @@
+if not finite( expression ) then ...
diff --git a/Task/Detect-division-by-zero/Icon/detect-division-by-zero.icon b/Task/Detect-division-by-zero/Icon/detect-division-by-zero.icon
new file mode 100644
index 0000000000..73389a8fdf
--- /dev/null
+++ b/Task/Detect-division-by-zero/Icon/detect-division-by-zero.icon
@@ -0,0 +1,4 @@
+procedure main()
+&error := 1
+udef := 1 / 0 | stop("Run-time error ", &errornumber, " : ", &errortext," in line #",&line," - converted to failure")
+end
diff --git a/Task/Detect-division-by-zero/J/detect-division-by-zero-1.j b/Task/Detect-division-by-zero/J/detect-division-by-zero-1.j
new file mode 100644
index 0000000000..a1fbfca317
--- /dev/null
+++ b/Task/Detect-division-by-zero/J/detect-division-by-zero-1.j
@@ -0,0 +1 @@
+funnydiv=: 0 { [: (,:'division by zero detected')"_^:(_ e. |@,) (,>:)@:(,:^:(0<#@$))@[ %"_1 _ ]
diff --git a/Task/Detect-division-by-zero/J/detect-division-by-zero-2.j b/Task/Detect-division-by-zero/J/detect-division-by-zero-2.j
new file mode 100644
index 0000000000..7f9975b4d5
--- /dev/null
+++ b/Task/Detect-division-by-zero/J/detect-division-by-zero-2.j
@@ -0,0 +1,10 @@
+ 3 funnydiv 2
+1.5
+ 3 funnydiv 0
+division by zero detected
+ 0 funnydiv 0
+division by zero detected
+ 0 funnydiv 3
+0
+ 2 3 4 funnydiv 5
+0.4 0.6 0.8
diff --git a/Task/Detect-division-by-zero/Liberty-BASIC/detect-division-by-zero.liberty b/Task/Detect-division-by-zero/Liberty-BASIC/detect-division-by-zero.liberty
new file mode 100644
index 0000000000..5b02911f51
--- /dev/null
+++ b/Task/Detect-division-by-zero/Liberty-BASIC/detect-division-by-zero.liberty
@@ -0,0 +1,12 @@
+result = DetectDividebyZero(1, 0)
+
+
+Function DetectDividebyZero(a, b)
+ On Error GoTo [Error]
+ DetectDividebyZero= (a/ b)
+ Exit Function
+ [Error]
+ If Err = 11 Then '11 is the error number raised when divide by zero occurs
+ Notice "Divide by Zero Detected!"
+ End If
+End Function
diff --git a/Task/Detect-division-by-zero/Locomotive-Basic/detect-division-by-zero.bas b/Task/Detect-division-by-zero/Locomotive-Basic/detect-division-by-zero.bas
new file mode 100644
index 0000000000..27ec7e1b97
--- /dev/null
+++ b/Task/Detect-division-by-zero/Locomotive-Basic/detect-division-by-zero.bas
@@ -0,0 +1,6 @@
+10 ON ERROR GOTO 60
+20 PRINT 2/3
+30 PRINT 3/5
+40 PRINT 4/0
+50 END
+60 IF ERR=11 THEN PRINT "Division by zero in line"ERL:RESUME 50
diff --git a/Task/Detect-division-by-zero/M4/detect-division-by-zero.m4 b/Task/Detect-division-by-zero/M4/detect-division-by-zero.m4
new file mode 100644
index 0000000000..3f488ed632
--- /dev/null
+++ b/Task/Detect-division-by-zero/M4/detect-division-by-zero.m4
@@ -0,0 +1 @@
+ifelse(eval(2/0),`',`detected divide by zero or some other error of some kind')
diff --git a/Task/Detect-division-by-zero/MAXScript/detect-division-by-zero.max b/Task/Detect-division-by-zero/MAXScript/detect-division-by-zero.max
new file mode 100644
index 0000000000..4242a52728
--- /dev/null
+++ b/Task/Detect-division-by-zero/MAXScript/detect-division-by-zero.max
@@ -0,0 +1 @@
+if not bit.isFinite (expression) then...
diff --git a/Task/Detect-division-by-zero/MUMPS/detect-division-by-zero.mumps b/Task/Detect-division-by-zero/MUMPS/detect-division-by-zero.mumps
new file mode 100644
index 0000000000..bbfe48c74d
--- /dev/null
+++ b/Task/Detect-division-by-zero/MUMPS/detect-division-by-zero.mumps
@@ -0,0 +1,11 @@
+DIV(A,B) ;Divide A by B, and watch for division by zero
+ ;The ANSI error code for division by zero is "M9".
+ ;$ECODE errors are surrounded by commas when set.
+ NEW $ETRAP
+ SET $ETRAP="GOTO DIVFIX^ROSETTA"
+ SET D=(A/B)
+ SET $ETRAP=""
+ QUIT D
+DIVFIX
+ IF $FIND($ECODE,",M9,")>1 WRITE !,"Error: Division by zero" SET $ECODE="" QUIT ""
+ QUIT "" ; Fall through for other errors
diff --git a/Task/Detect-division-by-zero/Mathematica/detect-division-by-zero.mathematica b/Task/Detect-division-by-zero/Mathematica/detect-division-by-zero.mathematica
new file mode 100644
index 0000000000..a5e9633fb5
--- /dev/null
+++ b/Task/Detect-division-by-zero/Mathematica/detect-division-by-zero.mathematica
@@ -0,0 +1 @@
+Check[2/0, Print["division by 0"], Power::infy]
diff --git a/Task/Detect-division-by-zero/Maxima/detect-division-by-zero.maxima b/Task/Detect-division-by-zero/Maxima/detect-division-by-zero.maxima
new file mode 100644
index 0000000000..c7fe5b0cc9
--- /dev/null
+++ b/Task/Detect-division-by-zero/Maxima/detect-division-by-zero.maxima
@@ -0,0 +1,7 @@
+f(a, b) := block([q: errcatch(a / b)], if emptyp(q) then 'error else q[1]);
+
+f(5, 6);
+5 / 6
+
+f(5, 0;)
+'error
diff --git a/Task/Determine-if-a-string-is-numeric/Factor/determine-if-a-string-is-numeric.factor b/Task/Determine-if-a-string-is-numeric/Factor/determine-if-a-string-is-numeric.factor
new file mode 100644
index 0000000000..f900738de3
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Factor/determine-if-a-string-is-numeric.factor
@@ -0,0 +1 @@
+: numeric? ( string -- ? ) string>number >boolean ;
diff --git a/Task/Determine-if-a-string-is-numeric/Fantom/determine-if-a-string-is-numeric.fantom b/Task/Determine-if-a-string-is-numeric/Fantom/determine-if-a-string-is-numeric.fantom
new file mode 100644
index 0000000000..18d805e00d
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Fantom/determine-if-a-string-is-numeric.fantom
@@ -0,0 +1,24 @@
+class Main
+{
+ // function to see if str contains a number of any of built-in types
+ static Bool readNum (Str str)
+ {
+ int := Int.fromStr (str, 10, false) // use base 10
+ if (int != null) return true
+ float := Float.fromStr (str, false)
+ if (float != null) return true
+ decimal := Decimal.fromStr (str, false)
+ if (decimal != null) return true
+
+ return false
+ }
+
+ public static Void main ()
+ {
+ echo ("For '2': " + readNum ("2"))
+ echo ("For '-2': " + readNum ("-2"))
+ echo ("For '2.5': " + readNum ("2.5"))
+ echo ("For '2a5': " + readNum ("2a5"))
+ echo ("For '-2.1e5': " + readNum ("-2.1e5"))
+ }
+}
diff --git a/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-1.groovy b/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-1.groovy
new file mode 100644
index 0000000000..088f2d73a8
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-1.groovy
@@ -0,0 +1,9 @@
+def isNumeric = {
+ def formatter = java.text.NumberFormat.instance
+ def pos = [0] as java.text.ParsePosition
+ formatter.parse(it, pos)
+
+ // if parse position index has moved to end of string
+ // them the whole string was numeric
+ pos.index == it.size()
+}
diff --git a/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-2.groovy b/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-2.groovy
new file mode 100644
index 0000000000..1d67a1bb60
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Groovy/determine-if-a-string-is-numeric-2.groovy
@@ -0,0 +1,5 @@
+println isNumeric('1')
+println isNumeric('-.555')
+println isNumeric('1,000,000')
+println isNumeric(' 1 1 1 1 ')
+println isNumeric('abcdef')
diff --git a/Task/Determine-if-a-string-is-numeric/HicEst/determine-if-a-string-is-numeric.hicest b/Task/Determine-if-a-string-is-numeric/HicEst/determine-if-a-string-is-numeric.hicest
new file mode 100644
index 0000000000..d37240b487
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/HicEst/determine-if-a-string-is-numeric.hicest
@@ -0,0 +1,27 @@
+ ! = bin + 2*int + 4*flt + 8*oct +16*hex + 32*sci
+ isNumeric("1001") ! 27 = 1 1 0 1 1 0
+ isNumeric("123") ! 26 = 0 1 0 1 1 0
+ isNumeric("1E78") ! 48 = 0 0 0 0 1 1
+ isNumeric("-0.123") ! 4 = 0 0 1 0 0 1
+ isNumeric("-123.456e-78") ! 32 = 0 0 0 0 0 1
+ isNumeric(" 123") ! 0: leading blank
+ isNumeric("-123.456f-78") ! 0: illegal character f
+
+
+FUNCTION isNumeric(string) ! true ( > 0 ), no leading/trailing blanks
+ CHARACTER string
+ b = INDEX(string, "[01]+", 128, Lbin) ! Lbin returns length found
+ i = INDEX(string, "-?\d+", 128, Lint) ! regular expression: 128
+ f = INDEX(string, "-?\d+\.\d*", 128, Lflt)
+ o = INDEX(string, "[0-7]+", 128, Loct)
+ h = INDEX(string, "[0-9A-F]+", 128, Lhex) ! case sensitive: 1+128
+ s = INDEX(string, "-?\d+\.*\d*E[+-]*\d*", 128, Lsci)
+ IF(anywhere) THEN ! 0 (false) by default
+ isNumeric = ( b > 0 ) + 2*( i > 0 ) + 4*( f > 0 ) + 8*( o > 0 ) + 16*( h > 0 ) + 32*( s > 0 )
+ ELSEIF(boolean) THEN ! 0 (false) by default
+ isNumeric = ( b + i + f + o + h + s ) > 0 ! this would return 0 or 1
+ ELSE
+ L = LEN(string)
+ isNumeric = (Lbin==L) + 2*(Lint==L) + 4*(Lflt==L) + 8*(Loct==L) + 16*(Lhex==L) + 32*(Lsci==L)
+ ENDIF
+ END
diff --git a/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-1.idl b/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-1.idl
new file mode 100644
index 0000000000..a51497c0f9
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-1.idl
@@ -0,0 +1,6 @@
+function isnumeric,input
+ on_ioerror, false
+ test = double(input)
+ return, 1
+ false: return, 0
+end
diff --git a/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-2.idl b/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-2.idl
new file mode 100644
index 0000000000..47cd02caf5
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/IDL/determine-if-a-string-is-numeric-2.idl
@@ -0,0 +1,4 @@
+if isnumeric('-123.45e-2') then print, 'yes' else print, 'no'
+; ==> yes
+if isnumeric('picklejuice') then print, 'yes' else print, 'no'
+; ==> no
diff --git a/Task/Determine-if-a-string-is-numeric/Icon/determine-if-a-string-is-numeric.icon b/Task/Determine-if-a-string-is-numeric/Icon/determine-if-a-string-is-numeric.icon
new file mode 100644
index 0000000000..e3caf02c12
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Icon/determine-if-a-string-is-numeric.icon
@@ -0,0 +1 @@
+write(image(x), if numeric(x) then " is numeric." else " is not numeric")
diff --git a/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-1.j b/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-1.j
new file mode 100644
index 0000000000..11cf155310
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-1.j
@@ -0,0 +1,4 @@
+isNumeric=: _ ~: _ ". ]
+isNumericScalar=: 1 -: isNumeric
+TXT=: ,&' a scalar numeric value.' &.> ' is not';' represents'
+sayIsNumericScalar=: , TXT {::~ isNumericScalar
diff --git a/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-2.j b/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-2.j
new file mode 100644
index 0000000000..e9ec8001d0
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/J/determine-if-a-string-is-numeric-2.j
@@ -0,0 +1,10 @@
+ isNumeric '152'
+1
+ isNumeric '152 -3.1415926 Foo123'
+1 1 0
+ isNumeric '42 foo42 4.2e1 4200e-2 126r3 16b2a 42foo'
+1 0 1 1 1 1 0
+ isNumericScalar '152 -3.1415926 Foo123'
+0
+ sayIsNumericScalar '-3.1415926'
+-3.1415926 represents a scalar numeric value.
diff --git a/Task/Determine-if-a-string-is-numeric/Liberty-BASIC/determine-if-a-string-is-numeric.liberty b/Task/Determine-if-a-string-is-numeric/Liberty-BASIC/determine-if-a-string-is-numeric.liberty
new file mode 100644
index 0000000000..1042212dbb
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Liberty-BASIC/determine-if-a-string-is-numeric.liberty
@@ -0,0 +1,56 @@
+DATA "PI", "0123", "-0123", "12.30", "-12.30", "123!", "0"
+DATA "0.0", ".123", "-.123", "12E3", "12E-3", "12+3", "end"
+
+
+while n$ <> "end"
+ read n$
+ print n$, IsNumber(n$)
+wend
+end
+
+function IsNumber(string$)
+ on error goto [NotNumber]
+ string$ = trim$(string$)
+ 'check for float overflow
+ n = val(string$)
+
+ 'assume it is number and try to prove wrong
+ IsNumber = 1
+ for i = 1 to len(string$)
+ select case mid$(string$, i, 1)
+ case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
+ HasNumeric = 1 'to check if there are any digits
+ case "e", "E"
+ '"e" must not occur more than once
+ 'must not occur before digits
+
+ if HasE > 0 or HasNumeric = 0 then
+ IsNumber = 0
+ exit for
+ end if
+ HasE = i 'store position of "e"
+ HasNumeric = 0 'needs numbers after "e"
+ case "-", "+"
+ 'must be either first character or immediately after "e"
+ '(HasE = 0 if no occurrences yet)
+ if HasE <> i-1 then
+ IsNumber = 0
+ exit for
+ end if
+ case "."
+ 'must not have previous points and must not come after "e"
+ if HasE <> 0 or HasPoint <> 0 then
+ IsNumber = 0
+ exit for
+ end if
+ HasPoint = 1
+ case else
+ 'no other characters allowed
+ IsNumber = 0
+ exit for
+ end select
+ next i
+ 'must have digits
+ if HasNumeric = 0 then IsNumber = 0
+ [NotNumber]
+end function
diff --git a/Task/Determine-if-a-string-is-numeric/Lisaac/determine-if-a-string-is-numeric.lisaac b/Task/Determine-if-a-string-is-numeric/Lisaac/determine-if-a-string-is-numeric.lisaac
new file mode 100644
index 0000000000..d122bbaa74
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Lisaac/determine-if-a-string-is-numeric.lisaac
@@ -0,0 +1,2 @@
+"123457".is_integer.println;
+// write TRUE on stdin
diff --git a/Task/Determine-if-a-string-is-numeric/Logo/determine-if-a-string-is-numeric.logo b/Task/Determine-if-a-string-is-numeric/Logo/determine-if-a-string-is-numeric.logo
new file mode 100644
index 0000000000..c2e6b23d46
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Logo/determine-if-a-string-is-numeric.logo
@@ -0,0 +1 @@
+show number? "-1.23 ; true
diff --git a/Task/Determine-if-a-string-is-numeric/MAXScript/determine-if-a-string-is-numeric.max b/Task/Determine-if-a-string-is-numeric/MAXScript/determine-if-a-string-is-numeric.max
new file mode 100644
index 0000000000..983409085c
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/MAXScript/determine-if-a-string-is-numeric.max
@@ -0,0 +1,10 @@
+fn isNumeric str =
+(
+ try
+ (
+ (str as integer) != undefined
+ )
+ catch(false)
+)
+
+isNumeric "123"
diff --git a/Task/Determine-if-a-string-is-numeric/Mathematica/determine-if-a-string-is-numeric.mathematica b/Task/Determine-if-a-string-is-numeric/Mathematica/determine-if-a-string-is-numeric.mathematica
new file mode 100644
index 0000000000..04c2d1b29c
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Mathematica/determine-if-a-string-is-numeric.mathematica
@@ -0,0 +1 @@
+NumberQ[ToExpression["02553352000242"]]
diff --git a/Task/Determine-if-a-string-is-numeric/Maxima/determine-if-a-string-is-numeric.maxima b/Task/Determine-if-a-string-is-numeric/Maxima/determine-if-a-string-is-numeric.maxima
new file mode 100644
index 0000000000..819dd2621d
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Maxima/determine-if-a-string-is-numeric.maxima
@@ -0,0 +1 @@
+numberp(parse_string("170141183460469231731687303715884105727"));
diff --git a/Task/Determine-if-a-string-is-numeric/Mirah/determine-if-a-string-is-numeric.mirah b/Task/Determine-if-a-string-is-numeric/Mirah/determine-if-a-string-is-numeric.mirah
new file mode 100644
index 0000000000..f8265e9da6
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Mirah/determine-if-a-string-is-numeric.mirah
@@ -0,0 +1,125 @@
+import java.text.NumberFormat
+import java.text.ParsePosition
+import java.util.Scanner
+
+# this first example relies on catching an exception,
+# which is bad style and poorly performing in Java
+def is_numeric?(s:string)
+ begin
+ Double.parseDouble(s)
+ return true
+ rescue
+ return false
+ end
+end
+
+puts '123 is numeric' if is_numeric?('123')
+puts '-123 is numeric' if is_numeric?('-123')
+puts '123.1 is numeric' if is_numeric?('123.1')
+
+puts 'nil is not numeric' unless is_numeric?(nil)
+puts "'' is not numeric" unless is_numeric?('')
+puts 'abc is not numeric' unless is_numeric?('abc')
+puts '123- is not numeric' unless is_numeric?('123-')
+puts '1.2.3 is not numeric' unless is_numeric?('1.2.3')
+
+
+# check every element of the string
+def is_numeric2?(s: string)
+ if (s == nil || s.isEmpty())
+ return false
+ end
+ if (!s.startsWith('-'))
+ if s.contains('-')
+ return false
+ end
+ end
+
+ 0.upto(s.length()-1) do |x|
+ c = s.charAt(x)
+ if ((x == 0) && (c == '-'.charAt(0)))
+ # negative number
+ elsif (c == '.'.charAt(0))
+ if (s.indexOf('.', x) > -1)
+ return false # more than one period
+ end
+ elsif (!Character.isDigit(c))
+ return false
+ end
+ end
+ true
+end
+
+
+puts '123 is numeric' if is_numeric2?('123')
+puts '-123 is numeric' if is_numeric2?('-123')
+puts '123.1 is numeric' if is_numeric2?('123.1')
+
+puts 'nil is not numeric' unless is_numeric2?(nil)
+puts "'' is not numeric" unless is_numeric2?('')
+puts 'abc is not numeric' unless is_numeric2?('abc')
+puts '123- is not numeric' unless is_numeric2?('123-')
+puts '1.2.3 is not numeric' unless is_numeric2?('1.2.3')
+
+
+
+# use a regular expression
+def is_numeric3?(s:string)
+ s == nil || s.matches("[-+]?\\d+(\\.\\d+)?")
+end
+
+puts '123 is numeric' if is_numeric3?('123')
+puts '-123 is numeric' if is_numeric3?('-123')
+puts '123.1 is numeric' if is_numeric3?('123.1')
+
+puts 'nil is not numeric' unless is_numeric3?(nil)
+puts "'' is not numeric" unless is_numeric3?('')
+puts 'abc is not numeric' unless is_numeric3?('abc')
+puts '123- is not numeric' unless is_numeric3?('123-')
+puts '1.2.3 is not numeric' unless is_numeric3?('1.2.3')
+
+
+# use the positional parser in the java.text.NumberFormat object
+# (a more robust solution). If, after parsing, the parse position is at
+# the end of the string, we can deduce that the entire string was a
+# valid number.
+def is_numeric4?(s:string)
+ return false if s == nil
+ formatter = NumberFormat.getInstance()
+ pos = ParsePosition.new(0)
+ formatter.parse(s, pos)
+ s.length() == pos.getIndex()
+end
+
+
+puts '123 is numeric' if is_numeric4?('123')
+puts '-123 is numeric' if is_numeric4?('-123')
+puts '123.1 is numeric' if is_numeric4?('123.1')
+
+puts 'nil is not numeric' unless is_numeric4?(nil)
+puts "'' is not numeric" unless is_numeric4?('')
+puts 'abc is not numeric' unless is_numeric4?('abc')
+puts '123- is not numeric' unless is_numeric4?('123-')
+puts '1.2.3 is not numeric' unless is_numeric4?('1.2.3')
+
+
+# use the java.util.Scanner object. Very useful if you have to
+# scan multiple entries. Scanner also has similar methods for longs,
+# shorts, bytes, doubles, floats, BigIntegers, and BigDecimals as well
+# as methods for integral types where you may input a base/radix other than
+# 10 (10 is the default, which can be changed using the useRadix method).
+def is_numeric5?(s:string)
+ return false if s == nil
+ Scanner sc = Scanner.new(s)
+ sc.hasNextDouble()
+end
+
+puts '123 is numeric' if is_numeric5?('123')
+puts '-123 is numeric' if is_numeric5?('-123')
+puts '123.1 is numeric' if is_numeric5?('123.1')
+
+puts 'nil is not numeric' unless is_numeric5?(nil)
+puts "'' is not numeric" unless is_numeric5?('')
+puts 'abc is not numeric' unless is_numeric5?('abc')
+puts '123- is not numeric' unless is_numeric5?('123-')
+puts '1.2.3 is not numeric' unless is_numeric5?('1.2.3')
diff --git a/Task/Determine-if-a-string-is-numeric/Modula-3/determine-if-a-string-is-numeric.mod3 b/Task/Determine-if-a-string-is-numeric/Modula-3/determine-if-a-string-is-numeric.mod3
new file mode 100644
index 0000000000..1c27b48eb9
--- /dev/null
+++ b/Task/Determine-if-a-string-is-numeric/Modula-3/determine-if-a-string-is-numeric.mod3
@@ -0,0 +1,25 @@
+MODULE Numeric EXPORTS Main;
+
+IMPORT IO, Fmt, Text;
+
+PROCEDURE isNumeric(s: TEXT): BOOLEAN =
+ BEGIN
+ FOR i := 0 TO Text.Length(s) DO
+ WITH char = Text.GetChar(s, i) DO
+ IF i = 0 AND char = '-' THEN
+ EXIT;
+ END;
+ IF char >= '0' AND char <= '9' THEN
+ EXIT;
+ END;
+ RETURN FALSE;
+ END;
+ END;
+ RETURN TRUE;
+ END isNumeric;
+
+BEGIN
+ IO.Put("isNumeric(152) = " & Fmt.Bool(isNumeric("152")) & "\n");
+ IO.Put("isNumeric(-3.1415926) = " & Fmt.Bool(isNumeric("-3.1415926")) & "\n");
+ IO.Put("isNumeric(Foo123) = " & Fmt.Bool(isNumeric("Foo123")) & "\n");
+END Numeric.
diff --git a/Task/Determine-if-only-one-instance-is-running/Liberty-BASIC/determine-if-only-one-instance-is-running.liberty b/Task/Determine-if-only-one-instance-is-running/Liberty-BASIC/determine-if-only-one-instance-is-running.liberty
new file mode 100644
index 0000000000..3d4cb3fa67
--- /dev/null
+++ b/Task/Determine-if-only-one-instance-is-running/Liberty-BASIC/determine-if-only-one-instance-is-running.liberty
@@ -0,0 +1,16 @@
+'Create a Mutex to prevent more than one instance from being open at a single time.
+CallDLL #kernel32, "CreateMutexA", 0 as Long, 1 as Long, "Global\My Program" as ptr, mutex as ulong
+CallDLL #kernel32, "GetLastError", LastError as Long
+
+if LastError = 183 then 'Error returned when a Mutex already exists
+ 'Close the handle if the mutex already exists
+ calldll #kernel32, "CloseHandle", mutex as ulong, ret as ulong
+ notice "An instance of My Program is currently running!"
+ end
+end if
+
+'Release the Mutex/ Close the handle prior to ending the program
+'Comment out these lines to allow the program to remain active to test for the mutex's presence
+calldll #kernel32, "ReleaseMutex", mutex as ulong, ret as ulong
+calldll #kernel32, "CloseHandle", mutex as ulong, ret as ulong
+end
diff --git a/Task/Determine-if-only-one-instance-is-running/Mathematica/determine-if-only-one-instance-is-running.mathematica b/Task/Determine-if-only-one-instance-is-running/Mathematica/determine-if-only-one-instance-is-running.mathematica
new file mode 100644
index 0000000000..234cb9d1e0
--- /dev/null
+++ b/Task/Determine-if-only-one-instance-is-running/Mathematica/determine-if-only-one-instance-is-running.mathematica
@@ -0,0 +1,5 @@
+$Epilog := Print["Another instance is running "];
+If[Attributes[Global`Mutex] == {Protected},
+ Exit[],
+ Global`Mutex[x_] := Locked; Protect[Global`Mutex];
+ ]
diff --git a/Task/Digital-root/J/digital-root-1.j b/Task/Digital-root/J/digital-root-1.j
new file mode 100644
index 0000000000..b076c0148e
--- /dev/null
+++ b/Task/Digital-root/J/digital-root-1.j
@@ -0,0 +1,2 @@
+digrot=: +/@(#.inv~&10)^:_
+addper=: _1 + [: # +/@(#.inv~&10)^:a:
diff --git a/Task/Digital-root/J/digital-root-2.j b/Task/Digital-root/J/digital-root-2.j
new file mode 100644
index 0000000000..acbcc10ae4
--- /dev/null
+++ b/Task/Digital-root/J/digital-root-2.j
@@ -0,0 +1,5 @@
+ (, addper, digrot)&> 627615 39390 588225 393900588225
+ 627615 2 9
+ 39390 2 6
+ 588225 2 3
+393900588225 2 9
diff --git a/Task/Digital-root/J/digital-root-3.j b/Task/Digital-root/J/digital-root-3.j
new file mode 100644
index 0000000000..a3db66b958
--- /dev/null
+++ b/Task/Digital-root/J/digital-root-3.j
@@ -0,0 +1 @@
+equals=: =&(9&|)"0
diff --git a/Task/Digital-root/J/digital-root-4.j b/Task/Digital-root/J/digital-root-4.j
new file mode 100644
index 0000000000..2f098f71ff
--- /dev/null
+++ b/Task/Digital-root/J/digital-root-4.j
@@ -0,0 +1,15 @@
+ equals table i. 10
+┌──────┬───────────────────┐
+│equals│0 1 2 3 4 5 6 7 8 9│
+├──────┼───────────────────┤
+│0 │1 0 0 0 0 0 0 0 0 1│
+│1 │0 1 0 0 0 0 0 0 0 0│
+│2 │0 0 1 0 0 0 0 0 0 0│
+│3 │0 0 0 1 0 0 0 0 0 0│
+│4 │0 0 0 0 1 0 0 0 0 0│
+│5 │0 0 0 0 0 1 0 0 0 0│
+│6 │0 0 0 0 0 0 1 0 0 0│
+│7 │0 0 0 0 0 0 0 1 0 0│
+│8 │0 0 0 0 0 0 0 0 1 0│
+│9 │1 0 0 0 0 0 0 0 0 1│
+└──────┴───────────────────┘
diff --git a/Task/Digital-root/J/digital-root-5.j b/Task/Digital-root/J/digital-root-5.j
new file mode 100644
index 0000000000..bb241eae97
--- /dev/null
+++ b/Task/Digital-root/J/digital-root-5.j
@@ -0,0 +1,2 @@
+digrt=: +/@(#.inv)^:_
+addpr=: _1 + [: # +/@(#.inv)^:a:
diff --git a/Task/Digital-root/Mathematica/digital-root.mathematica b/Task/Digital-root/Mathematica/digital-root.mathematica
new file mode 100644
index 0000000000..e6cc5bb7fe
--- /dev/null
+++ b/Task/Digital-root/Mathematica/digital-root.mathematica
@@ -0,0 +1,3 @@
+seq[n_, b_] := FixedPointList[Total[IntegerDigits[#, b]] &, n];
+root[n_Integer, base_: 10] := If[base == 10, #, BaseForm[#, base]] &[Last[seq[n, base]]]
+persistance[n_Integer, base_: 10] := Length[seq[n, base]] - 2;
diff --git a/Task/Dinesmans-multiple-dwelling-problem/Icon/dinesmans-multiple-dwelling-problem.icon b/Task/Dinesmans-multiple-dwelling-problem/Icon/dinesmans-multiple-dwelling-problem.icon
new file mode 100644
index 0000000000..ca48b0f48a
--- /dev/null
+++ b/Task/Dinesmans-multiple-dwelling-problem/Icon/dinesmans-multiple-dwelling-problem.icon
@@ -0,0 +1,71 @@
+invocable all
+global nameL, nameT, rules
+
+procedure main() # Dinesman
+
+nameT := table()
+nameL := ["Baker", "Cooper", "Fletcher", "Miller", "Smith"]
+rules := [ [ distinct ],
+ [ "~=", "Baker", top() ],
+ [ "~=", "Cooper", bottom() ],
+ [ "~=", "Fletcher", top() ],
+ [ "~=", "Fletcher", bottom() ],
+ [ ">", "Miller", "Cooper" ],
+ [ notadjacent, "Smith", "Fletcher" ],
+ [ notadjacent, "Fletcher", "Cooper" ],
+ [ showsolution ],
+ [ stop ] ]
+
+if not solve(1) then
+ write("No solution found.")
+end
+
+procedure dontstop() # use if you want to search for all solutions
+end
+
+procedure showsolution() # show the soluton
+ write("The solution is:")
+ every write(" ",n := !nameL, " lives in ", nameT[n])
+ return
+end
+
+procedure eval(n) # evaluate a rule
+ r := copy(rules[n-top()])
+ every r[i := 2 to *r] := rv(r[i])
+ if get(r)!r then suspend
+end
+
+procedure rv(x) # return referenced value if it exists
+return \nameT[x] | x
+end
+
+procedure solve(n) # recursive solver
+ if n > top() then { # apply rules
+ if n <= top() + *rules then
+ ( eval(n) & solve(n+1) ) | fail
+ }
+ else # setup locations
+ (( nameT[nameL[n]] := bottom() to top() ) & solve(n + 1)) | fail
+ return
+end
+
+procedure distinct(a,b) # ensure each name is distinct
+ if nameT[n := !nameL] = nameT[n ~== key(nameT)] then fail
+ suspend
+end
+
+procedure notadjacent(n1,n2) # ensure n1,2 are not adjacent
+ if not adjacent(n1,n2) then suspend
+end
+
+procedure adjacent(n1,n2) # ensure n1,2 are adjacent
+ if abs(n1 - n2) = 1 then suspend
+end
+
+procedure bottom() # return bottom
+ return if *nameL > 0 then 1 else 0
+end
+
+procedure top() # return top
+ return *nameL
+end
diff --git a/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-1.j b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-1.j
new file mode 100644
index 0000000000..de75166084
--- /dev/null
+++ b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-1.j
@@ -0,0 +1 @@
+possible=: ((i.!5) A. i.5) { 'BCFMS'
diff --git a/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-2.j b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-2.j
new file mode 100644
index 0000000000..befc0871ee
--- /dev/null
+++ b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-2.j
@@ -0,0 +1,9 @@
+possible=: (#~ 'B' ~: {:"1) possible NB. Baker not on top floor
+possible=: (#~ 'C' ~: {."1) possible NB. Cooper not on bottom floor
+possible=: (#~ 'F' ~: {:"1) possible NB. Fletcher not on top floor
+possible=: (#~ 'F' ~: {."1) possible NB. Fletcher not on bottom floor
+possible=: (#~ @i."1&'CM') possible NB. Miller on higher floor than Cooper
+possible=: (#~ 0 = +/@E."1~&'SF') possible NB. Smith not immediately below Fletcher
+possible=: (#~ 0 = +/@E."1~&'FS') possible NB. Fletcher not immediately below Smith
+possible=: (#~ 0 = +/@E."1~&'CF') possible NB. Cooper not immediately below Fletcher
+possible=: (#~ 0 = +/@E."1~&'FC') possible NB. Fletcher not immediately below Cooper
diff --git a/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-3.j b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-3.j
new file mode 100644
index 0000000000..c2ede3d88a
--- /dev/null
+++ b/Task/Dinesmans-multiple-dwelling-problem/J/dinesmans-multiple-dwelling-problem-3.j
@@ -0,0 +1,2 @@
+ possible
+SCBFM
diff --git a/Task/Dinesmans-multiple-dwelling-problem/Mathematica/dinesmans-multiple-dwelling-problem.mathematica b/Task/Dinesmans-multiple-dwelling-problem/Mathematica/dinesmans-multiple-dwelling-problem.mathematica
new file mode 100644
index 0000000000..ab3b32e9bb
--- /dev/null
+++ b/Task/Dinesmans-multiple-dwelling-problem/Mathematica/dinesmans-multiple-dwelling-problem.mathematica
@@ -0,0 +1,15 @@
+floor[x_,y_]:=Flatten[Position[y,x]][[1]]
+Select[Permutations[{"Baker","Cooper","Fletcher","Miller","Smith"}],
+ ( floor["Baker",#] < 5 )
+&&( Abs[floor["Fletcher",#] - floor["Cooper",#]] > 1 )
+&&( Abs[floor["Fletcher",#] - floor["Smith",#]] > 1 )
+&&( 1 < floor["Cooper",#] < floor["Miller",#] )
+&&( 1 < floor["Fletcher",#] < 5 )
+&] [[1]] //Reverse //Column
+
+->
+Miller
+Fletcher
+Baker
+Cooper
+Smith
diff --git a/Task/Dining-philosophers/JoCaml/dining-philosophers-1.jocaml b/Task/Dining-philosophers/JoCaml/dining-philosophers-1.jocaml
new file mode 100644
index 0000000000..6463eaa117
--- /dev/null
+++ b/Task/Dining-philosophers/JoCaml/dining-philosophers-1.jocaml
@@ -0,0 +1,21 @@
+let random_wait n = Unix.sleep (Random.int n);;
+let print s m = Printf.printf "philosopher %s is %s\n" s m; flush(stdout);;
+let will_eat s = print s "eating"; random_wait 10;;
+let will_think s = print s "thinking"; random_wait 20; print s "hungry";;
+
+ (* a,b,c,d,e are thinking philosophers; ah,bh,ch,dh,eh are the same philosophers when hungry;
+ fab is the fork located between philosophers a and b; similarly for fbc, fcd, ... *)
+
+def ah() & fab() & fea() = will_eat "Aristotle"; a() & fab() & fea()
+ or bh() & fab() & fbc() = will_eat "Kant"; b() & fab() & fbc()
+ or ch() & fbc() & fcd() = will_eat "Spinoza"; c() & fbc() & fcd()
+ or dh() & fcd() & fde() = will_eat "Marx"; d() & fcd() & fde()
+ or eh() & fde() & fea() = will_eat "Russell"; e() & fde() & fea()
+
+ and a() = will_think "Aristotle"; ah()
+ and b() = will_think "Kant"; bh()
+ and c() = will_think "Spinoza"; ch()
+ and d() = will_think "Marx"; dh()
+ and e() = will_think "Russell"; eh()
+;;
+spawn fab() & fbc() & fcd() & fde() & fea() & a() & b() & c() & d() & e();;
diff --git a/Task/Dining-philosophers/JoCaml/dining-philosophers-2.jocaml b/Task/Dining-philosophers/JoCaml/dining-philosophers-2.jocaml
new file mode 100644
index 0000000000..17daf02011
--- /dev/null
+++ b/Task/Dining-philosophers/JoCaml/dining-philosophers-2.jocaml
@@ -0,0 +1,47 @@
+let print s t m = Printf.printf "t=%d: philosopher %s is %s\n" t s m; flush(stdout);;
+let random_wait n = Unix.sleep (Random.int n);;
+
+(* auxiliary function to keep track of time ticks, using integer seconds *)
+def ts () & counter(n) = counter(n) & reply n to ts
+or update_counter() & counter(n) = counter(n+1) & reply to update_counter
+and counter_sentinel() = Unix.sleep 1; update_counter(); counter_sentinel()
+;;
+spawn counter(0) & counter_sentinel();;
+
+def stats(n, waited, maxwaited) & report_wait_time(m) =
+ let (n', waited', maxwaited') = (n+1, waited+m, max maxwaited m) in
+ Printf.printf "waiting average %f, max waited %d\n"
+ (float_of_int waited' /. float_of_int n')
+ maxwaited';
+ flush(stdout);
+ stats(n',waited',maxwaited') & reply () to report_wait_time
+;;
+
+spawn stats(0,0,0);;
+
+let eat s t = print s t "eating"; random_wait 10;;
+let think s = print s (ts()) "thinking"; random_wait 20;;
+
+(* "p" will be a philosopher channel, to be defined later
+ the messages ah, bh, ... do not need to be injected now. *)
+
+let will_eat s t = let t' = ts() in report_wait_time(t'-t); eat s t';;
+
+def ah(t,p) & fab() & fea() = will_eat "Aristotle" t; p() & fab() & fea()
+or bh(t,p) & fab() & fbc() = will_eat "Kant" t; p() & fab() & fbc()
+or ch(t,p) & fbc() & fcd() = will_eat "Spinoza" t; p() & fbc() & fcd()
+or dh(t,p) & fcd() & fde() = will_eat "Marx" t; p() & fcd() & fde()
+or eh(t,p) & fde() & fea() = will_eat "Russell" t; p() & fde() & fea()
+;;
+
+spawn fab() & fbc() & fcd() & fde() & fea();;
+
+(* define the thinking -> hungry transitions using local philosophers, and inject the philosophers *)
+List.map
+ (fun (h,s) -> def p() = think s; let t = ts() in print s t "hungry"; h(t,p) in spawn p())
+ [(ah,"Aristotle"); (bh,"Kant"); (ch,"Spinoza"); (dh,"Marx"); (eh,"Russell")]
+;;
+(* this replaces repetitive code such as that shown in the previous solution *)
+
+(* now we need to wait and do nothing; nobody will be able to inject godot() *)
+def wait_forever() & godot() = reply () to wait_forever in wait_forever();;
diff --git a/Task/Dining-philosophers/JoCaml/dining-philosophers-3.jocaml b/Task/Dining-philosophers/JoCaml/dining-philosophers-3.jocaml
new file mode 100644
index 0000000000..91c8304505
--- /dev/null
+++ b/Task/Dining-philosophers/JoCaml/dining-philosophers-3.jocaml
@@ -0,0 +1,77 @@
+#!/usr/bin/jocamlrun jocaml
+
+(* eating and thinking between 0 and this-1 *)
+let eating_max_interval = 10;;
+let thinking_max_interval = 10;;
+let number_of_philosophers = 5;;
+let random_wait n = Unix.sleep (Random.int n);;
+
+(* counter for unique timestamp, not related to time in seconds *)
+def get_current_time () & unique_ts_counter(n) = unique_ts_counter(n+1) & reply n to get_current_time;;
+spawn unique_ts_counter(0);;
+
+(* functions that wait and print diagnostics *)
+let name i = List.nth ["Aristotle"; "Kant"; "Spinoza"; "Marx"; "Russell"] i;;
+let message i m = Printf.printf "philosopher %s is %s\n" (name i) m; flush(stdout);;
+let eat i = message i "eating"; random_wait eating_max_interval;;
+let think i = message i "thinking"; random_wait thinking_max_interval;;
+
+type philosopher_state_t = Eating | Hungry of int | Thinking;;
+
+(* initial states *)
+let states = Array.make number_of_philosophers Thinking;;
+(* one philosopher's processes *)
+let make_philosopher i got_hungry done_eating =
+ def hungry() & forks() = eat i ; done_eating(i) & thinking()
+ and thinking() = think i; got_hungry(i) & hungry()
+ in spawn thinking(); forks
+;;
+
+(* deciding who will eat first *)
+let next_phil i = (i+1) mod number_of_philosophers;;
+let prev_phil i = (number_of_philosophers+i-1) mod number_of_philosophers;;
+let is_hungry p = match p with
+ | Hungry h -> true
+ | _ -> false;;
+let not_eating p = match p with
+ | Eating -> false
+ | _ -> true;;
+let is_more_hungry p q = match q with
+ | Hungry hj -> (
+ match p with
+ | Hungry hi -> hi <= hj
+ | _ -> false
+ )
+ | _ -> true
+;;
+
+let may_eat_first i =
+ is_hungry states.(i)
+ && not_eating states.(next_phil i) && not_eating states.(prev_phil i)
+ && is_more_hungry states.(i) states.(next_phil i)
+ && is_more_hungry states.(i) states.(prev_phil i);;
+
+let decide_eating i =
+ if (may_eat_first i) then (states.(i) <- Eating; true)
+ else false;;
+
+def waiter(all_forks) & got_hungry(i) =
+ states.(i) <- Hungry (get_current_time());
+ let will_eat = decide_eating i in (
+ waiter(all_forks) & (if will_eat then all_forks.(i)() else 0)
+)
+or waiter(all_forks) & done_eating(i) =
+ states.(i) <- Thinking;
+ let next_will_eat = decide_eating (next_phil i) in
+ let prev_will_eat = decide_eating (prev_phil i) in (
+ waiter(all_forks)
+ & (if next_will_eat then all_forks.(next_phil i)() else 0)
+ & (if prev_will_eat then all_forks.(prev_phil i)() else 0)
+ );;
+
+let all_forks = Array.init number_of_philosophers (fun i -> make_philosopher i got_hungry done_eating)
+in spawn waiter(all_forks);;
+
+(* now we need to wait and do nothing; nobody will be able to inject godot() *)
+
+def wait_forever() & godot() = reply () to wait_forever in wait_forever();;
diff --git a/Task/Dining-philosophers/Logtalk/dining-philosophers.logtalk b/Task/Dining-philosophers/Logtalk/dining-philosophers.logtalk
new file mode 100644
index 0000000000..246e4cd119
--- /dev/null
+++ b/Task/Dining-philosophers/Logtalk/dining-philosophers.logtalk
@@ -0,0 +1,156 @@
+:- category(chopstick).
+
+ % chopstick actions (picking up and putting down) are synchronized using a notification
+ % such that a chopstick can only be handled by a single philosopher at a time:
+
+ :- public(pick_up/0).
+ pick_up :-
+ threaded_wait(available).
+
+ :- public(put_down/0).
+ put_down :-
+ threaded_notify(available).
+
+:- end_category.
+
+
+:- object(cs1,
+ imports(chopstick)).
+
+ :- threaded.
+ :- initialization(threaded_notify(available)).
+
+:- end_object.
+
+
+:- object(cs2,
+ imports(chopstick)).
+
+ :- threaded.
+ :- initialization(threaded_notify(available)).
+
+:- end_object.
+
+
+:- object(cs3,
+ imports(chopstick)).
+
+ :- threaded.
+ :- initialization(threaded_notify(available)).
+
+:- end_object.
+
+
+:- object(cs4,
+ imports(chopstick)).
+
+ :- threaded.
+ :- initialization(threaded_notify(available)).
+
+:- end_object.
+
+
+:- object(cs5,
+ imports(chopstick)).
+
+ :- threaded.
+ :- initialization(threaded_notify(available)).
+
+:- end_object.
+
+
+:- category(philosopher).
+
+ :- public(left_chopstick/1).
+ :- public(right_chopstick/1).
+ :- public(run/2).
+
+ :- private(message/1).
+ :- synchronized(message/1).
+
+ :- uses(random, [random/3]).
+
+ run(0, _) :-
+ this(Philosopher),
+ message([Philosopher, ' terminated.']).
+
+ run(Count, MaxTime) :-
+ Count > 0,
+ think(MaxTime),
+ eat(MaxTime),
+ Count2 is Count - 1,
+ run(Count2, MaxTime).
+
+ think(MaxTime):-
+ this(Philosopher),
+ random(1, MaxTime, ThinkTime),
+ message(['Philosopher ', Philosopher, ' thinking for ', ThinkTime, ' seconds.']),
+ thread_sleep(ThinkTime).
+
+ eat(MaxTime):-
+ this(Philosopher),
+ random(1, MaxTime, EatTime),
+ ::left_chopstick(LeftStick),
+ ::right_chopstick(RightStick),
+ LeftStick::pick_up,
+ RightStick::pick_up,
+ message(['Philosopher ', Philosopher, ' eating for ', EatTime, ' seconds with chopsticks ', LeftStick, ' and ', RightStick, '.']),
+ thread_sleep(EatTime),
+ ::LeftStick::put_down,
+ ::RightStick::put_down.
+
+ % writing a message needs to be synchronized as it's accomplished
+ % using a combination of individual write/1 and nl/0 calls:
+ message([]) :-
+ nl,
+ flush_output.
+ message([Atom| Atoms]) :-
+ write(Atom),
+ message(Atoms).
+
+:- end_category.
+
+
+:- object(aristotle,
+ imports(philosopher)).
+
+ left_chopstick(cs1).
+ right_chopstick(cs2).
+
+:- end_object.
+
+
+:- object(kant,
+ imports(philosopher)).
+
+ left_chopstick(cs2).
+ right_chopstick(cs3).
+
+:- end_object.
+
+
+:- object(spinoza,
+ imports(philosopher)).
+
+ left_chopstick(cs3).
+ right_chopstick(cs4).
+
+:- end_object.
+
+
+:- object(marx,
+ imports(philosopher)).
+
+ left_chopstick(cs4).
+ right_chopstick(cs5).
+
+:- end_object.
+
+
+:- object(russell,
+ imports(philosopher)).
+
+ left_chopstick(cs1). % change order so that the chopsticks are picked
+ right_chopstick(cs5). % in different order from the other philosophers
+
+:- end_object.
diff --git a/Task/Discordian-date/Icon/discordian-date.icon b/Task/Discordian-date/Icon/discordian-date.icon
new file mode 100644
index 0000000000..d33beaa4b6
--- /dev/null
+++ b/Task/Discordian-date/Icon/discordian-date.icon
@@ -0,0 +1,55 @@
+link printf
+
+procedure main()
+ Demo(2010,1,1)
+ Demo(2010,7,22)
+ Demo(2012,2,28)
+ Demo(2012,2,29)
+ Demo(2012,3,1)
+ Demo(2010,1,5)
+ Demo(2011,5,3)
+ Demo(2012,2,28)
+ Demo(2012,2,29)
+ Demo(2012,3,1)
+ Demo(2010,7,22)
+ Demo(2012,12,22)
+end
+
+procedure Demo(y,m,d) #: demo display
+ printf("%i-%i-%i = %s\n",y,m,d,DiscordianDateString(DiscordianDate(y,m,d)))
+end
+
+record DiscordianDateRecord(year,yday,season,sday,holiday)
+
+procedure DiscordianDate(year,month,day) #: Convert normal date to Discordian
+static cal
+initial cal := [31,28,31,30,31,30,31,31,30,31,30,31]
+
+ ddate := DiscordianDateRecord(year+1166)
+ every (ddate.yday := day - 1) +:= cal[1 to month-1] # zero origin
+ ddate.sday := ddate.yday
+
+ if ddate.year % 4 = 2 & month = 2 & day = 29 then
+ ddate.holiday := 1 # Note: st tibs is outside of weekdays
+ else {
+ ddate.season := (ddate.yday / 73) + 1
+ ddate.sday := (ddate.yday % 73) + 1
+ ddate.holiday := 1 + ddate.season * case ddate.sday of { 5 : 1; 50 : 2}
+ }
+ return ddate
+end
+
+procedure DiscordianDateString(ddate) #: format a Discordian Date String
+static days,seasons,holidays
+initial {
+ days := ["Sweetmorn","Boomtime","Pungenday","Prickle-Prickle","Setting Orange"]
+ seasons := ["Chaos","Discord","Confusion","Bureaucracy","The Aftermath"]
+ holidays := ["St. Tib's Day","Mungday","Chaoflux","Mojoday","Discoflux",
+ "Syaday","Confuflux","Zaraday","Bureflux","Maladay","Afflux"]
+ }
+
+ return (( holidays[\ddate.holiday] || "," ) |
+ ( days[1+ddate.yday%5] || ", day " ||
+ ddate.sday || " of " || seasons[ddate.season])) ||
+ " in the YOLD " || ddate.year
+end
diff --git a/Task/Discordian-date/J/discordian-date-1.j b/Task/Discordian-date/J/discordian-date-1.j
new file mode 100644
index 0000000000..96c63f3a87
--- /dev/null
+++ b/Task/Discordian-date/J/discordian-date-1.j
@@ -0,0 +1,4 @@
+require'dates'
+leap=: _1j1 * 0 -/@:= 4 100 400 |/ {.@]
+bs=: ((#:{.) + 0 j. *@[ * {:@]) +.
+disc=: ((1+0 73 bs[ +^:(58<]) -/@todayno@(,: 1 1,~{.)@]) ,~1166+{.@])~ leap
diff --git a/Task/Discordian-date/J/discordian-date-2.j b/Task/Discordian-date/J/discordian-date-2.j
new file mode 100644
index 0000000000..b8daed7f89
--- /dev/null
+++ b/Task/Discordian-date/J/discordian-date-2.j
@@ -0,0 +1,10 @@
+ disc 2012 2 28
+3178 1 59
+ disc 2012 2 29
+3178 1 59j1
+ disc 2012 3 1
+3178 1 60j1
+ disc 2012 12 31
+3178 5 73j1
+ disc 2013 1 1
+3179 1 1
diff --git a/Task/Discordian-date/Mathematica/discordian-date.mathematica b/Task/Discordian-date/Mathematica/discordian-date.mathematica
new file mode 100644
index 0000000000..2d489342cb
--- /dev/null
+++ b/Task/Discordian-date/Mathematica/discordian-date.mathematica
@@ -0,0 +1,15 @@
+DiscordianDate[y_, m_, d_] := Module[{year = ToString[y + 1166], month = m, day = d},
+
+ DMONTHS = {"Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"};
+ DDAYS = {"Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"};
+ DayOfYear = DateDifference[{y} ,{y, m, d}] + 1;
+ LeapYearQ = (Mod[#, 4]== 0 && (Mod[#, 100] != 0 || Mod[#, 400] == 0))&@ y;
+
+ If [ LeapYearQ && month == 2 && day == 29,
+ Print["Today is St. Tib's Day, YOLD ", ]
+ ,
+ If [ LeapYearQ && DayOfYear >= 60, DayOfYear -= 1 ];
+ {season, dday} = {Quotient[DayOfYear, 73], Mod[DayOfYear, 73]};
+ Print["Today is ", DDAYS[[Mod[dday,4] + 1]],", ",DMONTHS[[season+1]]," ",dday,", YOLD ",year]
+ ];
+]
diff --git a/Task/Distributed-programming/Mathematica/distributed-programming.mathematica b/Task/Distributed-programming/Mathematica/distributed-programming.mathematica
new file mode 100644
index 0000000000..40212777f6
--- /dev/null
+++ b/Task/Distributed-programming/Mathematica/distributed-programming.mathematica
@@ -0,0 +1,2 @@
+LaunchKernels[2];
+ParallelEvaluate[RandomReal[]]
diff --git a/Task/Documentation/Fancy/documentation.fancy b/Task/Documentation/Fancy/documentation.fancy
new file mode 100644
index 0000000000..875dd94f92
--- /dev/null
+++ b/Task/Documentation/Fancy/documentation.fancy
@@ -0,0 +1,13 @@
+def class Foo {
+ """
+ This is a docstring. Every object in Fancy can have it's own docstring.
+ Either defined in the source code, like this one, or by using the Object#docstring: method
+ """
+ def a_method {
+ """
+ Same for methods. They can have docstrings, too.
+ """
+ }
+}
+Foo docstring println # prints docstring Foo class
+Foo instance_method: 'a_method . docstring println # prints method's docstring
diff --git a/Task/Documentation/J/documentation.j b/Task/Documentation/J/documentation.j
new file mode 100644
index 0000000000..6d3f113263
--- /dev/null
+++ b/Task/Documentation/J/documentation.j
@@ -0,0 +1,24 @@
+NB. =========================================================
+NB.*apply v apply verb x to y
+apply=: 128!:2
+
+NB. =========================================================
+NB.*def c : (explicit definition)
+def=: :
+
+NB.*define a : 0 (explicit definition script form)
+define=: : 0
+
+NB.*do v name for ".
+do=: ".
+
+NB.*drop v name for }.
+drop=: }.
+
+ Note 1
+Note accepts multi-line descriptions.
+Definitions display the source.
+)
+
+ usleep
+3 : '''libc.so.6 usleep > i i''&(15!:0) >.y'
diff --git a/Task/Documentation/Mathematica/documentation.mathematica b/Task/Documentation/Mathematica/documentation.mathematica
new file mode 100644
index 0000000000..399259573c
--- /dev/null
+++ b/Task/Documentation/Mathematica/documentation.mathematica
@@ -0,0 +1,5 @@
+f[x_,y_] := x + y (* Function comment : adds two numbers *)
+f::usage = "f[x,y] gives the sum of x and y"
+
+?f
+-> f[x,y] gives the sum of x and y
diff --git a/Task/Dot-product/FALSE/dot-product.false b/Task/Dot-product/FALSE/dot-product.false
new file mode 100644
index 0000000000..b6d9033938
--- /dev/null
+++ b/Task/Dot-product/FALSE/dot-product.false
@@ -0,0 +1,3 @@
+[[\1-$0=~][$d;2*1+\-ø\$d;2+\-ø@*@+]#]p:
+3d: {Vectors' length}
+1 3 5_ 4 2_ 1_ d;$1+ø@*p;!%. {Output: 3}
diff --git a/Task/Dot-product/Factor/dot-product.factor b/Task/Dot-product/Factor/dot-product.factor
new file mode 100644
index 0000000000..c48f452146
--- /dev/null
+++ b/Task/Dot-product/Factor/dot-product.factor
@@ -0,0 +1,5 @@
+USING: kernel math.vectors sequences ;
+
+: dot-product ( u v -- w )
+ 2dup [ length ] bi@ =
+ [ v. ] [ "Vector lengths must be equal" throw ] if ;
diff --git a/Task/Dot-product/Fantom/dot-product.fantom b/Task/Dot-product/Fantom/dot-product.fantom
new file mode 100644
index 0000000000..58bba0f38b
--- /dev/null
+++ b/Task/Dot-product/Fantom/dot-product.fantom
@@ -0,0 +1,20 @@
+class DotProduct
+{
+ static Int dotProduct (Int[] a, Int[] b)
+ {
+ Int result := 0
+ [a.size,b.size].min.times |i|
+ {
+ result += a[i] * b[i]
+ }
+ return result
+ }
+
+ public static Void main ()
+ {
+ Int[] x := [1,2,3,4]
+ Int[] y := [2,3,4]
+
+ echo ("Dot product of $x and $y is ${dotProduct(x, y)}")
+ }
+}
diff --git a/Task/Dot-product/GAP/dot-product.gap b/Task/Dot-product/GAP/dot-product.gap
new file mode 100644
index 0000000000..7be9742cb5
--- /dev/null
+++ b/Task/Dot-product/GAP/dot-product.gap
@@ -0,0 +1,4 @@
+# Built-in
+
+[1, 3, -5]*[4, -2, -1];
+# 3
diff --git a/Task/Dot-product/Groovy/dot-product-1.groovy b/Task/Dot-product/Groovy/dot-product-1.groovy
new file mode 100644
index 0000000000..37716e8e76
--- /dev/null
+++ b/Task/Dot-product/Groovy/dot-product-1.groovy
@@ -0,0 +1,4 @@
+def dotProduct = { x, y ->
+ assert x && y && x.size() == y.size()
+ [x, y].transpose().collect{ it[0] * it[1] }.sum()
+}
diff --git a/Task/Dot-product/Groovy/dot-product-2.groovy b/Task/Dot-product/Groovy/dot-product-2.groovy
new file mode 100644
index 0000000000..f346f7ce8f
--- /dev/null
+++ b/Task/Dot-product/Groovy/dot-product-2.groovy
@@ -0,0 +1 @@
+println dotProduct([1, 3, -5], [4, -2, -1])
diff --git a/Task/Dot-product/Icon/dot-product.icon b/Task/Dot-product/Icon/dot-product.icon
new file mode 100644
index 0000000000..b290943a14
--- /dev/null
+++ b/Task/Dot-product/Icon/dot-product.icon
@@ -0,0 +1,9 @@
+procedure main()
+write("a dot b := ",dotproduct([1, 3, -5],[4, -2, -1]))
+end
+
+procedure dotproduct(a,b) #: return dot product of vectors a & b or error
+if *a ~= *b & type(a) == type(b) == "list" then runerr(205,a) # invalid value
+every (dp := 0) +:= a[i := 1 to *a] * b[i]
+return dp
+end
diff --git a/Task/Dot-product/J/dot-product.j b/Task/Dot-product/J/dot-product.j
new file mode 100644
index 0000000000..b8e9d31691
--- /dev/null
+++ b/Task/Dot-product/J/dot-product.j
@@ -0,0 +1,5 @@
+ 1 3 _5 +/ . * 4 _2 _1
+3
+ dotp=: +/ . * NB. Or defined as a verb (function)
+ 1 3 _5 dotp 4 _2 _1
+3
diff --git a/Task/Dot-product/Julia/dot-product.julia b/Task/Dot-product/Julia/dot-product.julia
new file mode 100644
index 0000000000..c1b2f8c7ff
--- /dev/null
+++ b/Task/Dot-product/Julia/dot-product.julia
@@ -0,0 +1,3 @@
+x = [1 3 -5]
+y = [4 -2 -1]
+z = dot(x, y)
diff --git a/Task/Dot-product/K/dot-product.k b/Task/Dot-product/K/dot-product.k
new file mode 100644
index 0000000000..e09f04441b
--- /dev/null
+++ b/Task/Dot-product/K/dot-product.k
@@ -0,0 +1,5 @@
+ +/1 3 -5 * 4 -2 -1
+3
+
+ 1 3 -5 _dot 4 -2 -1
+3
diff --git a/Task/Dot-product/Liberty-BASIC/dot-product.liberty b/Task/Dot-product/Liberty-BASIC/dot-product.liberty
new file mode 100644
index 0000000000..c6bb69b588
--- /dev/null
+++ b/Task/Dot-product/Liberty-BASIC/dot-product.liberty
@@ -0,0 +1,24 @@
+vectorA$ = "1, 3, -5"
+vectorB$ = "4, -2, -1"
+print "DotProduct of ";vectorA$;" and "; vectorB$;" is ";
+print DotProduct(vectorA$, vectorB$)
+
+'arbitrary length
+vectorA$ = "3, 14, 15, 9, 26"
+vectorB$ = "2, 71, 18, 28, 1"
+print "DotProduct of ";vectorA$;" and "; vectorB$;" is ";
+print DotProduct(vectorA$, vectorB$)
+
+end
+
+function DotProduct(a$, b$)
+ DotProduct = 0
+ i = 1
+ while 1
+ x$=word$( a$, i, ",")
+ y$=word$( b$, i, ",")
+ if x$="" or y$="" then exit function
+ DotProduct = DotProduct + val(x$)*val(y$)
+ i = i+1
+ wend
+end function
diff --git a/Task/Dot-product/Logo/dot-product.logo b/Task/Dot-product/Logo/dot-product.logo
new file mode 100644
index 0000000000..10561054b0
--- /dev/null
+++ b/Task/Dot-product/Logo/dot-product.logo
@@ -0,0 +1,5 @@
+to dotprod :a :b
+ output apply "sum (map "product :a :b)
+end
+
+show dotprod [1 3 -5] [4 -2 -1] ; 3
diff --git a/Task/Dot-product/Logtalk/dot-product.logtalk b/Task/Dot-product/Logtalk/dot-product.logtalk
new file mode 100644
index 0000000000..c694436302
--- /dev/null
+++ b/Task/Dot-product/Logtalk/dot-product.logtalk
@@ -0,0 +1,7 @@
+dot_product(A, B, Sum) :-
+ dot_product(A, B, 0, Sum).
+
+dot_product([], [], Sum, Sum).
+dot_product([A| As], [B| Bs], Acc, Sum) :-
+ Acc2 is Acc + A*B,
+ dot_product(As, Bs, Acc2, Sum).
diff --git a/Task/Dot-product/MUMPS/dot-product.mumps b/Task/Dot-product/MUMPS/dot-product.mumps
new file mode 100644
index 0000000000..6b94761e96
--- /dev/null
+++ b/Task/Dot-product/MUMPS/dot-product.mumps
@@ -0,0 +1,9 @@
+DOTPROD(A,B)
+ ;Returns the dot product of two vectors. Vectors are assumed to be stored as caret-delimited strings of numbers.
+ ;If the vectors are not of equal length, a null string is returned.
+ QUIT:$LENGTH(A,"^")'=$LENGTH(B,"^") ""
+ NEW I,SUM
+ SET SUM=0
+ FOR I=1:1:$LENGTH(A,"^") SET SUM=SUM+($PIECE(A,"^",I)*$PIECE(B,"^",I))
+ KILL I
+ QUIT SUM
diff --git a/Task/Dot-product/Mathematica/dot-product.mathematica b/Task/Dot-product/Mathematica/dot-product.mathematica
new file mode 100644
index 0000000000..8a11f2990f
--- /dev/null
+++ b/Task/Dot-product/Mathematica/dot-product.mathematica
@@ -0,0 +1 @@
+{1,3,-5}.{4,-2,-1}
diff --git a/Task/Dot-product/Maxima/dot-product.maxima b/Task/Dot-product/Maxima/dot-product.maxima
new file mode 100644
index 0000000000..dd98fb5323
--- /dev/null
+++ b/Task/Dot-product/Maxima/dot-product.maxima
@@ -0,0 +1,2 @@
+[1, 3, -5] . [4, -2, -1];
+/* 3 */
diff --git a/Task/Dot-product/Mercury/dot-product.mercury b/Task/Dot-product/Mercury/dot-product.mercury
new file mode 100644
index 0000000000..7206bf7a4b
--- /dev/null
+++ b/Task/Dot-product/Mercury/dot-product.mercury
@@ -0,0 +1,17 @@
+:- module dot_product.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int, list.
+
+main(!IO) :-
+ io.write_int([1, 3, -5] `dot_product` [4, -2, -1], !IO),
+ io.nl(!IO).
+
+:- func dot_product(list(int), list(int)) = int.
+
+dot_product(As, Bs) =
+ list.foldl_corresponding((func(A, B, Acc) = Acc + A * B), As, Bs, 0).
diff --git a/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-1.j b/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-1.j
new file mode 100644
index 0000000000..87f3b7cfea
--- /dev/null
+++ b/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-1.j
@@ -0,0 +1,6 @@
+coclass'DoublyLinkedListElement'
+create=:3 :0
+ this=:coname''
+ 'predecessor successor data'=:y
+ successor__predecessor=: predecessor__successor=: this
+)
diff --git a/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-2.j b/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-2.j
new file mode 100644
index 0000000000..ce0b36e77d
--- /dev/null
+++ b/Task/Doubly-linked-list-Element-definition/J/doubly-linked-list-element-definition-2.j
@@ -0,0 +1,4 @@
+coclass'DoublyLinkedListHead'
+create=:3 :0
+ predecessor=:successor=:this=: coname''
+)
diff --git a/Task/Doubly-linked-list-Element-definition/Modula-2/doubly-linked-list-element-definition.mod2 b/Task/Doubly-linked-list-Element-definition/Modula-2/doubly-linked-list-element-definition.mod2
new file mode 100644
index 0000000000..aac65cf20d
--- /dev/null
+++ b/Task/Doubly-linked-list-Element-definition/Modula-2/doubly-linked-list-element-definition.mod2
@@ -0,0 +1,6 @@
+TYPE
+ Link = POINTER TO LinkRcd;
+ LinkRcd = RECORD
+ Prev, Next: Link;
+ Data: INTEGER
+ END;
diff --git a/Task/Doubly-linked-list-Traversal/J/doubly-linked-list-traversal.j b/Task/Doubly-linked-list-Traversal/J/doubly-linked-list-traversal.j
new file mode 100644
index 0000000000..1b106031d6
--- /dev/null
+++ b/Task/Doubly-linked-list-Traversal/J/doubly-linked-list-traversal.j
@@ -0,0 +1,8 @@
+traverse=:1 :0
+ work=. result=. conew 'DoublyLinkedListHead'
+ current=. y
+ while. y ~: current=. successor__current do.
+ work=. (work;result;0
+ print tab(2);dechex$(hCurrent);" ";Block.name$(hCurrent);" ";Block.age(hCurrent)
+ hCurrent=Block.next(hCurrent)
+ wend
+
+ print
+ print "-Deleting first, middle, and last person."
+
+ call Delete FirstUser'1
+ call Delete MiddleUser'2
+ call Delete LastUser'3
+
+ print
+ print "-Traversing the list backwards"
+ hCurrent=hLast
+ while hCurrent<>0
+ print tab(2);dechex$(hCurrent);" ";Block.name$(hCurrent);" ";Block.age(hCurrent)
+ hCurrent=Block.prev(hCurrent)
+ wend
+
+call Uninit
+
+end
+
+
+function Block.next(hBlock)
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ Block.next=block.nxt.struct
+end function
+
+function Block.prev(hBlock)
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ Block.prev=block.prev.struct
+end function
+
+function Block.age(hBlock)
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ Block.age=block.age.struct
+end function
+
+function Block.name$(hBlock)
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ Block.name$=block.nm.struct
+end function
+
+sub Block.age hBlock,age
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ block.age.struct=age
+ calldll #kernel32,"RtlMoveMemory",hBlock as ulong,block as struct,blockSize as long,ret as void
+end sub
+
+sub Block.name hBlock,name$
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ block.nm.struct=name$
+ calldll #kernel32,"RtlMoveMemory",hBlock as ulong,block as struct,blockSize as long,ret as void
+end sub
+
+sub Block.next hBlock,nxt
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ block.nxt.struct=nxt
+ calldll #kernel32,"RtlMoveMemory",hBlock as ulong,block as struct,blockSize as long,ret as void
+end sub
+
+sub Block.prev hBlock,prev
+ calldll #kernel32,"RtlMoveMemory",block as struct,hBlock as ulong,blockSize as long,ret as void
+ block.prev.struct=prev
+ calldll #kernel32,"RtlMoveMemory",hBlock as ulong,block as struct,blockSize as long,ret as void
+end sub
+
+function New(name$,age)
+ calldll #kernel32,"HeapAlloc",hHeap as ulong,_HEAP_ZERO_MEMORY as ulong,blockSize as long,New as ulong
+ if New<>0 then
+ blockCount=blockCount+1
+ if hFirst=0 then
+ hFirst=New
+ hLast=New
+ else
+ call Block.next hLast,New
+ call Block.prev New,hLast
+ hLast=New
+ end if
+ call Block.name New,name$
+ call Block.age New,age
+ end if
+end function
+
+sub Delete hBlock
+ if hBlock<>0 then
+ blockCount=blockCount-1
+ if blockCount=0 then
+ hFirst=0
+ hLast=0
+ else
+ if hBlock=hFirst then
+ hFirst=Block.next(hBlock)
+ call Block.prev hFirst,0
+ else
+ if hBlock=hLast then
+ hLast=Block.prev(hBlock)
+ call Block.next hLast,0
+ else
+ call Block.next Block.prev(hBlock),Block.next(hBlock)
+ call Block.prev Block.next(hBlock),Block.prev(hBlock)
+ end if
+ end if
+ end if
+ calldll #kernel32,"HeapFree",hHeap as ulong,0 as long,hBlock as ulong,ret as void
+ end if
+end sub
+
+
+sub Init
+ calldll #kernel32,"HeapCreate",0 as long,10000 as long,0 as long,hHeap as ulong
+end sub
+
+sub Uninit
+ calldll #kernel32,"HeapDestroy",hHeap as ulong,ret as void
+end sub
diff --git a/Task/Draw-a-cuboid/J/draw-a-cuboid.j b/Task/Draw-a-cuboid/J/draw-a-cuboid.j
new file mode 100644
index 0000000000..f56586ee76
--- /dev/null
+++ b/Task/Draw-a-cuboid/J/draw-a-cuboid.j
@@ -0,0 +1,22 @@
+ vectors =. ((% +/&.:*:"1) _1 1 0,:_1 _1 3) +/@:*"1/~ 2 3 4*=i.3
+ ' .*o' {~ +/ 1 2 3* (|:"2 -."_ 1~ vectors) ([:*./ 1 = 0 1 I. %.~)"_ 1"_1 _ ]4j21 ,~"0/&:i: 4j41
+
+
+
+
+
+
+
+ oooo
+ ooooooooooooo
+ oooooooooooooo....
+ *****oooo.........
+ *******...........
+ *******...........
+ *******...........
+ *******...........
+ *******...........
+ *******...........
+ *******...........
+ *******.........
+ *****.....
diff --git a/Task/Draw-a-cuboid/LSL/draw-a-cuboid.lsl b/Task/Draw-a-cuboid/LSL/draw-a-cuboid.lsl
new file mode 100644
index 0000000000..0d6097b52c
--- /dev/null
+++ b/Task/Draw-a-cuboid/LSL/draw-a-cuboid.lsl
@@ -0,0 +1,6 @@
+vector vSCALE = <2.0, 3.0, 4.0>;
+default {
+ state_entry() {
+ llSetScale(vSCALE);
+ }
+}
diff --git a/Task/Draw-a-cuboid/Logo/draw-a-cuboid-1.logo b/Task/Draw-a-cuboid/Logo/draw-a-cuboid-1.logo
new file mode 100644
index 0000000000..c5ffbbbf14
--- /dev/null
+++ b/Task/Draw-a-cuboid/Logo/draw-a-cuboid-1.logo
@@ -0,0 +1,14 @@
+to cuboid :l1 :l2 :l3
+cs perspective ;making the room ready to use
+setxyz :l1 0 0
+setxyz :l1 :l2 0
+setxyz 0 :l2 0
+setxyz 0 0 0
+setxyz :l1 0 0
+setxyz :l1 0 -:l3
+setxyz :l1 :l2 -:l3
+setxyz :l1 :l2 0
+setxyz 0 :l2 0
+setxyz 0 :l2 -:l3
+setxyz :l1 :l2 -:l3
+end
diff --git a/Task/Draw-a-cuboid/Logo/draw-a-cuboid-2.logo b/Task/Draw-a-cuboid/Logo/draw-a-cuboid-2.logo
new file mode 100644
index 0000000000..084c856e4c
--- /dev/null
+++ b/Task/Draw-a-cuboid/Logo/draw-a-cuboid-2.logo
@@ -0,0 +1 @@
+cuboid 50 100 150
diff --git a/Task/Draw-a-cuboid/Mathematica/draw-a-cuboid.mathematica b/Task/Draw-a-cuboid/Mathematica/draw-a-cuboid.mathematica
new file mode 100644
index 0000000000..d937962fa1
--- /dev/null
+++ b/Task/Draw-a-cuboid/Mathematica/draw-a-cuboid.mathematica
@@ -0,0 +1 @@
+Graphics3D[Cuboid[{0,0,0},{2,3,4}]]
diff --git a/Task/Draw-a-cuboid/Maxima/draw-a-cuboid.maxima b/Task/Draw-a-cuboid/Maxima/draw-a-cuboid.maxima
new file mode 100644
index 0000000000..ba85cc62e8
--- /dev/null
+++ b/Task/Draw-a-cuboid/Maxima/draw-a-cuboid.maxima
@@ -0,0 +1,6 @@
+load(draw)$
+
+draw3d(xu_grid=100, yv_grid=100, surface_hide=true,
+ palette=gray, enhanced3d=[x - z / 4 - y / 4, x, y, z],
+ implicit(max(abs(x / 4), abs(y / 6), abs(z / 8)) = 1,
+ x,-10,10,y,-10,10,z,-10,10))$
diff --git a/Task/Draw-a-sphere/J/draw-a-sphere-1.j b/Task/Draw-a-sphere/J/draw-a-sphere-1.j
new file mode 100644
index 0000000000..b2bd7bb7f2
--- /dev/null
+++ b/Task/Draw-a-sphere/J/draw-a-sphere-1.j
@@ -0,0 +1 @@
+load 'system/examples/graphics/opengl/simple/sphere.ijs'
diff --git a/Task/Draw-a-sphere/J/draw-a-sphere-2.j b/Task/Draw-a-sphere/J/draw-a-sphere-2.j
new file mode 100644
index 0000000000..d97a96eb72
--- /dev/null
+++ b/Task/Draw-a-sphere/J/draw-a-sphere-2.j
@@ -0,0 +1,8 @@
+'R k ambient' =. 10 2 0.4
+light =. (% +/&.:*:) 30 30 _50
+pts =. (0&*^:(0={:))@:(,,(0>.(*:R)-+)&.*:)"0/~ i:15j200
+luminosity =. (>:ambient) %~ (ambient * * +/&.:*:"1 pts) + k^~ 0>. R%~ pts +/@:*"1 -light
+
+load 'viewmat'
+togreyscale =. 256 #. [: <. 255 255 255 *"1 0 ]
+'rgb' viewmat togreyscale luminosity
diff --git a/Task/Draw-a-sphere/Liberty-BASIC/draw-a-sphere.liberty b/Task/Draw-a-sphere/Liberty-BASIC/draw-a-sphere.liberty
new file mode 100644
index 0000000000..735550a7b8
--- /dev/null
+++ b/Task/Draw-a-sphere/Liberty-BASIC/draw-a-sphere.liberty
@@ -0,0 +1,26 @@
+WindowWidth =420
+WindowHeight =460
+
+nomainwin
+
+open "Sphere" for graphics_nsb_nf as #w
+
+#w "down ; fill lightgray"
+
+xS =200
+yS =200
+for radius =150 to 0 step -1
+ level$ =str$( int( 256 -256 *radius /150))
+ c$ =level$ +" " +level$ +" " +level$
+ #w "color "; c$
+ #w "backcolor "; c$
+ #w "place "; xS; " "; yS
+ xS =xS -0.5
+ yS =yS -0.2
+ #w "circlefilled "; radius
+next radius
+
+#w "flush"
+wait
+close #w
+end
diff --git a/Task/Draw-a-sphere/Logo/draw-a-sphere.logo b/Task/Draw-a-sphere/Logo/draw-a-sphere.logo
new file mode 100644
index 0000000000..04204f24c5
--- /dev/null
+++ b/Task/Draw-a-sphere/Logo/draw-a-sphere.logo
@@ -0,0 +1,5 @@
+to sphere :r
+cs perspective ht ;making the room ready to use
+repeat 180 [polystart circle :r polyend down 1]
+polyview
+end
diff --git a/Task/Draw-a-sphere/Mathematica/draw-a-sphere.mathematica b/Task/Draw-a-sphere/Mathematica/draw-a-sphere.mathematica
new file mode 100644
index 0000000000..05da40b277
--- /dev/null
+++ b/Task/Draw-a-sphere/Mathematica/draw-a-sphere.mathematica
@@ -0,0 +1 @@
+Graphics3D[Sphere[{0,0,0},1]]
diff --git a/Task/Draw-a-sphere/Maxima/draw-a-sphere.maxima b/Task/Draw-a-sphere/Maxima/draw-a-sphere.maxima
new file mode 100644
index 0000000000..53b3456095
--- /dev/null
+++ b/Task/Draw-a-sphere/Maxima/draw-a-sphere.maxima
@@ -0,0 +1,11 @@
+/* Two solutions */
+plot3d(1, [theta, 0, %pi], [phi, 0, 2 * %pi],
+[transform_xy, spherical_to_xyz], [grid, 30, 60],
+[box, false], [legend, false])$
+
+load(draw)$
+draw3d(xu_grid=30, yv_grid=60, surface_hide=true,
+ parametric_surface(cos(phi)*sin(theta),
+ sin(phi)*sin(theta),
+ cos(theta),
+ theta, 0, %pi, phi, 0, 2 * %pi))$
diff --git a/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-1.j b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-1.j
new file mode 100644
index 0000000000..e979f9ffef
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-1.j
@@ -0,0 +1 @@
+i2b=: {&(;:'red white blue')
diff --git a/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-2.j b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-2.j
new file mode 100644
index 0000000000..f564c04ad7
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-2.j
@@ -0,0 +1 @@
+b2i=: i2b inv
diff --git a/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-3.j b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-3.j
new file mode 100644
index 0000000000..749124a248
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-3.j
@@ -0,0 +1,5 @@
+ BALLS=: i2b ?20#3
+ BALLS
+┌────┬───┬────┬───┬───┬─────┬─────┬─────┬────┬────┬─────┬────┬────┬───┬────┬───┬─────┬───┬────┬───┐
+│blue│red│blue│red│red│white│white│white│blue│blue│white│blue│blue│red│blue│red│white│red│blue│red│
+└────┴───┴────┴───┴───┴─────┴─────┴─────┴────┴────┴─────┴────┴────┴───┴────┴───┴─────┴───┴────┴───┘
diff --git a/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-4.j b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-4.j
new file mode 100644
index 0000000000..79b203affa
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-4.j
@@ -0,0 +1,4 @@
+ /:~&.b2i BALLS
+┌───┬───┬───┬───┬───┬───┬───┬─────┬─────┬─────┬─────┬─────┬────┬────┬────┬────┬────┬────┬────┬────┐
+│red│red│red│red│red│red│red│white│white│white│white│white│blue│blue│blue│blue│blue│blue│blue│blue│
+└───┴───┴───┴───┴───┴───┴───┴─────┴─────┴─────┴─────┴─────┴────┴────┴────┴────┴────┴────┴────┴────┘
diff --git a/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-5.j b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-5.j
new file mode 100644
index 0000000000..f1f09cbf7b
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/J/dutch-national-flag-problem-5.j
@@ -0,0 +1 @@
+ assert@(-: /:~)&b2i /:~&.b2i BALLS
diff --git a/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-1.logo b/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-1.logo
new file mode 100644
index 0000000000..e9a2621418
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-1.logo
@@ -0,0 +1,68 @@
+; We'll just use words for the balls
+make "colors {red white blue}
+
+; to get a mapping from colors back to a numeric value,
+; we make variables out of the color names (e.g. the variable
+; "red" has value "1").
+foreach arraytolist :colors [
+ make ? #
+]
+
+; Make a random list of a given size
+to random_balls :n
+ local "balls
+ make "balls array n
+ repeat n [
+ setitem # :balls pick :colors
+ ]
+ output :balls
+end
+
+; Test for Dutchness
+to dutch? :array
+ output dutchlist? arraytolist :array
+end
+
+; List is easier than array to test
+to dutchlist? :list
+ output cond [
+ [(less? count :list 2) "true]
+ [(greater? thing first :list thing item 2 :list) "false ]
+ [else dutchlist? butfirst :list]
+ ]
+end
+
+; But array is better for sorting algorithm
+to dutch :array
+ local "lo
+ make "lo 0
+ local "hi
+ make "hi sum 1 count :array
+ local "i
+ make "i 1
+ while [:i < :hi] [
+ case (item :i :array) [
+ [[red]
+ make "lo sum :lo 1
+ swap :array :lo :i
+ make "i sum :i 1
+ ]
+ [[white]
+ make "i sum :i 1
+ ]
+ [[blue]
+ make "hi difference :hi 1
+ swap :array :hi :i
+ ]
+ ]
+ ]
+ output :array
+end
+
+; utility routine to swap array elements
+to swap :array :a :b
+ local "temp
+ make "temp item :a :array
+ setitem :a :array item :b :array
+ setitem :b :array :temp
+end
diff --git a/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-2.logo b/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-2.logo
new file mode 100644
index 0000000000..277ff0f2b0
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/Logo/dutch-national-flag-problem-2.logo
@@ -0,0 +1,7 @@
+do.while [
+ make "list random_balls 10
+] [dutch? :list]
+
+print (sentence [Start list:] arraytolist :list)
+print (sentence [Sorted:] arraytolist dutch :list)
+bye
diff --git a/Task/Dutch-national-flag-problem/Mathematica/dutch-national-flag-problem.mathematica b/Task/Dutch-national-flag-problem/Mathematica/dutch-national-flag-problem.mathematica
new file mode 100644
index 0000000000..44cd140f90
--- /dev/null
+++ b/Task/Dutch-national-flag-problem/Mathematica/dutch-national-flag-problem.mathematica
@@ -0,0 +1 @@
+flagSort[data_List] := Sort[data, (#1 === RED || #2 === BLUE) &]
diff --git a/Task/Dynamic-variable-names/GAP/dynamic-variable-names.gap b/Task/Dynamic-variable-names/GAP/dynamic-variable-names.gap
new file mode 100644
index 0000000000..33e9f11fe8
--- /dev/null
+++ b/Task/Dynamic-variable-names/GAP/dynamic-variable-names.gap
@@ -0,0 +1,4 @@
+# As is, will not work if val is a String
+Assign := function(var, val)
+ Read(InputTextString(Concatenation(var, " := ", String(val), ";")));
+end;
diff --git a/Task/Dynamic-variable-names/Genyris/dynamic-variable-names.genyris b/Task/Dynamic-variable-names/Genyris/dynamic-variable-names.genyris
new file mode 100644
index 0000000000..9cf8f1d846
--- /dev/null
+++ b/Task/Dynamic-variable-names/Genyris/dynamic-variable-names.genyris
@@ -0,0 +1,2 @@
+defvar (intern 'This is not a pipe.') 42
+define || 2009
diff --git a/Task/Dynamic-variable-names/Groovy/dynamic-variable-names.groovy b/Task/Dynamic-variable-names/Groovy/dynamic-variable-names.groovy
new file mode 100644
index 0000000000..b77e9678d5
--- /dev/null
+++ b/Task/Dynamic-variable-names/Groovy/dynamic-variable-names.groovy
@@ -0,0 +1,6 @@
+def varname = 'foo'
+def value = 42
+
+new GroovyShell(this.binding).evaluate("${varname} = ${value}")
+
+assert foo == 42
diff --git a/Task/Dynamic-variable-names/Icon/dynamic-variable-names.icon b/Task/Dynamic-variable-names/Icon/dynamic-variable-names.icon
new file mode 100644
index 0000000000..2670e495ff
--- /dev/null
+++ b/Task/Dynamic-variable-names/Icon/dynamic-variable-names.icon
@@ -0,0 +1,5 @@
+procedure main(arglist)
+if *arglist = 0 then stop("Provide the names of variables in the argument list")
+&dump := 1 # dump program state information and variables after run
+every variable(!arglist) := 1 # set each user specified variable name in arglist to 1
+end
diff --git a/Task/Dynamic-variable-names/J/dynamic-variable-names-1.j b/Task/Dynamic-variable-names/J/dynamic-variable-names-1.j
new file mode 100644
index 0000000000..f1da048363
--- /dev/null
+++ b/Task/Dynamic-variable-names/J/dynamic-variable-names-1.j
@@ -0,0 +1,2 @@
+require 'misc'
+(prompt 'Enter variable name: ')=: 0
diff --git a/Task/Dynamic-variable-names/J/dynamic-variable-names-2.j b/Task/Dynamic-variable-names/J/dynamic-variable-names-2.j
new file mode 100644
index 0000000000..243910165c
--- /dev/null
+++ b/Task/Dynamic-variable-names/J/dynamic-variable-names-2.j
@@ -0,0 +1,5 @@
+ require 'misc'
+ (prompt 'Enter variable name: ')=: 0
+Enter variable name: FOO
+ FOO
+0
diff --git a/Task/Dynamic-variable-names/J/dynamic-variable-names-3.j b/Task/Dynamic-variable-names/J/dynamic-variable-names-3.j
new file mode 100644
index 0000000000..a2700077af
--- /dev/null
+++ b/Task/Dynamic-variable-names/J/dynamic-variable-names-3.j
@@ -0,0 +1 @@
+(userDefined)=: 0
diff --git a/Task/Dynamic-variable-names/Logo/dynamic-variable-names.logo b/Task/Dynamic-variable-names/Logo/dynamic-variable-names.logo
new file mode 100644
index 0000000000..431d159dfe
--- /dev/null
+++ b/Task/Dynamic-variable-names/Logo/dynamic-variable-names.logo
@@ -0,0 +1,5 @@
+? make readword readword
+julie
+12
+? show :julie
+12
diff --git a/Task/Dynamic-variable-names/M4/dynamic-variable-names.m4 b/Task/Dynamic-variable-names/M4/dynamic-variable-names.m4
new file mode 100644
index 0000000000..48b758a120
--- /dev/null
+++ b/Task/Dynamic-variable-names/M4/dynamic-variable-names.m4
@@ -0,0 +1,5 @@
+Enter foo, please.
+define(`inp',esyscmd(`echoinp'))
+define(`trim',substr(inp,0,decr(len(inp))))
+define(trim,42)
+foo
diff --git a/Task/Dynamic-variable-names/MUMPS/dynamic-variable-names.mumps b/Task/Dynamic-variable-names/MUMPS/dynamic-variable-names.mumps
new file mode 100644
index 0000000000..dad7136e18
--- /dev/null
+++ b/Task/Dynamic-variable-names/MUMPS/dynamic-variable-names.mumps
@@ -0,0 +1,12 @@
+USER>KILL ;Clean up workspace
+
+USER>WRITE ;show all variables and definitions
+
+USER>READ "Enter a variable name: ",A
+Enter a variable name: GIBBERISH
+USER>SET @A=3.14159
+
+USER>WRITE
+
+A="GIBBERISH"
+GIBBERISH=3.14159
diff --git a/Task/Dynamic-variable-names/Mathematica/dynamic-variable-names.mathematica b/Task/Dynamic-variable-names/Mathematica/dynamic-variable-names.mathematica
new file mode 100644
index 0000000000..72f5c4a78a
--- /dev/null
+++ b/Task/Dynamic-variable-names/Mathematica/dynamic-variable-names.mathematica
@@ -0,0 +1,4 @@
+varname = InputString["Enter a variable name"];
+varvalue = InputString["Enter a value"];
+ReleaseHold[ Hold[Set["nameholder", "value"]] /. {"nameholder" -> Symbol[varname], "value" -> varvalue}];
+Print[varname, " is now set to ", Symbol[varname]]
diff --git a/Task/Dynamic-variable-names/Maxima/dynamic-variable-names.maxima b/Task/Dynamic-variable-names/Maxima/dynamic-variable-names.maxima
new file mode 100644
index 0000000000..2259b0e24e
--- /dev/null
+++ b/Task/Dynamic-variable-names/Maxima/dynamic-variable-names.maxima
@@ -0,0 +1,2 @@
+/* Use :: for indirect assignment */
+block([name: read("name?"), x: read("value?")], name :: x);
diff --git a/Task/Echo-server/Factor/echo-server.factor b/Task/Echo-server/Factor/echo-server.factor
new file mode 100644
index 0000000000..a154c9b263
--- /dev/null
+++ b/Task/Echo-server/Factor/echo-server.factor
@@ -0,0 +1,17 @@
+USING: accessors io io.encodings.utf8 io.servers.connection
+threads ;
+IN: rosetta.echo
+
+CONSTANT: echo-port 12321
+
+: handle-client ( -- )
+ [ write "\r\n" write flush ] each-line ;
+
+: ( -- threaded-server )
+ utf8
+ "echo-server" >>name
+ echo-port >>insecure
+ [ handle-client ] >>handler ;
+
+: start-echo-server ( -- threaded-server )
+ [ start-server ] in-thread ;
diff --git a/Task/Element-wise-operations/J/element-wise-operations.j b/Task/Element-wise-operations/J/element-wise-operations.j
new file mode 100644
index 0000000000..1c81dffa49
--- /dev/null
+++ b/Task/Element-wise-operations/J/element-wise-operations.j
@@ -0,0 +1,24 @@
+ scalar =: 10
+ vector =: 2 3 5
+ matrix =: 3 3 $ 7 11 13 17 19 23 29 31 37
+
+ scalar * scalar
+100
+ scalar * vector
+20 30 50
+ scalar * matrix
+ 70 110 130
+170 190 230
+290 310 370
+
+ vector * vector
+4 9 25
+ vector * matrix
+ 14 22 26
+ 51 57 69
+145 155 185
+
+ matrix * matrix
+ 49 121 169
+289 361 529
+841 961 1369
diff --git a/Task/Element-wise-operations/K/element-wise-operations.k b/Task/Element-wise-operations/K/element-wise-operations.k
new file mode 100644
index 0000000000..6c7657157d
--- /dev/null
+++ b/Task/Element-wise-operations/K/element-wise-operations.k
@@ -0,0 +1,24 @@
+ scalar: 10
+ vector: 2 3 5
+ matrix: 3 3 # 7 11 13 17 19 23 29 31 37
+
+ scalar * scalar
+100
+ scalar * vector
+20 30 50
+ scalar * matrix
+(70 110 130
+ 170 190 230
+ 290 310 370)
+
+ vector * vector
+4 9 25
+ vector * matrix
+(14 22 26
+ 51 57 69
+ 145 155 185)
+
+ matrix * matrix
+(49 121 169
+ 289 361 529
+ 841 961 1369)
diff --git a/Task/Element-wise-operations/Mathematica/element-wise-operations.mathematica b/Task/Element-wise-operations/Mathematica/element-wise-operations.mathematica
new file mode 100644
index 0000000000..82a97abc2b
--- /dev/null
+++ b/Task/Element-wise-operations/Mathematica/element-wise-operations.mathematica
@@ -0,0 +1,32 @@
+S = 10 ; M = {{7, 11, 13}, {17 , 19, 23} , {29, 31, 37}};
+M + S
+M - S
+M * S
+M / S
+M ^ S
+
+M + M
+M - M
+M * M
+M / M
+M ^ M
+
+Gives:
+
+->{{17, 21, 23}, {27, 29, 33}, {39, 41, 47}}
+->{{-3, 1, 3}, {7, 9, 13}, {19, 21, 27}}
+->{{70, 110, 130}, {170, 190, 230}, {290, 310, 370}}
+->{{7/10, 11/10, 13/10}, {17/10, 19/10, 23/10}, {29/10, 31/10, 37/10}}
+->{{282475249, 25937424601, 137858491849}, {2015993900449,
+ 6131066257801, 41426511213649}, {420707233300201, 819628286980801,
+ 4808584372417849}}
+
+->{{14, 22, 26}, {34, 38, 46}, {58, 62, 74}}
+->{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
+->{{49, 121, 169}, {289, 361, 529}, {841, 961, 1369}}
+->{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
+->{{823543, 285311670611, 302875106592253}, {827240261886336764177,
+ 1978419655660313589123979,
+ 20880467999847912034355032910567}, {2567686153161211134561828214731016126483469,
+ 17069174130723235958610643029059314756044734431,
+ 10555134955777783414078330085995832946127396083370199442517}}
diff --git a/Task/Element-wise-operations/Maxima/element-wise-operations.maxima b/Task/Element-wise-operations/Maxima/element-wise-operations.maxima
new file mode 100644
index 0000000000..843767481a
--- /dev/null
+++ b/Task/Element-wise-operations/Maxima/element-wise-operations.maxima
@@ -0,0 +1,11 @@
+a: matrix([1, 2], [3, 4]);
+b: matrix([2, 4], [3, 1]);
+
+a * b;
+a / b;
+a + b;
+a - b;
+a^3;
+a^b; /* won't work */
+fullmapl("^", a, b);
+sin(a);
diff --git a/Task/Empty-directory/Groovy/empty-directory-1.groovy b/Task/Empty-directory/Groovy/empty-directory-1.groovy
new file mode 100644
index 0000000000..952baef099
--- /dev/null
+++ b/Task/Empty-directory/Groovy/empty-directory-1.groovy
@@ -0,0 +1,4 @@
+def isDirEmpty = { dirName ->
+ def dir = new File(dirName)
+ dir.exists() && dir.directory && (dir.list() as List).empty
+}
diff --git a/Task/Empty-directory/Groovy/empty-directory-2.groovy b/Task/Empty-directory/Groovy/empty-directory-2.groovy
new file mode 100644
index 0000000000..4d1fc06cd8
--- /dev/null
+++ b/Task/Empty-directory/Groovy/empty-directory-2.groovy
@@ -0,0 +1,9 @@
+def currentDir = new File('.')
+def random = new Random()
+def subDirName = "dir${random.nextInt(100000)}"
+def subDir = new File(subDirName)
+subDir.mkdir()
+subDir.deleteOnExit()
+
+assert ! isDirEmpty('.')
+assert isDirEmpty(subDirName)
diff --git a/Task/Empty-directory/J/empty-directory-1.j b/Task/Empty-directory/J/empty-directory-1.j
new file mode 100644
index 0000000000..ab8c438801
--- /dev/null
+++ b/Task/Empty-directory/J/empty-directory-1.j
@@ -0,0 +1,2 @@
+require 'dir'
+empty_dir=: 0 = '/*' #@dir@,~ ]
diff --git a/Task/Empty-directory/J/empty-directory-2.j b/Task/Empty-directory/J/empty-directory-2.j
new file mode 100644
index 0000000000..6905c40f21
--- /dev/null
+++ b/Task/Empty-directory/J/empty-directory-2.j
@@ -0,0 +1,5 @@
+$ mkdir /tmp/a
+$ touch /tmp/a/...
+$ mkdir /tmp/b
+$ mkdir /tmp/c
+$ mkdir /tmp/c/d
diff --git a/Task/Empty-directory/J/empty-directory-3.j b/Task/Empty-directory/J/empty-directory-3.j
new file mode 100644
index 0000000000..cc83d429b2
--- /dev/null
+++ b/Task/Empty-directory/J/empty-directory-3.j
@@ -0,0 +1,6 @@
+ empty_dir 'c:/cygwin/tmp/a'
+0
+ empty_dir 'c:/cygwin/tmp/b'
+1
+ empty_dir 'c:/cygwin/tmp/c'
+0
diff --git a/Task/Empty-directory/Liberty-BASIC/empty-directory.liberty b/Task/Empty-directory/Liberty-BASIC/empty-directory.liberty
new file mode 100644
index 0000000000..403f76cf58
--- /dev/null
+++ b/Task/Empty-directory/Liberty-BASIC/empty-directory.liberty
@@ -0,0 +1,15 @@
+dim info$(10, 10)
+files "c:\", info$()
+
+qtyFiles=val(info$(0,0))
+n = qtyFiles+1 'begin directory info
+
+folder$ = info$(n,0) 'path to first directory in c:
+
+files folder$, info$() 're-fill array with data from sub folder
+
+if val(info$(0,0)) + val(info$(0, 1)) <> 0 then
+ print "Folder ";folder$;" is not empty."
+else
+ print "Folder ";folder$;" is empty."
+end if
diff --git a/Task/Empty-directory/Mathematica/empty-directory.mathematica b/Task/Empty-directory/Mathematica/empty-directory.mathematica
new file mode 100644
index 0000000000..b392f76672
--- /dev/null
+++ b/Task/Empty-directory/Mathematica/empty-directory.mathematica
@@ -0,0 +1,5 @@
+EmptyDirectoryQ[x_] := (SetDirectory[x]; If[FileNames[] == {}, True, False])
+
+Example use:
+EmptyDirectoryQ["C:\\Program Files\\Wolfram Research\\Mathematica\\9"]
+->True
diff --git a/Task/Empty-program/FALSE/empty-program.false b/Task/Empty-program/FALSE/empty-program.false
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Factor/empty-program-1.factor b/Task/Empty-program/Factor/empty-program-1.factor
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Factor/empty-program-2.factor b/Task/Empty-program/Factor/empty-program-2.factor
new file mode 100644
index 0000000000..9e5f803ba4
--- /dev/null
+++ b/Task/Empty-program/Factor/empty-program-2.factor
@@ -0,0 +1,3 @@
+IN: rosetta.empty
+: main ( -- ) ;
+MAIN: main
diff --git a/Task/Empty-program/Fantom/empty-program.fantom b/Task/Empty-program/Fantom/empty-program.fantom
new file mode 100644
index 0000000000..ce35911d54
--- /dev/null
+++ b/Task/Empty-program/Fantom/empty-program.fantom
@@ -0,0 +1,4 @@
+class Main
+{
+ public static Void main () {}
+}
diff --git a/Task/Empty-program/Fish/empty-program-1.fish b/Task/Empty-program/Fish/empty-program-1.fish
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Fish/empty-program-2.fish b/Task/Empty-program/Fish/empty-program-2.fish
new file mode 100644
index 0000000000..092bc2b041
--- /dev/null
+++ b/Task/Empty-program/Fish/empty-program-2.fish
@@ -0,0 +1 @@
+;
diff --git a/Task/Empty-program/Frink/empty-program.frink b/Task/Empty-program/Frink/empty-program.frink
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Gecho/empty-program.gecho b/Task/Empty-program/Gecho/empty-program.gecho
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Gema/empty-program.gema b/Task/Empty-program/Gema/empty-program.gema
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Groovy/empty-program.groovy b/Task/Empty-program/Groovy/empty-program.groovy
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Haxe/empty-program.haxe b/Task/Empty-program/Haxe/empty-program.haxe
new file mode 100644
index 0000000000..478ffeddd7
--- /dev/null
+++ b/Task/Empty-program/Haxe/empty-program.haxe
@@ -0,0 +1,4 @@
+class Program {
+ static function main() {
+ }
+}
diff --git a/Task/Empty-program/HicEst/empty-program.hicest b/Task/Empty-program/HicEst/empty-program.hicest
new file mode 100644
index 0000000000..db763b52bd
--- /dev/null
+++ b/Task/Empty-program/HicEst/empty-program.hicest
@@ -0,0 +1 @@
+END ! looks better, but is not really needed
diff --git a/Task/Empty-program/IDL/empty-program.idl b/Task/Empty-program/IDL/empty-program.idl
new file mode 100644
index 0000000000..a6a9baf65e
--- /dev/null
+++ b/Task/Empty-program/IDL/empty-program.idl
@@ -0,0 +1 @@
+end
diff --git a/Task/Empty-program/Icon/empty-program.icon b/Task/Empty-program/Icon/empty-program.icon
new file mode 100644
index 0000000000..71f287c67a
--- /dev/null
+++ b/Task/Empty-program/Icon/empty-program.icon
@@ -0,0 +1,2 @@
+procedure main() # a null file will compile but generate a run-time error for missing main
+end
diff --git a/Task/Empty-program/Intercal/empty-program.ical b/Task/Empty-program/Intercal/empty-program.ical
new file mode 100644
index 0000000000..cc845c46d6
--- /dev/null
+++ b/Task/Empty-program/Intercal/empty-program.ical
@@ -0,0 +1 @@
+PLEASE GIVE UP
diff --git a/Task/Empty-program/J/empty-program-1.j b/Task/Empty-program/J/empty-program-1.j
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/J/empty-program-2.j b/Task/Empty-program/J/empty-program-2.j
new file mode 100644
index 0000000000..5c0cafad47
--- /dev/null
+++ b/Task/Empty-program/J/empty-program-2.j
@@ -0,0 +1,2 @@
+ '' -: ". ''
+1
diff --git a/Task/Empty-program/Joy/empty-program.joy b/Task/Empty-program/Joy/empty-program.joy
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/K/empty-program.k b/Task/Empty-program/K/empty-program.k
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/KonsolScript/empty-program.konso b/Task/Empty-program/KonsolScript/empty-program.konso
new file mode 100644
index 0000000000..7f0cc7bbd3
--- /dev/null
+++ b/Task/Empty-program/KonsolScript/empty-program.konso
@@ -0,0 +1,3 @@
+function main() {
+
+}
diff --git a/Task/Empty-program/Lang5/empty-program.lang5 b/Task/Empty-program/Lang5/empty-program.lang5
new file mode 100644
index 0000000000..a3abe50906
--- /dev/null
+++ b/Task/Empty-program/Lang5/empty-program.lang5
@@ -0,0 +1 @@
+exit
diff --git a/Task/Empty-program/Liberty-BASIC/empty-program.liberty b/Task/Empty-program/Liberty-BASIC/empty-program.liberty
new file mode 100644
index 0000000000..a6a9baf65e
--- /dev/null
+++ b/Task/Empty-program/Liberty-BASIC/empty-program.liberty
@@ -0,0 +1 @@
+end
diff --git a/Task/Empty-program/Lilypond/empty-program-1.lilypond b/Task/Empty-program/Lilypond/empty-program-1.lilypond
new file mode 100644
index 0000000000..927373865a
--- /dev/null
+++ b/Task/Empty-program/Lilypond/empty-program-1.lilypond
@@ -0,0 +1 @@
+\version "2.6.12"
diff --git a/Task/Empty-program/Lilypond/empty-program-2.lilypond b/Task/Empty-program/Lilypond/empty-program-2.lilypond
new file mode 100644
index 0000000000..88f6c11f88
--- /dev/null
+++ b/Task/Empty-program/Lilypond/empty-program-2.lilypond
@@ -0,0 +1,18 @@
+\version "2.16.2"
+
+\header {
+
+}
+
+\book {
+ \score {
+ \new Staff {
+ \new Voice {
+
+ }
+ }
+ \layout {
+
+ }
+ }
+}
diff --git a/Task/Empty-program/Lisp/empty-program.lisp b/Task/Empty-program/Lisp/empty-program.lisp
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Logo/empty-program-1.logo b/Task/Empty-program/Logo/empty-program-1.logo
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Logo/empty-program-2.logo b/Task/Empty-program/Logo/empty-program-2.logo
new file mode 100644
index 0000000000..c985fba794
--- /dev/null
+++ b/Task/Empty-program/Logo/empty-program-2.logo
@@ -0,0 +1,3 @@
+#! /usr/local/bin/logo
+
+bye
diff --git a/Task/Empty-program/M4/empty-program.m4 b/Task/Empty-program/M4/empty-program.m4
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/ML-I/empty-program.ml b/Task/Empty-program/ML-I/empty-program.ml
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/MMIX/empty-program.mmix b/Task/Empty-program/MMIX/empty-program.mmix
new file mode 100644
index 0000000000..ced9b57351
--- /dev/null
+++ b/Task/Empty-program/MMIX/empty-program.mmix
@@ -0,0 +1,2 @@
+ LOC #100
+Main TRAP 0,Halt,0 // main (argc, argv) {}
diff --git a/Task/Empty-program/Maple/empty-program.maple b/Task/Empty-program/Maple/empty-program.maple
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Mathematica/empty-program.mathematica b/Task/Empty-program/Mathematica/empty-program.mathematica
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/Task/Empty-program/Maxima/empty-program.maxima b/Task/Empty-program/Maxima/empty-program.maxima
new file mode 100644
index 0000000000..f05032b279
--- /dev/null
+++ b/Task/Empty-program/Maxima/empty-program.maxima
@@ -0,0 +1 @@
+block()$
diff --git a/Task/Empty-program/Metafont/empty-program.metafont b/Task/Empty-program/Metafont/empty-program.metafont
new file mode 100644
index 0000000000..a6a9baf65e
--- /dev/null
+++ b/Task/Empty-program/Metafont/empty-program.metafont
@@ -0,0 +1 @@
+end
diff --git a/Task/Empty-program/Modula-2/empty-program.mod2 b/Task/Empty-program/Modula-2/empty-program.mod2
new file mode 100644
index 0000000000..8dc08fda73
--- /dev/null
+++ b/Task/Empty-program/Modula-2/empty-program.mod2
@@ -0,0 +1,4 @@
+MODULE Main;
+
+BEGIN
+END Main.
diff --git a/Task/Empty-program/Modula-3/empty-program.mod3 b/Task/Empty-program/Modula-3/empty-program.mod3
new file mode 100644
index 0000000000..8dc08fda73
--- /dev/null
+++ b/Task/Empty-program/Modula-3/empty-program.mod3
@@ -0,0 +1,4 @@
+MODULE Main;
+
+BEGIN
+END Main.
diff --git a/Task/Empty-string/Fantom/empty-string.fantom b/Task/Empty-string/Fantom/empty-string.fantom
new file mode 100644
index 0000000000..617a87d415
--- /dev/null
+++ b/Task/Empty-string/Fantom/empty-string.fantom
@@ -0,0 +1,5 @@
+a := "" // assign an empty string to 'a'
+a.isEmpty // method on sys::Str to check if string is empty
+a.size == 0 // what isEmpty actually checks
+a == "" // alternate check for an empty string
+!a.isEmpty // check that a string is not empty
diff --git a/Task/Empty-string/Groovy/empty-string.groovy b/Task/Empty-string/Groovy/empty-string.groovy
new file mode 100644
index 0000000000..1120817b30
--- /dev/null
+++ b/Task/Empty-string/Groovy/empty-string.groovy
@@ -0,0 +1,5 @@
+def s = '' // or "" if you wish
+assert s.empty
+
+s = '1 is the loneliest number'
+assert !s.empty
diff --git a/Task/Empty-string/Icon/empty-string.icon b/Task/Empty-string/Icon/empty-string.icon
new file mode 100644
index 0000000000..454d771aab
--- /dev/null
+++ b/Task/Empty-string/Icon/empty-string.icon
@@ -0,0 +1,16 @@
+s := "" # null string
+s := string('A'--'A') # ... converted from cset difference
+s := char(0)[0:0] # ... by slicing
+
+s1 == "" # lexical comparison, could convert s1 to string
+s1 === "" # comparison won't force conversion
+*s1 = 0 # zero length, however, *x is polymorphic
+*string(s1) = 0 # zero length string
+
+s1 ~== "" # non null strings comparisons
+s1 ~=== ""
+*string(s1) ~= 0
+
+s := &null # NOT a null string, null type
+/s # test for null type
+\s # test for non-null type
diff --git a/Task/Empty-string/J/empty-string.j b/Task/Empty-string/J/empty-string.j
new file mode 100644
index 0000000000..e9681edb84
--- /dev/null
+++ b/Task/Empty-string/J/empty-string.j
@@ -0,0 +1,5 @@
+ variable=: ''
+ 0=#variable
+1
+ 0<#variable
+0
diff --git a/Task/Empty-string/K/empty-string.k b/Task/Empty-string/K/empty-string.k
new file mode 100644
index 0000000000..66b40f3ddf
--- /dev/null
+++ b/Task/Empty-string/K/empty-string.k
@@ -0,0 +1,5 @@
+ variable: ""
+ 0=#variable
+1
+ 0<#variable
+0
diff --git a/Task/Empty-string/LOLCODE/empty-string.lol b/Task/Empty-string/LOLCODE/empty-string.lol
new file mode 100644
index 0000000000..eed246c4ba
--- /dev/null
+++ b/Task/Empty-string/LOLCODE/empty-string.lol
@@ -0,0 +1,9 @@
+HAI 1.3
+
+I HAS A string ITZ ""
+string, O RLY?
+ YA RLY, VISIBLE "STRING HAZ CONTENZ"
+ NO WAI, VISIBLE "Y U NO HAS CHARZ?!"
+OIC
+
+KTHXBYE
diff --git a/Task/Empty-string/Lhogho/empty-string.lhogho b/Task/Empty-string/Lhogho/empty-string.lhogho
new file mode 100644
index 0000000000..7435f2dc80
--- /dev/null
+++ b/Task/Empty-string/Lhogho/empty-string.lhogho
@@ -0,0 +1,3 @@
+make "str " ;make null-string word
+print empty? :str ;prints 'true'
+print not empty? :str ;prints 'false'
diff --git a/Task/Empty-string/Liberty-BASIC/empty-string.liberty b/Task/Empty-string/Liberty-BASIC/empty-string.liberty
new file mode 100644
index 0000000000..1090885456
--- /dev/null
+++ b/Task/Empty-string/Liberty-BASIC/empty-string.liberty
@@ -0,0 +1,8 @@
+'assign empty string to variable
+a$ = ""
+'check for empty string
+if a$="" then print "Empty string."
+if len(a$)=0 then print "Empty string."
+'check for non-empty string
+if a$<>"" then print "Not empty."
+if len(a$)>0 then print "Not empty."
diff --git a/Task/Empty-string/Mathematica/empty-string.mathematica b/Task/Empty-string/Mathematica/empty-string.mathematica
new file mode 100644
index 0000000000..16fb3b29ba
--- /dev/null
+++ b/Task/Empty-string/Mathematica/empty-string.mathematica
@@ -0,0 +1,3 @@
+str=""; (*Create*)
+str==="" (*test empty*)
+str=!="" (*test not empty*)
diff --git a/Task/Empty-string/Maxima/empty-string.maxima b/Task/Empty-string/Maxima/empty-string.maxima
new file mode 100644
index 0000000000..5f4b768399
--- /dev/null
+++ b/Task/Empty-string/Maxima/empty-string.maxima
@@ -0,0 +1,9 @@
+s: ""$
+
+/* check using string contents */
+sequal(s, "");
+not sequal(s, "");
+
+/* check using string length */
+slength(s) = "";
+slength(s) # "";
diff --git a/Task/Empty-string/Mirah/empty-string.mirah b/Task/Empty-string/Mirah/empty-string.mirah
new file mode 100644
index 0000000000..9b969d4686
--- /dev/null
+++ b/Task/Empty-string/Mirah/empty-string.mirah
@@ -0,0 +1,6 @@
+empty_string1 = ""
+empty_string2 = String.new
+
+puts "empty string is empty" if empty_string1.isEmpty()
+puts "empty string has no length" if empty_string2.length() == 0
+puts "empty string is not nil" unless empty_string1 == nil
diff --git a/Task/Enforced-immutability/Icon/enforced-immutability.icon b/Task/Enforced-immutability/Icon/enforced-immutability.icon
new file mode 100644
index 0000000000..5b8199a149
--- /dev/null
+++ b/Task/Enforced-immutability/Icon/enforced-immutability.icon
@@ -0,0 +1 @@
+$define "1234"
diff --git a/Task/Enforced-immutability/J/enforced-immutability-1.j b/Task/Enforced-immutability/J/enforced-immutability-1.j
new file mode 100644
index 0000000000..1e6300e139
--- /dev/null
+++ b/Task/Enforced-immutability/J/enforced-immutability-1.j
@@ -0,0 +1,6 @@
+ B=: A=: 'this is a test'
+ A=: '*' 2 3 5 7} A
+ A
+th** *s*a test
+ B
+this is a test
diff --git a/Task/Enforced-immutability/J/enforced-immutability-2.j b/Task/Enforced-immutability/J/enforced-immutability-2.j
new file mode 100644
index 0000000000..90abb4138c
--- /dev/null
+++ b/Task/Enforced-immutability/J/enforced-immutability-2.j
@@ -0,0 +1,8 @@
+ C=: 'this is a test'
+ 1 readonly_jmf_ 'C'
+
+ C =: 'some new value'
+|read-only data
+| C =:'some new value'
+ C
+this is a test
diff --git a/Task/Enforced-immutability/MBS/enforced-immutability.mbs b/Task/Enforced-immutability/MBS/enforced-immutability.mbs
new file mode 100644
index 0000000000..6281b64c3f
--- /dev/null
+++ b/Task/Enforced-immutability/MBS/enforced-immutability.mbs
@@ -0,0 +1 @@
+CONSTANT INT foo=640;
diff --git a/Task/Enforced-immutability/Mathematica/enforced-immutability.mathematica b/Task/Enforced-immutability/Mathematica/enforced-immutability.mathematica
new file mode 100644
index 0000000000..393fb7795c
--- /dev/null
+++ b/Task/Enforced-immutability/Mathematica/enforced-immutability.mathematica
@@ -0,0 +1,5 @@
+Tau = 2*Pi;Protect[Tau]
+{"Tau"}
+
+Tau = 2
+->Set::wrsym: Symbol Tau is Protected.
diff --git a/Task/Entropy/J/entropy-1.j b/Task/Entropy/J/entropy-1.j
new file mode 100644
index 0000000000..51c80c1466
--- /dev/null
+++ b/Task/Entropy/J/entropy-1.j
@@ -0,0 +1 @@
+ entropy=: +/@:-@(* 2&^.)@(#/.~ % #)
diff --git a/Task/Entropy/J/entropy-2.j b/Task/Entropy/J/entropy-2.j
new file mode 100644
index 0000000000..9ff7ccd7d0
--- /dev/null
+++ b/Task/Entropy/J/entropy-2.j
@@ -0,0 +1,2 @@
+ entropy '1223334444'
+1.84644
diff --git a/Task/Entropy/Lang5/entropy.lang5 b/Task/Entropy/Lang5/entropy.lang5
new file mode 100644
index 0000000000..3eb60f1ade
--- /dev/null
+++ b/Task/Entropy/Lang5/entropy.lang5
@@ -0,0 +1,17 @@
+: -rot rot rot ; [] '__A set : dip swap __A swap 1 compress append '__A
+set execute __A -1 extract nip ; : nip swap drop ; : sum '+ reduce ;
+: 2array 2 compress ; : comb "" split ; : lensize length nip ;
+: #( a -- 'a )
+ grade subscript dup 's dress distinct strip
+ length 1 2array reshape swap
+ 'A set
+ : `filter(*) A in A swap select ;
+ '`filter apply
+ ;
+
+: elements(*) lensize ;
+: entropy #( s -- n )
+ length " 'elements apply" dip /
+ dup neg swap log * 2 log / sum ;
+
+"1223334444" comb entropy . # 1.84643934467102
diff --git a/Task/Entropy/Mathematica/entropy-1.mathematica b/Task/Entropy/Mathematica/entropy-1.mathematica
new file mode 100644
index 0000000000..929d420221
--- /dev/null
+++ b/Task/Entropy/Mathematica/entropy-1.mathematica
@@ -0,0 +1,2 @@
+shE[s_String] := -Plus @@ ((# Log[2., #]) & /@ ((Length /@ Gather[#])/
+ Length[#]) &[Characters[s]])
diff --git a/Task/Entropy/Mathematica/entropy-2.mathematica b/Task/Entropy/Mathematica/entropy-2.mathematica
new file mode 100644
index 0000000000..ae917b45bd
--- /dev/null
+++ b/Task/Entropy/Mathematica/entropy-2.mathematica
@@ -0,0 +1,4 @@
+ shE["1223334444"]
+1.84644
+shE["Rosetta Code"]
+3.08496
diff --git a/Task/Enumerations/Fantom/enumerations-1.fantom b/Task/Enumerations/Fantom/enumerations-1.fantom
new file mode 100644
index 0000000000..2ac7b75228
--- /dev/null
+++ b/Task/Enumerations/Fantom/enumerations-1.fantom
@@ -0,0 +1,2 @@
+// create an enumeration with named constants
+enum class Fruits { apple, banana, orange }
diff --git a/Task/Enumerations/Fantom/enumerations-2.fantom b/Task/Enumerations/Fantom/enumerations-2.fantom
new file mode 100644
index 0000000000..e37d03daba
--- /dev/null
+++ b/Task/Enumerations/Fantom/enumerations-2.fantom
@@ -0,0 +1,7 @@
+// create an enumeration with explicit values
+enum class Fruits_
+{
+ apple (1), banana (2), orange (3)
+ const Int value
+ private new make (Int value) { this.value = value }
+}
diff --git a/Task/Enumerations/Groovy/enumerations.groovy b/Task/Enumerations/Groovy/enumerations.groovy
new file mode 100644
index 0000000000..7c7b2086a4
--- /dev/null
+++ b/Task/Enumerations/Groovy/enumerations.groovy
@@ -0,0 +1,11 @@
+enum Fruit { apple, banana, cherry }
+
+enum ValuedFruit {
+ apple(1), banana(2), cherry(3);
+ def value
+ ValuedFruit(val) {value = val}
+ String toString() { super.toString() + "(${value})" }
+}
+
+println Fruit.values()
+println ValuedFruit.values()
diff --git a/Task/Enumerations/Icon/enumerations.icon b/Task/Enumerations/Icon/enumerations.icon
new file mode 100644
index 0000000000..413e4c7f0c
--- /dev/null
+++ b/Task/Enumerations/Icon/enumerations.icon
@@ -0,0 +1,6 @@
+ fruits := [ "apple", "banana", "cherry", "apple" ] # a list keeps ordered data
+ fruits := set("apple", "banana", "cherry") # a set keeps unique data
+ fruits := table() # table keeps an unique data with values
+ fruits["apple"] := 1
+ fruits["banana"] := 2
+ fruits["cherry"] := 3
diff --git a/Task/Enumerations/Inform-7/enumerations-1.inf b/Task/Enumerations/Inform-7/enumerations-1.inf
new file mode 100644
index 0000000000..b55e803100
--- /dev/null
+++ b/Task/Enumerations/Inform-7/enumerations-1.inf
@@ -0,0 +1 @@
+Fruit is a kind of value. The fruits are apple, banana, and cherry.
diff --git a/Task/Enumerations/Inform-7/enumerations-2.inf b/Task/Enumerations/Inform-7/enumerations-2.inf
new file mode 100644
index 0000000000..71a4af07b7
--- /dev/null
+++ b/Task/Enumerations/Inform-7/enumerations-2.inf
@@ -0,0 +1,6 @@
+[sentence form]
+Fruit is a kind of value. The fruits are apple, banana, and cherry.
+A fruit has a number called numeric value.
+The numeric value of apple is 1.
+The numeric value of banana is 2.
+The numeric value of cherry is 3.
diff --git a/Task/Enumerations/Inform-7/enumerations-3.inf b/Task/Enumerations/Inform-7/enumerations-3.inf
new file mode 100644
index 0000000000..684eb5d323
--- /dev/null
+++ b/Task/Enumerations/Inform-7/enumerations-3.inf
@@ -0,0 +1,8 @@
+[table form]
+Fruit is a kind of value. The fruits are defined by the Table of Fruits.
+
+Table of Fruits
+fruit numeric value
+apple 1
+banana 2
+cherry 3
diff --git a/Task/Enumerations/J/enumerations-1.j b/Task/Enumerations/J/enumerations-1.j
new file mode 100644
index 0000000000..712581f7ae
--- /dev/null
+++ b/Task/Enumerations/J/enumerations-1.j
@@ -0,0 +1,4 @@
+ enum =: cocreate''
+ ( (;:'apple banana cherry') ,L:0 '__enum' ) =: i. 3
+ cherry__enum
+2
diff --git a/Task/Enumerations/J/enumerations-2.j b/Task/Enumerations/J/enumerations-2.j
new file mode 100644
index 0000000000..a0eecd7f7b
--- /dev/null
+++ b/Task/Enumerations/J/enumerations-2.j
@@ -0,0 +1 @@
+ fruit=: ;:'apple banana cherry'
diff --git a/Task/Enumerations/J/enumerations-3.j b/Task/Enumerations/J/enumerations-3.j
new file mode 100644
index 0000000000..ccb58d261c
--- /dev/null
+++ b/Task/Enumerations/J/enumerations-3.j
@@ -0,0 +1,4 @@
+ 2 { fruit
++------+
+|cherry|
++------+
diff --git a/Task/Enumerations/J/enumerations-4.j b/Task/Enumerations/J/enumerations-4.j
new file mode 100644
index 0000000000..197d706478
--- /dev/null
+++ b/Task/Enumerations/J/enumerations-4.j
@@ -0,0 +1,2 @@
+ fruit i.<'banana'
+1
diff --git a/Task/Enumerations/J/enumerations-5.j b/Task/Enumerations/J/enumerations-5.j
new file mode 100644
index 0000000000..ee2be77e09
--- /dev/null
+++ b/Task/Enumerations/J/enumerations-5.j
@@ -0,0 +1,4 @@
+ (<'banana') +&.(fruit&i.) <'banana'
++------+
+|cherry|
++------+
diff --git a/Task/Enumerations/JScript.NET/enumerations.net b/Task/Enumerations/JScript.NET/enumerations.net
new file mode 100644
index 0000000000..39e00cef93
--- /dev/null
+++ b/Task/Enumerations/JScript.NET/enumerations.net
@@ -0,0 +1,2 @@
+enum fruits { apple, banana, cherry }
+enum fruits { apple = 0, banana = 1, cherry = 2 }
diff --git a/Task/Enumerations/M4/enumerations.m4 b/Task/Enumerations/M4/enumerations.m4
new file mode 100644
index 0000000000..0719bc9959
--- /dev/null
+++ b/Task/Enumerations/M4/enumerations.m4
@@ -0,0 +1,6 @@
+define(`enums',
+ `define(`$2',$1)`'ifelse(eval($#>2),1,`enums(incr($1),shift(shift($@)))')')
+define(`enum',
+ `enums(1,$@)')
+enum(a,b,c,d)
+`c='c
diff --git a/Task/Enumerations/Mathematica/enumerations.mathematica b/Task/Enumerations/Mathematica/enumerations.mathematica
new file mode 100644
index 0000000000..dc083935be
--- /dev/null
+++ b/Task/Enumerations/Mathematica/enumerations.mathematica
@@ -0,0 +1,11 @@
+MapIndexed[Set, {A, B, F, G}]
+->{{1}, {2}, {3}, {4}}
+
+A
+->{1}
+
+B
+->{2}
+
+G
+->{4}
diff --git a/Task/Enumerations/Metafont/enumerations-1.metafont b/Task/Enumerations/Metafont/enumerations-1.metafont
new file mode 100644
index 0000000000..80c88e9ddc
--- /dev/null
+++ b/Task/Enumerations/Metafont/enumerations-1.metafont
@@ -0,0 +1,4 @@
+vardef enum(expr first)(text t) =
+save ?; ? := first;
+forsuffixes e := t: e := ?; ?:=?+1; endfor
+enddef;
diff --git a/Task/Enumerations/Metafont/enumerations-2.metafont b/Task/Enumerations/Metafont/enumerations-2.metafont
new file mode 100644
index 0000000000..9b2e2a8560
--- /dev/null
+++ b/Task/Enumerations/Metafont/enumerations-2.metafont
@@ -0,0 +1,5 @@
+enum(1, Apple, Banana, Cherry);
+enum(5, Orange, Pineapple, Qfruit);
+show Apple, Banana, Cherry, Orange, Pineapple, Qfruit;
+
+end
diff --git a/Task/Enumerations/Modula-3/enumerations-1.mod3 b/Task/Enumerations/Modula-3/enumerations-1.mod3
new file mode 100644
index 0000000000..57a8a9b9b7
--- /dev/null
+++ b/Task/Enumerations/Modula-3/enumerations-1.mod3
@@ -0,0 +1 @@
+TYPE Fruit = {Apple, Banana, Cherry};
diff --git a/Task/Enumerations/Modula-3/enumerations-2.mod3 b/Task/Enumerations/Modula-3/enumerations-2.mod3
new file mode 100644
index 0000000000..3c8b021c49
--- /dev/null
+++ b/Task/Enumerations/Modula-3/enumerations-2.mod3
@@ -0,0 +1 @@
+fruit := Fruit.Apple;
diff --git a/Task/Enumerations/Modula-3/enumerations-3.mod3 b/Task/Enumerations/Modula-3/enumerations-3.mod3
new file mode 100644
index 0000000000..d93f3f1a48
--- /dev/null
+++ b/Task/Enumerations/Modula-3/enumerations-3.mod3
@@ -0,0 +1,2 @@
+ORD(Fruit.Apple); (* Returns 0 *)
+VAL(0, Fruit); (* Returns Fruit.Apple *)
diff --git a/Task/Equilibrium-index/Factor/equilibrium-index-1.factor b/Task/Equilibrium-index/Factor/equilibrium-index-1.factor
new file mode 100644
index 0000000000..2559aee139
--- /dev/null
+++ b/Task/Equilibrium-index/Factor/equilibrium-index-1.factor
@@ -0,0 +1,6 @@
+USE: math.vectors
+: accum-left ( seq id quot -- seq ) accumulate nip ; inline
+: accum-right ( seq id quot -- seq ) [ ] 2dip accum-left ; inline
+: equilibrium-indices ( seq -- inds )
+ 0 [ + ] [ accum-left ] [ accum-right ] 3bi [ = ] 2map
+ V{ } swap dup length iota [ [ suffix ] curry [ ] if ] 2each ;
diff --git a/Task/Equilibrium-index/Factor/equilibrium-index-2.factor b/Task/Equilibrium-index/Factor/equilibrium-index-2.factor
new file mode 100644
index 0000000000..3d7f62ddd5
--- /dev/null
+++ b/Task/Equilibrium-index/Factor/equilibrium-index-2.factor
@@ -0,0 +1,2 @@
+( scratchpad ) { -7 1 5 2 -4 3 0 } equilibrium-indices .
+V{ 3 6 }
diff --git a/Task/Equilibrium-index/Icon/equilibrium-index.icon b/Task/Equilibrium-index/Icon/equilibrium-index.icon
new file mode 100644
index 0000000000..595740c01f
--- /dev/null
+++ b/Task/Equilibrium-index/Icon/equilibrium-index.icon
@@ -0,0 +1,16 @@
+procedure main(arglist)
+L := if *arglist > 0 then arglist else [-7, 1, 5, 2, -4, 3, 0] # command line args or default
+every writes( "equilibrium indicies of [ " | (!L ||" ") | "] = " | (eqindex(L)||" ") | "\n" )
+end
+
+procedure eqindex(L) # generate equilibrium points in a list L or fail
+local s,l,i
+
+every (s := 0, i := !L) do
+ s +:= numeric(i) | fail # sum and validate
+
+every (l := 0, i := 1 to *L) do {
+ if l = (s-L[i])/2 then suspend i
+ l +:= L[i] # sum of left side
+ }
+end
diff --git a/Task/Equilibrium-index/J/equilibrium-index-1.j b/Task/Equilibrium-index/J/equilibrium-index-1.j
new file mode 100644
index 0000000000..fbf7433d23
--- /dev/null
+++ b/Task/Equilibrium-index/J/equilibrium-index-1.j
@@ -0,0 +1 @@
+equilidx=: +/\ I.@:= +/\.
diff --git a/Task/Equilibrium-index/J/equilibrium-index-2.j b/Task/Equilibrium-index/J/equilibrium-index-2.j
new file mode 100644
index 0000000000..9d6f58d7e6
--- /dev/null
+++ b/Task/Equilibrium-index/J/equilibrium-index-2.j
@@ -0,0 +1,2 @@
+ equilidx _7 1 5 2 _4 3 0
+3 6
diff --git a/Task/Equilibrium-index/K/equilibrium-index.k b/Task/Equilibrium-index/K/equilibrium-index.k
new file mode 100644
index 0000000000..9d8e5ca7d5
--- /dev/null
+++ b/Task/Equilibrium-index/K/equilibrium-index.k
@@ -0,0 +1,13 @@
+ f:{&{(+/y# x)=+/(y+1)_x}[x]'!#x}
+
+ f -7 1 5 2 -4 3 0
+3 6
+
+ f 2 4 6
+!0
+
+ f 2 9 2
+,1
+
+ f 1 -1 1 -1 1 -1 1
+0 1 2 3 4 5 6
diff --git a/Task/Equilibrium-index/Liberty-BASIC/equilibrium-index.liberty b/Task/Equilibrium-index/Liberty-BASIC/equilibrium-index.liberty
new file mode 100644
index 0000000000..fad97fdc1d
--- /dev/null
+++ b/Task/Equilibrium-index/Liberty-BASIC/equilibrium-index.liberty
@@ -0,0 +1,26 @@
+a(0)=-7
+a(1)=1
+a(2)=5
+a(3)=2
+a(4)=-4
+a(5)=3
+a(6)=0
+
+print "EQ Indices are ";EQindex$("a",0,6)
+
+wait
+
+function EQindex$(b$,mini,maxi)
+ if mini>=maxi then exit function
+ sum=0
+ for i = mini to maxi
+ sum=sum+eval(b$;"(";i;")")
+ next
+ sumA=0:sumB=sum
+ for i = mini to maxi
+ sumB = sumB - eval(b$;"(";i;")")
+ if sumA=sumB then EQindex$=EQindex$+str$(i)+", "
+ sumA = sumA + eval(b$;"(";i;")")
+ next
+ if len(EQindex$)>0 then EQindex$=mid$(EQindex$, 1, len(EQindex$)-2) 'remove last ", "
+end function
diff --git a/Task/Equilibrium-index/Mathematica/equilibrium-index.mathematica b/Task/Equilibrium-index/Mathematica/equilibrium-index.mathematica
new file mode 100644
index 0000000000..379705e75e
--- /dev/null
+++ b/Task/Equilibrium-index/Mathematica/equilibrium-index.mathematica
@@ -0,0 +1,3 @@
+equilibriumIndex[data_]:=Reap[
+ Do[If[Total[data[[;; n - 1]]] == Total[data[[n + 1 ;;]]],Sow[n]],
+ {n, Length[data]}]][[2, 1]]
diff --git a/Task/Ethiopian-multiplication/FALSE/ethiopian-multiplication.false b/Task/Ethiopian-multiplication/FALSE/ethiopian-multiplication.false
new file mode 100644
index 0000000000..472d28b335
--- /dev/null
+++ b/Task/Ethiopian-multiplication/FALSE/ethiopian-multiplication.false
@@ -0,0 +1,5 @@
+[2/]h:
+[2*]d:
+[1&]o:
+[0[@$][$o;![@@\$@+@]?h;!@d;!@]#%\%]m:
+17 34m;!. {578}
diff --git a/Task/Ethiopian-multiplication/Factor/ethiopian-multiplication.factor b/Task/Ethiopian-multiplication/Factor/ethiopian-multiplication.factor
new file mode 100644
index 0000000000..bc042e37ef
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Factor/ethiopian-multiplication.factor
@@ -0,0 +1,17 @@
+USING: arrays kernel math multiline sequences ;
+IN: ethiopian-multiplication
+
+/*
+This function is built-in
+: odd? ( n -- ? ) 1 bitand 1 number= ;
+*/
+
+: double ( n -- 2*n ) 2 * ;
+: halve ( n -- n/2 ) 2 /i ;
+
+: ethiopian-mult ( a b -- a*b )
+ [ 0 ] 2dip
+ [ dup 0 > ] [
+ [ odd? [ + ] [ drop ] if ] 2keep
+ [ double ] [ halve ] bi*
+ ] while 2drop ;
diff --git a/Task/Ethiopian-multiplication/GW-BASIC/ethiopian-multiplication.bas b/Task/Ethiopian-multiplication/GW-BASIC/ethiopian-multiplication.bas
new file mode 100644
index 0000000000..509d216c77
--- /dev/null
+++ b/Task/Ethiopian-multiplication/GW-BASIC/ethiopian-multiplication.bas
@@ -0,0 +1,10 @@
+10 DEF FNE(A)=(A+1) MOD 2
+20 DEF FNH(A)=INT(A/2)
+30 DEF FND(A)=2*A
+40 X=17:Y=34:TOT=0
+50 WHILE X>=1
+60 PRINT X,
+70 IF FNE(X)=0 THEN TOT=TOT+Y:PRINT Y ELSE PRINT
+80 X=FNH(X):Y=FND(Y)
+90 WEND
+100 PRINT "=", TOT
diff --git a/Task/Ethiopian-multiplication/HicEst/ethiopian-multiplication.hicest b/Task/Ethiopian-multiplication/HicEst/ethiopian-multiplication.hicest
new file mode 100644
index 0000000000..f50a85f549
--- /dev/null
+++ b/Task/Ethiopian-multiplication/HicEst/ethiopian-multiplication.hicest
@@ -0,0 +1,26 @@
+ WRITE(Messagebox) ethiopian( 17, 34 )
+END ! of "main"
+
+FUNCTION ethiopian(x, y)
+ ethiopian = 0
+ left = x
+ right = y
+ DO i = x, 1, -1
+ IF( isEven(left) == 0 ) ethiopian = ethiopian + right
+ IF( left == 1 ) RETURN
+ left = halve(left)
+ right = double(right)
+ ENDDO
+ END
+
+FUNCTION halve( x )
+ halve = INT( x/2 )
+ END
+
+FUNCTION double( x )
+ double = 2 * x
+ END
+
+FUNCTION isEven( x )
+ isEven = MOD(x, 2) == 0
+ END
diff --git a/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-1.icon b/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-1.icon
new file mode 100644
index 0000000000..77b9c5962b
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-1.icon
@@ -0,0 +1,22 @@
+procedure main(arglist)
+while ethiopian(integer(get(arglist)),integer(get(arglist))) # multiply successive pairs of command line arguments
+end
+
+procedure ethiopian(i,j) # recursive Ethiopian multiplication
+return ( if not even(i) then j # this exploits that icon control expressions return values
+ else 0 ) +
+ ( if i ~= 0 then ethiopian(halve(i),double(j))
+ else 0 )
+end
+
+procedure double(i)
+return i * 2
+end
+
+procedure halve(i)
+return i / 2
+end
+
+procedure even(i)
+return ( i % 2 = 0, i )
+end
diff --git a/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-2.icon b/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-2.icon
new file mode 100644
index 0000000000..84e62bad4f
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Icon/ethiopian-multiplication-2.icon
@@ -0,0 +1,19 @@
+procedure ethiopian(i,j) # iterative tutor
+local p,w
+w := *j+3
+write("Ethiopian Multiplication of ",i," * ",j)
+
+p := 0
+until i = 0 do {
+ writes(right(i,w),right(j,w))
+ if not even(i) then {
+ p +:= j
+ write(" add")
+ }
+ else write(" discard")
+ i := halve(i)
+ j := double(j)
+ }
+write(right("=",w),right(p,w))
+return p
+end
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-1.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-1.j
new file mode 100644
index 0000000000..451de43b71
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-1.j
@@ -0,0 +1,5 @@
+double =: 2&*
+halve =: %&2 NB. or the primitive -:
+odd =: 2&|
+
+ethiop =: +/@(odd@] # (double~ <@#)) (1>.<.@halve)^:a:
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-2.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-2.j
new file mode 100644
index 0000000000..3d935ae6fb
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-2.j
@@ -0,0 +1,2 @@
+ 17 ethiop 34
+578
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-3.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-3.j
new file mode 100644
index 0000000000..7c036ad767
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-3.j
@@ -0,0 +1,2 @@
+ (<5) double 17
+17 34 68 136 272
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-4.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-4.j
new file mode 100644
index 0000000000..ab3e3cbb6a
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-4.j
@@ -0,0 +1 @@
+ethio=: *@] * (ethiop |)
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-5.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-5.j
new file mode 100644
index 0000000000..4c0275e7be
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-5.j
@@ -0,0 +1 @@
+ethio=: *@] -@]^:(0 > [) (ethiop |)
diff --git a/Task/Ethiopian-multiplication/J/ethiopian-multiplication-6.j b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-6.j
new file mode 100644
index 0000000000..ac489587c8
--- /dev/null
+++ b/Task/Ethiopian-multiplication/J/ethiopian-multiplication-6.j
@@ -0,0 +1,8 @@
+ 7 ethio 11
+77
+ 7 ethio _11
+_77
+ _7 ethio 11
+_77
+ _7 ethio _11
+77
diff --git a/Task/Ethiopian-multiplication/Liberty-BASIC/ethiopian-multiplication.liberty b/Task/Ethiopian-multiplication/Liberty-BASIC/ethiopian-multiplication.liberty
new file mode 100644
index 0000000000..0330729a24
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Liberty-BASIC/ethiopian-multiplication.liberty
@@ -0,0 +1,29 @@
+x = 17
+y = 34
+msg$ = str$(x) + " * " + str$(y) + " = "
+Print str$(x) + " " + str$(y)
+'In this routine we will not worry about discarding the right hand value whos left hand partner is even;
+'we will just not add it to our product.
+Do Until x < 2
+ If Not(isEven(x)) Then
+ product = (product + y)
+ End If
+ x = halveInt(x)
+ y = doubleInt(y)
+ Print str$(x) + " " + str$(y)
+Loop
+product = (product + y)
+If (x < 0) Then product = (product * -1)
+Print msg$ + str$(product)
+
+Function isEven(num)
+ isEven = Abs(Not(num Mod 2))
+End Function
+
+Function halveInt(num)
+ halveInt = Int(num/ 2)
+End Function
+
+Function doubleInt(num)
+ doubleInt = (num * 2)
+End Function
diff --git a/Task/Ethiopian-multiplication/Locomotive-Basic/ethiopian-multiplication.bas b/Task/Ethiopian-multiplication/Locomotive-Basic/ethiopian-multiplication.bas
new file mode 100644
index 0000000000..5c944584a2
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Locomotive-Basic/ethiopian-multiplication.bas
@@ -0,0 +1,10 @@
+10 DEF FNiseven(a)=(a+1) MOD 2
+20 DEF FNhalf(a)=INT(a/2)
+30 DEF FNdouble(a)=2*a
+40 x=17:y=34:tot=0
+50 WHILE x>=1
+60 PRINT x,
+70 IF FNiseven(x)=0 THEN tot=tot+y:PRINT y ELSE PRINT
+80 x=FNhalf(x):y=FNdouble(y)
+90 WEND
+100 PRINT "=", tot
diff --git a/Task/Ethiopian-multiplication/Logo/ethiopian-multiplication.logo b/Task/Ethiopian-multiplication/Logo/ethiopian-multiplication.logo
new file mode 100644
index 0000000000..5716abbe7a
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Logo/ethiopian-multiplication.logo
@@ -0,0 +1,15 @@
+to double :x
+ output ashift :x 1
+end
+to halve :x
+ output ashift :x -1
+end
+to even? :x
+ output equal? 0 bitand 1 :x
+end
+to eproduct :x :y
+ if :x = 0 [output 0]
+ ifelse even? :x ~
+ [output eproduct halve :x double :y] ~
+ [output :y + eproduct halve :x double :y]
+end
diff --git a/Task/Ethiopian-multiplication/MMIX/ethiopian-multiplication.mmix b/Task/Ethiopian-multiplication/MMIX/ethiopian-multiplication.mmix
new file mode 100644
index 0000000000..f2897288be
--- /dev/null
+++ b/Task/Ethiopian-multiplication/MMIX/ethiopian-multiplication.mmix
@@ -0,0 +1,51 @@
+A IS 17
+B IS 34
+
+pliar IS $255 % designating main registers
+pliand GREG
+acc GREG
+str IS pliar % reuse reg $255 for printing
+
+ LOC Data_Segment
+ GREG @
+BUF OCTA #3030303030303030 % reserve a buffer that is big enough to hold
+ OCTA #3030303030303030 % a max (signed) 64 bit integer:
+ OCTA #3030300a00000000 % 2^63 - 1 = 9223372036854775807
+ % string is terminated with NL, 0
+
+ LOC #1000 % locate program at address
+ GREG @
+halve SR pliar,pliar,1
+ GO $127,$127,0
+
+double SL pliand,pliand,1
+ GO $127,$127,0
+
+odd DIV $77,pliar,2
+ GET $78,rR
+ GO $127,$127,0
+
+ % Main is the entry point of the program
+Main SET pliar,A % initialize registers for calculation
+ SET pliand,B
+ SET acc,0
+1H GO $127,odd
+ BZ $78,2F % if pliar is even skip incr. acc with pliand
+ ADD acc,acc,pliand %
+2H GO $127,halve % halve pliar
+ GO $127,double % and double pliand
+ PBNZ pliar,1B % repeat from 1H while pliar > 0
+// result: acc = 17 x 34
+// next: print result --> stdout
+// $0 is a temp register
+ LDA str,BUF+19 % points after the end of the string
+2H SUB str,str,1 % update buffer pointer
+ DIV acc,acc,10 % do a divide and mod
+ GET $0,rR % get digit from special purpose reg. rR
+ % containing the remainder of the division
+ INCL $0,'0' % convert to ascii
+ STBU $0,str % place digit in buffer
+ PBNZ acc,2B % next
+ % 'str' points to the start of the result
+ TRAP 0,Fputs,StdOut % output answer to stdout
+ TRAP 0,Halt,0 % exit
diff --git a/Task/Ethiopian-multiplication/MUMPS/ethiopian-multiplication.mumps b/Task/Ethiopian-multiplication/MUMPS/ethiopian-multiplication.mumps
new file mode 100644
index 0000000000..34c3b66ab1
--- /dev/null
+++ b/Task/Ethiopian-multiplication/MUMPS/ethiopian-multiplication.mumps
@@ -0,0 +1,17 @@
+HALVE(I)
+ ;I should be an integer
+ QUIT I\2
+DOUBLE(I)
+ ;I should be an integer
+ QUIT I*2
+ISEVEN(I)
+ ;I should be an integer
+ QUIT '(I#2)
+E2(M,N)
+ New W,A,E,L Set W=$Select($Length(M)>=$Length(N):$Length(M)+2,1:$L(N)+2),A=0,L=0,A(L,1)=M,A(L,2)=N
+ Write "Multiplying two numbers:"
+ For Write !,$Justify(A(L,1),W),?W,$Justify(A(L,2),W) Write:$$ISEVEN(A(L,1)) ?(2*W)," Struck" Set:'$$ISEVEN(A(L,1)) A=A+A(L,2) Set L=L+1,A(L,1)=$$HALVE(A(L-1,1)),A(L,2)=$$DOUBLE(A(L-1,2)) Quit:A(L,1)<1
+ Write ! For E=W:1:(2*W) Write ?E,"="
+ Write !,?W,$Justify(A,W),!
+ Kill W,A,E,L
+ Q
diff --git a/Task/Ethiopian-multiplication/Mathematica/ethiopian-multiplication.mathematica b/Task/Ethiopian-multiplication/Mathematica/ethiopian-multiplication.mathematica
new file mode 100644
index 0000000000..cb67413793
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Mathematica/ethiopian-multiplication.mathematica
@@ -0,0 +1,7 @@
+IntegerHalving[x_]:=Floor[x/2]
+IntegerDoubling[x_]:=x*2;
+OddInteger OddQ
+Ethiopian[x_, y_] :=
+Total[Select[NestWhileList[{IntegerHalving[#[[1]]],IntegerDoubling[#[[2]]]}&, {x,y}, (#[[1]]>1&)], OddQ[#[[1]]]&]][[2]]
+
+Ethiopian[17, 34]
diff --git a/Task/Ethiopian-multiplication/Metafont/ethiopian-multiplication.metafont b/Task/Ethiopian-multiplication/Metafont/ethiopian-multiplication.metafont
new file mode 100644
index 0000000000..ddb3092992
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Metafont/ethiopian-multiplication.metafont
@@ -0,0 +1,20 @@
+vardef halve(expr x) = floor(x/2) enddef;
+vardef double(expr x) = x*2 enddef;
+vardef iseven(expr x) = if (x mod 2) = 0: true else: false fi enddef;
+
+primarydef a ethiopicmult b =
+ begingroup
+ save r_, plier_, plicand_;
+ plier_ := a; plicand_ := b;
+ r_ := 0;
+ forever: exitif plier_ < 1;
+ if not iseven(plier_): r_ := r_ + plicand_; fi
+ plier_ := halve(plier_);
+ plicand_ := double(plicand_);
+ endfor
+ r_
+ endgroup
+enddef;
+
+show( (17 ethiopicmult 34) );
+end
diff --git a/Task/Ethiopian-multiplication/Modula-3/ethiopian-multiplication.mod3 b/Task/Ethiopian-multiplication/Modula-3/ethiopian-multiplication.mod3
new file mode 100644
index 0000000000..e11398eed5
--- /dev/null
+++ b/Task/Ethiopian-multiplication/Modula-3/ethiopian-multiplication.mod3
@@ -0,0 +1,38 @@
+MODULE Ethiopian EXPORTS Main;
+
+IMPORT IO, Fmt;
+
+PROCEDURE IsEven(n: INTEGER): BOOLEAN =
+ BEGIN
+ RETURN n MOD 2 = 0;
+ END IsEven;
+
+PROCEDURE Double(n: INTEGER): INTEGER =
+ BEGIN
+ RETURN n * 2;
+ END Double;
+
+PROCEDURE Half(n: INTEGER): INTEGER =
+ BEGIN
+ RETURN n DIV 2;
+ END Half;
+
+PROCEDURE Multiply(a, b: INTEGER): INTEGER =
+ VAR
+ temp := 0;
+ plier := a;
+ plicand := b;
+ BEGIN
+ WHILE plier >= 1 DO
+ IF NOT IsEven(plier) THEN
+ temp := temp + plicand;
+ END;
+ plier := Half(plier);
+ plicand := Double(plicand);
+ END;
+ RETURN temp;
+ END Multiply;
+
+BEGIN
+ IO.Put("17 times 34 = " & Fmt.Int(Multiply(17, 34)) & "\n");
+END Ethiopian.
diff --git a/Task/Euler-method/Groovy/euler-method-1.groovy b/Task/Euler-method/Groovy/euler-method-1.groovy
new file mode 100644
index 0000000000..b67f2b55ec
--- /dev/null
+++ b/Task/Euler-method/Groovy/euler-method-1.groovy
@@ -0,0 +1,15 @@
+def eulerStep = { xn, yn, h, dydx ->
+ (yn + h * dydx(xn, yn)) as BigDecimal
+}
+
+Map eulerMapping = { x0, y0, h, dydx, stopCond = { xx, yy, hh, xx0 -> abs(xx - xx0) > (hh * 100) }.rcurry(h, x0) ->
+ Map yMap = [:]
+ yMap[x0] = y0 as BigDecimal
+ def x = x0
+ while (!stopCond(x, yMap[x])) {
+ yMap[x + h] = eulerStep(x, yMap[x], h, dydx)
+ x += h
+ }
+ yMap
+}
+assert eulerMapping.maximumNumberOfParameters == 5
diff --git a/Task/Euler-method/Groovy/euler-method-2.groovy b/Task/Euler-method/Groovy/euler-method-2.groovy
new file mode 100644
index 0000000000..489bc23c47
--- /dev/null
+++ b/Task/Euler-method/Groovy/euler-method-2.groovy
@@ -0,0 +1,8 @@
+def dtdsNewton = { s, t, tR, k -> k * (tR - t) }
+assert dtdsNewton.maximumNumberOfParameters == 4
+
+def dtds = dtdsNewton.rcurry(20, 0.07)
+assert dtds.maximumNumberOfParameters == 2
+
+def tEulerH = eulerMapping.rcurry(dtds) { s, t -> s >= 100 }
+assert tEulerH.maximumNumberOfParameters == 3
diff --git a/Task/Euler-method/Groovy/euler-method-3.groovy b/Task/Euler-method/Groovy/euler-method-3.groovy
new file mode 100644
index 0000000000..2d9e79b628
--- /dev/null
+++ b/Task/Euler-method/Groovy/euler-method-3.groovy
@@ -0,0 +1,7 @@
+def tNewton = { s, s0, t0, tR, k ->
+ tR + (t0 - tR) * Math.exp(k * (s0 - s))
+}
+assert tNewton.maximumNumberOfParameters == 5
+
+def tAnalytic = tNewton.rcurry(0, 100, 20, 0.07)
+assert tAnalytic.maximumNumberOfParameters == 1
diff --git a/Task/Euler-method/Groovy/euler-method-4.groovy b/Task/Euler-method/Groovy/euler-method-4.groovy
new file mode 100644
index 0000000000..d841ad159a
--- /dev/null
+++ b/Task/Euler-method/Groovy/euler-method-4.groovy
@@ -0,0 +1,14 @@
+[10, 5, 2].each { h ->
+ def tEuler = tEulerH.rcurry(h)
+ assert tEuler.maximumNumberOfParameters == 2
+ println """
+STEP SIZE == ${h}
+ time analytic euler relative
+(seconds) (°C) (°C) error
+-------- -------- -------- ---------"""
+ tEuler(0, 100).each { BigDecimal s, tE ->
+ def tA = tAnalytic(s)
+ def relError = ((tE - tA)/(tA - 20)).abs()
+ printf('%5.0f %8.4f %8.4f %9.6f\n', s, tA, tE, relError)
+ }
+}
diff --git a/Task/Euler-method/Icon/euler-method.icon b/Task/Euler-method/Icon/euler-method.icon
new file mode 100644
index 0000000000..5294572c1c
--- /dev/null
+++ b/Task/Euler-method/Icon/euler-method.icon
@@ -0,0 +1,22 @@
+invocable "newton_cooling" # needed to use the 'proc' procedure
+
+procedure euler (f, y0, a, b, h)
+ t := a
+ y := y0
+ until (t >= b) do {
+ write (right(t, 4) || " " || left(y, 7))
+ t +:= h
+ y +:= h * (proc(f) (t, y)) # 'proc' applies procedure named in f to (t, y)
+ }
+ write ("DONE")
+end
+
+procedure newton_cooling (time, T)
+ return -0.07 * (T - 20)
+end
+
+procedure main ()
+ # generate data for all three step sizes [2, 5, 10]
+ every (step_size := ![2,5,10]) do
+ euler ("newton_cooling", 100, 0, 100, step_size)
+end
diff --git a/Task/Euler-method/J/euler-method-1.j b/Task/Euler-method/J/euler-method-1.j
new file mode 100644
index 0000000000..2442d16386
--- /dev/null
+++ b/Task/Euler-method/J/euler-method-1.j
@@ -0,0 +1,9 @@
+NB.*euler a Approximates Y(t) in Y'(t)=f(t,Y) with Y(a)=Y0 and t=a..b and step size h.
+euler=: adverb define
+ 'Y0 a b h'=. 4{. y
+ t=. i.@>:&.(%&h) b - a
+ Y=. (+ h * u)^:(<#t) Y0
+ t,.Y
+)
+
+ncl=: _0.07 * -&20 NB. Newton's Cooling Law
diff --git a/Task/Euler-method/J/euler-method-2.j b/Task/Euler-method/J/euler-method-2.j
new file mode 100644
index 0000000000..b96d806939
--- /dev/null
+++ b/Task/Euler-method/J/euler-method-2.j
@@ -0,0 +1,16 @@
+ ncl euler 100 0 100 2
+... NB. output redacted for brevity
+ ncl euler 100 0 100 5
+... NB. output redacted for brevity
+ ncl euler 100 0 100 10
+ 0 100
+ 10 44
+ 20 27.2
+ 30 22.16
+ 40 20.648
+ 50 20.1944
+ 60 20.0583
+ 70 20.0175
+ 80 20.0052
+ 90 20.0016
+100 20.0005
diff --git a/Task/Euler-method/Mathematica/euler-method.mathematica b/Task/Euler-method/Mathematica/euler-method.mathematica
new file mode 100644
index 0000000000..fd2ca20c09
--- /dev/null
+++ b/Task/Euler-method/Mathematica/euler-method.mathematica
@@ -0,0 +1 @@
+euler[step_, val_] := NDSolve[{T'[t] == -0.07 (T[t] - 20), T[0] == 100}, T, {t, 0, 100}, Method -> "ExplicitEuler", StartingStepSize -> step][[1, 1, 2]][val]
diff --git a/Task/Evaluate-binomial-coefficients/Frink/evaluate-binomial-coefficients.frink b/Task/Evaluate-binomial-coefficients/Frink/evaluate-binomial-coefficients.frink
new file mode 100644
index 0000000000..045ccb1095
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Frink/evaluate-binomial-coefficients.frink
@@ -0,0 +1 @@
+println[binomial[5,3]]
diff --git a/Task/Evaluate-binomial-coefficients/GAP/evaluate-binomial-coefficients.gap b/Task/Evaluate-binomial-coefficients/GAP/evaluate-binomial-coefficients.gap
new file mode 100644
index 0000000000..362dca5769
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/GAP/evaluate-binomial-coefficients.gap
@@ -0,0 +1,3 @@
+# Built-in
+Binomial(5, 3);
+# 10
diff --git a/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-1.golf b/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-1.golf
new file mode 100644
index 0000000000..236f95ecd5
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-1.golf
@@ -0,0 +1,3 @@
+;5 3 # Set up demo input
+{),(;{*}*}:f; # Define a factorial function
+.f@.f@/\@-f/
diff --git a/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-2.golf b/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-2.golf
new file mode 100644
index 0000000000..e7e1a2f278
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Golfscript/evaluate-binomial-coefficients-2.golf
@@ -0,0 +1,2 @@
+;5 3 # Set up demo input
+1\,@{1$-@\*\)/}+/
diff --git a/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-1.groovy b/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-1.groovy
new file mode 100644
index 0000000000..5c24b0ffd6
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-1.groovy
@@ -0,0 +1,10 @@
+def factorial = { x ->
+ assert x > -1
+ x == 0 ? 1 : (1..x).inject(1G) { BigInteger product, BigInteger factor -> product *= factor }
+}
+
+def combinations = { n, k ->
+ assert k >= 0
+ assert n >= k
+ factorial(n).intdiv(factorial(k)*factorial(n-k))
+}
diff --git a/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-2.groovy b/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-2.groovy
new file mode 100644
index 0000000000..e2d5568b12
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Groovy/evaluate-binomial-coefficients-2.groovy
@@ -0,0 +1,4 @@
+assert combinations(20, 0) == combinations(20, 20)
+assert combinations(20, 10) == (combinations(19, 9) + combinations(19, 10))
+assert combinations(5, 3) == 10
+println combinations(5, 3)
diff --git a/Task/Evaluate-binomial-coefficients/HicEst/evaluate-binomial-coefficients.hicest b/Task/Evaluate-binomial-coefficients/HicEst/evaluate-binomial-coefficients.hicest
new file mode 100644
index 0000000000..364f270d26
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/HicEst/evaluate-binomial-coefficients.hicest
@@ -0,0 +1,12 @@
+WRITE(Messagebox) BinomCoeff( 5, 3) ! displays 10
+
+FUNCTION factorial( n )
+ factorial = 1
+ DO i = 1, n
+ factorial = factorial * i
+ ENDDO
+END
+
+FUNCTION BinomCoeff( n, k )
+ BinomCoeff = factorial(n)/factorial(n-k)/factorial(k)
+END
diff --git a/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-1.icon b/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-1.icon
new file mode 100644
index 0000000000..3e066a7df5
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-1.icon
@@ -0,0 +1,5 @@
+link math, factors
+
+procedure main()
+write("choose(5,3)=",binocoef(5,3))
+end
diff --git a/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-2.icon b/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-2.icon
new file mode 100644
index 0000000000..a2cb55fba9
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Icon/evaluate-binomial-coefficients-2.icon
@@ -0,0 +1,27 @@
+procedure binocoef(n, k) #: binomial coefficient
+
+ k := integer(k) | fail
+ n := integer(n) | fail
+
+ if (k = 0) | (n = k) then return 1
+
+ if 0 <= k <= n then
+ return factorial(n) / (factorial(k) * factorial(n - k))
+ else fail
+
+end
+
+procedure factorial(n) #: return n! (n factorial)
+ local i
+
+ n := integer(n) | runerr(101, n)
+
+ if n < 0 then fail
+
+ i := 1
+
+ every i *:= 1 to n
+
+ return i
+
+end
diff --git a/Task/Evaluate-binomial-coefficients/J/evaluate-binomial-coefficients.j b/Task/Evaluate-binomial-coefficients/J/evaluate-binomial-coefficients.j
new file mode 100644
index 0000000000..44822d748d
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/J/evaluate-binomial-coefficients.j
@@ -0,0 +1,2 @@
+ 3 ! 5
+10
diff --git a/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-1.k b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-1.k
new file mode 100644
index 0000000000..92b9d98c9e
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-1.k
@@ -0,0 +1,2 @@
+ {[n;k]_(*/(k-1)_1+!n)%(*/1+!k)} . 5 3
+10
diff --git a/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-2.k b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-2.k
new file mode 100644
index 0000000000..447fd7b6d3
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-2.k
@@ -0,0 +1,2 @@
+ {[n;k]i:!(k-1);_*/((n-i)%(i+1))} . 5 3
+10
diff --git a/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-3.k b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-3.k
new file mode 100644
index 0000000000..bc08baf008
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/K/evaluate-binomial-coefficients-3.k
@@ -0,0 +1,11 @@
+ pascal:{x{+':0,x,0}\1}
+ pascal 5
+(1
+ 1 1
+ 1 2 1
+ 1 3 3 1
+ 1 4 6 4 1
+ 1 5 10 10 5 1)
+
+ {[n;k](pascal n)[n;k]} . 5 3
+10
diff --git a/Task/Evaluate-binomial-coefficients/Liberty-BASIC/evaluate-binomial-coefficients.liberty b/Task/Evaluate-binomial-coefficients/Liberty-BASIC/evaluate-binomial-coefficients.liberty
new file mode 100644
index 0000000000..cf510674d7
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Liberty-BASIC/evaluate-binomial-coefficients.liberty
@@ -0,0 +1,21 @@
+ ' [RC] Binomial Coefficients
+
+ print "Binomial Coefficient of "; 5; " and "; 3; " is ",BinomialCoefficient( 5, 3)
+ n =1 +int( 10 *rnd( 1))
+ k =1 +int( n *rnd( 1))
+ print "Binomial Coefficient of "; n; " and "; k; " is ",BinomialCoefficient( n, k)
+
+ end
+
+ function BinomialCoefficient( n, k)
+ BinomialCoefficient =factorial( n) /factorial( n -k) /factorial( k)
+ end function
+
+ function factorial( n)
+ if n <2 then
+ f =1
+ else
+ f =n *factorial( n -1)
+ end if
+ factorial =f
+ end function
diff --git a/Task/Evaluate-binomial-coefficients/Logo/evaluate-binomial-coefficients.logo b/Task/Evaluate-binomial-coefficients/Logo/evaluate-binomial-coefficients.logo
new file mode 100644
index 0000000000..d0e32dc354
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Logo/evaluate-binomial-coefficients.logo
@@ -0,0 +1,7 @@
+to choose :n :k
+ if :k = 0 [output 1]
+ output (choose :n :k-1) * (:n - :k + 1) / :k
+end
+
+show choose 5 3 ; 10
+show choose 60 30 ; 1.18264581564861e+17
diff --git a/Task/Evaluate-binomial-coefficients/Mathematica/evaluate-binomial-coefficients.mathematica b/Task/Evaluate-binomial-coefficients/Mathematica/evaluate-binomial-coefficients.mathematica
new file mode 100644
index 0000000000..c79a50d303
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Mathematica/evaluate-binomial-coefficients.mathematica
@@ -0,0 +1,2 @@
+(Local) In[1]:= Binomial[5,3]
+(Local) Out[1]= 10
diff --git a/Task/Evaluate-binomial-coefficients/Maxima/evaluate-binomial-coefficients.maxima b/Task/Evaluate-binomial-coefficients/Maxima/evaluate-binomial-coefficients.maxima
new file mode 100644
index 0000000000..e4caa80a37
--- /dev/null
+++ b/Task/Evaluate-binomial-coefficients/Maxima/evaluate-binomial-coefficients.maxima
@@ -0,0 +1,13 @@
+binomial( 5, 3); /* 10 */
+binomial(-5, 3); /* -35 */
+binomial( 5, -3); /* 0 */
+binomial(-5, -3); /* 0 */
+binomial( 3, 5); /* 0 */
+
+binomial(x, 3); /* ((x - 2)*(x - 1)*x)/6 */
+
+binomial(3, 1/2); /* binomial(3, 1/2) */
+makegamma(%); /* 32/(5*%pi) */
+
+binomial(a, b); /* binomial(a, b) */
+makegamma(%); /* gamma(a + 1)/(gamma(-b + a + 1)*gamma(b + 1)) */
diff --git a/Task/Even-or-odd/Fish/even-or-odd.fish b/Task/Even-or-odd/Fish/even-or-odd.fish
new file mode 100644
index 0000000000..c27494a242
--- /dev/null
+++ b/Task/Even-or-odd/Fish/even-or-odd.fish
@@ -0,0 +1,4 @@
+l0)?!vo v < v o<
+^ >i:a=?v>i:a=?v$a*+^>"The number is even."ar>l0=?!^>
+ > >2%0=?^"The number is odd."ar ^
diff --git a/Task/Even-or-odd/Groovy/even-or-odd-1.groovy b/Task/Even-or-odd/Groovy/even-or-odd-1.groovy
new file mode 100644
index 0000000000..617558f0a5
--- /dev/null
+++ b/Task/Even-or-odd/Groovy/even-or-odd-1.groovy
@@ -0,0 +1,2 @@
+def isOdd = { int i -> (i & 1) as boolean }
+def isEven = {int i -> ! isOdd(i) }
diff --git a/Task/Even-or-odd/Groovy/even-or-odd-2.groovy b/Task/Even-or-odd/Groovy/even-or-odd-2.groovy
new file mode 100644
index 0000000000..cf28907386
--- /dev/null
+++ b/Task/Even-or-odd/Groovy/even-or-odd-2.groovy
@@ -0,0 +1,3 @@
+1.step(20, 2) { assert isOdd(it) }
+
+50.step(-50, -2) { assert isEven(it) }
diff --git a/Task/Even-or-odd/Icon/even-or-odd.icon b/Task/Even-or-odd/Icon/even-or-odd.icon
new file mode 100644
index 0000000000..086fa084dc
--- /dev/null
+++ b/Task/Even-or-odd/Icon/even-or-odd.icon
@@ -0,0 +1,3 @@
+procedure isEven(n)
+ return n%2 = 0
+end
diff --git a/Task/Even-or-odd/J/even-or-odd-1.j b/Task/Even-or-odd/J/even-or-odd-1.j
new file mode 100644
index 0000000000..5592594947
--- /dev/null
+++ b/Task/Even-or-odd/J/even-or-odd-1.j
@@ -0,0 +1,4 @@
+ 2 | 2 3 5 7
+0 1 1 1
+ 2|2 3 5 7 + (2^89x)-1
+1 0 0 0
diff --git a/Task/Even-or-odd/J/even-or-odd-2.j b/Task/Even-or-odd/J/even-or-odd-2.j
new file mode 100644
index 0000000000..2c9c9b37ab
--- /dev/null
+++ b/Task/Even-or-odd/J/even-or-odd-2.j
@@ -0,0 +1,4 @@
+ (= <.&.-:) 2 3 5 7
+1 0 0 0
+ (= <.&.-:) 2 3 5 7+(2^89x)-1
+0 1 1 1
diff --git a/Task/Even-or-odd/J/even-or-odd-3.j b/Task/Even-or-odd/J/even-or-odd-3.j
new file mode 100644
index 0000000000..e52c35a4b7
--- /dev/null
+++ b/Task/Even-or-odd/J/even-or-odd-3.j
@@ -0,0 +1,4 @@
+ {:"1@#: 2 3 5 7
+0 1 1 1
+ {:"1@#: 2 3 5 7+(2^89x)-1
+1 0 0 0
diff --git a/Task/Even-or-odd/J/even-or-odd-4.j b/Task/Even-or-odd/J/even-or-odd-4.j
new file mode 100644
index 0000000000..83d59f5f59
--- /dev/null
+++ b/Task/Even-or-odd/J/even-or-odd-4.j
@@ -0,0 +1,2 @@
+ 1 (17 b.) 2 3 5 7
+0 1 1 1
diff --git a/Task/Even-or-odd/Lang5/even-or-odd.lang5 b/Task/Even-or-odd/Lang5/even-or-odd.lang5
new file mode 100644
index 0000000000..9eddc0ac9a
--- /dev/null
+++ b/Task/Even-or-odd/Lang5/even-or-odd.lang5
@@ -0,0 +1,4 @@
+: even? 2 % not ;
+: odd? 2 % ;
+1 even? . # 0
+1 odd? . # 1
diff --git a/Task/Even-or-odd/Liberty-BASIC/even-or-odd.liberty b/Task/Even-or-odd/Liberty-BASIC/even-or-odd.liberty
new file mode 100644
index 0000000000..38160d4238
--- /dev/null
+++ b/Task/Even-or-odd/Liberty-BASIC/even-or-odd.liberty
@@ -0,0 +1,3 @@
+n=12
+
+if n mod 2 = 0 then print "even" else print "odd"
diff --git a/Task/Even-or-odd/Mathematica/even-or-odd.mathematica b/Task/Even-or-odd/Mathematica/even-or-odd.mathematica
new file mode 100644
index 0000000000..31d1dc128b
--- /dev/null
+++ b/Task/Even-or-odd/Mathematica/even-or-odd.mathematica
@@ -0,0 +1 @@
+EvenQ[8]
diff --git a/Task/Even-or-odd/Maxima/even-or-odd.maxima b/Task/Even-or-odd/Maxima/even-or-odd.maxima
new file mode 100644
index 0000000000..f5d0a5184f
--- /dev/null
+++ b/Task/Even-or-odd/Maxima/even-or-odd.maxima
@@ -0,0 +1,2 @@
+evenp(n);
+oddp(n);
diff --git a/Task/Even-or-odd/Mercury/even-or-odd.mercury b/Task/Even-or-odd/Mercury/even-or-odd.mercury
new file mode 100644
index 0000000000..a551bba8b7
--- /dev/null
+++ b/Task/Even-or-odd/Mercury/even-or-odd.mercury
@@ -0,0 +1,10 @@
+even(N) % in a body, suceeeds iff N is even.
+odd(N). % in a body, succeeds iff N is odd.
+
+% rolling our own:
+:- pred even(int::in) is semidet.
+
+% It's an error to have all three in one module, mind; even/1 would fail to check as semidet.
+even(N) :- N mod 2 = 0. % using division that truncates towards -infinity
+even(N) :- N rem 2 = 0. % using division that truncates towards zero
+even(N) :- N /\ 1 = 0. % using bit-wise and.
diff --git a/Task/Events/Mathematica/events.mathematica b/Task/Events/Mathematica/events.mathematica
new file mode 100644
index 0000000000..87fd6d7d11
--- /dev/null
+++ b/Task/Events/Mathematica/events.mathematica
@@ -0,0 +1,2 @@
+Print["Will exit in 4 seconds"]; Pause[4]; Quit[]
+->Will exit in 4 seconds
diff --git a/Task/Evolutionary-algorithm/Fantom/evolutionary-algorithm.fantom b/Task/Evolutionary-algorithm/Fantom/evolutionary-algorithm.fantom
new file mode 100644
index 0000000000..f9fd354f1e
--- /dev/null
+++ b/Task/Evolutionary-algorithm/Fantom/evolutionary-algorithm.fantom
@@ -0,0 +1,56 @@
+class Main
+{
+ static const Str target := "METHINKS IT IS LIKE A WEASEL"
+ static const Int C := 100 // size of population
+ static const Float p := 0.1f // chance any char is mutated
+
+ // compute distance of str from target
+ static Int fitness (Str str)
+ {
+ Int sum := 0
+ str.each |Int c, Int index|
+ {
+ if (c != target[index]) sum += 1
+ }
+ return sum
+ }
+
+ // mutate given parent string
+ static Str mutate (Str str)
+ {
+ Str result := ""
+ str.size.times |Int index|
+ {
+ result += ((Float.random < p) ? randomChar() : str[index]).toChar
+ }
+ return result
+ }
+
+ // return a random char
+ static Int randomChar ()
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ "[Int.random(0..26)]
+ }
+
+ // make population by mutating parent and sorting by fitness
+ static Str[] makePopulation (Str parent)
+ {
+ Str[] result := [,]
+ C.times { result.add (mutate(parent)) }
+ result.sort |Str a, Str b -> Int| { fitness(a) <=> fitness(b) }
+ return result
+ }
+
+ public static Void main ()
+ {
+ Str parent := ""
+ target.size.times { parent += randomChar().toChar }
+
+ while (parent != target)
+ {
+ echo (parent)
+ parent = makePopulation(parent).first
+ }
+ echo (parent)
+ }
+}
diff --git a/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm.icon b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm.icon
new file mode 100644
index 0000000000..039ac0694b
--- /dev/null
+++ b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm.icon
@@ -0,0 +1,51 @@
+global target, chars, parent, C, M, current_fitness
+
+procedure fitness(s)
+ fit := 0
+ #Increment the fitness for every position in the string s that matches the target
+ every i := 1 to *target & s[i] == target[i] do fit +:= 1
+ return fit
+end
+
+procedure mutate(s)
+ #If a random number between 0 and 1 is inside the bounds of mutation randomly alter a character in the string
+ if (?0 <= M) then ?s := ?chars
+ return s
+end
+
+procedure generation()
+ population := [ ]
+ next_parent := ""
+ next_fitness := -1
+
+ #Create the next population
+ every 1 to C do push(population, mutate(parent))
+ #Find the member of the population with highest fitness, or use the last one inspected
+ every x := !population & (xf := fitness(x)) > next_fitness do {
+ next_parent := x
+ next_fitness := xf
+ }
+
+ parent := next_parent
+
+ return next_fitness
+end
+
+procedure main()
+ target := "METHINKS IT IS LIKE A WEASEL" #Our target string
+ chars := &ucase ++ " " #Set of usable characters
+ parent := "" & every 1 to *target do parent ||:= ?chars #The universal common ancestor!
+ current_fitness := fitness(parent) #The best fitness we have so far
+
+
+ C := 50 #Population size in each generation
+ M := 0.5 #Mutation rate per individual in a generation
+
+ gen := 1
+ #Until current fitness reaches a score of perfect match with the target string keep generating new populations
+ until ((current_fitness := generation()) = *target) do {
+ write(gen || " " || current_fitness || " " || parent)
+ gen +:= 1
+ }
+ write("At generation " || gen || " we found a string with perfect fitness at " || current_fitness || " reading: " || parent)
+end
diff --git a/Task/Evolutionary-algorithm/J/evolutionary-algorithm-1.j b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-1.j
new file mode 100644
index 0000000000..040a2f39c6
--- /dev/null
+++ b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-1.j
@@ -0,0 +1,14 @@
+CHARSET=: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '
+NPROG=: 100 NB. number of progeny (C)
+MRATE=: 0.05 NB. mutation rate
+
+create =: (?@$&$ { ])&CHARSET NB. creates random list from charset of same shape as y
+fitness =: +/@:~:"1
+copy =: # ,:
+mutate =: &(>: $ ?@$ 0:)(`(,: create))} NB. adverb
+select =: ] {~ (i. <./)@:fitness NB. select fittest member of population
+
+nextgen =: select ] , [: MRATE mutate NPROG copy ]
+while =: conjunction def '(] , (u {:))^:(v {:)^:_ ,:'
+
+evolve=: nextgen while (0 < fitness) create
diff --git a/Task/Evolutionary-algorithm/J/evolutionary-algorithm-2.j b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-2.j
new file mode 100644
index 0000000000..8d3b19b0b0
--- /dev/null
+++ b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-2.j
@@ -0,0 +1,6 @@
+ filter=: {: ,~ ({~ i.@>.&.(%&20)@#) NB. take every 20th and last item
+ filter evolve 'METHINKS IT IS LIKE A WEASEL'
+XXURVQXKQXDLCGFVICCUA NUQPND
+MEFHINVQQXT IW LIKEUA WEAPEL
+METHINVS IT IW LIKEUA WEAPEL
+METHINKS IT IS LIKE A WEASEL
diff --git a/Task/Evolutionary-algorithm/J/evolutionary-algorithm-3.j b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-3.j
new file mode 100644
index 0000000000..104bc99308
--- /dev/null
+++ b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-3.j
@@ -0,0 +1,27 @@
+CHARSET=: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '
+NPROG=: 100 NB. "C" from specification
+
+fitness=: +/@:~:"1
+select=: ] {~ (i. <./)@:fitness NB. select fittest member of population
+populate=: (?@$ { ])&CHARSET NB. get random list from charset of same length as y
+log=: [: smoutput [: ;:inv (('#';'fitness: ';'; ') ,&.> ":&.>)
+
+mutate=: dyad define
+ idxmut=. I. x >: (*/$y) ?@$ 0
+ (populate idxmut) idxmut"_} y
+)
+
+evolve=: monad define
+ target=. y
+ parent=. populate y
+ iter=. 0
+ mrate=. %#y
+ while. 0 < val=. target fitness parent do.
+ if. 0 = 50|iter do. log iter;val;parent end.
+ iter=. iter + 1
+ progeny=. mrate mutate NPROG # ,: parent NB. create progeny by mutating parent copies
+ parent=. target select parent,progeny NB. select fittest parent for next generation
+ end.
+ log iter;val;parent
+ parent
+)
diff --git a/Task/Evolutionary-algorithm/J/evolutionary-algorithm-4.j b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-4.j
new file mode 100644
index 0000000000..f12be43f82
--- /dev/null
+++ b/Task/Evolutionary-algorithm/J/evolutionary-algorithm-4.j
@@ -0,0 +1,5 @@
+ evolve 'METHINKS IT IS LIKE A WEASEL'
+#0 fitness: 27 ; YGFDJFTBEDB FAIJJGMFKDPYELOA
+#50 fitness: 2 ; MEVHINKS IT IS LIKE ADWEASEL
+#76 fitness: 0 ; METHINKS IT IS LIKE A WEASEL
+METHINKS IT IS LIKE A WEASEL
diff --git a/Task/Evolutionary-algorithm/Liberty-BASIC/evolutionary-algorithm.liberty b/Task/Evolutionary-algorithm/Liberty-BASIC/evolutionary-algorithm.liberty
new file mode 100644
index 0000000000..802c1bad5b
--- /dev/null
+++ b/Task/Evolutionary-algorithm/Liberty-BASIC/evolutionary-algorithm.liberty
@@ -0,0 +1,69 @@
+C = 10
+'mutaterate has to be greater than 1 or it will not mutate
+mutaterate = 2
+mutationstaken = 0
+generations = 0
+Dim parentcopies$((C - 1))
+Global targetString$ : targetString$ = "METHINKS IT IS LIKE A WEASEL"
+Global allowableCharacters$ : allowableCharacters$ = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+currentminFitness = Len(targetString$)
+
+For i = 1 To Len(targetString$)
+ parent$ = parent$ + Mid$(allowableCharacters$, Int(Rnd(1) * Len(allowableCharacters$)), 1)
+Next i
+
+Print "Parent = " + parent$
+
+While parent$ <> targetString$
+ generations = (generations + 1)
+ For i = 0 To (C - 1)
+ parentcopies$(i) = mutate$(parent$, mutaterate)
+ mutationstaken = (mutationstaken + 1)
+ Next i
+ For i = 0 To (C - 1)
+ currentFitness = Fitness(targetString$, parentcopies$(i))
+ If currentFitness = 0 Then
+ parent$ = parentcopies$(i)
+ Exit For
+ Else
+ If currentFitness < currentminFitness Then
+ currentminFitness = currentFitness
+ parent$ = parentcopies$(i)
+ End If
+ End If
+ Next i
+ CLS
+ Print "Generation - " + str$(generations)
+ Print "Parent - " + parent$
+ Scan
+Wend
+
+Print
+Print "Congratulations to me; I finished!"
+Print "Final Mutation: " + parent$
+'The ((i + 1) - (C)) reduces the total number of mutations that it took by one generation
+'minus the perfect child mutation since any after that would not have been required.
+Print "Total Mutations Taken - " + str$(mutationstaken - ((i + 1) - (C)))
+Print "Total Generations Taken - " + str$(generations)
+Print "Child Number " + str$(i) + " has perfect similarities to your target."
+End
+
+
+
+Function mutate$(mutate$, mutaterate)
+ If (Rnd(1) * mutaterate) > 1 Then
+ 'The mutatingcharater randomizer needs 1 more than the length of the string
+ 'otherwise it will likely take forever to get exactly that as a random number
+ mutatingcharacter = Int(Rnd(1) * (Len(targetString$) + 1))
+ mutate$ = Left$(mutate$, (mutatingcharacter - 1)) + Mid$(allowableCharacters$, Int(Rnd(1) * Len(allowableCharacters$)), 1) _
+ + Mid$(mutate$, (mutatingcharacter + 1))
+ End If
+End Function
+
+Function Fitness(parent$, offspring$)
+ For i = 1 To Len(targetString$)
+ If Mid$(parent$, i, 1) <> Mid$(offspring$, i, 1) Then
+ Fitness = (Fitness + 1)
+ End If
+ Next i
+End Function
diff --git a/Task/Evolutionary-algorithm/Logo/evolutionary-algorithm.logo b/Task/Evolutionary-algorithm/Logo/evolutionary-algorithm.logo
new file mode 100644
index 0000000000..2876b651d9
--- /dev/null
+++ b/Task/Evolutionary-algorithm/Logo/evolutionary-algorithm.logo
@@ -0,0 +1,44 @@
+make "target "|METHINKS IT IS LIKE A WEASEL|
+
+to distance :w
+ output reduce "sum (map.se [ifelse equal? ?1 ?2 [0][1]] :w :target)
+end
+
+to random.letter
+ output pick "| ABCDEFGHIJKLMNOPQRSTUVWXYZ|
+end
+
+to mutate :parent :rate
+ output map [ifelse random 100 < :rate [random.letter] [?]] :parent
+end
+
+make "C 100
+make "mutate.rate 10 ; percent
+
+to breed :parent
+ make "parent.distance distance :parent
+ localmake "best.child :parent
+ repeat :C [
+ localmake "child mutate :parent :mutate.rate
+ localmake "child.distance distance :child
+ if greater? :parent.distance :child.distance [
+ make "parent.distance :child.distance
+ make "best.child :child
+ ]
+ ]
+ output :best.child
+end
+
+to progress
+ output (sentence :trials :parent "distance: :parent.distance)
+end
+
+to evolve
+ make "parent cascade count :target [lput random.letter ?] "||
+ make "trials 0
+ while [not equal? :parent :target] [
+ make "parent breed :parent
+ print progress
+ make "trials :trials + 1
+ ]
+end
diff --git a/Task/Evolutionary-algorithm/Mathematica/evolutionary-algorithm.mathematica b/Task/Evolutionary-algorithm/Mathematica/evolutionary-algorithm.mathematica
new file mode 100644
index 0000000000..276742a2a0
--- /dev/null
+++ b/Task/Evolutionary-algorithm/Mathematica/evolutionary-algorithm.mathematica
@@ -0,0 +1,21 @@
+target = "METHINKS IT IS LIKE A WEASEL";
+alphabet = CharacterRange["A", "Z"]~Join~{" "};
+fitness = HammingDistance[target, #] &;
+Mutate[parent_String, rate_: 0.01, fertility_Integer: 25] := Module[
+ {offspring, kidfits, gen = 0, alphabet = CharacterRange["A", "Z"]~Join~{" "}},
+ offspring = ConstantArray[Characters[parent], fertility];
+ Table[
+ If[RandomReal[] <= rate, offspring[[j, k]] = RandomChoice[alphabet]],
+ {j, fertility}, {k, StringLength@parent}
+ ];
+ offspring = StringJoin[#] & /@ offspring;
+ kidfits = fitness[#] & /@ Flatten[{offspring, parent}];
+ Return[offspring[[First@Ordering[kidfits]]]];
+ ];
+
+mutationRate = 0.02;
+parent = StringJoin[ alphabet[[RandomInteger[{1, Length@alphabet}, StringLength@target]]] ];
+results = NestWhileList[Mutate[#, mutationRate, 100] &, parent, fitness[#] > 0 &];
+fits = fitness[#] & /@ results;
+results = Transpose[{results, fits}];
+TableForm[results[[;; ;; 2]], TableHeadings->{Range[1, Length@results, 2],{"String","Fitness"}}, TableSpacing -> {1, 2}]
diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Fantom/exceptions-catch-an-exception-thrown-in-a-nested-call.fantom b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Fantom/exceptions-catch-an-exception-thrown-in-a-nested-call.fantom
new file mode 100644
index 0000000000..34e083a479
--- /dev/null
+++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Fantom/exceptions-catch-an-exception-thrown-in-a-nested-call.fantom
@@ -0,0 +1,48 @@
+const class U0 : Err
+{
+ new make () : super ("U0") {}
+}
+
+const class U1 : Err
+{
+ new make () : super ("U1") {}
+}
+
+class Main
+{
+ Int bazCalls := 0
+
+ Void baz ()
+ {
+ bazCalls += 1
+ if (bazCalls == 1)
+ throw U0()
+ else
+ throw U1()
+ }
+
+ Void bar ()
+ {
+ baz ()
+ }
+
+ Void foo ()
+ {
+ 2.times
+ {
+ try
+ {
+ bar ()
+ }
+ catch (U0 e)
+ {
+ echo ("Caught U0")
+ }
+ }
+ }
+
+ public static Void main ()
+ {
+ Main().foo
+ }
+}
diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-1.j b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-1.j
new file mode 100644
index 0000000000..0a8a0b8cbf
--- /dev/null
+++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-1.j
@@ -0,0 +1,22 @@
+main=: monad define
+ smoutput 'main'
+ try. foo ''
+ catcht. smoutput 'main caught ',type_jthrow_
+ end.
+)
+
+foo=: monad define
+ smoutput ' foo'
+ for_i. 0 1 do.
+ try. bar i
+ catcht. if. type_jthrow_-:'U0' do. smoutput ' foo caught ',type_jthrow_ else. throw. end.
+ end.
+ end.
+)
+
+bar=: baz [ smoutput bind ' bar'
+
+baz=: monad define
+ smoutput ' baz'
+ type_jthrow_=: 'U',":y throw.
+)
diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-2.j b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-2.j
new file mode 100644
index 0000000000..a582254009
--- /dev/null
+++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/J/exceptions-catch-an-exception-thrown-in-a-nested-call-2.j
@@ -0,0 +1,9 @@
+ main ''
+main
+ foo
+ bar
+ baz
+ foo caught U0
+ bar
+ baz
+main caught U1
diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Mathematica/exceptions-catch-an-exception-thrown-in-a-nested-call.mathematica b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Mathematica/exceptions-catch-an-exception-thrown-in-a-nested-call.mathematica
new file mode 100644
index 0000000000..f31cae736c
--- /dev/null
+++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Mathematica/exceptions-catch-an-exception-thrown-in-a-nested-call.mathematica
@@ -0,0 +1,7 @@
+foo[] := Catch[ bar[1]; bar[2]; ]
+
+bar[i_] := baz[i];
+
+baz[i_] := Switch[i,
+ 1, Throw["Exception U0 in baz"];,
+ 2, Throw["Exception U1 in baz"];]
diff --git a/Task/Exceptions/Factor/exceptions-1.factor b/Task/Exceptions/Factor/exceptions-1.factor
new file mode 100644
index 0000000000..68ae678e88
--- /dev/null
+++ b/Task/Exceptions/Factor/exceptions-1.factor
@@ -0,0 +1,4 @@
+"Install Linux, Problem Solved" throw
+
+TUPLE: velociraptor ;
+\ velociraptor new throw
diff --git a/Task/Exceptions/Factor/exceptions-2.factor b/Task/Exceptions/Factor/exceptions-2.factor
new file mode 100644
index 0000000000..fee3da7a27
--- /dev/null
+++ b/Task/Exceptions/Factor/exceptions-2.factor
@@ -0,0 +1,2 @@
+ERROR: velociraptor ;
+velociraptor
diff --git a/Task/Exceptions/Factor/exceptions-3.factor b/Task/Exceptions/Factor/exceptions-3.factor
new file mode 100644
index 0000000000..a984eaab8a
--- /dev/null
+++ b/Task/Exceptions/Factor/exceptions-3.factor
@@ -0,0 +1,12 @@
+! Preferred exception handling
+: try-foo
+ [ foo ] [ foo-failed ] recover ;
+
+: try-bar
+ [ bar ] [ bar-errored ] [ bar-always ] cleanup ;
+
+! Used rarely
+[ "Fail" throw ] try ! throws a "Fail"
+[ "Fail" throw ] catch ! returns "Fail"
+[ "Hi" print ] catch ! returns f (looks the same as throwing f; don't throw f)
+[ f throw ] catch ! returns f, bad! use recover or cleanup instead
diff --git a/Task/Exceptions/Fancy/exceptions.fancy b/Task/Exceptions/Fancy/exceptions.fancy
new file mode 100644
index 0000000000..01fd1b140c
--- /dev/null
+++ b/Task/Exceptions/Fancy/exceptions.fancy
@@ -0,0 +1,20 @@
+# define custom exception class
+# StandardError is base class for all exception classes
+class MyError : StandardError {
+ def initialize: message {
+ # forward to StdError's initialize method
+ super initialize: message
+ }
+}
+
+try {
+ # raises/throws a new MyError exception within try-block
+ MyError new: "my message" . raise!
+} catch MyError => e {
+ # catch exception
+ # this will print "my message"
+ e message println
+} finally {
+ # this will always be executed (as in e.g. Java)
+ "This is how exception handling in Fancy works :)" println
+}
diff --git a/Task/Exceptions/Fantom/exceptions.fantom b/Task/Exceptions/Fantom/exceptions.fantom
new file mode 100644
index 0000000000..db6bee6744
--- /dev/null
+++ b/Task/Exceptions/Fantom/exceptions.fantom
@@ -0,0 +1,23 @@
+// Create a new error class by subclassing sys::Err
+const class SpecialErr : Err
+{
+ // you must provide some message about the error
+ // to the parent class, for reporting
+ new make () : super ("special error") {}
+}
+
+class Main
+{
+ static Void fn ()
+ {
+ throw SpecialErr ()
+ }
+
+ public static Void main ()
+ {
+ try
+ fn()
+ catch (SpecialErr e)
+ echo ("Caught " + e)
+ }
+}
diff --git a/Task/Exceptions/J/exceptions.j b/Task/Exceptions/J/exceptions.j
new file mode 100644
index 0000000000..ed73e0ba21
--- /dev/null
+++ b/Task/Exceptions/J/exceptions.j
@@ -0,0 +1,18 @@
+ pickyPicky =: verb define
+ if. y-:'bad argument' do.
+ throw.
+ else.
+ 'thanks!'
+ end.
+ )
+
+ tryThis =: verb define
+ try.
+ pickyPicky y
+ catcht.
+ 'Uh oh!'
+ end.
+ )
+
+ tryThis 'bad argument'
+Uh oh!
diff --git a/Task/Exceptions/Logo/exceptions.logo b/Task/Exceptions/Logo/exceptions.logo
new file mode 100644
index 0000000000..8e154f0433
--- /dev/null
+++ b/Task/Exceptions/Logo/exceptions.logo
@@ -0,0 +1,7 @@
+to div.checked :a :b
+ if :b = 0 [(throw "divzero 0)]
+ output :a / :b
+end
+to div.safely :a :b
+ output catch "divzero [div.checked :a :b]
+end
diff --git a/Task/Exceptions/MOO/exceptions-1.moo b/Task/Exceptions/MOO/exceptions-1.moo
new file mode 100644
index 0000000000..0cc6cf531a
--- /dev/null
+++ b/Task/Exceptions/MOO/exceptions-1.moo
@@ -0,0 +1 @@
+raise(E_PERM);
diff --git a/Task/Exceptions/MOO/exceptions-2.moo b/Task/Exceptions/MOO/exceptions-2.moo
new file mode 100644
index 0000000000..97fbf9b9ce
--- /dev/null
+++ b/Task/Exceptions/MOO/exceptions-2.moo
@@ -0,0 +1,5 @@
+try
+ this:foo();
+except e (ANY)
+ this:bar(e);
+endtry
diff --git a/Task/Exceptions/MOO/exceptions-3.moo b/Task/Exceptions/MOO/exceptions-3.moo
new file mode 100644
index 0000000000..51ee7dd2c7
--- /dev/null
+++ b/Task/Exceptions/MOO/exceptions-3.moo
@@ -0,0 +1,5 @@
+try
+ this:foo();
+finally
+ this:bar();
+endtry
diff --git a/Task/Exceptions/MOO/exceptions-4.moo b/Task/Exceptions/MOO/exceptions-4.moo
new file mode 100644
index 0000000000..4afbc228ad
--- /dev/null
+++ b/Task/Exceptions/MOO/exceptions-4.moo
@@ -0,0 +1 @@
+`this:foo()!ANY=>this:bar()';
diff --git a/Task/Exceptions/Make/exceptions-1.make b/Task/Exceptions/Make/exceptions-1.make
new file mode 100644
index 0000000000..1dd0cdb323
--- /dev/null
+++ b/Task/Exceptions/Make/exceptions-1.make
@@ -0,0 +1,2 @@
+all:
+ false
diff --git a/Task/Exceptions/Make/exceptions-2.make b/Task/Exceptions/Make/exceptions-2.make
new file mode 100644
index 0000000000..5d6465963d
--- /dev/null
+++ b/Task/Exceptions/Make/exceptions-2.make
@@ -0,0 +1,2 @@
+all:
+ -@make -f fail.mk
diff --git a/Task/Exceptions/Make/exceptions-3.make b/Task/Exceptions/Make/exceptions-3.make
new file mode 100644
index 0000000000..953555d8a5
--- /dev/null
+++ b/Task/Exceptions/Make/exceptions-3.make
@@ -0,0 +1,2 @@
+all:
+ make -f fail.mk; exit 0
diff --git a/Task/Exceptions/Mathematica/exceptions.mathematica b/Task/Exceptions/Mathematica/exceptions.mathematica
new file mode 100644
index 0000000000..3d0175be2c
--- /dev/null
+++ b/Task/Exceptions/Mathematica/exceptions.mathematica
@@ -0,0 +1,8 @@
+f[x_] := If[x > 10, Throw[overflow], x!]
+
+Example usage :
+Catch[f[2] + f[11]]
+-> overflow
+
+Catch[f[2] + f[3]]
+-> 8
diff --git a/Task/Exceptions/Modula-3/exceptions-1.mod3 b/Task/Exceptions/Modula-3/exceptions-1.mod3
new file mode 100644
index 0000000000..b7af559840
--- /dev/null
+++ b/Task/Exceptions/Modula-3/exceptions-1.mod3
@@ -0,0 +1,2 @@
+EXCEPTION EndOfFile;
+EXCEPTION Error(TEXT);
diff --git a/Task/Exceptions/Modula-3/exceptions-2.mod3 b/Task/Exceptions/Modula-3/exceptions-2.mod3
new file mode 100644
index 0000000000..624588a7eb
--- /dev/null
+++ b/Task/Exceptions/Modula-3/exceptions-2.mod3
@@ -0,0 +1,4 @@
+PROCEDURE Foo() RAISES { EndOfFile } =
+ ...
+ RAISE EndOfFile;
+ ...
diff --git a/Task/Exceptions/Modula-3/exceptions-3.mod3 b/Task/Exceptions/Modula-3/exceptions-3.mod3
new file mode 100644
index 0000000000..703eeda640
--- /dev/null
+++ b/Task/Exceptions/Modula-3/exceptions-3.mod3
@@ -0,0 +1,5 @@
+TRY
+ Foo();
+EXCEPT
+| EndOfFile => HandleFoo();
+END;
diff --git a/Task/Exceptions/Modula-3/exceptions-4.mod3 b/Task/Exceptions/Modula-3/exceptions-4.mod3
new file mode 100644
index 0000000000..603a4f9d4b
--- /dev/null
+++ b/Task/Exceptions/Modula-3/exceptions-4.mod3
@@ -0,0 +1,5 @@
+TRY
+ Foo();
+FINALLY
+ CleanupFoo(); (* always executed *)
+END;
diff --git a/Task/Executable-library/Factor/executable-library-1.factor b/Task/Executable-library/Factor/executable-library-1.factor
new file mode 100644
index 0000000000..94ac4bbf28
--- /dev/null
+++ b/Task/Executable-library/Factor/executable-library-1.factor
@@ -0,0 +1,31 @@
+! rosetta/hailstone/hailstone.factor
+USING: arrays io kernel math math.ranges prettyprint sequences vectors ;
+IN: rosetta.hailstone
+
+: hailstone ( n -- seq )
+ [ 1vector ] keep
+ [ dup 1 number= ]
+ [
+ dup even? [ 2 / ] [ 3 * 1 + ] if
+ 2dup swap push
+ ] until
+ drop ;
+
+ { length n }, and reduces to longest Hailstone sequence.
+ 1 100000 [a,b)
+ [ [ hailstone length ] keep 2array ]
+ [ [ [ first ] bi@ > ] most ] map-reduce
+ first2
+ "The hailstone sequence from " write pprint
+ " has length " write pprint "." print ;
+PRIVATE>
+
+MAIN: main
diff --git a/Task/Executable-library/Factor/executable-library-2.factor b/Task/Executable-library/Factor/executable-library-2.factor
new file mode 100644
index 0000000000..403d56b387
--- /dev/null
+++ b/Task/Executable-library/Factor/executable-library-2.factor
@@ -0,0 +1,27 @@
+! rosetta/hailstone/length/length.factor
+USING: assocs kernel io math math.ranges prettyprint
+ rosetta.hailstone sequences ;
+IN: rosetta.hailstone.length
+
+0 ( object/f -- object/0 )
+ dup [ drop 0 ] unless ;
+
+: max-value ( pair1 pair2 -- pair )
+ [ [ second ] bi@ > ] most ;
+
+: main ( -- )
+ H{ } clone ! Maps sequence length => count.
+ 1 100000 [a,b) [
+ hailstone length ! Find sequence length.
+ over [ f>0 1 + ] change-at ! Add 1 to count.
+ ] each
+ ! Find the length-count pair with the highest count.
+ >alist unclip-slice [ max-value ] reduce
+ first2 swap
+ "Among Hailstone sequences from 1 <= n < 100000," print
+ "there are " write pprint
+ " sequences of length " write pprint "." print ;
+PRIVATE>
+
+MAIN: main
diff --git a/Task/Executable-library/J/executable-library-1.j b/Task/Executable-library/J/executable-library-1.j
new file mode 100644
index 0000000000..14ec7a2e37
--- /dev/null
+++ b/Task/Executable-library/J/executable-library-1.j
@@ -0,0 +1,11 @@
+hailseq=: -:`(1 3&p.)@.(2&|) ^:(1 ~: ]) ^:a:"0
+9!:29]1
+9!:27'main 0'
+main=:3 :0
+ smoutput 'Hailstone sequence for the number 27'
+ smoutput hailseq 27
+ smoutput ''
+ smoutput 'Finding number with longest hailstone sequence which is'
+ smoutput 'less than 100000 (and finding that sequence length):'
+ smoutput (I.@(= >./),>./) #@hailseq i.1e5
+)
diff --git a/Task/Executable-library/J/executable-library-2.j b/Task/Executable-library/J/executable-library-2.j
new file mode 100644
index 0000000000..d53b254c6e
--- /dev/null
+++ b/Task/Executable-library/J/executable-library-2.j
@@ -0,0 +1,6 @@
+ load jpath '~temp/hailseq.ijs'
+Hailstone sequence for the number 27
+27 82 41 124 62 31 94 47 142 71 214 107 322 161 484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850 425 1276 638 319 958 479 1438 719 2158 1079 3238 ...
+Finding number with longest hailstone sequence which is
+less than 100000 (and finding that sequence length):
+77031 351
diff --git a/Task/Executable-library/J/executable-library-3.j b/Task/Executable-library/J/executable-library-3.j
new file mode 100644
index 0000000000..2bb186622c
--- /dev/null
+++ b/Task/Executable-library/J/executable-library-3.j
@@ -0,0 +1,8 @@
+require '~temp/hailseq.ijs'
+9!:29]1
+9!:27'main 0'
+main=:3 :0
+ smoutput 'Finding most frequent hailstone sequence length for'
+ smoutput 'Hailstone sequences for whole numbers less than 100000:'
+ smoutput {:{.\:~ (#/.~,.~.) #@hailseq }.i.1e5
+)
diff --git a/Task/Executable-library/J/executable-library-4.j b/Task/Executable-library/J/executable-library-4.j
new file mode 100644
index 0000000000..660d95e774
--- /dev/null
+++ b/Task/Executable-library/J/executable-library-4.j
@@ -0,0 +1,4 @@
+ load jpath '~temp/66.ijs'
+Finding most frequent hailstone sequence length for
+Hailstone sequences for whole numbers less than 100000
+72
diff --git a/Task/Execute-HQ9+/Icon/execute-hq9+.icon b/Task/Execute-HQ9+/Icon/execute-hq9+.icon
new file mode 100644
index 0000000000..16f788ff19
--- /dev/null
+++ b/Task/Execute-HQ9+/Icon/execute-hq9+.icon
@@ -0,0 +1,27 @@
+procedure main(A)
+repeat writes("Enter HQ9+ code: ") & HQ9(get(A)|read()|break)
+end
+
+procedure HQ9(code)
+static bnw,bcr
+initial { # number matching words and line feeds for the b-th bottle
+ bnw := table(" bottles"); bnw[1] := " bottle"; bnw[0] := "No more bottles"
+ bcr := table("\n"); bcr[0]:=""
+ }
+every c := map(!code) do # ignore case
+ case c of { # interpret
+ "h" : write("Hello, World!") # . hello
+ "q" : write(code) # . quine
+ "9" : { # . 99 bottles
+ every b := 99 to 1 by -1 do writes(
+ bcr[b],b,bnw[b]," of beer on the wall\n",
+ b,bnw[b]," of beer\nTake one down, pass it around\n",
+ 1~=b|"",bnw[b-1]," of beer on the wall",bcr[b-1])
+ write(", ",map(bnw[b-1])," of beer.\nGo to the store ",
+ "and buy some more, 99 bottles of beer on the wall.")
+ }
+ "+" : { /acc := 0 ; acc +:=1 } # . yes it is weird
+ default: stop("Syntax error in ",code) # . error/exit
+ }
+return
+end
diff --git a/Task/Execute-HQ9+/Inform-7/execute-hq9+.inf b/Task/Execute-HQ9+/Inform-7/execute-hq9+.inf
new file mode 100644
index 0000000000..2ccf888765
--- /dev/null
+++ b/Task/Execute-HQ9+/Inform-7/execute-hq9+.inf
@@ -0,0 +1,23 @@
+HQ9+ is a room.
+
+After reading a command:
+ interpret the player's command;
+ reject the player's command.
+
+To interpret (code - indexed text):
+ let accumulator be 0;
+ repeat with N running from 1 to the number of characters in code:
+ let C be character number N in code in upper case;
+ if C is "H":
+ say "Hello, world!";
+ otherwise if C is "Q":
+ say "[code][line break]";
+ otherwise if C is "9":
+ repeat with iteration running from 1 to 99:
+ let N be 100 - iteration;
+ say "[N] bottle[s] of beer on the wall[line break]";
+ say "[N] bottle[s] of beer[line break]";
+ say "Take one down, pass it around[line break]";
+ say "[N - 1] bottle[s] of beer on the wall[paragraph break]";
+ otherwise if C is "+":
+ increase accumulator by 1.
diff --git a/Task/Execute-HQ9+/J/execute-hq9+-1.j b/Task/Execute-HQ9+/J/execute-hq9+-1.j
new file mode 100644
index 0000000000..11181783ce
--- /dev/null
+++ b/Task/Execute-HQ9+/J/execute-hq9+-1.j
@@ -0,0 +1,3 @@
+bob =: ": , ' bottle' , (1 = ]) }. 's of beer'"_
+bobw=: bob , ' on the wall'"_
+beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:
diff --git a/Task/Execute-HQ9+/J/execute-hq9+-2.j b/Task/Execute-HQ9+/J/execute-hq9+-2.j
new file mode 100644
index 0000000000..633a9df02e
--- /dev/null
+++ b/Task/Execute-HQ9+/J/execute-hq9+-2.j
@@ -0,0 +1,6 @@
+H=: smoutput bind 'Hello, world!'
+Q=: smoutput @ [
+hq9=: smoutput @: (beer"0) bind (1+i.-99)
+hqp=: (A=:1)1 :'0 0$A=:A+m[y'@]
+
+hq9p=: H`H`Q`Q`hq9`hqp@.('HhQq9+' i. ])"_ 0~
diff --git a/Task/Execute-HQ9+/J/execute-hq9+-3.j b/Task/Execute-HQ9+/J/execute-hq9+-3.j
new file mode 100644
index 0000000000..d99cef88b1
--- /dev/null
+++ b/Task/Execute-HQ9+/J/execute-hq9+-3.j
@@ -0,0 +1,6 @@
+ hq9p 'hqQQq'
+Hello, world!
+hqQQq
+hqQQq
+hqQQq
+hqQQq
diff --git a/Task/Execute-HQ9+/Liberty-BASIC/execute-hq9+.liberty b/Task/Execute-HQ9+/Liberty-BASIC/execute-hq9+.liberty
new file mode 100644
index 0000000000..186b486319
--- /dev/null
+++ b/Task/Execute-HQ9+/Liberty-BASIC/execute-hq9+.liberty
@@ -0,0 +1,33 @@
+'Try this hq9+ program - "hq9+HqQ+Qq"
+Prompt "Please input your hq9+ program."; code$
+Print hq9plus$(code$)
+End
+
+Function hq9plus$(code$)
+ For i = 1 to Len(code$)
+ Select Case
+ Case Upper$(Mid$(code$, i, 1)) = "H"
+ hq9plus$ = hq9plus$ + "Hello, world!"
+ Case Upper$(Mid$(code$, i, 1)) = "Q"
+ hq9plus$ = hq9plus$ + code$
+ Case Mid$(code$, i, 1) = "9"
+ For bottles = 99 To 1 Step -1
+ hq9plus$ = hq9plus$ + str$(bottles) + " bottle"
+ If (bottles > 1) Then hq9plus$ = hq9plus$ + "s"
+ hq9plus$ = hq9plus$ + " of beer on the wall, " + str$(bottles) + " bottle"
+ If (bottles > 1) Then hq9plus$ = hq9plus$ + "s"
+ hq9plus$ = hq9plus$ + " of beer," + chr$(13) + chr$(10) + "Take one down, pass it around, " + str$(bottles - 1) + " bottle"
+ If (bottles > 2) Or (bottles = 1) Then hq9plus$ = hq9plus$ + "s"
+ hq9plus$ = hq9plus$ + " of beer on the wall." + chr$(13) + chr$(10)
+ Next bottles
+ hq9plus$ = hq9plus$ + "No more bottles of beer on the wall, no more bottles of beer." _
+ + chr$(13) + chr$(10) + "Go to the store and buy some more, 99 bottles of beer on the wall."
+ Case Mid$(code$, i, 1) = "+"
+ accumulator = (accumulator + 1)
+ End Select
+ If Mid$(code$, i, 1) <> "+" Then
+ hq9plus$ = hq9plus$ + chr$(13) + chr$(10)
+ End If
+ Next i
+ hq9plus$ = Left$(hq9plus$, (Len(hq9plus$) - 2))
+End Function
diff --git a/Task/Execute-HQ9+/Mathematica/execute-hq9+.mathematica b/Task/Execute-HQ9+/Mathematica/execute-hq9+.mathematica
new file mode 100644
index 0000000000..759ffa887c
--- /dev/null
+++ b/Task/Execute-HQ9+/Mathematica/execute-hq9+.mathematica
@@ -0,0 +1,10 @@
+hq9plus[program_] :=
+ Module[{accumulator = 0, bottle},
+ bottle[n_] :=
+ ToString[n] <> If[n == 1, " bottle", " bottles"] <> " of beer";
+ Do[Switch[chr, "H", Print@"hello, world", "Q", Print@program, "9",
+ Print@StringJoin[
+ Table[bottle[n] <> " on the wall\n" <> bottle[n] <>
+ "\ntake one down, pass it around\n" <> bottle[n - 1] <>
+ " on the wall" <> If[n == 1, "", "\n\n"], {n, 99, 1, -1}]],
+ "+", accumulator++], {chr, Characters@program}]; accumulator]
diff --git a/Task/Execute-a-system-command/Factor/execute-a-system-command.factor b/Task/Execute-a-system-command/Factor/execute-a-system-command.factor
new file mode 100644
index 0000000000..97c1f4b62d
--- /dev/null
+++ b/Task/Execute-a-system-command/Factor/execute-a-system-command.factor
@@ -0,0 +1 @@
+"ls" run-process wait-for-process
diff --git a/Task/Execute-a-system-command/Fantom/execute-a-system-command.fantom b/Task/Execute-a-system-command/Fantom/execute-a-system-command.fantom
new file mode 100644
index 0000000000..b22380dace
--- /dev/null
+++ b/Task/Execute-a-system-command/Fantom/execute-a-system-command.fantom
@@ -0,0 +1,8 @@
+class Main
+{
+ public static Void main ()
+ {
+ p := Process (["ls"])
+ p.run
+ }
+}
diff --git a/Task/Execute-a-system-command/GUISS/execute-a-system-command.guiss b/Task/Execute-a-system-command/GUISS/execute-a-system-command.guiss
new file mode 100644
index 0000000000..5a0a781fcd
--- /dev/null
+++ b/Task/Execute-a-system-command/GUISS/execute-a-system-command.guiss
@@ -0,0 +1 @@
+Start,Programs,Accessories,MSDOS Prompt,Type:dir[enter]
diff --git a/Task/Execute-a-system-command/HicEst/execute-a-system-command.hicest b/Task/Execute-a-system-command/HicEst/execute-a-system-command.hicest
new file mode 100644
index 0000000000..ea83e7ccdd
--- /dev/null
+++ b/Task/Execute-a-system-command/HicEst/execute-a-system-command.hicest
@@ -0,0 +1,2 @@
+SYSTEM(CoMmand='pause')
+SYSTEM(CoMmand='dir & pause')
diff --git a/Task/Execute-a-system-command/IDL/execute-a-system-command-1.idl b/Task/Execute-a-system-command/IDL/execute-a-system-command-1.idl
new file mode 100644
index 0000000000..1f6b6742e3
--- /dev/null
+++ b/Task/Execute-a-system-command/IDL/execute-a-system-command-1.idl
@@ -0,0 +1 @@
+$ls
diff --git a/Task/Execute-a-system-command/IDL/execute-a-system-command-2.idl b/Task/Execute-a-system-command/IDL/execute-a-system-command-2.idl
new file mode 100644
index 0000000000..cb273fd30e
--- /dev/null
+++ b/Task/Execute-a-system-command/IDL/execute-a-system-command-2.idl
@@ -0,0 +1 @@
+spawn,"ls",result
diff --git a/Task/Execute-a-system-command/IDL/execute-a-system-command-3.idl b/Task/Execute-a-system-command/IDL/execute-a-system-command-3.idl
new file mode 100644
index 0000000000..326b68127e
--- /dev/null
+++ b/Task/Execute-a-system-command/IDL/execute-a-system-command-3.idl
@@ -0,0 +1 @@
+spawn,"ls",unit=unit
diff --git a/Task/Execute-a-system-command/Icon/execute-a-system-command-1.icon b/Task/Execute-a-system-command/Icon/execute-a-system-command-1.icon
new file mode 100644
index 0000000000..5a7e381f15
--- /dev/null
+++ b/Task/Execute-a-system-command/Icon/execute-a-system-command-1.icon
@@ -0,0 +1,6 @@
+procedure main()
+
+write("Trying command ",cmd := if &features == "UNIX" then "ls" else "dir")
+system(cmd)
+
+end
diff --git a/Task/Execute-a-system-command/Icon/execute-a-system-command-2.icon b/Task/Execute-a-system-command/Icon/execute-a-system-command-2.icon
new file mode 100644
index 0000000000..d74a9aa96e
--- /dev/null
+++ b/Task/Execute-a-system-command/Icon/execute-a-system-command-2.icon
@@ -0,0 +1,2 @@
+ pid := system(command_string,&input,&output,&errout,"wait")
+ pid := system(command_string,&input,&output,&errout,"nowait")
diff --git a/Task/Execute-a-system-command/Io/execute-a-system-command.io b/Task/Execute-a-system-command/Io/execute-a-system-command.io
new file mode 100644
index 0000000000..c43a579c2c
--- /dev/null
+++ b/Task/Execute-a-system-command/Io/execute-a-system-command.io
@@ -0,0 +1 @@
+System runCommand("ls") stdout println
diff --git a/Task/Execute-a-system-command/J/execute-a-system-command.j b/Task/Execute-a-system-command/J/execute-a-system-command.j
new file mode 100644
index 0000000000..91bade7b4a
--- /dev/null
+++ b/Task/Execute-a-system-command/J/execute-a-system-command.j
@@ -0,0 +1,15 @@
+load'task'
+
+NB. Execute a command and wait for it to complete
+shell 'dir'
+
+NB. Execute a command but don't wait for it to complete
+fork 'notepad'
+
+NB. Execute a command and capture its stdout
+stdout =: shell 'dir'
+
+NB. Execute a command, provide it with stdin,
+NB. and capture its stdout
+stdin =: 'blahblahblah'
+stdout =: stdin spawn 'grep blah'
diff --git a/Task/Execute-a-system-command/Joy/execute-a-system-command.joy b/Task/Execute-a-system-command/Joy/execute-a-system-command.joy
new file mode 100644
index 0000000000..ffb4823f14
--- /dev/null
+++ b/Task/Execute-a-system-command/Joy/execute-a-system-command.joy
@@ -0,0 +1 @@
+"ls" system.
diff --git a/Task/Execute-a-system-command/K/execute-a-system-command-1.k b/Task/Execute-a-system-command/K/execute-a-system-command-1.k
new file mode 100644
index 0000000000..4f32642f3c
--- /dev/null
+++ b/Task/Execute-a-system-command/K/execute-a-system-command-1.k
@@ -0,0 +1 @@
+ \ls
diff --git a/Task/Execute-a-system-command/K/execute-a-system-command-2.k b/Task/Execute-a-system-command/K/execute-a-system-command-2.k
new file mode 100644
index 0000000000..8c24bf81fd
--- /dev/null
+++ b/Task/Execute-a-system-command/K/execute-a-system-command-2.k
@@ -0,0 +1 @@
+ r: 4:"ls"
diff --git a/Task/Execute-a-system-command/Lang5/execute-a-system-command.lang5 b/Task/Execute-a-system-command/Lang5/execute-a-system-command.lang5
new file mode 100644
index 0000000000..3130995d90
--- /dev/null
+++ b/Task/Execute-a-system-command/Lang5/execute-a-system-command.lang5
@@ -0,0 +1 @@
+'ls system
diff --git a/Task/Execute-a-system-command/Liberty-BASIC/execute-a-system-command.liberty b/Task/Execute-a-system-command/Liberty-BASIC/execute-a-system-command.liberty
new file mode 100644
index 0000000000..ee0e3ecea1
--- /dev/null
+++ b/Task/Execute-a-system-command/Liberty-BASIC/execute-a-system-command.liberty
@@ -0,0 +1,2 @@
+ drive1$ = left$(Drives$,1)
+run "cmd.exe /";drive1$;" dir & pause"
diff --git a/Task/Execute-a-system-command/Locomotive-Basic/execute-a-system-command.bas b/Task/Execute-a-system-command/Locomotive-Basic/execute-a-system-command.bas
new file mode 100644
index 0000000000..450cdfbda0
--- /dev/null
+++ b/Task/Execute-a-system-command/Locomotive-Basic/execute-a-system-command.bas
@@ -0,0 +1 @@
+LIST
diff --git a/Task/Execute-a-system-command/Logo/execute-a-system-command.logo b/Task/Execute-a-system-command/Logo/execute-a-system-command.logo
new file mode 100644
index 0000000000..288d19c74a
--- /dev/null
+++ b/Task/Execute-a-system-command/Logo/execute-a-system-command.logo
@@ -0,0 +1 @@
+print first butfirst shell [ls -a] ; ..
diff --git a/Task/Execute-a-system-command/M4/execute-a-system-command.m4 b/Task/Execute-a-system-command/M4/execute-a-system-command.m4
new file mode 100644
index 0000000000..ada3794e16
--- /dev/null
+++ b/Task/Execute-a-system-command/M4/execute-a-system-command.m4
@@ -0,0 +1 @@
+syscmd(ifdef(`__windows__',`dir',`ls'))
diff --git a/Task/Execute-a-system-command/MAXScript/execute-a-system-command.max b/Task/Execute-a-system-command/MAXScript/execute-a-system-command.max
new file mode 100644
index 0000000000..8904fff74c
--- /dev/null
+++ b/Task/Execute-a-system-command/MAXScript/execute-a-system-command.max
@@ -0,0 +1 @@
+dosCommand "pause"
diff --git a/Task/Execute-a-system-command/MUMPS/execute-a-system-command-1.mumps b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-1.mumps
new file mode 100644
index 0000000000..a804722df8
--- /dev/null
+++ b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-1.mumps
@@ -0,0 +1 @@
+Set X=$ZF(-1,"DIR")
diff --git a/Task/Execute-a-system-command/MUMPS/execute-a-system-command-2.mumps b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-2.mumps
new file mode 100644
index 0000000000..6059c25210
--- /dev/null
+++ b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-2.mumps
@@ -0,0 +1 @@
+ZSY "DIR"
diff --git a/Task/Execute-a-system-command/MUMPS/execute-a-system-command-3.mumps b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-3.mumps
new file mode 100644
index 0000000000..7816a7e686
--- /dev/null
+++ b/Task/Execute-a-system-command/MUMPS/execute-a-system-command-3.mumps
@@ -0,0 +1 @@
+ZSY "ls"
diff --git a/Task/Execute-a-system-command/Make/execute-a-system-command-1.make b/Task/Execute-a-system-command/Make/execute-a-system-command-1.make
new file mode 100644
index 0000000000..2839af56f0
--- /dev/null
+++ b/Task/Execute-a-system-command/Make/execute-a-system-command-1.make
@@ -0,0 +1,2 @@
+contents=$(shell cat foo)
+curdir=`pwd`
diff --git a/Task/Execute-a-system-command/Make/execute-a-system-command-2.make b/Task/Execute-a-system-command/Make/execute-a-system-command-2.make
new file mode 100644
index 0000000000..83a5b38bb1
--- /dev/null
+++ b/Task/Execute-a-system-command/Make/execute-a-system-command-2.make
@@ -0,0 +1,2 @@
+mytarget:
+ cat foo | grep mytext
diff --git a/Task/Execute-a-system-command/Mathematica/execute-a-system-command.mathematica b/Task/Execute-a-system-command/Mathematica/execute-a-system-command.mathematica
new file mode 100644
index 0000000000..489958b641
--- /dev/null
+++ b/Task/Execute-a-system-command/Mathematica/execute-a-system-command.mathematica
@@ -0,0 +1 @@
+Run["ls"]
diff --git a/Task/Execute-a-system-command/Maxima/execute-a-system-command.maxima b/Task/Execute-a-system-command/Maxima/execute-a-system-command.maxima
new file mode 100644
index 0000000000..a2a19f8c0e
--- /dev/null
+++ b/Task/Execute-a-system-command/Maxima/execute-a-system-command.maxima
@@ -0,0 +1 @@
+system("dir > list.txt")$
diff --git a/Task/Execute-a-system-command/Mercury/execute-a-system-command.mercury b/Task/Execute-a-system-command/Mercury/execute-a-system-command.mercury
new file mode 100644
index 0000000000..2dd2c0f58f
--- /dev/null
+++ b/Task/Execute-a-system-command/Mercury/execute-a-system-command.mercury
@@ -0,0 +1,10 @@
+:- module execute_sys_cmd.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+ io.call_system("ls", _Result, !IO).
diff --git a/Task/Execute-a-system-command/Modula-2/execute-a-system-command.mod2 b/Task/Execute-a-system-command/Modula-2/execute-a-system-command.mod2
new file mode 100644
index 0000000000..121f4b4af2
--- /dev/null
+++ b/Task/Execute-a-system-command/Modula-2/execute-a-system-command.mod2
@@ -0,0 +1,34 @@
+MODULE tri;
+
+FROM SYSTEM IMPORT ADR;
+FROM SysLib IMPORT system;
+
+IMPORT TextIO, InOut, ASCII;
+
+VAR fd : TextIO.File;
+ ch : CHAR;
+
+PROCEDURE SystemCommand (VAR command : ARRAY OF CHAR) : BOOLEAN;
+
+BEGIN
+ IF system (ADR (command) ) = 0 THEN
+ RETURN TRUE
+ ELSE
+ RETURN FALSE
+ END
+END SystemCommand;
+
+BEGIN
+ IF SystemCommand ("ls -1 tri.mod | ") = TRUE THEN
+ InOut.WriteString ("No error reported.")
+ ELSE
+ InOut.WriteString ("Error reported!")
+ END;
+ LOOP
+ InOut.Read (ch);
+ InOut.Write (ch);
+ IF ch < ' ' THEN EXIT END
+ END;
+ InOut.WriteLn;
+ InOut.WriteBf
+END tri.
diff --git a/Task/Execute-a-system-command/Modula-3/execute-a-system-command.mod3 b/Task/Execute-a-system-command/Modula-3/execute-a-system-command.mod3
new file mode 100644
index 0000000000..c3e4069224
--- /dev/null
+++ b/Task/Execute-a-system-command/Modula-3/execute-a-system-command.mod3
@@ -0,0 +1,10 @@
+UNSAFE MODULE Exec EXPORTS Main;
+
+IMPORT Unix, M3toC;
+
+VAR command := M3toC.CopyTtoS("ls");
+
+BEGIN
+ EVAL Unix.system(command);
+ M3toC.FreeCopiedS(command);
+END Exec.
diff --git a/Task/Exponentiation-operator/Factor/exponentiation-operator-1.factor b/Task/Exponentiation-operator/Factor/exponentiation-operator-1.factor
new file mode 100644
index 0000000000..9f981d7388
--- /dev/null
+++ b/Task/Exponentiation-operator/Factor/exponentiation-operator-1.factor
@@ -0,0 +1,3 @@
+: pow ( f n -- f' )
+ dup 0 < [ abs pow recip ]
+ [ [ 1 ] 2dip swap [ * ] curry times ] if ;
diff --git a/Task/Exponentiation-operator/Factor/exponentiation-operator-2.factor b/Task/Exponentiation-operator/Factor/exponentiation-operator-2.factor
new file mode 100644
index 0000000000..1b15d68b66
--- /dev/null
+++ b/Task/Exponentiation-operator/Factor/exponentiation-operator-2.factor
@@ -0,0 +1,6 @@
+: pow ( f n -- f' )
+ {
+ { [ dup 0 < ] [ abs pow recip ] }
+ { [ dup 0 = ] [ 2drop 1 ] }
+ [ [ 2 mod 1 = swap 1 ? ] [ [ sq ] [ 2 /i ] bi* pow ] 2bi * ]
+ } cond ;
diff --git a/Task/Exponentiation-operator/Factor/exponentiation-operator-3.factor b/Task/Exponentiation-operator/Factor/exponentiation-operator-3.factor
new file mode 100644
index 0000000000..493835e558
--- /dev/null
+++ b/Task/Exponentiation-operator/Factor/exponentiation-operator-3.factor
@@ -0,0 +1,13 @@
+USING: combinators kernel math ;
+IN: test
+
+: (pow) ( f n -- f' )
+ [ dup even? ] [ [ sq ] [ 2 /i ] bi* ] while
+ dup 1 = [ drop ] [ dupd 1 - (pow) * ] if ;
+
+: pow ( f n -- f' )
+ {
+ { [ dup 0 < ] [ abs (pow) recip ] }
+ { [ dup 0 = ] [ 2drop 1 ] }
+ [ (pow) ]
+ } cond ;
diff --git a/Task/Exponentiation-operator/Factor/exponentiation-operator-4.factor b/Task/Exponentiation-operator/Factor/exponentiation-operator-4.factor
new file mode 100644
index 0000000000..0ffec3c5f7
--- /dev/null
+++ b/Task/Exponentiation-operator/Factor/exponentiation-operator-4.factor
@@ -0,0 +1,6 @@
+: (pow) ( f n -- f' )
+ [ 1 ] 2dip
+ [ dup 1 = ] [
+ dup even? [ [ sq ] [ 2 /i ] bi* ] [ [ [ * ] keep ] dip 1 - ] if
+ ] until
+ drop * ;
diff --git a/Task/Exponentiation-operator/GAP/exponentiation-operator.gap b/Task/Exponentiation-operator/GAP/exponentiation-operator.gap
new file mode 100644
index 0000000000..65a17aa725
--- /dev/null
+++ b/Task/Exponentiation-operator/GAP/exponentiation-operator.gap
@@ -0,0 +1,20 @@
+expon := function(a, n, one, mul)
+ local p;
+ p := one;
+ while n > 0 do
+ if IsOddInt(n) then
+ p := mul(a, p);
+ fi;
+ a := mul(a, a);
+ n := QuoInt(n, 2);
+ od;
+ return p;
+end;
+
+expon(2, 10, 1, \*);
+# 1024
+
+# a more creative use of exponentiation
+List([0 .. 31], n -> (1 - expon(0, n, 1, \-))/2);
+# [ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
+# 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 ]
diff --git a/Task/Exponentiation-operator/HicEst/exponentiation-operator.hicest b/Task/Exponentiation-operator/HicEst/exponentiation-operator.hicest
new file mode 100644
index 0000000000..5b88f17b32
--- /dev/null
+++ b/Task/Exponentiation-operator/HicEst/exponentiation-operator.hicest
@@ -0,0 +1,9 @@
+WRITE(Clipboard) pow(5, 3) ! 125
+WRITE(ClipBoard) pow(5.5, 7) ! 152243.5234
+
+FUNCTION pow(x, n)
+ pow = 1
+ DO i = 1, n
+ pow = pow * x
+ ENDDO
+END
diff --git a/Task/Exponentiation-operator/Icon/exponentiation-operator.icon b/Task/Exponentiation-operator/Icon/exponentiation-operator.icon
new file mode 100644
index 0000000000..cad1978c7d
--- /dev/null
+++ b/Task/Exponentiation-operator/Icon/exponentiation-operator.icon
@@ -0,0 +1,22 @@
+procedure main()
+bases := [5,5.]
+numbers := [0,2,2.,-1,3]
+every write("expon(",b := !bases,", ",x := !numbers,")=",(expon(b,x) | "failed") \ 1)
+end
+
+procedure expon(base,power)
+local op,res
+
+base := numeric(base) | runerror(102,base)
+power := power = integer(power) | runerr(101,power)
+
+if power = 0 then return 1
+else op := if power < 1 then
+ (base := real(base)) & "/" # force real base
+ else "*"
+
+res := 1
+every 1 to abs(power) do
+ res := op(res,base)
+return res
+end
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-1.j b/Task/Exponentiation-operator/J/exponentiation-operator-1.j
new file mode 100644
index 0000000000..8ad58e6641
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-1.j
@@ -0,0 +1,7 @@
+ exp =: */@:#~
+
+ 10 exp 3
+1000
+
+ 10 exp 0
+1
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-2.j b/Task/Exponentiation-operator/J/exponentiation-operator-2.j
new file mode 100644
index 0000000000..dcdbdb948d
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-2.j
@@ -0,0 +1,4 @@
+ exp =: *@:] %: */@:(#~|)
+
+ 10 exp _3
+0.001
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-3.j b/Task/Exponentiation-operator/J/exponentiation-operator-3.j
new file mode 100644
index 0000000000..0a8313694a
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-3.j
@@ -0,0 +1,6 @@
+ exp =: dyad def 'x *^:y 1'
+
+ 10 exp 3
+1000
+ 10 exp _3
+0.001
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-4.j b/Task/Exponentiation-operator/J/exponentiation-operator-4.j
new file mode 100644
index 0000000000..096afd7ae3
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-4.j
@@ -0,0 +1,4 @@
+ exp =: ^.^:_1
+
+ 81 exp 0.5
+9
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-5.j b/Task/Exponentiation-operator/J/exponentiation-operator-5.j
new file mode 100644
index 0000000000..c6eb4365a1
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-5.j
@@ -0,0 +1,4 @@
+ exp =: %:^:_1~
+
+ 81 exp 0.5
+9
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-6.j b/Task/Exponentiation-operator/J/exponentiation-operator-6.j
new file mode 100644
index 0000000000..3b5eee41c3
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-6.j
@@ -0,0 +1,6 @@
+ pi =: 3.14159265358979323846
+ e =: 2.71828182845904523536
+ i =: 2 %: _1 NB. Square root of -1
+
+ e^(pi*i)
+_1
diff --git a/Task/Exponentiation-operator/J/exponentiation-operator-7.j b/Task/Exponentiation-operator/J/exponentiation-operator-7.j
new file mode 100644
index 0000000000..64ddf68722
--- /dev/null
+++ b/Task/Exponentiation-operator/J/exponentiation-operator-7.j
@@ -0,0 +1,4 @@
+ exp =: %:^:_1~
+
+ e exp (pi*i)
+_1
diff --git a/Task/Exponentiation-operator/Liberty-BASIC/exponentiation-operator.liberty b/Task/Exponentiation-operator/Liberty-BASIC/exponentiation-operator.liberty
new file mode 100644
index 0000000000..d2bf5f244d
--- /dev/null
+++ b/Task/Exponentiation-operator/Liberty-BASIC/exponentiation-operator.liberty
@@ -0,0 +1,25 @@
+ print " 11^5 = ", floatPow( 11, 5 )
+ print " (-11)^5 = ", floatPow( -11, 5 )
+ print " 11^( -5) = ", floatPow( 11, -5 )
+ print " 3.1416^3 = ", floatPow( 3.1416, 3 )
+ print " 0^2 = ", floatPow( 0, 2 )
+ print " 2^0 = ", floatPow( 2, 0 )
+ print " -2^0 = ", floatPow( -2, 0 )
+
+ end
+
+ function floatPow( a, b)
+ if a <>0 then
+ m =1
+ if b =abs( b) then
+ for n =1 to b
+ m =m *a
+ next n
+ else
+ m =1 /floatPow( a, 0 - b) ' LB has no unitary minus operator.
+ end if
+ else
+ m =0
+ end if
+ floatPow =m
+ end function
diff --git a/Task/Exponentiation-operator/Logo/exponentiation-operator.logo b/Task/Exponentiation-operator/Logo/exponentiation-operator.logo
new file mode 100644
index 0000000000..71bdc0c425
--- /dev/null
+++ b/Task/Exponentiation-operator/Logo/exponentiation-operator.logo
@@ -0,0 +1,5 @@
+to int_power :n :m
+ if equal? 0 :m [output 1]
+ if equal? 0 modulo :m 2 [output int_power :n*:n :m/2]
+ output :n * int_power :n :m-1
+end
diff --git a/Task/Exponentiation-operator/Lucid/exponentiation-operator.lucid b/Task/Exponentiation-operator/Lucid/exponentiation-operator.lucid
new file mode 100644
index 0000000000..eea04aaa8c
--- /dev/null
+++ b/Task/Exponentiation-operator/Lucid/exponentiation-operator.lucid
@@ -0,0 +1,6 @@
+pow(n,x)
+ k = n fby k div 2;
+ p = x fby p*p;
+ y =1 fby if even(k) then y else y*p;
+ result y asa k eq 0;
+end
diff --git a/Task/Exponentiation-operator/M4/exponentiation-operator.m4 b/Task/Exponentiation-operator/M4/exponentiation-operator.m4
new file mode 100644
index 0000000000..e25b337724
--- /dev/null
+++ b/Task/Exponentiation-operator/M4/exponentiation-operator.m4
@@ -0,0 +1,2 @@
+define(`power',`ifelse($2,0,1,`eval($1*$0($1,decr($2)))')')
+power(2,10)
diff --git a/Task/Exponentiation-operator/Mathematica/exponentiation-operator-1.mathematica b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-1.mathematica
new file mode 100644
index 0000000000..abd4588bf1
--- /dev/null
+++ b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-1.mathematica
@@ -0,0 +1,2 @@
+exponentiation[x_,y_Integer]:=Which[y>0,Times@@ConstantArray[x,y],y==0,1,y<0,1/exponentiation[x,-y]]
+CirclePlus[x_,y_Integer]:=exponentiation[x,y]
diff --git a/Task/Exponentiation-operator/Mathematica/exponentiation-operator-2.mathematica b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-2.mathematica
new file mode 100644
index 0000000000..d6ef4d82d9
--- /dev/null
+++ b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-2.mathematica
@@ -0,0 +1,6 @@
+exponentiation[1.23,3]
+exponentiation[4,0]
+exponentiation[2.5,-2]
+1.23\[CirclePlus]3
+4\[CirclePlus]0
+2.5\[CirclePlus]-2
diff --git a/Task/Exponentiation-operator/Mathematica/exponentiation-operator-3.mathematica b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-3.mathematica
new file mode 100644
index 0000000000..51997df377
--- /dev/null
+++ b/Task/Exponentiation-operator/Mathematica/exponentiation-operator-3.mathematica
@@ -0,0 +1,6 @@
+1.86087
+1
+0.16
+1.86087
+1
+0.16
diff --git a/Task/Exponentiation-operator/Maxima/exponentiation-operator.maxima b/Task/Exponentiation-operator/Maxima/exponentiation-operator.maxima
new file mode 100644
index 0000000000..7e7769a70b
--- /dev/null
+++ b/Task/Exponentiation-operator/Maxima/exponentiation-operator.maxima
@@ -0,0 +1,17 @@
+"^^^"(a, n) := block(
+ [p: 1],
+ while n > 0 do (
+ if oddp(n) then p: p * a,
+ a: a * a,
+ n: quotient(n, 2)
+ ),
+ p
+)$
+
+infix("^^^")$
+
+2 ^^^ 10;
+1024
+
+2.5 ^^^ 10;
+9536.7431640625
diff --git a/Task/Exponentiation-operator/Modula-2/exponentiation-operator.mod2 b/Task/Exponentiation-operator/Modula-2/exponentiation-operator.mod2
new file mode 100644
index 0000000000..fd57825355
--- /dev/null
+++ b/Task/Exponentiation-operator/Modula-2/exponentiation-operator.mod2
@@ -0,0 +1,46 @@
+(* Library Interface *)
+DEFINITION MODULE Exponentiation;
+
+PROCEDURE IntExp(base, exp : INTEGER) : INTEGER;
+ (* Raises base to the power of exp and returns the result
+ both base and exp must be of type INTEGER *)
+
+PROCEDURE RealExp(base : REAL; exp : INTEGER) : REAL;
+ (* Raises base to the power of exp and returns the result
+ base must be of type REAL, exp of type INTEGER *)
+
+END Exponentiation.
+
+(* Library Implementation *)
+IMPLEMENTATION MODULE Exponentiation;
+
+PROCEDURE IntExp(base, exp : INTEGER) : INTEGER;
+ VAR
+ i, res : INTEGER;
+ BEGIN
+ res := 1;
+ FOR i := 1 TO exp DO
+ res := res * base;
+ END;
+ RETURN res;
+ END IntExp;
+
+PROCEDURE RealExp(base: REAL; exp: INTEGER) : REAL;
+ VAR
+ i : INTEGER;
+ res : REAL;
+ BEGIN
+ res := 1.0;
+ IF exp < 0 THEN
+ FOR i := exp TO -1 DO
+ res := res / base;
+ END;
+ ELSE (* exp >= 0 *)
+ FOR i := 1 TO exp DO
+ res := res * base;
+ END;
+ END;
+ RETURN res;
+ END RealExp;
+
+END Exponentiation.
diff --git a/Task/Exponentiation-operator/Modula-3/exponentiation-operator.mod3 b/Task/Exponentiation-operator/Modula-3/exponentiation-operator.mod3
new file mode 100644
index 0000000000..00086dd52e
--- /dev/null
+++ b/Task/Exponentiation-operator/Modula-3/exponentiation-operator.mod3
@@ -0,0 +1,32 @@
+MODULE Expt EXPORTS Main;
+
+IMPORT IO, Fmt;
+
+PROCEDURE IntExpt(arg, exp: INTEGER): INTEGER =
+ VAR result := 1;
+ BEGIN
+ FOR i := 1 TO exp DO
+ result := result * arg;
+ END;
+ RETURN result;
+ END IntExpt;
+
+PROCEDURE RealExpt(arg: REAL; exp: INTEGER): REAL =
+ VAR result := 1.0;
+ BEGIN
+ IF exp < 0 THEN
+ FOR i := exp TO -1 DO
+ result := result / arg;
+ END;
+ ELSE
+ FOR i := 1 TO exp DO
+ result := result * arg;
+ END;
+ END;
+ RETURN result;
+ END RealExpt;
+
+BEGIN
+ IO.Put("2 ^ 4 = " & Fmt.Int(IntExpt(2, 4)) & "\n");
+ IO.Put("2.5 ^ 4 = " & Fmt.Real(RealExpt(2.5, 4)) & "\n");
+END Expt.
diff --git a/Task/Extend-your-language/Factor/extend-your-language.factor b/Task/Extend-your-language/Factor/extend-your-language.factor
new file mode 100644
index 0000000000..87da9b2683
--- /dev/null
+++ b/Task/Extend-your-language/Factor/extend-your-language.factor
@@ -0,0 +1,4 @@
+( scratchpad ) : 2ifte ( ..a ?0 ?1 quot0: ( ..a -- ..b ) quot1: ( ..a -- ..b ) quot2: ( ..a -- ..b ) quot3: ( ..a -- ..b ) -- ..b )
+[ [ if ] curry curry ] 2bi@ if ; inline
+( scratchpad ) 3 [ 0 > ] [ even? ] bi [ 0 ] [ 1 ] [ 2 ] [ 3 ] 2ifte .
+2
diff --git a/Task/Extend-your-language/Icon/extend-your-language.icon b/Task/Extend-your-language/Icon/extend-your-language.icon
new file mode 100644
index 0000000000..47e5805dcc
--- /dev/null
+++ b/Task/Extend-your-language/Icon/extend-your-language.icon
@@ -0,0 +1,20 @@
+procedure main(A)
+ if2 { (A[1] = A[2]), (A[3] = A[4]), # Use PDCO with all three else clauses
+ write("1: both true"),
+ write("1: only first true"),
+ write("1: only second true"),
+ write("1: neither true")
+ }
+ if2 { (A[1] = A[2]), (A[3] = A[4]), # Use same PDCO with only one else clause
+ write("2: both true"),
+ write("2: only first true"),
+ }
+end
+
+procedure if2(A) # The double-conditional PDCO
+ suspend if @A[1] then
+ if @A[2] then |@A[3] # Run-err if missing 'then' clause
+ else @\A[4] # (all else clauses are optional)
+ else if @A[2] then |@\A[5]
+ else |@\A[6]
+end
diff --git a/Task/Extend-your-language/Inform-7/extend-your-language-1.inf b/Task/Extend-your-language/Inform-7/extend-your-language-1.inf
new file mode 100644
index 0000000000..b441cce13c
--- /dev/null
+++ b/Task/Extend-your-language/Inform-7/extend-your-language-1.inf
@@ -0,0 +1,4 @@
+To if2 (c1 - condition) and-or (c2 - condition) begin -- end: (- switch (({c1})*2 + ({c2})) { 3: do -).
+To else1 -- in if2: (- } until (1); 2: do { -).
+To else2 -- in if2: (- } until (1); 1: do { -).
+To else0 -- in if2: (- } until (1); 0: -).
diff --git a/Task/Extend-your-language/Inform-7/extend-your-language-2.inf b/Task/Extend-your-language/Inform-7/extend-your-language-2.inf
new file mode 100644
index 0000000000..35bdd519e4
--- /dev/null
+++ b/Task/Extend-your-language/Inform-7/extend-your-language-2.inf
@@ -0,0 +1,12 @@
+Home is a room.
+
+When play begins:
+ if2 (the player is in Home) and-or (the player is a person) begin;
+ say "both";
+ else1;
+ say "only 1";
+ else2;
+ say "only 2";
+ else0;
+ say "neither";
+ end if2.
diff --git a/Task/Extend-your-language/Inform-7/extend-your-language-3.inf b/Task/Extend-your-language/Inform-7/extend-your-language-3.inf
new file mode 100644
index 0000000000..92094194cd
--- /dev/null
+++ b/Task/Extend-your-language/Inform-7/extend-your-language-3.inf
@@ -0,0 +1,6 @@
+To say if2 (c1 - condition) and-or (c2 - condition) -- beginning if2:
+ (- switch (({c1})*2 + ({c2})) { 3: -).
+To say else1 -- continuing if2: (- 2: -).
+To say else2 -- continuing if2: (- 1: -).
+To say else0 -- continuing if2: (- 0: -).
+To say end if2 -- ending if2: (- } -).
diff --git a/Task/Extend-your-language/Inform-7/extend-your-language-4.inf b/Task/Extend-your-language/Inform-7/extend-your-language-4.inf
new file mode 100644
index 0000000000..3223937727
--- /dev/null
+++ b/Task/Extend-your-language/Inform-7/extend-your-language-4.inf
@@ -0,0 +1,4 @@
+Home is a room.
+
+When play begins:
+ say "[if2 the player is not in Home and-or the player is not a person]both[else1]only 1[else2]only 2[else0]neither[end if2]".
diff --git a/Task/Extend-your-language/J/extend-your-language-1.j b/Task/Extend-your-language/J/extend-your-language-1.j
new file mode 100644
index 0000000000..aec6c53623
--- /dev/null
+++ b/Task/Extend-your-language/J/extend-your-language-1.j
@@ -0,0 +1,4 @@
+if2=: 2 :0
+ '`b1 b2'=. n
+ m@.(b1 + 2 * b2) f.
+)
diff --git a/Task/Extend-your-language/J/extend-your-language-2.j b/Task/Extend-your-language/J/extend-your-language-2.j
new file mode 100644
index 0000000000..0d02f139d6
--- /dev/null
+++ b/Task/Extend-your-language/J/extend-your-language-2.j
@@ -0,0 +1,14 @@
+f0=: [: smoutput 'neither option: ' , ":
+f1=: [: smoutput 'first option: ' , ":
+f2=: [: smoutput 'second option: ' , ":
+f3=: [: smoutput 'both options: ' , ":
+
+isprime=: 1&p:
+iseven=: 0 = 2&|
+
+ f0`f1`f2`f3 if2 (isprime`iseven)"0 i.5
+second option: 0
+neither option: 1
+both options: 2
+first option: 3
+second option: 4
diff --git a/Task/Extend-your-language/Mathematica/extend-your-language.mathematica b/Task/Extend-your-language/Mathematica/extend-your-language.mathematica
new file mode 100644
index 0000000000..e0bc0bd27c
--- /dev/null
+++ b/Task/Extend-your-language/Mathematica/extend-your-language.mathematica
@@ -0,0 +1,5 @@
+if2[c1_,c2_]:=Which[
+ c1&&c2, bothConditionsAreTrue[],
+ c1, firstConditionIsTrue[],
+ c2, secondConditionIsTrue[],
+ True,noConditionIsTrue]
diff --git a/Task/Extreme-floating-point-values/Groovy/extreme-floating-point-values.groovy b/Task/Extreme-floating-point-values/Groovy/extreme-floating-point-values.groovy
new file mode 100644
index 0000000000..2f9b1d2498
--- /dev/null
+++ b/Task/Extreme-floating-point-values/Groovy/extreme-floating-point-values.groovy
@@ -0,0 +1,13 @@
+def negInf = -1.0d / 0.0d; //also Double.NEGATIVE_INFINITY
+def inf = 1.0d / 0.0d; //also Double.POSITIVE_INFINITY
+def nan = 0.0d / 0.0d; //also Double.NaN
+def negZero = -2.0d / inf;
+
+println(" Negative inf: " + negInf);
+println(" Positive inf: " + inf);
+println(" NaN: " + nan);
+println(" Negative 0: " + negZero);
+println(" inf + -inf: " + (inf + negInf));
+println(" 0 * NaN: " + (0 * nan));
+println(" NaN == NaN: " + (nan == nan));
+println("NaN equals NaN: " + (nan.equals(nan)));
diff --git a/Task/Extreme-floating-point-values/J/extreme-floating-point-values-1.j b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-1.j
new file mode 100644
index 0000000000..73147cab41
--- /dev/null
+++ b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-1.j
@@ -0,0 +1,4 @@
+ Inf=: _
+ NegInf=: __
+ NB. Negative zero cannot be represented in J.
+ NaN=. _.
diff --git a/Task/Extreme-floating-point-values/J/extreme-floating-point-values-2.j b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-2.j
new file mode 100644
index 0000000000..59b4129e2d
--- /dev/null
+++ b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-2.j
@@ -0,0 +1,15 @@
+ (1 % 0) , (_1 % 0)
+_ __
+ (1e234 * 1e234) , (_1e234 * 1e234)
+_ __
+ _ + __ NB. generates NaN error, rather than NaN
+|NaN error
+| _ +__
+
+ _ - _ NB. generates NaN error, rather than NaN
+|NaN error
+| _ -_
+ %_
+0
+ %__ NB. Under the covers, the reciprocal of NegInf produces NegZero, but this fact isn't exposed to the user, who just sees zero
+0
diff --git a/Task/Extreme-floating-point-values/J/extreme-floating-point-values-3.j b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-3.j
new file mode 100644
index 0000000000..1b4c451654
--- /dev/null
+++ b/Task/Extreme-floating-point-values/J/extreme-floating-point-values-3.j
@@ -0,0 +1,8 @@
+ _ + _
+_
+ __ + __
+__
+ Inf + 0
+_
+ NegInf * 0
+0
diff --git a/Task/Extreme-floating-point-values/MUMPS/extreme-floating-point-values.mumps b/Task/Extreme-floating-point-values/MUMPS/extreme-floating-point-values.mumps
new file mode 100644
index 0000000000..8419457489
--- /dev/null
+++ b/Task/Extreme-floating-point-values/MUMPS/extreme-floating-point-values.mumps
@@ -0,0 +1,15 @@
+EXTREMES
+ NEW INF,NINF,ZERO,NOTNUM,NEGZERO
+ SET INF=$DOUBLE(3.0E310),NINF=$DOUBLE(-3.0E310),ZERO=$DOUBLE(0),NOTNUM=$DOUBLE(INF-INF),NEGZERO=$DOUBLE(ZERO*-1)
+ WRITE "Infinity: ",INF,!
+ WRITE "Infinity ",$SELECT($ISVALIDNUM(INF):"is a number",1:"is not a number"),!
+ WRITE "Negative Infinity: ",NINF,!
+ WRITE "Negative Infinity ",$SELECT($ISVALIDNUM(NINF):"is a number",1:"is not a number"),!
+ WRITE "Zero: ",ZERO,!
+ WRITE "Zero ",$SELECT($ISVALIDNUM(ZERO):"is a number",1:"is not a number"),!
+ WRITE "Negative Zero: ",NEGZERO,!
+ WRITE "Negative Zero ",$SELECT($ISVALIDNUM(NEGZERO):"is a number",1:"is not a number"),!
+ WRITE "Not a Number: ",NOTNUM,!
+ WRITE "Not a Number ",$SELECT($ISVALIDNUM(NOTNUM):"is a number",1:"is not a number"),!
+ KILL INF,NINF,ZERO,NONNUM,NEGZERO
+ QUIT
diff --git a/Task/Extreme-floating-point-values/Mathematica/extreme-floating-point-values.mathematica b/Task/Extreme-floating-point-values/Mathematica/extreme-floating-point-values.mathematica
new file mode 100644
index 0000000000..f57324bafd
--- /dev/null
+++ b/Task/Extreme-floating-point-values/Mathematica/extreme-floating-point-values.mathematica
@@ -0,0 +1,9 @@
+Column@{ReleaseHold[
+ Function[expression,
+ Row@{HoldForm@InputForm@expression, " = ", Quiet@expression},
+ HoldAll] /@
+ Hold[1./0., 0./0., Limit[-Log[x], x -> 0], Limit[Log[x], x -> 0],
+ Infinity + 1, Infinity + Infinity, 2 Infinity,
+ Infinity - Infinity, 0 Infinity, ComplexInfinity + 1,
+ ComplexInfinity + ComplexInfinity, 2 ComplexInfinity,
+ 0 ComplexInfinity, Indeterminate + 1, 0 Indeterminate]]}
diff --git a/Task/Factorial/0815/factorial.0815 b/Task/Factorial/0815/factorial.0815
new file mode 100644
index 0000000000..cf7a0bd226
--- /dev/null
+++ b/Task/Factorial/0815/factorial.0815
@@ -0,0 +1,11 @@
+}:r: Start reader loop.
+ |~ Read n,
+ #:end: if n is 0 terminates
+ >= enqueue it as the initial product, reposition.
+ }:f: Start factorial loop.
+ x<:1:x- Decrement n.
+ {=*> Dequeue product, position n, multiply, update product.
+ ^:f:
+ {+% Dequeue incidental 0, add to get Y into Z, output fac(n).
+ <:a:~$ Output a newline.
+^:r:
diff --git a/Task/Factorial/0DESCRIPTION b/Task/Factorial/0DESCRIPTION
new file mode 100644
index 0000000000..9b7a896e69
--- /dev/null
+++ b/Task/Factorial/0DESCRIPTION
@@ -0,0 +1,3 @@
+The '''Factorial Function''' of a positive integer, ''n'', is defined as the product of the sequence ''n'', ''n''-1, ''n''-2, ...1 and the factorial of zero, 0, is [[wp:Factorial#Definition|defined]] as being 1.
+
+Write a function to return the factorial of a number. Solutions can be iterative or recursive. Support for trapping negative n errors is optional.
diff --git a/Task/Factorial/1META.yaml b/Task/Factorial/1META.yaml
new file mode 100644
index 0000000000..f759feccfd
--- /dev/null
+++ b/Task/Factorial/1META.yaml
@@ -0,0 +1,7 @@
+---
+category:
+- Recursion
+- Memoization
+- Classic CS problems and programs
+- Arithmetic
+note: Arithmetic operations
diff --git a/Task/Factorial/ABAP/factorial-1.abap b/Task/Factorial/ABAP/factorial-1.abap
new file mode 100644
index 0000000000..585da9d32e
--- /dev/null
+++ b/Task/Factorial/ABAP/factorial-1.abap
@@ -0,0 +1,8 @@
+form factorial using iv_val type i.
+ data: lv_res type i value 1.
+ do iv_val times.
+ multiply lv_res by sy-index.
+ enddo.
+
+ iv_val = lv_res.
+endform.
diff --git a/Task/Factorial/ABAP/factorial-2.abap b/Task/Factorial/ABAP/factorial-2.abap
new file mode 100644
index 0000000000..f26b6b13cc
--- /dev/null
+++ b/Task/Factorial/ABAP/factorial-2.abap
@@ -0,0 +1,11 @@
+form fac_rec using iv_val type i.
+ data: lv_temp type i.
+
+ if iv_val = 0.
+ iv_val = 1.
+ else.
+ lv_temp = iv_val - 1.
+ perform fac_rec using lv_temp.
+ multiply iv_val by lv_temp.
+ endif.
+endform.
diff --git a/Task/Factorial/ALGOL-68/factorial-1.alg b/Task/Factorial/ALGOL-68/factorial-1.alg
new file mode 100644
index 0000000000..170a8c2633
--- /dev/null
+++ b/Task/Factorial/ALGOL-68/factorial-1.alg
@@ -0,0 +1,5 @@
+PROC factorial = (INT upb n)LONG LONG INT:(
+ LONG LONG INT z := 1;
+ FOR n TO upb n DO z *:= n OD;
+ z
+); ~
diff --git a/Task/Factorial/ALGOL-68/factorial-2.alg b/Task/Factorial/ALGOL-68/factorial-2.alg
new file mode 100644
index 0000000000..191fe07cfb
--- /dev/null
+++ b/Task/Factorial/ALGOL-68/factorial-2.alg
@@ -0,0 +1,30 @@
+INT g = 7;
+[]REAL p = []REAL(0.99999999999980993, 676.5203681218851, -1259.1392167224028,
+ 771.32342877765313, -176.61502916214059, 12.507343278686905,
+ -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7)[@0];
+
+PROC complex gamma = (COMPL in z)COMPL: (
+ # Reflection formula #
+ COMPL z := in z;
+ IF re OF z < 0.5 THEN
+ pi / (complex sin(pi*z)*complex gamma(1-z))
+ ELSE
+ z -:= 1;
+ COMPL x := p[0];
+ FOR i TO g+1 DO x +:= p[i]/(z+i) OD;
+ COMPL t := z + g + 0.5;
+ complex sqrt(2*pi) * t**(z+0.5) * complex exp(-t) * x
+ FI
+);
+
+OP ** = (COMPL z, p)COMPL: ( z=0|0|complex exp(complex ln(z)*p) );
+PROC factorial = (COMPL n)COMPL: complex gamma(n+1);
+
+FORMAT compl fmt = $g(-16, 8)"⊥"g(-10, 8)$;
+
+test:(
+ printf(($q"factorial(-0.5)**2="f(compl fmt)l$, factorial(-0.5)**2));
+ FOR i TO 9 DO
+ printf(($q"factorial("d")="f(compl fmt)l$, i, factorial(i)))
+ OD
+)
diff --git a/Task/Factorial/ALGOL-68/factorial-3.alg b/Task/Factorial/ALGOL-68/factorial-3.alg
new file mode 100644
index 0000000000..c9c3e54dd2
--- /dev/null
+++ b/Task/Factorial/ALGOL-68/factorial-3.alg
@@ -0,0 +1,7 @@
+PROC factorial = (INT n)LONG LONG INT:
+ CASE n+1 IN
+ 1,1,2,6,24,120,720 # a brief lookup #
+ OUT
+ n*factorial(n-1)
+ ESAC
+; ~
diff --git a/Task/Factorial/AWK/factorial-1.awk b/Task/Factorial/AWK/factorial-1.awk
new file mode 100644
index 0000000000..e94f90a94c
--- /dev/null
+++ b/Task/Factorial/AWK/factorial-1.awk
@@ -0,0 +1,5 @@
+function fact_r(n)
+{
+ if ( n <= 1 ) return 1;
+ return n*fact_r(n-1);
+}
diff --git a/Task/Factorial/AWK/factorial-2.awk b/Task/Factorial/AWK/factorial-2.awk
new file mode 100644
index 0000000000..f09705e617
--- /dev/null
+++ b/Task/Factorial/AWK/factorial-2.awk
@@ -0,0 +1,9 @@
+function fact(n)
+{
+ if ( n < 1 ) return 1;
+ r = 1
+ for(m = 2; m <= n; m++) {
+ r *= m;
+ }
+ return r
+}
diff --git a/Task/Factorial/ActionScript/factorial-1.as b/Task/Factorial/ActionScript/factorial-1.as
new file mode 100644
index 0000000000..e20a5a6452
--- /dev/null
+++ b/Task/Factorial/ActionScript/factorial-1.as
@@ -0,0 +1,11 @@
+public static function factorial(n:int):int
+{
+ if (n < 0)
+ return 0;
+
+ var fact:int = 1;
+ for (var i:int = 1; i <= n; i++)
+ fact *= i;
+
+ return fact;
+}
diff --git a/Task/Factorial/ActionScript/factorial-2.as b/Task/Factorial/ActionScript/factorial-2.as
new file mode 100644
index 0000000000..d73ac79c27
--- /dev/null
+++ b/Task/Factorial/ActionScript/factorial-2.as
@@ -0,0 +1,10 @@
+public static function factorial(n:int):int
+{
+ if (n < 0)
+ return 0;
+
+ if (n == 0)
+ return 1;
+
+ return n * factorial(n - 1);
+}
diff --git a/Task/Factorial/Ada/factorial-1.ada b/Task/Factorial/Ada/factorial-1.ada
new file mode 100644
index 0000000000..96e1766756
--- /dev/null
+++ b/Task/Factorial/Ada/factorial-1.ada
@@ -0,0 +1,9 @@
+function Factorial (N : Positive) return Positive is
+ Result : Positive := N;
+ Counter : Natural := N - 1;
+begin
+ for I in reverse 1..Counter loop
+ Result := Result * I;
+ end loop;
+ return Result;
+end Factorial;
diff --git a/Task/Factorial/Ada/factorial-2.ada b/Task/Factorial/Ada/factorial-2.ada
new file mode 100644
index 0000000000..4891867ed4
--- /dev/null
+++ b/Task/Factorial/Ada/factorial-2.ada
@@ -0,0 +1,8 @@
+function Factorial(N : Positive) return Positive is
+ Result : Positive := 1;
+begin
+ if N > 1 then
+ Result := N * Factorial(N - 1);
+ end if;
+ return Result;
+end Factorial;
diff --git a/Task/Factorial/Ada/factorial-3.ada b/Task/Factorial/Ada/factorial-3.ada
new file mode 100644
index 0000000000..a0b5d00151
--- /dev/null
+++ b/Task/Factorial/Ada/factorial-3.ada
@@ -0,0 +1,62 @@
+with Ada.Numerics.Generic_Complex_Types;
+with Ada.Numerics.Generic_Complex_Elementary_Functions;
+with Ada.Numerics.Generic_Elementary_Functions;
+with Ada.Text_IO.Complex_Io;
+with Ada.Text_Io; use Ada.Text_Io;
+
+procedure Factorial_Numeric_Approximation is
+ type Real is digits 15;
+ package Complex_Pck is new Ada.Numerics.Generic_Complex_Types(Real);
+ use Complex_Pck;
+ package Complex_Io is new Ada.Text_Io.Complex_Io(Complex_Pck);
+ use Complex_IO;
+ package Cmplx_Elem_Funcs is new Ada.Numerics.Generic_Complex_Elementary_Functions(Complex_Pck);
+ use Cmplx_Elem_Funcs;
+
+ function Gamma(X : Complex) return Complex is
+ package Elem_Funcs is new Ada.Numerics.Generic_Elementary_Functions(Real);
+ use Elem_Funcs;
+ use Ada.Numerics;
+ -- Coefficients used by the GNU Scientific Library
+ G : Natural := 7;
+ P : constant array (Natural range 0..G + 1) of Real := (
+ 0.99999999999980993, 676.5203681218851, -1259.1392167224028,
+ 771.32342877765313, -176.61502916214059, 12.507343278686905,
+ -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7);
+ Z : Complex := X;
+ Cx : Complex;
+ Ct : Complex;
+ begin
+ if Re(Z) < 0.5 then
+ return Pi / (Sin(Pi * Z) * Gamma(1.0 - Z));
+ else
+ Z := Z - 1.0;
+ Set_Re(Cx, P(0));
+ Set_Im(Cx, 0.0);
+ for I in 1..P'Last loop
+ Cx := Cx + (P(I) / (Z + Real(I)));
+ end loop;
+ Ct := Z + Real(G) + 0.5;
+ return Sqrt(2.0 * Pi) * Ct**(Z + 0.5) * Exp(-Ct) * Cx;
+ end if;
+ end Gamma;
+
+ function Factorial(N : Complex) return Complex is
+ begin
+ return Gamma(N + 1.0);
+ end Factorial;
+ Arg : Complex;
+begin
+ Put("factorial(-0.5)**2.0 = ");
+ Set_Re(Arg, -0.5);
+ Set_Im(Arg, 0.0);
+ Put(Item => Factorial(Arg) **2.0, Fore => 1, Aft => 8, Exp => 0);
+ New_Line;
+ for I in 0..9 loop
+ Set_Re(Arg, Real(I));
+ Set_Im(Arg, 0.0);
+ Put("factorial(" & Integer'Image(I) & ") = ");
+ Put(Item => Factorial(Arg), Fore => 6, Aft => 8, Exp => 0);
+ New_Line;
+ end loop;
+end Factorial_Numeric_Approximation;
diff --git a/Task/Factorial/Aime/factorial.aime b/Task/Factorial/Aime/factorial.aime
new file mode 100644
index 0000000000..2ac43df77b
--- /dev/null
+++ b/Task/Factorial/Aime/factorial.aime
@@ -0,0 +1,14 @@
+integer
+factorial(integer n)
+{
+ integer i, result;
+
+ result = 1;
+ i = 1;
+ while (i < n) {
+ i += 1;
+ result *= i;
+ }
+
+ return result;
+}
diff --git a/Task/Factorial/AmigaE/factorial-1.amiga b/Task/Factorial/AmigaE/factorial-1.amiga
new file mode 100644
index 0000000000..5bba6b4f93
--- /dev/null
+++ b/Task/Factorial/AmigaE/factorial-1.amiga
@@ -0,0 +1,5 @@
+PROC fact(x) IS IF x>=2 THEN x*fact(x-1) ELSE 1
+
+PROC main()
+ WriteF('5! = \d\n', fact(5))
+ENDPROC
diff --git a/Task/Factorial/AmigaE/factorial-2.amiga b/Task/Factorial/AmigaE/factorial-2.amiga
new file mode 100644
index 0000000000..b45960843f
--- /dev/null
+++ b/Task/Factorial/AmigaE/factorial-2.amiga
@@ -0,0 +1,6 @@
+PROC fact(x)
+ DEF r, y
+ IF x < 2 THEN RETURN 1
+ r := 1; y := x;
+ FOR x := 2 TO y DO r := r * x
+ENDPROC r
diff --git a/Task/Factorial/AppleScript/factorial-1.applescript b/Task/Factorial/AppleScript/factorial-1.applescript
new file mode 100644
index 0000000000..29a1d8971a
--- /dev/null
+++ b/Task/Factorial/AppleScript/factorial-1.applescript
@@ -0,0 +1,8 @@
+on factorial(x)
+ if x < 0 then return 0
+ set R to 1
+ repeat while x > 1
+ set {R, x} to {R * x, x - 1}
+ end repeat
+ return R
+end factorial
diff --git a/Task/Factorial/AppleScript/factorial-2.applescript b/Task/Factorial/AppleScript/factorial-2.applescript
new file mode 100644
index 0000000000..18f0a0568c
--- /dev/null
+++ b/Task/Factorial/AppleScript/factorial-2.applescript
@@ -0,0 +1,5 @@
+on factorial(x)
+ if x < 0 then return 0
+ if x > 1 then return x * (my factorial(x - 1))
+ return 1
+end factorial
diff --git a/Task/Factorial/AutoHotkey/factorial-1.ahk b/Task/Factorial/AutoHotkey/factorial-1.ahk
new file mode 100644
index 0000000000..2da6100d04
--- /dev/null
+++ b/Task/Factorial/AutoHotkey/factorial-1.ahk
@@ -0,0 +1,9 @@
+MsgBox % factorial(4)
+
+factorial(n)
+{
+ result := 1
+ Loop, % n
+ result *= A_Index
+ Return result
+}
diff --git a/Task/Factorial/AutoHotkey/factorial-2.ahk b/Task/Factorial/AutoHotkey/factorial-2.ahk
new file mode 100644
index 0000000000..680b95d900
--- /dev/null
+++ b/Task/Factorial/AutoHotkey/factorial-2.ahk
@@ -0,0 +1,6 @@
+MsgBox % factorial(4)
+
+factorial(n)
+{
+ return n > 1 ? n-- * factorial(n) : 1
+}
diff --git a/Task/Factorial/AutoIt/factorial-1.autoit b/Task/Factorial/AutoIt/factorial-1.autoit
new file mode 100644
index 0000000000..db1aad047b
--- /dev/null
+++ b/Task/Factorial/AutoIt/factorial-1.autoit
@@ -0,0 +1,12 @@
+;AutoIt Version: 3.2.10.0
+MsgBox (0,"Factorial",factorial(6))
+Func factorial($int)
+ If $int < 0 Then
+ Return 0
+ EndIf
+ $fact = 1
+ For $i = 1 To $int
+ $fact = $fact * $i
+ Next
+ Return $fact
+EndFunc
diff --git a/Task/Factorial/AutoIt/factorial-2.autoit b/Task/Factorial/AutoIt/factorial-2.autoit
new file mode 100644
index 0000000000..21e756fb1c
--- /dev/null
+++ b/Task/Factorial/AutoIt/factorial-2.autoit
@@ -0,0 +1,10 @@
+;AutoIt Version: 3.2.10.0
+MsgBox (0,"Factorial",factorial(6))
+Func factorial($int)
+ if $int < 0 Then
+ return 0
+ Elseif $int == 0 Then
+ return 1
+ EndIf
+ return $int * factorial($int - 1)
+EndFunc
diff --git a/Task/Factorial/BASIC/factorial-1.bas b/Task/Factorial/BASIC/factorial-1.bas
new file mode 100644
index 0000000000..d042027a50
--- /dev/null
+++ b/Task/Factorial/BASIC/factorial-1.bas
@@ -0,0 +1,8 @@
+FUNCTION factorial (n AS Integer) AS Integer
+ DIM f AS Integer, i AS Integer
+ f = 1
+ FOR i = 2 TO n
+ f = f*i
+ NEXT i
+ factorial = f
+END FUNCTION
diff --git a/Task/Factorial/BASIC/factorial-2.bas b/Task/Factorial/BASIC/factorial-2.bas
new file mode 100644
index 0000000000..0550090d6a
--- /dev/null
+++ b/Task/Factorial/BASIC/factorial-2.bas
@@ -0,0 +1,7 @@
+FUNCTION factorial (n AS Integer) AS Integer
+ IF n < 2 THEN
+ factorial = 1
+ ELSE
+ factorial = n * factorial(n-1)
+ END IF
+END FUNCTION
diff --git a/Task/Factorial/BASIC256/factorial.basic256 b/Task/Factorial/BASIC256/factorial.basic256
new file mode 100644
index 0000000000..f4a959798a
--- /dev/null
+++ b/Task/Factorial/BASIC256/factorial.basic256
@@ -0,0 +1,8 @@
+function factorial(n)
+ factorial = 1
+ if n>0 then
+ for p=1 to n
+ factorial *= p
+ next p
+ end if
+end function
diff --git a/Task/Factorial/BBC-BASIC/factorial.bbc b/Task/Factorial/BBC-BASIC/factorial.bbc
new file mode 100644
index 0000000000..fc1a52a96a
--- /dev/null
+++ b/Task/Factorial/BBC-BASIC/factorial.bbc
@@ -0,0 +1,8 @@
+ *FLOAT64
+ @% = &1010
+
+ PRINT FNfactorial(18)
+ END
+
+ DEF FNfactorial(n)
+ IF n <= 1 THEN = 1 ELSE = n * FNfactorial(n-1)
diff --git a/Task/Factorial/Babel/factorial.pb b/Task/Factorial/Babel/factorial.pb
new file mode 100644
index 0000000000..f02ae2a0fc
--- /dev/null
+++ b/Task/Factorial/Babel/factorial.pb
@@ -0,0 +1,16 @@
+main:
+ { argv 0 th $d
+ fac
+ %d cr << }
+
+fac!:
+ { dup zero?
+ { dup one?
+ { cp 1 - fac * }
+ { zap 1 }
+ if }
+ { zap 1 }
+ if }
+
+one?! : { 1 = }
+zero?!: { 0 = }
diff --git a/Task/Factorial/Batch-File/factorial.bat b/Task/Factorial/Batch-File/factorial.bat
new file mode 100644
index 0000000000..f7fe9e8010
--- /dev/null
+++ b/Task/Factorial/Batch-File/factorial.bat
@@ -0,0 +1,9 @@
+@echo off
+set /p x=
+set /a fs=%x%-1
+set y=%x%
+FOR /L %%a IN (%fs%, -1, 1) DO SET /a y*=%%a
+if %x% EQU 0 set y=1
+echo %y%
+pause
+exit
diff --git a/Task/Factorial/Befunge/factorial.bf b/Task/Factorial/Befunge/factorial.bf
new file mode 100644
index 0000000000..223963ac13
--- /dev/null
+++ b/Task/Factorial/Befunge/factorial.bf
@@ -0,0 +1,3 @@
+&1\> :v v *<
+ ^-1:_$>\:|
+ @.$<
diff --git a/Task/Factorial/Bracmat/factorial-1.bracmat b/Task/Factorial/Bracmat/factorial-1.bracmat
new file mode 100644
index 0000000000..273c5443ab
--- /dev/null
+++ b/Task/Factorial/Bracmat/factorial-1.bracmat
@@ -0,0 +1,27 @@
+ (
+ =
+ . !arg:0&1
+ | !arg
+ * ( (
+ = r
+ . !arg:?r
+ &
+ ' (
+ . !arg:0&1
+ | !arg*(($r)$($r))$(!arg+-1)
+ )
+ )
+ $ (
+ = r
+ . !arg:?r
+ &
+ ' (
+ . !arg:0&1
+ | !arg*(($r)$($r))$(!arg+-1)
+ )
+ )
+ )
+ $ (!arg+-1)
+ )
+ $ 10
+ : 3628800
diff --git a/Task/Factorial/Bracmat/factorial-2.bracmat b/Task/Factorial/Bracmat/factorial-2.bracmat
new file mode 100644
index 0000000000..4f27da9d74
--- /dev/null
+++ b/Task/Factorial/Bracmat/factorial-2.bracmat
@@ -0,0 +1,4 @@
+ ( (=(r.!arg:?r&'(.!arg:0&1|!arg*(($r)$($r))$(!arg+-1)))):?g
+ & (!g$!g):?f
+ & !f$10
+ )
diff --git a/Task/Factorial/Bracmat/factorial-3.bracmat b/Task/Factorial/Bracmat/factorial-3.bracmat
new file mode 100644
index 0000000000..56d06abcf2
--- /dev/null
+++ b/Task/Factorial/Bracmat/factorial-3.bracmat
@@ -0,0 +1,7 @@
+(factorial=
+ r
+. !arg:?r
+ & whl
+ ' (!arg:>1&(!arg+-1:?arg)*!r:?r)
+ & !r
+);
diff --git a/Task/Factorial/Brainf---/factorial.bf b/Task/Factorial/Brainf---/factorial.bf
new file mode 100644
index 0000000000..790e985d3f
--- /dev/null
+++ b/Task/Factorial/Brainf---/factorial.bf
@@ -0,0 +1,4 @@
+>++++++++++>>>+>+[>>>+[-[<<<<<[+<<<<<]>>[[-]>[<<+>+>-]<[>+<-]<[>+<-[>+<-[>
++<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>>>>+>+<<<<<<-[>+<-]]]]]]]]]]]>[<+>-
+]+>>>>>]<<<<<[<<<<<]>>>>>>>[>>>>>]++[-<<<<<]>>>>>>-]+>>>>>]<[>++<-]<<<<[<[
+>+<-]<<<<]>>[->[-]++++++[<++++++++>-]>>>>]<<<<<[<[>+>+<<-]>.<<<<<]>.>>>>]
diff --git a/Task/Factorial/Brat/factorial.brat b/Task/Factorial/Brat/factorial.brat
new file mode 100644
index 0000000000..cb4f2d70b7
--- /dev/null
+++ b/Task/Factorial/Brat/factorial.brat
@@ -0,0 +1,3 @@
+factorial = { x |
+ true? x == 0 1 { x * factorial(x - 1)}
+}
diff --git a/Task/Factorial/Burlesque/factorial-1.blq b/Task/Factorial/Burlesque/factorial-1.blq
new file mode 100644
index 0000000000..f06b1a0aa3
--- /dev/null
+++ b/Task/Factorial/Burlesque/factorial-1.blq
@@ -0,0 +1,2 @@
+blsq ) 6?!
+720
diff --git a/Task/Factorial/Burlesque/factorial-2.blq b/Task/Factorial/Burlesque/factorial-2.blq
new file mode 100644
index 0000000000..7f35b64dcd
--- /dev/null
+++ b/Task/Factorial/Burlesque/factorial-2.blq
@@ -0,0 +1,12 @@
+blsq ) 1 6r@pd
+720
+blsq ) 1 6r@{?*}r[
+720
+blsq ) 2 6r@(.*)\/[[1+]e!.*
+720
+blsq ) 1 6r@p^{.*}5E!
+720
+blsq ) 6ropd
+720
+blsq ) 7ro)(.*){0 1 11}die!
+720
diff --git a/Task/Factorial/C++/factorial-1.cpp b/Task/Factorial/C++/factorial-1.cpp
new file mode 100644
index 0000000000..fd75e3ac02
--- /dev/null
+++ b/Task/Factorial/C++/factorial-1.cpp
@@ -0,0 +1,8 @@
+#include
+#include
+
+int factorial(int n)
+{
+ // last is one-past-end
+ return std::accumulate(boost::counting_iterator(1), boost::counting_iterator(n+1), 1, std::multiplies());
+}
diff --git a/Task/Factorial/C++/factorial-2.cpp b/Task/Factorial/C++/factorial-2.cpp
new file mode 100644
index 0000000000..9f86aec292
--- /dev/null
+++ b/Task/Factorial/C++/factorial-2.cpp
@@ -0,0 +1,14 @@
+long long int Factorial(long long int m_nValue)
+ {
+ long long int result=m_nValue;
+ long long int result_next;
+ long long int pc = m_nValue;
+ do
+ {
+ result_next = result*(pc-1);
+ result = result_next;
+ pc--;
+ }while(pc>2);
+ m_nValue = result;
+ return m_nValue;
+ }
diff --git a/Task/Factorial/C++/factorial-3.cpp b/Task/Factorial/C++/factorial-3.cpp
new file mode 100644
index 0000000000..ee84f7c316
--- /dev/null
+++ b/Task/Factorial/C++/factorial-3.cpp
@@ -0,0 +1,19 @@
+template
+struct Factorial
+{
+ enum { value = N * Factorial::value };
+};
+
+template <>
+struct Factorial<0>
+{
+ enum { value = 1 };
+};
+
+// Factorial<4>::value == 24
+// Factorial<0>::value == 1
+void foo()
+{
+ int x = Factorial<4>::value; // == 24
+ int y = Factorial<0>::value; // == 1
+}
diff --git a/Task/Factorial/C/factorial-1.c b/Task/Factorial/C/factorial-1.c
new file mode 100644
index 0000000000..e3f16f66bf
--- /dev/null
+++ b/Task/Factorial/C/factorial-1.c
@@ -0,0 +1,6 @@
+int factorial(int n) {
+ int result = 1;
+ for (int i = 1; i <= n; ++i)
+ result *= i;
+ return result;
+}
diff --git a/Task/Factorial/C/factorial-2.c b/Task/Factorial/C/factorial-2.c
new file mode 100644
index 0000000000..8c6f303e63
--- /dev/null
+++ b/Task/Factorial/C/factorial-2.c
@@ -0,0 +1,3 @@
+int factorial(int n) {
+ return n == 0 ? 1 : n * factorial(n - 1);
+}
diff --git a/Task/Factorial/C/factorial-3.c b/Task/Factorial/C/factorial-3.c
new file mode 100644
index 0000000000..83a84276be
--- /dev/null
+++ b/Task/Factorial/C/factorial-3.c
@@ -0,0 +1,7 @@
+int fac_aux(int n, int acc) {
+ return n < 1 ? acc : fac_aux(n - 1, acc * n);
+}
+
+int factorial(int n) {
+ return fac_aux(n, 1);
+}
diff --git a/Task/Factorial/CLIPS/factorial.clips b/Task/Factorial/CLIPS/factorial.clips
new file mode 100644
index 0000000000..4de6993cca
--- /dev/null
+++ b/Task/Factorial/CLIPS/factorial.clips
@@ -0,0 +1,8 @@
+ (deffunction factorial (?a)
+ (if (or (not (integerp ?a)) (< ?a 0)) then
+ (printout t "Factorial Error!" crlf)
+ else
+ (if (= ?a 0) then
+ 1
+ else
+ (* ?a (factorial (- ?a 1))))))
diff --git a/Task/Factorial/CMake/factorial.cmake b/Task/Factorial/CMake/factorial.cmake
new file mode 100644
index 0000000000..7156c0353f
--- /dev/null
+++ b/Task/Factorial/CMake/factorial.cmake
@@ -0,0 +1,10 @@
+function(factorial var n)
+ set(product 1)
+ foreach(i RANGE 2 ${n})
+ math(EXPR product "${product} * ${i}")
+ endforeach(i)
+ set(${var} ${product} PARENT_SCOPE)
+endfunction(factorial)
+
+factorial(f 12)
+message("12! = ${f}")
diff --git a/Task/Factorial/Cat/factorial.cat b/Task/Factorial/Cat/factorial.cat
new file mode 100644
index 0000000000..5da86b5f29
--- /dev/null
+++ b/Task/Factorial/Cat/factorial.cat
@@ -0,0 +1,2 @@
+define rec_fac
+ { dup 1 <= [pop 1] [dec rec_fac *] if }
diff --git a/Task/Factorial/Chef/factorial.chef b/Task/Factorial/Chef/factorial.chef
new file mode 100644
index 0000000000..f82f135845
--- /dev/null
+++ b/Task/Factorial/Chef/factorial.chef
@@ -0,0 +1,17 @@
+Caramel Factorials.
+
+Only reads one value.
+
+Ingredients.
+1 g Caramel
+2 g Factorials
+
+Method.
+Take Factorials from refrigerator.
+Put Caramel into 1st mixing bowl.
+Verb the Factorials.
+Combine Factorials into 1st mixing bowl.
+Verb Factorials until verbed.
+Pour contents of the 1st mixing bowl into the 1st baking dish.
+
+Serves 1.
diff --git a/Task/Factorial/Clay/factorial-1.clay b/Task/Factorial/Clay/factorial-1.clay
new file mode 100644
index 0000000000..53a8510d72
--- /dev/null
+++ b/Task/Factorial/Clay/factorial-1.clay
@@ -0,0 +1,14 @@
+factorialRec(n) {
+ if (n == 0) return 1;
+ return n * factorialRec(n - 1);
+}
+
+factorialIter(n) {
+ for (i in range(1, n))
+ n *= i;
+ return n;
+}
+
+factorialFold(n) {
+ return reduce(multiply, 1, range(1, n + 1));
+}
diff --git a/Task/Factorial/Clay/factorial-2.clay b/Task/Factorial/Clay/factorial-2.clay
new file mode 100644
index 0000000000..b939c66a9f
--- /dev/null
+++ b/Task/Factorial/Clay/factorial-2.clay
@@ -0,0 +1,2 @@
+[n|n > 0] factorialStatic(static n) = n * factorialStatic(static n - 1);
+overload factorialStatic(static 0) = 1;
diff --git a/Task/Factorial/Clay/factorial-3.clay b/Task/Factorial/Clay/factorial-3.clay
new file mode 100644
index 0000000000..6e2219eb06
--- /dev/null
+++ b/Task/Factorial/Clay/factorial-3.clay
@@ -0,0 +1,4 @@
+[N|Integer?(N)] factorial(n: N) {
+ if (n == 0) return N(1);
+ return n * factorial(n - 1);
+}
diff --git a/Task/Factorial/Clay/factorial-4.clay b/Task/Factorial/Clay/factorial-4.clay
new file mode 100644
index 0000000000..e02fdbd5a4
--- /dev/null
+++ b/Task/Factorial/Clay/factorial-4.clay
@@ -0,0 +1,7 @@
+main() {
+ println(factorialRec(5)); // 120
+ println(factorialIter(5)); // 120
+ println(factorialFold(5)); // 120
+ println(factorialStatic(static 5)); // 120
+ println(factorial(Int64(20))); // 2432902008176640000
+}
diff --git a/Task/Factorial/Clojure/factorial-1.clj b/Task/Factorial/Clojure/factorial-1.clj
new file mode 100644
index 0000000000..f3fb799093
--- /dev/null
+++ b/Task/Factorial/Clojure/factorial-1.clj
@@ -0,0 +1,2 @@
+(defn factorial [x]
+ (apply * (range 2 (inc x))))
diff --git a/Task/Factorial/Clojure/factorial-2.clj b/Task/Factorial/Clojure/factorial-2.clj
new file mode 100644
index 0000000000..174c8bc8a8
--- /dev/null
+++ b/Task/Factorial/Clojure/factorial-2.clj
@@ -0,0 +1,4 @@
+(defn factorial [x]
+ (if (< x 2)
+ 1
+ (* x (factorial (dec x)))))
diff --git a/Task/Factorial/Clojure/factorial-3.clj b/Task/Factorial/Clojure/factorial-3.clj
new file mode 100644
index 0000000000..d9e87aff42
--- /dev/null
+++ b/Task/Factorial/Clojure/factorial-3.clj
@@ -0,0 +1,6 @@
+(defn factorial [x]
+ (loop [x x
+ acc 1]
+ (if (< x 2)
+ acc
+ (recur (dec x) (* acc x)))))
diff --git a/Task/Factorial/CoffeeScript/factorial-1.coffee b/Task/Factorial/CoffeeScript/factorial-1.coffee
new file mode 100644
index 0000000000..2d094e4134
--- /dev/null
+++ b/Task/Factorial/CoffeeScript/factorial-1.coffee
@@ -0,0 +1,5 @@
+fac = (n) ->
+ if n <= 1
+ 1
+ else
+ n * fac n-1
diff --git a/Task/Factorial/CoffeeScript/factorial-2.coffee b/Task/Factorial/CoffeeScript/factorial-2.coffee
new file mode 100644
index 0000000000..0494db14a3
--- /dev/null
+++ b/Task/Factorial/CoffeeScript/factorial-2.coffee
@@ -0,0 +1,2 @@
+fac = (n) ->
+ [1..n].reduce (x,y) -> x*y
diff --git a/Task/Factorial/Common-Lisp/factorial-1.lisp b/Task/Factorial/Common-Lisp/factorial-1.lisp
new file mode 100644
index 0000000000..f016a89abf
--- /dev/null
+++ b/Task/Factorial/Common-Lisp/factorial-1.lisp
@@ -0,0 +1,4 @@
+(defun fact (n)
+ (if (< n 2)
+ 1
+ (* n (fact(- n 1)))))
diff --git a/Task/Factorial/Common-Lisp/factorial-2.lisp b/Task/Factorial/Common-Lisp/factorial-2.lisp
new file mode 100644
index 0000000000..8e40d68ee5
--- /dev/null
+++ b/Task/Factorial/Common-Lisp/factorial-2.lisp
@@ -0,0 +1,5 @@
+(defun factorial (n)
+ "Calculates N!"
+ (loop for result = 1 then (* result i)
+ for i from 2 to n
+ finally (return result)))
diff --git a/Task/Factorial/Common-Lisp/factorial-3.lisp b/Task/Factorial/Common-Lisp/factorial-3.lisp
new file mode 100644
index 0000000000..3b40c52cdb
--- /dev/null
+++ b/Task/Factorial/Common-Lisp/factorial-3.lisp
@@ -0,0 +1,2 @@
+(defun factorial (n)
+ (reduce #'* (loop for i from 1 to n collect i)))
diff --git a/Task/Factorial/D/factorial.d b/Task/Factorial/D/factorial.d
new file mode 100644
index 0000000000..b12d15d18b
--- /dev/null
+++ b/Task/Factorial/D/factorial.d
@@ -0,0 +1,47 @@
+import std.stdio, std.algorithm, std.metastrings, std.range;
+
+// iterative
+int factorial(int n) {
+ int result = 1;
+ foreach (i; 1 .. n + 1)
+ result *= i;
+ return result;
+}
+
+// recursive
+int recFactorial(int n) {
+ if (n == 0)
+ return 1;
+ else
+ return n * recFactorial(n - 1);
+}
+
+// functional-style
+int fact(int n) {
+ return iota(1, n + 1).reduce!q{a * b}();
+}
+
+// tail recursive (at run-time, with DMD)
+int tfactorial(int n) {
+ static int facAux(int n, int acc) {
+ if (n < 1)
+ return acc;
+ else
+ return facAux(n - 1, acc * n);
+ }
+ return facAux(n, 1);
+}
+
+// computed and printed at compile-time
+pragma(msg, toStringNow!(factorial(15)));
+pragma(msg, toStringNow!(recFactorial(15)));
+pragma(msg, toStringNow!(fact(15)));
+pragma(msg, toStringNow!(tfactorial(15)));
+
+void main() {
+ // computed and printed at run-time
+ writeln(factorial(15));
+ writeln(recFactorial(15));
+ writeln(fact(15));
+ writeln(tfactorial(15));
+}
diff --git a/Task/Factorial/DWScript/factorial-1.dwscript b/Task/Factorial/DWScript/factorial-1.dwscript
new file mode 100644
index 0000000000..b1040e1024
--- /dev/null
+++ b/Task/Factorial/DWScript/factorial-1.dwscript
@@ -0,0 +1,8 @@
+function IterativeFactorial(n : Integer) : Integer;
+var
+ i : Integer;
+begin
+ Result := 1;
+ for i := 2 to n do
+ Result *= i;
+end;
diff --git a/Task/Factorial/DWScript/factorial-2.dwscript b/Task/Factorial/DWScript/factorial-2.dwscript
new file mode 100644
index 0000000000..be2ed7d4f7
--- /dev/null
+++ b/Task/Factorial/DWScript/factorial-2.dwscript
@@ -0,0 +1,6 @@
+function RecursiveFactorial(n : Integer) : Integer;
+begin
+ if n>1 then
+ Result := RecursiveFactorial(n-1)*n
+ else Result := 1;
+end;
diff --git a/Task/Factorial/Dart/factorial-1.dart b/Task/Factorial/Dart/factorial-1.dart
new file mode 100644
index 0000000000..78e12ba218
--- /dev/null
+++ b/Task/Factorial/Dart/factorial-1.dart
@@ -0,0 +1,11 @@
+int fact(int n) {
+ if(n<0) {
+ throw new IllegalArgumentException('Argument less than 0');
+ }
+ return n==0 ? 1 : n*fact(n-1);
+}
+
+main() {
+ print(fact(10));
+ print(fact(-1));
+}
diff --git a/Task/Factorial/Dart/factorial-2.dart b/Task/Factorial/Dart/factorial-2.dart
new file mode 100644
index 0000000000..f4aeb001c5
--- /dev/null
+++ b/Task/Factorial/Dart/factorial-2.dart
@@ -0,0 +1,15 @@
+int fact(int n) {
+ if(n<0) {
+ throw new IllegalArgumentException('Argument less than 0');
+ }
+ int res=1;
+ for(int i=1;i<=n;i++) {
+ res*=i;
+ }
+ return res;
+}
+
+main() {
+ print(fact(10));
+ print(fact(-1));
+}
diff --git a/Task/Factorial/Delphi/factorial-1.delphi b/Task/Factorial/Delphi/factorial-1.delphi
new file mode 100644
index 0000000000..7afc48fdf9
--- /dev/null
+++ b/Task/Factorial/Delphi/factorial-1.delphi
@@ -0,0 +1,16 @@
+program Factorial1;
+
+{$APPTYPE CONSOLE}
+
+function FactorialIterative(aNumber: Integer): Int64;
+var
+ i: Integer;
+begin
+ Result := 1;
+ for i := 1 to aNumber do
+ Result := i * Result;
+end;
+
+begin
+ Writeln('5! = ', FactorialIterative(5));
+end.
diff --git a/Task/Factorial/Delphi/factorial-2.delphi b/Task/Factorial/Delphi/factorial-2.delphi
new file mode 100644
index 0000000000..a067ba8935
--- /dev/null
+++ b/Task/Factorial/Delphi/factorial-2.delphi
@@ -0,0 +1,15 @@
+program Factorial2;
+
+{$APPTYPE CONSOLE}
+
+function FactorialRecursive(aNumber: Integer): Int64;
+begin
+ if aNumber < 1 then
+ Result := 1
+ else
+ Result := aNumber * FactorialRecursive(aNumber - 1);
+end;
+
+begin
+ Writeln('5! = ', FactorialRecursive(5));
+end.
diff --git a/Task/Factorial/Delphi/factorial-3.delphi b/Task/Factorial/Delphi/factorial-3.delphi
new file mode 100644
index 0000000000..5648e522b6
--- /dev/null
+++ b/Task/Factorial/Delphi/factorial-3.delphi
@@ -0,0 +1,24 @@
+program Factorial3;
+
+{$APPTYPE CONSOLE}
+
+function FactorialTailRecursive(aNumber: Integer): Int64;
+
+ function FactorialHelper(aNumber: Integer; aAccumulator: Int64): Int64;
+ begin
+ if aNumber = 0 then
+ Result := aAccumulator
+ else
+ Result := FactorialHelper(aNumber - 1, aNumber * aAccumulator);
+ end;
+
+begin
+ if aNumber < 1 then
+ Result := 1
+ else
+ Result := FactorialHelper(aNumber, 1);
+end;
+
+begin
+ Writeln('5! = ', FactorialTailRecursive(5));
+end.
diff --git a/Task/Factorial/Dylan/factorial.dylan b/Task/Factorial/Dylan/factorial.dylan
new file mode 100644
index 0000000000..44a5bb1fe8
--- /dev/null
+++ b/Task/Factorial/Dylan/factorial.dylan
@@ -0,0 +1,3 @@
+define method factorial(n)
+ reduce1(\*, range(from: 1, to: n));
+end
diff --git a/Task/Factorial/E/factorial.e b/Task/Factorial/E/factorial.e
new file mode 100644
index 0000000000..cf635f5c88
--- /dev/null
+++ b/Task/Factorial/E/factorial.e
@@ -0,0 +1,4 @@
+pragma.enable("accumulator")
+def factorial(n) {
+ return accum 1 for i in 2..n { _ * i }
+}
diff --git a/Task/Factorial/EGL/factorial-1.egl b/Task/Factorial/EGL/factorial-1.egl
new file mode 100644
index 0000000000..679f365396
--- /dev/null
+++ b/Task/Factorial/EGL/factorial-1.egl
@@ -0,0 +1,11 @@
+function fact(n int in) returns (bigint)
+ if (n < 0)
+ writestdout("No negative numbers");
+ return (0);
+ end
+ ans bigint = 1;
+ for (i int from 1 to n)
+ ans *= i;
+ end
+ return (ans);
+end
diff --git a/Task/Factorial/EGL/factorial-2.egl b/Task/Factorial/EGL/factorial-2.egl
new file mode 100644
index 0000000000..f085dacbcd
--- /dev/null
+++ b/Task/Factorial/EGL/factorial-2.egl
@@ -0,0 +1,11 @@
+function fact(n int in) returns (bigint)
+ if (n < 0)
+ SysLib.writeStdout("No negative numbers");
+ return (0);
+ end
+ if (n < 2)
+ return (1);
+ else
+ return (n * fact(n - 1));
+ end
+end
diff --git a/Task/Factorial/Ela/factorial.ela b/Task/Factorial/Ela/factorial.ela
new file mode 100644
index 0000000000..a0ec20ea39
--- /dev/null
+++ b/Task/Factorial/Ela/factorial.ela
@@ -0,0 +1,3 @@
+fact = fact' 1L
+ where fact' acc 0 = acc
+ fact' acc n = fact' (n * acc) (n - 1)
diff --git a/Task/Factorial/Emacs-Lisp/factorial-1.l b/Task/Factorial/Emacs-Lisp/factorial-1.l
new file mode 100644
index 0000000000..d806098ba8
--- /dev/null
+++ b/Task/Factorial/Emacs-Lisp/factorial-1.l
@@ -0,0 +1,6 @@
+(defun fact (n)
+ "n is an integer, this function returns n!, that is n * (n - 1)
+* (n - 2)....* 4 * 3 * 2 * 1"
+ (cond
+ ((= n 1) 1)
+ (t (* n (fact (1- n))))))
diff --git a/Task/Factorial/Emacs-Lisp/factorial-2.l b/Task/Factorial/Emacs-Lisp/factorial-2.l
new file mode 100644
index 0000000000..b7d69a4dfa
--- /dev/null
+++ b/Task/Factorial/Emacs-Lisp/factorial-2.l
@@ -0,0 +1,4 @@
+(require 'calc)
+(calc-eval "fact(30)")
+=>
+"265252859812191058636308480000000"
diff --git a/Task/Factorial/Erlang/factorial-1.erl b/Task/Factorial/Erlang/factorial-1.erl
new file mode 100644
index 0000000000..99a638b204
--- /dev/null
+++ b/Task/Factorial/Erlang/factorial-1.erl
@@ -0,0 +1 @@
+lists:foldl(fun(X,Y) -> X*Y end, 1, lists:seq(1,N)).
diff --git a/Task/Factorial/Erlang/factorial-2.erl b/Task/Factorial/Erlang/factorial-2.erl
new file mode 100644
index 0000000000..3f6661aed6
--- /dev/null
+++ b/Task/Factorial/Erlang/factorial-2.erl
@@ -0,0 +1,2 @@
+fac(1) -> 1;
+fac(N) -> N * fac(N-1).
diff --git a/Task/Factorial/Erlang/factorial-3.erl b/Task/Factorial/Erlang/factorial-3.erl
new file mode 100644
index 0000000000..5964d0a25e
--- /dev/null
+++ b/Task/Factorial/Erlang/factorial-3.erl
@@ -0,0 +1,3 @@
+fac(N) -> fac(N-1,N).
+fac(1,N) -> N;
+fac(I,N) -> fac(I-1,N*I).
diff --git a/Task/Factorial/Euphoria/factorial-1.euphoria b/Task/Factorial/Euphoria/factorial-1.euphoria
new file mode 100644
index 0000000000..f36ea675c6
--- /dev/null
+++ b/Task/Factorial/Euphoria/factorial-1.euphoria
@@ -0,0 +1,9 @@
+function factorial(integer n)
+ atom f = 1
+ while n > 1 do
+ f *= n
+ n -= 1
+ end while
+
+ return f
+end function
diff --git a/Task/Factorial/Euphoria/factorial-2.euphoria b/Task/Factorial/Euphoria/factorial-2.euphoria
new file mode 100644
index 0000000000..df1332ec75
--- /dev/null
+++ b/Task/Factorial/Euphoria/factorial-2.euphoria
@@ -0,0 +1,7 @@
+function factorial(integer n)
+ if n > 1 then
+ return factorial(n-1) * n
+ else
+ return 1
+ end if
+end function
diff --git a/Task/Factorial/Euphoria/factorial-3.euphoria b/Task/Factorial/Euphoria/factorial-3.euphoria
new file mode 100644
index 0000000000..e32d25e6da
--- /dev/null
+++ b/Task/Factorial/Euphoria/factorial-3.euphoria
@@ -0,0 +1,7 @@
+function factorial(integer n, integer acc = 1)
+ if n <= 0 then
+ return acc
+ else
+ return factorial(n-1, n*acc)
+ end if
+end function
diff --git a/Task/Factorial/Euphoria/factorial-4.euphoria b/Task/Factorial/Euphoria/factorial-4.euphoria
new file mode 100644
index 0000000000..0ef293f577
--- /dev/null
+++ b/Task/Factorial/Euphoria/factorial-4.euphoria
@@ -0,0 +1,106 @@
+include std/mathcons.e
+
+enum MUL_LLL,
+ TESTEQ_LIL,
+ TESTLT_LIL,
+ TRUEGO_LL,
+ MOVE_LL,
+ INCR_L,
+ TESTGT_LLL,
+ GOTO_L,
+ OUT_LI,
+ OUT_II,
+ STOP
+
+global sequence tape = {
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ {TESTLT_LIL, 5, 0, 4},
+ {TRUEGO_LL, 4, 22},
+ {TESTEQ_LIL, 5, 0, 4},
+ {TRUEGO_LL, 4, 20},
+ {MUL_LLL, 1, 2, 3},
+ {TESTEQ_LIL, 3, PINF, 4},
+ {TRUEGO_LL, 4, 18},
+ {MOVE_LL, 3, 1},
+ {INCR_L, 2},
+ {TESTGT_LLL, 2, 5, 4 },
+ {TRUEGO_LL, 4, 18},
+ {GOTO_L, 10},
+ {OUT_LI, 3, "%.0f\n"},
+ {STOP},
+ {OUT_II, 1, "%.0f\n"},
+ {STOP},
+ {OUT_II, "Negative argument", "%s\n"},
+ {STOP}
+}
+
+global integer ip = 1
+
+procedure eval( sequence cmd )
+ atom i = 1
+ while i <= length( cmd ) do
+ switch cmd[ i ] do
+ case MUL_LLL then -- multiply location location giving location
+ tape[ cmd[ i + 3 ] ] = tape[ cmd[ i + 1 ] ] * tape[ cmd[ i + 2 ] ]
+ i += 3
+ case TESTEQ_LIL then -- test if location eq value giving location
+ tape[ cmd[ i + 3 ]] = ( tape[ cmd[ i + 1 ] ] = cmd[ i + 2 ] )
+ i += 3
+ case TESTLT_LIL then -- test if location eq value giving location
+ tape[ cmd[ i + 3 ]] = ( tape[ cmd[ i + 1 ] ] < cmd[ i + 2 ] )
+ i += 3
+ case TRUEGO_LL then -- if true in location, goto location
+ if tape[ cmd[ i + 1 ] ] then
+ ip = cmd[ i + 2 ] - 1
+ end if
+ i += 2
+ case MOVE_LL then -- move value at location to location
+ tape[ cmd[ i + 2 ] ] = tape[ cmd[ i + 1 ] ]
+ i += 2
+ case INCR_L then -- increment value at location
+ tape[ cmd[ i + 1 ] ] += 1
+ i += 1
+ case TESTGT_LLL then -- test if location gt location giving location
+ tape[ cmd[ i + 3 ]] = ( tape[ cmd[ i + 1 ] ] > tape[ cmd[ i + 2 ] ] )
+ i += 3
+ case GOTO_L then -- goto location
+ ip = cmd[ i + 1 ] - 1
+ i += 1
+ case OUT_LI then -- output location using format
+ printf( 1, cmd[ i + 2], tape[ cmd[ i + 1 ] ] )
+ i += 2
+ case OUT_II then -- output immediate using format
+ if sequence( cmd[ i + 1 ] ) then
+ printf( 1, cmd[ i + 2], { cmd[ i + 1 ] } )
+ else
+ printf( 1, cmd[ i + 2], cmd[ i + 1 ] )
+ end if
+ i += 2
+ case STOP then -- stop
+ abort(0)
+ end switch
+ i += 1
+ end while
+end procedure
+
+include std/convert.e
+
+sequence cmd = command_line()
+if length( cmd ) > 2 then
+ puts( 1, cmd[ 3 ] & "! = " )
+ tape[ 5 ] = to_number(cmd[3])
+else
+ puts( 1, "eui fact.ex \n" )
+ abort(1)
+end if
+
+while 1 do
+ if sequence( tape[ ip ] ) then
+ eval( tape[ ip ] )
+ end if
+ ip += 1
+end while
diff --git a/Task/Factorial/FALSE/factorial-1.false b/Task/Factorial/FALSE/factorial-1.false
new file mode 100644
index 0000000000..78ffe76fb8
--- /dev/null
+++ b/Task/Factorial/FALSE/factorial-1.false
@@ -0,0 +1,2 @@
+[1\[$][$@*\1-]#%]f:
+^'0- f;!.
diff --git a/Task/Factorial/FALSE/factorial-2.false b/Task/Factorial/FALSE/factorial-2.false
new file mode 100644
index 0000000000..806b709ccc
--- /dev/null
+++ b/Task/Factorial/FALSE/factorial-2.false
@@ -0,0 +1 @@
+[$1=~[$1-f;!*]?]f:
diff --git a/Task/Factorial/Factor/factorial.factor b/Task/Factorial/Factor/factorial.factor
new file mode 100644
index 0000000000..18ecd2d6ef
--- /dev/null
+++ b/Task/Factorial/Factor/factorial.factor
@@ -0,0 +1,3 @@
+USING: math.ranges sequences ;
+
+: factorial ( n -- n ) [1,b] product ;
diff --git a/Task/Factorial/Fancy/factorial.fancy b/Task/Factorial/Fancy/factorial.fancy
new file mode 100644
index 0000000000..4af63f802e
--- /dev/null
+++ b/Task/Factorial/Fancy/factorial.fancy
@@ -0,0 +1,10 @@
+def class Number {
+ def factorial {
+ 1 upto: self . product
+ }
+}
+
+# print first ten factorials
+1 upto: 10 do_each: |i| {
+ i to_s ++ "! = " ++ (i factorial) println
+}
diff --git a/Task/Factorial/Fantom/factorial.fantom b/Task/Factorial/Fantom/factorial.fantom
new file mode 100644
index 0000000000..3c605207cd
--- /dev/null
+++ b/Task/Factorial/Fantom/factorial.fantom
@@ -0,0 +1,36 @@
+class Main
+{
+ static Int factorialRecursive (Int n)
+ {
+ if (n <= 1)
+ return 1
+ else
+ return n * (factorialRecursive (n - 1))
+ }
+
+ static Int factorialIterative (Int n)
+ {
+ Int product := 1
+ for (Int i := 2; i <=n ; ++i)
+ {
+ product *= i
+ }
+ return product
+ }
+
+ static Int factorialFunctional (Int n)
+ {
+ (1..n).toList.reduce(1) |a,v|
+ {
+ v->mult(a) // use a dynamic invoke
+ // alternatively, cast a: v * (Int)a
+ }
+ }
+
+ public static Void main ()
+ {
+ echo (factorialRecursive(20))
+ echo (factorialIterative(20))
+ echo (factorialFunctional(20))
+ }
+}
diff --git a/Task/Factorial/Forth/factorial.fth b/Task/Factorial/Forth/factorial.fth
new file mode 100644
index 0000000000..dc929b5b63
--- /dev/null
+++ b/Task/Factorial/Forth/factorial.fth
@@ -0,0 +1 @@
+: fac ( n -- n! ) 1 swap 1+ 1 ?do i * loop ;
diff --git a/Task/Factorial/Fortran/factorial-1.f b/Task/Factorial/Fortran/factorial-1.f
new file mode 100644
index 0000000000..7e43b5c997
--- /dev/null
+++ b/Task/Factorial/Fortran/factorial-1.f
@@ -0,0 +1 @@
+nfactorial = PRODUCT((/(i, i=1,n)/))
diff --git a/Task/Factorial/Fortran/factorial-2.f b/Task/Factorial/Fortran/factorial-2.f
new file mode 100644
index 0000000000..6313a74fdd
--- /dev/null
+++ b/Task/Factorial/Fortran/factorial-2.f
@@ -0,0 +1,6 @@
+ FUNCTION FACT(N)
+ INTEGER N,I,FACT
+ FACT=1
+ DO 10 I=1,N
+ 10 FACT=FACT*I
+ END
diff --git a/Task/Factorial/GAP/factorial.gap b/Task/Factorial/GAP/factorial.gap
new file mode 100644
index 0000000000..65ddffddad
--- /dev/null
+++ b/Task/Factorial/GAP/factorial.gap
@@ -0,0 +1,5 @@
+# Built-in
+Factorial(5);
+
+# An implementation
+fact := n -> Product([1 .. n]);
diff --git a/Task/Factorial/GML/factorial.gml b/Task/Factorial/GML/factorial.gml
new file mode 100644
index 0000000000..bc315226d3
--- /dev/null
+++ b/Task/Factorial/GML/factorial.gml
@@ -0,0 +1,5 @@
+n = argument0
+j = 1
+for(i = 1; i <= n; i += 1)
+ j *= i
+return j
diff --git a/Task/Factorial/Genyris/factorial.genyris b/Task/Factorial/Genyris/factorial.genyris
new file mode 100644
index 0000000000..3909f6e52c
--- /dev/null
+++ b/Task/Factorial/Genyris/factorial.genyris
@@ -0,0 +1,4 @@
+def factorial (n)
+ if (< n 2) 1
+ * n
+ factorial (- n 1)
diff --git a/Task/Factorial/Go/factorial-1.go b/Task/Factorial/Go/factorial-1.go
new file mode 100644
index 0000000000..7f1108a14e
--- /dev/null
+++ b/Task/Factorial/Go/factorial-1.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "fmt"
+ "math/big"
+)
+
+func main() {
+ fmt.Println(factorial(800))
+}
+
+func factorial(n int64) *big.Int {
+ if n < 0 {
+ return nil
+ }
+ r := big.NewInt(1)
+ var f big.Int
+ for i := int64(2); i <= n; i++ {
+ r.Mul(r, f.SetInt64(i))
+ }
+ return r
+}
diff --git a/Task/Factorial/Go/factorial-2.go b/Task/Factorial/Go/factorial-2.go
new file mode 100644
index 0000000000..fbf9b3287c
--- /dev/null
+++ b/Task/Factorial/Go/factorial-2.go
@@ -0,0 +1,15 @@
+package main
+
+import (
+ "math/big"
+ "fmt"
+)
+
+func factorial(n int64) *big.Int {
+ var z big.Int
+ return z.MulRange(1, n)
+}
+
+func main() {
+ fmt.Println(factorial(800))
+}
diff --git a/Task/Factorial/Golfscript/factorial-1.golf b/Task/Factorial/Golfscript/factorial-1.golf
new file mode 100644
index 0000000000..99bbd8a8a1
--- /dev/null
+++ b/Task/Factorial/Golfscript/factorial-1.golf
@@ -0,0 +1,2 @@
+{.!{1}{,{)}%{*}*}if}:fact;
+5fact puts # test
diff --git a/Task/Factorial/Golfscript/factorial-2.golf b/Task/Factorial/Golfscript/factorial-2.golf
new file mode 100644
index 0000000000..1c2fb3848a
--- /dev/null
+++ b/Task/Factorial/Golfscript/factorial-2.golf
@@ -0,0 +1 @@
+{),(;{*}*}:fact;
diff --git a/Task/Factorial/Golfscript/factorial-3.golf b/Task/Factorial/Golfscript/factorial-3.golf
new file mode 100644
index 0000000000..b09dc275b1
--- /dev/null
+++ b/Task/Factorial/Golfscript/factorial-3.golf
@@ -0,0 +1 @@
+{.1<{;1}{.(fact*}if}:fact;
diff --git a/Task/Factorial/Groovy/factorial-1.groovy b/Task/Factorial/Groovy/factorial-1.groovy
new file mode 100644
index 0000000000..eb55b8752e
--- /dev/null
+++ b/Task/Factorial/Groovy/factorial-1.groovy
@@ -0,0 +1,2 @@
+def rFact
+rFact = { (it > 1) ? it * rFact(it - 1) : 1 }
diff --git a/Task/Factorial/Groovy/factorial-2.groovy b/Task/Factorial/Groovy/factorial-2.groovy
new file mode 100644
index 0000000000..237d76fb80
--- /dev/null
+++ b/Task/Factorial/Groovy/factorial-2.groovy
@@ -0,0 +1 @@
+(0..6).each { println "${it}: ${rFact(it)}" }
diff --git a/Task/Factorial/Groovy/factorial-3.groovy b/Task/Factorial/Groovy/factorial-3.groovy
new file mode 100644
index 0000000000..16d91aa814
--- /dev/null
+++ b/Task/Factorial/Groovy/factorial-3.groovy
@@ -0,0 +1 @@
+def iFact = { (it > 1) ? (2..it).inject(1) { i, j -> i*j } : 1 }
diff --git a/Task/Factorial/Groovy/factorial-4.groovy b/Task/Factorial/Groovy/factorial-4.groovy
new file mode 100644
index 0000000000..6100d01f08
--- /dev/null
+++ b/Task/Factorial/Groovy/factorial-4.groovy
@@ -0,0 +1 @@
+(0..6).each { println "${it}: ${iFact(it)}" }
diff --git a/Task/Factorial/Haskell/factorial-1.hs b/Task/Factorial/Haskell/factorial-1.hs
new file mode 100644
index 0000000000..9c54462476
--- /dev/null
+++ b/Task/Factorial/Haskell/factorial-1.hs
@@ -0,0 +1 @@
+factorial n = product [1..n]
diff --git a/Task/Factorial/Haskell/factorial-2.hs b/Task/Factorial/Haskell/factorial-2.hs
new file mode 100644
index 0000000000..4a9556a5a8
--- /dev/null
+++ b/Task/Factorial/Haskell/factorial-2.hs
@@ -0,0 +1 @@
+factorial n = foldl (*) 1 [1..n]
diff --git a/Task/Factorial/Haskell/factorial-3.hs b/Task/Factorial/Haskell/factorial-3.hs
new file mode 100644
index 0000000000..1536f72670
--- /dev/null
+++ b/Task/Factorial/Haskell/factorial-3.hs
@@ -0,0 +1 @@
+factorials = scanl (*) 1 [1..]
diff --git a/Task/Factorial/Haskell/factorial-4.hs b/Task/Factorial/Haskell/factorial-4.hs
new file mode 100644
index 0000000000..6b76b69b6e
--- /dev/null
+++ b/Task/Factorial/Haskell/factorial-4.hs
@@ -0,0 +1,3 @@
+factorial :: Integral -> Integral
+factorial 0 = 1
+factorial n = n * factorial (n-1)
diff --git a/Task/Factorial/Haskell/factorial-5.hs b/Task/Factorial/Haskell/factorial-5.hs
new file mode 100644
index 0000000000..baef906bf8
--- /dev/null
+++ b/Task/Factorial/Haskell/factorial-5.hs
@@ -0,0 +1,5 @@
+fac n
+ | n >= 0 = go 1 n
+ | otherwise = error "Negative factorial!"
+ where go acc 0 = acc
+ go acc n = go (acc * n) (n - 1)
diff --git a/Task/Factorial/HicEst/factorial.hicest b/Task/Factorial/HicEst/factorial.hicest
new file mode 100644
index 0000000000..b7bc52434e
--- /dev/null
+++ b/Task/Factorial/HicEst/factorial.hicest
@@ -0,0 +1,8 @@
+WRITE(Clipboard) factorial(6) ! pasted: 720
+
+FUNCTION factorial(n)
+ factorial = 1
+ DO i = 2, n
+ factorial = factorial * i
+ ENDDO
+END
diff --git a/Task/Factorial/IDL/factorial.idl b/Task/Factorial/IDL/factorial.idl
new file mode 100644
index 0000000000..e7a8f13466
--- /dev/null
+++ b/Task/Factorial/IDL/factorial.idl
@@ -0,0 +1,3 @@
+function fact,n
+ return, product(lindgen(n)+1)
+end
diff --git a/Task/Factorial/Icon/factorial-1.icon b/Task/Factorial/Icon/factorial-1.icon
new file mode 100644
index 0000000000..a8ce2e87b1
--- /dev/null
+++ b/Task/Factorial/Icon/factorial-1.icon
@@ -0,0 +1,5 @@
+procedure factorial(n)
+ n := integer(n) | runerr(101, n)
+ if n < 0 then fail
+ return if n = 0 then 1 else n*factorial(n-1)
+end
diff --git a/Task/Factorial/Icon/factorial-2.icon b/Task/Factorial/Icon/factorial-2.icon
new file mode 100644
index 0000000000..fc539f9281
--- /dev/null
+++ b/Task/Factorial/Icon/factorial-2.icon
@@ -0,0 +1,8 @@
+procedure factorial(n) #: return n! (n factorial)
+ local i
+ n := integer(n) | runerr(101, n)
+ if n < 0 then fail
+ i := 1
+ every i *:= 1 to n
+ return i
+end
diff --git a/Task/Factorial/Inform-6/factorial.inf b/Task/Factorial/Inform-6/factorial.inf
new file mode 100644
index 0000000000..851dce6a29
--- /dev/null
+++ b/Task/Factorial/Inform-6/factorial.inf
@@ -0,0 +1,6 @@
+[ factorial n;
+ if(n == 0)
+ return 1;
+ else
+ return n * factorial(n - 1);
+];
diff --git a/Task/Factorial/Io/factorial.io b/Task/Factorial/Io/factorial.io
new file mode 100644
index 0000000000..435b6c7538
--- /dev/null
+++ b/Task/Factorial/Io/factorial.io
@@ -0,0 +1 @@
+3 factorial
diff --git a/Task/Factorial/J/factorial-1.j b/Task/Factorial/J/factorial-1.j
new file mode 100644
index 0000000000..153d75e9e7
--- /dev/null
+++ b/Task/Factorial/J/factorial-1.j
@@ -0,0 +1,2 @@
+ ! 8 NB. Built in factorial operator
+40320
diff --git a/Task/Factorial/J/factorial-2.j b/Task/Factorial/J/factorial-2.j
new file mode 100644
index 0000000000..70b6a815d6
--- /dev/null
+++ b/Task/Factorial/J/factorial-2.j
@@ -0,0 +1,2 @@
+ */1+i.8
+40320
diff --git a/Task/Factorial/J/factorial-3.j b/Task/Factorial/J/factorial-3.j
new file mode 100644
index 0000000000..786036644e
--- /dev/null
+++ b/Task/Factorial/J/factorial-3.j
@@ -0,0 +1,2 @@
+ (*$:@:<:)^:(1&<) 8
+40320
diff --git a/Task/Factorial/J/factorial-4.j b/Task/Factorial/J/factorial-4.j
new file mode 100644
index 0000000000..4deede7a9a
--- /dev/null
+++ b/Task/Factorial/J/factorial-4.j
@@ -0,0 +1,4 @@
+ ! 8 0.8 _0.8 NB. Generalizes as the gamma function
+40320 0.931384 4.59084
+ ! 800x NB. Also arbitrarily large
+7710530113353860041446393977750283605955564018160102391634109940339708518270930693670907697955390330926478612242306774446597851526397454014801846531749097625044706382742591201733097017026108750929188168469858421505936237186038616420630788341172340985137252...
diff --git a/Task/Factorial/Java/factorial-1.java b/Task/Factorial/Java/factorial-1.java
new file mode 100644
index 0000000000..b0b9d120c3
--- /dev/null
+++ b/Task/Factorial/Java/factorial-1.java
@@ -0,0 +1,11 @@
+public static long fact(final int n) {
+ if (n < 0) {
+ System.err.println("No negative numbers");
+ return 0;
+ }
+ long ans = 1;
+ for (int i = 1; i <= n; i++) {
+ ans *= i;
+ }
+ return ans;
+}
diff --git a/Task/Factorial/Java/factorial-2.java b/Task/Factorial/Java/factorial-2.java
new file mode 100644
index 0000000000..3f2e2ec883
--- /dev/null
+++ b/Task/Factorial/Java/factorial-2.java
@@ -0,0 +1,7 @@
+public static long fact(final int n) {
+ if (n < 0){
+ System.err.println("No negative numbers");
+ return 0;
+ }
+ return (n < 2) ? 1 : n * fact(n - 1);
+}
diff --git a/Task/Factorial/JavaScript/factorial-1.js b/Task/Factorial/JavaScript/factorial-1.js
new file mode 100644
index 0000000000..f94f8ecd87
--- /dev/null
+++ b/Task/Factorial/JavaScript/factorial-1.js
@@ -0,0 +1,7 @@
+function factorial(n) {
+ var x = 1;
+ for (var i = 2; i <= n; i++) {
+ x *= i;
+ }
+ return x;
+}
diff --git a/Task/Factorial/JavaScript/factorial-2.js b/Task/Factorial/JavaScript/factorial-2.js
new file mode 100644
index 0000000000..9035ce0b2e
--- /dev/null
+++ b/Task/Factorial/JavaScript/factorial-2.js
@@ -0,0 +1,3 @@
+function factorial(n) {
+ return n < 2 ? 1 : n * factorial(n - 1);
+}
diff --git a/Task/Factorial/JavaScript/factorial-3.js b/Task/Factorial/JavaScript/factorial-3.js
new file mode 100644
index 0000000000..9d8ded422e
--- /dev/null
+++ b/Task/Factorial/JavaScript/factorial-3.js
@@ -0,0 +1,8 @@
+function range(n) {
+ for (let i = 1; i <= n; i++)
+ yield i;
+}
+
+function factorial(n) {
+ return [i for (i in range(n))].reduce(function(a, b) a*b, 1);
+}
diff --git a/Task/Factorial/Joy/factorial.joy b/Task/Factorial/Joy/factorial.joy
new file mode 100644
index 0000000000..a65d9122c2
--- /dev/null
+++ b/Task/Factorial/Joy/factorial.joy
@@ -0,0 +1 @@
+DEFINE factorial == [0 =] [pop 1] [dup 1 - factorial *] ifte.
diff --git a/Task/Factorial/Julia/factorial.julia b/Task/Factorial/Julia/factorial.julia
new file mode 100644
index 0000000000..41d3c8f9e5
--- /dev/null
+++ b/Task/Factorial/Julia/factorial.julia
@@ -0,0 +1,16 @@
+# this is just a copy from the combinatorics.jl module of the Julia standard library
+function factorial(n::Integer)
+ if n < 0
+ return zero(n)
+ end
+ f = one(n)
+ for i = 2:n
+ f *= i
+ end
+ return f
+end
+
+load("bigint.jl") #use BigInt to avoid overflow for large values of n
+n=BigInt(30)
+factorial(n)
+265252859812191058636308480000000
diff --git a/Task/Factorial/K/factorial-1.k b/Task/Factorial/K/factorial-1.k
new file mode 100644
index 0000000000..f00ba1be40
--- /dev/null
+++ b/Task/Factorial/K/factorial-1.k
@@ -0,0 +1,3 @@
+ facti:*/1+!:
+ facti 5
+120
diff --git a/Task/Factorial/K/factorial-2.k b/Task/Factorial/K/factorial-2.k
new file mode 100644
index 0000000000..79e12f3e3a
--- /dev/null
+++ b/Task/Factorial/K/factorial-2.k
@@ -0,0 +1,3 @@
+ factr:{:[x>1;x*_f x-1;1]}
+ factr 6
+720
diff --git a/Task/Factorial/KonsolScript/factorial.konso b/Task/Factorial/KonsolScript/factorial.konso
new file mode 100644
index 0000000000..08d0f172f6
--- /dev/null
+++ b/Task/Factorial/KonsolScript/factorial.konso
@@ -0,0 +1,13 @@
+function factorial(Number n):Number {
+ Var:Number ret;
+ if (n >= 0) {
+ ret = 1;
+ Var:Number i = 1;
+ for (i = 1; i <= n; i++) {
+ ret = ret * i;
+ }
+ } else {
+ ret = 0;
+ }
+ return ret;
+}
diff --git a/Task/Factorial/Lang5/factorial-1.lang5 b/Task/Factorial/Lang5/factorial-1.lang5
new file mode 100644
index 0000000000..ae10faf759
--- /dev/null
+++ b/Task/Factorial/Lang5/factorial-1.lang5
@@ -0,0 +1,3 @@
+ : fact iota 1 + '* reduce ;
+ 5 fact
+120
diff --git a/Task/Factorial/Lang5/factorial-2.lang5 b/Task/Factorial/Lang5/factorial-2.lang5
new file mode 100644
index 0000000000..0547e94e71
--- /dev/null
+++ b/Task/Factorial/Lang5/factorial-2.lang5
@@ -0,0 +1,3 @@
+ : fact dup 2 < if else dup 1 - fact * then ;
+ 5 fact
+120
diff --git a/Task/Factorial/Liberty-BASIC/factorial.liberty b/Task/Factorial/Liberty-BASIC/factorial.liberty
new file mode 100644
index 0000000000..93c9a79077
--- /dev/null
+++ b/Task/Factorial/Liberty-BASIC/factorial.liberty
@@ -0,0 +1,29 @@
+ for i =0 to 40
+ print " FactorialI( "; using( "####", i); ") = "; factorialI( i)
+ print " FactorialR( "; using( "####", i); ") = "; factorialR( i)
+ next i
+
+ wait
+
+ function factorialI( n)
+ if n >1 then
+ f =1
+ For i = 2 To n
+ f = f * i
+ Next i
+ else
+ f =1
+ end if
+ factorialI =f
+ end function
+
+ function factorialR( n)
+ if n <2 then
+ f =1
+ else
+ f =n *factorialR( n -1)
+ end if
+ factorialR =f
+ end function
+
+ end
diff --git a/Task/Factorial/Lisaac/factorial.lisaac b/Task/Factorial/Lisaac/factorial.lisaac
new file mode 100644
index 0000000000..3545f5ff7c
--- /dev/null
+++ b/Task/Factorial/Lisaac/factorial.lisaac
@@ -0,0 +1,9 @@
+- factorial x : INTEGER : INTEGER <- (
+ + result : INTEGER;
+ (x <= 1).if {
+ result := 1;
+ } else {
+ result := x * factorial(x - 1);
+ };
+ result
+);
diff --git a/Task/Factorial/Logo/factorial-1.logo b/Task/Factorial/Logo/factorial-1.logo
new file mode 100644
index 0000000000..f81201ac97
--- /dev/null
+++ b/Task/Factorial/Logo/factorial-1.logo
@@ -0,0 +1,4 @@
+to factorial :n
+ if :n < 2 [output 1]
+ output :n * factorial :n-1
+end
diff --git a/Task/Factorial/Logo/factorial-2.logo b/Task/Factorial/Logo/factorial-2.logo
new file mode 100644
index 0000000000..90fb7728e6
--- /dev/null
+++ b/Task/Factorial/Logo/factorial-2.logo
@@ -0,0 +1,6 @@
+to factorial :n
+ make "fact 1
+ make "i 1
+ repeat :n [make "fact :fact * :i make "i :i + 1]
+ print :fact
+end
diff --git a/Task/Factorial/Lua/factorial-1.lua b/Task/Factorial/Lua/factorial-1.lua
new file mode 100644
index 0000000000..e9103b655e
--- /dev/null
+++ b/Task/Factorial/Lua/factorial-1.lua
@@ -0,0 +1,3 @@
+function fact(n)
+ return n > 0 and n * fact(n-1) or 1
+end
diff --git a/Task/Factorial/Lua/factorial-2.lua b/Task/Factorial/Lua/factorial-2.lua
new file mode 100644
index 0000000000..8b4dee8004
--- /dev/null
+++ b/Task/Factorial/Lua/factorial-2.lua
@@ -0,0 +1,7 @@
+function fact(n, acc)
+ acc = acc or 1
+ if n == 0 then
+ return acc
+ end
+ return fact(n-1, n*acc)
+end
diff --git a/Task/Factorial/M4/factorial.m4 b/Task/Factorial/M4/factorial.m4
new file mode 100644
index 0000000000..164be5283f
--- /dev/null
+++ b/Task/Factorial/M4/factorial.m4
@@ -0,0 +1,3 @@
+define(`factorial',`ifelse(`$1',0,1,`eval($1*factorial(decr($1)))')')dnl
+dnl
+factorial(5)
diff --git a/Task/Factorial/MATLAB/factorial-1.m b/Task/Factorial/MATLAB/factorial-1.m
new file mode 100644
index 0000000000..460b7231a1
--- /dev/null
+++ b/Task/Factorial/MATLAB/factorial-1.m
@@ -0,0 +1 @@
+answer = factorial(N)
diff --git a/Task/Factorial/MATLAB/factorial-2.m b/Task/Factorial/MATLAB/factorial-2.m
new file mode 100644
index 0000000000..34a2186469
--- /dev/null
+++ b/Task/Factorial/MATLAB/factorial-2.m
@@ -0,0 +1,7 @@
+function f=fac(n)
+ if n==0
+ f=1;
+ return
+ else
+ f=n*fac(n-1);
+ end
diff --git a/Task/Factorial/MATLAB/factorial-3.m b/Task/Factorial/MATLAB/factorial-3.m
new file mode 100644
index 0000000000..6c482bad90
--- /dev/null
+++ b/Task/Factorial/MATLAB/factorial-3.m
@@ -0,0 +1,5 @@
+ function b=factorial(a)
+ b=1;
+ for i=1:a
+ b=b*i;
+ end
diff --git a/Task/Factorial/MAXScript/factorial-1.max b/Task/Factorial/MAXScript/factorial-1.max
new file mode 100644
index 0000000000..9fc6bfa2d8
--- /dev/null
+++ b/Task/Factorial/MAXScript/factorial-1.max
@@ -0,0 +1,10 @@
+fn factorial n =
+(
+ if n == 0 then return 1
+ local fac = 1
+ for i in 1 to n do
+ (
+ fac *= i
+ )
+ fac
+)
diff --git a/Task/Factorial/MAXScript/factorial-2.max b/Task/Factorial/MAXScript/factorial-2.max
new file mode 100644
index 0000000000..d1e39fba79
--- /dev/null
+++ b/Task/Factorial/MAXScript/factorial-2.max
@@ -0,0 +1,9 @@
+fn factorial_rec n =
+(
+ local fac = 1
+ if n > 1 then
+ (
+ fac = n * factorial_rec (n - 1)
+ )
+ fac
+)
diff --git a/Task/Factorial/ML-I/factorial-1.ml b/Task/Factorial/ML-I/factorial-1.ml
new file mode 100644
index 0000000000..cbaa599e22
--- /dev/null
+++ b/Task/Factorial/ML-I/factorial-1.ml
@@ -0,0 +1,17 @@
+MCSKIP "WITH" NL
+"" Factorial - iterative
+MCSKIP MT,<>
+MCINS %.
+MCDEF FACTORIAL WITHS ()
+AS
+fact(1) is FACTORIAL(1)
+fact(2) is FACTORIAL(2)
+fact(3) is FACTORIAL(3)
+fact(4) is FACTORIAL(4)
diff --git a/Task/Factorial/ML-I/factorial-2.ml b/Task/Factorial/ML-I/factorial-2.ml
new file mode 100644
index 0000000000..ee127745a3
--- /dev/null
+++ b/Task/Factorial/ML-I/factorial-2.ml
@@ -0,0 +1,13 @@
+MCSKIP "WITH" NL
+"" Factorial - recursive
+MCSKIP MT,<>
+MCINS %.
+MCDEF FACTORIAL WITHS ()
+AS MCGO L0
+%L1.%%T1.*FACTORIAL(%T1.-1).>
+fact(1) is FACTORIAL(1)
+fact(2) is FACTORIAL(2)
+fact(3) is FACTORIAL(3)
+fact(4) is FACTORIAL(4)
diff --git a/Task/Factorial/MUMPS/factorial-1.mumps b/Task/Factorial/MUMPS/factorial-1.mumps
new file mode 100644
index 0000000000..6a1339671c
--- /dev/null
+++ b/Task/Factorial/MUMPS/factorial-1.mumps
@@ -0,0 +1,13 @@
+factorial(num) New ii,result
+ If num<0 Quit "Negative number"
+ If num["." Quit "Not an integer"
+ Set result=1 For ii=1:1:num Set result=result*ii
+ Quit result
+
+Write $$factorial(0) ; 1
+Write $$factorial(1) ; 1
+Write $$factorial(2) ; 2
+Write $$factorial(3) ; 6
+Write $$factorial(10) ; 3628800
+Write $$factorial(-6) ; Negative number
+Write $$factorial(3.7) ; Not an integer
diff --git a/Task/Factorial/MUMPS/factorial-2.mumps b/Task/Factorial/MUMPS/factorial-2.mumps
new file mode 100644
index 0000000000..7a08b65698
--- /dev/null
+++ b/Task/Factorial/MUMPS/factorial-2.mumps
@@ -0,0 +1,13 @@
+factorial(num) ;
+ If num<0 Quit "Negative number"
+ If num["." Quit "Not an integer"
+ If num<2 Quit 1
+ Quit num*$$factorial(num-1)
+
+Write $$factorial(0) ; 1
+Write $$factorial(1) ; 1
+Write $$factorial(2) ; 2
+Write $$factorial(3) ; 6
+Write $$factorial(10) ; 3628800
+Write $$factorial(-6) ; Negative number
+Write $$factorial(3.7) ; Not an integer
diff --git a/Task/Factorial/Maple/factorial-1.maple b/Task/Factorial/Maple/factorial-1.maple
new file mode 100644
index 0000000000..33c4c0173f
--- /dev/null
+++ b/Task/Factorial/Maple/factorial-1.maple
@@ -0,0 +1,2 @@
+> 5!;
+ 120
diff --git a/Task/Factorial/Maple/factorial-2.maple b/Task/Factorial/Maple/factorial-2.maple
new file mode 100644
index 0000000000..645dc8bebe
--- /dev/null
+++ b/Task/Factorial/Maple/factorial-2.maple
@@ -0,0 +1,7 @@
+RecFact := proc( n :: nonnegint )
+ if n = 0 or n = 1 then
+ 1
+ else
+ n * thisproc( n - 1 )
+ end if
+end proc:
diff --git a/Task/Factorial/Maple/factorial-3.maple b/Task/Factorial/Maple/factorial-3.maple
new file mode 100644
index 0000000000..59aa0c9dfe
--- /dev/null
+++ b/Task/Factorial/Maple/factorial-3.maple
@@ -0,0 +1,4 @@
+> seq( RecFact( i ) = i!, i = 0 .. 10 );
+1 = 1, 1 = 1, 2 = 2, 6 = 6, 24 = 24, 120 = 120, 720 = 720, 5040 = 5040,
+
+ 40320 = 40320, 362880 = 362880, 3628800 = 3628800
diff --git a/Task/Factorial/Maple/factorial-4.maple b/Task/Factorial/Maple/factorial-4.maple
new file mode 100644
index 0000000000..917a28a0e4
--- /dev/null
+++ b/Task/Factorial/Maple/factorial-4.maple
@@ -0,0 +1,4 @@
+IterFact := proc( n :: nonnegint )
+ local i;
+ mul( i, i = 2 .. n )
+end proc:
diff --git a/Task/Factorial/Maple/factorial-5.maple b/Task/Factorial/Maple/factorial-5.maple
new file mode 100644
index 0000000000..b7938f1b93
--- /dev/null
+++ b/Task/Factorial/Maple/factorial-5.maple
@@ -0,0 +1,4 @@
+> seq( IterFact( i ) = i!, i = 0 .. 10 );
+1 = 1, 1 = 1, 2 = 2, 6 = 6, 24 = 24, 120 = 120, 720 = 720, 5040 = 5040,
+
+ 40320 = 40320, 362880 = 362880, 3628800 = 3628800
diff --git a/Task/Factorial/Mathematica/factorial-1.mathematica b/Task/Factorial/Mathematica/factorial-1.mathematica
new file mode 100644
index 0000000000..a55b09e0ed
--- /dev/null
+++ b/Task/Factorial/Mathematica/factorial-1.mathematica
@@ -0,0 +1,2 @@
+factorial[n_Integer] := n*factorial[n-1]
+factorial[0] = 1
diff --git a/Task/Factorial/Mathematica/factorial-2.mathematica b/Task/Factorial/Mathematica/factorial-2.mathematica
new file mode 100644
index 0000000000..5c2649b671
--- /dev/null
+++ b/Task/Factorial/Mathematica/factorial-2.mathematica
@@ -0,0 +1,2 @@
+factorial[n_Integer] :=
+ Block[{i, result = 1}, For[i = 1, i <= n, ++i, result *= i]; result]
diff --git a/Task/Factorial/Mathematica/factorial-3.mathematica b/Task/Factorial/Mathematica/factorial-3.mathematica
new file mode 100644
index 0000000000..05e3a33d29
--- /dev/null
+++ b/Task/Factorial/Mathematica/factorial-3.mathematica
@@ -0,0 +1 @@
+factorial[n_Integer] := Block[{i}, Times @@ Table[i, {i, n}]]
diff --git a/Task/Factorial/Maxima/factorial-1.maxima b/Task/Factorial/Maxima/factorial-1.maxima
new file mode 100644
index 0000000000..e749da3428
--- /dev/null
+++ b/Task/Factorial/Maxima/factorial-1.maxima
@@ -0,0 +1 @@
+n!
diff --git a/Task/Factorial/Maxima/factorial-2.maxima b/Task/Factorial/Maxima/factorial-2.maxima
new file mode 100644
index 0000000000..5bbf5c92eb
--- /dev/null
+++ b/Task/Factorial/Maxima/factorial-2.maxima
@@ -0,0 +1 @@
+fact(n) := if n < 2 then 1 else n * fact(n - 1)$
diff --git a/Task/Factorial/Maxima/factorial-3.maxima b/Task/Factorial/Maxima/factorial-3.maxima
new file mode 100644
index 0000000000..d6ad798946
--- /dev/null
+++ b/Task/Factorial/Maxima/factorial-3.maxima
@@ -0,0 +1 @@
+fact2(n) := block([r: 1], for i thru n do r: r * i, r)$
diff --git a/Task/Factorial/Mirah/factorial.mirah b/Task/Factorial/Mirah/factorial.mirah
new file mode 100644
index 0000000000..8ca2a74959
--- /dev/null
+++ b/Task/Factorial/Mirah/factorial.mirah
@@ -0,0 +1,8 @@
+def factorial_iterative(n:int)
+ 2.upto(n-1) do |i|
+ n *= i
+ end
+ n
+end
+
+puts factorial_iterative 10
diff --git a/Task/Factorial/Modula-3/factorial-1.mod3 b/Task/Factorial/Modula-3/factorial-1.mod3
new file mode 100644
index 0000000000..4972a60a60
--- /dev/null
+++ b/Task/Factorial/Modula-3/factorial-1.mod3
@@ -0,0 +1,11 @@
+PROCEDURE FactIter(n: CARDINAL): CARDINAL =
+ VAR
+ result := n;
+ counter := n - 1;
+
+ BEGIN
+ FOR i := counter TO 1 BY -1 DO
+ result := result * i;
+ END;
+ RETURN result;
+ END FactIter;
diff --git a/Task/Factorial/Modula-3/factorial-2.mod3 b/Task/Factorial/Modula-3/factorial-2.mod3
new file mode 100644
index 0000000000..87d1b6b204
--- /dev/null
+++ b/Task/Factorial/Modula-3/factorial-2.mod3
@@ -0,0 +1,9 @@
+PROCEDURE FactRec(n: CARDINAL): CARDINAL =
+ VAR result := 1;
+
+ BEGIN
+ IF n > 1 THEN
+ result := n * FactRec(n - 1);
+ END;
+ RETURN result;
+ END FactRec;
diff --git a/Task/Factorial/PHP/factorial-1.php b/Task/Factorial/PHP/factorial-1.php
new file mode 100644
index 0000000000..ee0b0d0d91
--- /dev/null
+++ b/Task/Factorial/PHP/factorial-1.php
@@ -0,0 +1,14 @@
+= 1; $i--) {
+ $factorial = $factorial * $i;
+ }
+
+ return $factorial;
+}
+?>
diff --git a/Task/Factorial/PHP/factorial-2.php b/Task/Factorial/PHP/factorial-2.php
new file mode 100644
index 0000000000..de26d6f4ab
--- /dev/null
+++ b/Task/Factorial/PHP/factorial-2.php
@@ -0,0 +1,15 @@
+
diff --git a/Task/Factorial/PHP/factorial-3.php b/Task/Factorial/PHP/factorial-3.php
new file mode 100644
index 0000000000..878316b7e3
--- /dev/null
+++ b/Task/Factorial/PHP/factorial-3.php
@@ -0,0 +1,3 @@
+
diff --git a/Task/Factorial/PHP/factorial-4.php b/Task/Factorial/PHP/factorial-4.php
new file mode 100644
index 0000000000..072c1d95db
--- /dev/null
+++ b/Task/Factorial/PHP/factorial-4.php
@@ -0,0 +1 @@
+gmp_fact($n)
diff --git a/Task/Factorial/Perl/factorial-1.pl b/Task/Factorial/Perl/factorial-1.pl
new file mode 100644
index 0000000000..ed88223239
--- /dev/null
+++ b/Task/Factorial/Perl/factorial-1.pl
@@ -0,0 +1,17 @@
+sub factorial
+{
+ my $n = shift;
+ my $result = 1;
+ for (my $i = 1; $i <= $n; ++$i)
+ {
+ $result *= $i;
+ };
+ $result;
+}
+
+# using a .. range
+sub factorial {
+ my $r = 1;
+ $r *= $_ for 1..shift;
+ $r;
+}
diff --git a/Task/Factorial/Perl/factorial-2.pl b/Task/Factorial/Perl/factorial-2.pl
new file mode 100644
index 0000000000..a985818bb1
--- /dev/null
+++ b/Task/Factorial/Perl/factorial-2.pl
@@ -0,0 +1,5 @@
+sub factorial
+{
+ my $n = shift;
+ ($n == 0)? 1 : $n*factorial($n-1);
+}
diff --git a/Task/Factorial/Perl/factorial-3.pl b/Task/Factorial/Perl/factorial-3.pl
new file mode 100644
index 0000000000..3469a7206a
--- /dev/null
+++ b/Task/Factorial/Perl/factorial-3.pl
@@ -0,0 +1,6 @@
+use List::Util qw(reduce);
+sub factorial
+{
+ my $n = shift;
+ reduce { $a * $b } 1, 1 .. $n
+}
diff --git a/Task/Factorial/PicoLisp/factorial-1.l b/Task/Factorial/PicoLisp/factorial-1.l
new file mode 100644
index 0000000000..637b2a9c10
--- /dev/null
+++ b/Task/Factorial/PicoLisp/factorial-1.l
@@ -0,0 +1,4 @@
+(de fact (N)
+ (if (=0 N)
+ 1
+ (* N (fact (dec N))) ) )
diff --git a/Task/Factorial/PicoLisp/factorial-2.l b/Task/Factorial/PicoLisp/factorial-2.l
new file mode 100644
index 0000000000..1e8b545cc6
--- /dev/null
+++ b/Task/Factorial/PicoLisp/factorial-2.l
@@ -0,0 +1,2 @@
+(de fact (N)
+ (apply * (range 1 N) )
diff --git a/Task/Factorial/Prolog/factorial-1.pro b/Task/Factorial/Prolog/factorial-1.pro
new file mode 100644
index 0000000000..988bbad858
--- /dev/null
+++ b/Task/Factorial/Prolog/factorial-1.pro
@@ -0,0 +1,2 @@
+fact(X, 1) :- X<2.
+fact(X, F) :- Y is X-1, fact(Y,Z), F is Z*X.
diff --git a/Task/Factorial/Prolog/factorial-2.pro b/Task/Factorial/Prolog/factorial-2.pro
new file mode 100644
index 0000000000..71c8127db5
--- /dev/null
+++ b/Task/Factorial/Prolog/factorial-2.pro
@@ -0,0 +1,8 @@
+fact(N, NF) :-
+ fact(1, N, 1, NF).
+
+fact(X, X, F, F) :- !.
+fact(X, N, FX, F) :-
+ FX1 is FX * X,
+ X1 is X + 1,
+ fact(X1, N, FX1, F).
diff --git a/Task/Factorial/Prolog/factorial-3.pro b/Task/Factorial/Prolog/factorial-3.pro
new file mode 100644
index 0000000000..f15ea94a00
--- /dev/null
+++ b/Task/Factorial/Prolog/factorial-3.pro
@@ -0,0 +1,13 @@
+% foldl(Pred, Init, List, R).
+%
+foldl(_Pred, Val, [], Val).
+foldl(Pred, Val, [H | T], Res) :-
+ call(Pred, Val, H, Val1),
+ foldl(Pred, Val1, T, Res).
+
+% factorial
+p(X, Y, Z) :- Z is X * Y).
+
+fact(X, F) :-
+ numlist(2, X, L),
+ foldl(p, 1, L, F).
diff --git a/Task/Factorial/Prolog/factorial-4.pro b/Task/Factorial/Prolog/factorial-4.pro
new file mode 100644
index 0000000000..7d62ce017c
--- /dev/null
+++ b/Task/Factorial/Prolog/factorial-4.pro
@@ -0,0 +1,12 @@
+:- use_module(lambda).
+
+% foldl(Pred, Init, List, R).
+%
+foldl(_Pred, Val, [], Val).
+foldl(Pred, Val, [H | T], Res) :-
+ call(Pred, Val, H, Val1),
+ foldl(Pred, Val1, T, Res).
+
+fact(N, F) :-
+ numlist(2, N, L),
+ foldl(\X^Y^Z^(Z is X * Y), 1, L, F).
diff --git a/Task/Factorial/Prolog/factorial-5.pro b/Task/Factorial/Prolog/factorial-5.pro
new file mode 100644
index 0000000000..7db88cbfed
--- /dev/null
+++ b/Task/Factorial/Prolog/factorial-5.pro
@@ -0,0 +1,14 @@
+:- use_module(lambda).
+
+fact(N, FN) :-
+ cont_fact(N, FN, \X^Y^(Y = X)).
+
+cont_fact(N, F, Pred) :-
+ ( N = 0 ->
+ call(Pred, 1, F)
+ ; N1 is N - 1,
+
+ P = \Z^T^(T is Z * N),
+ cont_fact(N1, FT, P),
+ call(Pred, FT, F)
+ ).
diff --git a/Task/Factorial/Python/factorial-1.py b/Task/Factorial/Python/factorial-1.py
new file mode 100644
index 0000000000..ff5a65d9e8
--- /dev/null
+++ b/Task/Factorial/Python/factorial-1.py
@@ -0,0 +1,2 @@
+import math
+math.factorial(n)
diff --git a/Task/Factorial/Python/factorial-2.py b/Task/Factorial/Python/factorial-2.py
new file mode 100644
index 0000000000..45f8c61712
--- /dev/null
+++ b/Task/Factorial/Python/factorial-2.py
@@ -0,0 +1,5 @@
+def factorial(n):
+ result = 1
+ for i in range(1, n+1):
+ result *= i
+ return result
diff --git a/Task/Factorial/Python/factorial-3.py b/Task/Factorial/Python/factorial-3.py
new file mode 100644
index 0000000000..4c0d73302c
--- /dev/null
+++ b/Task/Factorial/Python/factorial-3.py
@@ -0,0 +1,4 @@
+from operator import mul
+
+def factorial(n):
+ return reduce(mul, xrange(1,n+1), 1)
diff --git a/Task/Factorial/Python/factorial-4.py b/Task/Factorial/Python/factorial-4.py
new file mode 100644
index 0000000000..e440a26db6
--- /dev/null
+++ b/Task/Factorial/Python/factorial-4.py
@@ -0,0 +1,10 @@
+>>> for i in range(6):
+ print i, factorial(i)
+
+0 1
+1 1
+2 2
+3 6
+4 24
+5 120
+>>>
diff --git a/Task/Factorial/Python/factorial-5.py b/Task/Factorial/Python/factorial-5.py
new file mode 100644
index 0000000000..2e8331bac3
--- /dev/null
+++ b/Task/Factorial/Python/factorial-5.py
@@ -0,0 +1,27 @@
+from cmath import *
+
+# Coefficients used by the GNU Scientific Library
+g = 7
+p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,
+ 771.32342877765313, -176.61502916214059, 12.507343278686905,
+ -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]
+
+def gamma(z):
+ z = complex(z)
+ # Reflection formula
+ if z.real < 0.5:
+ return pi / (sin(pi*z)*gamma(1-z))
+ else:
+ z -= 1
+ x = p[0]
+ for i in range(1, g+2):
+ x += p[i]/(z+i)
+ t = z + g + 0.5
+ return sqrt(2*pi) * t**(z+0.5) * exp(-t) * x
+
+def factorial(n):
+ return gamma(n+1)
+
+print "factorial(-0.5)**2=",factorial(-0.5)**2
+for i in range(10):
+ print "factorial(%d)=%s"%(i,factorial(i))
diff --git a/Task/Factorial/Python/factorial-6.py b/Task/Factorial/Python/factorial-6.py
new file mode 100644
index 0000000000..5bf8836512
--- /dev/null
+++ b/Task/Factorial/Python/factorial-6.py
@@ -0,0 +1,5 @@
+def factorial(n):
+ z=1
+ if n>1:
+ z=n*factorial(n-1)
+ return z
diff --git a/Task/Factorial/R/factorial-1.r b/Task/Factorial/R/factorial-1.r
new file mode 100644
index 0000000000..d8baa8a6d8
--- /dev/null
+++ b/Task/Factorial/R/factorial-1.r
@@ -0,0 +1,4 @@
+fact <- function(n) {
+ if ( n <= 1 ) 1
+ else n * fact(n-1)
+}
diff --git a/Task/Factorial/R/factorial-2.r b/Task/Factorial/R/factorial-2.r
new file mode 100644
index 0000000000..fc3a2ececd
--- /dev/null
+++ b/Task/Factorial/R/factorial-2.r
@@ -0,0 +1,5 @@
+factIter <- function(n) {
+ f = 1
+ for (i in 2:n) f <- f * i
+ f
+}
diff --git a/Task/Factorial/R/factorial-3.r b/Task/Factorial/R/factorial-3.r
new file mode 100644
index 0000000000..7de2679c7f
--- /dev/null
+++ b/Task/Factorial/R/factorial-3.r
@@ -0,0 +1 @@
+print(factorial(50)) # 3.041409e+64
diff --git a/Task/Factorial/REXX/factorial-1.rexx b/Task/Factorial/REXX/factorial-1.rexx
new file mode 100644
index 0000000000..9d45e4c027
--- /dev/null
+++ b/Task/Factorial/REXX/factorial-1.rexx
@@ -0,0 +1,21 @@
+/*REXX program computes the factorial of a non-negative integer. */
+numeric digits 100000 /*100k digs: handles N up to 25k.*/
+parse arg n /*get argument from command line. */
+if n='' then call er 'no argument specified'
+if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
+if \datatype(n,'N') then call er "argument isn't numeric: " n
+if \datatype(n,'W') then call er "argument isn't a whole number: " n
+if n<0 then call er "argument can't be negative: " n
+!=1 /*define factorial product so far.*/
+
+/*══════════════════════════════════════where da rubber meets da road──┐*/
+ do j=2 to n; !=!*j /*compute the ! the hard way◄───┘*/
+ end /*j*/
+/*══════════════════════════════════════════════════════════════════════*/
+
+say n'! is ['length(!) "digits]:" /*display # of digits in factorial*/
+say /*add some whitespace to output. */
+say !/1 /*normalize the factorial product.*/
+exit /*stick a fork in it, we're done. */
+/*─────────────────────────────────ER subroutine────────────────────────*/
+er: say; say '***error!***'; say; say arg(1); say; say; exit 13
diff --git a/Task/Factorial/REXX/factorial-2.rexx b/Task/Factorial/REXX/factorial-2.rexx
new file mode 100644
index 0000000000..1e2a3c0beb
--- /dev/null
+++ b/Task/Factorial/REXX/factorial-2.rexx
@@ -0,0 +1,53 @@
+/*REXX program computes the factorial of a non-negative integer, and */
+/* automatically adjusts the number of digits to accommodate the answer.*/
+/* ┌────────────────────────────────────────────────────────────────┐
+ │ ───── Some factorial lengths ───── │
+ │ │
+ │ 10 ! = 7 digits │
+ │ 20 ! = 19 digits │
+ │ 52 ! = 68 digits │
+ │ 104 ! = 167 digits │
+ │ 208 ! = 394 digits │
+ │ 416 ! = 394 digits (8 deck shoe) │
+ │ │
+ │ 1k ! = 2,568 digits │
+ │ 10k ! = 35,660 digits │
+ │ 100k ! = 456,574 digits │
+ │ │
+ │ 1m ! = 5,565,709 digits │
+ │ 10m ! = 65,657,060 digits │
+ │ 100m ! = 756,570,556 digits │
+ │ │
+ │ Only one result is shown below for pratical reasons. │
+ │ │
+ │ This version of the REXX interpreter is essentially limited │
+ │ to around 8 million digits, but with some programming │
+ │ tricks, it could yield a result up to ≈ 16 million digits. │
+ │ │
+ │ Also, the Regina REXX interpreter is limited to an exponent │
+ │ 9 digits, i.e.: 9.999...999e+999999999 │
+ └────────────────────────────────────────────────────────────────┘ */
+numeric digits 99 /*99 digs initially, then expanded*/
+numeric form /*exponentiated #s =scientric form*/
+parse arg n /*get argument from command line. */
+if n='' then call er 'no argument specified'
+if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
+if \datatype(n,'N') then call er "argument isn't numeric: " n
+if \datatype(n,'W') then call er "argument isn't a whole number: " n
+if n<0 then call er "argument can't be negative: " n
+!=1 /*define factorial product so far.*/
+
+/*══════════════════════════════════════where da rubber meets da road──┐*/
+ do j=2 to n; !=!*j /*compute the ! the hard way◄───┘*/
+ if pos('E',!)==0 then iterate /*is ! in exponential notation? */
+ parse var ! 'E' digs /*pick off the factorial exponent.*/
+ numeric digits digs+digs%10 /* and incease it by ten percent.*/
+ end /*j*/
+/*══════════════════════════════════════════════════════════════════════*/
+
+say n'! is ['length(!) "digits]:" /*display # of digits in factorial*/
+say /*add some whitespace to output. */
+say !/1 /*normalize the factorial product.*/
+exit /*stick a fork in it, we're done. */
+/*─────────────────────────────────ER subroutine────────────────────────*/
+er: say; say '***error!***'; say; say arg(1); say; say; exit 13
diff --git a/Task/Factorial/REXX/factorial-3.rexx b/Task/Factorial/REXX/factorial-3.rexx
new file mode 100644
index 0000000000..7957839124
--- /dev/null
+++ b/Task/Factorial/REXX/factorial-3.rexx
@@ -0,0 +1,34 @@
+/*REXX program computes the factorial of a non-negative integer, and */
+/* automatically adjusts the number of digits to accommodate the answer.*/
+
+/*This version allows for faster multiplying of #s (no trailing zeros).*/
+numeric digits 100 /*start with 100 digits. */
+numeric form /*indicates we want scientric form*/
+parse arg n .; if n=='' then n=0 /*get argument from command line. */
+
+/*════════════════════════════════════where the rubber meets the road. */
+!=1 /*define factorial product so far.*/
+ do j=2 to n /*compute factorial the hard way. */
+ o!=! /*save old ! in case of overflow. */
+ !=!*j /*multiple the factorial with J, */
+ /* and strip all trailing zeroes. */
+ if pos('E',!)\==0 then do /*is ! in exponential notation? */
+ d=digits() /*D is current digs*/
+ numeric digits d+d%10 /*add ten percent. */
+ !=o!*j /*recalculate for the lost digit. */
+ end
+ !=strip(!,'tail-end',0) /*kill some electrons, strip 0's. */
+ end /*(above) only 1st letter is used.*/
+ /*let's perform some housekeeping.*/
+if pos('E',!)\==0 then !=strip(!/1,"T",0) /*! in exponential notation?*/
+v=5; tz=0
+ do while v<=n /*calculate # of trailing zeroes. */
+ tz=tz+n%v
+ v=v*5
+ end /*while v≤n*/
+!=! || copies(0,tz) /*add some water to rehydrate !. */
+/*══════════════════════════════════════════════════════════════════════*/
+
+say n'! is ['length(!) "digits]:" /*display # of digits in factorial*/
+say /*add some whitespace to output, */
+say ! /* ... and display the ! product.*/
diff --git a/Task/Factorial/Racket/factorial-1.rkt b/Task/Factorial/Racket/factorial-1.rkt
new file mode 100644
index 0000000000..81fc7f4703
--- /dev/null
+++ b/Task/Factorial/Racket/factorial-1.rkt
@@ -0,0 +1,4 @@
+(define (factorial n)
+ (if (= 0 n)
+ 1
+ (* n (factorial (- n 1)))))
diff --git a/Task/Factorial/Racket/factorial-2.rkt b/Task/Factorial/Racket/factorial-2.rkt
new file mode 100644
index 0000000000..006508d94b
--- /dev/null
+++ b/Task/Factorial/Racket/factorial-2.rkt
@@ -0,0 +1,6 @@
+(define (factorial n)
+ (define (fact n acc)
+ (if (= 0 n)
+ acc
+ (fact (- n 1) (* n acc))))
+ (fact n 1))
diff --git a/Task/Factorial/Ruby/factorial.rb b/Task/Factorial/Ruby/factorial.rb
new file mode 100644
index 0000000000..17350ea554
--- /dev/null
+++ b/Task/Factorial/Ruby/factorial.rb
@@ -0,0 +1,39 @@
+# Recursive
+def factorial_recursive(n)
+ n.zero? ? 1 : n * factorial_recursive(n - 1)
+end
+
+# Tail-recursive
+def factorial_tail_recursive(n, prod = 1)
+ n.zero? ? prod : factorial_tail_recursive(n - 1, prod * n)
+end
+
+# Iterative with Range#each
+def factorial_iterative(n)
+ (2 .. n - 1).each {|i| n *= i}
+ n
+end
+
+# Iterative with Range#inject
+def factorial_inject(n)
+ (1..n).inject {|prod, i| prod * i}
+end
+
+# Iterative with Range#reduce, requires Ruby 1.8.7
+def factorial_reduce(n)
+ (1..n).reduce(:*)
+end
+
+
+require 'benchmark'
+
+n = 400
+m = 10000
+
+Benchmark.bm(16) do |b|
+ b.report('recursive:') {m.times {factorial_recursive(n)}}
+ b.report('tail recursive:') {m.times {factorial_tail_recursive(n)}}
+ b.report('iterative:') {m.times {factorial_iterative(n)}}
+ b.report('inject:') {m.times {factorial_inject(n)}}
+ b.report('reduce:') {m.times {factorial_reduce(n)}}
+end
diff --git a/Task/Factorial/Sather/factorial.sa b/Task/Factorial/Sather/factorial.sa
new file mode 100644
index 0000000000..3a69b9f1f2
--- /dev/null
+++ b/Task/Factorial/Sather/factorial.sa
@@ -0,0 +1,20 @@
+class MAIN is
+
+ -- recursive
+ fact(a: INTI):INTI is
+ if a < 1.inti then return 1.inti; end;
+ return a * fact(a - 1.inti);
+ end;
+
+ -- iterative
+ fact_iter(a:INTI):INTI is
+ s ::= 1.inti;
+ loop s := s * a.downto!(1.inti); end;
+ return s;
+ end;
+
+ main is
+ a :INTI := 10.inti;
+ #OUT + fact(a) + " = " + fact_iter(a) + "\n";
+ end;
+end;
diff --git a/Task/Factorial/Scala/factorial-1.scala b/Task/Factorial/Scala/factorial-1.scala
new file mode 100644
index 0000000000..d2c66b7055
--- /dev/null
+++ b/Task/Factorial/Scala/factorial-1.scala
@@ -0,0 +1,6 @@
+def factorial(n: Int)={
+ var res = 1
+ for(i <- 1 to n)
+ res *=i
+ res
+}
diff --git a/Task/Factorial/Scala/factorial-2.scala b/Task/Factorial/Scala/factorial-2.scala
new file mode 100644
index 0000000000..21f31bb7f8
--- /dev/null
+++ b/Task/Factorial/Scala/factorial-2.scala
@@ -0,0 +1 @@
+def factorial(n: Int) = if(n == 0) 1 else n * factorial(n-1)
diff --git a/Task/Factorial/Scala/factorial-3.scala b/Task/Factorial/Scala/factorial-3.scala
new file mode 100644
index 0000000000..cf4ecb16c2
--- /dev/null
+++ b/Task/Factorial/Scala/factorial-3.scala
@@ -0,0 +1 @@
+def factorial(n: Int) = (2 to n).foldLeft(1)(_*_)
diff --git a/Task/Factorial/Scala/factorial-4.scala b/Task/Factorial/Scala/factorial-4.scala
new file mode 100644
index 0000000000..0229f8c3e2
--- /dev/null
+++ b/Task/Factorial/Scala/factorial-4.scala
@@ -0,0 +1,5 @@
+// Note use of big integer support in this version
+
+implicit def IntToFac(i : Int) = new {
+ def ! = (2 to i).foldLeft(BigInt(1))(_*_)
+}
diff --git a/Task/Factorial/Scala/factorial-5.scala b/Task/Factorial/Scala/factorial-5.scala
new file mode 100644
index 0000000000..7092a52751
--- /dev/null
+++ b/Task/Factorial/Scala/factorial-5.scala
@@ -0,0 +1,10 @@
+scala> implicit def IntToFac(i : Int) = new {
+ | def ! = (2 to i).foldLeft(BigInt(1))(_*_)
+ | }
+IntToFac: (i: Int)java.lang.Object{def !: scala.math.BigInt}
+
+scala> 20!
+res0: scala.math.BigInt = 2432902008176640000
+
+scala> 100!
+res1: scala.math.BigInt = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
diff --git a/Task/Factorial/Scheme/factorial-1.ss b/Task/Factorial/Scheme/factorial-1.ss
new file mode 100644
index 0000000000..a8dd066343
--- /dev/null
+++ b/Task/Factorial/Scheme/factorial-1.ss
@@ -0,0 +1,4 @@
+(define (factorial n)
+ (if (<= n 0)
+ 1
+ (* n (factorial (- n 1)))))
diff --git a/Task/Factorial/Scheme/factorial-2.ss b/Task/Factorial/Scheme/factorial-2.ss
new file mode 100644
index 0000000000..065b372525
--- /dev/null
+++ b/Task/Factorial/Scheme/factorial-2.ss
@@ -0,0 +1,6 @@
+(define (factorial n)
+ (let loop ((i 1)
+ (accum 1))
+ (if (> i n)
+ accum
+ (loop (+ i 1) (* accum i)))))
diff --git a/Task/Factorial/Scheme/factorial-3.ss b/Task/Factorial/Scheme/factorial-3.ss
new file mode 100644
index 0000000000..ca482efb19
--- /dev/null
+++ b/Task/Factorial/Scheme/factorial-3.ss
@@ -0,0 +1,4 @@
+(define (factorial n)
+ (do ((i 1 (+ i 1))
+ (accum 1 (* accum i)))
+ ((> i n) accum)))
diff --git a/Task/Factorial/Scheme/factorial-4.ss b/Task/Factorial/Scheme/factorial-4.ss
new file mode 100644
index 0000000000..3e179ef9e9
--- /dev/null
+++ b/Task/Factorial/Scheme/factorial-4.ss
@@ -0,0 +1,23 @@
+;Using a generator and a function that apply generated values to a function taking two arguments
+
+;A generator knows commands 'next? and 'next
+(define (range a b)
+(let ((k a))
+(lambda (msg)
+(cond
+ ((eq? msg 'next?) (<= k b))
+ ((eq? msg 'next)
+ (cond
+ ((<= k b) (set! k (+ k 1)) (- k 1))
+ (else 'nothing-left)))))))
+
+;Similar to List.fold_left in OCaml, but uses a generator
+(define (fold fun a gen)
+(let aux ((a a))
+ (if (gen 'next?) (aux (fun a (gen 'next))) a)))
+
+;Now the factorial function
+(define (factorial n) (fold * 1 (range 1 n)))
+
+(factorial 8)
+;40320
diff --git a/Task/Factorial/Smalltalk/factorial-1.st b/Task/Factorial/Smalltalk/factorial-1.st
new file mode 100644
index 0000000000..ad16a599d1
--- /dev/null
+++ b/Task/Factorial/Smalltalk/factorial-1.st
@@ -0,0 +1,13 @@
+Number extend [
+ my_factorial [
+ (self < 2) ifTrue: [ ^1 ]
+ ifFalse: [ |c|
+ c := OrderedCollection new.
+ 2 to: self do: [ :i | c add: i ].
+ ^ (c fold: [ :a :b | a * b ] )
+ ]
+ ]
+].
+
+7 factorial printNl.
+7 my_factorial printNl.
diff --git a/Task/Factorial/Smalltalk/factorial-2.st b/Task/Factorial/Smalltalk/factorial-2.st
new file mode 100644
index 0000000000..a91d22ab71
--- /dev/null
+++ b/Task/Factorial/Smalltalk/factorial-2.st
@@ -0,0 +1,7 @@
+Number extend [
+ my_factorial [
+ self < 0 ifTrue: [ self error: 'my_factorial is defined for natural numbers' ].
+ self isZero ifTrue: [ ^1 ].
+ ^self * ((self - 1) my_factorial)
+ ]
+].
diff --git a/Task/Factorial/Smalltalk/factorial-3.st b/Task/Factorial/Smalltalk/factorial-3.st
new file mode 100644
index 0000000000..a8fe8fe876
--- /dev/null
+++ b/Task/Factorial/Smalltalk/factorial-3.st
@@ -0,0 +1,10 @@
+ |fac|
+
+ fac := [:n |
+ n < 0 ifTrue: [ self error: 'fac is defined for natural numbers' ].
+ n <= 1
+ ifTrue: [ 1 ]
+ ifFalse: [ n * (fac value:(n - 1)) ]
+ ].
+ fac value:1000.
+].
diff --git a/Task/Factorial/Smalltalk/factorial-4.st b/Task/Factorial/Smalltalk/factorial-4.st
new file mode 100644
index 0000000000..01038d5720
--- /dev/null
+++ b/Task/Factorial/Smalltalk/factorial-4.st
@@ -0,0 +1,4 @@
+| fac |
+fac := [ :n | (1 to: n) inject: 1 into: [ :prod :next | prod * next ] ].
+fac value: 10.
+"3628800"
diff --git a/Task/Factorial/Tcl/factorial-1.tcl b/Task/Factorial/Tcl/factorial-1.tcl
new file mode 100644
index 0000000000..8220088fdf
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-1.tcl
@@ -0,0 +1,6 @@
+proc ifact n {
+ for {set i $n; set sum 1} {$i >= 2} {incr i -1} {
+ set sum [expr {$sum * $i}]
+ }
+ return $sum
+}
diff --git a/Task/Factorial/Tcl/factorial-2.tcl b/Task/Factorial/Tcl/factorial-2.tcl
new file mode 100644
index 0000000000..40cc360692
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-2.tcl
@@ -0,0 +1,3 @@
+proc rfact n {
+ expr {$n < 2 ? 1 : $n * [rfact [incr n -1]]}
+}
diff --git a/Task/Factorial/Tcl/factorial-3.tcl b/Task/Factorial/Tcl/factorial-3.tcl
new file mode 100644
index 0000000000..e25b3f18c7
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-3.tcl
@@ -0,0 +1 @@
+proc tcl::mathfunc::fact n {expr {$n < 2? 1: $n*fact($n-1)}}
diff --git a/Task/Factorial/Tcl/factorial-4.tcl b/Task/Factorial/Tcl/factorial-4.tcl
new file mode 100644
index 0000000000..9a9a02de85
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-4.tcl
@@ -0,0 +1,17 @@
+proc ifact_caching n {
+ global fact_cache
+ if { ! [info exists fact_cache]} {
+ set fact_cache {1 1}
+ }
+ if {$n < [llength $fact_cache]} {
+ return [lindex $fact_cache $n]
+ }
+ set i [expr {[llength $fact_cache] - 1}]
+ set sum [lindex $fact_cache $i]
+ while {$i < $n} {
+ incr i
+ set sum [expr {$sum * $i}]
+ lappend fact_cache $sum
+ }
+ return $sum
+}
diff --git a/Task/Factorial/Tcl/factorial-5.tcl b/Task/Factorial/Tcl/factorial-5.tcl
new file mode 100644
index 0000000000..ecdfbe5752
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-5.tcl
@@ -0,0 +1,11 @@
+puts [ifact 30]
+puts [rfact 30]
+puts [ifact_caching 30]
+
+set n 400
+set iterations 10000
+puts "calculate $n factorial $iterations times"
+puts "ifact: [time {ifact $n} $iterations]"
+puts "rfact: [time {rfact $n} $iterations]"
+# for the caching proc, reset the cache between each iteration so as not to skew the results
+puts "ifact_caching: [time {ifact_caching $n; unset -nocomplain fact_cache} $iterations]"
diff --git a/Task/Factorial/Tcl/factorial-6.tcl b/Task/Factorial/Tcl/factorial-6.tcl
new file mode 100644
index 0000000000..46e5e0fcab
--- /dev/null
+++ b/Task/Factorial/Tcl/factorial-6.tcl
@@ -0,0 +1,5 @@
+package require math::special
+
+proc gfact n {
+ expr {round([::math::special::Gamma [expr {$n+1}]])}
+}
diff --git a/Task/Factors-of-a-Mersenne-number/0DESCRIPTION b/Task/Factors-of-a-Mersenne-number/0DESCRIPTION
new file mode 100644
index 0000000000..5f89db5f47
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/0DESCRIPTION
@@ -0,0 +1,17 @@
+A Mersenne number is a number in the form of 2P-1. If P is prime, the Mersenne number may be a Mersenne prime (if P is not prime, the Mersenne number is also not prime). In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, [[Lucas-Lehmer test]]. There are very efficient algorithms for determining if a number divides 2P-1 (or equivalently, if 2P mod (the number) = 1). Some languages already have built-in implementations of this exponent-and-mod operation (called ''modPow'' or similar). The following is how to implement this ''modPow'' yourself:
+
+For example, let's compute 223 mod 47. Convert the exponent 23 to binary, you get 10111. Starting with square = 1, repeatedly square it. Remove the top bit of the exponent, and if it's 1 multiply square by the base of the exponentiation (2), then compute square modulo 47. Use the result of the modulo from the last step as the initial value of square in the next step:
+ Remove Optional
+ square top bit multiply by 2 mod 47
+ ------------ ------- ------------- ------
+ 1*1 = 1 1 0111 1*2 = 2 2
+ 2*2 = 4 0 111 no 4
+ 4*4 = 16 1 11 16*2 = 32 32
+ 32*32 = 1024 1 1 1024*2 = 2048 27
+ 27*27 = 729 1 729*2 = 1458 1
+
+Since 223 mod 47 = 1, 47 is a factor of 2P-1. (To see this, subtract 1 from both sides: 223-1 = 0 mod 47.) Since we've shown that 47 is a factor, 223-1 is not prime. Further properties of Mersenne numbers allow us to refine the process even more. Any factor q of 2P-1 must be of the form 2kP+1, k being a positive integer or zero. Furthermore, q must be 1 or 7 mod 8. Finally any potential factor q must be [[Primality by Trial Division|prime]]. As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N).
+
+These primality tests only work on Mersenne numbers where P is prime. For example, M4=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.
+
+'''Task:''' Using the above method find a factor of 2929-1 (aka M929)
diff --git a/Task/Factors-of-a-Mersenne-number/1META.yaml b/Task/Factors-of-a-Mersenne-number/1META.yaml
new file mode 100644
index 0000000000..fdeafd347e
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/1META.yaml
@@ -0,0 +1,4 @@
+---
+category:
+- Arithmetic operations
+note: Prime Numbers
diff --git a/Task/Factors-of-a-Mersenne-number/ALGOL-68/factors-of-a-mersenne-number.alg b/Task/Factors-of-a-Mersenne-number/ALGOL-68/factors-of-a-mersenne-number.alg
new file mode 100644
index 0000000000..9f30ef2f6f
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/ALGOL-68/factors-of-a-mersenne-number.alg
@@ -0,0 +1,51 @@
+MODE ISPRIMEINT = INT;
+PR READ "prelude/is_prime.a68" PR;
+
+MODE POWMODSTRUCT = INT;
+PR READ "prelude/pow_mod.a68" PR;
+
+PROC m factor = (INT p)INT:BEGIN
+ INT m factor;
+ INT max k, msb, n, q;
+
+ FOR i FROM bits width - 2 BY -1 TO 0 WHILE ( BIN p SHR i AND 2r1 ) = 2r0 DO
+ msb := i
+ OD;
+
+ max k := ENTIER sqrt(max int) OVER p; # limit for k to prevent overflow of max int #
+ FOR k FROM 1 TO max k DO
+ q := 2*p*k + 1;
+ IF NOT is prime(q) THEN
+ SKIP
+ ELIF q MOD 8 /= 1 AND q MOD 8 /= 7 THEN
+ SKIP
+ ELSE
+ n := pow mod(2,p,q);
+ IF n = 1 THEN
+ m factor := q;
+ return
+ FI
+ FI
+ OD;
+ m factor := 0;
+ return:
+ m factor
+END;
+
+BEGIN
+
+ INT exponent, factor;
+ print("Enter exponent of Mersenne number:");
+ read(exponent);
+ IF NOT is prime(exponent) THEN
+ print(("Exponent is not prime: ", exponent, new line))
+ ELSE
+ factor := m factor(exponent);
+ IF factor = 0 THEN
+ print(("No factor found for M", exponent, new line))
+ ELSE
+ print(("M", exponent, " has a factor: ", factor, new line))
+ FI
+ FI
+
+END
diff --git a/Task/Factors-of-a-Mersenne-number/Ada/factors-of-a-mersenne-number.ada b/Task/Factors-of-a-Mersenne-number/Ada/factors-of-a-mersenne-number.ada
new file mode 100644
index 0000000000..3a8772ee0c
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Ada/factors-of-a-mersenne-number.ada
@@ -0,0 +1,68 @@
+with Ada.Text_IO;
+-- reuse Is_Prime from [[Primality by Trial Division]]
+with Is_Prime;
+
+procedure Mersenne is
+ function Is_Set (Number : Natural; Bit : Positive) return Boolean is
+ begin
+ return Number / 2 ** (Bit - 1) mod 2 = 1;
+ end Is_Set;
+
+ function Get_Max_Bit (Number : Natural) return Natural is
+ Test : Natural := 0;
+ begin
+ while 2 ** Test <= Number loop
+ Test := Test + 1;
+ end loop;
+ return Test;
+ end Get_Max_Bit;
+
+ function Modular_Power (Base, Exponent, Modulus : Positive) return Natural is
+ Maximum_Bit : constant Natural := Get_Max_Bit (Exponent);
+ Square : Natural := 1;
+ begin
+ for Bit in reverse 1 .. Maximum_Bit loop
+ Square := Square ** 2;
+ if Is_Set (Exponent, Bit) then
+ Square := Square * Base;
+ end if;
+ Square := Square mod Modulus;
+ end loop;
+ return Square;
+ end Modular_Power;
+
+ Not_A_Prime_Exponent : exception;
+
+ function Get_Factor (Exponent : Positive) return Natural is
+ Factor : Positive;
+ begin
+ if not Is_Prime (Exponent) then
+ raise Not_A_Prime_Exponent;
+ end if;
+ for K in 1 .. 16384 / Exponent loop
+ Factor := 2 * K * Exponent + 1;
+ if Factor mod 8 = 1 or else Factor mod 8 = 7 then
+ if Is_Prime (Factor) and then Modular_Power (2, Exponent, Factor) = 1 then
+ return Factor;
+ end if;
+ end if;
+ end loop;
+ return 0;
+ end Get_Factor;
+
+ To_Test : constant Positive := 929;
+ Factor : Natural;
+begin
+ Ada.Text_IO.Put ("2 **" & Integer'Image (To_Test) & " - 1 ");
+ begin
+ Factor := Get_Factor (To_Test);
+ if Factor = 0 then
+ Ada.Text_IO.Put_Line ("is prime.");
+ else
+ Ada.Text_IO.Put_Line ("has factor" & Integer'Image (Factor));
+ end if;
+ exception
+ when Not_A_Prime_Exponent =>
+ Ada.Text_IO.Put_Line ("is not a Mersenne number");
+ end;
+end Mersenne;
diff --git a/Task/Factors-of-a-Mersenne-number/AutoHotkey/factors-of-a-mersenne-number.ahk b/Task/Factors-of-a-Mersenne-number/AutoHotkey/factors-of-a-mersenne-number.ahk
new file mode 100644
index 0000000000..f4eba05ecb
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/AutoHotkey/factors-of-a-mersenne-number.ahk
@@ -0,0 +1,56 @@
+MsgBox % MFact(27) ;-1: 27 is not prime
+MsgBox % MFact(2) ; 0
+MsgBox % MFact(3) ; 0
+MsgBox % MFact(5) ; 0
+MsgBox % MFact(7) ; 0
+MsgBox % MFact(11) ; 23
+MsgBox % MFact(13) ; 0
+MsgBox % MFact(17) ; 0
+MsgBox % MFact(19) ; 0
+MsgBox % MFact(23) ; 47
+MsgBox % MFact(29) ; 233
+MsgBox % MFact(31) ; 0
+MsgBox % MFact(37) ; 223
+MsgBox % MFact(41) ; 13367
+MsgBox % MFact(43) ; 431
+MsgBox % MFact(47) ; 2351
+MsgBox % MFact(53) ; 6361
+MsgBox % MFact(929) ; 13007
+
+MFact(p) { ; blank if 2**p-1 can be prime, otherwise a prime divisor < 2**32
+ If !IsPrime32(p)
+ Return -1 ; Error (p must be prime)
+ Loop % 2.0**(p<64 ? p/2-1 : 31)/p ; test prime divisors < 2**32, up to sqrt(2**p-1)
+ If (((q:=2*p*A_Index+1)&7 = 1 || q&7 = 7) && IsPrime32(q) && PowMod(2,p,q)=1)
+ Return q
+ Return 0
+}
+
+IsPrime32(n) { ; n < 2**32
+ If n in 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
+ Return 1
+ If (!(n&1)||!mod(n,3)||!mod(n,5)||!mod(n,7)||!mod(n,11)||!mod(n,13)||!mod(n,17)||!mod(n,19))
+ Return 0
+ n1 := d := n-1, s := 0
+ While !(d&1)
+ d>>=1, s++
+ Loop 3 {
+ x := PowMod( A_Index=1 ? 2 : A_Index=2 ? 7 : 61, d, n)
+ If (x=1 || x=n1)
+ Continue
+ Loop % s-1
+ If (1 = x:=PowMod(x,2,n))
+ Return 0
+ Else If (x = n1)
+ Break
+ IfLess x,%n1%, Return 0
+ }
+ Return 1
+}
+
+PowMod(x,n,m) { ; x**n mod m
+ y := 1, i := n, z := x
+ While i>0
+ y := i&1 ? mod(y*z,m) : y, z := mod(z*z,m), i >>= 1
+ Return y
+}
diff --git a/Task/Factors-of-a-Mersenne-number/BBC-BASIC/factors-of-a-mersenne-number.bbc b/Task/Factors-of-a-Mersenne-number/BBC-BASIC/factors-of-a-mersenne-number.bbc
new file mode 100644
index 0000000000..a2f7270f45
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/BBC-BASIC/factors-of-a-mersenne-number.bbc
@@ -0,0 +1,37 @@
+ PRINT "A factor of M929 is "; FNmersenne_factor(929)
+ PRINT "A factor of M937 is "; FNmersenne_factor(937)
+ END
+
+ DEF FNmersenne_factor(P%)
+ LOCAL K%, Q%
+ IF NOT FNisprime(P%) THEN = -1
+ FOR K% = 1 TO 1000000
+ Q% = 2*K%*P% + 1
+ IF (Q% AND 7) = 1 OR (Q% AND 7) = 7 THEN
+ IF FNisprime(Q%) IF FNmodpow(2, P%, Q%) = 1 THEN = Q%
+ ENDIF
+ NEXT K%
+ = 0
+
+ DEF FNisprime(N%)
+ LOCAL D%
+ IF N% MOD 2=0 THEN = (N% = 2)
+ IF N% MOD 3=0 THEN = (N% = 3)
+ D% = 5
+ WHILE D% * D% <= N%
+ IF N% MOD D% = 0 THEN = FALSE
+ D% += 2
+ IF N% MOD D% = 0 THEN = FALSE
+ D% += 4
+ ENDWHILE
+ = TRUE
+
+ DEF FNmodpow(X%, N%, M%)
+ LOCAL I%, Y%, Z%
+ I% = N% : Y% = 1 : Z% = X%
+ WHILE I%
+ IF I% AND 1 THEN Y% = (Y% * Z%) MOD M%
+ Z% = (Z% * Z%) MOD M%
+ I% = I% >>> 1
+ ENDWHILE
+ = Y%
diff --git a/Task/Factors-of-a-Mersenne-number/C-sharp/factors-of-a-mersenne-number.cs b/Task/Factors-of-a-Mersenne-number/C-sharp/factors-of-a-mersenne-number.cs
new file mode 100644
index 0000000000..d5d65d1d81
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/C-sharp/factors-of-a-mersenne-number.cs
@@ -0,0 +1,46 @@
+using System;
+
+namespace prog
+{
+ class MainClass
+ {
+ public static void Main (string[] args)
+ {
+ int q = 929;
+ if ( !isPrime(q) ) return;
+ int r = q;
+ while( r > 0 )
+ r <<= 1;
+ int d = 2 * q + 1;
+ do
+ {
+ int i = 1;
+ for( int p=r; p!=0; p<<=1 )
+ {
+ i = (i*i) % d;
+ if (p < 0) i *= 2;
+ if (i > d) i -= d;
+ }
+ if (i != 1) d += 2 * q; else break;
+ }
+ while(true);
+
+ Console.WriteLine("2^"+q+"-1 = 0 (mod "+d+")");
+ }
+
+ static bool isPrime(int n)
+ {
+ if ( n % 2 == 0 ) return n == 2;
+ if ( n % 3 == 0 ) return n == 3;
+ int d = 5;
+ while( d*d <= n )
+ {
+ if ( n % d == 0 ) return false;
+ d += 2;
+ if ( n % d == 0 ) return false;
+ d += 4;
+ }
+ return true;
+ }
+ }
+}
diff --git a/Task/Factors-of-a-Mersenne-number/C/factors-of-a-mersenne-number.c b/Task/Factors-of-a-Mersenne-number/C/factors-of-a-mersenne-number.c
new file mode 100644
index 0000000000..3705c02064
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/C/factors-of-a-mersenne-number.c
@@ -0,0 +1,24 @@
+int isPrime(int n){
+ if (n%2==0) return n==2;
+ if (n%3==0) return n==3;
+ int d=5;
+ while(d*d<=n){
+ if(n%d==0) return 0;
+ d+=2;
+ if(n%d==0) return 0;
+ d+=4;}
+ return 1;}
+
+main() {int i,d,p,r,q=929;
+ if (!isPrime(q)) return 1;
+ r=q;
+ while(r>0) r<<=1;
+ d=2*q+1;
+ do { for(p=r, i= 1; p; p<<= 1){
+ i=((long long)i * i) % d;
+ if (p < 0) i *= 2;
+ if (i > d) i -= d;}
+ if (i != 1) d += 2*q;
+ else break;
+ } while(1);
+ printf("2^%d - 1 = 0 (mod %d)\n", q, d);}
diff --git a/Task/Factors-of-a-Mersenne-number/CoffeeScript/factors-of-a-mersenne-number.coffee b/Task/Factors-of-a-Mersenne-number/CoffeeScript/factors-of-a-mersenne-number.coffee
new file mode 100644
index 0000000000..32796d2cfb
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/CoffeeScript/factors-of-a-mersenne-number.coffee
@@ -0,0 +1,27 @@
+mersenneFactor = (p) ->
+ limit = Math.sqrt(Math.pow(2,p) - 1)
+ k = 1
+ while (2*k*p - 1) < limit
+ q = 2*k*p + 1
+ if isPrime(q) and (q % 8 == 1 or q % 8 == 7) and trialFactor(2,p,q)
+ return q
+ k++
+ return null
+
+isPrime = (value) ->
+ for i in [2...value]
+ return false if value % i == 0
+ return true if value % i != 0
+
+trialFactor = (base, exp, mod) ->
+ square = 1
+ bits = exp.toString(2).split('')
+ for bit in bits
+ square = Math.pow(square, 2) * (if +bit is 1 then base else 1) % mod
+ return square == 1
+
+checkMersenne = (p) ->
+ factor = mersenneFactor(+p)
+ console.log "M#{p} = 2^#{p}-1 is #{if factor is null then "prime" else "composite with #{factor}"}"
+
+checkMersenne(prime) for prime in ["2","3","4","5","7","11","13","17","19","23","29","31","37","41","43","47","53","929"]
diff --git a/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-1.lisp b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-1.lisp
new file mode 100644
index 0000000000..1e9a6a8882
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-1.lisp
@@ -0,0 +1,7 @@
+(defun mersenne-fac (p &aux (m (1- (expt 2 p))))
+ (loop for k from 1
+ for n = (1+ (* 2 k p))
+ until (zerop (mod m n))
+ finally (return n)))
+
+(print (mersenne-fac 929))
diff --git a/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-2.lisp b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-2.lisp
new file mode 100644
index 0000000000..d233bc737b
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-2.lisp
@@ -0,0 +1,14 @@
+(defun primep (a)
+ (cond ((= a 2) T)
+ ((or (<= a 1) (= (mod a 2) 0)) nil)
+ ((loop for i from 3 to (sqrt a) by 2 do
+ (if (= (mod a i) 0)
+ (return nil))) nil)
+ (T T)))
+
+(defun primep (n)
+ "Is N prime?"
+ (and (> n 1)
+ (or (= n 2) (oddp n))
+ (loop for i from 3 to (isqrt n) by 2
+ never (zerop (rem n i)))))
diff --git a/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-3.lisp b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-3.lisp
new file mode 100644
index 0000000000..cc1378bc93
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Common-Lisp/factors-of-a-mersenne-number-3.lisp
@@ -0,0 +1,19 @@
+(defun modulo-power (base power modulus)
+ (loop with square = 1
+ for bit across (format nil "~b" power)
+ do (setf square (* square square))
+ when (char= bit #\1) do (setf square (* square base))
+ do (setf square (mod square modulus))
+ finally (return square)))
+
+(defun mersenne-prime-p (power)
+ (do* ((N (1- (expt 2 power)))
+ (sqN (isqrt N))
+ (k 1 (1+ k))
+ (q (1+ (* 2 power k)) (1+ (* 2 power k)))
+ (m (mod q 8) (mod q 8)))
+ ((> q sqN) (values t))
+ (when (and (or (= 1 m) (= 7 m))
+ (primep q)
+ (= 1 (modulo-power 2 power q)))
+ (return (values nil q)))))
diff --git a/Task/Factors-of-a-Mersenne-number/D/factors-of-a-mersenne-number.d b/Task/Factors-of-a-Mersenne-number/D/factors-of-a-mersenne-number.d
new file mode 100644
index 0000000000..2846eeea76
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/D/factors-of-a-mersenne-number.d
@@ -0,0 +1,36 @@
+import std.stdio, std.math, std.traits;
+
+ulong mersenneFactor(in ulong p) pure nothrow {
+ static bool isPrime(T)(in T n) pure nothrow {
+ if (n < 2 || n % 2 == 0)
+ return n == 2;
+ for (Unqual!T i = 3; i ^^ 2 <= n; i += 2)
+ if (n % i == 0)
+ return false;
+ return true;
+ }
+
+ static long modPow(in long cb,in long ce,in long m) pure nothrow {
+ long b = cb;
+ long result = 1;
+ for (long e = ce; e > 0; e >>= 1) {
+ if ((e & 1) == 1)
+ result = (result * b) % m;
+ b = (b ^^ 2) % m;
+ }
+ return result;
+ }
+
+ immutable ulong limit = cast(ulong)sqrt(cast(real)(2 ^^ p - 1));
+ for (ulong k = 1; (2 * p * k - 1) < limit; k++) {
+ immutable ulong q = 2 * p * k + 1;
+ if (isPrime(q) && (q % 8 == 1 || q % 8 == 7) &&
+ modPow(2, p, q) == 1)
+ return q;
+ }
+ return 0;
+}
+
+void main() {
+ writefln("Factor of M929: %s", mersenneFactor(929));
+}
diff --git a/Task/Factors-of-a-Mersenne-number/Forth/factors-of-a-mersenne-number.fth b/Task/Factors-of-a-Mersenne-number/Forth/factors-of-a-mersenne-number.fth
new file mode 100644
index 0000000000..79feec96bf
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Forth/factors-of-a-mersenne-number.fth
@@ -0,0 +1,33 @@
+: prime? ( odd -- ? )
+ 3
+ begin 2dup dup * >=
+ while 2dup mod 0=
+ if 2drop false exit
+ then 2 +
+ repeat 2drop true ;
+
+: 2-exp-mod { e m -- 2^e mod m }
+ 1
+ 0 30 do
+ e 1 i lshift >= if
+ dup *
+ e 1 i lshift and if 2* then
+ m mod
+ then
+ -1 +loop ;
+
+: factor-mersenne ( exponent -- factor )
+ 16384 over / dup 2 < abort" Exponent too large!"
+ 1 do
+ dup i * 2* 1+ ( q )
+ dup prime? if
+ dup 7 and dup 1 = swap 7 = or if
+ 2dup 2-exp-mod 1 = if
+ nip unloop exit
+ then
+ then
+ then drop
+ loop drop 0 ;
+
+ 929 factor-mersenne . \ 13007
+4423 factor-mersenne . \ 0
diff --git a/Task/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.f b/Task/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.f
new file mode 100644
index 0000000000..334db9efdc
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.f
@@ -0,0 +1,52 @@
+PROGRAM EXAMPLE
+ IMPLICIT NONE
+ INTEGER :: exponent, factor
+
+ WRITE(*,*) "Enter exponent of Mersenne number"
+ READ(*,*) exponent
+ factor = Mfactor(exponent)
+ IF (factor == 0) THEN
+ WRITE(*,*) "No Factor found"
+ ELSE
+ WRITE(*,"(A,I0,A,I0)") "M", exponent, " has a factor: ", factor
+ END IF
+
+CONTAINS
+
+FUNCTION isPrime(number)
+! code omitted - see [[Primality by Trial Division]]
+END FUNCTION
+
+FUNCTION Mfactor(p)
+ INTEGER :: Mfactor
+ INTEGER, INTENT(IN) :: p
+ INTEGER :: i, k, maxk, msb, n, q
+
+ DO i = 30, 0 , -1
+ IF(BTEST(p, i)) THEN
+ msb = i
+ EXIT
+ END IF
+ END DO
+
+ maxk = 16384 / p ! limit for k to prevent overflow of 32 bit signed integer
+ DO k = 1, maxk
+ q = 2*p*k + 1
+ IF (.NOT. isPrime(q)) CYCLE
+ IF (MOD(q, 8) /= 1 .AND. MOD(q, 8) /= 7) CYCLE
+ n = 1
+ DO i = msb, 0, -1
+ IF (BTEST(p, i)) THEN
+ n = MOD(n*n*2, q)
+ ELSE
+ n = MOD(n*n, q)
+ ENDIF
+ END DO
+ IF (n == 1) THEN
+ Mfactor = q
+ RETURN
+ END IF
+ END DO
+ Mfactor = 0
+END FUNCTION
+END PROGRAM EXAMPLE
diff --git a/Task/Factors-of-a-Mersenne-number/GAP/factors-of-a-mersenne-number.gap b/Task/Factors-of-a-Mersenne-number/GAP/factors-of-a-mersenne-number.gap
new file mode 100644
index 0000000000..2b479a025e
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/GAP/factors-of-a-mersenne-number.gap
@@ -0,0 +1,29 @@
+MersenneSmallFactor := function(n)
+ local k, m;
+ if IsPrime(n) then
+ for k in [1 .. 1000000] do
+ m := 2*k*n + 1;
+ if PowerModInt(2, n, m) = 1 then
+ return m;
+ fi;
+ od;
+ fi;
+ return fail;
+end;
+
+# If n is not prime, fail immediately
+MersenneSmallFactor(15);
+# fail
+
+MersenneSmallFactor(929);
+# 13007
+
+MersenneSmallFactor(1009);
+# 3454817
+
+# We stop at k = 1000000 in 2*k*n + 1, so it may fail if 2^n - 1 has only large factors
+MersenneSmallFactor(101);
+# fail
+
+FactorsInt(2^101-1);
+# [ 7432339208719, 341117531003194129 ]
diff --git a/Task/Factors-of-a-Mersenne-number/Go/factors-of-a-mersenne-number.go b/Task/Factors-of-a-Mersenne-number/Go/factors-of-a-mersenne-number.go
new file mode 100644
index 0000000000..36f7231dbd
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Go/factors-of-a-mersenne-number.go
@@ -0,0 +1,81 @@
+package main
+
+import (
+ "fmt"
+ "math"
+)
+
+// limit search to small primes. really this is higher than
+// you'd want it, but it's fun to factor M67.
+const qlimit = 2e8
+
+func main() {
+ mtest(31)
+ mtest(67)
+ mtest(929)
+}
+
+func mtest(m int32) {
+ // the function finds odd prime factors by
+ // searching no farther than sqrt(N), where N = 2^m-1.
+ // the first odd prime is 3, 3^2 = 9, so M3 = 7 is still too small.
+ // M4 = 15 is first number for which test is meaningful.
+ if m < 4 {
+ fmt.Printf("%d < 4. M%d not tested.\n", m, m)
+ return
+ }
+ flimit := math.Sqrt(math.Pow(2, float64(m)) - 1)
+ var qlast int32
+ if flimit < qlimit {
+ qlast = int32(flimit)
+ } else {
+ qlast = qlimit
+ }
+ composite := make([]bool, qlast+1)
+ sq := int32(math.Sqrt(float64(qlast)))
+loop:
+ for q := int32(3); ; {
+ if q <= sq {
+ for i := q * q; i <= qlast; i += q {
+ composite[i] = true
+ }
+ }
+ if q8 := q % 8; (q8 == 1 || q8 == 7) && modPow(2, m, q) == 1 {
+ fmt.Printf("M%d has factor %d\n", m, q)
+ return
+ }
+ for {
+ q += 2
+ if q > qlast {
+ break loop
+ }
+ if !composite[q] {
+ break
+ }
+ }
+ }
+ fmt.Printf("No factors of M%d found.\n", m)
+}
+
+// base b to power p, mod m
+func modPow(b, p, m int32) int32 {
+ pow := int64(1)
+ b64 := int64(b)
+ m64 := int64(m)
+ bit := uint(30)
+ for 1< if x==0 then Nothing
+ else Just ((uncurry.flip$(,))$divMod x 2))
+
+trialfac m = take 1. dropWhile ((/=1).(\q -> foldl (((`mod` q).).pm) 1 bs)) $ qs
+ where qs = filter (liftM2 (&&) (liftM2 (||) (==1) (==7) .(`mod`8)) isPrime ).
+ map (succ.(2*m*)). enumFromTo 1 $ m `div` 2
+ bs = int2bin m
+ pm n b = 2^b*n*n
diff --git a/Task/Factors-of-a-Mersenne-number/Haskell/factors-of-a-mersenne-number-2.hs b/Task/Factors-of-a-Mersenne-number/Haskell/factors-of-a-mersenne-number-2.hs
new file mode 100644
index 0000000000..f62fb65a75
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Haskell/factors-of-a-mersenne-number-2.hs
@@ -0,0 +1,2 @@
+*Main> trialfac 929
+[13007]
diff --git a/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-1.j b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-1.j
new file mode 100644
index 0000000000..dc2a49c451
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-1.j
@@ -0,0 +1,4 @@
+trialfac=: 3 : 0
+ qs=. (#~8&(1=|+.7=|))(#~1&p:)1+(*(1x+i.@<:@<.)&.-:)y
+ qs#~1=qs&|@(2&^@[**:@])/ 1,~ |.#: y
+)
diff --git a/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-2.j b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-2.j
new file mode 100644
index 0000000000..959369b4e1
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-2.j
@@ -0,0 +1,2 @@
+trialfac 929
+13007
diff --git a/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-3.j b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-3.j
new file mode 100644
index 0000000000..0a8b4590eb
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/J/factors-of-a-mersenne-number-3.j
@@ -0,0 +1 @@
+trialfac 44497
diff --git a/Task/Factors-of-a-Mersenne-number/Java/factors-of-a-mersenne-number.java b/Task/Factors-of-a-Mersenne-number/Java/factors-of-a-mersenne-number.java
new file mode 100644
index 0000000000..7fd07df54a
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Java/factors-of-a-mersenne-number.java
@@ -0,0 +1,68 @@
+import java.math.BigInteger;
+
+class MersenneFactorCheck
+{
+
+ private final static BigInteger TWO = BigInteger.valueOf(2);
+
+ public static boolean isPrime(long n)
+ {
+ if (n == 2)
+ return true;
+ if ((n < 2) || ((n & 1) == 0))
+ return false;
+ long maxFactor = (long)Math.sqrt((double)n);
+ for (long possibleFactor = 3; possibleFactor <= maxFactor; possibleFactor += 2)
+ if ((n % possibleFactor) == 0)
+ return false;
+ return true;
+ }
+
+ public static BigInteger findFactorMersenneNumber(int primeP)
+ {
+ if (primeP <= 0)
+ throw new IllegalArgumentException();
+ BigInteger bigP = BigInteger.valueOf(primeP);
+ BigInteger m = BigInteger.ONE.shiftLeft(primeP).subtract(BigInteger.ONE);
+ // There are more complicated ways of getting closer to sqrt(), but not that important here, so go with simple
+ BigInteger maxFactor = BigInteger.ONE.shiftLeft((primeP + 1) >>> 1);
+ BigInteger twoP = BigInteger.valueOf(primeP << 1);
+ BigInteger possibleFactor = BigInteger.ONE;
+ int possibleFactorBits12 = 0;
+ int twoPBits12 = primeP & 3;
+
+ while ((possibleFactor = possibleFactor.add(twoP)).compareTo(maxFactor) <= 0)
+ {
+ possibleFactorBits12 = (possibleFactorBits12 + twoPBits12) & 3;
+ // "Furthermore, q must be 1 or 7 mod 8". We know it's odd due to the +1 done above, so bit 0 is set. Therefore, we only care about bits 1 and 2 equaling 00 or 11
+ if ((possibleFactorBits12 == 0) || (possibleFactorBits12 == 3))
+ if (TWO.modPow(bigP, possibleFactor).equals(BigInteger.ONE))
+ return possibleFactor;
+ }
+ return null;
+ }
+
+ public static void checkMersenneNumber(int p)
+ {
+ if (!isPrime(p))
+ {
+ System.out.println("M" + p + " is not prime");
+ return;
+ }
+ BigInteger factor = findFactorMersenneNumber(p);
+ if (factor == null)
+ System.out.println("M" + p + " is prime");
+ else
+ System.out.println("M" + p + " is not prime, has factor " + factor);
+ return;
+ }
+
+ public static void main(String[] args)
+ {
+ for (int p = 1; p <= 50; p++)
+ checkMersenneNumber(p);
+ checkMersenneNumber(929);
+ return;
+ }
+
+}
diff --git a/Task/Factors-of-a-Mersenne-number/JavaScript/factors-of-a-mersenne-number.js b/Task/Factors-of-a-Mersenne-number/JavaScript/factors-of-a-mersenne-number.js
new file mode 100644
index 0000000000..28f4061419
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/JavaScript/factors-of-a-mersenne-number.js
@@ -0,0 +1,41 @@
+function mersenne_factor(p){
+ var limit, k, q
+ limit = Math.sqrt(Math.pow(2,p) - 1)
+ k = 1
+ while ((2*k*p - 1) < limit){
+ q = 2*k*p + 1
+ if (isPrime(q) && (q % 8 == 1 || q % 8 == 7) && trial_factor(2,p,q)){
+ return q // q is a factor of 2**p-1
+ }
+ k++
+ }
+ return null
+}
+
+function isPrime(value){
+ for (var i=2; i < value; i++){
+ if (value % i == 0){
+ return false
+ }
+ if (value % i != 0){
+ return true;
+ }
+ }
+}
+
+function trial_factor(base, exp, mod){
+ var square, bits
+ square = 1
+ bits = exp.toString(2).split('')
+ for (var i=0,ln=bits.length; ii]]]; Print["prime test passed; call Lucas and Lehmer"]
diff --git a/Task/Factors-of-a-Mersenne-number/Maxima/factors-of-a-mersenne-number.maxima b/Task/Factors-of-a-Mersenne-number/Maxima/factors-of-a-mersenne-number.maxima
new file mode 100644
index 0000000000..e56fed28e7
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Maxima/factors-of-a-mersenne-number.maxima
@@ -0,0 +1,7 @@
+mersenne_fac(p) := block([m: 2^p - 1, k: 1],
+ while mod(m, 2 * k * p + 1) # 0 do k: k + 1,
+ 2 * k * p + 1
+)$
+
+mersenne_fac(929);
+/* 13007 */
diff --git a/Task/Factors-of-a-Mersenne-number/PHP/factors-of-a-mersenne-number.php b/Task/Factors-of-a-Mersenne-number/PHP/factors-of-a-mersenne-number.php
new file mode 100644
index 0000000000..b9d864764a
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/PHP/factors-of-a-mersenne-number.php
@@ -0,0 +1,22 @@
+echo 'M929 has a factor: ', mersenneFactor(929), '';
+
+function mersenneFactor($p) {
+ $limit = sqrt(pow(2, $p) - 1);
+ for ($k = 1; 2 * $p * $k - 1 < $limit; $k++) {
+ $q = 2 * $p * $k + 1;
+ if (isPrime($q) && ($q % 8 == 1 || $q % 8 == 7) && bcpowmod("2", "$p", "$q") == "1") {
+ return $q;
+ }
+ }
+ return 0;
+}
+
+function isPrime($n) {
+ if ($n < 2 || $n % 2 == 0) return $n == 2;
+ for ($i = 3; $i * $i <= $n; $i += 2) {
+ if ($n % $i == 0) {
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-1.pl b/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-1.pl
new file mode 100644
index 0000000000..7acadd43de
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-1.pl
@@ -0,0 +1,61 @@
+use strict;
+use utf8;
+
+sub factors {
+ my $n = shift;
+ my $p = 2;
+ my @out;
+
+ while ($n >= $p * $p) {
+ while ($n % $p == 0) {
+ push @out, $p;
+ $n /= $p;
+ }
+ $p = next_prime($p);
+ }
+ push @out, $n if $n > 1 || !@out;
+ @out;
+}
+
+sub next_prime {
+ my $p = shift;
+ do { $p = $p == 2 ? 3 : $p + 2 } until is_prime($p);
+ $p;
+}
+
+my %pcache;
+sub is_prime {
+ my $x = shift;
+ $pcache{$x} //= (factors($x) == 1)
+}
+
+sub mtest {
+ my @bits = split "", sprintf("%b", shift);
+ my $p = shift;
+ my $sq = 1;
+ while (@bits) {
+ $sq = $sq * $sq;
+ $sq *= 2 if shift @bits;
+ $sq %= $p;
+ }
+ $sq == 1;
+}
+
+for my $m (2 .. 60, 929) {
+ next unless is_prime($m);
+ use bigint;
+
+ my ($f, $k, $x) = (0, 0, 2**$m - 1);
+
+ my $q;
+ while (++$k) {
+ $q = 2 * $k * $m + 1;
+ next if (($q & 7) != 1 && ($q & 7) != 7);
+ next unless is_prime($q);
+ last if $q * $q > $x;
+ last if $f = mtest($m, $q);
+ }
+
+ print $f? "M$m = $x = $q × @{[$x / $q]}\n"
+ : "M$m = $x is prime\n";
+}
diff --git a/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-2.pl b/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-2.pl
new file mode 100644
index 0000000000..bc44baf888
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Perl/factors-of-a-mersenne-number-2.pl
@@ -0,0 +1,11 @@
+M2 = 3 is prime
+M2 = 3 is prime
+M3 = 7 is prime
+M5 = 31 is prime
+M7 = 127 is prime
+M11 = 2047 = 23 × 89
+M13 = 8191 is prime
+...
+M53 = 9007199254740991 = 6361 × 1416003655831
+M59 = 576460752303423487 = 179951 × 3203431780337
+M929 = 4538....8911 = 13007 × 348890....84273
diff --git a/Task/Factors-of-a-Mersenne-number/PicoLisp/factors-of-a-mersenne-number.l b/Task/Factors-of-a-Mersenne-number/PicoLisp/factors-of-a-mersenne-number.l
new file mode 100644
index 0000000000..9d784e6821
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/PicoLisp/factors-of-a-mersenne-number.l
@@ -0,0 +1,30 @@
+(de **Mod (X Y N)
+ (let M 1
+ (loop
+ (when (bit? 1 Y)
+ (setq M (% (* M X) N)) )
+ (T (=0 (setq Y (>> 1 Y)))
+ M )
+ (setq X (% (* X X) N)) ) ) )
+
+(de prime? (N)
+ (or
+ (= N 2)
+ (and
+ (> N 1)
+ (bit? 1 N)
+ (for (D 3 T (+ D 2))
+ (T (> D (sqrt N)) T)
+ (T (=0 (% N D)) NIL) ) ) ) )
+
+(de mFactor (P)
+ (let (Lim (sqrt (dec (** 2 P))) K 0 Q)
+ (loop
+ (setq Q (inc (* 2 (inc 'K) P)))
+ (T (>= Q Lim) NIL)
+ (T
+ (and
+ (member (% Q 8) (1 7))
+ (prime? Q)
+ (= 1 (**Mod 2 P Q)) )
+ Q ) ) ) )
diff --git a/Task/Factors-of-a-Mersenne-number/Python/factors-of-a-mersenne-number.py b/Task/Factors-of-a-Mersenne-number/Python/factors-of-a-mersenne-number.py
new file mode 100644
index 0000000000..5efe93532c
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Python/factors-of-a-mersenne-number.py
@@ -0,0 +1,25 @@
+def is_prime(number):
+ return True # code omitted - see Primality by Trial Division
+
+def m_factor(p):
+ max_k = 16384 / p # arbitrary limit; since Python automatically uses long's, it doesn't overflow
+ for k in xrange(max_k):
+ q = 2*p*k + 1
+ if not is_prime(q):
+ continue
+ elif q % 8 != 1 and q % 8 != 7:
+ continue
+ elif pow(2, p, q) == 1:
+ return q
+ return None
+
+if __name__ == '__main__':
+ exponent = int(raw_input("Enter exponent of Mersenne number: "))
+ if not is_prime(exponent):
+ print "Exponent is not prime: %d" % exponent
+ else:
+ factor = m_factor(exponent)
+ if not factor:
+ print "No factor found for M%d" % exponent
+ else:
+ print "M%d has a factor: %d" % (exponent, factor)
diff --git a/Task/Factors-of-a-Mersenne-number/REXX/factors-of-a-mersenne-number.rexx b/Task/Factors-of-a-Mersenne-number/REXX/factors-of-a-mersenne-number.rexx
new file mode 100644
index 0000000000..584ab4f0a4
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/REXX/factors-of-a-mersenne-number.rexx
@@ -0,0 +1,39 @@
+/*REXX program uses exponent-&-mod operator to test possible Mersenne #s*/
+numeric digits 500 /*we're dealing with some biggies*/
+
+ do j=1 to 61; z=j /*when J=61, it turns into 929. */
+ if z==61 then z=929 /*switcheroo, 61 turns into 929.*/
+ if \isPrime(z) then iterate /*if not prime, keep plugging. */
+ r=testM(z) /*not, give it the 3rd degree. */
+ if r==0 then say right('M'z,8) "──────── is a Mersenne prime."
+ else say right('M'z,48) "is composite, a factor:" r
+ end /*j*/
+exit /*stick a fork in it, we're done.*/
+/*──────────────────────────────────MODPOW subroutine───────────────────*/
+modPow: procedure; parse arg base,n,div; sq=1
+bits=x2b(d2x(n))+0 /*dec──► hex──► binary, normalize*/
+ do until bits==''; sq=sq ** 2
+ if left(bits,1) then sq=sq * base // div
+ bits=substr(bits,2)
+ end /*until*/
+return sq
+/*─────────────────────────────────────ISPRIME subroutine───────────────*/
+isPrime: procedure; parse arg x; if wordpos(x,'2 3 5 7')\==0 then return 1
+if x<11 then return 0; if x//2==0 then return 0; if x//3==0 then return 0
+do j=5 by 6; if x//j==0|x//(j+2)==0 then return 0; if j*j>x then return 1;end
+/*─────────────────────────────────────ISQRT subroutine─────────────────*/
+iSqrt: procedure; parse arg x; r=0; q=1; do while q<=x; q=q*4; end
+do while q>1; q=q%4;_=x-r-q;r=r%2;if _>=0 then do;x=_;r=r+q;end;end; return r
+/*──────────────────────────────────TESTM subroutine────────────────────*/
+testM: procedure; parse arg x /*test a possible Mersenne prime.*/
+sqroot=iSqrt(2**x) /*iSqrt is: integer square root.*/
+ /*───── ─ ── ─ ─ */
+ do k=1; q=2*k*x + 1 /* _____ */
+ if q>sqroot then leave /*Is q>√(2^x) ? Then we're done*/
+ _=q // 8 /*perform modulus arithmetic. */
+ if _\==1 & _\==7 then iterate /*must be either one or seven. */
+ if \isPrime(q) then iterate /*if not prime, keep on trukin'. */
+ if modPow(2,x,q)==1 then return q /*Not a prime? Return a factor.*/
+ end /*k*/
+
+return 0 /*it's a Mersenne prime, by gum. */
diff --git a/Task/Factors-of-a-Mersenne-number/Ruby/factors-of-a-mersenne-number.rb b/Task/Factors-of-a-Mersenne-number/Ruby/factors-of-a-mersenne-number.rb
new file mode 100644
index 0000000000..31af7e6248
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Ruby/factors-of-a-mersenne-number.rb
@@ -0,0 +1,49 @@
+require 'mathn'
+
+def mersenne_factor(p)
+ limit = Math.sqrt(2**p - 1)
+ k = 1
+ while (2*k*p - 1) < limit
+ q = 2*k*p + 1
+ if prime?(q) and (q % 8 == 1 or q % 8 == 7) and trial_factor(2,p,q)
+ # q is a factor of 2**p-1
+ return q
+ end
+ k += 1
+ end
+ nil
+end
+
+def prime?(value)
+ return false if value < 2
+ png = Prime.new
+ for prime in png
+ q,r = value.divmod prime
+ return true if q < prime
+ return false if r == 0
+ end
+end
+
+def trial_factor(base, exp, mod)
+ square = 1
+ ("%b" % exp).each_char {|bit| square = square**2 * (bit == "1" ? base : 1) % mod}
+ (square == 1)
+end
+
+def check_mersenne(p)
+ print "M#{p} = 2**#{p}-1 is "
+ f = mersenne_factor(p)
+ if f.nil?
+ puts "prime"
+ else
+ puts "composite with factor #{f}"
+ end
+end
+
+png = Prime.new
+for p in png
+ check_mersenne p
+ break if p == 53
+end
+p = 929
+check_mersenne p
diff --git a/Task/Factors-of-a-Mersenne-number/Scala/factors-of-a-mersenne-number.scala b/Task/Factors-of-a-Mersenne-number/Scala/factors-of-a-mersenne-number.scala
new file mode 100644
index 0000000000..37d8bffea4
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Scala/factors-of-a-mersenne-number.scala
@@ -0,0 +1,65 @@
+import scala.math.BigInt
+
+def factorMersenne( p:BigInt ) : Option[BigInt] = {
+
+ val two = BigInt("2")
+
+ val factorLimit : BigInt = (two pow p.toInt) - 1
+ val limit = factorLimit min (math.sqrt(Long.MaxValue).toInt)
+
+
+ def factorTest( p : BigInt, q : BigInt ) : Boolean = {
+
+ // Is q an early factor?
+ if(
+ two.modPow(p,q) == 1 && // number divides 2**P-1
+ ((q % 8).toInt match {case 1 | 7 => true; case _ => false}) && // mod(8) is of 1 or 7
+ q.isProbablePrime(7) // it is a prime number
+ )
+ {true}
+ else
+ {false}
+ }
+
+ // Build a stream of factors from (2*p+1) step-by (2*p)
+ def s(a:BigInt) : Stream[BigInt] = a #:: s(a + (two * p)) // Build stream of possible factors
+
+ // Limit and Filter Stream and then take the head element
+ val e = s(two*p+1).takeWhile(_ < limit).filter(factorTest(p,_))
+ e.headOption
+}
+
+val l = List(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,929)
+
+// Test
+l.foreach(p => println( "M" + p + ": " + (factorMersenne(p) getOrElse "prime") ))
+
+/*
+Results:
+M2: prime
+M3: prime
+M5: prime
+M7: prime
+M11: 23
+M13: prime
+M17: prime
+M19: prime
+M23: 47
+M29: 233
+M31: prime
+M37: 223
+M41: 13367
+M43: 431
+M47: 2351
+M53: 6361
+M59: 179951
+M61: prime
+M67: 193707721
+M71: 228479
+M73: 439
+M79: 2687
+M83: 167
+M89: prime
+M97: 11447
+M929: 13007
+*/
diff --git a/Task/Factors-of-a-Mersenne-number/Scheme/factors-of-a-mersenne-number.ss b/Task/Factors-of-a-Mersenne-number/Scheme/factors-of-a-mersenne-number.ss
new file mode 100644
index 0000000000..7df3abd070
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Scheme/factors-of-a-mersenne-number.ss
@@ -0,0 +1,21 @@
+#lang scheme
+
+;;; this needs to be changed for other R6RS implementations
+(require rnrs/arithmetic/bitwise-6)
+
+;;; modpow, as per the task description.
+(define (modpow exponent base)
+ (let loop ([square 1] [index (- (bitwise-length exponent) 1)])
+ (if (< index 0)
+ square
+ (loop (modulo (* (if (bitwise-bit-set? exponent index) 2 1)
+ square square) base)
+ (- index 1)))))
+
+;;; search through all integers from 1 on to find the first divisor
+;;; returns #f if 2^p-1 is prime
+(define (mersenne-factor p)
+ (for/first ((i (in-range 1 (floor (expt 2 (quotient p 2))) (* 2 p)))
+ #:when (and (or (= 1 (modulo i 8)) (= 7 (modulo i 8)))
+ (= 1 (modpow p i))))
+ i))
diff --git a/Task/Factors-of-a-Mersenne-number/Tcl/factors-of-a-mersenne-number.tcl b/Task/Factors-of-a-Mersenne-number/Tcl/factors-of-a-mersenne-number.tcl
new file mode 100644
index 0000000000..c472614e28
--- /dev/null
+++ b/Task/Factors-of-a-Mersenne-number/Tcl/factors-of-a-mersenne-number.tcl
@@ -0,0 +1,45 @@
+proc int2bits {n} {
+ binary scan [binary format I1 $n] B* binstring
+ return [split [string trimleft $binstring 0] ""]
+
+ # another method
+ if {$n == 0} {return 0}
+ set bits [list]
+ while {$n > 0} {
+ lappend bits [expr {$n % 2}]
+ set n [expr {$n / 2}]
+ }
+ return [lreverse $bits]
+}
+
+proc trial_factor {base exp mod} {
+ set square 1
+ foreach bit [int2bits $exp] {
+ set square [expr {($square ** 2) * ($bit == 1 ? $base : 1) % $mod}]
+ }
+ return [expr {$square == 1}]
+}
+
+proc m_factor p {
+ set limit [expr {sqrt(2**$p - 1)}]
+ for {set k 1} {2 * $k * $p - 1 < $limit} {incr k} {
+ set q [expr {2 * $k * $p + 1}]
+ if { ! [primes::is_prime $q]} {
+ continue
+ } elseif { ! ($q % 8 == 1 || $q % 8 == 7)} {
+ # optimization
+ continue
+ } elseif {[trial_factor 2 $p $q]} {
+ # $q is a factor of 2**$p-1
+ return $q
+ }
+ }
+ return -1
+}
+
+set exp 929
+if {[set fact [m_factor 929]] > 0} {
+ puts "M$exp has a factor: $fact"
+} else {
+ puts "no factor found for M$exp"
+}
diff --git a/Task/Factors-of-an-integer/0815/factors-of-an-integer.0815 b/Task/Factors-of-an-integer/0815/factors-of-an-integer.0815
new file mode 100644
index 0000000000..82bfd6f56c
--- /dev/null
+++ b/Task/Factors-of-an-integer/0815/factors-of-an-integer.0815
@@ -0,0 +1,2 @@
+<:1:~>|~#:end:^>~x}:str:/={^:wei:~%x<:a:x=$~
+=}:wei:x<:1:+{>~>x=-#:fin:^:str:}:fin:{{~%
diff --git a/Task/Factors-of-an-integer/0DESCRIPTION b/Task/Factors-of-an-integer/0DESCRIPTION
new file mode 100644
index 0000000000..cd69d7c6bc
--- /dev/null
+++ b/Task/Factors-of-an-integer/0DESCRIPTION
@@ -0,0 +1,7 @@
+{{basic data operation}}
+[[Category:Arithmetic operations]]
+[[Category:Mathematical_operations]]
+Compute the [[wp:Divisor|factors]] of a positive integer. These factors are the positive integers by which the number being factored can be divided to yield a positive integer result (though the concepts function correctly for zero and negative integers, the set of factors of zero is has countably infinite members, and the factors of negative integers can be obtained from the factors of related positive numbers without difficulty; this task does not require handling of either of these cases). Note that even prime numbers will have at least two factors; ‘1’ and themselves.
+
+See also:
+* [[Prime decomposition]]
diff --git a/Task/Factors-of-an-integer/1META.yaml b/Task/Factors-of-an-integer/1META.yaml
new file mode 100644
index 0000000000..659c8686af
--- /dev/null
+++ b/Task/Factors-of-an-integer/1META.yaml
@@ -0,0 +1,2 @@
+---
+note: Basic language learning
diff --git a/Task/Factors-of-an-integer/ACL2/factors-of-an-integer.acl2 b/Task/Factors-of-an-integer/ACL2/factors-of-an-integer.acl2
new file mode 100644
index 0000000000..7a032a43a6
--- /dev/null
+++ b/Task/Factors-of-an-integer/ACL2/factors-of-an-integer.acl2
@@ -0,0 +1,10 @@
+(defun factors-r (n i)
+ (declare (xargs :measure (nfix (- n i))))
+ (cond ((zp (- n i))
+ (list n))
+ ((= (mod n i) 0)
+ (cons i (factors-r n (1+ i))))
+ (t (factors-r n (1+ i)))))
+
+(defun factors (n)
+ (factors-r n 1))
diff --git a/Task/Factors-of-an-integer/ALGOL-68/factors-of-an-integer.alg b/Task/Factors-of-an-integer/ALGOL-68/factors-of-an-integer.alg
new file mode 100644
index 0000000000..4a34f3ec98
--- /dev/null
+++ b/Task/Factors-of-an-integer/ALGOL-68/factors-of-an-integer.alg
@@ -0,0 +1,25 @@
+MODE YIELDINT = PROC(INT)VOID;
+
+PROC gen factors = (INT n, YIELDINT yield)VOID: (
+ FOR i FROM 1 TO ENTIER sqrt(n) DO
+ IF n MOD i = 0 THEN
+ yield(i);
+ INT other = n OVER i;
+ IF i NE other THEN yield(n OVER i) FI
+ FI
+ OD
+);
+
+[]INT nums2factor = (45, 53, 64);
+
+FOR i TO UPB nums2factor DO
+ INT num = nums2factor[i];
+ STRING sep := ": ";
+ print(num);
+# FOR INT j IN # gen factors(num, # ) DO ( #
+## (INT j)VOID:(
+ print((sep,whole(j,0)));
+ sep:=", "
+# OD # ));
+ print(new line)
+OD
diff --git a/Task/Factors-of-an-integer/ActionScript/factors-of-an-integer.as b/Task/Factors-of-an-integer/ActionScript/factors-of-an-integer.as
new file mode 100644
index 0000000000..2fcfe1aa3d
--- /dev/null
+++ b/Task/Factors-of-an-integer/ActionScript/factors-of-an-integer.as
@@ -0,0 +1,7 @@
+function factor(n:uint):Vector.
+{
+ var factors:Vector. = new Vector.();
+ for(var i:uint = 1; i <= n; i++)
+ if(n % i == 0)factors.push(i);
+ return factors;
+}
diff --git a/Task/Factors-of-an-integer/Ada/factors-of-an-integer.ada b/Task/Factors-of-an-integer/Ada/factors-of-an-integer.ada
new file mode 100644
index 0000000000..4212998a28
--- /dev/null
+++ b/Task/Factors-of-an-integer/Ada/factors-of-an-integer.ada
@@ -0,0 +1,22 @@
+with Ada.Text_IO;
+with Ada.Command_Line;
+procedure Factors is
+ Number : Positive;
+ Test_Nr : Positive := 1;
+begin
+ if Ada.Command_Line.Argument_Count /= 1 then
+ Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
+ Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
+ return;
+ end if;
+ Number := Positive'Value (Ada.Command_Line.Argument (1));
+ Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
+ loop
+ if Number mod Test_Nr = 0 then
+ Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
+ end if;
+ exit when Test_Nr ** 2 >= Number;
+ Test_Nr := Test_Nr + 1;
+ end loop;
+ Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
+end Factors;
diff --git a/Task/Factors-of-an-integer/Aikido/factors-of-an-integer.aikido b/Task/Factors-of-an-integer/Aikido/factors-of-an-integer.aikido
new file mode 100644
index 0000000000..c77b45513c
--- /dev/null
+++ b/Task/Factors-of-an-integer/Aikido/factors-of-an-integer.aikido
@@ -0,0 +1,34 @@
+import math
+
+function factor (n:int) {
+ var result = []
+ function append (v) {
+ if (!(v in result)) {
+ result.append (v)
+ }
+ }
+ var sqrt = cast(Math.sqrt (n))
+ append (1)
+ for (var i = n-1 ; i >= sqrt ; i--) {
+ if ((n % i) == 0) {
+ append (i)
+ append (n/i)
+ }
+ }
+ append (n)
+ return result.sort()
+}
+
+function printvec (vec) {
+ var comma = ""
+ print ("[")
+ foreach v vec {
+ print (comma + v)
+ comma = ", "
+ }
+ println ("]")
+}
+
+printvec (factor (45))
+printvec (factor (25))
+printvec (factor (100))
diff --git a/Task/Factors-of-an-integer/AutoHotkey/factors-of-an-integer.ahk b/Task/Factors-of-an-integer/AutoHotkey/factors-of-an-integer.ahk
new file mode 100644
index 0000000000..7ab1f70861
--- /dev/null
+++ b/Task/Factors-of-an-integer/AutoHotkey/factors-of-an-integer.ahk
@@ -0,0 +1,9 @@
+msgbox, % factors(45) "`n" factors(53) "`n" factors(64)
+
+Factors(n)
+{ Loop, % floor(sqrt(n))
+ { v := A_Index = 1 ? 1 "," n : mod(n,A_Index) ? v : v "," A_Index "," n//A_Index
+ }
+ Sort, v, N U D,
+ Return, v
+}
diff --git a/Task/Factors-of-an-integer/AutoIt/factors-of-an-integer.autoit b/Task/Factors-of-an-integer/AutoIt/factors-of-an-integer.autoit
new file mode 100644
index 0000000000..24d556fd64
--- /dev/null
+++ b/Task/Factors-of-an-integer/AutoIt/factors-of-an-integer.autoit
@@ -0,0 +1,13 @@
+;AutoIt Version: 3.2.10.0
+$num = 45
+MsgBox (0,"Factors", "Factors of " & $num & " are: " & factors($num))
+consolewrite ("Factors of " & $num & " are: " & factors($num))
+Func factors($intg)
+ $ls_factors=""
+ For $i = 1 to $intg/2
+ if ($intg/$i - int($intg/$i))=0 Then
+ $ls_factors=$ls_factors&$i &", "
+ EndIf
+ Next
+ Return $ls_factors&$intg
+EndFunc
diff --git a/Task/Factors-of-an-integer/BASIC/factors-of-an-integer.bas b/Task/Factors-of-an-integer/BASIC/factors-of-an-integer.bas
new file mode 100644
index 0000000000..98f6370e71
--- /dev/null
+++ b/Task/Factors-of-an-integer/BASIC/factors-of-an-integer.bas
@@ -0,0 +1,41 @@
+DECLARE SUB factor (what AS INTEGER)
+
+REDIM SHARED factors(0) AS INTEGER
+
+DIM i AS INTEGER, L AS INTEGER
+
+INPUT "Gimme a number"; i
+
+factor i
+
+PRINT factors(0);
+FOR L = 1 TO UBOUND(factors)
+ PRINT ","; factors(L);
+NEXT
+PRINT
+
+SUB factor (what AS INTEGER)
+ DIM tmpint1 AS INTEGER
+ DIM L0 AS INTEGER, L1 AS INTEGER
+
+ REDIM tmp(0) AS INTEGER
+ REDIM factors(0) AS INTEGER
+ factors(0) = 1
+
+ FOR L0 = 2 TO what
+ IF (0 = (what MOD L0)) THEN
+ 'all this REDIMing and copying can be replaced with:
+ 'REDIM PRESERVE factors(UBOUND(factors)+1)
+ 'in languages that support the PRESERVE keyword
+ REDIM tmp(UBOUND(factors)) AS INTEGER
+ FOR L1 = 0 TO UBOUND(factors)
+ tmp(L1) = factors(L1)
+ NEXT
+ REDIM factors(UBOUND(factors) + 1)
+ FOR L1 = 0 TO UBOUND(factors) - 1
+ factors(L1) = tmp(L1)
+ NEXT
+ factors(UBOUND(factors)) = L0
+ END IF
+ NEXT
+END SUB
diff --git a/Task/Factors-of-an-integer/BBC-BASIC/factors-of-an-integer.bbc b/Task/Factors-of-an-integer/BBC-BASIC/factors-of-an-integer.bbc
new file mode 100644
index 0000000000..d75cf566e7
--- /dev/null
+++ b/Task/Factors-of-an-integer/BBC-BASIC/factors-of-an-integer.bbc
@@ -0,0 +1,25 @@
+ INSTALL @lib$+"SORTLIB"
+ sort% = FN_sortinit(0, 0)
+
+ PRINT "The factors of 45 are " FNfactorlist(45)
+ PRINT "The factors of 12345 are " FNfactorlist(12345)
+ END
+
+ DEF FNfactorlist(N%)
+ LOCAL C%, I%, L%(), L$
+ DIM L%(32)
+ FOR I% = 1 TO SQR(N%)
+ IF (N% MOD I% = 0) THEN
+ L%(C%) = I%
+ C% += 1
+ IF (N% <> I%^2) THEN
+ L%(C%) = (N% DIV I%)
+ C% += 1
+ ENDIF
+ ENDIF
+ NEXT I%
+ CALL sort%, L%(0)
+ FOR I% = 0 TO C%-1
+ L$ += STR$(L%(I%)) + ", "
+ NEXT
+ = LEFT$(LEFT$(L$))
diff --git a/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-1.bat b/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-1.bat
new file mode 100644
index 0000000000..75c74474f7
--- /dev/null
+++ b/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-1.bat
@@ -0,0 +1,9 @@
+@echo off
+set res=Factors of %1:
+for /L %%i in (1,1,%1) do call :fac %1 %%i
+echo %res%
+goto :eof
+
+:fac
+set /a test = %1 %% %2
+if %test% equ 0 set res=%res% %2
diff --git a/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-2.bat b/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-2.bat
new file mode 100644
index 0000000000..993fcd46fa
--- /dev/null
+++ b/Task/Factors-of-an-integer/Batch-File/factors-of-an-integer-2.bat
@@ -0,0 +1,10 @@
+@echo off
+set /p limit=Gimme a number:
+set res=Factors of %limit%:
+for /L %%i in (1,1,%limit%) do call :fac %limit% %%i
+echo %res%
+goto :eof
+
+:fac
+set /a test = %1 %% %2
+if %test% equ 0 set res=%res% %2
diff --git a/Task/Factors-of-an-integer/C++/factors-of-an-integer.cpp b/Task/Factors-of-an-integer/C++/factors-of-an-integer.cpp
new file mode 100644
index 0000000000..3b746244ef
--- /dev/null
+++ b/Task/Factors-of-an-integer/C++/factors-of-an-integer.cpp
@@ -0,0 +1,36 @@
+#include
+#include
+#include
+#include
+
+std::vector GenerateFactors(int n)
+{
+ std::vector factors;
+ factors.push_back(1);
+ factors.push_back(n);
+ for(int i = 2; i * i <= n; ++i)
+ {
+ if(n % i == 0)
+ {
+ factors.push_back(i);
+ if(i * i != n)
+ factors.push_back(n / i);
+ }
+ }
+
+ std::sort(factors.begin(), factors.end());
+ return factors;
+}
+
+int main()
+{
+ const int SampleNumbers[] = {3135, 45, 60, 81};
+
+ for(size_t i = 0; i < sizeof(SampleNumbers) / sizeof(int); ++i)
+ {
+ std::vector factors = GenerateFactors(SampleNumbers[i]);
+ std::cout << "Factors of " << SampleNumbers[i] << " are:\n";
+ std::copy(factors.begin(), factors.end(), std::ostream_iterator(std::cout, "\n"));
+ std::cout << std::endl;
+ }
+}
diff --git a/Task/Factors-of-an-integer/C/factors-of-an-integer-1.c b/Task/Factors-of-an-integer/C/factors-of-an-integer-1.c
new file mode 100644
index 0000000000..e9cb31e2b1
--- /dev/null
+++ b/Task/Factors-of-an-integer/C/factors-of-an-integer-1.c
@@ -0,0 +1,68 @@
+#include
+#include
+
+typedef struct {
+ int *list;
+ short count;
+} Factors;
+
+void xferFactors( Factors *fctrs, int *flist, int flix )
+{
+ int ix, ij;
+ int newSize = fctrs->count + flix;
+ if (newSize > flix) {
+ fctrs->list = realloc( fctrs->list, newSize * sizeof(int));
+ }
+ else {
+ fctrs->list = malloc( newSize * sizeof(int));
+ }
+ for (ij=0,ix=fctrs->count; ixlist[ix] = flist[ij];
+ }
+ fctrs->count = newSize;
+}
+
+Factors *factor( int num, Factors *fctrs)
+{
+ int flist[301], flix;
+ int dvsr;
+ flix = 0;
+ fctrs->count = 0;
+ free(fctrs->list);
+ fctrs->list = NULL;
+ for (dvsr=1; dvsr*dvsr < num; dvsr++) {
+ if (num % dvsr != 0) continue;
+ if ( flix == 300) {
+ xferFactors( fctrs, flist, flix );
+ flix = 0;
+ }
+ flist[flix++] = dvsr;
+ flist[flix++] = num/dvsr;
+ }
+ if (dvsr*dvsr == num)
+ flist[flix++] = dvsr;
+ if (flix > 0)
+ xferFactors( fctrs, flist, flix );
+
+ return fctrs;
+}
+
+int main(int argc, char*argv[])
+{
+ int nums2factor[] = { 2059, 223092870, 3135, 45 };
+ Factors ftors = { NULL, 0};
+ char sep;
+ int i,j;
+
+ for (i=0; i<4; i++) {
+ factor( nums2factor[i], &ftors );
+ printf("\nfactors of %d are:\n ", nums2factor[i]);
+ sep = ' ';
+ for (j=0; j
+#include
+#include
+
+/* 65536 = 2^16, so we can factor all 32 bit ints */
+char bits[65536];
+
+typedef unsigned long ulong;
+ulong primes[7000], n_primes;
+
+typedef struct { ulong p, e; } prime_factor; /* prime, exponent */
+
+void sieve()
+{
+ int i, j;
+ memset(bits, 1, 65536);
+ bits[0] = bits[1] = 0;
+ for (i = 0; i < 256; i++)
+ if (bits[i])
+ for (j = i * i; j < 65536; j += i)
+ bits[j] = 0;
+
+ /* collect primes into a list. slightly faster this way if dealing with large numbers */
+ for (i = j = 0; i < 65536; i++)
+ if (bits[i]) primes[j++] = i;
+
+ n_primes = j;
+}
+
+int get_prime_factors(ulong n, prime_factor *lst)
+{
+ ulong i, e, p;
+ int len = 0;
+
+ for (i = 0; i < n_primes; i++) {
+ p = primes[i];
+ if (p * p > n) break;
+ for (e = 0; !(n % p); n /= p, e++);
+ if (e) {
+ lst[len].p = p;
+ lst[len++].e = e;
+ }
+ }
+
+ return n == 1 ? len : (lst[len].p = n, lst[len].e = 1, ++len);
+}
+
+int ulong_cmp(const void *a, const void *b)
+{
+ return *(ulong*)a < *(ulong*)b ? -1 : *(ulong*)a > *(ulong*)b;
+}
+
+int get_factors(ulong n, ulong *lst)
+{
+ int n_f, len, len2, i, j, k, p;
+ prime_factor f[100];
+
+ n_f = get_prime_factors(n, f);
+
+ len2 = len = lst[0] = 1;
+ /* L = (1); L = (L, L * p**(1 .. e)) forall((p, e)) */
+ for (i = 0; i < n_f; i++, len2 = len)
+ for (j = 0, p = f[i].p; j < f[i].e; j++, p *= f[i].p)
+ for (k = 0; k < len2; k++)
+ lst[len++] = lst[k] * p;
+
+ qsort(lst, len, sizeof(ulong), ulong_cmp);
+ return len;
+}
+
+int main()
+{
+ ulong fac[10000];
+ int len, i, j;
+ ulong nums[] = {3, 120, 1024, 2UL*2*2*2*3*3*3*5*5*7*11*13*17*19 };
+
+ sieve();
+
+ for (i = 0; i < 4; i++) {
+ len = get_factors(nums[i], fac);
+ printf("%lu:", nums[i]);
+ for (j = 0; j < len; j++)
+ printf(" %lu", fac[j]);
+ printf("\n");
+ }
+
+ return 0;
+}
diff --git a/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-1.clj b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-1.clj
new file mode 100644
index 0000000000..3dcb9d74fc
--- /dev/null
+++ b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-1.clj
@@ -0,0 +1,4 @@
+(defn factors [n]
+ (filter #(zero? (rem n %)) (range 1 (inc n))))
+
+(print (factors 45))
diff --git a/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-2.clj b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-2.clj
new file mode 100644
index 0000000000..b2cb67e7a1
--- /dev/null
+++ b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-2.clj
@@ -0,0 +1,4 @@
+(defn factors [n]
+ (into (sorted-set)
+ (mapcat (fn [x] [x (/ n x)])
+ (filter #(zero? (rem n %)) (range 1 (inc (sqrt n)))) )))
diff --git a/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-3.clj b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-3.clj
new file mode 100644
index 0000000000..af4b734e22
--- /dev/null
+++ b/Task/Factors-of-an-integer/Clojure/factors-of-an-integer-3.clj
@@ -0,0 +1,5 @@
+(defn factors [n]
+ (into (sorted-set)
+ (reduce concat
+ (for [x (range 1 (inc (sqrt n))) :when (zero? (rem n x))]
+ [x (/ n x)]))))
diff --git a/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-1.coffee b/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-1.coffee
new file mode 100644
index 0000000000..50fa310a15
--- /dev/null
+++ b/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-1.coffee
@@ -0,0 +1,59 @@
+# Reference implementation for finding factors is slow, but hopefully
+# robust--we'll use it to verify the more complicated (but hopefully faster)
+# algorithm.
+slow_factors = (n) ->
+ (i for i in [1..n] when n % i == 0)
+
+# The rest of this code does two optimizations:
+# 1) When you find a prime factor, divide it out of n (smallest_prime_factor).
+# 2) Find the prime factorization first, then compute composite factors from those.
+
+smallest_prime_factor = (n) ->
+ for i in [2..n]
+ return n if i*i > n
+ return i if n % i == 0
+
+prime_factors = (n) ->
+ return {} if n == 1
+ spf = smallest_prime_factor n
+ result = prime_factors(n / spf)
+ result[spf] or= 0
+ result[spf] += 1
+ result
+
+fast_factors = (n) ->
+ prime_hash = prime_factors n
+ exponents = []
+ for p of prime_hash
+ exponents.push
+ p: p
+ exp: 0
+ result = []
+ while true
+ factor = 1
+ for obj in exponents
+ factor *= Math.pow obj.p, obj.exp
+ result.push factor
+ break if factor == n
+ # roll the odometer
+ for obj, i in exponents
+ if obj.exp < prime_hash[obj.p]
+ obj.exp += 1
+ break
+ else
+ obj.exp = 0
+
+ return result.sort (a, b) -> a - b
+
+verify_factors = (factors, n) ->
+ expected_result = slow_factors n
+ throw Error("wrong length") if factors.length != expected_result.length
+ for factor, i in expected_result
+ console.log Error("wrong value") if factors[i] != factor
+
+
+for n in [1, 3, 4, 8, 24, 37, 1001, 11111111111, 99999999999]
+ factors = fast_factors n
+ console.log n, factors
+ if n < 1000000
+ verify_factors factors, n
diff --git a/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-2.coffee b/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-2.coffee
new file mode 100644
index 0000000000..532bee5b8f
--- /dev/null
+++ b/Task/Factors-of-an-integer/CoffeeScript/factors-of-an-integer-2.coffee
@@ -0,0 +1,21 @@
+> coffee factors.coffee
+1 [ 1 ]
+3 [ 1, 3 ]
+4 [ 1, 2, 4 ]
+8 [ 1, 2, 4, 8 ]
+24 [ 1, 2, 3, 4, 6, 8, 12, 24 ]
+37 [ 1, 37 ]
+1001 [ 1, 7, 11, 13, 77, 91, 143, 1001 ]
+11111111111 [ 1, 21649, 513239, 11111111111 ]
+99999999999 [ 1,
+ 3,
+ 9,
+ 21649,
+ 64947,
+ 194841,
+ 513239,
+ 1539717,
+ 4619151,
+ 11111111111,
+ 33333333333,
+ 99999999999 ]
diff --git a/Task/Factors-of-an-integer/Common-Lisp/factors-of-an-integer.lisp b/Task/Factors-of-an-integer/Common-Lisp/factors-of-an-integer.lisp
new file mode 100644
index 0000000000..3ab77c0701
--- /dev/null
+++ b/Task/Factors-of-an-integer/Common-Lisp/factors-of-an-integer.lisp
@@ -0,0 +1,10 @@
+(defun factors (n &aux (lows '()) (highs '()))
+ (do ((limit (isqrt n)) (factor 1 (1+ factor)))
+ ((= factor limit)
+ (when (= n (* limit limit))
+ (push limit highs))
+ (nreconc lows highs))
+ (multiple-value-bind (quotient remainder) (floor n factor)
+ (when (zerop remainder)
+ (push factor lows)
+ (push quotient highs)))))
diff --git a/Task/Factors-of-an-integer/D/factors-of-an-integer-1.d b/Task/Factors-of-an-integer/D/factors-of-an-integer-1.d
new file mode 100644
index 0000000000..2fb629c75a
--- /dev/null
+++ b/Task/Factors-of-an-integer/D/factors-of-an-integer-1.d
@@ -0,0 +1,23 @@
+import std.stdio, std.math, std.algorithm;
+
+T[] factor(T)(in T n) /*pure nothrow*/ {
+ if (n == 1) return [n];
+
+ T[] res = [1, n];
+ T limit = cast(T)sqrt(cast(real)n) + 1;
+ for (T i = 2; i < limit; i++) {
+ if (n % i == 0) {
+ res ~= i;
+ auto q = n / i;
+ if (q > i)
+ res ~= q;
+ }
+ }
+
+ return res.sort().release();
+}
+
+void main() {
+ foreach (i; [45, 53, 64, 1111111])
+ writeln(factor(i));
+}
diff --git a/Task/Factors-of-an-integer/D/factors-of-an-integer-2.d b/Task/Factors-of-an-integer/D/factors-of-an-integer-2.d
new file mode 100644
index 0000000000..f1c6ada6ee
--- /dev/null
+++ b/Task/Factors-of-an-integer/D/factors-of-an-integer-2.d
@@ -0,0 +1,9 @@
+import std.stdio, std.algorithm, std.range;
+
+auto factors(I)(I n) {
+ return iota(1, n+1).filter!(i => n % i == 0)();
+}
+
+void main() {
+ writeln(factors(36));
+}
diff --git a/Task/Factors-of-an-integer/E/factors-of-an-integer.e b/Task/Factors-of-an-integer/E/factors-of-an-integer.e
new file mode 100644
index 0000000000..a09859b4d8
--- /dev/null
+++ b/Task/Factors-of-an-integer/E/factors-of-an-integer.e
@@ -0,0 +1,7 @@
+def factors(x :(int > 0)) {
+ var xfactors := []
+ for f ? (x % f <=> 0) in 1..x {
+ xfactors with= f
+ }
+ return xfactors
+}
diff --git a/Task/Factors-of-an-integer/Ela/factors-of-an-integer-1.ela b/Task/Factors-of-an-integer/Ela/factors-of-an-integer-1.ela
new file mode 100644
index 0000000000..79ae0ffd8d
--- /dev/null
+++ b/Task/Factors-of-an-integer/Ela/factors-of-an-integer-1.ela
@@ -0,0 +1,3 @@
+open list
+
+factors m = filter (\x -> m % x == 0) [1..m]
diff --git a/Task/Factors-of-an-integer/Ela/factors-of-an-integer-2.ela b/Task/Factors-of-an-integer/Ela/factors-of-an-integer-2.ela
new file mode 100644
index 0000000000..e0f6e4e394
--- /dev/null
+++ b/Task/Factors-of-an-integer/Ela/factors-of-an-integer-2.ela
@@ -0,0 +1 @@
+factors m = [x \\ x <- [1..m] | m % x == 0]
diff --git a/Task/Factors-of-an-integer/Erlang/factors-of-an-integer.erl b/Task/Factors-of-an-integer/Erlang/factors-of-an-integer.erl
new file mode 100644
index 0000000000..048759cdb1
--- /dev/null
+++ b/Task/Factors-of-an-integer/Erlang/factors-of-an-integer.erl
@@ -0,0 +1,2 @@
+factors(N) ->
+ [I || I <- lists:seq(1,trunc(math:sqrt(N))), N rem I == 0]++[N].
diff --git a/Task/Factors-of-an-integer/FALSE/factors-of-an-integer.false b/Task/Factors-of-an-integer/FALSE/factors-of-an-integer.false
new file mode 100644
index 0000000000..9006d1723c
--- /dev/null
+++ b/Task/Factors-of-an-integer/FALSE/factors-of-an-integer.false
@@ -0,0 +1,2 @@
+[1[\$@$@-][\$@$@$@$@\/*=[$." "]?1+]#.%]f:
+45f;! 53f;! 64f;!
diff --git a/Task/Factors-of-an-integer/Forth/factors-of-an-integer.fth b/Task/Factors-of-an-integer/Forth/factors-of-an-integer.fth
new file mode 100644
index 0000000000..7d909a7326
--- /dev/null
+++ b/Task/Factors-of-an-integer/Forth/factors-of-an-integer.fth
@@ -0,0 +1,7 @@
+: factors dup 2/ 1+ 1 do dup i mod 0= if i swap then loop ;
+: .factors factors begin dup dup . 1 <> while drop repeat drop cr ;
+
+45 .factors
+53 .factors
+64 .factors
+100 .factors
diff --git a/Task/Factors-of-an-integer/Fortran/factors-of-an-integer.f b/Task/Factors-of-an-integer/Fortran/factors-of-an-integer.f
new file mode 100644
index 0000000000..333765e87c
--- /dev/null
+++ b/Task/Factors-of-an-integer/Fortran/factors-of-an-integer.f
@@ -0,0 +1,20 @@
+program Factors
+ implicit none
+ integer :: i, number
+
+ write(*,*) "Enter a number between 1 and 2147483647"
+ read*, number
+
+ do i = 1, int(sqrt(real(number))) - 1
+ if (mod(number, i) == 0) write (*,*) i, number/i
+ end do
+
+ ! Check to see if number is a square
+ i = int(sqrt(real(number)))
+ if (i*i == number) then
+ write (*,*) i
+ else if (mod(number, i) == 0) then
+ write (*,*) i, number/i
+ end if
+
+end program
diff --git a/Task/Factors-of-an-integer/GAP/factors-of-an-integer.gap b/Task/Factors-of-an-integer/GAP/factors-of-an-integer.gap
new file mode 100644
index 0000000000..cf7fc47627
--- /dev/null
+++ b/Task/Factors-of-an-integer/GAP/factors-of-an-integer.gap
@@ -0,0 +1,20 @@
+# Built-in function
+DivisorsInt(Factorial(5));
+# [ 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 ]
+
+# A possible implementation, not suitable to large n
+div := n -> Filtered([1 .. n], k -> n mod k = 0);
+
+div(Factorial(5));
+# [ 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 ]
+
+# Another implementation, usable for large n (if n can be factored quickly)
+div2 := function(n)
+ local f, p;
+ f := Collected(FactorsInt(n));
+ p := List(f, v -> List([0 .. v[2]], k -> v[1]^k));
+ return SortedList(List(Cartesian(p), Product));
+end;
+
+div2(Factorial(5));
+# [ 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 ]
diff --git a/Task/Factors-of-an-integer/Go/factors-of-an-integer.go b/Task/Factors-of-an-integer/Go/factors-of-an-integer.go
new file mode 100644
index 0000000000..c825dfbedf
--- /dev/null
+++ b/Task/Factors-of-an-integer/Go/factors-of-an-integer.go
@@ -0,0 +1,52 @@
+package main
+
+import "fmt"
+
+func main() {
+ printFactors(-1)
+ printFactors(0)
+ printFactors(1)
+ printFactors(2)
+ printFactors(3)
+ printFactors(53)
+ printFactors(45)
+ printFactors(64)
+ printFactors(600851475143)
+ printFactors(999999999999999989)
+}
+
+func printFactors(nr int64) {
+ if nr < 1 {
+ fmt.Println("\nFactors of", nr, "not computed")
+ return
+ }
+ fmt.Printf("\nFactors of %d: ", nr)
+ fs := make([]int64, 1)
+ fs[0] = 1
+ apf := func(p int64, e int) {
+ n := len(fs)
+ for i, pp := 0, p; i < e; i, pp = i+1, pp*p {
+ for j := 0; j < n; j++ {
+ fs = append(fs, fs[j]*pp)
+ }
+ }
+ }
+ e := 0
+ for ; nr & 1 == 0; e++ {
+ nr >>= 1
+ }
+ apf(2, e)
+ for d := int64(3); nr > 1; d += 2 {
+ if d*d > nr {
+ d = nr
+ }
+ for e = 0; nr%d == 0; e++ {
+ nr /= d
+ }
+ if e > 0 {
+ apf(d, e)
+ }
+ }
+ fmt.Println(fs)
+ fmt.Println("Number of factors =", len(fs))
+}
diff --git a/Task/Factors-of-an-integer/Groovy/factors-of-an-integer-1.groovy b/Task/Factors-of-an-integer/Groovy/factors-of-an-integer-1.groovy
new file mode 100644
index 0000000000..d422cc90b9
--- /dev/null
+++ b/Task/Factors-of-an-integer/Groovy/factors-of-an-integer-1.groovy
@@ -0,0 +1,13 @@
+def factorize = { long target ->
+
+ if (target == 1) return [1L]
+
+ if (target < 4) return [1L, target]
+
+ def targetSqrt = Math.sqrt(target)
+ def lowfactors = (2L..targetSqrt).grep { (target % it) == 0 }
+ if (lowfactors == []) return [1L, target]
+ def nhalf = lowfactors.size() - ((lowfactors[-1] == targetSqrt) ? 1 : 0)
+
+ [1] + lowfactors + (0..:)&.>/) __ q: 420
+┌─────┬───┬───┬───┐
+│1 2 4│1 3│1 5│1 7│
+└─────┴───┴───┴───┘
diff --git a/Task/Factors-of-an-integer/J/factors-of-an-integer-4.j b/Task/Factors-of-an-integer/J/factors-of-an-integer-4.j
new file mode 100644
index 0000000000..6d29de6a01
--- /dev/null
+++ b/Task/Factors-of-an-integer/J/factors-of-an-integer-4.j
@@ -0,0 +1,6 @@
+factrs=: */&>@{@((^ i.@>:)&.>/)@q:~&__
+ factrs 40
+ 1 5
+ 2 10
+ 4 20
+ 8 40
diff --git a/Task/Factors-of-an-integer/J/factors-of-an-integer-5.j b/Task/Factors-of-an-integer/J/factors-of-an-integer-5.j
new file mode 100644
index 0000000000..efd8eced61
--- /dev/null
+++ b/Task/Factors-of-an-integer/J/factors-of-an-integer-5.j
@@ -0,0 +1,3 @@
+ factors=: [: /:~@, */&>@{@((^ i.@>:)&.>/)@q:~&__
+ factors 420
+1 2 3 4 5 6 7 10 12 14 15 20 21 28 30 35 42 60 70 84 105 140 210 420
diff --git a/Task/Factors-of-an-integer/J/factors-of-an-integer-6.j b/Task/Factors-of-an-integer/J/factors-of-an-integer-6.j
new file mode 100644
index 0000000000..318ac2efa1
--- /dev/null
+++ b/Task/Factors-of-an-integer/J/factors-of-an-integer-6.j
@@ -0,0 +1,2 @@
+ ~.,*/&> { 1 ,&.> q: 40
+1 5 2 10 4 20 8 40
diff --git a/Task/Factors-of-an-integer/J/factors-of-an-integer-7.j b/Task/Factors-of-an-integer/J/factors-of-an-integer-7.j
new file mode 100644
index 0000000000..cfa234ef6c
--- /dev/null
+++ b/Task/Factors-of-an-integer/J/factors-of-an-integer-7.j
@@ -0,0 +1,7 @@
+factorsOfNumber=: monad define
+ Y=. y"_
+ /:~ ~. ( , Y%]) ( #~ 0=]|Y) 1+i.>.%:y
+)
+
+ factorsOfNumber 40
+1 2 4 5 8 10 20 40
diff --git a/Task/Factors-of-an-integer/Java/factors-of-an-integer.java b/Task/Factors-of-an-integer/Java/factors-of-an-integer.java
new file mode 100644
index 0000000000..b2d73af86f
--- /dev/null
+++ b/Task/Factors-of-an-integer/Java/factors-of-an-integer.java
@@ -0,0 +1,13 @@
+public static TreeSet factors(long n)
+{
+ TreeSet factors = new TreeSet();
+ factors.add(n);
+ factors.add(1L);
+ for(long test = n - 1; test >= Math.sqrt(n); test--)
+ if(n % test == 0)
+ {
+ factors.add(test);
+ factors.add(n / test);
+ }
+ return factors;
+}
diff --git a/Task/Factors-of-an-integer/JavaScript/factors-of-an-integer.js b/Task/Factors-of-an-integer/JavaScript/factors-of-an-integer.js
new file mode 100644
index 0000000000..b3ed1ef663
--- /dev/null
+++ b/Task/Factors-of-an-integer/JavaScript/factors-of-an-integer.js
@@ -0,0 +1,20 @@
+function factors(num)
+{
+ var
+ n_factors = [],
+ i;
+
+ for (i = 1; i <= Math.floor(Math.sqrt(num)); i += 1)
+ if (num % i === 0)
+ {
+ n_factors.push(i);
+ if (num / i !== i)
+ n_factors.push(num / i);
+ }
+ n_factors.sort(function(a, b){return a - b;}); // numeric sort
+ return n_factors;
+}
+
+factors(45); // [1,3,5,9,15,45]
+factors(53); // [1,53]
+factors(64); // [1,2,4,8,16,32,64]
diff --git a/Task/Factors-of-an-integer/K/factors-of-an-integer.k b/Task/Factors-of-an-integer/K/factors-of-an-integer.k
new file mode 100644
index 0000000000..62f8cfb163
--- /dev/null
+++ b/Task/Factors-of-an-integer/K/factors-of-an-integer.k
@@ -0,0 +1,23 @@
+ f:{d:&~x!'!1+_sqrt x;?d,_ x%|d}
+
+ f 1
+1
+
+ f 3
+1 3
+
+ f 120
+1 2 3 4 5 6 8 10 12 15 20 24 30 40 60 120
+
+ f 1024
+1 2 4 8 16 32 64 128 256 512 1024
+
+ f 600851475143
+1 71 839 1471 6857 59569 104441 486847 1234169 5753023 10086647 87625999 408464633 716151937 8462696833 600851475143
+
+ #f 3491888400 / has 1920 factors
+1920
+
+ / Number of factors for 3491888400 .. 3491888409
+ #:'f' 3491888400+!10
+1920 16 4 4 12 16 32 16 8 24
diff --git a/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-1.liberty b/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-1.liberty
new file mode 100644
index 0000000000..291e74ed94
--- /dev/null
+++ b/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-1.liberty
@@ -0,0 +1,73 @@
+num = 10677106534462215678539721403561279
+maxnFactors = 1000
+dim primeFactors(maxnFactors), nPrimeFactors(maxnFactors)
+global nDifferentPrimeNumbersFound, nFactors, iFactor
+
+
+print "Start finding all factors of ";num; ":"
+
+nDifferentPrimeNumbersFound=0
+dummy = factorize(num,2)
+nFactors = showPrimeFactors(num)
+dim factors(nFactors)
+dummy = generateFactors(1,1)
+sort factors(), 0, nFactors-1
+for i=1 to nFactors
+ print i;" ";factors(i-1)
+next i
+
+print "done"
+
+wait
+
+
+function factorize(iNum,offset)
+ factorFound=0
+ i = offset
+ do
+ if (iNum MOD i)=0 _
+ then
+ if primeFactors(nDifferentPrimeNumbersFound) = i _
+ then
+ nPrimeFactors(nDifferentPrimeNumbersFound) = nPrimeFactors(nDifferentPrimeNumbersFound) + 1
+ else
+ nDifferentPrimeNumbersFound = nDifferentPrimeNumbersFound + 1
+ primeFactors(nDifferentPrimeNumbersFound) = i
+ nPrimeFactors(nDifferentPrimeNumbersFound) = 1
+ end if
+ if iNum/i<>1 then dummy = factorize(iNum/i,i)
+ factorFound=1
+ end if
+ i=i+1
+ loop while factorFound=0 and i<=sqr(iNum)
+ if factorFound=0 _
+ then
+ nDifferentPrimeNumbersFound = nDifferentPrimeNumbersFound + 1
+ primeFactors(nDifferentPrimeNumbersFound) = iNum
+ nPrimeFactors(nDifferentPrimeNumbersFound) = 1
+ end if
+end function
+
+
+function showPrimeFactors(iNum)
+ showPrimeFactors=1
+ print iNum;" = ";
+ for i=1 to nDifferentPrimeNumbersFound
+ print primeFactors(i);"^";nPrimeFactors(i);
+ if inDifferentPrimeNumbersFound _
+ then
+ factors(iFactor) = product
+ iFactor=iFactor+1
+ else
+ for i=0 to nPrimeFactors(pIndex)
+ dummy = generateFactors(product*primeFactors(pIndex)^i,pIndex+1)
+ next i
+ end if
+ end function
diff --git a/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-2.liberty b/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-2.liberty
new file mode 100644
index 0000000000..a1f577ddcf
--- /dev/null
+++ b/Task/Factors-of-an-integer/Liberty-BASIC/factors-of-an-integer-2.liberty
@@ -0,0 +1,51 @@
+Start finding all factors of 10677106534462215678539721403561279:
+10677106534462215678539721403561279 = 29269^1 * 32579^1 * 98731^2 * 104729^3
+1 1
+2 29269
+3 32579
+4 98731
+5 104729
+6 953554751
+7 2889757639
+8 3065313101
+9 3216557249
+10 3411966091
+11 9747810361
+12 10339998899
+13 10968163441
+14 94145414120981
+15 99864835517479
+16 285308661456109
+17 302641427774831
+18 317573913751019
+19 321027175754629
+20 336866824130521
+21 357331796744339
+22 1020878431297169
+23 1082897744693371
+24 1148684789012489
+25 9295070881578575111
+26 9859755075476219149
+27 10458744358910058191
+28 29880090805636839461
+29 31695334089430275799
+30 33259198413230468851
+31 33620855089606540541
+32 35279725624365333809
+33 37423001741237879131
+34 106915577231321212201
+35 113410797903992051459
+36 973463478356842592799919
+37 1032602289299548955255621
+38 1095333837964291484285239
+39 3129312029983540559911069
+40 3319420643851943354153471
+41 3483202590619213772296379
+42 3694810384914157044482761
+43 11197161487859039232598529
+44 101949856624833767901342716951
+45 108143405156052462534965931709
+46 327729719588146219298926345301
+47 364792324112959639158827476291
+48 10677106534462215678539721403561279
+done
diff --git a/Task/Factors-of-an-integer/Logo/factors-of-an-integer.logo b/Task/Factors-of-an-integer/Logo/factors-of-an-integer.logo
new file mode 100644
index 0000000000..6064639be2
--- /dev/null
+++ b/Task/Factors-of-an-integer/Logo/factors-of-an-integer.logo
@@ -0,0 +1,5 @@
+to factors :n
+ output filter [equal? 0 modulo :n ?] iseq 1 :n
+end
+
+show factors 28 ; [1 2 4 7 14 28]
diff --git a/Task/Factors-of-an-integer/Lua/factors-of-an-integer.lua b/Task/Factors-of-an-integer/Lua/factors-of-an-integer.lua
new file mode 100644
index 0000000000..d4537ce8db
--- /dev/null
+++ b/Task/Factors-of-an-integer/Lua/factors-of-an-integer.lua
@@ -0,0 +1,12 @@
+function Factors( n )
+ local f = {}
+
+ for i = 1, n/2 do
+ if n % i == 0 then
+ f[#f+1] = i
+ end
+ end
+ f[#f+1] = n
+
+ return f
+end
diff --git a/Task/Factors-of-an-integer/MATLAB/factors-of-an-integer.m b/Task/Factors-of-an-integer/MATLAB/factors-of-an-integer.m
new file mode 100644
index 0000000000..e8832a593b
--- /dev/null
+++ b/Task/Factors-of-an-integer/MATLAB/factors-of-an-integer.m
@@ -0,0 +1,11 @@
+ function fact(n);
+ f = factor(n); % prime decomposition
+ K = dec2bin(0:2^length(f)-1)-'0'; % generate all possible permutations
+ F = ones(1,2^length(f));
+ for k = 1:size(K)
+ F(k) = prod(f(~K(k,:))); % and compute products
+ end;
+ F = unique(F); % eliminate duplicates
+ printf('There are %i factors for %i.\n',length(F),n);
+ disp(F);
+ end;
diff --git a/Task/Factors-of-an-integer/MUMPS/factors-of-an-integer.mumps b/Task/Factors-of-an-integer/MUMPS/factors-of-an-integer.mumps
new file mode 100644
index 0000000000..eb094f260b
--- /dev/null
+++ b/Task/Factors-of-an-integer/MUMPS/factors-of-an-integer.mumps
@@ -0,0 +1,11 @@
+factors(num) New fctr,list,sep,sqrt
+ If num<1 Quit "Too small a number"
+ If num["." Quit "Not an integer"
+ Set sqrt=num**0.5\1
+ For fctr=1:1:sqrt Set:num/fctr'["." list(fctr)=1,list(num/fctr)=1
+ Set (list,fctr)="",sep="[" For Set fctr=$Order(list(fctr)) Quit:fctr="" Set list=list_sep_fctr,sep=","
+ Quit list_"]"
+
+w $$factors(45) ; [1,3,5,9,15,45]
+w $$factors(53) ; [1,53]
+w $$factors(64) ; [1,2,4,8,16,32,64]
diff --git a/Task/Factors-of-an-integer/Mathematica/factors-of-an-integer.mathematica b/Task/Factors-of-an-integer/Mathematica/factors-of-an-integer.mathematica
new file mode 100644
index 0000000000..96b7302ed4
--- /dev/null
+++ b/Task/Factors-of-an-integer/Mathematica/factors-of-an-integer.mathematica
@@ -0,0 +1 @@
+Factorize[n_Integer] := Divisors[n]
diff --git a/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-1.maxima b/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-1.maxima
new file mode 100644
index 0000000000..ca56e9c032
--- /dev/null
+++ b/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-1.maxima
@@ -0,0 +1,2 @@
+(%i96) divisors(100);
+(%o96) {1,2,4,5,10,20,25,50,100}
diff --git a/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-2.maxima b/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-2.maxima
new file mode 100644
index 0000000000..42725b35d7
--- /dev/null
+++ b/Task/Factors-of-an-integer/Maxima/factors-of-an-integer-2.maxima
@@ -0,0 +1,5 @@
+divisors2(n) := map( lambda([l], lreduce("*", l)),
+ apply( cartesian_product,
+ map( lambda([fac],
+ setify(makelist(fac[1]^i, i, 0, fac[2]))),
+ ifactors(n))));
diff --git a/Task/Factors-of-an-integer/Mercury/factors-of-an-integer.mercury b/Task/Factors-of-an-integer/Mercury/factors-of-an-integer.mercury
new file mode 100644
index 0000000000..907fc5d8fa
--- /dev/null
+++ b/Task/Factors-of-an-integer/Mercury/factors-of-an-integer.mercury
@@ -0,0 +1,40 @@
+:- module fac.
+
+:- interface.
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module float, int, list, math, string.
+
+main(!IO) :-
+ io.command_line_arguments(Args, !IO),
+ list.filter_map(string.to_int, Args, CleanArgs),
+ list.foldl((pred(Arg::in, !.IO::di, !:IO::uo) is det :-
+ factor(Arg, X),
+ io.format("factor(%d, [", [i(Arg)], !IO),
+ io.write_list(X, ",", io.write_int, !IO),
+ io.write_string("])\n", !IO)
+ ), CleanArgs, !IO).
+
+:- pred factor(int::in, list(int)::out) is det.
+factor(N, Factors) :-
+ Limit = float.truncate_to_int(math.sqrt(float(N))),
+ factor(N, 2, Limit, [], Unsorted),
+ list.sort_and_remove_dups([1, N | Unsorted], Factors).
+
+:- pred factor(int, int, int, list(int), list(int)).
+:- mode factor(in, in, in, in, out) is det.
+factor(N, X, Limit, !Accumulator) :-
+ ( if X > Limit
+ then true
+ else ( if 0 = N mod X
+ then !:Accumulator = [X, N / X | !.Accumulator]
+ else true ),
+ factor(N, X + 1, Limit, !Accumulator) ).
+
+:- func factor(int) = list(int).
+%:- mode factor(in) = out is det.
+factor(N) = Factors :- factor(N, Factors).
+
+:- end_module fac.
diff --git a/Task/Factors-of-an-integer/PHP/factors-of-an-integer.php b/Task/Factors-of-an-integer/PHP/factors-of-an-integer.php
new file mode 100644
index 0000000000..33d5f4fec2
--- /dev/null
+++ b/Task/Factors-of-an-integer/PHP/factors-of-an-integer.php
@@ -0,0 +1,12 @@
+function GetFactors($n){
+ $factors = array(1, $n);
+ for($i = 2; $i * $i <= $n; $i++){
+ if($n % $i == 0){
+ $factors[] = $i;
+ if($i * $i != $n)
+ $factors[] = $n/$i;
+ }
+ }
+ sort($factors);
+ return $factors;
+}
diff --git a/Task/Factors-of-an-integer/Perl/factors-of-an-integer.pl b/Task/Factors-of-an-integer/Perl/factors-of-an-integer.pl
new file mode 100644
index 0000000000..a2f4f485ac
--- /dev/null
+++ b/Task/Factors-of-an-integer/Perl/factors-of-an-integer.pl
@@ -0,0 +1,6 @@
+sub factors
+{
+ my($n) = @_;
+ return grep { $n % $_ == 0 }(1 .. $n);
+}
+print join ' ',factors(64);
diff --git a/Task/Factors-of-an-integer/PicoLisp/factors-of-an-integer.l b/Task/Factors-of-an-integer/PicoLisp/factors-of-an-integer.l
new file mode 100644
index 0000000000..9efd5fe282
--- /dev/null
+++ b/Task/Factors-of-an-integer/PicoLisp/factors-of-an-integer.l
@@ -0,0 +1,4 @@
+(de factors (N)
+ (filter
+ '((D) (=0 (% N D)))
+ (range 1 N) ) )
diff --git a/Task/Factors-of-an-integer/Prolog/factors-of-an-integer.pro b/Task/Factors-of-an-integer/Prolog/factors-of-an-integer.pro
new file mode 100644
index 0000000000..a9279ebfe1
--- /dev/null
+++ b/Task/Factors-of-an-integer/Prolog/factors-of-an-integer.pro
@@ -0,0 +1,26 @@
+factor(N, L) :-
+ factor(N, 1, [], L).
+
+factor(N, X, LC, L) :-
+ 0 is N mod X,
+ !,
+ Q is N / X,
+ (Q = X ->
+ sort([Q | LC], L)
+ ;
+ (Q > X ->
+ X1 is X+1,
+ factor(N, X1, [X, Q|LC], L)
+ ;
+ sort(LC, L)
+ )
+ ).
+
+factor(N, X, LC, L) :-
+ Q is N / X,
+ (Q > X ->
+ X1 is X+1,
+ factor(N, X1, LC, L)
+ ;
+ sort(LC, L)
+ ).
diff --git a/Task/Factors-of-an-integer/Python/factors-of-an-integer-1.py b/Task/Factors-of-an-integer/Python/factors-of-an-integer-1.py
new file mode 100644
index 0000000000..a0928c5d9a
--- /dev/null
+++ b/Task/Factors-of-an-integer/Python/factors-of-an-integer-1.py
@@ -0,0 +1,2 @@
+>>> def factors(n):
+ return [i for i in range(1, n + 1) if not n%i]
diff --git a/Task/Factors-of-an-integer/Python/factors-of-an-integer-2.py b/Task/Factors-of-an-integer/Python/factors-of-an-integer-2.py
new file mode 100644
index 0000000000..1238e13b35
--- /dev/null
+++ b/Task/Factors-of-an-integer/Python/factors-of-an-integer-2.py
@@ -0,0 +1,5 @@
+>>> def factors(n):
+ return [i for i in range(1, n//2 + 1) if not n%i] + [n]
+
+>>> factors(45)
+[1, 3, 5, 9, 15, 45]
diff --git a/Task/Factors-of-an-integer/Python/factors-of-an-integer-3.py b/Task/Factors-of-an-integer/Python/factors-of-an-integer-3.py
new file mode 100644
index 0000000000..ff077bff37
--- /dev/null
+++ b/Task/Factors-of-an-integer/Python/factors-of-an-integer-3.py
@@ -0,0 +1,14 @@
+>>> from math import sqrt
+>>> def factor(n):
+ factors = set()
+ for x in range(1, int(sqrt(n)) + 1):
+ if n % x == 0:
+ factors.add(x)
+ factors.add(n//x)
+ return sorted(factors)
+
+>>> for i in (45, 53, 64): print( "%i: factors: %s" % (i, factor(i)) )
+
+45: factors: [1, 3, 5, 9, 15, 45]
+53: factors: [1, 53]
+64: factors: [1, 2, 4, 8, 16, 32, 64]
diff --git a/Task/Factors-of-an-integer/Python/factors-of-an-integer-4.py b/Task/Factors-of-an-integer/Python/factors-of-an-integer-4.py
new file mode 100644
index 0000000000..2104905adb
--- /dev/null
+++ b/Task/Factors-of-an-integer/Python/factors-of-an-integer-4.py
@@ -0,0 +1,13 @@
+def factor(n):
+ a, r = 1, [1]
+ while a * a < n:
+ a += 1
+ if n % a: continue
+ b, f = 1, []
+ while n % a == 0:
+ n //= a
+ b *= a
+ f += [i * b for i in r]
+ r += f
+ if n > 1: r += [i * n for i in r]
+ return r
diff --git a/Task/Factors-of-an-integer/R/factors-of-an-integer-1.r b/Task/Factors-of-an-integer/R/factors-of-an-integer-1.r
new file mode 100644
index 0000000000..9e6db29310
--- /dev/null
+++ b/Task/Factors-of-an-integer/R/factors-of-an-integer-1.r
@@ -0,0 +1,12 @@
+factors <- function(n)
+{
+ if(length(n) > 1)
+ {
+ lapply(as.list(n), factors)
+ } else
+ {
+ one.to.n <- seq_len(n)
+ one.to.n[(n %% one.to.n) == 0]
+ }
+}
+factors(60)
diff --git a/Task/Factors-of-an-integer/R/factors-of-an-integer-2.r b/Task/Factors-of-an-integer/R/factors-of-an-integer-2.r
new file mode 100644
index 0000000000..ddd3d31eff
--- /dev/null
+++ b/Task/Factors-of-an-integer/R/factors-of-an-integer-2.r
@@ -0,0 +1 @@
+factors(c(45, 53, 64))
diff --git a/Task/Factors-of-an-integer/REXX/factors-of-an-integer-1.rexx b/Task/Factors-of-an-integer/REXX/factors-of-an-integer-1.rexx
new file mode 100644
index 0000000000..27075d8e59
--- /dev/null
+++ b/Task/Factors-of-an-integer/REXX/factors-of-an-integer-1.rexx
@@ -0,0 +1,18 @@
+/*REXX program to calculate and show divisors of positive integer(s). */
+parse arg low high .; high=word(high low 20,1); low=word(low 1,1)
+numeric digits max(9,length(high)) /*ensure modulus has enough digs.*/
+
+ do n=low to high /*the default range is: 1 ──> 20*/
+ say 'divisors of' right(n,length(high)) " ──► " divisors(n)
+ end /*n*/
+exit /*stick a fork in it, we're done.*/
+/*──────────────────────────────────DIVISORS subroutine─────────────────*/
+divisors: procedure; parse arg x 1 b; if x==1 then return 1; a=1; odd=x//2
+ /*Odd? Then use only odd divisors*/
+ do j=2+odd by 1+odd while j*jList(n/x,x)).toList.sort(_>_)
diff --git a/Task/Factors-of-an-integer/Scheme/factors-of-an-integer.ss b/Task/Factors-of-an-integer/Scheme/factors-of-an-integer.ss
new file mode 100644
index 0000000000..37cc801a17
--- /dev/null
+++ b/Task/Factors-of-an-integer/Scheme/factors-of-an-integer.ss
@@ -0,0 +1,9 @@
+(define (factors n)
+ (define (*factors d)
+ (cond ((> d n) (list))
+ ((= (modulo n d) 0) (cons d (*factors (+ d 1))))
+ (else (*factors (+ d 1)))))
+ (*factors 1))
+
+(display (factors 1111111))
+(newline)
diff --git a/Task/Factors-of-an-integer/Tcl/factors-of-an-integer.tcl b/Task/Factors-of-an-integer/Tcl/factors-of-an-integer.tcl
new file mode 100644
index 0000000000..070bcdb8ba
--- /dev/null
+++ b/Task/Factors-of-an-integer/Tcl/factors-of-an-integer.tcl
@@ -0,0 +1,12 @@
+proc factors {n} {
+ set factors {}
+ for {set i 1} {$i <= sqrt($n)} {incr i} {
+ if {$n % $i == 0} {
+ lappend factors $i [expr {$n / $i}]
+ }
+ }
+ return [lsort -unique -integer $factors]
+}
+puts [factors 64]
+puts [factors 45]
+puts [factors 53]
diff --git a/Task/Fast-Fourier-transform/0DESCRIPTION b/Task/Fast-Fourier-transform/0DESCRIPTION
new file mode 100644
index 0000000000..a4b80f2bf2
--- /dev/null
+++ b/Task/Fast-Fourier-transform/0DESCRIPTION
@@ -0,0 +1 @@
+The purpose of this task is to calculate the FFT (Fast Fourier Transform) of an input sequence. The most general case allows for complex numbers at the input and results in a sequence of equal length, again of complex numbers. If you need to restrict yourself to real numbers the output should be the magnitude (i.e. sqrt(re²+im²)) of the complex result. The classic version is the recursive Cooley–Tukey FFT. [http://en.wikipedia.org/wiki/Cooley–Tukey_FFT_algorithm Wikipedia] has pseudocode for that. Further optimizations are possible but not required.
diff --git a/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-1.alg b/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-1.alg
new file mode 100644
index 0000000000..6b7f7c3c9c
--- /dev/null
+++ b/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-1.alg
@@ -0,0 +1,38 @@
+PRIO DICE = 9; # ideally = 11 #
+
+OP DICE = ([]SCALAR in, INT step)[]SCALAR: (
+ ### Dice the array, extract array values a "step" apart ###
+ IF step = 1 THEN
+ in
+ ELSE
+ INT upb out := 0;
+ [(UPB in-LWB in)%step+1]SCALAR out;
+ FOR index FROM LWB in BY step TO UPB in DO
+ out[upb out+:=1] := in[index] OD;
+ out[@LWB in]
+ FI
+);
+
+PROC fft = ([]SCALAR in t)[]SCALAR: (
+ ### The Cooley-Tukey FFT algorithm ###
+ IF LWB in t >= UPB in t THEN
+ in t[@0]
+ ELSE
+ []SCALAR t = in t[@0];
+ INT n = UPB t + 1, half n = n % 2;
+ [LWB t:UPB t]SCALAR coef;
+
+ []SCALAR even = fft(t DICE 2),
+ odd = fft(t[1:]DICE 2);
+
+ COMPL i = 0 I 1;
+
+ REAL w = 2*pi / n;
+ FOR k FROM LWB t TO half n-1 DO
+ COMPL cis t = scalar exp(0 I (-w * k))*odd[k];
+ coef[k] := even[k] + cis t;
+ coef[k + half n] := even[k] - cis t
+ OD;
+ coef
+ FI
+);
diff --git a/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-2.alg b/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-2.alg
new file mode 100644
index 0000000000..f0e07d6183
--- /dev/null
+++ b/Task/Fast-Fourier-transform/ALGOL-68/fast-fourier-transform-2.alg
@@ -0,0 +1,22 @@
+#!/usr/local/bin/a68g --script #
+# -*- coding: utf-8 -*- #
+
+MODE SCALAR = COMPL;
+PROC (COMPL)COMPL scalar exp = complex exp;
+PR READ "Template.Fast_Fourier_transform.a68" PR
+
+FORMAT real fmt := $g(0,3)$;
+FORMAT real array fmt := $f(real fmt)", "$;
+FORMAT compl fmt := $f(real fmt)"⊥"f(real fmt)$;
+FORMAT compl array fmt := $f(compl fmt)", "$;
+
+test:(
+ []COMPL
+ tooth wave ft = fft((1, 1, 1, 1, 0, 0, 0, 0)),
+ one and a quarter wave ft = fft((0, 0.924, 0.707,-0.383,-1,-0.383, 0.707, 0.924,
+ 0,-0.924,-0.707, 0.383, 1, 0.383,-0.707,-0.924));
+ printf((
+ $"Tooth wave: "$,compl array fmt, tooth wave ft, $l$,
+ $"1¼ cycle wave: "$, compl array fmt, one and a quarter wave ft, $l$
+ ))
+)
diff --git a/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-1.ada b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-1.ada
new file mode 100644
index 0000000000..24c6ce5d03
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-1.ada
@@ -0,0 +1,7 @@
+with Ada.Numerics.Generic_Complex_Arrays;
+
+generic
+ with package Complex_Arrays is
+ new Ada.Numerics.Generic_Complex_Arrays (<>);
+ use Complex_Arrays;
+function Generic_FFT (X : Complex_Vector) return Complex_Vector;
diff --git a/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-2.ada b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-2.ada
new file mode 100644
index 0000000000..578137caca
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-2.ada
@@ -0,0 +1,39 @@
+with Ada.Numerics;
+with Ada.Numerics.Generic_Complex_Elementary_Functions;
+
+function Generic_FFT (X : Complex_Vector) return Complex_Vector is
+
+ package Complex_Elementary_Functions is
+ new Ada.Numerics.Generic_Complex_Elementary_Functions
+ (Complex_Arrays.Complex_Types);
+
+ use Ada.Numerics;
+ use Complex_Elementary_Functions;
+ use Complex_Arrays.Complex_Types;
+
+ function FFT (X : Complex_Vector; N, S : Positive)
+ return Complex_Vector is
+ begin
+ if N = 1 then
+ return (1..1 => X (X'First));
+ else
+ declare
+ F : constant Complex := exp (Pi * j / Real_Arrays.Real (N/2));
+ Even : Complex_Vector := FFT (X, N/2, 2*S);
+ Odd : Complex_Vector := FFT (X (X'First + S..X'Last), N/2, 2*S);
+ begin
+ for K in 0..N/2 - 1 loop
+ declare
+ T : constant Complex := Odd (Odd'First + K) / F ** K;
+ begin
+ Odd (Odd'First + K) := Even (Even'First + K) - T;
+ Even (Even'First + K) := Even (Even'First + K) + T;
+ end;
+ end loop;
+ return Even & Odd;
+ end;
+ end if;
+ end FFT;
+begin
+ return FFT (X, X'Length, 1);
+end Generic_FFT;
diff --git a/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-3.ada b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-3.ada
new file mode 100644
index 0000000000..97309d3333
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Ada/fast-fourier-transform-3.ada
@@ -0,0 +1,20 @@
+with Ada.Numerics.Complex_Arrays; use Ada.Numerics.Complex_Arrays;
+with Ada.Complex_Text_IO; use Ada.Complex_Text_IO;
+with Ada.Text_IO; use Ada.Text_IO;
+
+with Ada.Numerics.Complex_Elementary_Functions;
+with Generic_FFT;
+
+procedure Example is
+ function FFT is new Generic_FFT (Ada.Numerics.Complex_Arrays);
+ X : Complex_Vector := (1..4 => (1.0, 0.0), 5..8 => (0.0, 0.0));
+ Y : Complex_Vector := FFT (X);
+begin
+ Put_Line (" X FFT X ");
+ for I in Y'Range loop
+ Put (X (I - Y'First + X'First), Aft => 3, Exp => 0);
+ Put (" ");
+ Put (Y (I), Aft => 3, Exp => 0);
+ New_Line;
+ end loop;
+end;
diff --git a/Task/Fast-Fourier-transform/BBC-BASIC/fast-fourier-transform.bbc b/Task/Fast-Fourier-transform/BBC-BASIC/fast-fourier-transform.bbc
new file mode 100644
index 0000000000..a2ae4ceeba
--- /dev/null
+++ b/Task/Fast-Fourier-transform/BBC-BASIC/fast-fourier-transform.bbc
@@ -0,0 +1,44 @@
+ @% = &60A
+
+ DIM Complex{r#, i#}
+ DIM in{(7)} = Complex{}, out{(7)} = Complex{}
+ DATA 1, 1, 1, 1, 0, 0, 0, 0
+
+ PRINT "Input (real, imag):"
+ FOR I% = 0 TO 7
+ READ in{(I%)}.r#
+ PRINT in{(I%)}.r# "," in{(I%)}.i#
+ NEXT
+
+ PROCfft(out{()}, in{()}, 0, 1, DIM(in{()},1)+1)
+
+ PRINT "Output (real, imag):"
+ FOR I% = 0 TO 7
+ PRINT out{(I%)}.r# "," out{(I%)}.i#
+ NEXT
+ END
+
+ DEF PROCfft(b{()}, o{()}, B%, S%, N%)
+ LOCAL I%, t{} : DIM t{} = Complex{}
+ IF S% < N% THEN
+ PROCfft(o{()}, b{()}, B%, S%*2, N%)
+ PROCfft(o{()}, b{()}, B%+S%, S%*2, N%)
+ FOR I% = 0 TO N%-1 STEP 2*S%
+ t.r# = COS(-PI*I%/N%)
+ t.i# = SIN(-PI*I%/N%)
+ PROCcmul(t{}, o{(B%+I%+S%)})
+ b{(B%+I% DIV 2)}.r# = o{(B%+I%)}.r# + t.r#
+ b{(B%+I% DIV 2)}.i# = o{(B%+I%)}.i# + t.i#
+ b{(B%+(I%+N%) DIV 2)}.r# = o{(B%+I%)}.r# - t.r#
+ b{(B%+(I%+N%) DIV 2)}.i# = o{(B%+I%)}.i# - t.i#
+ NEXT
+ ENDIF
+ ENDPROC
+
+ DEF PROCcmul(c{},d{})
+ LOCAL r#, i#
+ r# = c.r#*d.r# - c.i#*d.i#
+ i# = c.r#*d.i# + c.i#*d.r#
+ c.r# = r#
+ c.i# = i#
+ ENDPROC
diff --git a/Task/Fast-Fourier-transform/C++/fast-fourier-transform.cpp b/Task/Fast-Fourier-transform/C++/fast-fourier-transform.cpp
new file mode 100644
index 0000000000..ea71b12340
--- /dev/null
+++ b/Task/Fast-Fourier-transform/C++/fast-fourier-transform.cpp
@@ -0,0 +1,45 @@
+#include
+#include
+#include
+
+const double PI = 3.141592653589793238460;
+
+typedef std::complex Complex;
+typedef std::valarray CArray;
+
+// Cooley–Tukey FFT (in-place)
+void fft(CArray& x)
+{
+ const size_t N = x.size();
+ if (N <= 1) return;
+
+ // divide
+ CArray even = x[std::slice(0, N/2, 2)];
+ CArray odd = x[std::slice(1, N/2, 2)];
+
+ // conquer
+ fft(even);
+ fft(odd);
+
+ // combine
+ for (size_t k = 0; k < N/2; ++k)
+ {
+ Complex t = std::polar(1.0, -2 * PI * k / N) * odd[k];
+ x[k ] = even[k] + t;
+ x[k+N/2] = even[k] - t;
+ }
+}
+
+int main()
+{
+ const Complex test[] = { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 };
+ CArray data(test, 8);
+
+ fft(data);
+
+ for (int i = 0; i < 8; ++i)
+ {
+ std::cout << data[i] << "\n";
+ }
+ return 0;
+}
diff --git a/Task/Fast-Fourier-transform/C/fast-fourier-transform-1.c b/Task/Fast-Fourier-transform/C/fast-fourier-transform-1.c
new file mode 100644
index 0000000000..21c5b24912
--- /dev/null
+++ b/Task/Fast-Fourier-transform/C/fast-fourier-transform-1.c
@@ -0,0 +1,49 @@
+#include
+#include
+#include
+
+double PI;
+typedef double complex cplx;
+
+void _fft(cplx buf[], cplx out[], int n, int step)
+{
+ if (step < n) {
+ _fft(out, buf, n, step * 2);
+ _fft(out + step, buf + step, n, step * 2);
+
+ for (int i = 0; i < n; i += 2 * step) {
+ cplx t = cexp(-I * PI * i / n) * out[i + step];
+ buf[i / 2] = out[i] + t;
+ buf[(i + n)/2] = out[i] - t;
+ }
+ }
+}
+
+void fft(cplx buf[], int n)
+{
+ cplx out[n];
+ for (int i = 0; i < n; i++) out[i] = buf[i];
+
+ _fft(buf, out, n, 1);
+}
+
+int main()
+{
+ PI = atan2(1, 1) * 4;
+ cplx buf[] = {1, 1, 1, 1, 0, 0, 0, 0};
+
+ void show(const char * s) {
+ printf("%s", s);
+ for (int i = 0; i < 8; i++)
+ if (!cimag(buf[i]))
+ printf("%g ", creal(buf[i]));
+ else
+ printf("(%g, %g) ", creal(buf[i]), cimag(buf[i]));
+ }
+
+ show("Data: ");
+ fft(buf, 8);
+ show("\nFFT : ");
+
+ return 0;
+}
diff --git a/Task/Fast-Fourier-transform/C/fast-fourier-transform-2.c b/Task/Fast-Fourier-transform/C/fast-fourier-transform-2.c
new file mode 100644
index 0000000000..427fd572bc
--- /dev/null
+++ b/Task/Fast-Fourier-transform/C/fast-fourier-transform-2.c
@@ -0,0 +1,2 @@
+Data: 1 1 1 1 0 0 0 0
+FFT : 4 (1, -2.41421) 0 (1, -0.414214) 0 (1, 0.414214) 0 (1, 2.41421)
diff --git a/Task/Fast-Fourier-transform/D/fast-fourier-transform-1.d b/Task/Fast-Fourier-transform/D/fast-fourier-transform-1.d
new file mode 100644
index 0000000000..f68b1d9f32
--- /dev/null
+++ b/Task/Fast-Fourier-transform/D/fast-fourier-transform-1.d
@@ -0,0 +1,15 @@
+import std.stdio, std.math, std.algorithm, std.range;
+
+/*auto*/ creal[] fft(/*in*/ creal[] x) /*pure nothrow*/ {
+ int N = x.length;
+ if (N <= 1) return x;
+ auto ev = stride(x, 2).array().fft();
+ auto od = stride(x[1 .. $], 2).array().fft();
+ auto l = map!(k => ev[k] + expi(-2*PI*k/N) * od[k])(iota(N / 2));
+ auto r = map!(k => ev[k] - expi(-2*PI*k/N) * od[k])(iota(N / 2));
+ return l.chain(r).array();
+}
+
+void main() {
+ writeln(fft([1.0L+0i, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]));
+}
diff --git a/Task/Fast-Fourier-transform/D/fast-fourier-transform-2.d b/Task/Fast-Fourier-transform/D/fast-fourier-transform-2.d
new file mode 100644
index 0000000000..e6158c28c4
--- /dev/null
+++ b/Task/Fast-Fourier-transform/D/fast-fourier-transform-2.d
@@ -0,0 +1,19 @@
+import std.stdio, std.math, std.algorithm, std.range, std.complex;
+
+auto fft(Complex!real[] x)
+{
+ ulong N = x.length;
+ if (N <= 1) { return x; }
+ auto ev = stride(x, 2).array.fft;
+ auto od = stride(x[1 .. $], 2).array.fft;
+ auto l = map!(k => ev[k] + std.complex.expi(-2*PI*k/N) * od[k])(iota(N / 2));
+ auto r = map!(k => ev[k] - std.complex.expi(-2*PI*k/N) * od[k])(iota(N / 2));
+ return l.chain(r).array;
+}
+
+void main()
+{
+ // map produces range, .array converts range to array
+ auto data = [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0].map!(a => Complex!real(a, 0)).array;
+ data.fft.writeln;
+}
diff --git a/Task/Fast-Fourier-transform/D/fast-fourier-transform-3.d b/Task/Fast-Fourier-transform/D/fast-fourier-transform-3.d
new file mode 100644
index 0000000000..5d02157c26
--- /dev/null
+++ b/Task/Fast-Fourier-transform/D/fast-fourier-transform-3.d
@@ -0,0 +1,5 @@
+import std.stdio : writeln;
+import std.numeric : fft;
+void main() {
+ [1.0, 1.0, 1.0, 1.0, 0, 0, 0, 0].fft.writeln;
+}
diff --git a/Task/Fast-Fourier-transform/Fortran/fast-fourier-transform.f b/Task/Fast-Fourier-transform/Fortran/fast-fourier-transform.f
new file mode 100644
index 0000000000..fd4d3e4b5f
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Fortran/fast-fourier-transform.f
@@ -0,0 +1,60 @@
+module fft_mod
+ implicit none
+ integer, parameter :: dp=selected_real_kind(15,300)
+ real(kind=dp), parameter :: pi=3.141592653589793238460_dp
+contains
+
+ ! In place Cooley-Tukey FFT
+ recursive subroutine fft(x)
+ complex(kind=dp), dimension(:), intent(inout) :: x
+ complex(kind=dp) :: t
+ integer :: N
+ integer :: i
+ complex(kind=dp), dimension(:), allocatable :: even, odd
+
+ N=size(x)
+
+ if(n.le.1) return
+
+ allocate(odd((N+1)/2))
+ allocate(even(N/2))
+
+ ! divide
+ odd =x(1:N:2)
+ even=x(2:N:2)
+
+ ! conquer
+ call fft(odd)
+ call fft(even)
+
+ ! combine
+ do i=1,N/2
+
+
+t=exp(cmplx(0.0_dp,-2.0_dp*pi*real(i-1,dp)/real(N,dp),KIND=DP))*even(i)
+ x(i) = odd(i) + t
+ x(i+N/2) = odd(i) - t
+ end do
+
+ deallocate(odd)
+ deallocate(even)
+
+ end subroutine fft
+
+end module fft_mod
+
+program test
+ use fft_mod
+ implicit none
+ complex(kind=dp), dimension(8) :: data = (/1.0, 1.0, 1.0, 1.0, 0.0,
+
+0.0, 0.0, 0.0/)
+ integer :: i
+
+ call fft(data)
+
+ do i=1,8
+ write(*,'("(", F20.15, ",", F20.15, "i )")') data(i)
+ end do
+
+end program test
diff --git a/Task/Fast-Fourier-transform/GAP/fast-fourier-transform.gap b/Task/Fast-Fourier-transform/GAP/fast-fourier-transform.gap
new file mode 100644
index 0000000000..6279554cca
--- /dev/null
+++ b/Task/Fast-Fourier-transform/GAP/fast-fourier-transform.gap
@@ -0,0 +1,23 @@
+# Here an implementation with no optimization (O(n^2)).
+# In GAP, E(n) = exp(2*i*pi/n), a primitive root of the unity.
+
+Fourier := function(a)
+ local n, z;
+ n := Size(a);
+ z := E(n);
+ return List([0 .. n - 1], k -> Sum([0 .. n - 1], j -> a[j + 1]*z^(-k*j)));
+end;
+
+InverseFourier := function(a)
+ local n, z;
+ n := Size(a);
+ z := E(n);
+ return List([0 .. n - 1], k -> Sum([0 .. n - 1], j -> a[j + 1]*z^(k*j)))/n;
+end;
+
+Fourier([1, 1, 1, 1, 0, 0, 0, 0]);
+# [ 4, 1-E(8)-E(8)^2-E(8)^3, 0, 1-E(8)+E(8)^2-E(8)^3,
+# 0, 1+E(8)-E(8)^2+E(8)^3, 0, 1+E(8)+E(8)^2+E(8)^3 ]
+
+InverseFourier(last);
+# [ 1, 1, 1, 1, 0, 0, 0, 0 ]
diff --git a/Task/Fast-Fourier-transform/Go/fast-fourier-transform.go b/Task/Fast-Fourier-transform/Go/fast-fourier-transform.go
new file mode 100644
index 0000000000..05c38e6d61
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Go/fast-fourier-transform.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "fmt"
+ "math"
+ "math/cmplx"
+)
+
+func ditfft2(x []float64, y []complex128, n, s int) {
+ if n == 1 {
+ y[0] = complex(x[0], 0)
+ return
+ }
+ ditfft2(x, y, n/2, 2*s)
+ ditfft2(x[s:], y[n/2:], n/2, 2*s)
+ for k := 0; k < n/2; k++ {
+ tf := cmplx.Rect(1, -2*math.Pi*float64(k)/float64(n)) * y[k+n/2]
+ y[k], y[k+n/2] = y[k]+tf, y[k]-tf
+ }
+}
+
+func main() {
+ x := []float64{1, 1, 1, 1, 0, 0, 0, 0}
+ y := make([]complex128, len(x))
+ ditfft2(x, y, len(x), 1)
+ for _, c := range y {
+ fmt.Printf("%8.4f\n", c)
+ }
+}
diff --git a/Task/Fast-Fourier-transform/Haskell/fast-fourier-transform.hs b/Task/Fast-Fourier-transform/Haskell/fast-fourier-transform.hs
new file mode 100644
index 0000000000..d811dd4e8e
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Haskell/fast-fourier-transform.hs
@@ -0,0 +1,17 @@
+import Data.Complex
+
+-- Cooley-Tukey
+fft [] = []
+fft [x] = [x]
+fft xs = zipWith (+) ys ts ++ zipWith (-) ys ts
+ where n = length xs
+ ys = fft evens
+ zs = fft odds
+ (evens, odds) = split xs
+ split [] = ([], [])
+ split [x] = ([x], [])
+ split (x:y:xs) = (x:xt, y:yt) where (xt, yt) = split xs
+ ts = zipWith (\z k -> exp' k n * z) zs [0..]
+ exp' k n = cis $ -2 * pi * (fromIntegral k) / (fromIntegral n)
+
+main = mapM_ print $ fft [1,1,1,1,0,0,0,0]
diff --git a/Task/Fast-Fourier-transform/J/fast-fourier-transform-1.j b/Task/Fast-Fourier-transform/J/fast-fourier-transform-1.j
new file mode 100644
index 0000000000..4f0b412325
--- /dev/null
+++ b/Task/Fast-Fourier-transform/J/fast-fourier-transform-1.j
@@ -0,0 +1,4 @@
+cube =: ($~ q:@#) :. ,
+rou =: ^@j.@o.@(% #)@i.@-: NB. roots of unity
+floop =: 4 : 'for_r. i.#$x do. (y=.{."1 y) ] x=.(+/x) ,&,:"r (-/x)*y end.'
+fft =: ] floop&.cube rou@#
diff --git a/Task/Fast-Fourier-transform/J/fast-fourier-transform-2.j b/Task/Fast-Fourier-transform/J/fast-fourier-transform-2.j
new file mode 100644
index 0000000000..737ec8889d
--- /dev/null
+++ b/Task/Fast-Fourier-transform/J/fast-fourier-transform-2.j
@@ -0,0 +1,3 @@
+ (**+)&.+. (,: fft) 1 o. 2p1*3r16 * i.16
+0 0.92388 0.707107 0.382683 1 0.382683 0.707107 0.92388 0 0.92388 0.707107 0.382683 1 0.382683 0.707107 0.92388
+0 0 0 0j8 0 0 0 0 0 0 0 0 0 0j8 0 0
diff --git a/Task/Fast-Fourier-transform/J/fast-fourier-transform-3.j b/Task/Fast-Fourier-transform/J/fast-fourier-transform-3.j
new file mode 100644
index 0000000000..6f6139d699
--- /dev/null
+++ b/Task/Fast-Fourier-transform/J/fast-fourier-transform-3.j
@@ -0,0 +1,9 @@
+ Re=: {.@+.@fft
+ Im=: {:@+.@fft
+ M=: 4#1 0
+ M
+1 1 1 1 0 0 0 0
+ Re M
+4 1 0 1 0 1 0 1
+ Im M
+0 2.41421 0 0.414214 0 _0.414214 0 _2.41421
diff --git a/Task/Fast-Fourier-transform/Liberty-BASIC/fast-fourier-transform.liberty b/Task/Fast-Fourier-transform/Liberty-BASIC/fast-fourier-transform.liberty
new file mode 100644
index 0000000000..d24046979c
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Liberty-BASIC/fast-fourier-transform.liberty
@@ -0,0 +1,105 @@
+ P =8
+ S =int( log( P) /log( 2) +0.9999)
+
+ Pi =3.14159265
+ R1 =2^S
+
+ R =R1 -1
+ R2 =div( R1, 2)
+ R4 =div( R1, 4)
+ R3 =R4 +R2
+
+ Dim Re( R1), Im( R1), Co( R3)
+
+ for N =0 to P -1
+ read dummy: Re( N) =dummy
+ read dummy: Im( N) =dummy
+ next N
+
+ data 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
+
+ S2 =div( S, 2)
+ S1 =S -S2
+ P1 =2^S1
+ P2 =2^S2
+
+ dim V( P1 -1)
+ V( 0) =0
+ DV =1
+ DP =P1
+
+ for J =1 to S1
+ HA =div( DP, 2)
+ PT =P1 -HA
+ for I =HA to PT step DP
+ V( I) =V( I -HA) +DV
+ next I
+ DV =DV +DV
+ DP =HA
+ next J
+
+ K =2 *Pi /R1
+
+ for X =0 to R4
+ COX =cos( K *X)
+ Co( X) =COX
+ Co( R2 -X) =0 -COX
+ Co( R2 +X) =0 -COX
+ next X
+
+ print "FFT: bit reversal"
+
+ for I =0 to P1 -1
+ IP =I *P2
+ for J =0 to P2 -1
+ H =IP +J
+ G =V( J) *P2 +V( I)
+ if G >H then temp =Re( G): Re( G) =Re( H): Re( H) =temp
+ if G >H then temp =Im( G): Im( G) =Im( H): Im( H) =temp
+ next J
+ next I
+
+ T =1
+
+ for stage =0 to S -1
+ print " Stage:- "; stage
+ D =div( R2, T)
+ for Z =0 to T -1
+ L =D *Z
+ LS =L +R4
+ for I =0 to D -1
+ A =2 *I *T +Z
+ B =A +T
+ F1 =Re( A)
+ F2 =Im( A)
+ P1 =Co( L) *Re( B)
+ P2 =Co( LS) *Im( B)
+ P3 =Co( LS) *Re( B)
+ P4 =Co( L) *Im( B)
+ Re( A) =F1 +P1 -P2
+ Im( A) =F2 +P3 +P4
+ Re( B) =F1 -P1 +P2
+ Im( B) =F2 -P3 -P4
+ next I
+ next Z
+ T =T +T
+ next stage
+
+ print " M Re( M) Im( M)"
+
+ for M =0 to R
+ if abs( Re( M)) <10^-5 then Re( M) =0
+ if abs( Im( M)) <10^-5 then Im( M) =0
+ print " "; M, Re( M), Im( M)
+ next M
+
+ end
+
+
+ wait
+
+ function div( a, b)
+ div =int( a /b)
+ end function
+
+ end
diff --git a/Task/Fast-Fourier-transform/MATLAB/fast-fourier-transform.m b/Task/Fast-Fourier-transform/MATLAB/fast-fourier-transform.m
new file mode 100644
index 0000000000..4a06ec63d5
--- /dev/null
+++ b/Task/Fast-Fourier-transform/MATLAB/fast-fourier-transform.m
@@ -0,0 +1 @@
+ fft([1,1,1,1,0,0,0,0]')
diff --git a/Task/Fast-Fourier-transform/Mathematica/fast-fourier-transform.mathematica b/Task/Fast-Fourier-transform/Mathematica/fast-fourier-transform.mathematica
new file mode 100644
index 0000000000..b1a04c9722
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Mathematica/fast-fourier-transform.mathematica
@@ -0,0 +1 @@
+Fourier[{1,1,1,1,0,0,0,0}, FourierParameters->{1,-1}]
diff --git a/Task/Fast-Fourier-transform/Maxima/fast-fourier-transform.maxima b/Task/Fast-Fourier-transform/Maxima/fast-fourier-transform.maxima
new file mode 100644
index 0000000000..4c04161fcf
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Maxima/fast-fourier-transform.maxima
@@ -0,0 +1,3 @@
+load(fft)$
+fft([1, 2, 3, 4]);
+[2.5, -0.5 * %i - 0.5, -0.5, 0.5 * %i - 0.5]
diff --git a/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-1.l b/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-1.l
new file mode 100644
index 0000000000..c0d495a19a
--- /dev/null
+++ b/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-1.l
@@ -0,0 +1,20 @@
+# apt-get install libfftw3-dev
+
+(scl 4)
+
+(de FFTW_FORWARD . -1)
+(de FFTW_ESTIMATE . 64)
+
+(de fft (Lst)
+ (let
+ (Len (length Lst)
+ In (native "libfftw3.so" "fftw_malloc" 'N (* Len 16))
+ Out (native "libfftw3.so" "fftw_malloc" 'N (* Len 16))
+ P (native "libfftw3.so" "fftw_plan_dft_1d" 'N
+ Len In Out FFTW_FORWARD FFTW_ESTIMATE ) )
+ (struct In NIL (cons 1.0 (apply append Lst)))
+ (native "libfftw3.so" "fftw_execute" NIL P)
+ (prog1 (struct Out (make (do Len (link (1.0 . 2)))))
+ (native "libfftw3.so" "fftw_destroy_plan" NIL P)
+ (native "libfftw3.so" "fftw_free" NIL Out)
+ (native "libfftw3.so" "fftw_free" NIL In) ) ) )
diff --git a/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-2.l b/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-2.l
new file mode 100644
index 0000000000..fcf9ee4451
--- /dev/null
+++ b/Task/Fast-Fourier-transform/PicoLisp/fast-fourier-transform-2.l
@@ -0,0 +1,4 @@
+(for R (fft '((1.0 0) (1.0 0) (1.0 0) (1.0 0) (0 0) (0 0) (0 0) (0 0)))
+ (tab (6 8)
+ (round (car R))
+ (round (cadr R)) ) )
diff --git a/Task/Fast-Fourier-transform/Python/fast-fourier-transform-1.py b/Task/Fast-Fourier-transform/Python/fast-fourier-transform-1.py
new file mode 100644
index 0000000000..fc0151d1d4
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Python/fast-fourier-transform-1.py
@@ -0,0 +1,11 @@
+from cmath import exp, pi
+
+def fft(x):
+ N = len(x)
+ if N <= 1: return x
+ even = fft(x[0::2])
+ odd = fft(x[1::2])
+ return [even[k] + exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)] + \
+ [even[k] - exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)]
+
+print fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])
diff --git a/Task/Fast-Fourier-transform/Python/fast-fourier-transform-2.py b/Task/Fast-Fourier-transform/Python/fast-fourier-transform-2.py
new file mode 100644
index 0000000000..33534e7988
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Python/fast-fourier-transform-2.py
@@ -0,0 +1,5 @@
+>>> from numpy.fft import fft
+>>> from numpy import array
+>>> a = array((0.0, 0.924, 0.707, -0.383, -1.0, -0.383, 0.707, 0.924, 0.0, -0.924, -0.707, 0.383, 1.0, 0.383, -0.707, -0.924))
+>>> print( ' '.join("%5.3f" % abs(f) for f in fft(a)) )
+0.000 0.001 0.000 8.001 0.000 0.001 0.000 0.001 0.000 0.001 0.000 0.001 0.000 8.001 0.000 0.001
diff --git a/Task/Fast-Fourier-transform/R/fast-fourier-transform.r b/Task/Fast-Fourier-transform/R/fast-fourier-transform.r
new file mode 100644
index 0000000000..c753e33866
--- /dev/null
+++ b/Task/Fast-Fourier-transform/R/fast-fourier-transform.r
@@ -0,0 +1 @@
+fft(c(1,1,1,1,0,0,0,0))
diff --git a/Task/Fast-Fourier-transform/REXX/fast-fourier-transform.rexx b/Task/Fast-Fourier-transform/REXX/fast-fourier-transform.rexx
new file mode 100644
index 0000000000..95ec69c891
--- /dev/null
+++ b/Task/Fast-Fourier-transform/REXX/fast-fourier-transform.rexx
@@ -0,0 +1,77 @@
+/*REXX pgm does a fast Fourier transform (FFT) on a set of complex nums.*/
+numeric digits 85
+arg data; if data='' then data='1 1 1 1 0' /*no data? Then use default*/
+data=translate(data, 'J', "I") /*allow use of i as well as j */
+size=words(data); pad=left('',6) /*PAD: for indenting/padding SAYs*/
+ do sig=0 until 2**sig>=size ;end /* # args exactly a power of 2?*/
+ do j=size+1 to 2**sig;data=data 0;end /*add zeroes until a power of 2.*/
+size=words(data); call hdr /*┌─────────────────────────────┐*/
+ /*│ Numbers in data can be in │*/
+ do j=0 for size /*│ 7 formats: real │*/
+ _=word(data,j+1) /*│ real,imag │*/
+ parse var _ #.1.j ',' #.2.j /*│ ,imag │*/
+ if right(#.1.j,1)=='J' then /*│ nnnJ │*/
+ parse var #.1.j #2.j "J" @.1.j /*│ nnnj │*/
+ do p=1 for 2 /*omitted?*/ /*│ nnnI │*/
+ #.p.j=word(#.p.j 0, 1) /*│ nnni │*/
+ end /*p*/ /*└─────────────────────────────┘*/
+ say pad " FFT in " center(j+1,7) pad nice(#.1.j) nice(#.2.j,'i')
+ end /*j*/
+
+say; say; tran=2*pi()/2**sig; !.=0
+hsig=2**sig%2; counterA=2**(sig-sig%2); pointer=counterA; doubler=1
+
+ do sig-sig%2; halfpointer=pointer%2
+ do i=halfpointer by pointer to counterA-halfpointer
+ _=i-halfpointer; !.i=!._+doubler
+ end /*i*/
+ doubler=doubler*2; pointer=halfpointer
+ end /*sig-sig%2*/
+
+ do j=0 to 2**sig%4; cmp.j=cos(j*tran); _m=hsig-j; cmp._m=-cmp.j
+ _p=hsig+j; cmp._p=-cmp.j
+ end /*j*/
+
+counterB=2**(sig%2)
+
+ do i=0 for counterA; p=i*counterB
+ do j=0 for counterB; h=p+j; _=!.j*counterB+!.i; if _<=h then iterate
+ parse value #.1._ #.1.h #.2._ #.2.h with #.1.h #.1._ #.2.h #.2._
+ end /*j*/ /* [↓] switch two sets of values*/
+ end /*i*/
+
+double=1; do sig ; w=2**sig%2%double
+ do k=0 for double ; lb=w*k ; lh=lb+2**sig%4
+ do j=0 for w ; a=j*double*2+k ; b=a+double
+ r=#.1.a; i=#.2.a ; c1=cmp.lb*#.1.b ; c4=cmp.lb*#.2.b
+ c2=cmp.lh*#.2.b ; c3=cmp.lh*#.1.b
+ #.1.a=r+c1-c2 ; #.2.a=i+c3+c4
+ #.1.b=r-c1+c2 ; #.2.b=i-c3-c4
+ end /*j*/
+ end /*k*/
+ double=double+double
+ end /*sig*/
+call hdr
+ do i=0 for size
+ say pad " FFT out " center(i+1,7) pad nice(#.1.i) nice(#.2.i,'j')
+ end /*i*/
+exit /*stick a fork in it, we're done.*/
+/*──────────────────────────────────HDR subroutine──────────────────────*/
+hdr: _='───data─── num real-part imaginary-part'; say pad _
+ say pad translate(_, " "copies('═',256), " "xrange()); return
+/*──────────────────────────────────PI subroutine───────────────────────────────────*/
+pi: return , /*add more digs if NUMERIC DIGITS > 85. */
+3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628
+/*──────────────────────────────────R2R subroutine──────────────────────*/
+r2r: return arg(1) // (2*pi()) /*reduce radians to unit circle. */
+/*──────────────────────────────────COS subroutine──────────────────────*/
+cos: procedure; parse arg x; x=r2r(x); return .sincos(1,1,-1)
+.sincos: parse arg z,_,i; x=x*x; p=z
+ do k=2 by 2; _=-_*x/(k*(k+i)); z=z+_; if z=p then leave; p=z; end
+ return z
+/*──────────────────────────────────NICE subroutine─────────────────────*/
+nice: procedure; parse arg x,j /*makes complex nums look nicer. */
+numeric digits digits()%10; nz='1e-'digits() /*show ≈10% of DIGITS.*/
+if abs(x)=0 then x=' '||x; return left(x||j,digits()+4)
diff --git a/Task/Fast-Fourier-transform/Scala/fast-fourier-transform.scala b/Task/Fast-Fourier-transform/Scala/fast-fourier-transform.scala
new file mode 100644
index 0000000000..08ae1d4449
--- /dev/null
+++ b/Task/Fast-Fourier-transform/Scala/fast-fourier-transform.scala
@@ -0,0 +1,32 @@
+object FFT extends App {
+ import scala.math._
+
+ case class Complex(re: Double, im: Double = 0.0) {
+ def +(x: Complex): Complex = Complex((this.re+x.re),(this.im+x.im))
+ def -(x: Complex): Complex = Complex((this.re-x.re),(this.im-x.im))
+ def *(x: Complex): Complex = Complex(this.re*x.re-this.im*x.im,this.re*x.im+this.im*x.re)
+ }
+
+ def fft(f: List[Complex]): List[Complex] = {
+ import Stream._
+ require((f.size==0)||(from(0) map {x=>pow(2,x).toInt}).takeWhile(_<2*f.size).toList.exists(_==f.size)==true,"list size "+f.size+" not allowed!")
+ f.size match {
+ case 0 => Nil
+ case 1 => f
+ case n => {
+ val cis: Double => Complex = phi => Complex(cos(phi),sin(phi))
+ val e = fft(f.zipWithIndex.filter(_._2%2==0).map(_._1))
+ val o = fft(f.zipWithIndex.filter(_._2%2!=0).map(_._1))
+ import scala.collection.mutable.ListBuffer
+ val lb = new ListBuffer[Pair[Int, Complex]]()
+ for (k <- 0 to n/2-1) {
+ lb += Pair(k,e(k)+o(k)*cis(-2*Pi*k/n))
+ lb += Pair(k+n/2,e(k)-o(k)*cis(-2*Pi*k/n))
+ }
+ lb.toList.sortWith((x,y)=>x._1n = 2 we have the Fibonacci sequence; with initial values and
+# For we have the tribonacci sequence; with initial values and
+# For we have the tetranacci sequence; with initial values and
...
+# For general we have the Fibonacci -step sequence - ; with initial values of the first values of the 'th Fibonacci -step sequence ; and 'th value of this 'th sequence being
+
+For small values of , [[wp:Number prefix#Greek_series|Greek numeric prefixes]] are sometimes used to individually name each series.
+
+:{| style="text-align: left;" border="4" cellpadding="2" cellspacing="2"
+|+ Fibonacci -step sequences
+|- style="background-color: rgb(255, 204, 255);"
+! !! Series name !! Values
+|-
+| 2 || fibonacci || 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
+|-
+| 3 || tribonacci || 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...
+|-
+| 4 || tetranacci || 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...
+|-
+| 5 || pentanacci || 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...
+|-
+| 6 || hexanacci || 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...
+|-
+| 7 || heptanacci || 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...
+|-
+| 8 || octonacci || 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...
+|-
+| 9 || nonanacci || 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...
+|-
+| 10 || decanacci || 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ...
+|}
+
+Allied sequences can be generated where the initial values are changed:
+: '''The [[wp:Lucas number|Lucas series]]''' sums the two preceeding values like the fibonacci series for but uses as its initial values.
+
+;The task is to:
+# Write a function to generate Fibonacci -step number sequences given its initial values and assuming the number of initial values determines how many previous values are summed to make the next number of the series.
+# Use this to print and show here at least the first ten members of the Fibo/tribo/tetra-nacci and Lucas sequences.
+
+;Cf.:
+* [[Fibonacci sequence]]
+* [http://mathworld.wolfram.com/Fibonaccin-StepNumber.html Wolfram Mathworld]
+* [[Hofstadter Q sequence]]
diff --git a/Task/Fibonacci-n-step-number-sequences/ACL2/fibonacci-n-step-number-sequences.acl2 b/Task/Fibonacci-n-step-number-sequences/ACL2/fibonacci-n-step-number-sequences.acl2
new file mode 100644
index 0000000000..e39199b9e6
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/ACL2/fibonacci-n-step-number-sequences.acl2
@@ -0,0 +1,13 @@
+(defun sum (xs)
+ (if (endp xs)
+ 0
+ (+ (first xs)
+ (sum (rest xs)))))
+
+(defun n-bonacci (prevs limit)
+ (if (zp limit)
+ nil
+ (let ((next (append (rest prevs)
+ (list (sum prevs)))))
+ (cons (first next)
+ (n-bonacci next (1- limit))))))
diff --git a/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-1.ada b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-1.ada
new file mode 100644
index 0000000000..7284d33835
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-1.ada
@@ -0,0 +1,11 @@
+package Bonacci is
+
+ type Sequence is array(Positive range <>) of Positive;
+
+ function Generate(Start: Sequence; Length: Positive := 10) return Sequence;
+
+ Start_Fibonacci: constant Sequence := (1, 1);
+ Start_Tribonacci: constant Sequence := (1, 1, 2);
+ Start_Tetranacci: constant Sequence := (1, 1, 2, 4);
+ Start_Lucas: constant Sequence := (2, 1);
+end Bonacci;
diff --git a/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-2.ada b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-2.ada
new file mode 100644
index 0000000000..c1c4709cff
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-2.ada
@@ -0,0 +1,20 @@
+package body Bonacci is
+
+ function Generate(Start: Sequence; Length: Positive := 10) return Sequence is
+ begin
+ if Length <= Start'Length then
+ return Start(Start'First .. Start'First+Length-1);
+ else
+ declare
+ Sum: Natural := 0;
+ begin
+ for I in Start'Range loop
+ Sum := Sum + Start(I);
+ end loop;
+ return Start(Start'First)
+ & Generate(Start(Start'First+1 .. Start'Last) & Sum, Length-1);
+ end;
+ end if;
+ end Generate;
+
+end Bonacci;
diff --git a/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-3.ada b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-3.ada
new file mode 100644
index 0000000000..9e069f09a5
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ada/fibonacci-n-step-number-sequences-3.ada
@@ -0,0 +1,21 @@
+with Ada.Text_IO, Bonacci;
+
+procedure Test_Bonacci is
+
+ procedure Print(Name: String; S: Bonacci.Sequence) is
+ begin
+ Ada.Text_IO.Put(Name & "(");
+ for I in S'First .. S'Last-1 loop
+ Ada.Text_IO.Put(Integer'Image(S(I)) & ",");
+ end loop;
+ Ada.Text_IO.Put_Line(Integer'Image(S(S'Last)) & " )");
+ end Print;
+
+begin
+ Print("Fibonacci: ", Bonacci.Generate(Bonacci.Start_Fibonacci));
+ Print("Tribonacci: ", Bonacci.Generate(Bonacci.Start_Tribonacci));
+ Print("Tetranacci: ", Bonacci.Generate(Bonacci.Start_Tetranacci));
+ Print("Lucas: ", Bonacci.Generate(Bonacci.Start_Lucas));
+ Print("Decanacci: ",
+ Bonacci.Generate((1, 1, 2, 4, 8, 16, 32, 64, 128, 256), 15));
+end Test_Bonacci;
diff --git a/Task/Fibonacci-n-step-number-sequences/BBC-BASIC/fibonacci-n-step-number-sequences.bbc b/Task/Fibonacci-n-step-number-sequences/BBC-BASIC/fibonacci-n-step-number-sequences.bbc
new file mode 100644
index 0000000000..ac4f4409d4
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/BBC-BASIC/fibonacci-n-step-number-sequences.bbc
@@ -0,0 +1,27 @@
+ @% = 5 : REM Column width
+
+ PRINT "Fibonacci:"
+ DIM f2%(1) : f2%() = 1,1
+ FOR i% = 1 TO 12 : PRINT f2%(0); : PROCfibn(f2%()) : NEXT : PRINT " ..."
+
+ PRINT "Tribonacci:"
+ DIM f3%(2) : f3%() = 1,1,2
+ FOR i% = 1 TO 12 : PRINT f3%(0); : PROCfibn(f3%()) : NEXT : PRINT " ..."
+
+ PRINT "Tetranacci:"
+ DIM f4%(3) : f4%() = 1,1,2,4
+ FOR i% = 1 TO 12 : PRINT f4%(0); : PROCfibn(f4%()) : NEXT : PRINT " ..."
+
+ PRINT "Lucas:"
+ DIM fl%(1) : fl%() = 2,1
+ FOR i% = 1 TO 12 : PRINT fl%(0); : PROCfibn(fl%()) : NEXT : PRINT " ..."
+ END
+
+ DEF PROCfibn(f%())
+ LOCAL i%, s%
+ s% = SUM(f%())
+ FOR i% = 1 TO DIM(f%(),1)
+ f%(i%-1) = f%(i%)
+ NEXT
+ f%(i%-1) = s%
+ ENDPROC
diff --git a/Task/Fibonacci-n-step-number-sequences/C++/fibonacci-n-step-number-sequences.cpp b/Task/Fibonacci-n-step-number-sequences/C++/fibonacci-n-step-number-sequences.cpp
new file mode 100644
index 0000000000..7ab202eba6
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/C++/fibonacci-n-step-number-sequences.cpp
@@ -0,0 +1,50 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+std::vector nacci ( const std::vector & start , int arity ) {
+ std::vector result ( start ) ;
+ int sumstart = 1 ;//summing starts at vector's begin + sumstart as
+ //soon as the vector is longer than arity
+ while ( result.size( ) < 15 ) { //we print out the first 15 numbers
+ if ( result.size( ) <= arity )
+ result.push_back( std::accumulate( result.begin( ) ,
+ result.begin( ) + result.size( ) , 0 ) ) ;
+ else {
+ result.push_back( std::accumulate ( result.begin( ) +
+ sumstart , result.begin( ) + sumstart + arity , 0 )) ;
+ sumstart++ ;
+ }
+ }
+ return std::move ( result ) ;
+}
+
+int main( ) {
+ std::vector naccinames {"fibo" , "tribo" ,
+ "tetra" , "penta" , "hexa" , "hepta" , "octo" , "nona" , "deca" } ;
+ const std::vector fibo { 1 , 1 } , lucas { 2 , 1 } ;
+ for ( int i = 2 ; i < 11 ; i++ ) {
+ std::vector numberrow = nacci ( fibo , i ) ;
+ std::cout << std::left << std::setw( 10 ) <<
+ naccinames[ i - 2 ].append( "nacci" ) <<
+ std::setw( 2 ) << " : " ;
+ std::copy ( numberrow.begin( ) , numberrow.end( ) ,
+ std::ostream_iterator( std::cout , " " ) ) ;
+ std::cout << "...\n" ;
+ numberrow = nacci ( lucas , i ) ;
+ std::cout << "Lucas-" << i ;
+ if ( i < 10 ) //for formatting purposes
+ std::cout << " : " ;
+ else
+ std::cout << " : " ;
+ std::copy ( numberrow.begin( ) , numberrow.end( ) ,
+ std::ostream_iterator( std::cout , " " ) ) ;
+ std::cout << "...\n" ;
+ }
+ return 0 ;
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/C/fibonacci-n-step-number-sequences.c b/Task/Fibonacci-n-step-number-sequences/C/fibonacci-n-step-number-sequences.c
new file mode 100644
index 0000000000..99b9482504
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/C/fibonacci-n-step-number-sequences.c
@@ -0,0 +1,45 @@
+/*29th August, 2012
+Abhishek Ghosh
+
+The function anynacci determines the n-arity of the sequence from the number of seed elements. 0 ended arrays are used since C does not have a way of determining the length of dynamic and function-passed integer arrays.*/
+
+#include
+#include
+
+int *
+anynacci (int *seedArray, int howMany)
+{
+ int *result = malloc (howMany * sizeof (int));
+ int i, j, initialCardinality;
+
+ for (i = 0; seedArray[i] != 0; i++);
+ initialCardinality = i;
+
+ for (i = 0; i < initialCardinality; i++)
+ result[i] = seedArray[i];
+
+ for (i = initialCardinality; i < howMany; i++)
+ {
+ result[i] = 0;
+ for (j = i - initialCardinality; j < i; j++)
+ result[i] += result[j];
+ }
+ return result;
+}
+
+int
+main ()
+{
+ int fibo[] = { 1, 1, 0 }, tribo[] = { 1, 1, 2, 0 }, tetra[] = { 1, 1, 2, 4, 0 }, luca[] = { 2, 1, 0 };
+ int *fibonacci = anynacci (fibo, 10), *tribonacci = anynacci (tribo, 10), *tetranacci = anynacci (tetra, 10),
+ *lucas = anynacci(luca, 10);
+ int i;
+
+ printf ("\nFibonacci\tTribonacci\tTetranacci\tLucas\n");
+
+ for (i = 0; i < 10; i++)
+ printf ("\n%d\t\t%d\t\t%d\t\t%d", fibonacci[i], tribonacci[i],
+ tetranacci[i], lucas[i]);
+
+ return 0;
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-1.d b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-1.d
new file mode 100644
index 0000000000..cc32b84217
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-1.d
@@ -0,0 +1,29 @@
+import std.stdio, std.algorithm, std.range, std.conv;
+
+void main() {
+ int[] memo;
+ size_t addNum;
+
+ void setHead(int[] head) nothrow {
+ memo = head;
+ addNum = head.length;
+ }
+
+ int fibber(in size_t n) /*nothrow*/ {
+ if (n >= memo.length)
+ memo ~= iota(n - addNum, n).map!fibber().reduce!q{a + b}();
+ return memo[n];
+ }
+
+ setHead([1, 1]);
+ iota(10).map!fibber().writeln();
+ setHead([2, 1]);
+ iota(10).map!fibber().writeln();
+
+ auto prefixes = "fibo tribo tetra penta hexa hepta octo nona deca";
+ foreach (n, name; zip(iota(2, 11), prefixes.split())) {
+ setHead(1 ~ iota(n - 1).map!q{2 ^^ a}().array());
+ auto items = iota(15).map!(i => text(fibber(i)))().join(" ");
+ writefln("n=%2d, %5snacci -> %s ...", n, name, items);
+ }
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-2.d b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-2.d
new file mode 100644
index 0000000000..e500b0f2a9
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-2.d
@@ -0,0 +1,34 @@
+import std.stdio, std.algorithm, std.range, std.conv;
+
+struct fiblike(T) {
+ T[] memo;
+ immutable size_t addNum;
+
+ this(in T[] start) /*nothrow*/ {
+ this.memo = start.dup;
+ this.addNum = start.length;
+ }
+
+ T opCall(in size_t n) /*nothrow*/ {
+ if (n >= memo.length)
+ memo ~= iota(n - addNum, n)
+ .map!(i => opCall(i))()
+ .reduce!q{a + b}();
+ return memo[n];
+ }
+}
+
+void main() {
+ auto fibo = fiblike!int([1, 1]);
+ iota(10).map!fibo().writeln();
+
+ auto lucas = fiblike!int([2, 1]);
+ iota(10).map!lucas().writeln();
+
+ const prefixes = "fibo tribo tetra penta hexa hepta octo nona deca";
+ foreach (n, name; zip(iota(2, 11), prefixes.split())) {
+ auto fib = fiblike!int(1 ~ iota(n - 1).map!q{2 ^^ a}().array());
+ writefln("n=%2d, %5snacci -> %(%d %) ...",
+ n, name, iota(15).map!fib());
+ }
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-3.d b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-3.d
new file mode 100644
index 0000000000..7cee5cf0f8
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/D/fibonacci-n-step-number-sequences-3.d
@@ -0,0 +1,41 @@
+import std.stdio, std.algorithm, std.range, std.traits;
+
+struct Fiblike(T) {
+ T[] tail;
+
+ int opApply(int delegate(ref T) dg) {
+ int result, pos;
+ foreach (x; tail) {
+ result = dg(x);
+ if (result) return result;
+ }
+ foreach (i; cycle(iota(tail.length))) {
+ auto x = tail.reduce!q{a + b}();
+ result = dg(x);
+ if (result) break;
+ tail[i] = x;
+ }
+ return result;
+ }
+}
+
+// std.range.take doesn't work with opApply
+ForeachType!It[] takeApply(It)(It iterable, size_t n) {
+ typeof(return) result;
+ foreach (x; iterable) {
+ result ~= x;
+ if (result.length == n) break;
+ }
+ return result;
+}
+
+void main() {
+ Fiblike!int([1, 1]).takeApply(10).writeln();
+ Fiblike!int([2, 1]).takeApply(10).writeln();
+
+ auto prefixes = "fibo tribo tetra penta hexa hepta octo nona deca";
+ foreach (n, name; zip(iota(2, 11), prefixes.split())) {
+ auto fib = Fiblike!int(1 ~ iota(n-1).map!q{2 ^^ a}().array());
+ writefln("n=%2d, %5snacci -> %s", n, name, fib.takeApply(15));
+ }
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/Go/fibonacci-n-step-number-sequences.go b/Task/Fibonacci-n-step-number-sequences/Go/fibonacci-n-step-number-sequences.go
new file mode 100644
index 0000000000..55f6d56d46
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Go/fibonacci-n-step-number-sequences.go
@@ -0,0 +1,38 @@
+package main
+
+import "fmt"
+
+func g(i []int, c chan int) {
+ var sum int
+ b := append([]int{}, i...)
+ for _, t := range b {
+ c <- t
+ sum += t
+ }
+ for {
+ for j, t := range b {
+ c <- sum
+ b[j], sum = sum, sum+sum-t
+ }
+ }
+}
+
+func main() {
+ for _, s := range []struct {
+ seq string
+ i []int
+ } {
+ {"Fibonacci", []int{1, 1}},
+ {"Tribonacci", []int{1, 1, 2}},
+ {"Tetranacci", []int{1, 1, 2, 4}},
+ {"Lucas", []int{2, 1}},
+ } {
+ fmt.Printf("%10s:", s.seq)
+ c := make(chan int)
+ go g(s.i, c)
+ for j := 0; j < 10; j++ {
+ fmt.Print(" ", <-c)
+ }
+ fmt.Println()
+ }
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/Haskell/fibonacci-n-step-number-sequences.hs b/Task/Fibonacci-n-step-number-sequences/Haskell/fibonacci-n-step-number-sequences.hs
new file mode 100644
index 0000000000..428e5cb513
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Haskell/fibonacci-n-step-number-sequences.hs
@@ -0,0 +1,18 @@
+import Data.List (tails)
+import Control.Monad (zipWithM_)
+
+fiblike :: [Integer] -> [Integer]
+fiblike st = xs where
+ xs = st ++ map (sum . take n) (tails xs)
+ n = length st
+
+nstep :: Int -> [Integer]
+nstep n = fiblike $ take n $ 1 : iterate (2*) 1
+
+main :: IO ()
+main = do
+ print $ take 10 $ fiblike [1,1]
+ print $ take 10 $ fiblike [2,1]
+ zipWithM_ (\n name -> do putStr (name ++ "nacci -> ")
+ print $ take 15 $ nstep n)
+ [2..] (words "fibo tribo tetra penta hexa hepta octo nona deca")
diff --git a/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-1.j b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-1.j
new file mode 100644
index 0000000000..afce6484a8
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-1.j
@@ -0,0 +1 @@
+ nacci =: (] , +/@{.)^:(-@#@]`(-#)`])
diff --git a/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-2.j b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-2.j
new file mode 100644
index 0000000000..28ee446e09
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-2.j
@@ -0,0 +1,2 @@
+ 10 nacci 2 1 NB. Lucas series, first 10 terms
+2 1 3 4 7 11 18 29 47 76
diff --git a/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-3.j b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-3.j
new file mode 100644
index 0000000000..5478f6df37
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/J/fibonacci-n-step-number-sequences-3.j
@@ -0,0 +1,23 @@
+ TESTS =: }."1 fixdsv noun define [ require 'tables/dsv' NB. Tests from task description
+ 2 fibonacci 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
+ 3 tribonacci 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...
+ 4 tetranacci 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...
+ 5 pentanacci 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...
+ 6 hexanacci 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...
+ 7 heptanacci 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...
+ 8 octonacci 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...
+ 9 nonanacci 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...
+ 10 decanacci 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ...
+)
+ testNacci =: ] -: #@] nacci {. NB. Given an order & test sequence, compare nacci to sequence
+ OT =: __ ".&.> (<<<1) { |: TESTS NB. 'nacci order and test sequence
+ (> 1 {"1 TESTS) ,. ' ' ,. (u: 16b274c 16b2713) {~ (testNacci }:)&>/ OT NB. ✓ or ❌ for success or failure
+fibonacci ✓
+tribonacci ✓
+tetranacci ✓
+pentanacci ✓
+hexanacci ✓
+heptanacci ✓
+octonacci ✓
+nonanacci ✓
+decanacci ✓
diff --git a/Task/Fibonacci-n-step-number-sequences/Java/fibonacci-n-step-number-sequences.java b/Task/Fibonacci-n-step-number-sequences/Java/fibonacci-n-step-number-sequences.java
new file mode 100644
index 0000000000..c59f00d625
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Java/fibonacci-n-step-number-sequences.java
@@ -0,0 +1,45 @@
+class Fibonacci
+{
+ public static int[] lucas(int n, int numRequested)
+ {
+ if (n < 2)
+ throw new IllegalArgumentException("Fibonacci value must be at least 2");
+ return fibonacci((n == 2) ? new int[] { 2, 1 } : lucas(n - 1, n), numRequested);
+ }
+
+ public static int[] fibonacci(int n, int numRequested)
+ {
+ if (n < 2)
+ throw new IllegalArgumentException("Fibonacci value must be at least 2");
+ return fibonacci((n == 2) ? new int[] { 1, 1 } : fibonacci(n - 1, n), numRequested);
+ }
+
+ public static int[] fibonacci(int[] startingValues, int numRequested)
+ {
+ int[] output = new int[numRequested];
+ int n = startingValues.length;
+ System.arraycopy(startingValues, 0, output, 0, n);
+ for (int i = n; i < numRequested; i++)
+ for (int j = 1; j <= n; j++)
+ output[i] += output[i - j];
+ return output;
+ }
+
+ public static void main(String[] args)
+ {
+ for (int n = 2; n <= 10; n++)
+ {
+ System.out.print("nacci(" + n + "):");
+ for (int value : fibonacci(n, 15))
+ System.out.print(" " + value);
+ System.out.println();
+ }
+ for (int n = 2; n <= 10; n++)
+ {
+ System.out.print("lucas(" + n + "):");
+ for (int value : lucas(n, 15))
+ System.out.print(" " + value);
+ System.out.println();
+ }
+ }
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/JavaScript/fibonacci-n-step-number-sequences.js b/Task/Fibonacci-n-step-number-sequences/JavaScript/fibonacci-n-step-number-sequences.js
new file mode 100644
index 0000000000..47a15bb1b2
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/JavaScript/fibonacci-n-step-number-sequences.js
@@ -0,0 +1,26 @@
+function fib(arity, len) {
+ return nacci(nacci([1,1], arity, arity), arity, len);
+}
+
+function lucas(arity, len) {
+ return nacci(nacci([2,1], arity, arity), arity, len);
+}
+
+function nacci(a, arity, len) {
+ while (a.length < len) {
+ var sum = 0;
+ for (var i = Math.max(0, a.length - arity); i < a.length; i++)
+ sum += a[i];
+ a.push(sum);
+ }
+ return a;
+}
+
+function main() {
+ for (var arity = 2; arity <= 10; arity++)
+ console.log("fib(" + arity + "): " + fib(arity, 15));
+ for (var arity = 2; arity <= 10; arity++)
+ console.log("lucas(" + arity + "): " + lucas(arity, 15));
+}
+
+main();
diff --git a/Task/Fibonacci-n-step-number-sequences/Mathematica/fibonacci-n-step-number-sequences.mathematica b/Task/Fibonacci-n-step-number-sequences/Mathematica/fibonacci-n-step-number-sequences.mathematica
new file mode 100644
index 0000000000..0caf822fb2
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Mathematica/fibonacci-n-step-number-sequences.mathematica
@@ -0,0 +1,6 @@
+f2=Function[{l,k},
+ Module[{n=Length@l,m},
+ m=SparseArray[{{i_,j_}/;i==1||i==j+1->1},{n,n}];
+ NestList[m.#&,l,k]]];
+Table[Last/@f2[{1,1}~Join~Table[0,{n-2}],15+n][[-18;;]],{n,2,10}]//TableForm
+Table[Last/@f2[{1,2}~Join~Table[0,{n-2}],15+n][[-18;;]],{n,2,10}]//TableForm
diff --git a/Task/Fibonacci-n-step-number-sequences/PHP/fibonacci-n-step-number-sequences.php b/Task/Fibonacci-n-step-number-sequences/PHP/fibonacci-n-step-number-sequences.php
new file mode 100644
index 0000000000..1edb5fd19b
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/PHP/fibonacci-n-step-number-sequences.php
@@ -0,0 +1,80 @@
+
+ */
+
+/**
+ * @param int $x
+ * @param array $series
+ * @param int $n
+ * @return array
+ */
+function fib_n_step($x, &$series = array(1, 1), $n = 15)
+{
+ $count = count($series);
+
+ if($count > $x && $count == $n) // exit point
+ {
+ return $series;
+ }
+
+ if($count < $n)
+ {
+ if($count >= $x) // 4 or less
+ {
+ fib($series, $x, $count);
+ return fib_n_step($x, $series, $n);
+ }
+ else // 5 or more
+ {
+ while(count($series) < $x )
+ {
+ $count = count($series);
+ fib($series, $count, $count);
+ }
+ return fib_n_step($x, $series, $n);
+ }
+ }
+
+ return $series;
+}
+
+/**
+ * @param array $series
+ * @param int $n
+ * @param int $i
+ */
+function fib(&$series, $n, $i)
+{
+ $end = 0;
+ for($j = $n; $j > 0; $j--)
+ {
+ $end += $series[$i-$j];
+ }
+ $series[$i] = $end;
+}
+
+
+/*=================== OUTPUT ============================*/
+
+header('Content-Type: text/plain');
+$steps = array(
+ 'LUCAS' => array(2, array(2, 1)),
+ 'FIBONACCI' => array(2, array(1, 1)),
+ 'TRIBONACCI' => array(3, array(1, 1, 2)),
+ 'TETRANACCI' => array(4, array(1, 1, 2, 4)),
+ 'PENTANACCI' => array(5, array(1, 1, 2, 4)),
+ 'HEXANACCI' => array(6, array(1, 1, 2, 4)),
+ 'HEPTANACCI' => array(7, array(1, 1, 2, 4)),
+ 'OCTONACCI' => array(8, array(1, 1, 2, 4)),
+ 'NONANACCI' => array(9, array(1, 1, 2, 4)),
+ 'DECANACCI' => array(10, array(1, 1, 2, 4)),
+);
+
+foreach($steps as $name=>$pair)
+{
+ $ser = fib_n_step($pair[0],$pair[1]);
+ $n = count($ser)-1;
+
+ echo $name." => ".implode(',', $ser) . "\n";
+}
diff --git a/Task/Fibonacci-n-step-number-sequences/Perl/fibonacci-n-step-number-sequences.pl b/Task/Fibonacci-n-step-number-sequences/Perl/fibonacci-n-step-number-sequences.pl
new file mode 100644
index 0000000000..aa098e4b9f
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Perl/fibonacci-n-step-number-sequences.pl
@@ -0,0 +1,24 @@
+use 5.010;
+
+use List::Util qw/max sum/;
+
+sub fib {
+ my $n = shift;
+ my $xs = shift // [1];
+ my @xs = @{$xs};
+
+ while (my $len = scalar @xs) {
+ last if $len >= 20;
+ push(
+ @xs,
+ sum(@xs[max($len - $n, 0)..$len-1])
+ );
+ }
+
+ return @xs;
+}
+
+for (2..10) {
+ say join(' ', fib($_));
+}
+say join(' ', fib(2, [2,1]));
diff --git a/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-1.l b/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-1.l
new file mode 100644
index 0000000000..214d9e5e18
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-1.l
@@ -0,0 +1,6 @@
+(de nacci (Init Cnt)
+ (let N (length Init)
+ (make
+ (made Init)
+ (do (- Cnt N)
+ (link (apply + (tail N (made)))) ) ) ) )
diff --git a/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-2.l b/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-2.l
new file mode 100644
index 0000000000..d704b1f20a
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/PicoLisp/fibonacci-n-step-number-sequences-2.l
@@ -0,0 +1,19 @@
+# Fibonacci
+: (nacci (1 1) 10)
+-> (1 1 2 3 5 8 13 21 34 55)
+
+# Tribonacci
+: (nacci (1 1 2) 10)
+-> (1 1 2 4 7 13 24 44 81 149)
+
+# Tetranacci
+: (nacci (1 1 2 4) 10)
+-> (1 1 2 4 8 15 29 56 108 208)
+
+# Lucas
+: (nacci (2 1) 10)
+-> (2 1 3 4 7 11 18 29 47 76)
+
+# Decanacci
+: (nacci (1 1 2 4 8 16 32 64 128 256) 15)
+-> (1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172)
diff --git a/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-1.py b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-1.py
new file mode 100644
index 0000000000..baef86169c
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-1.py
@@ -0,0 +1,33 @@
+>>> def fiblike(start):
+ addnum = len(start)
+ memo = start[:]
+ def fibber(n):
+ try:
+ return memo[n]
+ except IndexError:
+ ans = sum(fibber(i) for i in range(n-addnum, n))
+ memo.append(ans)
+ return ans
+ return fibber
+
+>>> fibo = fiblike([1,1])
+>>> [fibo(i) for i in range(10)]
+[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
+>>> lucas = fiblike([2,1])
+>>> [lucas(i) for i in range(10)]
+[2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
+>>> for n, name in zip(range(2,11), 'fibo tribo tetra penta hexa hepta octo nona deca'.split()) :
+ fibber = fiblike([1] + [2**i for i in range(n-1)])
+ print('n=%2i, %5snacci -> %s ...' % (n, name, ' '.join(str(fibber(i)) for i in range(15))))
+
+
+n= 2, fibonacci -> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
+n= 3, tribonacci -> 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...
+n= 4, tetranacci -> 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...
+n= 5, pentanacci -> 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...
+n= 6, hexanacci -> 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...
+n= 7, heptanacci -> 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...
+n= 8, octonacci -> 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...
+n= 9, nonanacci -> 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...
+n=10, decanacci -> 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ...
+>>>
diff --git a/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-2.py b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-2.py
new file mode 100644
index 0000000000..003de61acd
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-2.py
@@ -0,0 +1,34 @@
+>>> class Fiblike():
+ def __init__(self, start):
+ self.addnum = len(start)
+ self.memo = start[:]
+ def __call__(self, n):
+ try:
+ return self.memo[n]
+ except IndexError:
+ ans = sum(self(i) for i in range(n-self.addnum, n))
+ self.memo.append(ans)
+ return ans
+
+
+>>> fibo = Fiblike([1,1])
+>>> [fibo(i) for i in range(10)]
+[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
+>>> lucas = Fiblike([2,1])
+>>> [lucas(i) for i in range(10)]
+[2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
+>>> for n, name in zip(range(2,11), 'fibo tribo tetra penta hexa hepta octo nona deca'.split()) :
+ fibber = Fiblike([1] + [2**i for i in range(n-1)])
+ print('n=%2i, %5snacci -> %s ...' % (n, name, ' '.join(str(fibber(i)) for i in range(15))))
+
+
+n= 2, fibonacci -> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
+n= 3, tribonacci -> 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ...
+n= 4, tetranacci -> 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ...
+n= 5, pentanacci -> 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ...
+n= 6, hexanacci -> 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ...
+n= 7, heptanacci -> 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ...
+n= 8, octonacci -> 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ...
+n= 9, nonanacci -> 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ...
+n=10, decanacci -> 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ...
+>>>
diff --git a/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-3.py b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-3.py
new file mode 100644
index 0000000000..fb273a2545
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Python/fibonacci-n-step-number-sequences-3.py
@@ -0,0 +1,19 @@
+from itertools import islice, cycle
+
+def fiblike(tail):
+ for x in tail:
+ yield x
+ for i in cycle(xrange(len(tail))):
+ tail[i] = x = sum(tail)
+ yield x
+
+fibo = fiblike([1, 1])
+print list(islice(fibo, 10))
+lucas = fiblike([2, 1])
+print list(islice(lucas, 10))
+
+suffixes = "fibo tribo tetra penta hexa hepta octo nona deca"
+for n, name in zip(xrange(2, 11), suffixes.split()):
+ fib = fiblike([1] + [2 ** i for i in xrange(n - 1)])
+ items = list(islice(fib, 15))
+ print "n=%2i, %5snacci -> %s ..." % (n, name, items)
diff --git a/Task/Fibonacci-n-step-number-sequences/REXX/fibonacci-n-step-number-sequences.rexx b/Task/Fibonacci-n-step-number-sequences/REXX/fibonacci-n-step-number-sequences.rexx
new file mode 100644
index 0000000000..aca60056be
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/REXX/fibonacci-n-step-number-sequences.rexx
@@ -0,0 +1,40 @@
+/*REXX program calculates and displays N-step Fibonacci sequences. */
+parse arg FibName values /*allow user to specify which Fib*/
+
+if FibName\='' then do /*if specified, show that Fib. */
+ call nStepFib FibName, values
+ exit /*stick a fork in it, we're done.*/
+ end
+ /*nothing given, so show a bunch.*/
+call nStepFib 'Lucas' , 2 1
+call nStepFib 'fibonacci' , 1 1
+call nStepFib 'tribonacci' , 1 1 2
+call nStepFib 'tetranacci' , 1 1 2 4
+call nStepFib 'pentanacci' , 1 1 2 4 8
+call nStepFib 'hexanacci' , 1 1 2 4 8 16
+call nStepFib 'heptanacci' , 1 1 2 4 8 16 32
+call nStepFib 'octonacci' , 1 1 2 4 8 16 32 64
+call nStepFib 'nonanacci' , 1 1 2 4 8 16 32 64 128
+call nStepFib 'decanacci' , 1 1 2 4 8 16 32 64 128 256
+call nStepFib 'undecanacci' , 1 1 2 4 8 16 32 64 128 256 512
+call nStepFib 'dodecanacci' , 1 1 2 4 8 16 32 64 128 256 512 1024
+call nStepFib '13th-order' , 1 1 2 4 8 16 32 64 128 256 512 1024 2048
+exit /*stick a fork in it, we're done.*/
+
+/*──────────────────────────────────NSTEPFIB subroutine─────────────────*/
+nStepFib: procedure; parse arg Fname,vals,m; if m=='' then m=30; L=
+N=words(vals)
+ do pop=1 for N /*use N initial vals*/
+ @.pop=word(vals,pop) /*populate initial #s.*/
+ end /*pop*/
+ do j=1 for m /*calculate M Fibonacci numbers*/
+ if j>N then do; @.j=0 /*inialize the sum. */
+ do k=j-N for N /*sum the last N #.s*/
+ @.j=@.j+@.k /*add the [N-j]th #.*/
+ end /*k*/
+ end
+ L=L @.j /*append this Fib num to the list*/
+ end /*j*/
+
+say right(Fname,11)'[sum'right(N,3) "terms]:" strip(L) '...' /*show #s*/
+return
diff --git a/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-1.rb b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-1.rb
new file mode 100644
index 0000000000..3682cbf212
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-1.rb
@@ -0,0 +1,12 @@
+def anynacci(start_sequence, count)
+ n = start_sequence.length # Get the n-step for the type of fibonacci sequence
+ result = start_sequence.dup # Create a new result array with the values copied from the array that was passed by reference
+
+ (n+1..count).each do # Loop for the remaining results up to count
+ tail = result.last(n) # Get the last n elements from result
+ next_num = tail.reduce(:+) # In Rails: tail.sum
+ result << next_num # Array append
+ end
+
+ result # Return result
+end
diff --git a/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-2.rb b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-2.rb
new file mode 100644
index 0000000000..b9cee748e2
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-2.rb
@@ -0,0 +1,13 @@
+def print_nacci
+ naccis = { :fibo => [1,1],
+ :lucas => [2,1],
+ :tribo => [1,1,2],
+ :tetra => [1,1,2,4] }
+
+ naccis.each do |name, start_sequence|
+ nacci_result = anynacci(start_sequence, 10)
+ puts "#{name}nacci: #{nacci_result}"
+ end
+
+ nil
+end
diff --git a/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-3.rb b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-3.rb
new file mode 100644
index 0000000000..e7d96596a3
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Ruby/fibonacci-n-step-number-sequences-3.rb
@@ -0,0 +1,4 @@
+fibonacci: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
+lucasnacci: [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]
+tribonacci: [1, 1, 2, 4, 7, 13, 24, 44, 81, 149]
+tetranacci: [1, 1, 2, 4, 8, 15, 29, 56, 108, 208]
diff --git a/Task/Fibonacci-n-step-number-sequences/Tcl/fibonacci-n-step-number-sequences.tcl b/Task/Fibonacci-n-step-number-sequences/Tcl/fibonacci-n-step-number-sequences.tcl
new file mode 100644
index 0000000000..8feef897eb
--- /dev/null
+++ b/Task/Fibonacci-n-step-number-sequences/Tcl/fibonacci-n-step-number-sequences.tcl
@@ -0,0 +1,30 @@
+package require Tcl 8.6
+
+proc fibber {args} {
+ coroutine fib[incr ::fibs]=[join $args ","] apply {fn {
+ set n [info coroutine]
+ foreach f $fn {
+ if {![yield $n]} return
+ set n $f
+ }
+ while {[yield $n]} {
+ set fn [linsert [lreplace $fn 0 0] end [set n [+ {*}$fn]]]
+ }
+ } ::tcl::mathop} $args
+}
+
+proc print10 cr {
+ for {set i 1} {$i <= 10} {incr i} {
+ lappend out [$cr true]
+ }
+ puts \[[join [lappend out ...] ", "]\]
+ $cr false
+}
+puts "FIBONACCI"
+print10 [fibber 1 1]
+puts "TRIBONACCI"
+print10 [fibber 1 1 2]
+puts "TETRANACCI"
+print10 [fibber 1 1 2 4]
+puts "LUCAS"
+print10 [fibber 2 1]
diff --git a/Task/Fibonacci-sequence/0815/fibonacci-sequence.0815 b/Task/Fibonacci-sequence/0815/fibonacci-sequence.0815
new file mode 100644
index 0000000000..f8e9df921f
--- /dev/null
+++ b/Task/Fibonacci-sequence/0815/fibonacci-sequence.0815
@@ -0,0 +1,2 @@
+%<:0D:>~$<:01:~%>=<:a94fad42221f2702:>~>
+}:_s:{x{={~$x+%{=>~>x~-x<:0D:~>~>~^:_s:?
diff --git a/Task/Fibonacci-sequence/0DESCRIPTION b/Task/Fibonacci-sequence/0DESCRIPTION
new file mode 100644
index 0000000000..58010a6249
--- /dev/null
+++ b/Task/Fibonacci-sequence/0DESCRIPTION
@@ -0,0 +1,23 @@
+The '''Fibonacci sequence''' is a sequence Fn of natural numbers defined recursively:
+ F0 = 0
+ F1 = 1
+ Fn = Fn-1 + Fn-2, if n>1
+
+Write a function to generate the nth Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow and are mostly used as an exercise in recursion).
+
+The sequence is sometimes extended into negative numbers by using a straightforward inverse of the positive definition:
+
+ Fn = Fn+2 - Fn+1, if n<0
+
+Support for negative n in the solution is optional.
+
+;Cf.:
+* [[Fibonacci n-step number sequences]]
+
+;References:
+* [[wp:Fibonacci number|Wikipedia, Fibonacci number]]
+* [[wp:Lucas number|Wikipedia, Lucas number]]
+* [http://mathworld.wolfram.com/FibonacciNumber.html MathWorld, Fibonacci Number]
+* [http://www.math-cs.ucmo.edu/~curtisc/articles/howardcooper/genfib4.pdf Some identities for r-Fibonacci numbers]
+*[[oeis:A000045|OEIS Fibonacci numbers]]
+*[[oeis:A000032|OEIS Lucas numbers]]
diff --git a/Task/Fibonacci-sequence/1META.yaml b/Task/Fibonacci-sequence/1META.yaml
new file mode 100644
index 0000000000..4dd49fa137
--- /dev/null
+++ b/Task/Fibonacci-sequence/1META.yaml
@@ -0,0 +1,6 @@
+---
+category:
+- Recursion
+- Memoization
+- Classic CS problems and programs
+note: Arithmetic operations
diff --git a/Task/Fibonacci-sequence/ACL2/fibonacci-sequence.acl2 b/Task/Fibonacci-sequence/ACL2/fibonacci-sequence.acl2
new file mode 100644
index 0000000000..02f47fc006
--- /dev/null
+++ b/Task/Fibonacci-sequence/ACL2/fibonacci-sequence.acl2
@@ -0,0 +1,17 @@
+(defun fast-fib-r (n a b)
+ (if (or (zp n) (zp (1- n)))
+ b
+ (fast-fib-r (1- n) b (+ a b))))
+
+(defun fast-fib (n)
+ (fast-fib-r n 1 1))
+
+(defun first-fibs-r (n i)
+ (declare (xargs :measure (nfix (- n i))))
+ (if (zp (- n i))
+ nil
+ (cons (fast-fib i)
+ (first-fibs-r n (1+ i)))))
+
+(defun first-fibs (n)
+ (first-fibs-r n 0))
diff --git a/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-1.alg b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-1.alg
new file mode 100644
index 0000000000..e13d686dc7
--- /dev/null
+++ b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-1.alg
@@ -0,0 +1,13 @@
+PROC analytic fibonacci = (LONG INT n)LONG INT:(
+ LONG REAL sqrt 5 = long sqrt(5);
+ LONG REAL p = (1 + sqrt 5) / 2;
+ LONG REAL q = 1/p;
+ ROUND( (p**n + q**n) / sqrt 5 )
+);
+
+FOR i FROM 1 TO 30 WHILE
+ print(whole(analytic fibonacci(i),0));
+# WHILE # i /= 30 DO
+ print(", ")
+OD;
+print(new line)
diff --git a/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-2.alg b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-2.alg
new file mode 100644
index 0000000000..f4c1dbfcf8
--- /dev/null
+++ b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-2.alg
@@ -0,0 +1,17 @@
+PROC iterative fibonacci = (INT n)INT:
+ CASE n+1 IN
+ 0, 1, 1, 2, 3, 5
+ OUT
+ INT even:=3, odd:=5;
+ FOR i FROM odd+1 TO n DO
+ (ODD i|odd|even) := odd + even
+ OD;
+ (ODD n|odd|even)
+ ESAC;
+
+FOR i FROM 0 TO 30 WHILE
+ print(whole(iterative fibonacci(i),0));
+# WHILE # i /= 30 DO
+ print(", ")
+OD;
+print(new line)
diff --git a/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-3.alg b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-3.alg
new file mode 100644
index 0000000000..35625a50de
--- /dev/null
+++ b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-3.alg
@@ -0,0 +1,2 @@
+PROC recursive fibonacci = (INT n)INT:
+ ( n < 2 | n | fib(n-1) + fib(n-2));
diff --git a/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-4.alg b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-4.alg
new file mode 100644
index 0000000000..12289120ed
--- /dev/null
+++ b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-4.alg
@@ -0,0 +1,18 @@
+MODE YIELDINT = PROC(INT)VOID;
+
+PROC gen fibonacci = (INT n, YIELDINT yield)VOID: (
+ INT even:=0, odd:=1;
+ yield(even);
+ yield(odd);
+ FOR i FROM odd+1 TO n DO
+ yield( (ODD i|odd|even) := odd + even )
+ OD
+);
+
+main:(
+ # FOR INT n IN # gen fibonacci(30, # ) DO ( #
+ ## (INT n)VOID:(
+ print((" ",whole(n,0)))
+ # OD # ));
+ print(new line)
+)
diff --git a/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-5.alg b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-5.alg
new file mode 100644
index 0000000000..1afd4b97e5
--- /dev/null
+++ b/Task/Fibonacci-sequence/ALGOL-68/fibonacci-sequence-5.alg
@@ -0,0 +1,30 @@
+[]INT const fibonacci = []INT( -1836311903, 1134903170,
+ -701408733, 433494437, -267914296, 165580141, -102334155,
+ 63245986, -39088169, 24157817, -14930352, 9227465, -5702887,
+ 3524578, -2178309, 1346269, -832040, 514229, -317811, 196418,
+ -121393, 75025, -46368, 28657, -17711, 10946, -6765, 4181,
+ -2584, 1597, -987, 610, -377, 233, -144, 89, -55, 34, -21, 13,
+ -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
+ 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711,
+ 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040,
+ 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817,
+ 39088169, 63245986, 102334155, 165580141, 267914296, 433494437,
+ 701408733, 1134903170, 1836311903
+)[@-46];
+
+PROC VOID value error := stop;
+
+PROC lookup fibonacci = (INT i)INT: (
+ IF LWB const fibonacci <= i AND i<= UPB const fibonacci THEN
+ const fibonacci[i]
+ ELSE
+ value error; SKIP
+ FI
+);
+
+FOR i FROM 0 TO 30 WHILE
+ print(whole(lookup fibonacci(i),0));
+# WHILE # i /= 30 DO
+ print(", ")
+OD;
+print(new line)
diff --git a/Task/Fibonacci-sequence/AWK/fibonacci-sequence.awk b/Task/Fibonacci-sequence/AWK/fibonacci-sequence.awk
new file mode 100644
index 0000000000..3ce0872bd9
--- /dev/null
+++ b/Task/Fibonacci-sequence/AWK/fibonacci-sequence.awk
@@ -0,0 +1,3 @@
+$ awk 'func fib(n){return(n<2?n:fib(n-1)+fib(n-2))}{print "fib("$1")="fib($1)}'
+10
+fib(10)=55
diff --git a/Task/Fibonacci-sequence/ActionScript/fibonacci-sequence.as b/Task/Fibonacci-sequence/ActionScript/fibonacci-sequence.as
new file mode 100644
index 0000000000..90077f8c45
--- /dev/null
+++ b/Task/Fibonacci-sequence/ActionScript/fibonacci-sequence.as
@@ -0,0 +1,7 @@
+public function fib(n:uint):uint
+{
+ if (n < 2)
+ return n;
+
+ return fib(n - 1) + fib(n - 2);
+}
diff --git a/Task/Fibonacci-sequence/Ada/fibonacci-sequence-1.ada b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-1.ada
new file mode 100644
index 0000000000..7e4e9f8563
--- /dev/null
+++ b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-1.ada
@@ -0,0 +1,19 @@
+with Ada.Text_IO, Ada.Command_Line;
+
+procedure Fib is
+
+ X: Positive := Positive'Value(Ada.Command_Line.Argument(1));
+
+ function Fib(P: Positive) return Positive is
+ begin
+ if P <= 2 then
+ return 1;
+ else
+ return Fib(P-1) + Fib(P-2);
+ end if;
+ end Fib;
+
+begin
+ Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
+ Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
+end Fib;
diff --git a/Task/Fibonacci-sequence/Ada/fibonacci-sequence-2.ada b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-2.ada
new file mode 100644
index 0000000000..63f969409b
--- /dev/null
+++ b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-2.ada
@@ -0,0 +1,20 @@
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Test_Fibonacci is
+ function Fibonacci (N : Natural) return Natural is
+ This : Natural := 0;
+ That : Natural := 1;
+ Sum : Natural;
+ begin
+ for I in 1..N loop
+ Sum := This + That;
+ That := This;
+ This := Sum;
+ end loop;
+ return This;
+ end Fibonacci;
+begin
+ for N in 0..10 loop
+ Put_Line (Positive'Image (Fibonacci (N)));
+ end loop;
+end Test_Fibonacci;
diff --git a/Task/Fibonacci-sequence/Ada/fibonacci-sequence-3.ada b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-3.ada
new file mode 100644
index 0000000000..1bab08c378
--- /dev/null
+++ b/Task/Fibonacci-sequence/Ada/fibonacci-sequence-3.ada
@@ -0,0 +1,33 @@
+with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;
+
+procedure Fibonacci is
+
+ X: Positive := Positive'Value(Ada.Command_Line.Argument(1));
+
+ Bit_Length: Positive := 1 + (696 * X) / 1000;
+ -- that number of bits is sufficient to store the full result.
+
+ package LN is new Crypto.Types.Big_Numbers
+ (Bit_Length + (32 - Bit_Length mod 32));
+ -- the actual number of bits has to be a multiple of 32
+ use LN;
+
+ function Fib(P: Positive) return Big_Unsigned is
+ Previous: Big_Unsigned := Big_Unsigned_Zero;
+ Result: Big_Unsigned := Big_Unsigned_One;
+ Tmp: Big_Unsigned;
+ begin
+ -- Result = 1 = Fibonacci(1)
+ for I in 1 .. P-1 loop
+ Tmp := Result;
+ Result := Previous + Result;
+ Previous := Tmp;
+ -- Result = Fibonacci(I+1))
+ end loop;
+ return Result;
+ end Fib;
+
+begin
+ Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
+ Ada.Text_IO.Put_Line(LN.Utils.To_String(Fib(X)));
+end Fibonacci;
diff --git a/Task/Fibonacci-sequence/Alore/fibonacci-sequence.alore b/Task/Fibonacci-sequence/Alore/fibonacci-sequence.alore
new file mode 100644
index 0000000000..1a6e509968
--- /dev/null
+++ b/Task/Fibonacci-sequence/Alore/fibonacci-sequence.alore
@@ -0,0 +1,6 @@
+def fib(n as Int) as Int
+ if n < 2
+ return 1
+ end
+ return fib(n-1) + fib(n-2)
+end
diff --git a/Task/Fibonacci-sequence/AppleScript/fibonacci-sequence.applescript b/Task/Fibonacci-sequence/AppleScript/fibonacci-sequence.applescript
new file mode 100644
index 0000000000..4aaa24a506
--- /dev/null
+++ b/Task/Fibonacci-sequence/AppleScript/fibonacci-sequence.applescript
@@ -0,0 +1,11 @@
+set fibs to {}
+set x to (text returned of (display dialog "What fibbonaci number do you want?" default answer "3"))
+set x to x as integer
+repeat with y from 1 to x
+ if (y = 1 or y = 2) then
+ copy 1 to the end of fibs
+ else
+ copy ((item (y - 1) of fibs) + (item (y - 2) of fibs)) to the end of fibs
+ end if
+end repeat
+return item x of fibs
diff --git a/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-1.ahk b/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-1.ahk
new file mode 100644
index 0000000000..8df8ac4c57
--- /dev/null
+++ b/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-1.ahk
@@ -0,0 +1,18 @@
+Loop, 5
+ MsgBox % fib(A_Index)
+Return
+
+fib(n)
+{
+ If (n < 2)
+ Return n
+ i := last := this := 1
+ While (i <= n)
+ {
+ new := last + this
+ last := this
+ this := new
+ i++
+ }
+ Return this
+}
diff --git a/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-2.ahk b/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-2.ahk
new file mode 100644
index 0000000000..4824e2c1e5
--- /dev/null
+++ b/Task/Fibonacci-sequence/AutoHotkey/fibonacci-sequence-2.ahk
@@ -0,0 +1,17 @@
+/*
+Important note: the recursive version would be very slow
+without a global or static array. The iterative version
+handles also negative arguments properly.
+*/
+
+FibR(n) { ; n-th Fibonacci number (n>=0, recursive with static array Fibo)
+ Static
+ Return n<2 ? n : Fibo%n% ? Fibo%n% : Fibo%n% := FibR(n-1)+FibR(n-2)
+}
+
+Fib(n) { ; n-th Fibonacci number (n < 0 OK, iterative)
+ a := 0, b := 1
+ Loop % abs(n)-1
+ c := b, b += a, a := c
+ Return n=0 ? 0 : n>0 || n&1 ? b : -b
+}
diff --git a/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-1.autoit b/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-1.autoit
new file mode 100644
index 0000000000..33e8dadbe5
--- /dev/null
+++ b/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-1.autoit
@@ -0,0 +1,27 @@
+#AutoIt Version: 3.2.10.0
+$n0 = 0
+$n1 = 1
+$n = 10
+MsgBox (0,"Iterative Fibonacci ", it_febo($n0,$n1,$n))
+
+Func it_febo($n_0,$n_1,$N)
+ $first = $n_0
+ $second = $n_1
+ $next = $first + $second
+ $febo = 0
+ For $i = 1 To $N-3
+ $first = $second
+ $second = $next
+ $next = $first + $second
+ Next
+ if $n==0 Then
+ $febo = 0
+ ElseIf $n==1 Then
+ $febo = $n_0
+ ElseIf $n==2 Then
+ $febo = $n_1
+ Else
+ $febo = $next
+ EndIf
+ Return $febo
+EndFunc
diff --git a/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-2.autoit b/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-2.autoit
new file mode 100644
index 0000000000..a8cdffb481
--- /dev/null
+++ b/Task/Fibonacci-sequence/AutoIt/fibonacci-sequence-2.autoit
@@ -0,0 +1,19 @@
+#AutoIt Version: 3.2.10.0
+$n0 = 0
+$n1 = 1
+$n = 10
+MsgBox (0,"Recursive Fibonacci ", rec_febo($n0,$n1,$n))
+Func rec_febo($r_0,$r_1,$R)
+ if $R<3 Then
+ if $R==2 Then
+ Return $r_1
+ ElseIf $R==1 Then
+ Return $r_0
+ ElseIf $R==0 Then
+ Return 0
+ EndIf
+ Return $R
+ Else
+ Return rec_febo($r_0,$r_1,$R-1) + rec_febo($r_0,$r_1,$R-2)
+ EndIf
+EndFunc
diff --git a/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-1.bas b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-1.bas
new file mode 100644
index 0000000000..8aaa8bfbb8
--- /dev/null
+++ b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-1.bas
@@ -0,0 +1,14 @@
+FUNCTION itFib (n)
+ n1 = 0
+ n2 = 1
+ FOR k = 1 TO ABS(n)
+ sum = n1 + n2
+ n1 = n2
+ n2 = sum
+ NEXT k
+ IF n < 0 THEN
+ itFib = n1 * ((-1) ^ ((-n) + 1))
+ ELSE
+ itFib = n1
+ END IF
+END FUNCTION
diff --git a/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-2.bas b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-2.bas
new file mode 100644
index 0000000000..21b1b5e89c
--- /dev/null
+++ b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-2.bas
@@ -0,0 +1,38 @@
+DECLARE FUNCTION fibonacci& (n AS INTEGER)
+
+REDIM SHARED fibNum(1) AS LONG
+
+fibNum(1) = 1
+
+'*****sample inputs*****
+PRINT fibonacci(0) 'no calculation needed
+PRINT fibonacci(13) 'figure F(2)..F(13)
+PRINT fibonacci(-42) 'figure F(14)..F(42)
+PRINT fibonacci(47) 'error: too big
+'*****sample inputs*****
+
+FUNCTION fibonacci& (n AS INTEGER)
+ DIM a AS INTEGER
+ a = ABS(n)
+ SELECT CASE a
+ CASE 0 TO 46
+ SHARED fibNum() AS LONG
+ DIM u AS INTEGER, L0 AS INTEGER
+ u = UBOUND(fibNum)
+ IF a > u THEN
+ REDIM PRESERVE fibNum(a) AS LONG
+ FOR L0 = u + 1 TO a
+ fibNum(L0) = fibNum(L0 - 1) + fibNum(L0 - 2)
+ NEXT
+ END IF
+ IF n < 0 THEN
+ fibonacci = fibNum(a) * ((-1) ^ (a + 1))
+ ELSE
+ fibonacci = fibNum(n)
+ END IF
+ CASE ELSE
+ 'limited to signed 32-bit int (LONG)
+ 'F(47)=&hB11924E1
+ ERROR 6 'overflow
+ END SELECT
+END FUNCTION
diff --git a/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-3.bas b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-3.bas
new file mode 100644
index 0000000000..3ab578dd8c
--- /dev/null
+++ b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-3.bas
@@ -0,0 +1,7 @@
+FUNCTION recFib (n)
+ IF (n < 2) THEN
+ recFib = n
+ ELSE
+ recFib = recFib(n - 1) + recFib(n - 2)
+ END IF
+END FUNCTION
diff --git a/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-4.bas b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-4.bas
new file mode 100644
index 0000000000..f721f68f05
--- /dev/null
+++ b/Task/Fibonacci-sequence/BASIC/fibonacci-sequence-4.bas
@@ -0,0 +1,21 @@
+DATA -1836311903,1134903170,-701408733,433494437,-267914296,165580141,-102334155
+DATA 63245986,-39088169,24157817,-14930352,9227465,-5702887,3524578,-2178309
+DATA 1346269,-832040,514229,-317811,196418,-121393,75025,-46368,28657,-17711
+DATA 10946,-6765,4181,-2584,1597,-987,610,-377,233,-144,89,-55,34,-21,13,-8,5,-3
+DATA 2,-1,1,0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765
+DATA 10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269
+DATA 2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986
+DATA 102334155,165580141,267914296,433494437,701408733,1134903170,1836311903
+
+DIM fibNum(-46 TO 46) AS LONG
+
+FOR n = -46 TO 46
+ READ fibNum(n)
+NEXT
+
+'*****sample inputs*****
+FOR n = -46 TO 46
+ PRINT fibNum(n),
+NEXT
+PRINT
+'*****sample inputs*****
diff --git a/Task/Fibonacci-sequence/BBC-BASIC/fibonacci-sequence.bbc b/Task/Fibonacci-sequence/BBC-BASIC/fibonacci-sequence.bbc
new file mode 100644
index 0000000000..c0dabaf9a8
--- /dev/null
+++ b/Task/Fibonacci-sequence/BBC-BASIC/fibonacci-sequence.bbc
@@ -0,0 +1,19 @@
+ PRINT FNfibonacci_r(1), FNfibonacci_i(1)
+ PRINT FNfibonacci_r(13), FNfibonacci_i(13)
+ PRINT FNfibonacci_r(26), FNfibonacci_i(26)
+ END
+
+ DEF FNfibonacci_r(N)
+ IF N < 2 THEN = N
+ = FNfibonacci_r(N-1) + FNfibonacci_r(N-2)
+
+ DEF FNfibonacci_i(N)
+ LOCAL F, I, P, T
+ IF N < 2 THEN = N
+ P = 1
+ FOR I = 1 TO N
+ T = F
+ F += P
+ P = T
+ NEXT
+ = F
diff --git a/Task/Fibonacci-sequence/Babel/fibonacci-sequence.pb b/Task/Fibonacci-sequence/Babel/fibonacci-sequence.pb
new file mode 100644
index 0000000000..7f87b4a452
--- /dev/null
+++ b/Task/Fibonacci-sequence/Babel/fibonacci-sequence.pb
@@ -0,0 +1,17 @@
+main:
+ { argv 0 th $d
+ fib
+ %d cr << }
+
+fib!:
+ { dup zero?
+ { dup one?
+ { cp <- 2 - fib -> 1 - fib + }
+ { zap 1 }
+ if }
+ { zap 1 }
+ if }
+
+zero?!: { 0 = }
+
+one?!: { 1 = }
diff --git a/Task/Fibonacci-sequence/Batch-File/fibonacci-sequence.bat b/Task/Fibonacci-sequence/Batch-File/fibonacci-sequence.bat
new file mode 100644
index 0000000000..c0e1325fdb
--- /dev/null
+++ b/Task/Fibonacci-sequence/Batch-File/fibonacci-sequence.bat
@@ -0,0 +1,21 @@
+::fibo.cmd
+@echo off
+if "%1" equ "" goto :eof
+call :fib %1
+echo %errorlevel%
+goto :eof
+
+:fib
+setlocal enabledelayedexpansion
+if %1 geq 2 goto :ge2
+exit /b %1
+
+:ge2
+set /a r1 = %1 - 1
+set /a r2 = %1 - 2
+call :fib !r1!
+set r1=%errorlevel%
+call :fib !r2!
+set r2=%errorlevel%
+set /a r0 = r1 + r2
+exit /b !r0!
diff --git a/Task/Fibonacci-sequence/Befunge/fibonacci-sequence.bf b/Task/Fibonacci-sequence/Befunge/fibonacci-sequence.bf
new file mode 100644
index 0000000000..b886df7358
--- /dev/null
+++ b/Task/Fibonacci-sequence/Befunge/fibonacci-sequence.bf
@@ -0,0 +1,2 @@
+00:.1:.>:"@"8**++\1+:67+`#@_v
+ ^ .:\/*8"@"\%*8"@":\ <
diff --git a/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-1.bracmat b/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-1.bracmat
new file mode 100644
index 0000000000..daf2c3caeb
--- /dev/null
+++ b/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-1.bracmat
@@ -0,0 +1 @@
+fib=.!arg:<2|fib$(!arg+-2)+fib$(!arg+-1)
diff --git a/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-2.bracmat b/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-2.bracmat
new file mode 100644
index 0000000000..a8a87ca1c7
--- /dev/null
+++ b/Task/Fibonacci-sequence/Bracmat/fibonacci-sequence-2.bracmat
@@ -0,0 +1,13 @@
+(fib=
+ last i this new
+. !arg:<2
+ | 0:?last:?i
+ & 1:?this
+ & whl
+ ' ( !i+1:>+<<[->[->+>+<<]>[-<+>]>[-<+>]<<<]
diff --git a/Task/Fibonacci-sequence/Brainf---/fibonacci-sequence-2.bf b/Task/Fibonacci-sequence/Brainf---/fibonacci-sequence-2.bf
new file mode 100644
index 0000000000..ab977a3e10
--- /dev/null
+++ b/Task/Fibonacci-sequence/Brainf---/fibonacci-sequence-2.bf
@@ -0,0 +1,37 @@
++++++ +++++ #0 set to n
+>> + Init #2 to 1
+<<
+[
+ - #Decrement counter in #0
+ >>. Notice: This doesn't print it in ascii
+ To look at results you can pipe into a file and look with a hex editor
+
+ Copying sequence to save #2 in #4 using #5 as restore space
+ >>[-] Move to #4 and clear
+ >[-] Clear #5
+ <<< #2
+ [ Move loop
+ - >> + > + <<< Subtract #2 and add #4 and #5
+ ]
+ >>>
+ [ Restore loop
+ - <<< + >>> Subtract from #5 and add to #2
+ ]
+
+ <<<< Back to #1
+ Non destructive add sequence using #3 as restore value
+ [ Loop to add
+ - > + > + << Subtract #1 and add to value #2 and restore space #3
+ ]
+ >>
+ [ Loop to restore #1 from #3
+ - << + >> Subtract from restore space #3 and add in #1
+ ]
+
+ << [-] Clear #1
+ >>>
+ [ Loop to move #4 to #1
+ - <<< + >>> Subtract from #4 and add to #1
+ ]
+ <<<< Back to #0
+]
diff --git a/Task/Fibonacci-sequence/Brat/fibonacci-sequence-1.brat b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-1.brat
new file mode 100644
index 0000000000..1a7ab97c9a
--- /dev/null
+++ b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-1.brat
@@ -0,0 +1,3 @@
+fibonacci = { x |
+ true? x < 2, x, { fibonacci(x - 1) + fibonacci(x - 2) }
+}
diff --git a/Task/Fibonacci-sequence/Brat/fibonacci-sequence-2.brat b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-2.brat
new file mode 100644
index 0000000000..e78ace44a5
--- /dev/null
+++ b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-2.brat
@@ -0,0 +1,9 @@
+fib_aux = { x, next, result |
+ true? x == 0,
+ result,
+ { fib_aux x - 1, next + result, next }
+}
+
+fibonacci = { x |
+ fib_aux x, 1, 0
+}
diff --git a/Task/Fibonacci-sequence/Brat/fibonacci-sequence-3.brat b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-3.brat
new file mode 100644
index 0000000000..bbc475a63c
--- /dev/null
+++ b/Task/Fibonacci-sequence/Brat/fibonacci-sequence-3.brat
@@ -0,0 +1,7 @@
+cache = hash.new
+
+fibonacci = { x |
+ true? cache.key?(x)
+ { cache[x] }
+ {true? x < 2, x, { cache[x] = fibonacci(x - 1) + fibonacci(x - 2) }}
+}
diff --git a/Task/Fibonacci-sequence/Burlesque/fibonacci-sequence.blq b/Task/Fibonacci-sequence/Burlesque/fibonacci-sequence.blq
new file mode 100644
index 0000000000..c6bbadce37
--- /dev/null
+++ b/Task/Fibonacci-sequence/Burlesque/fibonacci-sequence.blq
@@ -0,0 +1 @@
+{0 1}{^^++[+[-^^-]\/}30.*\[e!vv
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-1.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-1.cpp
new file mode 100644
index 0000000000..3c47a2244e
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-1.cpp
@@ -0,0 +1,16 @@
+#include
+
+int main()
+{
+ unsigned int a = 1, b = 1;
+ unsigned int target = 48;
+ for(unsigned int n = 3; n <= target; ++n)
+ {
+ unsigned int fib = a + b;
+ std::cout << "F("<< n << ") = " << fib << std::endl;
+ a = b;
+ b = fib;
+ }
+
+ return 0;
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-2.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-2.cpp
new file mode 100644
index 0000000000..dbcf09e1cc
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-2.cpp
@@ -0,0 +1,21 @@
+#include
+#include
+
+int main()
+{
+ mpz_class a = mpz_class(1), b = mpz_class(1);
+ mpz_class target = mpz_class(100);
+ for(mpz_class n = mpz_class(3); n <= target; ++n)
+ {
+ mpz_class fib = b + a;
+ if ( fib < b )
+ {
+ std::cout << "Overflow at " << n << std::endl;
+ break;
+ }
+ std::cout << "F("<< n << ") = " << fib << std::endl;
+ a = b;
+ b = fib;
+ }
+ return 0;
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-3.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-3.cpp
new file mode 100644
index 0000000000..2cb0cdba5e
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-3.cpp
@@ -0,0 +1,13 @@
+#include
+#include
+#include
+#include
+
+unsigned int fibonacci(unsigned int n) {
+ if (n == 0) return 0;
+ std::vector v(n+1);
+ v[1] = 1;
+ transform(v.begin(), v.end()-2, v.begin()+1, v.begin()+2, std::plus());
+ // "v" now contains the Fibonacci sequence from 0 up
+ return v[n];
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-4.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-4.cpp
new file mode 100644
index 0000000000..011e954219
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-4.cpp
@@ -0,0 +1,12 @@
+#include
+#include
+#include
+#include
+
+unsigned int fibonacci(unsigned int n) {
+ if (n == 0) return 0;
+ std::vector v(n, 1);
+ adjacent_difference(v.begin(), v.end()-1, v.begin()+1, std::plus());
+ // "array" now contains the Fibonacci sequence from 1 up
+ return v[n-1];
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-5.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-5.cpp
new file mode 100644
index 0000000000..f1a47fc3ac
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-5.cpp
@@ -0,0 +1,24 @@
+#include
+
+template struct fibo
+{
+ enum {value=fibo::value+fibo::value};
+};
+
+template <> struct fibo<0>
+{
+ enum {value=0};
+};
+
+template <> struct fibo<1>
+{
+ enum {value=1};
+};
+
+
+int main(int argc, char const *argv[])
+{
+ std::cout<::value<::value<
+
+inline void fibmul(int* f, int* g)
+{
+ int tmp = f[0]*g[0] + f[1]*g[1];
+ f[1] = f[0]*g[1] + f[1]*(g[0] + g[1]);
+ f[0] = tmp;
+}
+
+int fibonacci(int n)
+{
+ int f[] = { 1, 0 };
+ int g[] = { 0, 1 };
+ while (n > 0)
+ {
+ if (n & 1) // n odd
+ {
+ fibmul(f, g);
+ --n;
+ }
+ else
+ {
+ fibmul(g, g);
+ n >>= 1;
+ }
+ }
+ return f[1];
+}
+
+int main()
+{
+ for (int i = 0; i < 20; ++i)
+ std::cout << fibonacci(i) << " ";
+ std::cout << std::endl;
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-7.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-7.cpp
new file mode 100644
index 0000000000..09b53a7e92
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-7.cpp
@@ -0,0 +1,15 @@
+// Use Zeckendorf numbers to display Fibonacci sequence.
+// Nigel Galloway October 23rd., 2012
+int main(void) {
+ char NG[22] = {'1',0};
+ int x = -1;
+ N G;
+ for (int fibs = 1; fibs <= 20; fibs++) {
+ for (;G <= N(NG); ++G) x++;
+ NG[fibs] = '0';
+ NG[fibs+1] = 0;
+ std::cout << x << " ";
+ }
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/Task/Fibonacci-sequence/C++/fibonacci-sequence-8.cpp b/Task/Fibonacci-sequence/C++/fibonacci-sequence-8.cpp
new file mode 100644
index 0000000000..f8f3d4e336
--- /dev/null
+++ b/Task/Fibonacci-sequence/C++/fibonacci-sequence-8.cpp
@@ -0,0 +1,11 @@
+// Use Standard Template Library to display Fibonacci sequence.
+// Nigel Galloway March 30th., 2013
+#include
+#include
+#include
+int main()
+{
+ int x = 1, y = 1;
+ generate_n(std::ostream_iterator(std::cout, " "), 21, [&]{int n=x; x=y; y+=n; return n;});
+ return 0;
+}
diff --git a/Task/Fibonacci-sequence/C/fibonacci-sequence-1.c b/Task/Fibonacci-sequence/C/fibonacci-sequence-1.c
new file mode 100644
index 0000000000..30e6a23ce5
--- /dev/null
+++ b/Task/Fibonacci-sequence/C/fibonacci-sequence-1.c
@@ -0,0 +1,3 @@
+long long unsigned fib(unsigned n) {
+ return n < 2 ? n : fib(n - 1) + fib(n - 2);
+}
diff --git a/Task/Fibonacci-sequence/C/fibonacci-sequence-2.c b/Task/Fibonacci-sequence/C/fibonacci-sequence-2.c
new file mode 100644
index 0000000000..2016fb230b
--- /dev/null
+++ b/Task/Fibonacci-sequence/C/fibonacci-sequence-2.c
@@ -0,0 +1,10 @@
+long long unsigned fib(unsigned n) {
+ long long unsigned last = 0, this = 1, new, i;
+ if (n < 2) return n;
+ for (i = 1 ; i < n ; ++i) {
+ new = last + this;
+ last = this;
+ this = new;
+ }
+ return this;
+}
diff --git a/Task/Fibonacci-sequence/C/fibonacci-sequence-3.c b/Task/Fibonacci-sequence/C/fibonacci-sequence-3.c
new file mode 100644
index 0000000000..f7be627bea
--- /dev/null
+++ b/Task/Fibonacci-sequence/C/fibonacci-sequence-3.c
@@ -0,0 +1,6 @@
+#include
+#define PHI ((1 + sqrt(5))/2)
+
+long long unsigned fib(unsigned n) {
+ return floor( (pow(PHI, n) - pow(1 - PHI, n))/sqrt(5) );
+}
diff --git a/Task/Fibonacci-sequence/C/fibonacci-sequence-4.c b/Task/Fibonacci-sequence/C/fibonacci-sequence-4.c
new file mode 100644
index 0000000000..536084dc9e
--- /dev/null
+++ b/Task/Fibonacci-sequence/C/fibonacci-sequence-4.c
@@ -0,0 +1,37 @@
+#include
+typedef enum{false=0, true=!0} bool;
+typedef void iterator;
+
+#include