+
+ 40->
+ IF NS>1 OR (NS=1 AND STACK$[1]<>"@") THEN NS=NS+1 END IF
+ STACK$[NS]="(" NPA=NPA+1
+ IF MID$(EXPRESSION$,W+1,1)="-" THEN FLAG=-1 W=W+1 END IF
+ END ->
+
+ 41->
+ SVOLGI_PAR
+ IF NERR=7 THEN
+ NERR=0 NOP=0 NPA=0 NS=1
+ ELSE
+ IF NERR=0 OR NERR=1 THEN
+ DB#=VAL(STACK$[NS])
+ REGISTRO_X#=DB#
+ ELSE
+ NOP=0 NPA=0 NS=1
+ END IF
+ END IF
+ END ->
+
+ OTHERWISE
+ NERR=8
+ END CASE
+ K$=""
+ DISEGNA_STACK
+END FOR
+
+98:
+ IF K$<>"" THEN
+ IF NS>1 OR (NS=1 AND STACK$[1]<>"@") THEN NS=NS+1 END IF
+ IF FLAG=0 THEN STACK$[NS]=K$ ELSE STACK$[NS]=STR$(VAL(K$)*FLAG) END IF
+ END IF
+ DISEGNA_STACK
+ IF INSTR(OP_LIST$,STACK$[NS])<>0 THEN
+ NERR=6
+ ELSE
+ WHILE NPA<>0 DO
+ SVOLGI_PAR
+ END WHILE
+ IF NERR<>7 THEN NS1=1 NS2=NS CALC_ARITM END IF
+ END IF
+ NS=1 NOP=0 NPA=0
+ !$RCODE="LOCATE 23,1"
+ IF NERR>0 THEN PRINT("Internal Error #";NERR) ELSE PRINT("Value is ";DB#) END IF
+END PROGRAM
diff --git a/Task/Arithmetic-evaluation/FreeBASIC/arithmetic-evaluation.freebasic b/Task/Arithmetic-evaluation/FreeBASIC/arithmetic-evaluation.freebasic
new file mode 100644
index 0000000000..c57ff93980
--- /dev/null
+++ b/Task/Arithmetic-evaluation/FreeBASIC/arithmetic-evaluation.freebasic
@@ -0,0 +1,195 @@
+'Arithmetic evaluation
+'
+'Create a program which parses and evaluates arithmetic expressions.
+'
+'Requirements
+'
+' * An abstract-syntax tree (AST) for the expression must be created from parsing the
+' input.
+' * The AST must be used in evaluation, also, so the input may not be directly evaluated
+' (e.g. by calling eval or a similar language feature.)
+' * The expression will be a string or list of symbols like "(1+3)*7".
+' * The four symbols + - * / must be supported as binary operators with conventional
+' precedence rules.
+' * Precedence-control parentheses must also be supported.
+'
+'Standard mathematical precedence should be followed:
+'
+' Parentheses
+' Multiplication/Division (left to right)
+' Addition/Subtraction (left to right)
+'
+' test cases:
+' 2*-3--4+-0.25 : returns -2.25
+' 1 + 2 * (3 + (4 * 5 + 6 * 7 * 8) - 9) / 10 : returns 71
+
+enum
+ false = 0
+ true = -1
+end enum
+
+enum Symbol
+ unknown_sym
+ minus_sym
+ plus_sym
+ lparen_sym
+ rparen_sym
+ number_sym
+ mul_sym
+ div_sym
+ unary_minus_sym
+ unary_plus_sym
+ done_sym
+ eof_sym
+end enum
+
+type Tree
+ as Tree ptr leftp, rightp
+ op as Symbol
+ value as double
+end type
+
+dim shared sym as Symbol
+dim shared tokenval as double
+dim shared usr_input as string
+
+declare function expr(byval p as integer) as Tree ptr
+
+function isdigit(byval ch as string) as long
+ return ch <> "" and Asc(ch) >= Asc("0") and Asc(ch) <= Asc("9")
+end function
+
+sub error_msg(byval msg as string)
+ print msg
+ system
+end sub
+
+' tokenize the input string
+sub getsym()
+ do
+ if usr_input = "" then
+ line input usr_input
+ usr_input += chr(10)
+ endif
+ dim as string ch = mid(usr_input, 1, 1) ' get the next char
+ usr_input = mid(usr_input, 2) ' remove it from input
+
+ sym = unknown_sym
+ select case ch
+ case " ": continue do
+ case chr(10), "": sym = done_sym: return
+ case "+": sym = plus_sym: return
+ case "-": sym = minus_sym: return
+ case "*": sym = mul_sym: return
+ case "/": sym = div_sym: return
+ case "(": sym = lparen_sym: return
+ case ")": sym = rparen_sym: return
+ case else
+ if isdigit(ch) then
+ dim s as string = ""
+ dim dot as integer = 0
+ do
+ s += ch
+ if ch = "." then dot += 1
+ ch = mid(usr_input, 1, 1) ' get the next char
+ usr_input = mid(usr_input, 2) ' remove it from input
+ loop while isdigit(ch) orelse ch = "."
+ if ch = "." or dot > 1 then error_msg("bogus number")
+ usr_input = ch + usr_input ' prepend the char to input
+ tokenval = val(s)
+ sym = number_sym
+ end if
+ return
+ end select
+ loop
+end sub
+
+function make_node(byval op as Symbol, byval leftp as Tree ptr, byval rightp as Tree ptr) as Tree ptr
+ dim t as Tree ptr
+
+ t = callocate(len(Tree))
+ t->op = op
+ t->leftp = leftp
+ t->rightp = rightp
+ return t
+end function
+
+function is_binary(byval op as Symbol) as integer
+ select case op
+ case mul_sym, div_sym, plus_sym, minus_sym: return true
+ case else: return false
+ end select
+end function
+
+function prec(byval op as Symbol) as integer
+ select case op
+ case unary_minus_sym, unary_plus_sym: return 100
+ case mul_sym, div_sym: return 90
+ case plus_sym, minus_sym: return 80
+ case else: return 0
+ end select
+end function
+
+function primary as Tree ptr
+ dim t as Tree ptr = 0
+
+ select case sym
+ case minus_sym, plus_sym
+ dim op as Symbol = sym
+ getsym()
+ t = expr(prec(unary_minus_sym))
+ if op = minus_sym then return make_node(unary_minus_sym, t, 0)
+ if op = plus_sym then return make_node(unary_plus_sym, t, 0)
+ case lparen_sym
+ getsym()
+ t = expr(0)
+ if sym <> rparen_sym then error_msg("expecting rparen")
+ getsym()
+ return t
+ case number_sym
+ t = make_node(sym, 0, 0)
+ t->value = tokenval
+ getsym()
+ return t
+ case else: error_msg("expecting a primary")
+ end select
+end function
+
+function expr(byval p as integer) as Tree ptr
+ dim t as Tree ptr = primary()
+
+ while is_binary(sym) andalso prec(sym) >= p
+ dim t1 as Tree ptr
+ dim op as Symbol = sym
+ getsym()
+ t1 = expr(prec(op) + 1)
+ t = make_node(op, t, t1)
+ wend
+ return t
+end function
+
+function eval(byval t as Tree ptr) as double
+ if t <> 0 then
+ select case t->op
+ case minus_sym: return eval(t->leftp) - eval(t->rightp)
+ case plus_sym: return eval(t->leftp) + eval(t->rightp)
+ case mul_sym: return eval(t->leftp) * eval(t->rightp)
+ case div_sym: return eval(t->leftp) / eval(t->rightp)
+ case unary_minus_sym: return -eval(t->leftp)
+ case unary_plus_sym: return eval(t->leftp)
+ case number_sym: return t->value
+ case else: error_msg("unexpected tree node")
+ end select
+ end if
+ return 0
+end function
+
+do
+ getsym()
+ if sym = eof_sym then exit do
+ if sym = done_sym then continue do
+ dim t as Tree ptr = expr(0)
+ print"> "; eval(t)
+ if sym = eof_sym then exit do
+ if sym <> done_sym then error_msg("unexpected input")
+loop
diff --git a/Task/Arithmetic-evaluation/Phix/arithmetic-evaluation.phix b/Task/Arithmetic-evaluation/Phix/arithmetic-evaluation.phix
new file mode 100644
index 0000000000..5eb43e2884
--- /dev/null
+++ b/Task/Arithmetic-evaluation/Phix/arithmetic-evaluation.phix
@@ -0,0 +1,218 @@
+sequence opstack = {} -- atom elements are literals,
+ -- sequence elements are subexpressions
+ -- on completion length(opstack) should be 1
+object token
+
+constant op_p_p = 0 -- 1: expressions stored as op,p1,p2
+ -- p_op_p -- 0: expressions stored as p1,op,p2
+ -- p_p_op -- -1: expressions stored as p1,p2,op
+
+object op = 0 -- 0 if none, else "+", "-", "*", "/", "^", "%", or "u-"
+
+string s -- the expression being parsed
+integer ch
+integer sidx
+
+procedure err(string msg)
+ printf(1,"%s\n%s^ %s\n\nPressEnter...",{s,repeat(' ',sidx-1),msg})
+ {} = wait_key()
+ abort(0)
+end procedure
+
+procedure nxtch(object msg="eof")
+ sidx += 1
+ if sidx>length(s) then
+ if string(msg) then err(msg) end if
+ ch = -1
+ else
+ ch = s[sidx]
+ end if
+end procedure
+
+procedure skipspaces()
+ while find(ch," \t\r\n")!=0 do nxtch(0) end while
+end procedure
+
+procedure get_token()
+atom n, fraction
+integer dec
+ skipspaces()
+ if ch=-1 then token = "eof" return end if
+ if ch>='0' and ch<='9' then
+ n = ch-'0'
+ while 1 do
+ nxtch(0)
+ if ch<'0' or ch>'9' then exit end if
+ n = n*10+ch-'0'
+ end while
+ if ch='.' then
+ dec = 1
+ fraction = 0
+ while 1 do
+ nxtch(0)
+ if ch<'0' or ch>'9' then exit end if
+ fraction = fraction*10 + ch-'0'
+ dec *= 10
+ end while
+ n += fraction/dec
+ end if
+-- if find(ch,"eE") then -- you get the idea
+-- end if
+ token = n
+ return
+ end if
+ if find(ch,"+-/*()^%")=0 then err("syntax error") end if
+ token = s[sidx..sidx]
+ nxtch(0)
+ return
+end procedure
+
+procedure Match(string t)
+ if token!=t then err(t&" expected") end if
+ get_token()
+end procedure
+
+procedure PopFactor()
+object p2 = opstack[$]
+ if op="u-" then
+ if op_p_p=1 then -- op_p_p
+ opstack[$] = {op,0,p2}
+ elsif op_p_p=0 then -- p_op_p
+ opstack[$] = {0,op,p2}
+ else -- -1 -- p_p_op
+ opstack[$] = {0,p2,op}
+ end if
+ else
+ opstack = opstack[1..$-1]
+ if op_p_p=1 then -- op_p_p
+ opstack[$] = {op,opstack[$],p2}
+ elsif op_p_p=0 then -- p_op_p
+ opstack[$] = {opstack[$],op,p2}
+ else -- -1 -- p_p_op
+ opstack[$] = {opstack[$],p2,op}
+ end if
+ end if
+ op = 0
+end procedure
+
+procedure PushFactor(atom t)
+ if op!=0 then PopFactor() end if
+ opstack = append(opstack,t)
+end procedure
+
+procedure PushOp(string t)
+ if op!=0 then PopFactor() end if
+ op = t
+end procedure
+
+procedure Factor()
+ if atom(token) then
+ PushFactor(token)
+ if ch!=-1 then
+ get_token()
+ end if
+ elsif token="-" then
+ get_token()
+-- Factor()
+ Expr(3) -- makes "-3^2" yield -9 (ie -(3^2)) not 9 (ie (-3)^2).
+ if op!=0 then PopFactor() end if
+ if integer(opstack[$]) then
+ opstack[$] = -opstack[$]
+ else
+ PushOp("u-")
+ end if
+ elsif token="(" then
+ get_token()
+ Expr(0)
+ Match(")")
+ elsif token="+" then -- (ignore)
+ nxtch()
+ Factor()
+ else
+ err("syntax error")
+ end if
+end procedure
+
+constant {operators,
+ precedence,
+ associativity} = columnize({{"^",3,0},
+ {"%",2,1},
+ {"*",2,1},
+ {"/",2,1},
+ {"+",1,1},
+ {"-",1,1},
+ $})
+
+procedure Expr(integer p)
+--
+-- Parse an expression, using precedence climbing.
+--
+-- p is the precedence level we should parse to, eg/ie
+-- 4: Factor only (may as well just call Factor)
+-- 3: "" and ^
+-- 2: "" and *,/,%
+-- 1: "" and +,-
+-- 0: full expression (effectively the same as 1)
+-- obviously, parentheses override any setting of p.
+--
+integer k, thisp
+ Factor()
+ while 1 do
+ k = find(token,operators) -- *,/,+,-
+ if k=0 then exit end if
+ thisp = precedence[k]
+ if thisp 5],
+ ['-4-3' => -7],
+ ['-+2+3/4' => -1.25],
+ ['2*3-4' => 2],
+ ['2*(3+4)+2/4' => 2/4 + 14],
+ ['2*-3--4+-0.25' => -2.25],
+ ['2 * (3 + (4 * 5 + (6 * 7) * 8) - 9) * 10' => 7000],
+] {
+ var num = evalArithmeticExp(expr);
+ assert_eq(num, res);
+ "%-45s == %10g\n".printf(expr, num);
+}
diff --git a/Task/Arithmetic-geometric-mean-Calculate-Pi/Phix/arithmetic-geometric-mean-calculate-pi.phix b/Task/Arithmetic-geometric-mean-Calculate-Pi/Phix/arithmetic-geometric-mean-calculate-pi.phix
new file mode 100644
index 0000000000..e03a1905d1
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean-Calculate-Pi/Phix/arithmetic-geometric-mean-calculate-pi.phix
@@ -0,0 +1,20 @@
+include bigatom.e
+
+{} = scale(203)
+bigatom a = BA_ONE,
+ n = BA_ONE,
+ g = ba_divide(BA_ONE,ba_sqrt(2)),
+ z = ba_new(0.25),
+ half = ba_new(0.5),
+ x1, x2, var
+for i=1 to 18 do
+?i
+ x1 = ba_multiply(ba_add(a,g),half)
+ x2 = ba_sqrt(ba_multiply(a,g))
+ var = ba_sub(x1,a)
+ z = ba_sub(z,ba_multiply(ba_multiply(var,var),n))
+ n = ba_add(n,n)
+ a = x1
+ g = x2
+end for
+ba_printf(1,"%.200aB\n",ba_divide(ba_multiply(a,a),z))
diff --git a/Task/Arithmetic-geometric-mean-Calculate-Pi/Sidef/arithmetic-geometric-mean-calculate-pi.sidef b/Task/Arithmetic-geometric-mean-Calculate-Pi/Sidef/arithmetic-geometric-mean-calculate-pi.sidef
new file mode 100644
index 0000000000..9659c70eec
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean-Calculate-Pi/Sidef/arithmetic-geometric-mean-calculate-pi.sidef
@@ -0,0 +1,23 @@
+func agm_pi(digits) {
+ var acc = (digits + 8);
+
+ local Num!PREC = 4*digits;
+
+ var an = 1;
+ var bn = sqrt(0.5);
+ var tn = 0.5**2;
+ var pn = 1;
+
+ while (pn < acc) {
+ var prev_an = an;
+ an = (bn+an / 2);
+ bn = sqrt(bn * prev_an);
+ prev_an -= an;
+ tn -= (pn * prev_an**2);
+ pn *= 2;
+ }
+
+ ((an+bn)**2 / 4*tn).to_s
+}
+
+say agm_pi(100);
diff --git a/Task/Arithmetic-geometric-mean/ERRE/arithmetic-geometric-mean.erre b/Task/Arithmetic-geometric-mean/ERRE/arithmetic-geometric-mean.erre
new file mode 100644
index 0000000000..19e943c2ef
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/ERRE/arithmetic-geometric-mean.erre
@@ -0,0 +1,21 @@
+PROGRAM AGM
+
+!
+! for rosettacode.org
+!
+
+!$DOUBLE
+
+PROCEDURE AGM(A,G->A)
+ LOCAL TA
+ REPEAT
+ TA=A
+ A=(A+G)/2
+ G=SQR(TA*G)
+ UNTIL A=TA
+END PROCEDURE
+
+BEGIN
+ AGM(1.0,1/SQR(2)->A)
+ PRINT(A)
+END PROGRAM
diff --git a/Task/Arithmetic-geometric-mean/EchoLisp/arithmetic-geometric-mean.echolisp b/Task/Arithmetic-geometric-mean/EchoLisp/arithmetic-geometric-mean.echolisp
new file mode 100644
index 0000000000..3b0f9a4bf2
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/EchoLisp/arithmetic-geometric-mean.echolisp
@@ -0,0 +1,14 @@
+(lib 'math)
+
+(define (agm a g)
+ (if (~= a g) a
+ (agm (// (+ a g ) 2) (sqrt (* a g)))))
+
+(math-precision)
+ → 0.000001 ;; default
+(agm 1 (/ 1 (sqrt 2)))
+ → 0.8472130848351929
+(math-precision 1.e-15)
+ → 1e-15
+(agm 1 (/ 1 (sqrt 2)))
+ → 0.8472130847939792
diff --git a/Task/Arithmetic-geometric-mean/FreeBASIC/arithmetic-geometric-mean.freebasic b/Task/Arithmetic-geometric-mean/FreeBASIC/arithmetic-geometric-mean.freebasic
new file mode 100644
index 0000000000..6b92859e0c
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/FreeBASIC/arithmetic-geometric-mean.freebasic
@@ -0,0 +1,26 @@
+' version 16-09-2015
+' compile with: fbc -s console
+
+Function agm(a As Double, g As Double) As Double
+
+ Dim As Double t_a
+
+ Do
+ t_a = (a + g) / 2
+ g = Sqr(a * g)
+ Swap a, t_a
+ Loop Until a = t_a
+
+ Return a
+
+End Function
+
+' ------=< MAIN >=------
+
+Print agm(1, 1 / Sqr(2) )
+
+' empty keyboard buffer
+While InKey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Arithmetic-geometric-mean/Futhark/arithmetic-geometric-mean.futhark b/Task/Arithmetic-geometric-mean/Futhark/arithmetic-geometric-mean.futhark
new file mode 100644
index 0000000000..ccb89b197c
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Futhark/arithmetic-geometric-mean.futhark
@@ -0,0 +1,6 @@
+fun agm(a: f64, g: f64): f64 =
+ let eps = 1.0E-16
+ loop ((a,g)) = while abs(a-g) > eps do
+ ((a+g) / 2.0,
+ sqrt64 (a*g))
+ in a
diff --git a/Task/Arithmetic-geometric-mean/LFE/arithmetic-geometric-mean.lfe b/Task/Arithmetic-geometric-mean/LFE/arithmetic-geometric-mean.lfe
new file mode 100644
index 0000000000..0231cadb99
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/LFE/arithmetic-geometric-mean.lfe
@@ -0,0 +1,15 @@
+(defun agm (a g)
+ (agm a g 1.0e-15))
+
+(defun agm (a g tol)
+ (if (=< (- a g) tol)
+ a
+ (agm (next-a a g)
+ (next-g a g)
+ tol)))
+
+(defun next-a (a g)
+ (/ (+ a g) 2))
+
+(defun next-g (a g)
+ (math:sqrt (* a g)))
diff --git a/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-1.livecode b/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-1.livecode
new file mode 100644
index 0000000000..a66c064999
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-1.livecode
@@ -0,0 +1,13 @@
+function agm aa,g
+ put abs(aa-g) into absdiff
+ put (aa+g)/2 into aan
+ put sqrt(aa*g) into gn
+ repeat while abs(aan - gn) < absdiff
+ put abs(aa-g) into absdiff
+ put (aa+g)/2 into aan
+ put sqrt(aa*g) into gn
+ put aan into aa
+ put gn into g
+ end repeat
+ return aa
+end agm
diff --git a/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-2.livecode b/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-2.livecode
new file mode 100644
index 0000000000..f1d0c4191f
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/LiveCode/arithmetic-geometric-mean-2.livecode
@@ -0,0 +1,3 @@
+put agm(1, 1/sqrt(2))
+-- ouput
+-- 0.847213
diff --git a/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-1.nim b/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-1.nim
new file mode 100644
index 0000000000..dcc5f0f4ad
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-1.nim
@@ -0,0 +1,14 @@
+import math
+
+proc agm(a, g: float,delta: float = 1.0e-15): float =
+ var
+ aNew: float = 0
+ aOld: float = a
+ gOld: float = g
+ while (abs(aOld - gOld) > delta):
+ aNew = 0.5 * (aOld + gOld)
+ gOld = sqrt(aOld * gOld)
+ aOld = aNew
+ result = aOld
+
+echo ($agm(1.0,1.0/sqrt(2)))
diff --git a/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-2.nim b/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-2.nim
new file mode 100644
index 0000000000..2f192cd8ca
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Nim/arithmetic-geometric-mean-2.nim
@@ -0,0 +1,20 @@
+from math import sqrt
+from strutils import parseFloat, formatFloat, ffDecimal
+
+proc agm(x,y: float): tuple[resA,resG: float] =
+ var
+ a,g: array[0 .. 23,float]
+
+ a[0] = x
+ g[0] = y
+
+ for n in 1 .. 23:
+ a[n] = 0.5 * (a[n - 1] + g[n - 1])
+ g[n] = sqrt(a[n - 1] * g[n - 1])
+
+ (a[23], g[23])
+
+var t = agm(1, 1/sqrt(2))
+
+echo("Result A: " & formatFloat(t.resA, ffDecimal, 24))
+echo("Result G: " & formatFloat(t.resG, ffDecimal, 24))
diff --git a/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-1.oforth b/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-1.oforth
new file mode 100644
index 0000000000..cf897d86c9
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-1.oforth
@@ -0,0 +1 @@
+: agm while(2dup <>) [ 2dup + 2 / tor * sqrt ] drop ;
diff --git a/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-2.oforth b/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-2.oforth
new file mode 100644
index 0000000000..856ebf338e
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Oforth/arithmetic-geometric-mean-2.oforth
@@ -0,0 +1 @@
+1 2 sqrt inv agm
diff --git a/Task/Arithmetic-geometric-mean/Phix/arithmetic-geometric-mean.phix b/Task/Arithmetic-geometric-mean/Phix/arithmetic-geometric-mean.phix
new file mode 100644
index 0000000000..f8b0e09de9
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Phix/arithmetic-geometric-mean.phix
@@ -0,0 +1,8 @@
+function agm(atom a, atom g, atom tolerance=1.0e-15)
+ while abs(a-g)>tolerance do
+ {a,g} = {(a + g)/2,sqrt(a*g)}
+ printf(1,"%0.15g\n",a)
+ end while
+ return a
+end function
+?agm(1,1/sqrt(2)) -- (rounds to 10 d.p.)
diff --git a/Task/Arithmetic-geometric-mean/Potion/arithmetic-geometric-mean.potion b/Task/Arithmetic-geometric-mean/Potion/arithmetic-geometric-mean.potion
new file mode 100644
index 0000000000..e756775c39
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Potion/arithmetic-geometric-mean.potion
@@ -0,0 +1,17 @@
+sqrt = (x) :
+ xi = 1
+ 7 times :
+ xi = (xi + x / xi) / 2
+ .
+ xi
+.
+
+agm = (x, y) :
+ 7 times :
+ a = (x + y) / 2
+ g = sqrt(x * y)
+ x = a
+ y = g
+ .
+ x
+.
diff --git a/Task/Arithmetic-geometric-mean/Ring/arithmetic-geometric-mean.ring b/Task/Arithmetic-geometric-mean/Ring/arithmetic-geometric-mean.ring
new file mode 100644
index 0000000000..7b3aecd3d5
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Ring/arithmetic-geometric-mean.ring
@@ -0,0 +1,13 @@
+decimals(9)
+see agm(1, 1/sqrt(2)) + nl
+see agm(1,1/pow(2,0.5)) + nl
+
+func agm agm,g
+ while agm
+ an = (agm + g)/2
+ gn = sqrt(agm*g)
+ if fabs(agm-g) <= fabs(an-gn) exit ok
+ agm = an
+ g = gn
+ end
+ return gn
diff --git a/Task/Arithmetic-geometric-mean/Sidef/arithmetic-geometric-mean.sidef b/Task/Arithmetic-geometric-mean/Sidef/arithmetic-geometric-mean.sidef
new file mode 100644
index 0000000000..da7db80329
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/Sidef/arithmetic-geometric-mean.sidef
@@ -0,0 +1,9 @@
+func agm(a, g) {
+ loop {
+ var x = [float(a+g / 2), sqrt(a*g)]
+ x == [a, g] && return a
+ x >> \(a, g)
+ }
+}
+
+say agm(1, 1/sqrt(2))
diff --git a/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-1.jq b/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-1.jq
new file mode 100644
index 0000000000..4d5df81971
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-1.jq
@@ -0,0 +1,9 @@
+def naive_agm(a; g; tolerance):
+ def abs: if . < 0 then -. else . end;
+ def _agm:
+ # state [an,gn]
+ if ((.[0] - .[1])|abs) > tolerance
+ then [add/2, ((.[0] * .[1])|sqrt)] | _agm
+ else .
+ end;
+ [a, g] | _agm | .[0] ;
diff --git a/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-2.jq b/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-2.jq
new file mode 100644
index 0000000000..670a910080
--- /dev/null
+++ b/Task/Arithmetic-geometric-mean/jq/arithmetic-geometric-mean-2.jq
@@ -0,0 +1,16 @@
+def agm(a; g; tolerance):
+ def abs: if . < 0 then -. else . end;
+ def _agm:
+ # state [an,gn, delta]
+ ((.[0] - .[1])|abs) as $delta
+ | if $delta == .[2] and $delta < 10e-16 then .
+ elif $delta > tolerance
+ then [ .[0:2]|add / 2, ((.[0] * .[1])|sqrt), $delta] | _agm
+ else .
+ end;
+ if tolerance <= 0 then error("specified tolerance must be > 0")
+ else [a, g, 0] | _agm | .[0]
+ end ;
+
+# Example:
+agm(1; 1/(2|sqrt); 1e-100)
diff --git a/Task/Array-concatenation/AntLang/array-concatenation.antlang b/Task/Array-concatenation/AntLang/array-concatenation.antlang
new file mode 100644
index 0000000000..64d32e6139
--- /dev/null
+++ b/Task/Array-concatenation/AntLang/array-concatenation.antlang
@@ -0,0 +1,3 @@
+a:<1; <2; 3>>
+b: <"Hello"; 42>
+c: a,b
diff --git a/Task/Array-concatenation/Apex/array-concatenation.apex b/Task/Array-concatenation/Apex/array-concatenation.apex
new file mode 100644
index 0000000000..0551662a18
--- /dev/null
+++ b/Task/Array-concatenation/Apex/array-concatenation.apex
@@ -0,0 +1,4 @@
+List listA = new List { 'apple' };
+List listB = new List { 'banana' };
+listA.addAll(listB);
+System.debug(listA); // Prints (apple, banana)
diff --git a/Task/Array-concatenation/Ceylon/array-concatenation.ceylon b/Task/Array-concatenation/Ceylon/array-concatenation.ceylon
new file mode 100644
index 0000000000..971bef4f1d
--- /dev/null
+++ b/Task/Array-concatenation/Ceylon/array-concatenation.ceylon
@@ -0,0 +1,6 @@
+shared void arrayConcatenation() {
+ value a = Array {1, 2, 3};
+ value b = Array {4, 5, 6};
+ value c = concatenate(a, b);
+ print(c);
+}
diff --git a/Task/Array-concatenation/ECL/array-concatenation.ecl b/Task/Array-concatenation/ECL/array-concatenation.ecl
new file mode 100644
index 0000000000..cd1479609e
--- /dev/null
+++ b/Task/Array-concatenation/ECL/array-concatenation.ecl
@@ -0,0 +1,4 @@
+ A := [1, 2, 3, 4];
+ B := [5, 6, 7, 8];
+
+ C := A + B;
diff --git a/Task/Array-concatenation/ERRE/array-concatenation.erre b/Task/Array-concatenation/ERRE/array-concatenation.erre
new file mode 100644
index 0000000000..b175303cec
--- /dev/null
+++ b/Task/Array-concatenation/ERRE/array-concatenation.erre
@@ -0,0 +1,31 @@
+PROGRAM ARRAY_CONCAT
+
+DIM A[5],B[5],C[10]
+
+!
+! for rosettacode.org
+!
+
+BEGIN
+ DATA(1,2,3,4,5)
+ DATA(6,7,8,9,0)
+
+ FOR I=1 TO 5 DO ! read array A[.]
+ READ(A[I])
+ END FOR
+ FOR I=1 TO 5 DO ! read array B[.]
+ READ(B[I])
+ END FOR
+
+ FOR I=1 TO 10 DO ! append B[.] to A[.]
+ IF I>5 THEN
+ C[I]=B[I-5]
+ ELSE
+ C[I]=A[I]
+ END IF
+ PRINT(C[I];) ! print single C value
+ END FOR
+
+ PRINT
+
+END PROGRAM
diff --git a/Task/Array-concatenation/EchoLisp/array-concatenation.echolisp b/Task/Array-concatenation/EchoLisp/array-concatenation.echolisp
new file mode 100644
index 0000000000..0b37da134e
--- /dev/null
+++ b/Task/Array-concatenation/EchoLisp/array-concatenation.echolisp
@@ -0,0 +1,12 @@
+;;;; VECTORS
+(vector-append (make-vector 6 42) (make-vector 4 666))
+ → #( 42 42 42 42 42 42 666 666 666 666)
+
+;;;; LISTS
+(append (iota 5) (iota 6))
+ → (0 1 2 3 4 0 1 2 3 4 5)
+
+;; NB - append may also be used with sequences (lazy lists)
+(lib 'sequences)
+ (take (append [1 .. 7] [7 6 .. 0]) #:all)
+ → (1 2 3 4 5 6 7 6 5 4 3 2 1)
diff --git a/Task/Array-concatenation/Elm/array-concatenation.elm b/Task/Array-concatenation/Elm/array-concatenation.elm
new file mode 100644
index 0000000000..bebfc008b1
--- /dev/null
+++ b/Task/Array-concatenation/Elm/array-concatenation.elm
@@ -0,0 +1,19 @@
+import Element exposing (show, toHtml) -- elm-package install evancz/elm-graphics
+import Html.App exposing (beginnerProgram)
+import Array exposing (Array, append, initialize)
+
+
+xs : Array Int
+xs =
+ initialize 3 identity -- [0, 1, 2]
+
+ys : Array Int
+ys =
+ initialize 3 <| (+) 3 -- [3, 4, 5]
+
+main = beginnerProgram { model = ()
+ , view = \_ -> toHtml (show (append xs ys))
+ , update = \_ _ -> ()
+ }
+
+-- Array.fromList [0,1,2,3,4,5]
diff --git a/Task/Array-concatenation/FreeBASIC/array-concatenation.freebasic b/Task/Array-concatenation/FreeBASIC/array-concatenation.freebasic
new file mode 100644
index 0000000000..2f67fe40df
--- /dev/null
+++ b/Task/Array-concatenation/FreeBASIC/array-concatenation.freebasic
@@ -0,0 +1,26 @@
+' FB 1.05.0 Win64
+
+Sub ConcatArrays(a() As String, b() As String, c() As String)
+ Dim aSize As Integer = UBound(a) - LBound(a) + 1
+ Dim bSize As Integer = UBound(b) - LBound(b) + 1
+ Dim cSize As Integer = aSize + bSize
+ Redim c(0 To cSize - 1)
+ Dim i As Integer
+ For i = 0 To aSize - 1
+ c(i) = a(LBound(a) + i)
+ Next
+ For i = 0 To bSize - 1
+ c(UBound(a) + i + 1) = b(LBound(b) + i)
+ Next
+End Sub
+
+Dim a(3) As String = {"The", "quick", "brown", "fox"}
+Dim b(4) As String = {"jumped", "over", "the", "lazy", "dog"}
+Dim c() As String
+ConcatArrays(a(), b(), c())
+For i As Integer = LBound(c) To UBound(c)
+ Print c(i); " ";
+Next
+Print : Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Array-concatenation/FunL/array-concatenation.funl b/Task/Array-concatenation/FunL/array-concatenation.funl
new file mode 100644
index 0000000000..02c5baaad2
--- /dev/null
+++ b/Task/Array-concatenation/FunL/array-concatenation.funl
@@ -0,0 +1,5 @@
+arr1 = array( [1, 2, 3] )
+arr2 = array( [4, 5, 6] )
+arr3 = array( [7, 8, 9] )
+
+println( arr1 + arr2 + arr3 )
diff --git a/Task/Array-concatenation/Futhark/array-concatenation.futhark b/Task/Array-concatenation/Futhark/array-concatenation.futhark
new file mode 100644
index 0000000000..5b10455351
--- /dev/null
+++ b/Task/Array-concatenation/Futhark/array-concatenation.futhark
@@ -0,0 +1 @@
+concat as bs cd
diff --git a/Task/Array-concatenation/I/array-concatenation.i b/Task/Array-concatenation/I/array-concatenation.i
new file mode 100644
index 0000000000..5c6d1f13aa
--- /dev/null
+++ b/Task/Array-concatenation/I/array-concatenation.i
@@ -0,0 +1,6 @@
+software {
+ var a = [1, 2, 3]
+ var b = [4, 5, 6]
+
+ print(a + b)
+}
diff --git a/Task/Array-concatenation/LFE/array-concatenation.lfe b/Task/Array-concatenation/LFE/array-concatenation.lfe
new file mode 100644
index 0000000000..9047497ba1
--- /dev/null
+++ b/Task/Array-concatenation/LFE/array-concatenation.lfe
@@ -0,0 +1,4 @@
+> (++ '(1 2 3) '(4 5 6))
+(1 2 3 4 5 6)
+> (: lists append '(1 2 3) '(4 5 6))
+(1 2 3 4 5 6)
diff --git a/Task/Array-concatenation/Lasso/array-concatenation.lasso b/Task/Array-concatenation/Lasso/array-concatenation.lasso
new file mode 100644
index 0000000000..a9732188a2
--- /dev/null
+++ b/Task/Array-concatenation/Lasso/array-concatenation.lasso
@@ -0,0 +1,12 @@
+local(arr1 = array(1, 2, 3))
+local(arr2 = array(4, 5, 6))
+local(arr3 = #arr1->asCopy) // make arr3 a copy of arr2
+#arr3->merge(#arr2) // concatenate 2 arrays
+
+
+Result:
+
+arr1 = array(1, 2, 3)
+arr2 = array(4, 5, 6)
+arr3 = array(4, 5, 6)
+arr3 = array(1, 2, 3, 4, 5, 6)
diff --git a/Task/Array-concatenation/Lingo/array-concatenation.lingo b/Task/Array-concatenation/Lingo/array-concatenation.lingo
new file mode 100644
index 0000000000..56f55c91b6
--- /dev/null
+++ b/Task/Array-concatenation/Lingo/array-concatenation.lingo
@@ -0,0 +1,9 @@
+a = [1,2]
+b = [3,4,5]
+
+repeat with v in b
+ a.append(v)
+end repeat
+
+put a
+-- [1, 2, 3, 4, 5]
diff --git a/Task/Array-concatenation/Nim/array-concatenation-1.nim b/Task/Array-concatenation/Nim/array-concatenation-1.nim
new file mode 100644
index 0000000000..7b20bf0b18
--- /dev/null
+++ b/Task/Array-concatenation/Nim/array-concatenation-1.nim
@@ -0,0 +1,4 @@
+var
+ x = @[1,2,3,4,5,6]
+ y = @[7,8,9,10,11]
+ z = x & y
diff --git a/Task/Array-concatenation/Nim/array-concatenation-2.nim b/Task/Array-concatenation/Nim/array-concatenation-2.nim
new file mode 100644
index 0000000000..03f1186dc2
--- /dev/null
+++ b/Task/Array-concatenation/Nim/array-concatenation-2.nim
@@ -0,0 +1,7 @@
+var
+ a = [1,2,3,4,5,6]
+ b = [7,8,9,10,11]
+ c: array[11, int]
+
+c[0..5] = a
+c[6..10] = b
diff --git a/Task/Array-concatenation/Oforth/array-concatenation.oforth b/Task/Array-concatenation/Oforth/array-concatenation.oforth
new file mode 100644
index 0000000000..3f2a4556fb
--- /dev/null
+++ b/Task/Array-concatenation/Oforth/array-concatenation.oforth
@@ -0,0 +1 @@
+[1, 2, 3 ] [ 4, 5, 6, 7 ] +
diff --git a/Task/Array-concatenation/Phix/array-concatenation.phix b/Task/Array-concatenation/Phix/array-concatenation.phix
new file mode 100644
index 0000000000..ba146b581e
--- /dev/null
+++ b/Task/Array-concatenation/Phix/array-concatenation.phix
@@ -0,0 +1,2 @@
+sequence s1 = {1,2,3}, s2 = {4,5,6}
+? s1 & s2
diff --git a/Task/Array-concatenation/Ring/array-concatenation.ring b/Task/Array-concatenation/Ring/array-concatenation.ring
new file mode 100644
index 0000000000..96ec1b2167
--- /dev/null
+++ b/Task/Array-concatenation/Ring/array-concatenation.ring
@@ -0,0 +1,8 @@
+arr1 = [1, 2, 3]
+arr2 = [4, 5, 6]
+arr3 = [7, 8, 9]
+arr4 = arr1 + arr2
+see arr4
+see nl
+arr5 = arr4 + arr3
+see arr5
diff --git a/Task/Array-concatenation/Sidef/array-concatenation.sidef b/Task/Array-concatenation/Sidef/array-concatenation.sidef
new file mode 100644
index 0000000000..c94a262601
--- /dev/null
+++ b/Task/Array-concatenation/Sidef/array-concatenation.sidef
@@ -0,0 +1,3 @@
+var arr1 = [1, 2, 3];
+var arr2 = [4, 5, 6];
+var arr3 = (arr1 + arr2); # => [1, 2, 3, 4, 5, 6]
diff --git a/Task/Array-concatenation/Swift/array-concatenation.swift b/Task/Array-concatenation/Swift/array-concatenation.swift
new file mode 100644
index 0000000000..d98de394c5
--- /dev/null
+++ b/Task/Array-concatenation/Swift/array-concatenation.swift
@@ -0,0 +1,3 @@
+let array1 = [1,2,3]
+let array2 = [4,5,6]
+let array3 = array1 + array2
diff --git a/Task/Array-concatenation/Ursa/array-concatenation.ursa b/Task/Array-concatenation/Ursa/array-concatenation.ursa
new file mode 100644
index 0000000000..12664a5ef9
--- /dev/null
+++ b/Task/Array-concatenation/Ursa/array-concatenation.ursa
@@ -0,0 +1,16 @@
+# create two streams (the ursa equivalent of arrays)
+# a contains the numbers 1-10, b contains 11-20
+decl int<> a b
+decl int i
+for (set i 1) (< i 11) (inc i)
+ append i a
+end for
+for (set i 11) (< i 21) (inc i)
+ append i b
+end for
+
+# append the values in b to a
+append b a
+
+# output a to the console
+out a endl console
diff --git a/Task/Array-concatenation/Wart/array-concatenation.wart b/Task/Array-concatenation/Wart/array-concatenation.wart
new file mode 100644
index 0000000000..d20242b97c
--- /dev/null
+++ b/Task/Array-concatenation/Wart/array-concatenation.wart
@@ -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/Wren/array-concatenation.wren b/Task/Array-concatenation/Wren/array-concatenation.wren
new file mode 100644
index 0000000000..169b5adac1
--- /dev/null
+++ b/Task/Array-concatenation/Wren/array-concatenation.wren
@@ -0,0 +1,6 @@
+var arr1 = [1,2,3]
+var arr2 = [4,5,6]
+for (e in arr2) {
+ arr1.add(e)
+}
+System.print(arr1)
diff --git a/Task/Array-concatenation/jq/array-concatenation.jq b/Task/Array-concatenation/jq/array-concatenation.jq
new file mode 100644
index 0000000000..30e63f6f20
--- /dev/null
+++ b/Task/Array-concatenation/jq/array-concatenation.jq
@@ -0,0 +1,3 @@
+[1,2] + [3] + [null] # => [1,2,3,null]
+
+[range(1;3), 3, null] # => [1,2,3,null]
diff --git a/Task/Arrays/8051-Assembly/arrays.8051 b/Task/Arrays/8051-Assembly/arrays.8051
new file mode 100644
index 0000000000..00f60e39b5
--- /dev/null
+++ b/Task/Arrays/8051-Assembly/arrays.8051
@@ -0,0 +1,90 @@
+; constant array (elements are unchangeable) - the array is stored in the CODE segment
+myarray db 'Array' ; db = define bytes - initializes 5 bytes with values 41, 72, 72, etc. (the ascii characters A,r,r,a,y)
+myarray2 dw 'A','r','r','a','y' ; dw = define words - initializes 5 words (1 word = 2 bytes) with values 41 00 , 72 00, 72 00, etc.
+; how to read index a of the array
+ push acc
+ push dph
+ push dpl
+ mov dpl,#low(myarray) ; location of array
+ mov dph,#high(myarray)
+ movc a,@a+dptr ; a = element a
+ mov r0, a ; r0 = element a
+ pop dpl
+ pop dph
+ pop acc ; a = original index again
+
+; array stored in internal RAM (A_START is the first register of the array, A_END is the last)
+; initalise array data (with 0's)
+ push 0
+ mov r0, #A_START
+clear:
+ mov @r0, #0
+ inc r0
+ cjne r0, #A_END, clear
+ pop 0
+; how to read index r1 of array
+ push psw
+ mov a, #A_START
+ add a, r1 ; a = memory location of element r1
+ push 0
+ mov r0, a
+ mov a, @r0 ; a = element r1
+ pop 0
+ pop psw
+; how to write value of acc into index r1 of array
+ push psw
+ push 0
+ push acc
+ mov a, #A_START
+ add a, r1
+ mov r0, a
+ pop acc
+ mov @r0, a ; element r1 = a
+ pop 0
+ pop psw
+
+; array stored in external RAM (A_START is the first memory location of the array, LEN is the length)
+; initalise array data (with 0's)
+ push dph
+ push dpl
+ push acc
+ push 0
+ mov dptr, #A_START
+ clr a
+ mov r0, #LEN
+clear:
+ movx @dptr, a
+ inc dptr
+ djnz r0, clear
+ pop 0
+ pop acc
+ pop dpl
+ pop dph
+; how to read index r1 of array
+ push dph
+ push dpl
+ push 0
+ mov dptr, #A_START-1
+ mov r0, r1
+ inc r0
+loop:
+ inc dptr
+ djnz r0, loop
+ movx a, @dptr ; a = element r1
+ pop 0
+ pop dpl
+ pop dph
+; how to write value of acc into index r1 of array
+ push dph
+ push dpl
+ push 0
+ mov dptr, #A_START-1
+ mov r0, r1
+ inc r0
+loop:
+ inc dptr
+ djnz r0, loop
+ movx @dptr, a ; element r1 = a
+ pop 0
+ pop dpl
+ pop dph
diff --git a/Task/Arrays/8th/arrays.8th b/Task/Arrays/8th/arrays.8th
new file mode 100644
index 0000000000..8291343779
--- /dev/null
+++ b/Task/Arrays/8th/arrays.8th
@@ -0,0 +1,14 @@
+[ 1 , 2 ,3 ] \ an array holding three numbers
+1 a:@ \ this will be '2', the element at index 1
+drop
+1 123 a:@ \ this will store the value '123' at index 1, so now
+. \ will print [1,123,3]
+
+[1,2,3] 45 a:push
+\ gives us [1,2,3,45]
+\ and empty spots are filled with null:
+[1,2,3] 5 15 a:!
+\ gives [1,2,3,null,15]
+
+\ arrays don't have to be homogenous:
+[1,"one", 2, "two"]
diff --git a/Task/Arrays/AntLang/arrays.antlang b/Task/Arrays/AntLang/arrays.antlang
new file mode 100644
index 0000000000..f8dda813f9
--- /dev/null
+++ b/Task/Arrays/AntLang/arrays.antlang
@@ -0,0 +1,13 @@
+/ Create an immutable sequence (array)
+arr: <1;2;3>
+
+/ Get the head an tail part
+h: head[arr]
+t: tail[arr]
+
+/ Get everything except the last element and the last element
+nl: first[arr]
+l: last[arr]
+
+/ Get the nth element (index origin = 0)
+nth:arr[n]
diff --git a/Task/Arrays/Apex/arrays-1.apex b/Task/Arrays/Apex/arrays-1.apex
new file mode 100644
index 0000000000..7c0b2cd072
--- /dev/null
+++ b/Task/Arrays/Apex/arrays-1.apex
@@ -0,0 +1,3 @@
+Integer[] array = new Integer[10]; // optionally, append a braced list of Integers like "{1, 2, 3}"
+array[0] = 42;
+System.debug(array[0]); // Prints 42
diff --git a/Task/Arrays/Apex/arrays-2.apex b/Task/Arrays/Apex/arrays-2.apex
new file mode 100644
index 0000000000..54a643dfcb
--- /dev/null
+++ b/Task/Arrays/Apex/arrays-2.apex
@@ -0,0 +1,4 @@
+List aList = new List (); // optionally add an initial size as an argument
+aList.add(5);// appends to the end of the list
+aList.add(1, 6);// assigns the element at index 1
+System.debug(list[0]); // Prints 5, alternatively you can use list.get(0)
diff --git a/Task/Arrays/Axe/arrays.axe b/Task/Arrays/Axe/arrays.axe
new file mode 100644
index 0000000000..5f9d9b4a67
--- /dev/null
+++ b/Task/Arrays/Axe/arrays.axe
@@ -0,0 +1,8 @@
+1→{L₁}
+2→{L₁+1}
+3→{L₁+2}
+4→{L₁+3}
+Disp {L₁}►Dec,i
+Disp {L₁+1}►Dec,i
+Disp {L₁+2}►Dec,i
+Disp {L₁+3}►Dec,i
diff --git a/Task/Arrays/BML/arrays.bml b/Task/Arrays/BML/arrays.bml
new file mode 100644
index 0000000000..661b0a3bd1
--- /dev/null
+++ b/Task/Arrays/BML/arrays.bml
@@ -0,0 +1,11 @@
+% Define an array(containing the numbers 1-3) named arr in the group $
+in $ let arr hold 1 2 3
+
+% Replace the value at index 0 in array to "Index 0"
+set $arr index 0 to "Index 0"
+
+% Will display "Index 0"
+display $arr index 0
+
+% There is no automatic garbage collection
+delete $arr
diff --git a/Task/Arrays/Ceylon/arrays.ceylon b/Task/Arrays/Ceylon/arrays.ceylon
new file mode 100644
index 0000000000..75f9415ea9
--- /dev/null
+++ b/Task/Arrays/Ceylon/arrays.ceylon
@@ -0,0 +1,20 @@
+import ceylon.collection {
+
+ ArrayList
+}
+
+shared void run() {
+
+ // you can get an array from the Array.ofSize named constructor
+ value array = Array.ofSize(10, "hello");
+ value a = array[3];
+ print(a);
+ array[4] = "goodbye";
+ print(array);
+
+ // for a dynamic list import ceylon.collection in your module.ceylon file
+ value list = ArrayList();
+ list.push("hello");
+ list.push("hello again");
+ print(list);
+}
diff --git a/Task/Arrays/ChucK/arrays.chuck b/Task/Arrays/ChucK/arrays.chuck
new file mode 100644
index 0000000000..d289adcd35
--- /dev/null
+++ b/Task/Arrays/ChucK/arrays.chuck
@@ -0,0 +1,9 @@
+int array[0]; // instantiate int array
+array << 1; // append item
+array << 2 << 3; // append items
+4 => array[3]; // assign element(4) to index(3)
+5 => array.size; // resize
+array.clear(); // clear elements
+<<>>; // print in cosole array size
+[1,2,3,4,5,6,7] @=> array;
+array.popBack(); // Pop last element
diff --git a/Task/Arrays/Computer-zero-Assembly/arrays-1.computer b/Task/Arrays/Computer-zero-Assembly/arrays-1.computer
new file mode 100644
index 0000000000..23c40daae3
--- /dev/null
+++ b/Task/Arrays/Computer-zero-Assembly/arrays-1.computer
@@ -0,0 +1,31 @@
+load: LDA ary
+ ADD sum
+ STA sum
+
+ LDA load
+ ADD one
+ STA load
+
+ SUB end
+ BRZ done
+
+ JMP load
+
+done: LDA sum
+ STP
+
+one: 1
+end: LDA ary+10
+
+sum: 0
+
+ary: 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
diff --git a/Task/Arrays/Computer-zero-Assembly/arrays-2.computer b/Task/Arrays/Computer-zero-Assembly/arrays-2.computer
new file mode 100644
index 0000000000..c2d0a3bd34
--- /dev/null
+++ b/Task/Arrays/Computer-zero-Assembly/arrays-2.computer
@@ -0,0 +1,30 @@
+load: LDA ary
+ BRZ done
+
+ ADD sum
+ STA sum
+
+ LDA load
+ ADD one
+ STA load
+
+ JMP load
+
+done: LDA sum
+ STP
+
+one: 1
+
+sum: 0
+
+ary: 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 0
diff --git a/Task/Arrays/FreeBASIC/arrays.freebasic b/Task/Arrays/FreeBASIC/arrays.freebasic
new file mode 100644
index 0000000000..7fe8b9455c
--- /dev/null
+++ b/Task/Arrays/FreeBASIC/arrays.freebasic
@@ -0,0 +1,82 @@
+' compile with: FBC -s console.
+' compile with: FBC -s console -exx to have boundary checks.
+
+Dim As Integer a(5) ' from s(0) to s(5)
+Dim As Integer num = 1
+Dim As String s(-num To num) ' s1(-1), s1(0) and s1(1)
+
+Static As UByte c(5) ' create a array with 6 elements (0 to 5)
+
+'dimension array and initializing it with Data
+Dim d(1 To 2, 1 To 5) As Integer => {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}}
+Print " The first dimension has a lower bound of"; LBound(d);_
+ " and a upper bound of"; UBound(d)
+Print " The second dimension has a lower bound of"; LBound(d,2);_
+ " and a upper bound of"; UBound(d,2)
+Print : Print
+
+Dim Shared As UByte u(0 To 3) ' make a shared array of UByte with 4 elements
+
+Dim As UInteger pow() ' make a variable length array
+' you must Dim the array before you can use ReDim
+ReDim pow(num) ' pow now has 1 element
+pow(num) = 10 ' lets fill it with 10 and print it
+Print " The value of pow(num) = "; pow(num)
+
+ReDim pow(10) ' make pow a 10 element array
+Print
+Print " Pow now has"; UBound(pow) - LBound(pow) +1; " elements"
+' the value of pow(num) is gone now
+Print " The value of pow(num) = "; pow(num); ", should be 0"
+
+Print
+For i As Integer = LBound(pow) To UBound(pow)
+ pow(i) = i * i
+ Print pow(i),
+Next
+Print:Print
+
+ReDim Preserve pow(3 To 7)
+' the first five elements will be preserved, not elements 3 to 7
+Print
+Print " The lower bound is now"; LBound(pow);_
+ " and the upper bound is"; UBound(pow)
+Print " Pow now has"; UBound(pow) - LBound(pow) +1; " elements"
+Print
+For i As Integer = LBound(pow) To UBound(pow)
+ Print pow(i),
+Next
+Print : Print
+
+'erase the variable length array
+Erase pow
+Print " The lower bound is now"; LBound(pow);_
+ " and the upper bound is "; UBound(pow)
+Print " If the lower bound is 0 and the upper bound is -1 it means,"
+Print " that the array has no elements, it's completely removed"
+Print : Print
+
+'erase the fixed length array
+Print " Display the contents of the array d"
+For i As Integer = 1 To 2 : For j As Integer = 1 To 5
+ Print d(i,j);" ";
+Next : Next : Print : Print
+
+Erase d
+Print " We have erased array d"
+Print " The first dimension has a lower bound of"; LBound(d);_
+ " and a upper bound of"; UBound(d)
+Print " The second dimension has a lower bound of"; LBound(d,2);_
+ " and a upper bound of"; UBound(d,2)
+Print
+For i As Integer = 1 To 2 : For j As Integer = 1 To 5
+ Print d(i,j);" ";
+Next : Next
+Print
+Print " The elements self are left untouched but there content is set to 0"
+
+' empty keyboard buffer
+While InKey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Arrays/Futhark/arrays-1.futhark b/Task/Arrays/Futhark/arrays-1.futhark
new file mode 100644
index 0000000000..b5d8bb58d9
--- /dev/null
+++ b/Task/Arrays/Futhark/arrays-1.futhark
@@ -0,0 +1 @@
+[1, 2, 3]
diff --git a/Task/Arrays/Futhark/arrays-2.futhark b/Task/Arrays/Futhark/arrays-2.futhark
new file mode 100644
index 0000000000..13658c363c
--- /dev/null
+++ b/Task/Arrays/Futhark/arrays-2.futhark
@@ -0,0 +1,2 @@
+replicate 5 3 == [3,3,3,3,3]
+iota 5 = [0,1,2,3,4]
diff --git a/Task/Arrays/Futhark/arrays-3.futhark b/Task/Arrays/Futhark/arrays-3.futhark
new file mode 100644
index 0000000000..c5007221b6
--- /dev/null
+++ b/Task/Arrays/Futhark/arrays-3.futhark
@@ -0,0 +1,3 @@
+fun update(as: *[]int, i: int, x: int): []int =
+ let as[i] = x
+ in x
diff --git a/Task/Arrays/Harbour/arrays-1.harbour b/Task/Arrays/Harbour/arrays-1.harbour
new file mode 100644
index 0000000000..fff55e29c3
--- /dev/null
+++ b/Task/Arrays/Harbour/arrays-1.harbour
@@ -0,0 +1,11 @@
+ // Declare and initialize two-dimensional array
+ local arr1 := { { "NITEM", "N", 10, 0 }, { "CONTENT", "C", 60, 0 } }
+ // Create an empty array
+ local arr2 := {}
+ // Declare three-dimensional array
+ local arr3[ 2, 100, 3 ]
+ // Create an array
+ local arr4 := Array( 50 )
+
+ // Array can be dynamically resized:
+ arr4 := ASize( arr4, 80 )
diff --git a/Task/Arrays/Harbour/arrays-2.harbour b/Task/Arrays/Harbour/arrays-2.harbour
new file mode 100644
index 0000000000..0f710c5620
--- /dev/null
+++ b/Task/Arrays/Harbour/arrays-2.harbour
@@ -0,0 +1,6 @@
+// Adding new item to array, its size is incremented
+ AAdd( arr1, { "LBASE", "L", 1, 0 } )
+// Delete the first item of arr3, The size of arr3 remains the same, all items are shifted to one position, the last item is replaced by Nil:
+ ADel( arr1, 1 )
+// Assigning a value to array item
+ arr3[ 1, 1, 1 ] := 11.4
diff --git a/Task/Arrays/Harbour/arrays-3.harbour b/Task/Arrays/Harbour/arrays-3.harbour
new file mode 100644
index 0000000000..c0a304c6c3
--- /dev/null
+++ b/Task/Arrays/Harbour/arrays-3.harbour
@@ -0,0 +1,2 @@
+ x := arr3[ 1, 10, 2 ]
+// The retrieved item can be nested array, in this case it isn't copied, the pointer to it is assigned
diff --git a/Task/Arrays/Harbour/arrays-4.harbour b/Task/Arrays/Harbour/arrays-4.harbour
new file mode 100644
index 0000000000..bfbe043281
--- /dev/null
+++ b/Task/Arrays/Harbour/arrays-4.harbour
@@ -0,0 +1,7 @@
+// Fill the 20 items of array with 0, starting from 5-th item:
+ AFill( arr4, 0, 5, 20 )
+// Copy 10 items from arr4 to arr3[ 2 ], starting from the first position:
+ ACopy( arr4, arr3[ 2 ], 1, 10 )
+// Duplicate the whole or nested array:
+ arr5 := AClone( arr1 )
+ arr6 := AClone( arr1[ 3 ] )
diff --git a/Task/Arrays/I/arrays-1.i b/Task/Arrays/I/arrays-1.i
new file mode 100644
index 0000000000..50294476d4
--- /dev/null
+++ b/Task/Arrays/I/arrays-1.i
@@ -0,0 +1,9 @@
+software {
+ var a = []
+ a += 2
+ print(a[0]) //Outputs 2
+
+ a[0] = 4
+
+ print(a[0]) //Outputs 4
+}
diff --git a/Task/Arrays/I/arrays-2.i b/Task/Arrays/I/arrays-2.i
new file mode 100644
index 0000000000..ae65dbdff8
--- /dev/null
+++ b/Task/Arrays/I/arrays-2.i
@@ -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/I/arrays-3.i b/Task/Arrays/I/arrays-3.i
new file mode 100644
index 0000000000..a3a972a13f
--- /dev/null
+++ b/Task/Arrays/I/arrays-3.i
@@ -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/LFE/arrays.lfe b/Task/Arrays/LFE/arrays.lfe
new file mode 100644
index 0000000000..7e795da653
--- /dev/null
+++ b/Task/Arrays/LFE/arrays.lfe
@@ -0,0 +1,51 @@
+; Create a fixed-size array with entries 0-9 set to 'undefined'
+> (set a0 (: array new 10))
+#(array 10 0 undefined 10)
+> (: array size a0)
+10
+
+; Create an extendible array and set entry 17 to 'true',
+; causing the array to grow automatically
+> (set a1 (: array set 17 'true (: array new)))
+#(array
+ 18
+ ...
+(: array size a1)
+18
+
+; Read back a stored value
+> (: array get 17 a1)
+true
+
+; Accessing an unset entry returns the default value
+> (: array get 3 a1)
+undefined
+
+; Accessing an entry beyond the last set entry also returns the
+; default value, if the array does not have fixed size
+> (: array get 18 a1)
+undefined
+
+; "sparse" functions ignore default-valued entries
+> (set a2 (: array set 4 'false a1))
+#(array
+ 18
+ ...
+> (: array sparse_to_orddict a2)
+(#(4 false) #(17 true))
+
+; An extendible array can be made fixed-size later
+> (set a3 (: array fix a2))
+#(array
+ 18
+ ...
+
+; A fixed-size array does not grow automatically and does not
+; allow accesses beyond the last set entry
+> (: array set 18 'true a3)
+exception error: badarg
+ in (array set 3)
+
+> (: array get 18 a3)
+exception error: badarg
+ in (array get 2)
diff --git a/Task/Arrays/Lasso/arrays-1.lasso b/Task/Arrays/Lasso/arrays-1.lasso
new file mode 100644
index 0000000000..3e9e63a3dc
--- /dev/null
+++ b/Task/Arrays/Lasso/arrays-1.lasso
@@ -0,0 +1,33 @@
+// Create a new empty array
+local(array1) = array
+
+// Create an array with 2 members (#myarray->size is 2)
+local(array1) = array('ItemA','ItemB')
+
+// Assign a value to member [2]
+#array1->get(2) = 5
+
+// Retrieve a value from an array
+#array1->get(2) + #array1->size // 8
+
+// Merge arrays
+local(
+ array1 = array('a','b','c'),
+ array2 = array('a','b','c')
+)
+#array1->merge(#array2) // a, b, c, a, b, c
+
+// Sort an array
+#array1->sort // a, a, b, b, c, c
+
+// Remove value by index
+#array1->remove(2) // a, b, b, c, c
+
+// Remove matching items
+#array1->removeall('b') // a, c, c
+
+// Insert item
+#array1->insert('z') // a, c, c, z
+
+// Insert item at specific position
+#array1->insert('0',1) // 0, a, c, c, z
diff --git a/Task/Arrays/Lasso/arrays-2.lasso b/Task/Arrays/Lasso/arrays-2.lasso
new file mode 100644
index 0000000000..03faace747
--- /dev/null
+++ b/Task/Arrays/Lasso/arrays-2.lasso
@@ -0,0 +1,11 @@
+// Create a staticarray containing 5 items
+local(mystaticArray) = staticarray('a','b','c','d','e')
+
+// Retreive an item
+#mystaticArray->get(3) // c
+
+// Set an item
+#mystaticArray->get(3) = 'changed' // a, b, changed, d, e
+
+// Create an empty static array with a length of 32
+local(mystaticArray) = staticarray_join(32,void)
diff --git a/Task/Arrays/Lingo/arrays-1.lingo b/Task/Arrays/Lingo/arrays-1.lingo
new file mode 100644
index 0000000000..d702014b6d
--- /dev/null
+++ b/Task/Arrays/Lingo/arrays-1.lingo
@@ -0,0 +1,15 @@
+a = [1,2] -- or: a = list(1,2)
+put a[2] -- or: put a.getAt(2)
+-- 2
+a.append(3)
+put a
+-- [1, 2, 3]
+a.deleteAt(2)
+put a
+-- [1, 3]
+a[1] = 5 -- or: a.setAt(1, 5)
+put a
+-- [5, 3]
+a.sort()
+put a
+-- [3, 5]
diff --git a/Task/Arrays/Lingo/arrays-2.lingo b/Task/Arrays/Lingo/arrays-2.lingo
new file mode 100644
index 0000000000..291925dcd5
--- /dev/null
+++ b/Task/Arrays/Lingo/arrays-2.lingo
@@ -0,0 +1,11 @@
+ba = bytearray(2, 255) -- initialized with size 2 and filled with 0xff
+put ba
+--
+ba[1] = 1
+ba[2] = 2
+ba[ba.length+1] = 3 -- dynamically increases size
+put ba
+--
+ba[1] = 5
+put ba
+--
diff --git a/Task/Arrays/Monte/arrays-1.monte b/Task/Arrays/Monte/arrays-1.monte
new file mode 100644
index 0000000000..070286da43
--- /dev/null
+++ b/Task/Arrays/Monte/arrays-1.monte
@@ -0,0 +1 @@
+var myArray := ['a', 'b', 'c','d']
diff --git a/Task/Arrays/Monte/arrays-2.monte b/Task/Arrays/Monte/arrays-2.monte
new file mode 100644
index 0000000000..a41f0891d8
--- /dev/null
+++ b/Task/Arrays/Monte/arrays-2.monte
@@ -0,0 +1 @@
+traceln(myArray[0])
diff --git a/Task/Arrays/Monte/arrays-3.monte b/Task/Arrays/Monte/arrays-3.monte
new file mode 100644
index 0000000000..b737b77449
--- /dev/null
+++ b/Task/Arrays/Monte/arrays-3.monte
@@ -0,0 +1 @@
+myArray := myArray.with(3, 'z')
diff --git a/Task/Arrays/Nim/arrays.nim b/Task/Arrays/Nim/arrays.nim
new file mode 100644
index 0000000000..3367079b77
--- /dev/null
+++ b/Task/Arrays/Nim/arrays.nim
@@ -0,0 +1,22 @@
+var # fixed size arrays
+ x = [1,2,3,4,5,6,7,8,9,10] # type and size automatically inferred
+ y: array[1..5, int] = [1,2,3,4,5] # starts at 1 instead of 0
+ z: array['a'..'z', int] # indexed using characters
+
+x[0] = x[1] + 1
+echo x[0]
+echo z['d']
+
+x[7..9] = y[3..5] # copy part of array
+
+var # variable size sequences
+ a = @[1,2,3,4,5,6,7,8,9,10]
+ b: seq[int] = @[1,2,3,4,5]
+
+a[0] = a[1] + 1
+echo a[0]
+
+a.add(b) # append another sequence
+a.add(200) # append another element
+echo a.pop() # pop last item, removing and returning it
+echo a
diff --git a/Task/Arrays/Oforth/arrays.oforth b/Task/Arrays/Oforth/arrays.oforth
new file mode 100644
index 0000000000..0c80c7d547
--- /dev/null
+++ b/Task/Arrays/Oforth/arrays.oforth
@@ -0,0 +1,3 @@
+[ "abd", "def", "ghi" ] at(3) println
+
+ListBuffer new dup addAll([1, 2, 3]) dup put(2, 8.1) println
diff --git a/Task/Arrays/Phix/arrays.phix b/Task/Arrays/Phix/arrays.phix
new file mode 100644
index 0000000000..4cd8a1e932
--- /dev/null
+++ b/Task/Arrays/Phix/arrays.phix
@@ -0,0 +1,74 @@
+-- simple one-dimensional arrays:
+sequence s1 = {0.5, 1, 4.7, 9}, -- length(s1) is now 4
+ s2 = repeat(0,6), -- s2 is {0,0,0,0,0,0}
+ s3 = tagset(5) -- s3 is {1,2,3,4,5}
+
+ ?s1[3] -- displays 4.7 (nb 1-based indexing)
+ s1[3] = 0 -- replace that 4.7
+ s1 &= {5,6} -- length(s1) is now 6 ({0.5,1,0,9,5,6})
+ s1 = s1[2..5] -- length(s1) is now 4 ({1,0,9,5})
+ s1[2..3] = {2,3,4} -- length(s1) is now 5 ({1,2,3,4,5})
+ s1 = append(s1,6) -- length(s1) is now 6 ({1,2,3,4,5,6})
+ s1 = prepend(s1,0) -- length(s1) is now 7 ({0,1,2,3,4,5,6})
+
+-- negative subscripts can also be used, counting from the other end, eg
+ s2[-2..-1] = {-2,-1} -- s2 is now {0,0,0,0,-2,-1}
+
+-- multi dimensional arrays:
+sequence y = {{{1,1},{3,3},{5,5}},
+ {{0,0},{0,1},{9,1}},
+ {{1,7},{1,1},{2,2}}}
+ -- y[2][3][1] is 9
+
+ y = repeat(repeat(repeat(0,2),3),3)
+ -- same structure, but all 0s
+
+-- Array of strings:
+sequence s = {"Hello", "World", "Phix", "", "Last One"}
+ -- s[3] is "Phix"
+ -- s[3][2] is 'h'
+
+-- A Structure:
+sequence employee = {{"John","Smith"},
+ 45000,
+ 27,
+ 185.5}
+
+-- To simplify access to elements within a structure it is good programming style to define constants that name the various fields, eg:
+ constant SALARY = 2
+
+-- Array of structures:
+sequence employees = {
+ {{"Jane","Adams"}, 47000, 34, 135.5}, -- a[1]
+ {{"Bill","Jones"}, 57000, 48, 177.2}, -- a[2]
+ -- .... etc.
+ }
+ -- employees[2][SALARY] is 57000
+
+-- A tree can be represented easily, for example after adding "b","c","a" to it you might have:
+sequence tree = {{"b",3,2},
+ {"c",0,0},
+ {"a",0,0}}
+
+-- ie assuming
+constant ROOT=1, VALUE=1, LEFT=2, RIGHT=3 -- then
+-- tree[ROOT][VALUE] is "b"
+-- tree[ROOT][LEFT] is 3, and tree[3] is the "a"
+-- tree[ROOT][RIGHT] is 2, and tree[2] is the "c"
+
+-- The operations you might use to build such a tree (tests/loops/etc omitted) could be:
+ tree = {}
+ tree = append(tree,{"b",0,0})
+ tree = append(tree,{"c",0,0})
+ tree[1][RIGHT] = length(tree)
+ tree = append(tree,{"a",0,0})
+ tree[1][LEFT] = length(tree)
+
+-- Finally, some tests (recall that we have already output a 4.7):
+?s[3]
+?tree
+?tree[ROOT][VALUE]
+employees = append(employees, employee)
+?employees[3][SALARY]
+?s1
+?s2
diff --git a/Task/Arrays/Pony/arrays.pony b/Task/Arrays/Pony/arrays.pony
new file mode 100644
index 0000000000..b148ddc65a
--- /dev/null
+++ b/Task/Arrays/Pony/arrays.pony
@@ -0,0 +1,13 @@
+var numbers = Array[I32](16) // creating array of 32-bit ints with initial allocation for 16 elements
+numbers.push(10) // add value 10 to the end of array, extending the underlying memory if needed
+try
+ let x = numbers(0) // fetch the first element of array. index starts at 0
+ Fact(x == 10) // try block is needed, because both lines inside it can throw exception
+end
+
+var other: Array[U64] = [10, 20, 30] // array literal
+let s = other.size() // return the number of elements in array
+try
+ Fact(s == 3) // size of array 'other' is 3
+ other(1) = 40 // 'other' now is [10, 40, 30]
+end
diff --git a/Task/Arrays/Ring/arrays.ring b/Task/Arrays/Ring/arrays.ring
new file mode 100644
index 0000000000..3ebb6d49bb
--- /dev/null
+++ b/Task/Arrays/Ring/arrays.ring
@@ -0,0 +1,11 @@
+# create an array with one string in it
+a = ['foo']
+
+# add items
+a + 1 # ["foo", 1]
+
+# set the value at a specific index in the array
+a[1] = 2 # [2, 1]
+
+# retrieve an element
+see a[1]
diff --git a/Task/Arrays/SSEM/arrays.ssem b/Task/Arrays/SSEM/arrays.ssem
new file mode 100644
index 0000000000..5d9b064bff
--- /dev/null
+++ b/Task/Arrays/SSEM/arrays.ssem
@@ -0,0 +1,27 @@
+10101000000000100000000000000000 0. -21 to c
+11101000000000010000000000000000 1. Sub. 23
+00101000000001100000000000000000 2. c to 20
+00101000000000100000000000000000 3. -20 to c
+10101000000001100000000000000000 4. c to 21
+10000000000000100000000000000000 5. -1 to c
+01001000000000010000000000000000 6. Sub. 18
+00101000000001100000000000000000 7. c to 20
+00101000000000100000000000000000 8. -20 to c
+10000000000001100000000000000000 9. c to 1
+01101000000000010000000000000000 10. Sub. 22
+00000000000000110000000000000000 11. Test
+01001000000001000000000000000000 12. Add 18 to CI
+11001000000000000000000000000000 13. 19 to CI
+10101000000000100000000000000000 14. -21 to c
+00101000000001100000000000000000 15. c to 20
+00101000000000100000000000000000 16. -20 to c
+00000000000001110000000000000000 17. Stop
+10000000000000000000000000000000 18. 1
+11111111111111111111111111111111 19. -1
+00000000000000000000000000000000 20. 0
+00000000000000000000000000000000 21. 0
+11011000000000010000000000000000 22. Sub. 27
+10000000000000000000000000000000 23. 1
+01000000000000000000000000000000 24. 2
+11000000000000000000000000000000 25. 3
+00100000000000000000000000000000 26. 4
diff --git a/Task/Arrays/Sidef/arrays.sidef b/Task/Arrays/Sidef/arrays.sidef
new file mode 100644
index 0000000000..c6143bc504
--- /dev/null
+++ b/Task/Arrays/Sidef/arrays.sidef
@@ -0,0 +1,29 @@
+# create an empty array
+var arr = [];
+
+# push objects into the array
+arr << "a"; #: ['a']
+arr.append(1,2,3); #: ['a', 1, 2, 3]
+
+# change an element inside the array
+arr[2] = "b"; #: ['a', 1, 'b', 3]
+
+# set the value at a specific index in the array (with autovivification)
+arr[5] = "end"; #: ['a', 1, 'b', 3, nil, 'end']
+
+# resize the array
+arr.resize_to(-1); #: []
+
+# slice assignment
+arr[0..2] = @|('a'..'c'); #: ['a', 'b', 'c']
+
+# indices as arrays
+var indices = [0, -1];
+arr[indices] = ("foo", "baz"); #: ['foo', 'b', 'baz']
+
+# retrieve multiple elements
+var *elems = arr[0, -1]
+say elems #=> ['foo', 'baz']
+
+# retrieve an element
+say arr[-1]; #=> 'baz'
diff --git a/Task/Arrays/Swift/arrays.swift b/Task/Arrays/Swift/arrays.swift
new file mode 100644
index 0000000000..a33940f0ac
--- /dev/null
+++ b/Task/Arrays/Swift/arrays.swift
@@ -0,0 +1,6 @@
+// Arrays are typed in Swift, however, using the Any object we can add any type. Swift does not support fixed length arrays
+var anyArray = [Any]()
+anyArray.append("foo") // Adding to an Array
+anyArray.append(1) // ["foo", 1]
+anyArray.removeAtIndex(1) // Remove object
+anyArray[0] = "bar" // ["bar"]]
diff --git a/Task/Arrays/Wren/arrays.wren b/Task/Arrays/Wren/arrays.wren
new file mode 100644
index 0000000000..461591a6ea
--- /dev/null
+++ b/Task/Arrays/Wren/arrays.wren
@@ -0,0 +1,14 @@
+var arr = []
+arr.add(1)
+arr.add(2)
+arr.count // 2
+arr.clear()
+
+arr.add(0)
+arr.add(arr[0])
+arr.add(1)
+arr.add(arr[-1]) // [0, 0, 1, 1]
+
+arr[-1] = 0
+arr.insert(-1, 0) // [0, 0, 1, 0, 0]
+arr.removeAt(2) // [0, 0, 0, 0]
diff --git a/Task/Arrays/XLISP/arrays.xlisp b/Task/Arrays/XLISP/arrays.xlisp
new file mode 100644
index 0000000000..ccb45aeed1
--- /dev/null
+++ b/Task/Arrays/XLISP/arrays.xlisp
@@ -0,0 +1,24 @@
+[1] (define a (make-vector 10)) ; vector of 10 elements initialized to the empty list
+
+A
+[2] (define b (make-vector 10 5)) ; vector of 10 elements initialized to 5
+
+B
+[3] (define c #(1 2 3 4 5 6 7 8 9 10)) ; vector literal
+
+C
+[4] (vector-ref c 3) ; retrieve a value -- NB. indexed from 0
+
+4
+[5] (vector-set! a 5 1) ; set a_5 to 1
+
+1
+[6] (define d (make-array 5 6 7)) ; 3-dimensional array of size 5 by 6 by 7
+
+D
+[7] (array-set! d 1 2 3 10) ; set d_1,2,3 to 10 -- NB. still indexed from 0
+
+10
+[8] (array-ref d 1 2 3) ; and get the value of d_1,2,3
+
+10
diff --git a/Task/Arrays/jq/arrays.jq b/Task/Arrays/jq/arrays.jq
new file mode 100644
index 0000000000..d585b64f3a
--- /dev/null
+++ b/Task/Arrays/jq/arrays.jq
@@ -0,0 +1,36 @@
+# Create a new array with length 0
+[]
+
+# Create a new array of 5 nulls
+[][4] = null # setting the element at offset 4 expands the array
+
+# Create an array having the elements 1 and 2 in that order
+[1,2]
+
+# Create an array of integers from 0 to 10 inclusive
+[ range(0; 11) ]
+
+# If a is an array (of any length), update it so that a[2] is 5
+a[2] = 5;
+
+# Append arrays a and b
+a + b
+
+# Append an element, e, to an array a
+a + [e]
+
+##################################################
+# In the following, a is assumed to be [0,1,2,3,4]
+
+# It is not an error to use an out-of-range index:
+a[10] # => null
+
+# Negative indices count backwards from after the last element:
+a[-1] # => 4
+
+# jq supports simple slice operations but
+# only in the forward direction:
+a[:1] # => [0]
+a[1:] # => [1,2,3,4]
+a[2:4] # => [2,3]
+a[4:2] # null
diff --git a/Task/Assertions/Apex/assertions-1.apex b/Task/Assertions/Apex/assertions-1.apex
new file mode 100644
index 0000000000..e6f6e3d791
--- /dev/null
+++ b/Task/Assertions/Apex/assertions-1.apex
@@ -0,0 +1,2 @@
+String myStr = 'test;
+System.assert(myStr == 'something else', 'Assertion Failed Message');
diff --git a/Task/Assertions/Apex/assertions-2.apex b/Task/Assertions/Apex/assertions-2.apex
new file mode 100644
index 0000000000..33d4f9c7c3
--- /dev/null
+++ b/Task/Assertions/Apex/assertions-2.apex
@@ -0,0 +1,2 @@
+Integer i = 5;
+System.assertEquals(6, i, 'Expected 6, received ' + i);
diff --git a/Task/Assertions/Apex/assertions-3.apex b/Task/Assertions/Apex/assertions-3.apex
new file mode 100644
index 0000000000..0f4a3f1dca
--- /dev/null
+++ b/Task/Assertions/Apex/assertions-3.apex
@@ -0,0 +1,2 @@
+Integer i = 5;
+System.assertNotEquals(5, i, 'Expected different value than ' + i);
diff --git a/Task/Assertions/Axe/assertions.axe b/Task/Assertions/Axe/assertions.axe
new file mode 100644
index 0000000000..2ae4a4d152
--- /dev/null
+++ b/Task/Assertions/Axe/assertions.axe
@@ -0,0 +1 @@
+A=42??Returnʳ
diff --git a/Task/Assertions/ECL/assertions.ecl b/Task/Assertions/ECL/assertions.ecl
new file mode 100644
index 0000000000..aa8ca44dba
--- /dev/null
+++ b/Task/Assertions/ECL/assertions.ecl
@@ -0,0 +1 @@
+ASSERT(a = 42,'A is not 42!',FAIL);
diff --git a/Task/Assertions/EchoLisp/assertions.echolisp b/Task/Assertions/EchoLisp/assertions.echolisp
new file mode 100644
index 0000000000..7a4818bf17
--- /dev/null
+++ b/Task/Assertions/EchoLisp/assertions.echolisp
@@ -0,0 +1,9 @@
+(assert (integer? 42)) → #t ;; success returns true
+
+;; error and return to top level if not true;
+(assert (integer? 'quarante-deux))
+⛔ error: assert : assertion failed : (#integer? 'quarante-deux)
+
+;; assertion with message (optional)
+(assert (integer? 'quarante-deux) "☝️ expression must evaluate to the integer 42")
+💥 error: ☝️ expression must evaluate to the integer 42 : assertion failed : (#integer? 'quarante-deux)
diff --git a/Task/Assertions/FreeBASIC/assertions.freebasic b/Task/Assertions/FreeBASIC/assertions.freebasic
new file mode 100644
index 0000000000..9795d3b854
--- /dev/null
+++ b/Task/Assertions/FreeBASIC/assertions.freebasic
@@ -0,0 +1,8 @@
+' FB 1.05.0 Win64
+' requires compilation with -g switch
+
+Dim a As Integer = 5
+Assert(a = 6)
+'The rest of the code will not be executed
+Print a
+Sleep
diff --git a/Task/Assertions/Lasso/assertions.lasso b/Task/Assertions/Lasso/assertions.lasso
new file mode 100644
index 0000000000..3d9b0f547a
--- /dev/null
+++ b/Task/Assertions/Lasso/assertions.lasso
@@ -0,0 +1,6 @@
+local(a) = 8
+fail_if(
+ #a != 42,
+ error_code_runtimeAssertion,
+ error_msg_runtimeAssertion + ": #a is not 42"
+)
diff --git a/Task/Assertions/Lingo/assertions.lingo b/Task/Assertions/Lingo/assertions.lingo
new file mode 100644
index 0000000000..5b1ad2a933
--- /dev/null
+++ b/Task/Assertions/Lingo/assertions.lingo
@@ -0,0 +1,17 @@
+-- in a movie script
+on assert (ok, message)
+ if not ok then
+ if not voidP(message) then _player.alert(message)
+ abort -- exits from current call stack, i.e. also from the caller function
+ end if
+end
+
+-- anywhere in the code
+on test
+ x = 42
+ assert(x=42, "Assertion 'x=42' failed")
+ put "this shows up"
+ x = 23
+ assert(x=42, "Assertion 'x=42' failed")
+ put "this will never show up"
+end
diff --git a/Task/Assertions/Nim/assertions.nim b/Task/Assertions/Nim/assertions.nim
new file mode 100644
index 0000000000..541f20f9c9
--- /dev/null
+++ b/Task/Assertions/Nim/assertions.nim
@@ -0,0 +1,2 @@
+var a = 42
+assert(a == 42)
diff --git a/Task/Assertions/Oforth/assertions.oforth b/Task/Assertions/Oforth/assertions.oforth
new file mode 100644
index 0000000000..1575ca1313
--- /dev/null
+++ b/Task/Assertions/Oforth/assertions.oforth
@@ -0,0 +1,5 @@
+: testInteger(n, m)
+ assert: [ n isInteger ]
+ assert: [ n 42 == ]
+
+ System.Out "Assertions are ok, parameters are : " << n << ", " << m << cr ;
diff --git a/Task/Assertions/Phix/assertions-1.phix b/Task/Assertions/Phix/assertions-1.phix
new file mode 100644
index 0000000000..b74e126c0f
--- /dev/null
+++ b/Task/Assertions/Phix/assertions-1.phix
@@ -0,0 +1,7 @@
+type int42(object i)
+ return i=42
+end type
+
+int42 i
+
+i = 41 -- type-check failure
diff --git a/Task/Assertions/Phix/assertions-2.phix b/Task/Assertions/Phix/assertions-2.phix
new file mode 100644
index 0000000000..170487b290
--- /dev/null
+++ b/Task/Assertions/Phix/assertions-2.phix
@@ -0,0 +1,13 @@
+global constant DEBUG = 0 -- (or any other identifier name can be used)
+global procedure assert(integer flag, string msg)
+ if DEBUG then
+ if not flag then
+ {} = message_box(msg,"failed assertion",MB_OK) -- or
+ puts(1,msg) -- , and/or
+ crash(msg) -- crash/ex.err report -- or
+ trace(1) -- start debugging
+ end if
+ end if
+end function
+
+assert(i=42,"i is not 42!!")
diff --git a/Task/Assertions/Phix/assertions-3.phix b/Task/Assertions/Phix/assertions-3.phix
new file mode 100644
index 0000000000..3ff4946042
--- /dev/null
+++ b/Task/Assertions/Phix/assertions-3.phix
@@ -0,0 +1,2 @@
+if i!=42 then ?9/0 end if
+if i!=42 then crash("i is not 42!!") end if
diff --git a/Task/Assertions/Ring/assertions.ring b/Task/Assertions/Ring/assertions.ring
new file mode 100644
index 0000000000..e47bc51303
--- /dev/null
+++ b/Task/Assertions/Ring/assertions.ring
@@ -0,0 +1,3 @@
+x = 42
+assert( x = 42 )
+assert( x = 100 )
diff --git a/Task/Assertions/Sidef/assertions.sidef b/Task/Assertions/Sidef/assertions.sidef
new file mode 100644
index 0000000000..826113d16a
--- /dev/null
+++ b/Task/Assertions/Sidef/assertions.sidef
@@ -0,0 +1,2 @@
+var num = pick(0..100);
+assert_eq(num, 42); # dies when "num" is not 42
diff --git a/Task/Assertions/Swift/assertions.swift b/Task/Assertions/Swift/assertions.swift
new file mode 100644
index 0000000000..57627959ca
--- /dev/null
+++ b/Task/Assertions/Swift/assertions.swift
@@ -0,0 +1,6 @@
+var a = 5
+//...input or change a here
+assert(a == 42) // aborts program when a is not 42
+assert(a == 42, "Error message") // aborts program
+ // when a is not 42 with "Error message" for the message
+ // the error message must be a static string
diff --git a/Task/Associative-array-Creation/Apex/associative-array-creation-1.apex b/Task/Associative-array-Creation/Apex/associative-array-creation-1.apex
new file mode 100644
index 0000000000..2d79b1db73
--- /dev/null
+++ b/Task/Associative-array-Creation/Apex/associative-array-creation-1.apex
@@ -0,0 +1,9 @@
+// Cannot / Do not need to instantiate the algorithm implementation (e.g, HashMap).
+Map strMap = new Map();
+strMap.put('a', 'aval');
+strMap.put('b', 'bval');
+
+System.assert( strMap.containsKey('a') );
+System.assertEquals( 'bval', strMap.get('b') );
+// String keys are case-sensitive
+System.assert( !strMap.containsKey('A') );
diff --git a/Task/Associative-array-Creation/Apex/associative-array-creation-2.apex b/Task/Associative-array-Creation/Apex/associative-array-creation-2.apex
new file mode 100644
index 0000000000..4173304650
--- /dev/null
+++ b/Task/Associative-array-Creation/Apex/associative-array-creation-2.apex
@@ -0,0 +1,7 @@
+Map strMap = new Map{
+ 'a' => 'aval',
+ 'b' => 'bval'
+};
+
+System.assert( strMap.containsKey('a') );
+System.assertEquals( 'bval', strMap.get('b') );
diff --git a/Task/Associative-array-Creation/Ceylon/associative-array-creation.ceylon b/Task/Associative-array-Creation/Ceylon/associative-array-creation.ceylon
new file mode 100644
index 0000000000..90797a27f4
--- /dev/null
+++ b/Task/Associative-array-Creation/Ceylon/associative-array-creation.ceylon
@@ -0,0 +1,36 @@
+import ceylon.collection {
+
+ ArrayList,
+ HashMap,
+ naturalOrderTreeMap
+}
+
+shared void run() {
+
+ // the easiest way is to use the map function to create
+ // an immutable map
+ value myMap = map {
+ "foo" -> 5,
+ "bar" -> 10,
+ "baz" -> 15,
+ "foo" -> 6 // by default the first "foo" will remain
+ };
+
+ // or you can use the HashMap constructor to create
+ // a mutable one
+ value myOtherMap = HashMap {
+ "foo"->"bar"
+ };
+ myOtherMap.put("baz", "baxx");
+
+ // there's also a sorted red/black tree map
+ value myTreeMap = naturalOrderTreeMap {
+ 1 -> "won",
+ 2 -> "too",
+ 4 -> "fore"
+ };
+ for(num->homophone in myTreeMap) {
+ print("``num`` is ``homophone``");
+ }
+
+}
diff --git a/Task/Associative-array-Creation/EchoLisp/associative-array-creation.echolisp b/Task/Associative-array-Creation/EchoLisp/associative-array-creation.echolisp
new file mode 100644
index 0000000000..1743774e89
--- /dev/null
+++ b/Task/Associative-array-Creation/EchoLisp/associative-array-creation.echolisp
@@ -0,0 +1,18 @@
+(lib 'hash) ;; needs hash.lib
+(define H (make-hash)) ;; new hash table
+;; keys may be symbols, numbers, strings ..
+;; values may be any lisp object
+(hash-set H 'simon 'antoniette)
+ → antoniette
+(hash-set H 'antoinette 'albert)
+ → albert
+(hash-set H "Elvis" 42)
+ → 42
+(hash-ref H 'Elvis)
+ → #f ;; not found. Elvis is not "Elvis"
+(hash-ref H "Elvis")
+ → 42
+(hash-ref H 'simon)
+ → antoniette
+(hash-count H)
+ → 3
diff --git a/Task/Associative-array-Creation/Harbour/associative-array-creation-1.harbour b/Task/Associative-array-Creation/Harbour/associative-array-creation-1.harbour
new file mode 100644
index 0000000000..243fc14571
--- /dev/null
+++ b/Task/Associative-array-Creation/Harbour/associative-array-creation-1.harbour
@@ -0,0 +1,3 @@
+arr := { => }
+arr[ 10 ] := "Val_10"
+arr[ "foo" ] := "foovalue"
diff --git a/Task/Associative-array-Creation/Harbour/associative-array-creation-2.harbour b/Task/Associative-array-Creation/Harbour/associative-array-creation-2.harbour
new file mode 100644
index 0000000000..2d1ae01881
--- /dev/null
+++ b/Task/Associative-array-Creation/Harbour/associative-array-creation-2.harbour
@@ -0,0 +1,3 @@
+arr := hb_Hash( 10, "Val_10", "foo", "foovalue" )
+// or
+arr := { 10 => "Val_10", "foo" => "foovalue" }
diff --git a/Task/Associative-array-Creation/LFE/associative-array-creation.lfe b/Task/Associative-array-Creation/LFE/associative-array-creation.lfe
new file mode 100644
index 0000000000..6a79d6a51b
--- /dev/null
+++ b/Task/Associative-array-Creation/LFE/associative-array-creation.lfe
@@ -0,0 +1,5 @@
+(let* ((my-dict (: dict new))
+ (my-dict (: dict store 'key-1 '"value 1" my-dict))
+ (my-dict (: dict store 'key-2 '"value 2" my-dict)))
+ (: io format '"size: ~p~n" (list (: dict size my-dict)))
+ (: io format '"some data: ~p~n" (list (: dict fetch 'key-1 my-dict))))
diff --git a/Task/Associative-array-Creation/Lasso/associative-array-creation.lasso b/Task/Associative-array-Creation/Lasso/associative-array-creation.lasso
new file mode 100644
index 0000000000..3f09055ecd
--- /dev/null
+++ b/Task/Associative-array-Creation/Lasso/associative-array-creation.lasso
@@ -0,0 +1,38 @@
+// In Lasso associative arrays are called maps
+
+// Define an empty map
+local(mymap = map)
+
+// Define a map with content
+local(mymap = map(
+ 'one' = 'Monday',
+ '2' = 'Tuesday',
+ 3 = 'Wednesday'
+))
+
+// add elements to an existing map
+#mymap -> insert('fourth' = 'Thursday')
+
+// retrieve a value from a map
+#mymap -> find('2') // Tuesday
+'
'
+#mymap -> find(3) // Wednesday, found by the key not the position
+'
'
+
+// Get all keys from a map
+#mymap -> keys // staticarray(2, fourth, one, 3)
+'
'
+
+// Iterate thru a map and get values
+with v in #mymap do {^
+ #v
+ '
'
+^}
+// Tuesday
Thursday
Monday
Wednesday
+
+// Perform actions on each value of a map
+#mymap -> foreach => {
+ #1 -> uppercase
+ #1 -> reverse
+}
+#mymap // map(2 = YADSEUT, fourth = YADSRUHT, one = YADNOM, 3 = YADSENDEW)
diff --git a/Task/Associative-array-Creation/Lingo/associative-array-creation.lingo b/Task/Associative-array-Creation/Lingo/associative-array-creation.lingo
new file mode 100644
index 0000000000..d7ff7a8b49
--- /dev/null
+++ b/Task/Associative-array-Creation/Lingo/associative-array-creation.lingo
@@ -0,0 +1,10 @@
+props = [#key1: "value1", #key2: "value2"]
+
+put props[#key2]
+-- "value2"
+put props["key2"]
+-- "value2"
+put props.key2
+-- "value2"
+put props.getProp(#key2)
+-- "value2"
diff --git a/Task/Associative-array-Creation/LiveCode/associative-array-creation-1.livecode b/Task/Associative-array-Creation/LiveCode/associative-array-creation-1.livecode
new file mode 100644
index 0000000000..897c8ed6a0
--- /dev/null
+++ b/Task/Associative-array-Creation/LiveCode/associative-array-creation-1.livecode
@@ -0,0 +1,10 @@
+command assocArray
+ local tArray
+ put "value 1" into tArray["key 1"]
+ put 123 into tArray["key numbers"]
+ put "a,b,c" into tArray["abc"]
+
+ put "number of elements:" && the number of elements of tArray & return & \
+ "length of item 3:" && the length of tArray["abc"] & return & \
+ "keys:" && the keys of tArray
+end assocArray
diff --git a/Task/Associative-array-Creation/LiveCode/associative-array-creation-2.livecode b/Task/Associative-array-Creation/LiveCode/associative-array-creation-2.livecode
new file mode 100644
index 0000000000..66149e2bc0
--- /dev/null
+++ b/Task/Associative-array-Creation/LiveCode/associative-array-creation-2.livecode
@@ -0,0 +1,5 @@
+number of elements: 3
+length of item 3: 5
+keys: key numbers
+abc
+key 1
diff --git a/Task/Associative-array-Creation/Nim/associative-array-creation.nim b/Task/Associative-array-Creation/Nim/associative-array-creation.nim
new file mode 100644
index 0000000000..641303de27
--- /dev/null
+++ b/Task/Associative-array-Creation/Nim/associative-array-creation.nim
@@ -0,0 +1,28 @@
+import tables
+
+var
+ hash = initTable[string, int]() # empty hash table
+ hash2 = {"key1": 1, "key2": 2}.toTable # hash table with two keys
+ hash3 = [("key1", 1), ("key2", 2)].toTable # hash table from tuple array
+ hash4 = @[("key1", 1), ("key2", 2)].toTable # hash table from tuple seq
+ value = hash2["key1"]
+
+hash["spam"] = 1
+hash["eggs"] = 2
+hash.add("foo", 3)
+
+echo "hash has ", hash.len, " elements"
+echo "hash has key foo? ", hash.hasKey("foo")
+echo "hash has key bar? ", hash.hasKey("bar")
+
+echo "iterate pairs:" # iterating over (key, value) pairs
+for key, value in hash:
+ echo key, ": ", value
+
+echo "iterate keys:" # iterating over keys
+for key in hash.keys:
+ echo key
+
+echo "iterate values:" # iterating over values
+for key in hash.values:
+ echo key
diff --git a/Task/Associative-array-Creation/Phix/associative-array-creation.phix b/Task/Associative-array-Creation/Phix/associative-array-creation.phix
new file mode 100644
index 0000000000..455672dfc6
--- /dev/null
+++ b/Task/Associative-array-Creation/Phix/associative-array-creation.phix
@@ -0,0 +1,8 @@
+setd("one",1)
+setd(2,"duo")
+setd({3,4},{5,"six"})
+?getd("one") -- shows 1
+?getd({3,4}) -- shows {5,"six"}
+?getd(2) -- shows "duo"
+deld(2)
+?getd(2) -- shows 0
diff --git a/Task/Associative-array-Creation/Potion/associative-array-creation.potion b/Task/Associative-array-Creation/Potion/associative-array-creation.potion
new file mode 100644
index 0000000000..ee74f37eba
--- /dev/null
+++ b/Task/Associative-array-Creation/Potion/associative-array-creation.potion
@@ -0,0 +1,8 @@
+mydictionary = (red=0xff0000, green=0x00ff00, blue=0x0000ff)
+
+redblue = "purple"
+mydictionary put(redblue, 0xff00ff)
+
+255 == mydictionary("blue")
+65280 == mydictionary("green")
+16711935 == mydictionary("purple")
diff --git a/Task/Associative-array-Creation/Sidef/associative-array-creation.sidef b/Task/Associative-array-Creation/Sidef/associative-array-creation.sidef
new file mode 100644
index 0000000000..34cb21492b
--- /dev/null
+++ b/Task/Associative-array-Creation/Sidef/associative-array-creation.sidef
@@ -0,0 +1,7 @@
+var hash = Hash.new(
+ key1 => 'value1',
+ key2 => 'value2',
+);
+
+# Add a new key-value pair
+hash{:key3} = 'value3';
diff --git a/Task/Associative-array-Creation/Swift/associative-array-creation.swift b/Task/Associative-array-Creation/Swift/associative-array-creation.swift
new file mode 100644
index 0000000000..c2d8497cc3
--- /dev/null
+++ b/Task/Associative-array-Creation/Swift/associative-array-creation.swift
@@ -0,0 +1,13 @@
+// make an empty map
+var a = [String: Int]()
+// or
+var b: [String: Int] = [:]
+
+// make an empty map with an initial capacity
+var c = [String: Int](minimumCapacity: 42)
+
+// set a value
+c["foo"] = 3
+
+// make a map with a literal
+var d = ["foo": 2, "bar": 42, "baz": -1]
diff --git a/Task/Associative-array-Creation/Visual-FoxPro/associative-array-creation.visual b/Task/Associative-array-Creation/Visual-FoxPro/associative-array-creation.visual
new file mode 100644
index 0000000000..3689e0dbca
--- /dev/null
+++ b/Task/Associative-array-Creation/Visual-FoxPro/associative-array-creation.visual
@@ -0,0 +1,39 @@
+LOCAL loCol As Collection, k, n, o
+CLEAR
+*!* Example using strings
+loCol = NEWOBJECT("Collection")
+loCol.Add("Apples", "A")
+loCol.Add("Oranges", "O")
+loCol.Add("Pears", "P")
+n = loCol.Count
+? "Items:", n
+*!* Loop through the collection
+k = 1
+FOR EACH o IN loCol FOXOBJECT
+ ? o, loCol.GetKey(k)
+ k = k + 1
+ENDFOR
+*!* Get an item by its key
+? loCol("O")
+?
+*!* Example using objects
+LOCAL loFruits As Collection
+loFruits = NEWOBJECT("Collection")
+loFruits.Add(CREATEOBJECT("fruit", "Apples"), "A")
+loFruits.Add(CREATEOBJECT("fruit", "Oranges"), "O")
+loFruits.Add(CREATEOBJECT("fruit", "Pears"), "P")
+*!* Loop through the collection
+k = 1
+FOR EACH o IN loFruits FOXOBJECT
+ ? o.Name, loFruits.GetKey(k)
+ k = k + 1
+ENDFOR
+*!* Get an item name by its key
+? loFruits("P").Name
+
+
+DEFINE CLASS fruit As Custom
+PROCEDURE Init(tcName As String)
+THIS.Name = tcName
+ENDPROC
+ENDDEFINE
diff --git a/Task/Associative-array-Creation/Wart/associative-array-creation.wart b/Task/Associative-array-Creation/Wart/associative-array-creation.wart
new file mode 100644
index 0000000000..82b87e120e
--- /dev/null
+++ b/Task/Associative-array-Creation/Wart/associative-array-creation.wart
@@ -0,0 +1,3 @@
+h <- (table 'a 1 'b 2)
+h 'a
+=> 1
diff --git a/Task/Associative-array-Creation/XLISP/associative-array-creation-1.xlisp b/Task/Associative-array-Creation/XLISP/associative-array-creation-1.xlisp
new file mode 100644
index 0000000000..36a36d8c56
--- /dev/null
+++ b/Task/Associative-array-Creation/XLISP/associative-array-creation-1.xlisp
@@ -0,0 +1 @@
+(define starlings (make-table))
diff --git a/Task/Associative-array-Creation/XLISP/associative-array-creation-2.xlisp b/Task/Associative-array-Creation/XLISP/associative-array-creation-2.xlisp
new file mode 100644
index 0000000000..62732864da
--- /dev/null
+++ b/Task/Associative-array-Creation/XLISP/associative-array-creation-2.xlisp
@@ -0,0 +1,3 @@
+(table-set! starlings "Common starling" "Sturnus vulgaris")
+(table-set! starlings "Abbot's starling" "Poeoptera femoralis")
+(table-set! starlings "Cape starling" "Lamprotornis nitens")
diff --git a/Task/Associative-array-Creation/XLISP/associative-array-creation-3.xlisp b/Task/Associative-array-Creation/XLISP/associative-array-creation-3.xlisp
new file mode 100644
index 0000000000..6105b17044
--- /dev/null
+++ b/Task/Associative-array-Creation/XLISP/associative-array-creation-3.xlisp
@@ -0,0 +1 @@
+(table-ref starlings "Cape starling")
diff --git a/Task/Associative-array-Creation/XLISP/associative-array-creation-4.xlisp b/Task/Associative-array-Creation/XLISP/associative-array-creation-4.xlisp
new file mode 100644
index 0000000000..70463bf3d9
--- /dev/null
+++ b/Task/Associative-array-Creation/XLISP/associative-array-creation-4.xlisp
@@ -0,0 +1 @@
+(map-over-table-entries starlings (lambda (x y) (print (string-append x " (Linnaean name " y ")"))))
diff --git a/Task/Associative-array-Creation/jq/associative-array-creation-1.jq b/Task/Associative-array-Creation/jq/associative-array-creation-1.jq
new file mode 100644
index 0000000000..ed83953c9a
--- /dev/null
+++ b/Task/Associative-array-Creation/jq/associative-array-creation-1.jq
@@ -0,0 +1,22 @@
+# An empty object:
+{}
+
+# Its type:
+{} | type
+# "object"
+
+# An object literal:
+{"a": 97, "b" : 98}
+
+# Programmatic object construction:
+reduce ("a", "b", "c", "d") as $c ({}; . + { ($c) : ($c|explode[.0])} )
+# {"a":97,"c":99,"b":98,"d":100}
+
+# Same as above:
+reduce range (97;101) as $i ({}; . + { ([$i]|implode) : $i })
+
+# Addition of a key/value pair by assignment:
+{}["A"] = 65 # in this case, the object being added to is {}
+
+# Alteration of the value of an existing key:
+{"A": 65}["A"] = "AA"
diff --git a/Task/Associative-array-Creation/jq/associative-array-creation-2.jq b/Task/Associative-array-Creation/jq/associative-array-creation-2.jq
new file mode 100644
index 0000000000..cc70ab5429
--- /dev/null
+++ b/Task/Associative-array-Creation/jq/associative-array-creation-2.jq
@@ -0,0 +1,15 @@
+def collisionless:
+ if type == "object" then with_entries(.value = (.value|collisionless))|tostring
+ elif type == "array" then map(collisionless)|tostring
+ else (type[0:1] + tostring)
+ end;
+
+# WARNING: addKey(key;value) will erase any previous value associated with key
+def addKey(key;value):
+ if type == "object" then . + { (key|collisionless): value }
+ else {} | addKey(key;value)
+ end;
+
+def getKey(key): .[key|collisionless];
+
+def removeKey(key): delpaths( [ [key|collisionless] ] );
diff --git a/Task/Associative-array-Creation/jq/associative-array-creation-3.jq b/Task/Associative-array-Creation/jq/associative-array-creation-3.jq
new file mode 100644
index 0000000000..d12ec798c5
--- /dev/null
+++ b/Task/Associative-array-Creation/jq/associative-array-creation-3.jq
@@ -0,0 +1 @@
+{} | addKey(1;"one") | addKey(2; "two") | removeKey(1) | getKey(2)
diff --git a/Task/Associative-array-Creation/jq/associative-array-creation-4.jq b/Task/Associative-array-Creation/jq/associative-array-creation-4.jq
new file mode 100644
index 0000000000..65693f7cff
--- /dev/null
+++ b/Task/Associative-array-Creation/jq/associative-array-creation-4.jq
@@ -0,0 +1 @@
+"two"
diff --git a/Task/Associative-array-Iteration/Ceylon/associative-array-iteration.ceylon b/Task/Associative-array-Iteration/Ceylon/associative-array-iteration.ceylon
new file mode 100644
index 0000000000..e30e624b0f
--- /dev/null
+++ b/Task/Associative-array-Iteration/Ceylon/associative-array-iteration.ceylon
@@ -0,0 +1,21 @@
+shared void run() {
+
+ value myMap = map {
+ "foo" -> 5,
+ "bar" -> 10,
+ "baz" -> 15
+ };
+
+ for(key in myMap.keys) {
+ print(key);
+ }
+
+ for(item in myMap.items) {
+ print(item);
+ }
+
+ for(key->item in myMap) {
+ print("``key`` maps to ``item``");
+ }
+
+}
diff --git a/Task/Associative-array-Iteration/EchoLisp/associative-array-iteration.echolisp b/Task/Associative-array-Iteration/EchoLisp/associative-array-iteration.echolisp
new file mode 100644
index 0000000000..dcd1c25098
--- /dev/null
+++ b/Task/Associative-array-Iteration/EchoLisp/associative-array-iteration.echolisp
@@ -0,0 +1,24 @@
+(lib 'hash) ;; load hash.lib
+(define H (make-hash))
+;; fill hash table
+(hash-set H 'Simon 42)
+(hash-set H 'Albert 666)
+(hash-set H 'Antoinette 33)
+
+;; iterate over (key . value ) pairs
+(for ([kv H]) (writeln kv))
+(Simon . 42)
+(Albert . 666)
+(Antoinette . 33)
+
+;; iterate over keys
+(for ([k (hash-keys H)]) (writeln 'key-> k))
+key-> Simon
+key-> Albert
+key-> Antoinette
+
+;; iterate over values
+(for ([v (hash-values H)]) (writeln 'value-> v))
+value-> 42
+value-> 666
+value-> 33
diff --git a/Task/Associative-array-Iteration/Harbour/associative-array-iteration.harbour b/Task/Associative-array-Iteration/Harbour/associative-array-iteration.harbour
new file mode 100644
index 0000000000..39465740ab
--- /dev/null
+++ b/Task/Associative-array-Iteration/Harbour/associative-array-iteration.harbour
@@ -0,0 +1,11 @@
+LOCAL arr := { 6 => 16, "eight" => 8, "eleven" => 11 }
+LOCAL x
+
+FOR EACH x IN arr
+ // key, value
+ ? x:__enumKey(), x
+ // or key only
+ ? x:__enumKey()
+ // or value only
+ ? x
+NEXT
diff --git a/Task/Associative-array-Iteration/LFE/associative-array-iteration-1.lfe b/Task/Associative-array-Iteration/LFE/associative-array-iteration-1.lfe
new file mode 100644
index 0000000000..6920c890d1
--- /dev/null
+++ b/Task/Associative-array-Iteration/LFE/associative-array-iteration-1.lfe
@@ -0,0 +1,7 @@
+(let ((data '(#(key1 "foo") #(key2 "bar")))
+ (hash (: dict from_list data)))
+ (: dict fold
+ (lambda (key val accum)
+ (: io format '"~s: ~s~n" (list key val)))
+ 0
+ hash))
diff --git a/Task/Associative-array-Iteration/LFE/associative-array-iteration-2.lfe b/Task/Associative-array-Iteration/LFE/associative-array-iteration-2.lfe
new file mode 100644
index 0000000000..70f9e08009
--- /dev/null
+++ b/Task/Associative-array-Iteration/LFE/associative-array-iteration-2.lfe
@@ -0,0 +1,6 @@
+(let ((data '(#(key1 "foo") #(key2 "bar")))
+ (hash (: dict from_list data)))
+ (: lists map
+ (lambda (key)
+ (: io format '"~s~n" (list key)))
+ (: dict fetch_keys hash)))
diff --git a/Task/Associative-array-Iteration/Lasso/associative-array-iteration.lasso b/Task/Associative-array-Iteration/Lasso/associative-array-iteration.lasso
new file mode 100644
index 0000000000..32aba5661c
--- /dev/null
+++ b/Task/Associative-array-Iteration/Lasso/associative-array-iteration.lasso
@@ -0,0 +1,29 @@
+//iterate over associative array
+//Lasso maps
+ local('aMap' = map('weight' = 112,
+ 'height' = 45,
+ 'name' = 'jason'))
+ ' Map output: \n '
+ #aMap->forEachPair => {^
+ //display pair, then show accessing key and value individually
+ #1+'\n '
+ #1->first+': '+#1->second+'\n '
+ ^}
+ //display keys and values separately
+ '\n'
+ ' Map Keys: '+#aMap->keys->join(',')+'\n'
+ ' Map values: '+#aMap->values->join(',')+'\n'
+
+ //display using forEach
+ '\n'
+ ' Use ForEach to iterate Map keys: \n'
+ #aMap->keys->forEach => {^
+ #1+'\n'
+ ^}
+ '\n'
+ ' Use ForEach to iterate Map values: \n'
+ #aMap->values->forEach => {^
+ #1+'\n'
+ ^}
+ //the {^ ^} indicates that output should be printed (AutoCollect) ,
+ // if output is not desired, just { } is used
diff --git a/Task/Associative-array-Iteration/Lingo/associative-array-iteration.lingo b/Task/Associative-array-Iteration/Lingo/associative-array-iteration.lingo
new file mode 100644
index 0000000000..28a5a2c43c
--- /dev/null
+++ b/Task/Associative-array-Iteration/Lingo/associative-array-iteration.lingo
@@ -0,0 +1,11 @@
+hash = [#key1:"value1", #key2:"value2", #key3:"value3"]
+
+-- iterate over key-value pairs
+repeat with i = 1 to hash.count
+ put hash.getPropAt(i) & "=" & hash[i]
+end repeat
+
+-- iterating over values only can be written shorter
+repeat with val in hash
+ put val
+end repeat
diff --git a/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-1.livecode b/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-1.livecode
new file mode 100644
index 0000000000..8f53a80f24
--- /dev/null
+++ b/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-1.livecode
@@ -0,0 +1,24 @@
+put 3 into fruit["apples"]
+put 5 into fruit["pears"]
+put 6 into fruit["oranges"]
+put "none" into fruit["bananas"]
+
+put "Keys:" & cr & the keys of fruit & cr into tTmp
+put "Values 1:" & tab after tTmp
+repeat for each line tKey in the keys of fruit
+ put fruit[tkey] & comma after tTmp
+end repeat
+
+-- need to copy array as combine will change variable
+put fruit into fruit2
+combine fruit2 using comma
+put cr & "Values2:" & tab after tTmp
+repeat for each item f2val in fruit2
+ put f2val & comma after tTmp
+end repeat
+
+combine fruit using return and ":"
+put cr & "Key:Values" & cr & fruit after tTmp
+-- alternatively, use same loop as for values 1 with tkey && fruit[tKey]
+
+put tTmp
diff --git a/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-2.livecode b/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-2.livecode
new file mode 100644
index 0000000000..5914a8c56f
--- /dev/null
+++ b/Task/Associative-array-Iteration/LiveCode/associative-array-iteration-2.livecode
@@ -0,0 +1,12 @@
+Keys:
+apples
+pears
+oranges
+bananas
+Values 1: 3,5,6,none,
+Values2: 3,none,6,5,
+Key:Values
+apples:3
+bananas:none
+oranges:6
+pears:5
diff --git a/Task/Associative-array-Iteration/Nim/associative-array-iteration.nim b/Task/Associative-array-Iteration/Nim/associative-array-iteration.nim
new file mode 100644
index 0000000000..052b5413d5
--- /dev/null
+++ b/Task/Associative-array-Iteration/Nim/associative-array-iteration.nim
@@ -0,0 +1,23 @@
+import tables
+
+var t: TTable[int,string] = initTable[int,string]()
+
+t[1] = "one"
+t[2] = "two"
+t[3] = "three"
+t.add(4,"four")
+
+echo "t has " & $t.len & " elements"
+
+echo "has t key 4? " & $t.hasKey(4)
+echo "has t key 5? " & $t.hasKey(5)
+
+#iterate keys
+echo "key iteration:"
+for k in t.keys:
+ echo "at[" & $k & "]=" & t[k]
+
+#itetate pairs
+echo "pair iteration:"
+for k,v in t.pairs:
+ echo "at[" & $k & "]=" & v
diff --git a/Task/Associative-array-Iteration/Phix/associative-array-iteration-1.phix b/Task/Associative-array-Iteration/Phix/associative-array-iteration-1.phix
new file mode 100644
index 0000000000..8013c48ad7
--- /dev/null
+++ b/Task/Associative-array-Iteration/Phix/associative-array-iteration-1.phix
@@ -0,0 +1,9 @@
+setd("one",1)
+setd(2,"duo")
+setd({3,4},{5,"six"})
+
+function visitor(object key, object data, object /*userdata*/)
+ ?{key,data}
+ return 1 -- (continue traversal)
+end function
+traverse_dict(routine_id("visitor"))
diff --git a/Task/Associative-array-Iteration/Phix/associative-array-iteration-2.phix b/Task/Associative-array-Iteration/Phix/associative-array-iteration-2.phix
new file mode 100644
index 0000000000..b353296475
--- /dev/null
+++ b/Task/Associative-array-Iteration/Phix/associative-array-iteration-2.phix
@@ -0,0 +1,4 @@
+include builtins\map.e
+?pairs()
+?keys()
+?values()
diff --git a/Task/Associative-array-Iteration/Potion/associative-array-iteration.potion b/Task/Associative-array-Iteration/Potion/associative-array-iteration.potion
new file mode 100644
index 0000000000..de7d5d9459
--- /dev/null
+++ b/Task/Associative-array-Iteration/Potion/associative-array-iteration.potion
@@ -0,0 +1,4 @@
+mydictionary = (red=0xff0000, green=0x00ff00, blue=0x0000ff)
+
+mydictionary each (key, val): (key, ":", val, "\n") join print.
+mydictionary each (key): (key, "\n") join print.
diff --git a/Task/Associative-array-Iteration/Sidef/associative-array-iteration.sidef b/Task/Associative-array-Iteration/Sidef/associative-array-iteration.sidef
new file mode 100644
index 0000000000..09f5304311
--- /dev/null
+++ b/Task/Associative-array-Iteration/Sidef/associative-array-iteration.sidef
@@ -0,0 +1,19 @@
+var hash = Hash.new(
+ key1 => 'value1',
+ key2 => 'value2',
+)
+
+# Iterate over key-value pairs
+hash.each { |key, value|
+ say "#{key}: #{value}";
+}
+
+# Iterate only over keys
+hash.keys.each { |key|
+ say key;
+}
+
+# Iterate only over values
+hash.values.each { |value|
+ say value;
+}
diff --git a/Task/Associative-array-Iteration/Swift/associative-array-iteration.swift b/Task/Associative-array-Iteration/Swift/associative-array-iteration.swift
new file mode 100644
index 0000000000..ae4987f597
--- /dev/null
+++ b/Task/Associative-array-Iteration/Swift/associative-array-iteration.swift
@@ -0,0 +1,9 @@
+let myMap = [
+ "hello": 13,
+ "world": 31,
+ "!" : 71 ]
+
+// iterating over key-value pairs:
+for (key, value) in myMap {
+ println("key = \(key), value = \(value)")
+}
diff --git a/Task/Associative-array-Iteration/Wart/associative-array-iteration.wart b/Task/Associative-array-Iteration/Wart/associative-array-iteration.wart
new file mode 100644
index 0000000000..fd808e1a1c
--- /dev/null
+++ b/Task/Associative-array-Iteration/Wart/associative-array-iteration.wart
@@ -0,0 +1,3 @@
+h <- (table 'a 1 'b 2)
+each (key val) table
+ prn key " " val
diff --git a/Task/Atomic-updates/Lasso/atomic-updates.lasso b/Task/Atomic-updates/Lasso/atomic-updates.lasso
new file mode 100644
index 0000000000..d5290a32f8
--- /dev/null
+++ b/Task/Atomic-updates/Lasso/atomic-updates.lasso
@@ -0,0 +1,76 @@
+define atomic => thread {
+ data
+ private buckets = staticarray_join(10, void),
+ private lock = 0
+
+ public onCreate => {
+ loop(.buckets->size) => {
+ .`buckets`->get(loop_count) = math_random(0, 1000)
+ }
+ }
+
+ public buckets => .`buckets`
+
+ public bucket(index::integer) => .`buckets`->get(#index)
+
+ public transfer(source::integer, dest::integer, amount::integer) => {
+ #source == #dest
+ ? return
+
+ #amount = math_min(#amount, .`buckets`->get(#source))
+ .`buckets`->get(#source) -= #amount
+ .`buckets`->get(#dest) += #amount
+ }
+
+ public numBuckets => .`buckets`->size
+
+ public lock => {
+ .`lock` == 1
+ ? return false
+
+ .`lock` = 1
+ return true
+ }
+ public unlock => {
+ .`lock` = 0
+ }
+}
+
+local(initial_total) = (with b in atomic->buckets sum #b)
+local(total) = #initial_total
+
+// Make 2 buckets close to equal
+local(_) = split_thread => {
+ local(bucket1) = math_random(1, atomic->numBuckets)
+ local(bucket2) = math_random(1, atomic->numBuckets)
+ local(value1) = atomic->bucket(#bucket1)
+ local(value2) = atomic->bucket(#bucket2)
+
+ if(#value1 >= #value2) => {
+ atomic->transfer(#bucket1, #bucket2, (#value1 - #value2) / 2)
+ else
+ atomic->transfer(#bucket2, #bucket1, (#value2 - #value1) / 2)
+ }
+
+ currentCapture->restart
+}
+
+// Randomly distribute 2 buckets
+local(_) = split_thread => {
+ local(bucket1) = math_random(1, atomic->numBuckets)
+ local(bucket2) = math_random(1, atomic->numBuckets)
+ local(value1) = atomic->bucket(#bucket1)
+
+ atomic->transfer(#bucket1, #bucket2, math_random(1, #value1))
+
+ currentCapture->restart
+}
+
+local(buckets)
+while(#initial_total == #total) => {
+ sleep(2000)
+ #buckets = atomic->buckets
+ #total = with b in #buckets sum #b
+ stdoutnl(#buckets->asString + " -- total: " + #total)
+}
+stdoutnl(`ERROR: totals no longer match: ` + #initial_total + ', ' + #total)
diff --git a/Task/Atomic-updates/Phix/atomic-updates.phix b/Task/Atomic-updates/Phix/atomic-updates.phix
new file mode 100644
index 0000000000..ab372015ff
--- /dev/null
+++ b/Task/Atomic-updates/Phix/atomic-updates.phix
@@ -0,0 +1,48 @@
+constant nBuckets = 20
+sequence buckets = tagset(nBuckets) -- {1,2,3,..,20}
+constant bucket_cs = init_cs() -- critical section
+atom equals = 0, rands = 0 -- operation counts
+integer terminate = 0 -- control flag
+
+procedure mythreads(integer eq)
+-- if eq then equalise else randomise
+integer b1,b2,amt
+ while not terminate do
+ b1 = rand(nBuckets)
+ b2 = rand(nBuckets)
+ if b1!=b2 then -- (test not actually needed)
+ enter_cs(bucket_cs)
+ if eq then
+ amt = floor((buckets[b1]-buckets[b2])/2)
+ equals += 1
+ else
+ amt = rand(buckets[b1]+1)-1
+ rands += 1
+ end if
+ buckets[b1] -= amt
+ buckets[b2] += amt
+ leave_cs(bucket_cs)
+ end if
+ end while
+ exit_thread(0)
+end procedure
+
+procedure display()
+ enter_cs(bucket_cs)
+ ?{sum(buckets),equals,rands,buckets}
+ leave_cs(bucket_cs)
+end procedure
+
+display()
+
+constant threads = {create_thread(routine_id("mythreads"),{1}), -- equalise
+ create_thread(routine_id("mythreads"),{0})} -- randomise
+
+constant ESC = #1B
+while not find(get_key(),{ESC,'q','Q'}) do
+ sleep(1)
+ display()
+end while
+terminate = 1
+wait_thread(threads)
+delete_cs(bucket_cs)
diff --git a/Task/Average-loop-length/EchoLisp/average-loop-length.echolisp b/Task/Average-loop-length/EchoLisp/average-loop-length.echolisp
new file mode 100644
index 0000000000..dd4197c5fc
--- /dev/null
+++ b/Task/Average-loop-length/EchoLisp/average-loop-length.echolisp
@@ -0,0 +1,29 @@
+(lib 'math) ;; Σ aka (sigma f(n) nfrom nto)
+
+(define (f-count N (times 100000))
+ (define count 0)
+ (for ((i times))
+
+ ;; new random f mapping from 0..N-1 to 0..N-1
+ ;; (f n) is NOT (random N)
+ ;; because each call (f n) must return the same value
+
+ (define f (build-vector N (lambda(i) (random N))))
+
+ (define hits (make-vector N))
+ (define n 0)
+ (while (zero? [hits n])
+ (++ count)
+ (vector+= hits n 1)
+ (set! n [f n])))
+ (// count times))
+
+(define (f-anal N)
+ (Σ (lambda(i) (// (! N) (! (- N i)) (^ N i))) 1 N))
+
+(decimals 5)
+(define (f-print (maxN 21))
+ (for ((N (in-range 1 maxN)))
+ (define fc (f-count N))
+ (define fa (f-anal N))
+ (printf "%3d %10d %10d %10.2d %%" N fc fa (// (abs (- fa fc)) fc 0.01))))
diff --git a/Task/Average-loop-length/Nim/average-loop-length.nim b/Task/Average-loop-length/Nim/average-loop-length.nim
new file mode 100644
index 0000000000..0179fe9023
--- /dev/null
+++ b/Task/Average-loop-length/Nim/average-loop-length.nim
@@ -0,0 +1,34 @@
+import math, strfmt
+randomize()
+
+const
+ maxN = 20
+ times = 1_000_000
+
+proc factorial(n): float =
+ result = 1
+ for i in 1 .. n:
+ result *= i.float
+
+proc expected(n): float =
+ for i in 1 .. n:
+ result += factorial(n) / pow(n.float, i.float) / factorial(n - i)
+
+proc test(n, times): int =
+ for i in 1 .. times:
+ var
+ x = 1
+ bits = 0
+ while (bits and x) == 0:
+ inc result
+ bits = bits or x
+ x = 1 shl random(n)
+
+echo " n\tavg\texp.\tdiff"
+echo "-------------------------------"
+for n in 1 .. maxN:
+ let cnt = test(n, times)
+ let avg = cnt.float / times
+ let theory = expected(n)
+ let diff = (avg / theory - 1) * 100
+ printlnfmt "{:2} {:8.4f} {:8.4f} {:6.3f}%", n, avg, theory, diff
diff --git a/Task/Average-loop-length/Phix/average-loop-length.phix b/Task/Average-loop-length/Phix/average-loop-length.phix
new file mode 100644
index 0000000000..1730f198b3
--- /dev/null
+++ b/Task/Average-loop-length/Phix/average-loop-length.phix
@@ -0,0 +1,33 @@
+constant MAX = 20,
+ ITER = 1000000
+
+function expected(integer n)
+atom sum = 0
+ for i=1 to n do
+ sum += factorial(n) / power(n,i) / factorial(n-i)
+ end for
+ return sum
+end function
+
+function test(integer n)
+integer count = 0, x, bits
+ for i=1 to ITER do
+ x = 1
+ bits = 0
+ while not and_bits(bits,x) do
+ count += 1
+ bits = or_bits(bits,x)
+ x = power(2,rand(n)-1)
+ end while
+ end for
+ return count/ITER
+end function
+
+atom av, ex
+ puts(1," n avg. exp. (error%)\n");
+ puts(1,"== ====== ====== ========\n");
+ for n=1 to MAX do
+ av = test(n)
+ ex = expected(n)
+ printf(1,"%2d %8.4f %8.4f (%5.3f%%)\n", {n,av,ex,abs(1-av/ex)*100})
+ end for
diff --git a/Task/Averages-Arithmetic-mean/8th/averages-arithmetic-mean.8th b/Task/Averages-Arithmetic-mean/8th/averages-arithmetic-mean.8th
new file mode 100644
index 0000000000..c0fb8f22d8
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/8th/averages-arithmetic-mean.8th
@@ -0,0 +1,9 @@
+: avg \ a -- avg(a)
+ dup ' n:+ 0 a:reduce
+ swap a:len nip n:/ ;
+
+\ test:
+[ 1.0, 2.3, 1.1, 5.0, 3, 2.8, 2.01, 3.14159 ] avg . cr
+[ ] avg . cr
+[ 10 ] avg . cr
+bye
diff --git a/Task/Averages-Arithmetic-mean/AntLang/averages-arithmetic-mean.antlang b/Task/Averages-Arithmetic-mean/AntLang/averages-arithmetic-mean.antlang
new file mode 100644
index 0000000000..a63d353e08
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/AntLang/averages-arithmetic-mean.antlang
@@ -0,0 +1 @@
+avg[list]
diff --git a/Task/Averages-Arithmetic-mean/ECL/averages-arithmetic-mean.ecl b/Task/Averages-Arithmetic-mean/ECL/averages-arithmetic-mean.ecl
new file mode 100644
index 0000000000..963a9ab432
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/ECL/averages-arithmetic-mean.ecl
@@ -0,0 +1,6 @@
+AveVal(SET OF INTEGER s) := AVE(s);
+
+//example usage
+
+SetVals := [14,9,16,20,91];
+AveVal(SetVals) //returns 30.0 ;
diff --git a/Task/Averages-Arithmetic-mean/EchoLisp/averages-arithmetic-mean.echolisp b/Task/Averages-Arithmetic-mean/EchoLisp/averages-arithmetic-mean.echolisp
new file mode 100644
index 0000000000..4838b02b05
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/EchoLisp/averages-arithmetic-mean.echolisp
@@ -0,0 +1,21 @@
+(lib 'math)
+(mean '(1 2 3 4)) ;; mean of a list
+ → 2.5
+(mean #(1 2 3 4)) ;; mean of a vector
+ → 2.5
+
+(lib 'sequences)
+(mean [1 3 .. 10]) ;; mean of a sequence
+ → 5
+
+;; error handling
+(mean 'elvis)
+ ⛔ error: mean : expected sequence : elvis
+(mean ())
+ 💣 error: mean : null is not an object
+(mean #())
+ 😐 warning: mean : zero-divide : empty-vector
+ → 0
+(mean [2 2 .. 2])
+ 😁 warning: mean : zero-divide : empty-sequence
+ → 0
diff --git a/Task/Averages-Arithmetic-mean/FreeBASIC/averages-arithmetic-mean.freebasic b/Task/Averages-Arithmetic-mean/FreeBASIC/averages-arithmetic-mean.freebasic
new file mode 100644
index 0000000000..4c8fd6d27a
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/FreeBASIC/averages-arithmetic-mean.freebasic
@@ -0,0 +1,42 @@
+' FB 1.05.0 Win64
+
+Function Mean(array() As Double) As Double
+ Dim length As Integer = Ubound(array) - Lbound(array) + 1
+ If length = 0 Then
+ Return 0.0/0.0 'NaN
+ End If
+ Dim As Double sum = 0.0
+ For i As Integer = LBound(array) To UBound(array)
+ sum += array(i)
+ Next
+ Return sum/length
+End Function
+
+Function IsNaN(number As Double) As Boolean
+ Return Str(number) = "-1.#IND" ' NaN as a string in FB
+End Function
+
+Dim As Integer n, i
+Dim As Double num
+Print "Sample input and output"
+Print
+Do
+ Input "How many numbers are to be input ? : ", n
+Loop Until n > 0
+Dim vector(1 To N) As Double
+Print
+For i = 1 to n
+ Print " Number #"; i; " : ";
+ Input "", vector(i)
+Next
+Print
+Print "Mean is"; Mean(vector())
+Print
+Erase vector
+num = Mean(vector())
+If IsNaN(num) Then
+ Print "After clearing the vector, the mean is 'NaN'"
+End If
+Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Averages-Arithmetic-mean/GEORGE/averages-arithmetic-mean.george b/Task/Averages-Arithmetic-mean/GEORGE/averages-arithmetic-mean.george
new file mode 100644
index 0000000000..66381ad8e5
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/GEORGE/averages-arithmetic-mean.george
@@ -0,0 +1,7 @@
+R (n) P ;
+0
+1, n rep (i)
+ R P +
+]
+n div
+P
diff --git a/Task/Averages-Arithmetic-mean/GFA-Basic/averages-arithmetic-mean.gfa b/Task/Averages-Arithmetic-mean/GFA-Basic/averages-arithmetic-mean.gfa
new file mode 100644
index 0000000000..88641d469f
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/GFA-Basic/averages-arithmetic-mean.gfa
@@ -0,0 +1,23 @@
+DIM a%(10)
+FOR i%=0 TO 10
+ a%(i%)=i%*2
+ PRINT "element ";i%;" is ";a%(i%)
+NEXT i%
+PRINT "mean is ";@mean(a%)
+'
+FUNCTION mean(a%)
+ LOCAL i%,size%,sum
+ ' find size of array,
+ size%=DIM?(a%())
+ ' return 0 for empty arrays
+ IF size%<=0
+ RETURN 0
+ ENDIF
+ ' find sum of all elements
+ sum=0
+ FOR i%=0 TO size%-1
+ sum=sum+a%(i%)
+ NEXT i%
+ ' mean is sum over size
+ RETURN sum/size%
+ENDFUNC
diff --git a/Task/Averages-Arithmetic-mean/Hy/averages-arithmetic-mean.hy b/Task/Averages-Arithmetic-mean/Hy/averages-arithmetic-mean.hy
new file mode 100644
index 0000000000..ffc7f4ede5
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Hy/averages-arithmetic-mean.hy
@@ -0,0 +1,3 @@
+(defn arithmetic-mean [xs]
+ (if xs
+ (/ (sum xs) (len xs))))
diff --git a/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-1.lfe b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-1.lfe
new file mode 100644
index 0000000000..6debf6514d
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-1.lfe
@@ -0,0 +1,3 @@
+(defun mean (data)
+ (/ (lists:sum data)
+ (length data)))
diff --git a/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-2.lfe b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-2.lfe
new file mode 100644
index 0000000000..fbb7ebeb32
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-2.lfe
@@ -0,0 +1,8 @@
+> (mean '(1 1))
+1.0
+> (mean '(1 2))
+1.5
+> (mean '(2 10))
+6.0
+> (mean '(6 12 18 24 30 36 42 48 54 60 66 72 78))
+42.0
diff --git a/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-3.lfe b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-3.lfe
new file mode 100644
index 0000000000..62382367da
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-3.lfe
@@ -0,0 +1,3 @@
+(defmacro mean args
+ `(/ (lists:sum ,args)
+ ,(length args)))
diff --git a/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-4.lfe b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-4.lfe
new file mode 100644
index 0000000000..7055a142b7
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LFE/averages-arithmetic-mean-4.lfe
@@ -0,0 +1,6 @@
+> (mean 42)
+42.0
+> (mean 18 66)
+42.0
+> (mean 6 12 18 24 30 36 42 48 54 60 66 72 78)
+42.0
diff --git a/Task/Averages-Arithmetic-mean/Lasso/averages-arithmetic-mean.lasso b/Task/Averages-Arithmetic-mean/Lasso/averages-arithmetic-mean.lasso
new file mode 100644
index 0000000000..6e8c6593bc
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Lasso/averages-arithmetic-mean.lasso
@@ -0,0 +1,8 @@
+define average(a::array) => {
+ not #a->size ? return 0
+ local(x = 0.0)
+ with i in #a do => { #x += #i }
+ return #x / #a->size
+}
+
+average(array(1,2,5,17,7.4)) //6.48
diff --git a/Task/Averages-Arithmetic-mean/LiveCode/averages-arithmetic-mean.livecode b/Task/Averages-Arithmetic-mean/LiveCode/averages-arithmetic-mean.livecode
new file mode 100644
index 0000000000..42cfa7d584
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/LiveCode/averages-arithmetic-mean.livecode
@@ -0,0 +1,2 @@
+average(1,2,3,4,5) -- 3
+average(empty) -- 0
diff --git a/Task/Averages-Arithmetic-mean/Nim/averages-arithmetic-mean.nim b/Task/Averages-Arithmetic-mean/Nim/averages-arithmetic-mean.nim
new file mode 100644
index 0000000000..491cece56f
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Nim/averages-arithmetic-mean.nim
@@ -0,0 +1,11 @@
+import strutils
+
+proc mean(xs): float =
+ for x in xs:
+ result += x
+ result = result / float(xs.len)
+
+var v = @[1.0, 2.0, 2.718, 3.0, 3.142]
+for i in 0..5:
+ echo "mean of first ", v.len, " = ", formatFloat(mean(v), precision = 0)
+ v.setLen(v.high)
diff --git a/Task/Averages-Arithmetic-mean/Oforth/averages-arithmetic-mean.oforth b/Task/Averages-Arithmetic-mean/Oforth/averages-arithmetic-mean.oforth
new file mode 100644
index 0000000000..e6f3e8827d
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Oforth/averages-arithmetic-mean.oforth
@@ -0,0 +1,2 @@
+[1, 2, 2.718, 3, 3.142] avg println
+[ ] avg println
diff --git a/Task/Averages-Arithmetic-mean/Phix/averages-arithmetic-mean.phix b/Task/Averages-Arithmetic-mean/Phix/averages-arithmetic-mean.phix
new file mode 100644
index 0000000000..f4efc0a859
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Phix/averages-arithmetic-mean.phix
@@ -0,0 +1,6 @@
+function mean(sequence s)
+ if length(s)=0 then return 0 end if
+ return sum(s)/length(s)
+end function
+
+? mean({1, 2, 5, -5, -9.5, 3.14159})
diff --git a/Task/Averages-Arithmetic-mean/Ring/averages-arithmetic-mean.ring b/Task/Averages-Arithmetic-mean/Ring/averages-arithmetic-mean.ring
new file mode 100644
index 0000000000..b4cd3af8fb
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Ring/averages-arithmetic-mean.ring
@@ -0,0 +1,9 @@
+nums = [1,2,3,4,5,6,7,8,9,10]
+sum = 0
+see "Average = " + average(nums) + nl
+
+func average numbers
+ for i = 1 to len(numbers)
+ sum = sum + nums[i]
+ next
+ return sum/len(numbers)
diff --git a/Task/Averages-Arithmetic-mean/Sidef/averages-arithmetic-mean.sidef b/Task/Averages-Arithmetic-mean/Sidef/averages-arithmetic-mean.sidef
new file mode 100644
index 0000000000..cb65d428f5
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Sidef/averages-arithmetic-mean.sidef
@@ -0,0 +1,10 @@
+func avg(Array list) {
+ list.len > 0 || return 0;
+ list.sum / list.len;
+}
+
+say avg([Math.inf, Math.inf]);
+say avg([3,1,4,1,5,9]);
+say avg([1e+20, 3, 1, 4, 1, 5, 9, -1e+20]);
+say avg([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0.11]);
+say avg([10, 20, 30, 40, 50, -100, 4.7, -1100]);
diff --git a/Task/Averages-Arithmetic-mean/Swift/averages-arithmetic-mean.swift b/Task/Averages-Arithmetic-mean/Swift/averages-arithmetic-mean.swift
new file mode 100644
index 0000000000..d9d453741e
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Swift/averages-arithmetic-mean.swift
@@ -0,0 +1,6 @@
+func meanDoubles(s: [Double]) -> Double {
+ return s.reduce(0, +) / Double(s.count)
+}
+func meanInts(s: [Int]) -> Double {
+ return meanDoubles(s.map{Double($0)})
+}
diff --git a/Task/Averages-Arithmetic-mean/Ursa/averages-arithmetic-mean.ursa b/Task/Averages-Arithmetic-mean/Ursa/averages-arithmetic-mean.ursa
new file mode 100644
index 0000000000..7acabde12e
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Ursa/averages-arithmetic-mean.ursa
@@ -0,0 +1,11 @@
+#
+# arithmetic mean
+#
+
+decl int<> input
+decl int i
+for (set i 1) (< i (size args)) (inc i)
+ append (int args) input
+end for
+
+out (/ (+ input) (size input)) endl console
diff --git a/Task/Averages-Arithmetic-mean/Wart/averages-arithmetic-mean.wart b/Task/Averages-Arithmetic-mean/Wart/averages-arithmetic-mean.wart
new file mode 100644
index 0000000000..8256f8eb08
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Wart/averages-arithmetic-mean.wart
@@ -0,0 +1,2 @@
+def (mean l)
+ sum.l / len.l
diff --git a/Task/Averages-Arithmetic-mean/Wortel/averages-arithmetic-mean.wortel b/Task/Averages-Arithmetic-mean/Wortel/averages-arithmetic-mean.wortel
new file mode 100644
index 0000000000..37e1a22cfb
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Wortel/averages-arithmetic-mean.wortel
@@ -0,0 +1,12 @@
+@let {
+ ; using a fork (sum divided-by length)
+ mean1 @(@sum / #)
+
+ ; using a function with a named argument
+ mean2 &a / @sum a #a
+
+ [[
+ !mean1 [3 1 4 1 5 9 2]
+ !mean2 [3 1 4 1 5 9 2]
+ ]]
+}
diff --git a/Task/Averages-Arithmetic-mean/Wren/averages-arithmetic-mean.wren b/Task/Averages-Arithmetic-mean/Wren/averages-arithmetic-mean.wren
new file mode 100644
index 0000000000..f98c7c2b38
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/Wren/averages-arithmetic-mean.wren
@@ -0,0 +1,7 @@
+class Arithmetic {
+ static mean(arr) {
+ if (arr.count == 0) Fiber.abort("Length must be greater than zero")
+ return arr.reduce(Fn.new{ |x,y| x+y }) / arr.count
+ }
+}
+Arithmetic.mean([1,2,3,4,5]) // 3
diff --git a/Task/Averages-Arithmetic-mean/XLISP/averages-arithmetic-mean.xlisp b/Task/Averages-Arithmetic-mean/XLISP/averages-arithmetic-mean.xlisp
new file mode 100644
index 0000000000..32294e1399
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/XLISP/averages-arithmetic-mean.xlisp
@@ -0,0 +1,5 @@
+(defun mean (v)
+ (if (= (vector-length v) 0)
+ nil
+ (let ((l (vector->list v)))
+ (/ (apply + l) (length l)))))
diff --git a/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-1.jq b/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-1.jq
new file mode 100644
index 0000000000..0eaa6dc134
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-1.jq
@@ -0,0 +1 @@
+add/length
diff --git a/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-2.jq b/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-2.jq
new file mode 100644
index 0000000000..3d2b59863d
--- /dev/null
+++ b/Task/Averages-Arithmetic-mean/jq/averages-arithmetic-mean-2.jq
@@ -0,0 +1,3 @@
+def mean: if length == 0 then null
+ else add/length
+ end;
diff --git a/Task/Averages-Mean-angle/EchoLisp/averages-mean-angle.echolisp b/Task/Averages-Mean-angle/EchoLisp/averages-mean-angle.echolisp
new file mode 100644
index 0000000000..aa2bc3f249
--- /dev/null
+++ b/Task/Averages-Mean-angle/EchoLisp/averages-mean-angle.echolisp
@@ -0,0 +1,14 @@
+(define-syntax-rule (deg->radian deg) (* deg 1/180 PI))
+(define-syntax-rule (radian->deg rad) (* 180 (/ PI) rad))
+
+(define (mean-angles angles)
+ (radian->deg
+ (angle
+ (for/sum ((a angles)) (make-polar 1 (deg->radian a))))))
+
+(mean-angles '( 350 10))
+ → -0
+(mean-angles '[90 180 270 360])
+ → -90
+(mean-angles '[10 20 30])
+ → 20
diff --git a/Task/Averages-Mean-angle/FreeBASIC/averages-mean-angle.freebasic b/Task/Averages-Mean-angle/FreeBASIC/averages-mean-angle.freebasic
new file mode 100644
index 0000000000..c2464ab94b
--- /dev/null
+++ b/Task/Averages-Mean-angle/FreeBASIC/averages-mean-angle.freebasic
@@ -0,0 +1,25 @@
+' FB 1.05.0 Win64
+
+Const PI As Double = 3.1415926535897932
+
+Function MeanAngle(angles() As Double) As Double
+ Dim As Integer length = Ubound(angles) - Lbound(angles) + 1
+ Dim As Double sinSum = 0.0
+ Dim As Double cosSum = 0.0
+ For i As Integer = LBound(angles) To UBound(angles)
+ sinSum += Sin(angles(i) * PI / 180.0)
+ cosSum += Cos(angles(i) * PI / 180.0)
+ Next
+ Return Atan2(sinSum / length, cosSum / length) * 180.0 / PI
+End Function
+
+Dim As Double angles1(1 To 2) = {350, 10}
+Dim As Double angles2(1 To 4) = {90, 180, 270, 360}
+Dim As Double angles3(1 To 3) = {10, 20, 30}
+
+Print Using "Mean for angles 1 is : ####.## degrees"; MeanAngle(angles1())
+Print Using "Mean for angles 2 is : ####.## degrees"; MeanAngle(angles2())
+Print Using "Mean for angles 3 is : ####.## degrees"; MeanAngle(angles3())
+Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Averages-Mean-angle/Nim/averages-mean-angle.nim b/Task/Averages-Mean-angle/Nim/averages-mean-angle.nim
new file mode 100644
index 0000000000..55635307b7
--- /dev/null
+++ b/Task/Averages-Mean-angle/Nim/averages-mean-angle.nim
@@ -0,0 +1,17 @@
+import math, complex
+
+proc rect(r, phi): Complex = (r * cos(phi), sin(phi))
+proc phase(c): float = arctan2(c.im, c.re)
+
+proc radians(x): float = (x * Pi) / 180.0
+proc degrees(x): float = (x * 180.0) / Pi
+
+proc meanAngle(deg): float =
+ var c: Complex
+ for d in deg:
+ c += rect(1.0, radians(d))
+ degrees(phase(c / float(deg.len)))
+
+echo "The 1st mean angle is: ", meanAngle([350.0, 10.0]), " degrees"
+echo "The 2nd mean angle is: ", meanAngle([90.0, 180.0, 270.0, 360.0]), " degrees"
+echo "The 3rd mean angle is: ", meanAngle([10.0, 20.0, 30.0]), " degrees"
diff --git a/Task/Averages-Mean-angle/Phix/averages-mean-angle.phix b/Task/Averages-Mean-angle/Phix/averages-mean-angle.phix
new file mode 100644
index 0000000000..4f42895c3b
--- /dev/null
+++ b/Task/Averages-Mean-angle/Phix/averages-mean-angle.phix
@@ -0,0 +1,24 @@
+function atan2(atom y, atom x)
+ return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y)
+end function
+
+function MeanAngle(sequence angles)
+atom x=0, y=0, ai_rad
+integer l=length(angles)
+
+ for i=1 to l do
+ ai_rad = angles[i]*PI/180
+ x += cos(ai_rad)
+ y += sin(ai_rad)
+ end for
+ if abs(x)<1e-16 then return "not meaningful" end if
+ return sprintf("%9.5f",atan2(y,x)*180/PI)
+end function
+
+constant AngleLists = {{350,10},{90,180,270,360},{10,20,30},{180},{0,180}}
+sequence ai
+for i=1 to length(AngleLists) do
+ ai = AngleLists[i]
+ printf(1,"%+16s: Mean Angle is %s\n",{sprint(ai),MeanAngle(ai)})
+end for
+{} = wait_key()
diff --git a/Task/Averages-Mean-angle/Sidef/averages-mean-angle.sidef b/Task/Averages-Mean-angle/Sidef/averages-mean-angle.sidef
new file mode 100644
index 0000000000..e91d17e16d
--- /dev/null
+++ b/Task/Averages-Mean-angle/Sidef/averages-mean-angle.sidef
@@ -0,0 +1,10 @@
+func mean_angle(angles) {
+ Math.atan2(
+ Math.avg(angles.map{ .deg2rad.sin }...),
+ Math.avg(angles.map{ .deg2rad.cos }...),
+ ) -> rad2deg;
+}
+
+[[350,10], [90,180,270,360], [10,20,30]].each { |angles|
+ say "The mean angle of #{angles.dump} is: #{ '%.2f' % mean_angle(angles)} degrees";
+}
diff --git a/Task/Averages-Mean-angle/jq/averages-mean-angle-1.jq b/Task/Averages-Mean-angle/jq/averages-mean-angle-1.jq
new file mode 100644
index 0000000000..0210e2bcdb
--- /dev/null
+++ b/Task/Averages-Mean-angle/jq/averages-mean-angle-1.jq
@@ -0,0 +1,19 @@
+def pi: 4 * (1|atan);
+
+def deg2rad: . * pi / 180;
+
+def rad2deg: if . == null then null else . * 180 / pi end;
+
+# Input: [x,y] (special handling of x==0)
+# Output: [r, theta] where theta may be null
+def to_polar:
+ if .[0] == 0
+ then [1, if .[1] > 5e-14 then pi/2 elif .[1] < -5e-14 then -pi/2 else null end]
+ else [1, ((.[1]/.[0]) | atan)]
+ end;
+
+def from_polar: .[1] | [ cos, sin];
+
+def abs: if . < 0 then - . else . end;
+
+def summation(f): map(f) | add;
diff --git a/Task/Averages-Mean-angle/jq/averages-mean-angle-2.jq b/Task/Averages-Mean-angle/jq/averages-mean-angle-2.jq
new file mode 100644
index 0000000000..c551d8a832
--- /dev/null
+++ b/Task/Averages-Mean-angle/jq/averages-mean-angle-2.jq
@@ -0,0 +1,15 @@
+# input: degrees
+def mean_angle:
+ def round:
+ if . == null then null
+ elif . < 0 then -1 * ((- .) | round) | if . == -0 then 0 else . end
+ else ((. + 3e-14) | floor) as $x
+ | if ($x - .) | abs < 3e-14 then $x else . end
+ end;
+
+ map( [1, deg2rad] | from_polar)
+ | [ summation(.[0]), summation(.[1]) ]
+ | to_polar
+ | .[1]
+ | rad2deg
+ | round;
diff --git a/Task/Averages-Mean-angle/jq/averages-mean-angle-3.jq b/Task/Averages-Mean-angle/jq/averages-mean-angle-3.jq
new file mode 100644
index 0000000000..17a0e37e25
--- /dev/null
+++ b/Task/Averages-Mean-angle/jq/averages-mean-angle-3.jq
@@ -0,0 +1,2 @@
+([350, 10], [90, 180, 270, 360], [10, 20, 30])
+| "The mean angle of \(.) is: \(mean_angle)"
diff --git a/Task/Averages-Mean-angle/jq/averages-mean-angle-4.jq b/Task/Averages-Mean-angle/jq/averages-mean-angle-4.jq
new file mode 100644
index 0000000000..66e489155e
--- /dev/null
+++ b/Task/Averages-Mean-angle/jq/averages-mean-angle-4.jq
@@ -0,0 +1,4 @@
+jq -r -n -f Mean_angle.jq
+The mean angle of [350,10] is: 0
+The mean angle of [90,180,270,360] is: null
+The mean angle of [10,20,30] is: 20
diff --git a/Task/Averages-Mean-time-of-day/EchoLisp/averages-mean-time-of-day.echolisp b/Task/Averages-Mean-time-of-day/EchoLisp/averages-mean-time-of-day.echolisp
new file mode 100644
index 0000000000..12c213f5d3
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/EchoLisp/averages-mean-time-of-day.echolisp
@@ -0,0 +1,21 @@
+;; string hh:mm:ss to radians
+(define (time->radian time)
+ (define-values (h m s) (map string->number (string-split time ":")))
+ (+ (* h (/ PI 12)) (* m (/ PI 12 60)) (* s (/ PI 12 3600))))
+
+;; radians to string hh:mm;ss
+(define (radian->time rad)
+ (when (< rad 0) (+= rad (* 2 PI)))
+ (define t (round (/ (* 12 3600 rad) PI)))
+ (define h (quotient t 3600))
+ (define m (quotient (- t (* h 3600)) 60))
+ (define s (- t (* 3600 h) (* 60 m)))
+ (string-join (map number->string (list h m s)) ":"))
+
+(define (mean-time times)
+ (radian->time
+ (angle
+ (for/sum ((t times)) (make-polar 1 (time->radian t))))))
+
+(mean-time '{"23:00:17" "23:40:20" "00:12:45" "00:17:19"})
+ → "23:47:43"
diff --git a/Task/Averages-Mean-time-of-day/FreeBASIC/averages-mean-time-of-day.freebasic b/Task/Averages-Mean-time-of-day/FreeBASIC/averages-mean-time-of-day.freebasic
new file mode 100644
index 0000000000..097b3b95a4
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/FreeBASIC/averages-mean-time-of-day.freebasic
@@ -0,0 +1,54 @@
+' FB 1.05.0 Win64
+
+Const pi As Double = 3.1415926535897932
+
+Function meanAngle(angles() As Double) As Double
+ Dim As Integer length = Ubound(angles) - Lbound(angles) + 1
+ Dim As Double sinSum = 0.0
+ Dim As Double cosSum = 0.0
+ For i As Integer = LBound(angles) To UBound(angles)
+ sinSum += Sin(angles(i) * pi / 180.0)
+ cosSum += Cos(angles(i) * pi / 180.0)
+ Next
+ Return Atan2(sinSum / length, cosSum / length) * 180.0 / pi
+End Function
+
+' time string assumed to be in format "hh:mm:ss"
+Function timeToSecs(t As String) As Integer
+ Dim As Integer hours = Val(Left(t, 2))
+ Dim As Integer mins = Val(Mid(t, 4, 2))
+ Dim As Integer secs = Val(Right(t, 2))
+ Return 3600 * hours + 60 * mins + secs
+End Function
+
+' 1 second of time = 360/(24 * 3600) = 1/240th degree
+Function timeToDegrees(t As String) As Double
+ Dim secs As Integer = timeToSecs(t)
+ Return secs/240.0
+End Function
+
+Function degreesToTime(d As Double) As String
+ If d < 0 Then d += 360.0
+ Dim secs As Integer = d * 240.0
+ Dim hours As Integer = secs \ 3600
+ Dim mins As Integer = secs Mod 3600
+ secs = mins Mod 60
+ mins = mins \ 60
+ Dim hBuffer As String = Right("0" + Str(hours), 2)
+ Dim mBuffer As String = Right("0" + Str(mins), 2)
+ Dim sBuffer As String = Right("0" + Str(secs), 2)
+ Return hBuffer + ":" + mBuffer + ":" + sBuffer
+End Function
+
+Dim tm(1 To 4) As String = {"23:00:17", "23:40:20", "00:12:45", "00:17:19"}
+Dim angles(1 To 4) As Double
+
+For i As Integer = 1 To 4
+ angles(i) = timeToDegrees(tm(i))
+Next
+
+Dim mean As Double = meanAngle(angles())
+Print "Average time is : "; degreesToTime(mean)
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Averages-Mean-time-of-day/Nim/averages-mean-time-of-day.nim b/Task/Averages-Mean-time-of-day/Nim/averages-mean-time-of-day.nim
new file mode 100644
index 0000000000..7ef8c37880
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/Nim/averages-mean-time-of-day.nim
@@ -0,0 +1,26 @@
+import math, complex, strutils
+
+proc rect(r, phi): Complex = (r * cos(phi), sin(phi))
+proc phase(c): float = arctan2(c.im, c.re)
+
+proc radians(x): float = (x * Pi) / 180.0
+proc degrees(x): float = (x * 180.0) / Pi
+
+proc meanAngle(deg): float =
+ var c: Complex
+ for d in deg:
+ c += rect(1.0, radians(d))
+ degrees(phase(c / float(deg.len)))
+
+proc meanTime(times): string =
+ const day = 24 * 60 * 60
+ let
+ angles = times.map(proc(time: string): float =
+ let t = time.split(":")
+ (t[2].parseInt + t[1].parseInt * 60 + t[0].parseInt * 3600) * 360 / day)
+ ms = (angles.meanAngle * day / 360 + day) mod day
+ (h,m,s) = (ms.int div 3600, (ms.int mod 3600) div 60, ms.int mod 60)
+
+ align($h, 2, '0') &":"& align($m, 2, '0') &":"& align($s, 2, '0')
+
+echo meanTime(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])
diff --git a/Task/Averages-Mean-time-of-day/Phix/averages-mean-time-of-day.phix b/Task/Averages-Mean-time-of-day/Phix/averages-mean-time-of-day.phix
new file mode 100644
index 0000000000..b50bc1c624
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/Phix/averages-mean-time-of-day.phix
@@ -0,0 +1,37 @@
+function atan2(atom y, atom x)
+ return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y)
+end function
+
+function MeanAngle(sequence angles)
+atom x=0, y=0, ai_rad
+integer l=length(angles)
+
+ for i=1 to l do
+ ai_rad = angles[i]*PI/180
+ x += cos(ai_rad)
+ y += sin(ai_rad)
+ end for
+ if abs(x)<1e-16 then return "not meaningful" end if
+ return atan2(y,x)*180/PI
+end function
+
+function toSecAngle(integer hours, integer minutes, integer seconds)
+ return ((hours*60+minutes)*60+seconds)/(24*60*60)*360
+end function
+
+constant Times = {toSecAngle(23,00,17),
+ toSecAngle(23,40,20),
+ toSecAngle(00,12,45),
+ toSecAngle(00,17,19)}
+
+function toHMS(object s)
+ if not string(s) then
+ if s<0 then s+=360 end if
+ s = 24*60*60*s/360
+ s = sprintf("%02d:%02d:%02d",{floor(s/3600),floor(remainder(s,3600)/60),remainder(s,60)})
+ end if
+ return s
+end function
+
+printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))})
+{} = wait_key()
diff --git a/Task/Averages-Mean-time-of-day/Sidef/averages-mean-time-of-day.sidef b/Task/Averages-Mean-time-of-day/Sidef/averages-mean-time-of-day.sidef
new file mode 100644
index 0000000000..56c069e849
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/Sidef/averages-mean-time-of-day.sidef
@@ -0,0 +1,17 @@
+func time2deg(t) {
+ (var m = t.match(/^(\d\d):(\d\d):(\d\d)$/)) || die "invalid time"
+ var (hh,mm,ss) = m.cap.map{.to_i}...
+ ((hh ~~ 24.range) && (mm ~~ 60.range) && (ss ~~ 60.range)) || die "invalid time"
+ (hh*3600 + mm*60 + ss) * 360 / 86400
+}
+
+func deg2time(d) {
+ var sec = ((d % 360) * 86400 / 360)
+ "%02d:%02d:%02d" % (sec/3600, (sec%3600)/60, sec%60)
+}
+
+func mean_time(times) {
+ deg2time(mean_angle(times.map {|t| time2deg(t)}))
+}
+
+say mean_time(["23:00:17", "23:40:20", "00:12:45", "00:17:19"])
diff --git a/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-1.jq b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-1.jq
new file mode 100644
index 0000000000..b563624233
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-1.jq
@@ -0,0 +1,31 @@
+# input: array of "h:m:s"
+def mean_time_of_day:
+ def pi: 4 * (1|atan);
+ def to_radians: pi * . /(12*60*60);
+ def from_radians: (. * 12*60*60) / pi;
+
+ def secs2time: # produce "hh:mm:ss" string
+ def pad: tostring | (2 - length) * "0" + .;
+ "\(./60/60 % 24 | pad):\(./60 % 60 | pad):\(. % 60 | pad)";
+
+ def round:
+ if . < 0 then -1 * ((- .) | round) | if . == -0 then 0 else . end
+ else floor as $x
+ | if (. - $x) < 0.5 then $x else $x+1 end
+ end;
+
+ map( split(":")
+ | map(tonumber)
+ | (.[0]*3600 + .[1]*60 + .[2])
+ | to_radians )
+ | (map(sin) | add) as $y
+ | (map(cos) | add) as $x
+ | if $x == 0 then (if $y > 3e-14 then pi/2 elif $y < -3e-14 then -(pi/2) else null end)
+ else ($y / $x) | atan
+ end
+ | if . == null then null
+ else from_radians
+ | if (.<0) then . + (24*60*60) else . end
+ | round
+ | secs2time
+ end ;
diff --git a/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-2.jq b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-2.jq
new file mode 100644
index 0000000000..5c1a4f2613
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-2.jq
@@ -0,0 +1,8 @@
+["0:0:0", "12:0:0" ],
+["0:0:0", "24:0:0" ],
+["1:0:0", "1:0:0" ],
+["20:0:0", "4:0:0" ],
+["20:0:0", "4:0:2" ],
+["23:0:0", "23:0:0" ],
+["23:00:17", "23:40:20", "00:12:45", "00:17:19"]
+| mean_time_of_day
diff --git a/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-3.jq b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-3.jq
new file mode 100644
index 0000000000..4ab73fdb70
--- /dev/null
+++ b/Task/Averages-Mean-time-of-day/jq/averages-mean-time-of-day-3.jq
@@ -0,0 +1,8 @@
+$ jq -r -n -f Mean_time_of_day.jq
+null
+00:00:00
+01:00:00
+00:00:00
+00:00:01
+23:00:00
+23:47:43
diff --git a/Task/Averages-Median/AntLang/averages-median.antlang b/Task/Averages-Median/AntLang/averages-median.antlang
new file mode 100644
index 0000000000..116153ade1
--- /dev/null
+++ b/Task/Averages-Median/AntLang/averages-median.antlang
@@ -0,0 +1 @@
+median[list]
diff --git a/Task/Averages-Median/ERRE/averages-median.erre b/Task/Averages-Median/ERRE/averages-median.erre
new file mode 100644
index 0000000000..3071e3af26
--- /dev/null
+++ b/Task/Averages-Median/ERRE/averages-median.erre
@@ -0,0 +1,36 @@
+PROGRAM MEDIAN
+
+DIM X[10]
+
+PROCEDURE QUICK_SELECT
+ LT=0 RT=L-1
+ J=LT
+ REPEAT
+ PT=X[K]
+ SWAP(X[K],X[RT])
+ P=LT
+ FOR I=P TO RT-1 DO
+ IF X[I]=K THEN RT=P-1 END IF
+ UNTIL J>RT
+END PROCEDURE
+
+PROCEDURE MEDIAN
+ K=INT(L/2)
+ QUICK_SELECT
+ R=X[K]
+ IF L-2*INT(L/2)<>0 THEN R=(R+X[K+1])/2 END IF
+END PROCEDURE
+
+BEGIN
+ PRINT(CHR$(12);) !CLS
+ X[0]=4.4 X[1]=2.3 X[2]=-1.7 X[3]=7.5 X[4]=6.6 X[5]=0
+ X[6]=1.9 X[7]=8.2 X[8]=9.3 X[9]=4.5 X[10]=-11.7
+ L=11
+ MEDIAN
+ PRINT(R)
+END PROGRAM
diff --git a/Task/Averages-Median/EchoLisp/averages-median.echolisp b/Task/Averages-Median/EchoLisp/averages-median.echolisp
new file mode 100644
index 0000000000..1b74fde4b1
--- /dev/null
+++ b/Task/Averages-Median/EchoLisp/averages-median.echolisp
@@ -0,0 +1,15 @@
+(define (median L) ;; O(n log(n))
+ (set! L (vector-sort! < (list->vector L)))
+ (define dim (// (vector-length L) 2))
+ (if (integer? dim)
+ (// (+ [L dim] [L (1- dim)]) 2)
+ [L (floor dim)]))
+
+(median '( 3 4 5))
+ → 4
+(median '(6 5 4 3))
+ → 4.5
+(median (iota 10000))
+ → 4999.5
+(median (iota 10001))
+ → 5000
diff --git a/Task/Averages-Median/FreeBASIC/averages-median.freebasic b/Task/Averages-Median/FreeBASIC/averages-median.freebasic
new file mode 100644
index 0000000000..c41069890c
--- /dev/null
+++ b/Task/Averages-Median/FreeBASIC/averages-median.freebasic
@@ -0,0 +1,46 @@
+' FB 1.05.0 Win64
+
+Sub quicksort(a() As Double, first As Integer, last As Integer)
+ Dim As Integer length = last - first + 1
+ If length < 2 Then Return
+ Dim pivot As Double = a(first + length\ 2)
+ Dim lft As Integer = first
+ Dim rgt As Integer = last
+ While lft <= rgt
+ While a(lft) < pivot
+ lft +=1
+ Wend
+ While a(rgt) > pivot
+ rgt -= 1
+ Wend
+ If lft <= rgt Then
+ Swap a(lft), a(rgt)
+ lft += 1
+ rgt -= 1
+ End If
+ Wend
+ quicksort(a(), first, rgt)
+ quicksort(a(), lft, last)
+End Sub
+
+Function median(a() As Double) As Double
+ Dim lb As Integer = LBound(a)
+ Dim ub As Integer = UBound(a)
+ Dim length As Integer = ub - lb + 1
+ If length = 0 Then Return 0.0/0.0 '' NaN
+ If length = 1 Then Return a(ub)
+ Dim mb As Integer = (lb + ub) \2
+ If length Mod 2 = 1 Then Return a(mb)
+ Return (a(mb) + a(mb + 1))/2.0
+End Function
+
+Dim a(0 To 9) As Double = {4.4, 2.3, -1.7, 7.5, 6.6, 0.0, 1.9, 8.2, 9.3, 4.5}
+quicksort(a(), 0, 9)
+Print "Median for all 10 elements : "; median(a())
+' now get rid of final element
+Dim b(0 To 8) As Double = {4.4, 2.3, -1.7, 7.5, 6.6, 0.0, 1.9, 8.2, 9.3}
+quicksort(b(), 0, 8)
+Print "Median for first 9 elements : "; median(b())
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Averages-Median/Lasso/averages-median.lasso b/Task/Averages-Median/Lasso/averages-median.lasso
new file mode 100644
index 0000000000..0e0d79eeec
--- /dev/null
+++ b/Task/Averages-Median/Lasso/averages-median.lasso
@@ -0,0 +1,15 @@
+define median_ext(a::array) => {
+ #a->sort
+
+ if(#a->size % 2) => {
+ // odd numbered element array, pick middle
+ return #a->get(#a->size / 2 + 1)
+
+ else
+ // even number elements in array
+ return (#a->get(#a->size / 2) + #a->get(#a->size / 2 + 1)) / 2.0
+ }
+}
+
+median_ext(array(3,2,7,6)) // 4.5
+median_ext(array(3,2,9,7,6)) // 6
diff --git a/Task/Averages-Median/LiveCode/averages-median-1.livecode b/Task/Averages-Median/LiveCode/averages-median-1.livecode
new file mode 100644
index 0000000000..40df6fd75d
--- /dev/null
+++ b/Task/Averages-Median/LiveCode/averages-median-1.livecode
@@ -0,0 +1,2 @@
+put median("4.1,5.6,7.2,1.7,9.3,4.4,3.2") & "," & median("4.1,7.2,1.7,9.3,4.4,3.2")
+returns 4.4, 4.25
diff --git a/Task/Averages-Median/LiveCode/averages-median-2.livecode b/Task/Averages-Median/LiveCode/averages-median-2.livecode
new file mode 100644
index 0000000000..12f008571a
--- /dev/null
+++ b/Task/Averages-Median/LiveCode/averages-median-2.livecode
@@ -0,0 +1,24 @@
+function floor n
+ if n < 0 then
+ return (trunc(n) - 1)
+ else
+ return trunc(n)
+ end if
+end floor
+
+function median2 x
+ local n, m
+ set itemdelimiter to comma
+ sort items of x ascending numeric
+ put the number of items of x into n
+ put floor(n / 2) into m
+ if n mod 2 is 0 then
+ return (item m of x + item (m + 1) of x) / 2
+ else
+ return item (m + 1) of x
+ end if
+end median2
+
+returns the same as the built-in median, viz.
+put median2("4.1,5.6,7.2,1.7,9.3,4.4,3.2") & "," & median2("4.1,7.2,1.7,9.3,4.4,3.2")
+4.4,4.25
diff --git a/Task/Averages-Median/Nim/averages-median.nim b/Task/Averages-Median/Nim/averages-median.nim
new file mode 100644
index 0000000000..a4162b6304
--- /dev/null
+++ b/Task/Averages-Median/Nim/averages-median.nim
@@ -0,0 +1,11 @@
+import algorithm, strutils
+
+proc median(xs): float =
+ var ys = xs
+ sort(ys, system.cmp[float])
+ 0.5 * (ys[ys.high div 2] + ys[ys.len div 2])
+
+var a = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
+echo formatFloat(median(a), precision = 0)
+a = @[4.1, 7.2, 1.7, 9.3, 4.4, 3.2]
+echo formatFloat(median(a), precision = 0)
diff --git a/Task/Averages-Median/Phix/averages-median-1.phix b/Task/Averages-Median/Phix/averages-median-1.phix
new file mode 100644
index 0000000000..32333743a5
--- /dev/null
+++ b/Task/Averages-Median/Phix/averages-median-1.phix
@@ -0,0 +1,12 @@
+function median(sequence s)
+atom res=0
+integer l = length(s), k = floor((l+1)/2)
+ if l then
+ s = sort(s)
+ res = s[k]
+ if remainder(l,2)=0 then
+ res = (res+s[k+1])/2
+ end if
+ end if
+ return res
+end function
diff --git a/Task/Averages-Median/Phix/averages-median-2.phix b/Task/Averages-Median/Phix/averages-median-2.phix
new file mode 100644
index 0000000000..6ddce6800c
--- /dev/null
+++ b/Task/Averages-Median/Phix/averages-median-2.phix
@@ -0,0 +1,12 @@
+function medianq(sequence s)
+atom res=0, tmp
+integer l = length(s), k = floor((l+1)/2)
+ if l then
+ {s,res} = quick_select(s,k)
+ if remainder(l,2)=0 then
+ {s,tmp} = quick_select(s,k+1)
+ res = (res+tmp)/2
+ end if
+ end if
+ return res -- (or perhaps return {s,res})
+end function
diff --git a/Task/Averages-Median/Ring/averages-median.ring b/Task/Averages-Median/Ring/averages-median.ring
new file mode 100644
index 0000000000..848a17501c
--- /dev/null
+++ b/Task/Averages-Median/Ring/averages-median.ring
@@ -0,0 +1,9 @@
+aList = [5,4,2,3]
+see "medium : " + median(aList) + nl
+
+func median aray
+ srtd = sort(aray)
+ alen = len(srtd)
+ if alen % 2 = 0
+ return (srtd[alen/2] + srtd[alen/2 + 1]) / 2.0
+ else return srtd[ceil(alen/2)] ok
diff --git a/Task/Averages-Median/Sidef/averages-median.sidef b/Task/Averages-Median/Sidef/averages-median.sidef
new file mode 100644
index 0000000000..f82988ac9c
--- /dev/null
+++ b/Task/Averages-Median/Sidef/averages-median.sidef
@@ -0,0 +1,5 @@
+func median(arry) {
+ var srtd = arry.sort;
+ var alen = srtd.length;
+ srtd[(alen-1)/2]+srtd[alen/2] / 2;
+}
diff --git a/Task/Averages-Median/Wortel/averages-median.wortel b/Task/Averages-Median/Wortel/averages-median.wortel
new file mode 100644
index 0000000000..c6a9f6533f
--- /dev/null
+++ b/Task/Averages-Median/Wortel/averages-median.wortel
@@ -0,0 +1,14 @@
+@let {
+ ; iterative
+ med1 &l @let {a @sort l s #a i @/s 2 ?{%%s 2 ~/ 2 +`-i 1 a `i a `i a}}
+
+ ; tacit
+ med2 ^(\~/2 @sum @(^(\&![#~f #~c] \~/2 \~-1 #) @` @id) @sort)
+
+ [[
+ !med1 [4 2 5 2 1]
+ !med1 [4 5 2 1]
+ !med2 [4 2 5 2 1]
+ !med2 [4 5 2 1]
+ ]]
+}
diff --git a/Task/Averages-Median/jq/averages-median-1.jq b/Task/Averages-Median/jq/averages-median-1.jq
new file mode 100644
index 0000000000..006fc34fc4
--- /dev/null
+++ b/Task/Averages-Median/jq/averages-median-1.jq
@@ -0,0 +1,10 @@
+def median:
+ length as $length
+ | sort as $s
+ | if $length == 0 then null
+ else ($length / 2 | floor) as $l2
+ | if ($length % 2) == 0 then
+ ($s[$l2 - 1] + $s[$l2]) / 2
+ else $s[$l2]
+ end
+ end ;
diff --git a/Task/Averages-Median/jq/averages-median-2.jq b/Task/Averages-Median/jq/averages-median-2.jq
new file mode 100644
index 0000000000..528a1d6549
--- /dev/null
+++ b/Task/Averages-Median/jq/averages-median-2.jq
@@ -0,0 +1,2 @@
+[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
+[4.1, 7.2, 1.7, 9.3, 4.4, 3.2]
diff --git a/Task/Averages-Median/jq/averages-median-3.jq b/Task/Averages-Median/jq/averages-median-3.jq
new file mode 100644
index 0000000000..5b70173338
--- /dev/null
+++ b/Task/Averages-Median/jq/averages-median-3.jq
@@ -0,0 +1,3 @@
+$ jq -f median.jq in.dat
+4.4
+4.25
diff --git a/Task/Averages-Mode/ERRE/averages-mode.erre b/Task/Averages-Mode/ERRE/averages-mode.erre
new file mode 100644
index 0000000000..7915ba0a41
--- /dev/null
+++ b/Task/Averages-Mode/ERRE/averages-mode.erre
@@ -0,0 +1,61 @@
+PROGRAM MODE_AVG
+
+!$INTEGER
+
+DIM A[10],B[10],Z[10]
+
+PROCEDURE SORT(Z[],P->Z[])
+ LOCAL N,FLIPS
+ FLIPS=TRUE
+ WHILE FLIPS DO
+ FLIPS=FALSE
+ FOR N=0 TO P-1 DO
+ IF Z[N]>Z[N+1] THEN SWAP(Z[N],Z[N+1]) FLIPS=TRUE
+ END FOR
+ END WHILE
+END PROCEDURE
+
+PROCEDURE CALC_MODE(Z[],P->MODES$)
+ LOCAL I,OCCURRENCE,MAXOCCURRENCE,OLDVAL
+ SORT(Z[],P->Z[])
+ OCCURENCE=1
+ MAXOCCURENCE=0
+ OLDVAL=Z[0]
+ MODES$=""
+ FOR I=1 TO P DO
+ IF Z[I]=OLDVAL THEN
+ OCCURENCE=OCCURENCE+1
+ ELSE
+ IF OCCURENCE>MAXOCCURENCE THEN
+ MAXOCCURENCE=OCCURENCE
+ MODES$=STR$(OLDVAL)
+ ELSIF OCCURENCE=MAXOCCURENCE THEN
+ MODES$=MODES$+STR$(OLDVAL)
+ ELSE
+ !$NULL
+ END IF
+ OCCURENCE=1
+ END IF
+ OLDVAL=Z[I]
+ END FOR
+ !check after loop
+ IF OCCURENCE>MAXOCCURENCE THEN
+ MAXOCCURENCE=OCCURENCE
+ MODES$=STR$(OLDVAL)
+ ELSIF OCCURENCE=MAXOCCURENCE THEN
+ MODES$=MODES$+STR$(OLDVAL)
+ ELSE
+ !$NULL
+ END IF
+END PROCEDURE
+
+BEGIN
+ A[]=(1,3,6,6,6,6,7,7,12,12,17)
+ B[]=(1,2,4,4,1)
+ PRINT("Modes for array A (1,3,6,6,6,6,7,7,12,12,17)";)
+ CALC_MODE(A[],10->MODES$)
+ PRINT(MODES$)
+ PRINT("Modes for array B (1,2,4,4,1)";)
+ CALC_MODE(B[],4->MODES$)
+ PRINT(MODES$)
+END PROGRAM
diff --git a/Task/Averages-Mode/EchoLisp/averages-mode.echolisp b/Task/Averages-Mode/EchoLisp/averages-mode.echolisp
new file mode 100644
index 0000000000..5ef3497e2a
--- /dev/null
+++ b/Task/Averages-Mode/EchoLisp/averages-mode.echolisp
@@ -0,0 +1,16 @@
+(define (modes L)
+ (define G (group* L)) ;; sorts and group equal items
+ (define cardmax (for/max [(g G)] (length g)))
+ (map first (filter (lambda(g) (= cardmax (length g))) G)))
+
+(modes '( a b c a d e f))
+ → (a)
+(modes (iota 6))
+ → (0 1 2 3 4 5)
+(modes '(x))
+ → (x)
+(modes '(🎾 🏉 ☕️ 🎾 🎲 🎯 🎺 ☕️ 🎲 🎸 🎻 🏆 ☕️ 🏁 🎾 🎲 🎻 🏉 ))
+ → (🎾 ☕️ 🎲)
+
+(modes '())
+😖️ error: group : expected list : null 🔎 'modes'
diff --git a/Task/Averages-Mode/FreeBASIC/averages-mode.freebasic b/Task/Averages-Mode/FreeBASIC/averages-mode.freebasic
new file mode 100644
index 0000000000..8dc6197023
--- /dev/null
+++ b/Task/Averages-Mode/FreeBASIC/averages-mode.freebasic
@@ -0,0 +1,66 @@
+' FB 1.05.0 Win64
+
+Sub quicksort(a() As Integer, first As Integer, last As Integer)
+ Dim As Integer length = last - first + 1
+ If length < 2 Then Return
+ Dim pivot As Integer = a(first + length\ 2)
+ Dim lft As Integer = first
+ Dim rgt As Integer = last
+ While lft <= rgt
+ While a(lft) < pivot
+ lft +=1
+ Wend
+ While a(rgt) > pivot
+ rgt -= 1
+ Wend
+ If lft <= rgt Then
+ Swap a(lft), a(rgt)
+ lft += 1
+ rgt -= 1
+ End If
+ Wend
+ quicksort(a(), first, rgt)
+ quicksort(a(), lft, last)
+End Sub
+
+' The modal value(s) is/are stored in 'm'.
+' The function returns the modal count.
+Function mode(a() As Integer, m() As Integer, sorted As Boolean = false) As Integer
+ Dim lb As Integer = LBound(a)
+ Dim ub As Integer = UBound(a)
+ If ub = -1 Then Return 0 '' empty array
+ If Not sorted Then quicksort(a(), lb, ub)
+ Dim cValue As Integer = a(lb)
+ Dim cCount As Integer = 1
+ Dim cMax As Integer = 0
+ '' We iterate to the end of the array plus 1 to ensure the
+ '' final value is dealt with properly
+ For i As Integer = lb + 1 To ub + 1
+ If i <= ub AndAlso a(i) = cValue Then
+ cCount += 1
+ Else
+ If cCount > cMax Then
+ Erase m
+ Redim m(1 To 1)
+ m(1) = cValue
+ cMax = cCount
+ ElseIf cCount = cMax Then
+ Redim Preserve m(1 To UBound(m) + 1)
+ m(UBound(m)) = cValue
+ End If
+ If i = ub + 1 Then Exit For
+ cValue = a(i)
+ cCount = 1
+ End If
+ Next
+ Return cMax
+End Function
+
+Dim a(1 To 14) As Integer = {1, 2, 3, 1, 2, 4, 2, 5, 2, 3, 3, 1, 3, 6}
+Dim m() As Integer '' to store the mode(s)
+Dim mCount As Integer = mode(a(), m())
+Print "The following are the modes which occur"; mCount; " times : "
+For i As Integer = LBound(m) To UBound(m) : Print m(i); " "; : Next
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Averages-Mode/Lasso/averages-mode.lasso b/Task/Averages-Mode/Lasso/averages-mode.lasso
new file mode 100644
index 0000000000..fe83ade545
--- /dev/null
+++ b/Task/Averages-Mode/Lasso/averages-mode.lasso
@@ -0,0 +1,12 @@
+define getmode(a::array)::array => {
+ local(mmap = map, maxv = 0, modes = array)
+ // store counts
+ with e in #a do => { #mmap->keys >> #e ? #mmap->find(#e) += 1 | #mmap->insert(#e = 1) }
+ // get max value
+ with e in #mmap->keys do => { #mmap->find(#e) > #maxv ? #maxv = #mmap->find(#e) }
+ // get modes with max value
+ with e in #mmap->keys where #mmap->find(#e) == #maxv do => { #modes->insert(#e) }
+ return #modes
+}
+getmode(array(1,3,6,6,6,6,7,7,12,12,17))
+getmode(array(1,3,6,3,4,8,9,1,2,3,2,2))
diff --git a/Task/Averages-Mode/Nim/averages-mode.nim b/Task/Averages-Mode/Nim/averages-mode.nim
new file mode 100644
index 0000000000..ae044d1de0
--- /dev/null
+++ b/Task/Averages-Mode/Nim/averages-mode.nim
@@ -0,0 +1,10 @@
+import tables
+
+proc modes[T](xs: openArray[T]): T =
+ var count = initCountTable[T]()
+ for x in xs:
+ count.inc(x)
+ largest(count).key
+
+echo modes(@[1,3,6,6,6,6,7,7,12,12,17])
+echo modes(@[1,1,2,4,4])
diff --git a/Task/Averages-Mode/Phix/averages-mode.phix b/Task/Averages-Mode/Phix/averages-mode.phix
new file mode 100644
index 0000000000..bb394f535d
--- /dev/null
+++ b/Task/Averages-Mode/Phix/averages-mode.phix
@@ -0,0 +1,40 @@
+function mode(sequence s)
+-- returns a list of the most common values, each of which occurs the same number of times
+object this
+integer nxt = 1, count = 1, maxc = 1
+sequence res = {}
+ if length(s)!=0 then
+ s = sort(s)
+ this = s[1]
+ for i=2 to length(s) do
+ if s[i]!=this then
+ s[nxt] = {count,this}
+ nxt += 1
+ this = s[i]
+ count = 1
+ else
+ count += 1
+ if count>maxc then
+ maxc = count
+ end if
+ end if
+ end for
+ s[nxt] = {count,this}
+ res = ""
+ for i=1 to nxt do
+ if s[i][1]=maxc then
+ res = append(res,s[i][2])
+ end if
+ end for
+ end if
+ return res
+end function
+
+?mode({1, 2, 5, -5, -9.5, 3.14159})
+?mode({ 1, "blue", 2, 7.5, 5, "green", "red", 5, 2, "blue", "white" })
+?mode({1, 2, 3, 1, 2, 4, 2, 5, 2, 3, 3, 1, 3, 6})
+?mode({.2, .7, .1, .8, .2})
+?mode({"two", 7, 1, 8, "two", 8})
+?mode("Hello there world")
+?mode({})
+{} = wait_key()
diff --git a/Task/Averages-Mode/Sidef/averages-mode-1.sidef b/Task/Averages-Mode/Sidef/averages-mode-1.sidef
new file mode 100644
index 0000000000..ceedb684f1
--- /dev/null
+++ b/Task/Averages-Mode/Sidef/averages-mode-1.sidef
@@ -0,0 +1,6 @@
+func mode(array) {
+ var c = Hash.new;
+ array.each{|i| c{i} := 0 ++};
+ var max = c.values.max;
+ c.keys.grep{|i| c{i} == max};
+}
diff --git a/Task/Averages-Mode/Sidef/averages-mode-2.sidef b/Task/Averages-Mode/Sidef/averages-mode-2.sidef
new file mode 100644
index 0000000000..04c17cf222
--- /dev/null
+++ b/Task/Averages-Mode/Sidef/averages-mode-2.sidef
@@ -0,0 +1,2 @@
+say mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]).join(' ');
+say mode([1, 1, 2, 4, 4]).join(' ');
diff --git a/Task/Averages-Mode/Sidef/averages-mode-3.sidef b/Task/Averages-Mode/Sidef/averages-mode-3.sidef
new file mode 100644
index 0000000000..3c3aee7e1d
--- /dev/null
+++ b/Task/Averages-Mode/Sidef/averages-mode-3.sidef
@@ -0,0 +1,3 @@
+func one_mode(arr) {
+ arr.max_by{|i| arr.count(i)};
+}
diff --git a/Task/Averages-Mode/Wren/averages-mode.wren b/Task/Averages-Mode/Wren/averages-mode.wren
new file mode 100644
index 0000000000..04315207ea
--- /dev/null
+++ b/Task/Averages-Mode/Wren/averages-mode.wren
@@ -0,0 +1,13 @@
+class Arithmetic {
+ static mode(arr) {
+ var map = {}
+ for (e in arr) {
+ if (map[e] == null) map[e] = 0
+ map[e] = map[e] + 1
+ }
+ var max = map.values.reduce {|x, y| x > y ? x : y}
+ return map.keys.where {|x| map[x] == max}.toList
+ }
+}
+
+System.print(Arithmetic.mode([1,2,3,4,5,5,51,2,3]))
diff --git a/Task/Averages-Mode/jq/averages-mode-1.jq b/Task/Averages-Mode/jq/averages-mode-1.jq
new file mode 100644
index 0000000000..cdffaf2d3c
--- /dev/null
+++ b/Task/Averages-Mode/jq/averages-mode-1.jq
@@ -0,0 +1,19 @@
+# modes/0 produces an array of [value, count]
+# in increasing order of count:
+def modes:
+ sort | reduce .[] as $i ([];
+ # state variable is an array of [value, count]
+ if length == 0 then [ [$i, 1] ]
+ elif .[-1][0] == $i then setpath([-1,1]; .[-1][1] + 1)
+ else . + [[$i,1]]
+ end )
+ | sort_by( .[1] );
+
+# mode/0 outputs a stream of the modal values;
+# if the input array is empty, the output stream is also empty.
+def mode:
+ if length == 0 then empty
+ else modes as $modes
+ | $modes[-1][1] as $count
+ | $modes[] | select( .[1] == $count) | .[0]
+ end;
diff --git a/Task/Averages-Mode/jq/averages-mode-2.jq b/Task/Averages-Mode/jq/averages-mode-2.jq
new file mode 100644
index 0000000000..b86a8efadf
--- /dev/null
+++ b/Task/Averages-Mode/jq/averages-mode-2.jq
@@ -0,0 +1,3 @@
+[1,2,3,1,2,1] | mode # => 1
+[1,2,3,1,2,1,2] | mode # => 1 2
+[1.1, 1.2, 1.3, 1.1, 1.2, 1.1] | mode) # => 1.1
diff --git a/Task/Averages-Pythagorean-means/ERRE/averages-pythagorean-means.erre b/Task/Averages-Pythagorean-means/ERRE/averages-pythagorean-means.erre
new file mode 100644
index 0000000000..aa3f8b1cff
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/ERRE/averages-pythagorean-means.erre
@@ -0,0 +1,43 @@
+PROGRAM MEANS
+
+DIM A[9]
+
+PROCEDURE ARITHMETIC_MEAN(A[]->M)
+ LOCAL S,I%
+ NEL%=UBOUND(A,1)
+ S=0
+ FOR I%=0 TO NEL% DO
+ S+=A[I%]
+ END FOR
+ M=S/(NEL%+1)
+END PROCEDURE
+
+PROCEDURE GEOMETRIC_MEAN(A[]->M)
+ LOCAL S,I%
+ NEL%=UBOUND(A,1)
+ S=1
+ FOR I%=0 TO NEL% DO
+ S*=A[I%]
+ END FOR
+ M=S^(1/(NEL%+1))
+END PROCEDURE
+
+PROCEDURE HARMONIC_MEAN(A[]->M)
+ LOCAL S,I%
+ NEL%=UBOUND(A,1)
+ S=0
+ FOR I%=0 TO NEL% DO
+ S+=1/A[I%]
+ END FOR
+ M=(NEL%+1)/S
+END PROCEDURE
+
+BEGIN
+ A[]=(1,2,3,4,5,6,7,8,9,10)
+ ARITHMETIC_MEAN(A[]->M)
+ PRINT("Arithmetic mean = ";M)
+ GEOMETRIC_MEAN(A[]->M)
+ PRINT("Geometric mean = ";M)
+ HARMONIC_MEAN(A[]->M)
+ PRINT("Harmonic mean = ";M)
+END PROGRAM
diff --git a/Task/Averages-Pythagorean-means/EchoLisp/averages-pythagorean-means.echolisp b/Task/Averages-Pythagorean-means/EchoLisp/averages-pythagorean-means.echolisp
new file mode 100644
index 0000000000..ae22b35cc5
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/EchoLisp/averages-pythagorean-means.echolisp
@@ -0,0 +1,9 @@
+(define (A xs) (// (for/sum ((x xs)) x) (length xs)))
+
+(define (G xs) (expt (for/product ((x xs)) x) (// (length xs))))
+
+(define (H xs) (// (length xs) (for/sum ((x xs)) (// x))))
+
+(define xs (range 1 11))
+(and (>= (A xs) (G xs)) (>= (G xs) (H xs)))
+ → #t
diff --git a/Task/Averages-Pythagorean-means/FreeBASIC/averages-pythagorean-means.freebasic b/Task/Averages-Pythagorean-means/FreeBASIC/averages-pythagorean-means.freebasic
new file mode 100644
index 0000000000..947c3365d6
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/FreeBASIC/averages-pythagorean-means.freebasic
@@ -0,0 +1,40 @@
+' FB 1.05.0 Win64
+
+Function ArithmeticMean(array() As Double) As Double
+ Dim length As Integer = Ubound(array) - Lbound(array) + 1
+ Dim As Double sum = 0.0
+ For i As Integer = LBound(array) To UBound(array)
+ sum += array(i)
+ Next
+ Return sum/length
+End Function
+
+Function GeometricMean(array() As Double) As Double
+ Dim length As Integer = Ubound(array) - Lbound(array) + 1
+ Dim As Double product = 1.0
+ For i As Integer = LBound(array) To UBound(array)
+ product *= array(i)
+ Next
+ Return product ^ (1.0 / length)
+End Function
+
+Function HarmonicMean(array() As Double) As Double
+ Dim length As Integer = Ubound(array) - Lbound(array) + 1
+ Dim As Double sum = 0.0
+ For i As Integer = LBound(array) To UBound(array)
+ sum += 1.0 / array(i)
+ Next
+ Return length / sum
+End Function
+
+Dim vector(1 To 10) As Double
+For i As Integer = 1 To 10
+ vector(i) = i
+Next
+
+Print "Arithmetic mean is :"; ArithmeticMean(vector())
+Print "Geometric mean is :"; GeometricMean(vector())
+Print "Harmonic mean is :"; HarmonicMean(vector())
+Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Averages-Pythagorean-means/FunL/averages-pythagorean-means.funl b/Task/Averages-Pythagorean-means/FunL/averages-pythagorean-means.funl
new file mode 100644
index 0000000000..753e5ca8d8
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/FunL/averages-pythagorean-means.funl
@@ -0,0 +1,16 @@
+import lists.zip
+
+def
+ mean( s, 0 ) = product( s )^(1/s.length())
+ mean( s, p ) = (1/s.length() sum( x^p | x <- s ))^(1/p)
+
+def
+ monotone( [_], _ ) = true
+ monotone( a1:a2:as, p ) = p( a1, a2 ) and monotone( a2:as, p )
+
+means = [mean( 1..10, m ) | m <- [1, 0, -1]]
+
+for (m, l) <- zip( means, ['Arithmetic', 'Geometric', 'Harmonic'] )
+ println( "$l: $m" + (if m is Rational then " or ${m.doubleValue()}" else '') )
+
+println( monotone(means, (>=)) )
diff --git a/Task/Averages-Pythagorean-means/Futhark/averages-pythagorean-means.futhark b/Task/Averages-Pythagorean-means/Futhark/averages-pythagorean-means.futhark
new file mode 100644
index 0000000000..480f2732b7
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Futhark/averages-pythagorean-means.futhark
@@ -0,0 +1,13 @@
+fun arithmetic_mean(as: [n]f64): f64 =
+ reduce (+) 0.0 (map (/f64(n)) as)
+
+fun geometric_mean(as: [n]f64): f64 =
+ reduce (*) 1.0 (map (**(1.0/f64(n))) as)
+
+fun harmonic_mean(as: [n]f64): f64 =
+ f64(n) / reduce (+) 0.0 (map (1.0/) as)
+
+fun main(as: [n]f64): (f64,f64,f64) =
+ (arithmetic_mean as,
+ geometric_mean as,
+ harmonic_mean as)
diff --git a/Task/Averages-Pythagorean-means/Lasso/averages-pythagorean-means.lasso b/Task/Averages-Pythagorean-means/Lasso/averages-pythagorean-means.lasso
new file mode 100644
index 0000000000..a52a4a4f19
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Lasso/averages-pythagorean-means.lasso
@@ -0,0 +1,18 @@
+define arithmetic_mean(a::staticarray)::decimal => {
+ //sum of the list divided by its length
+ return (with e in #a sum #e) / decimal(#a->size)
+}
+define geometric_mean(a::staticarray)::decimal => {
+ // The geometric mean is the nth root of the product of the list
+ local(prod = 1)
+ with e in #a do => { #prod *= #e }
+ return math_pow(#prod,1/decimal(#a->size))
+}
+define harmonic_mean(a::staticarray)::decimal => {
+ // The harmonic mean is n divided by the sum of the reciprocal of each item in the list
+ return decimal(#a->size)/(with e in #a sum 1/decimal(#e))
+}
+
+arithmetic_mean(generateSeries(1,10)->asStaticArray)
+geometric_mean(generateSeries(1,10)->asStaticArray)
+harmonic_mean(generateSeries(1,10)->asStaticArray)
diff --git a/Task/Averages-Pythagorean-means/Nim/averages-pythagorean-means.nim b/Task/Averages-Pythagorean-means/Nim/averages-pythagorean-means.nim
new file mode 100644
index 0000000000..b0f1278695
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Nim/averages-pythagorean-means.nim
@@ -0,0 +1,25 @@
+import math, sequtils, future
+
+proc amean(num): float =
+ sum(num) / float(len(num))
+
+proc gmean(num): float =
+ result = 1
+ for n in num: result *= n
+ result = pow(result, 1.0 / float(num.len))
+
+proc hmean(num): float =
+ for n in num: result += 1.0 / n
+ result = float(num.len) / result
+
+proc ameanFunctional(num: seq[float]): float =
+ sum(num) / float(num.len)
+
+proc gmeanFunctional(num: seq[float]): float =
+ num.foldl(a * b).pow(1.0 / float(num.len))
+
+proc hmeanFunctional(num: seq[float]): float =
+ float(num.len) / sum(num.mapIt(float, 1.0 / it))
+
+let numbers = toSeq(1..10).map((x: int) => float(x))
+echo amean(numbers), " ", gmean(numbers), " ", hmean(numbers)
diff --git a/Task/Averages-Pythagorean-means/Oforth/averages-pythagorean-means.oforth b/Task/Averages-Pythagorean-means/Oforth/averages-pythagorean-means.oforth
new file mode 100644
index 0000000000..c061f928b9
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Oforth/averages-pythagorean-means.oforth
@@ -0,0 +1,9 @@
+: A(l) l avg ;
+: G(l) l prod l size inv powf ;
+: H(l) l size l map(#inv) sum / ;
+
+: averages
+| g |
+ "Geometric mean :" . G(10 seq) dup .cr ->g
+ "Arithmetic mean :" . A(10 seq) dup . g >= ifTrue: [ " ==> A >= G" .cr ]
+ "Harmonic mean :" . H(10 seq) dup . g <= ifTrue: [ " ==> G >= H" .cr ] ;
diff --git a/Task/Averages-Pythagorean-means/Phix/averages-pythagorean-means.phix b/Task/Averages-Pythagorean-means/Phix/averages-pythagorean-means.phix
new file mode 100644
index 0000000000..331ea2dac1
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Phix/averages-pythagorean-means.phix
@@ -0,0 +1,32 @@
+function arithmetic_mean(sequence s)
+ return sum(s)/length(s)
+end function
+
+function geometric_mean(sequence s)
+atom p = 1
+ for i=1 to length(s) do
+ p *= s[i]
+ end for
+ return power(p,1/length(s))
+end function
+
+function harmonic_mean(sequence s)
+atom rsum = 0
+ for i=1 to length(s) do
+ rsum += 1/s[i]
+ end for
+ return length(s)/rsum
+end function
+
+function iff(integer condition, object Tval, object Fval)
+ if condition then return Tval else return Fval end if
+end function
+
+constant s = {1,2,3,4,5,6,7,8,9,10}
+constant arithmetic = arithmetic_mean(s),
+ geometric = geometric_mean(s),
+ harmonic = harmonic_mean(s)
+printf(1,"Arithmetic: %.10g\n", arithmetic)
+printf(1,"Geometric: %.10g\n", geometric)
+printf(1,"Harmonic: %.10g\n", harmonic)
+printf(1,"Arithmetic>=Geometric>=Harmonic: %s\n", {iff((arithmetic>=geometric and geometric>=harmonic),"true","false")})
diff --git a/Task/Averages-Pythagorean-means/Ring/averages-pythagorean-means.ring b/Task/Averages-Pythagorean-means/Ring/averages-pythagorean-means.ring
new file mode 100644
index 0000000000..b49f9745f5
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Ring/averages-pythagorean-means.ring
@@ -0,0 +1,29 @@
+decimals(8)
+array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+see "arithmetic mean = " + arithmeticMean(array) + nl
+see "geometric mean = " + geometricMean(array) + nl
+see "harmonic mean = " + harmonicMean(array) + nl
+
+func arithmeticMean a
+ return summary(a) / len(a)
+
+func geometricMean a
+ b = 1
+ for i = 1 to len(a)
+ b *= a[i]
+ next
+ return pow(b, (1/len(a)))
+
+func harmonicMean a
+ b = list(len(a))
+ for nr = 1 to len(a)
+ b[nr] = 1/a[nr]
+ next
+ return len(a) / summary(b)
+
+func summary s
+ sum = 0
+ for n = 1 to len(s)
+ sum += s[n]
+ next
+ return sum
diff --git a/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-1.sidef b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-1.sidef
new file mode 100644
index 0000000000..9231b9c399
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-1.sidef
@@ -0,0 +1,3 @@
+func A(a) { a.sum / a.len }
+func G(a) { a.prod.root(a.len) }
+func H(a) { a.len / a.map{1/_}.sum }
diff --git a/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-2.sidef b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-2.sidef
new file mode 100644
index 0000000000..5e3697e0aa
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-2.sidef
@@ -0,0 +1,3 @@
+func A(a) { a«+» / a.len }
+func G(a) { a«*» ** (1/a.len) }
+func H(a) { a.len / (a«/«1 «+») }
diff --git a/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-3.sidef b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-3.sidef
new file mode 100644
index 0000000000..dedb93bbb6
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/Sidef/averages-pythagorean-means-3.sidef
@@ -0,0 +1,3 @@
+say("A(1,...,10) = ", A(1..10));
+say("G(1,...,10) = ", G(1..10));
+say("H(1,...,10) = ", H(1..10));
diff --git a/Task/Averages-Pythagorean-means/jq/averages-pythagorean-means.jq b/Task/Averages-Pythagorean-means/jq/averages-pythagorean-means.jq
new file mode 100644
index 0000000000..cd8a6f8c2a
--- /dev/null
+++ b/Task/Averages-Pythagorean-means/jq/averages-pythagorean-means.jq
@@ -0,0 +1,12 @@
+def amean: add/length;
+
+def logProduct: map(log) | add;
+
+def gmean: (logProduct / length) | exp;
+
+def hmean: length / (map(1/.) | add);
+
+# Tasks:
+ [range(1;11) ] | [amean, gmean, hmean] as $ans
+ | ( $ans[],
+ "amean > gmean > hmean => \($ans[0] > $ans[1] and $ans[1] > $ans[2] )" )
diff --git a/Task/Averages-Root-mean-square/ERRE/averages-root-mean-square.erre b/Task/Averages-Root-mean-square/ERRE/averages-root-mean-square.erre
new file mode 100644
index 0000000000..bfcfda6081
--- /dev/null
+++ b/Task/Averages-Root-mean-square/ERRE/averages-root-mean-square.erre
@@ -0,0 +1,9 @@
+PROGRAM ROOT_MEAN_SQUARE
+BEGIN
+ N=10
+ FOR I=1 TO N DO
+ S=S+I*I
+ END FOR
+ X=SQR(S/N)
+ PRINT("Root mean square is";X)
+END PROGRAM
diff --git a/Task/Averages-Root-mean-square/EchoLisp/averages-root-mean-square.echolisp b/Task/Averages-Root-mean-square/EchoLisp/averages-root-mean-square.echolisp
new file mode 100644
index 0000000000..05d48e13c1
--- /dev/null
+++ b/Task/Averages-Root-mean-square/EchoLisp/averages-root-mean-square.echolisp
@@ -0,0 +1,5 @@
+(define (rms xs)
+ (sqrt (// (for/sum ((x xs)) (* x x)) (length xs))))
+
+(rms (range 1 11))
+ → 6.2048368229954285
diff --git a/Task/Averages-Root-mean-square/FreeBASIC/averages-root-mean-square.freebasic b/Task/Averages-Root-mean-square/FreeBASIC/averages-root-mean-square.freebasic
new file mode 100644
index 0000000000..335bc3176b
--- /dev/null
+++ b/Task/Averages-Root-mean-square/FreeBASIC/averages-root-mean-square.freebasic
@@ -0,0 +1,20 @@
+' FB 1.05.0 Win64
+
+Function QuadraticMean(array() As Double) As Double
+ Dim length As Integer = Ubound(array) - Lbound(array) + 1
+ Dim As Double sum = 0.0
+ For i As Integer = LBound(array) To UBound(array)
+ sum += array(i) * array(i)
+ Next
+ Return Sqr(sum/length)
+End Function
+
+Dim vector(1 To 10) As Double
+For i As Integer = 1 To 10
+ vector(i) = i
+Next
+
+Print "Quadratic mean (or RMS) is :"; QuadraticMean(vector())
+Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Averages-Root-mean-square/Futhark/averages-root-mean-square.futhark b/Task/Averages-Root-mean-square/Futhark/averages-root-mean-square.futhark
new file mode 100644
index 0000000000..d1e296e87d
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Futhark/averages-root-mean-square.futhark
@@ -0,0 +1,2 @@
+fun main(as: [n]f64): f64 =
+ sqrt64 ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))
diff --git a/Task/Averages-Root-mean-square/GEORGE/averages-root-mean-square.george b/Task/Averages-Root-mean-square/GEORGE/averages-root-mean-square.george
new file mode 100644
index 0000000000..ba1cd2b0ee
--- /dev/null
+++ b/Task/Averages-Root-mean-square/GEORGE/averages-root-mean-square.george
@@ -0,0 +1,9 @@
+1, 10 rep (i)
+ i i | (v) ;
+0
+ 1, 10 rep (i)
+ i dup mult +
+ ]
+10 div
+ sqrt
+ print
diff --git a/Task/Averages-Root-mean-square/Lasso/averages-root-mean-square.lasso b/Task/Averages-Root-mean-square/Lasso/averages-root-mean-square.lasso
new file mode 100644
index 0000000000..6c9c7fec85
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Lasso/averages-root-mean-square.lasso
@@ -0,0 +1,4 @@
+define rms(a::staticarray)::decimal => {
+ return math_sqrt((with n in #a sum #n*#n) / decimal(#a->size))
+}
+rms(generateSeries(1,10)->asStaticArray)
diff --git a/Task/Averages-Root-mean-square/Morfa/averages-root-mean-square.morfa b/Task/Averages-Root-mean-square/Morfa/averages-root-mean-square.morfa
new file mode 100644
index 0000000000..2f653da452
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Morfa/averages-root-mean-square.morfa
@@ -0,0 +1,14 @@
+import morfa.base;
+import morfa.functional.base;
+
+template
+func rms(d: TRange): float
+{
+ var count = 1;
+ return sqrt(reduce( (a: float, b: float) { count += 1; return a + b * b; }, d) / count);
+}
+
+func main(): void
+{
+ println(rms(1 .. 11));
+}
diff --git a/Task/Averages-Root-mean-square/Nim/averages-root-mean-square.nim b/Task/Averages-Root-mean-square/Nim/averages-root-mean-square.nim
new file mode 100644
index 0000000000..670470ffcb
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Nim/averages-root-mean-square.nim
@@ -0,0 +1,8 @@
+import math
+
+proc qmean(num): float =
+ for n in num:
+ result += n*n
+ result = sqrt(result / float(num.len))
+
+echo qmean([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0])
diff --git a/Task/Averages-Root-mean-square/Oforth/averages-root-mean-square.oforth b/Task/Averages-Root-mean-square/Oforth/averages-root-mean-square.oforth
new file mode 100644
index 0000000000..4ea5d1becf
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Oforth/averages-root-mean-square.oforth
@@ -0,0 +1 @@
+10 seq map(#sq) sum 10.0 / sqrt .
diff --git a/Task/Averages-Root-mean-square/Phix/averages-root-mean-square.phix b/Task/Averages-Root-mean-square/Phix/averages-root-mean-square.phix
new file mode 100644
index 0000000000..c31c1560e2
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Phix/averages-root-mean-square.phix
@@ -0,0 +1,9 @@
+function rms(sequence s)
+atom sqsum = 0
+ for i=1 to length(s) do
+ sqsum += power(s[i],2)
+ end for
+ return sqrt(sqsum/length(s))
+end function
+
+? rms({1,2,3,4,5,6,7,8,9,10})
diff --git a/Task/Averages-Root-mean-square/Powerbuilder/averages-root-mean-square.powerbuilder b/Task/Averages-Root-mean-square/Powerbuilder/averages-root-mean-square.powerbuilder
new file mode 100644
index 0000000000..9cb2aaea9a
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Powerbuilder/averages-root-mean-square.powerbuilder
@@ -0,0 +1,12 @@
+long ll_x, ll_y, ll_product
+decimal ld_rms
+
+ll_x = 1
+ll_y = 10
+DO WHILE ll_x <= ll_y
+ ll_product += ll_x * ll_x
+ ll_x ++
+LOOP
+ld_rms = Sqrt(ll_product / ll_y)
+
+//ld_rms value is 6.20483682299542849
diff --git a/Task/Averages-Root-mean-square/Ring/averages-root-mean-square.ring b/Task/Averages-Root-mean-square/Ring/averages-root-mean-square.ring
new file mode 100644
index 0000000000..c61e32b1aa
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Ring/averages-root-mean-square.ring
@@ -0,0 +1,11 @@
+nums = [1,2,3,4,5,6,7,8,9,10]
+sum = 0
+decimals(5)
+see "Average = " + average(nums) + nl
+
+func average number
+ for i = 1 to len(number)
+ sum = sum + pow(number[i],2)
+ next
+ x = sqrt(sum / len(number))
+ return x
diff --git a/Task/Averages-Root-mean-square/Sidef/averages-root-mean-square.sidef b/Task/Averages-Root-mean-square/Sidef/averages-root-mean-square.sidef
new file mode 100644
index 0000000000..bc1ce57f90
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Sidef/averages-root-mean-square.sidef
@@ -0,0 +1,5 @@
+func rms(a) {
+ Math.sqrt(a.map{.**2}.sum / a.len);
+}
+
+say rms(1..10);
diff --git a/Task/Averages-Root-mean-square/Wortel/averages-root-mean-square.wortel b/Task/Averages-Root-mean-square/Wortel/averages-root-mean-square.wortel
new file mode 100644
index 0000000000..0ab161285a
--- /dev/null
+++ b/Task/Averages-Root-mean-square/Wortel/averages-root-mean-square.wortel
@@ -0,0 +1,12 @@
+@let {
+ ; using a composition and a fork (like you would do in J)
+ rms1 ^(@sqrt @(@sum / #) *^@sq)
+
+ ; using a function with a named argument
+ rms2 &a @sqrt ~/ #a @sum !*^@sq a
+
+ [[
+ !rms1 @to 10
+ !rms2 @to 10
+ ]]
+}
diff --git a/Task/Averages-Root-mean-square/XLISP/averages-root-mean-square.xlisp b/Task/Averages-Root-mean-square/XLISP/averages-root-mean-square.xlisp
new file mode 100644
index 0000000000..8eef3b4acd
--- /dev/null
+++ b/Task/Averages-Root-mean-square/XLISP/averages-root-mean-square.xlisp
@@ -0,0 +1,16 @@
+(defun quadratic-mean (xs)
+ (sqrt
+ (/
+ (apply +
+ (mapcar (lambda (x) (expt x 2)) xs))
+ (length xs))))
+
+; define a RANGE function, for testing purposes
+
+(defun range (x y)
+ (if (< x y)
+ (cons x (range (+ x 1) y))))
+
+; test QUADRATIC-MEAN
+
+(print (quadratic-mean (range 1 11)))
diff --git a/Task/Averages-Root-mean-square/jq/averages-root-mean-square-1.jq b/Task/Averages-Root-mean-square/jq/averages-root-mean-square-1.jq
new file mode 100644
index 0000000000..6e75a34df8
--- /dev/null
+++ b/Task/Averages-Root-mean-square/jq/averages-root-mean-square-1.jq
@@ -0,0 +1,4 @@
+def rms: length as $length
+ | if $length == 0 then null
+ else map(. * .) | add | sqrt / $length
+ end ;
diff --git a/Task/Averages-Root-mean-square/jq/averages-root-mean-square-2.jq b/Task/Averages-Root-mean-square/jq/averages-root-mean-square-2.jq
new file mode 100644
index 0000000000..baa67a5516
--- /dev/null
+++ b/Task/Averages-Root-mean-square/jq/averages-root-mean-square-2.jq
@@ -0,0 +1 @@
+rms
diff --git a/Task/Averages-Simple-moving-average/EchoLisp/averages-simple-moving-average.echolisp b/Task/Averages-Simple-moving-average/EchoLisp/averages-simple-moving-average.echolisp
new file mode 100644
index 0000000000..2fc52af9e6
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/EchoLisp/averages-simple-moving-average.echolisp
@@ -0,0 +1,10 @@
+(lib 'tree) ;; queues operations
+
+
+(define (make-sma p)
+ (define Q (queue (gensym)))
+ (lambda (item)
+ (q-push Q item)
+ (when (> (queue-length Q) p) (q-pop Q))
+ (// (for/sum ((x (queue->list Q))) x) (queue-length Q))))
+
diff --git a/Task/Averages-Simple-moving-average/FreeBASIC/averages-simple-moving-average.freebasic b/Task/Averages-Simple-moving-average/FreeBASIC/averages-simple-moving-average.freebasic
new file mode 100644
index 0000000000..31172e0475
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/FreeBASIC/averages-simple-moving-average.freebasic
@@ -0,0 +1,46 @@
+' FB 1.05.0 Win64
+
+Type FuncType As Function(As Double) As Double
+
+' These 'shared' variables are available to all functions defined below
+Dim Shared p As UInteger
+Dim Shared list() As Double
+
+Function sma(n As Double) As Double
+ Redim Preserve list(0 To UBound(list) + 1)
+ list(UBound(list)) = n
+ Dim start As Integer = 0
+ Dim length As Integer = UBound(list) + 1
+ If length > p Then
+ start = UBound(list) - p + 1
+ length = p
+ End If
+ Dim sum As Double = 0.0
+ For i As Integer = start To UBound(list)
+ sum += list(i)
+ Next
+ Return sum / length
+End Function
+
+Function initSma(period As Uinteger) As FuncType
+ p = period
+ Erase list '' ensure the array is empty on each initialization
+ Return @sma
+End Function
+
+Dim As FuncType ma = initSma(3)
+Print "Period = "; p
+Print
+For i As Integer = 0 To 9
+ Print "Add"; i; " => moving average ="; ma(i)
+Next
+Print
+ma = initSma(5)
+Print "Period = "; p
+Print
+For i As Integer = 9 To 0 Step -1
+ Print "Add"; i; " => moving average ="; ma(i)
+Next
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Averages-Simple-moving-average/Lasso/averages-simple-moving-average.lasso b/Task/Averages-Simple-moving-average/Lasso/averages-simple-moving-average.lasso
new file mode 100644
index 0000000000..8e0aaa32c9
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Lasso/averages-simple-moving-average.lasso
@@ -0,0 +1,32 @@
+define simple_moving_average(a::array,s::integer)::decimal => {
+ #a->size == 0 ? return 0.00
+ #s == 0 ? return 0.00
+ #a->size == 1 ? return decimal(#a->first)
+ #s == 1 ? return decimal(#a->last)
+ local(na = array)
+ if(#a->size <= #s) => {
+ #na = #a
+ else
+ local(ar = #a->ascopy)
+ #ar->reverse
+ loop(#s) => { #na->insert(#ar->get(loop_count)) }
+ }
+ #s > #na->size ? #s = #na->size
+ return (with e in #na sum #e) / decimal(#s)
+}
+// tests:
+'SMA 3 on array(1,2,3,4,5,5,4,3,2,1): '
+simple_moving_average(array(1,2,3,4,5,5,4,3,2,1),3)
+
+'\rSMA 5 on array(1,2,3,4,5,5,4,3,2,1): '
+simple_moving_average(array(1,2,3,4,5,5,4,3,2,1),5)
+
+'\r\rFurther example: \r'
+local(mynumbers = array, sma_num = 5)
+loop(10) => {^
+ #mynumbers->insert(integer_random(1,100))
+ #mynumbers->size + ' numbers: ' + #mynumbers
+ ' SMA3 is: ' + simple_moving_average(#mynumbers,3)
+ ', SMA5 is: ' + simple_moving_average(#mynumbers,5)
+ '\r'
+^}
diff --git a/Task/Averages-Simple-moving-average/Nim/averages-simple-moving-average.nim b/Task/Averages-Simple-moving-average/Nim/averages-simple-moving-average.nim
new file mode 100644
index 0000000000..df1aee5467
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Nim/averages-simple-moving-average.nim
@@ -0,0 +1,28 @@
+import queues
+
+proc simplemovingaverage(period: int): auto =
+ assert period > 0
+
+ var
+ summ, n = 0.0
+ values = initQueue[float]()
+ for i in 1..period:
+ values.add(0)
+
+ proc sma(x: float): float =
+ values.add(x)
+ summ += x - values.dequeue()
+ n = min(n+1, float(period))
+ result = summ / n
+
+ return sma
+
+var sma = simplemovingaverage(3)
+for i in 1..5: echo sma(float(i))
+for i in countdown(5,1): echo sma(float(i))
+
+echo ""
+
+var sma2 = simplemovingaverage(5)
+for i in 1..5: echo sma2(float(i))
+for i in countdown(5,1): echo sma2(float(i))
diff --git a/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-1.oforth b/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-1.oforth
new file mode 100644
index 0000000000..22d169983c
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-1.oforth
@@ -0,0 +1,6 @@
+import: parallel
+
+: createSMA(period)
+| ch |
+ Channel new [ ] over send drop ->ch
+ #[ ch receive + left(period) dup avg swap ch send drop ] ;
diff --git a/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-2.oforth b/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-2.oforth
new file mode 100644
index 0000000000..f296a67a47
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Oforth/averages-simple-moving-average-2.oforth
@@ -0,0 +1,7 @@
+: test
+| sma3 sma5 l |
+ 3 createSMA -> sma3
+ 5 createSMA -> sma5
+ [ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 ] ->l
+ "SMA3" .cr l apply( #[ sma3 perform . ] ) printcr
+ "SMA5" .cr l apply( #[ sma5 perform . ] ) ;
diff --git a/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-1.phix b/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-1.phix
new file mode 100644
index 0000000000..d682347b7d
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-1.phix
@@ -0,0 +1,50 @@
+sequence sma = {} -- {{period,history,circnxt}} (private to sma.e)
+integer sma_free = 0
+
+global function new_sma(integer period)
+integer res
+ if sma_free then
+ res = sma_free
+ sma_free = sma[sma_free]
+ sma[res] = {period,{},0}
+ else
+ sma = append(sma,{period,{},0})
+ res = length(sma)
+ end if
+ return res
+end function
+
+global procedure add_sma(integer sidx, atom val)
+integer period, circnxt
+sequence history
+ {period,history,circnxt} = sma[sidx]
+ sma[sidx][2] = 0 -- (kill refcount)
+ if length(history)period then
+ circnxt = 1
+ end if
+ sma[sidx][3] = circnxt
+ history[circnxt] = val
+ end if
+ sma[sidx][2] = history
+end procedure
+
+global function get_sma_average(integer sidx)
+sequence history = sma[sidx][2]
+integer l = length(history)
+ if l=0 then return 0 end if
+ return sum(history)/l
+end function
+
+global function moving_average(integer sidx, atom val)
+ add_sma(sidx,val)
+ return get_sma_average(sidx)
+end function
+
+global procedure free_sma(integer sidx)
+ sma[sidx] = sma_free
+ sma_free = sidx
+end procedure
diff --git a/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-2.phix b/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-2.phix
new file mode 100644
index 0000000000..29f51002b0
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Phix/averages-simple-moving-average-2.phix
@@ -0,0 +1,11 @@
+include sma.e
+
+constant sma3 = new_sma(3)
+constant sma5 = new_sma(5)
+constant s = {1,2,3,4,5,5,4,3,2,1}
+integer si
+
+for i=1 to length(s) do
+ si = s[i]
+ printf(1,"%2g: sma3=%8g, sma5=%8g\n",{si,moving_average(sma3,si),moving_average(sma5,si)})
+end for
diff --git a/Task/Averages-Simple-moving-average/Ring/averages-simple-moving-average-1.ring b/Task/Averages-Simple-moving-average/Ring/averages-simple-moving-average-1.ring
new file mode 100644
index 0000000000..880a190b67
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Ring/averages-simple-moving-average-1.ring
@@ -0,0 +1,31 @@
+load "stdlib.ring"
+decimals(8)
+maxperiod = 20
+nums = newlist(maxperiod,maxperiod)
+accum = list(maxperiod)
+index = list(maxperiod)
+window = list(maxperiod)
+for i = 1 to maxperiod
+ index[i] = 1
+ accum[i] = 0
+ window[i] = 0
+next
+for i = 1 to maxperiod
+ for j = 1 to maxperiod
+ nums[i][j] = 0
+ next
+next
+for n = 1 to 5
+ see "number = " + n + " sma3 = " + left((string(sma(n,3)) + " "),9) + " sma5 = " + sma(n,5) + nl
+next
+for n = 5 to 1 step -1
+ see "number = " + n + " sma3 = " + left((string(sma(n,3)) + " "),9) + " sma5 = " + sma(n,5) + nl
+next
+see nl
+
+func sma number, period
+ accum[period] += number - nums[period][index[period]]
+ nums[period][index[period]] = number
+ index[period]= (index[period] + 1) % period + 1
+ if window[period] period) {
+ sum -= list.shift
+ }
+ (sum / list.length)
+ }
+}
+
+var ma3 = simple_moving_average(3);
+var ma5 = simple_moving_average(5);
+
+[1 ..^ 6, 6 ^.. 1].map{@|_} -> each {|num|
+ printf("Next number = %d, SMA_3 = %.3f, SMA_5 = %.1f\n",
+ num, ma3.call(num), ma5.call(num))
+}
diff --git a/Task/Averages-Simple-moving-average/Sidef/averages-simple-moving-average-2.sidef b/Task/Averages-Simple-moving-average/Sidef/averages-simple-moving-average-2.sidef
new file mode 100644
index 0000000000..5d8393d679
--- /dev/null
+++ b/Task/Averages-Simple-moving-average/Sidef/averages-simple-moving-average-2.sidef
@@ -0,0 +1,19 @@
+class sma_generator(period, list=[], sum=0) {
+
+ method SMA(number) {
+ list.append(number)
+ sum += number
+ if (list.len > period) {
+ sum -= list.shift
+ }
+ (sum / list.len)
+ }
+}
+
+var ma3 = sma_generator(3)
+var ma5 = sma_generator(5)
+
+for num in [@|(1..5), @|(1..5 -> flip)] {
+ printf("Next number = %d, SMA_3 = %.3f, SMA_5 = %.1f\n",
+ num, ma3.SMA(num), ma5.SMA(num))
+}
diff --git a/Task/Balanced-brackets/Ceylon/balanced-brackets.ceylon b/Task/Balanced-brackets/Ceylon/balanced-brackets.ceylon
new file mode 100644
index 0000000000..69e4e7a280
--- /dev/null
+++ b/Task/Balanced-brackets/Ceylon/balanced-brackets.ceylon
@@ -0,0 +1,27 @@
+import com.vasileff.ceylon.random.api {
+ platformRandom,
+ Random
+}
+"""Run the example code for Rosetta Code ["Balanced brackets" task] (http://rosettacode.org/wiki/Balanced_brackets)."""
+shared void run() {
+ value rnd = platformRandom();
+ for (len in (0..10)) {
+ value c = generate(rnd, len);
+ print("``c.padTrailing(20)`` - ``if (balanced(c)) then "OK" else "NOT OK" ``");
+ }
+}
+
+String generate(Random rnd, Integer count)
+ => if (count == 0) then ""
+ else let(length = 2*count,
+ brackets = zipEntries(rnd.integers(length).take(length),
+ "[]".repeat(count))
+ .sort((a,b) => a.key<=>b.key)
+ .map(Entry.item))
+ String(brackets);
+
+Boolean balanced(String input)
+ => let (value ints = { for (c in input) if (c == '[') then 1 else -1 })
+ ints.filter((i) => i != 0)
+ .scan(0)(plus)
+ .every((i) => i >= 0);
diff --git a/Task/Balanced-brackets/EchoLisp/balanced-brackets.echolisp b/Task/Balanced-brackets/EchoLisp/balanced-brackets.echolisp
new file mode 100644
index 0000000000..6dc8e3269f
--- /dev/null
+++ b/Task/Balanced-brackets/EchoLisp/balanced-brackets.echolisp
@@ -0,0 +1,28 @@
+(define (balance str)
+ (for/fold (closed 0) ((par str))
+ #:break (< closed 0 ) => closed
+ (+ closed
+ (cond
+ ((string=? par "[") 1)
+ ((string=? par "]") -1)
+ (else 0)))))
+
+(define (task N)
+(define str (list->string (append (make-list N "[") (make-list N "]"))))
+ (for ((i 10))
+ (set! str (list->string (shuffle (string->list str))))
+ (writeln (if (zero? (balance str)) '👍 '❌ ) str)))
+
+(task 4)
+
+❌ "[]]][[]["
+❌ "]][][[[]"
+❌ "][[[]]]["
+👍 "[][[[]]]"
+❌ "]][[][]["
+❌ "][][[[]]"
+👍 "[][][[]]"
+❌ "]][[][[]"
+❌ "[[]]][[]"
+❌ "[[][]]]["
+
diff --git a/Task/Balanced-brackets/FreeBASIC/balanced-brackets.freebasic b/Task/Balanced-brackets/FreeBASIC/balanced-brackets.freebasic
new file mode 100644
index 0000000000..13758bd3a7
--- /dev/null
+++ b/Task/Balanced-brackets/FreeBASIC/balanced-brackets.freebasic
@@ -0,0 +1,45 @@
+' FB 1.05.0 Win64
+
+Function isBalanced(s As String) As Boolean
+ If s = "" Then Return True
+ Dim countLeft As Integer = 0 '' counts number of left brackets so far unmatched
+ Dim c As String
+ For i As Integer = 1 To Len(s)
+ c = Mid(s, i, 1)
+ If c = "[" Then
+ countLeft += 1
+ ElseIf countLeft > 0 Then
+ countLeft -= 1
+ Else
+ Return False
+ End If
+ Next
+ Return countLeft = 0
+End Function
+
+' checking examples in task description
+Dim brackets(1 To 7) As String = {"", "[]", "][", "[][]", "][][", "[[][]]", "[]][[]"}
+For i As Integer = 1 To 7
+ Print IIf(brackets(i) <> "", brackets(i), "(empty)"); Tab(10); IIf(isBalanced(brackets(i)), "OK", "NOT OK")
+Next
+
+' checking 7 random strings of brackets of length 8 say
+Randomize
+Dim r As Integer '' 0 will signify "[" and 1 will signify "]"
+Dim s As String
+For i As Integer = 1 To 7
+ s = Space(8)
+ For j As Integer = 1 To 8
+ r = Int(Rnd * 2)
+ If r = 0 Then
+ Mid(s, j) = "["
+ Else
+ Mid(s, j) = "]"
+ End If
+ Next j
+ Print s; Tab(10); IIf(isBalanced(s), "OK", "NOT OK")
+Next i
+
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Balanced-brackets/L++/balanced-brackets.lpp b/Task/Balanced-brackets/L++/balanced-brackets.lpp
new file mode 100644
index 0000000000..ee2a99ab1e
--- /dev/null
+++ b/Task/Balanced-brackets/L++/balanced-brackets.lpp
@@ -0,0 +1,15 @@
+(include "string")
+
+(defn bool balanced (std::string s)
+ (def bal 0)
+ (foreach c s
+ (if (== c #\[) (++ bal)
+ (if (== c #\]) (-- bal)))
+ (if (< bal 0) (return false)))
+ (return (== bal 0)))
+
+(main
+ (decl std::string (at tests) |{"", "[]", "[][]", "[[][]]", "][", "][][", "[]][[]"}|)
+ (pr std::boolalpha)
+ (foreach x tests
+ (prn x "\t" (balanced x))))
diff --git a/Task/Balanced-brackets/Lasso/balanced-brackets.lasso b/Task/Balanced-brackets/Lasso/balanced-brackets.lasso
new file mode 100644
index 0000000000..f55edd97c3
--- /dev/null
+++ b/Task/Balanced-brackets/Lasso/balanced-brackets.lasso
@@ -0,0 +1,22 @@
+define randomparens(num::integer,open::string='[',close::string=']') => {
+ local(out) = array
+
+ with i in 1 to #num do {
+ #out->insert(']', integer_random(1,#out->size || 1))
+ #out->insert('[', integer_random(1,#out->size || 1))
+ }
+ return #out->join
+}
+
+define validateparens(input::string,open::string='[',close::string=']') => {
+ local(i) = 0
+ #input->foreachcharacter => {
+ #1 == #open ? #i++
+ #1 == #close && --#i < 0 ? return false
+ }
+ return #i == 0 ? true | false
+}
+
+with i in 1 to 10
+let input = randomparens(#i)
+select #input + ' = ' + validateparens(#input)
diff --git a/Task/Balanced-brackets/Nim/balanced-brackets.nim b/Task/Balanced-brackets/Nim/balanced-brackets.nim
new file mode 100644
index 0000000000..1d1f0c89e7
--- /dev/null
+++ b/Task/Balanced-brackets/Nim/balanced-brackets.nim
@@ -0,0 +1,30 @@
+import random
+randomize()
+
+proc shuffle(s: var string) =
+ for i in countdown(s.high, 0):
+ swap(s[i], s[random(s.len)])
+
+proc gen(n: int): string =
+ result = newString(2 * n)
+ for i in 0 .. ifTrue: [ continue ]
+ 1- dup 0 < ifTrue: [ drop false return ]
+ ]
+ 0 == ;
+
+: genBrackets(n)
+ "" #[ "[" "]" 2 rand 2 == ifTrue: [ swap ] rot + swap + ] times(n) ;
diff --git a/Task/Balanced-brackets/Phix/balanced-brackets.phix b/Task/Balanced-brackets/Phix/balanced-brackets.phix
new file mode 100644
index 0000000000..475bf1a8c7
--- /dev/null
+++ b/Task/Balanced-brackets/Phix/balanced-brackets.phix
@@ -0,0 +1,21 @@
+function check_brackets(sequence s)
+integer level = 0
+ for i=1 to length(s) do
+ switch s[i]
+ case '[': level += 1
+ case ']': level -= 1
+ if level<0 then exit end if
+ end switch
+ end for
+ return (level=0)
+end function
+
+sequence s
+constant ok = {"not ok","ok"}
+
+for i=1 to 10 do
+ for j=1 to 2 do
+ s = shuffle(join(repeat("[]",i-1),""))
+ printf(1,"%s %s\n",{s,ok[check_brackets(s)+1]})
+ end for
+end for
diff --git a/Task/Balanced-brackets/Ring/balanced-brackets.ring b/Task/Balanced-brackets/Ring/balanced-brackets.ring
new file mode 100644
index 0000000000..160b028b48
--- /dev/null
+++ b/Task/Balanced-brackets/Ring/balanced-brackets.ring
@@ -0,0 +1,26 @@
+nr = 0
+while nr < 10
+ nr += 1
+ test=generate(random(9)+1)
+ see "bracket string " + test + " is " + valid(test) + nl
+end
+
+func generate n
+l = 0 r = 0 output = ""
+while l Bool {
+
+ var count = 0
+
+ return !str.characters.contains { ($0 == "[" ? ++count : --count) < 0 } && count == 0
+
+}
diff --git a/Task/Balanced-brackets/Swift/balanced-brackets-2.swift b/Task/Balanced-brackets/Swift/balanced-brackets-2.swift
new file mode 100644
index 0000000000..2e09c60d99
--- /dev/null
+++ b/Task/Balanced-brackets/Swift/balanced-brackets-2.swift
@@ -0,0 +1,3 @@
+isBal("[[[]]]") // true
+
+isBal("[]][[]") // false
diff --git a/Task/Balanced-brackets/Swift/balanced-brackets-3.swift b/Task/Balanced-brackets/Swift/balanced-brackets-3.swift
new file mode 100644
index 0000000000..28538a7450
--- /dev/null
+++ b/Task/Balanced-brackets/Swift/balanced-brackets-3.swift
@@ -0,0 +1,13 @@
+func randBrack(n: Int) -> String {
+
+ var bracks: [Character] = Array(Repeat(count: n, repeatedValue: "["))
+
+ for i in UInt32(n+1)...UInt32(n + n) {
+
+ bracks.insert("]", atIndex: Int(arc4random_uniform(i)))
+
+ }
+
+ return String(bracks)
+
+}
diff --git a/Task/Balanced-brackets/Swift/balanced-brackets-4.swift b/Task/Balanced-brackets/Swift/balanced-brackets-4.swift
new file mode 100644
index 0000000000..a0ba0614c6
--- /dev/null
+++ b/Task/Balanced-brackets/Swift/balanced-brackets-4.swift
@@ -0,0 +1 @@
+randBrack(2) // "]][["
diff --git a/Task/Balanced-brackets/Swift/balanced-brackets-5.swift b/Task/Balanced-brackets/Swift/balanced-brackets-5.swift
new file mode 100644
index 0000000000..d46d608857
--- /dev/null
+++ b/Task/Balanced-brackets/Swift/balanced-brackets-5.swift
@@ -0,0 +1,12 @@
+func randIsBal(n: Int) {
+
+ let (bal, un) = ("", "un")
+
+ for str in (1...n).map(randBrack) {
+
+ print("\(str) is \(isBal(str) ? bal : un)balanced\n")
+
+ }
+}
+
+randIsBal(4)
diff --git a/Task/Balanced-brackets/Swift/balanced-brackets-6.swift b/Task/Balanced-brackets/Swift/balanced-brackets-6.swift
new file mode 100644
index 0000000000..153c171bc1
--- /dev/null
+++ b/Task/Balanced-brackets/Swift/balanced-brackets-6.swift
@@ -0,0 +1,7 @@
+// ][ is unbalanced
+//
+// ]][[ is unbalanced
+//
+// []][[] is unbalanced
+//
+// [][][[]] is balanced
diff --git a/Task/Balanced-brackets/Ya/balanced-brackets.ya b/Task/Balanced-brackets/Ya/balanced-brackets.ya
new file mode 100644
index 0000000000..0b3e76f880
--- /dev/null
+++ b/Task/Balanced-brackets/Ya/balanced-brackets.ya
@@ -0,0 +1,37 @@
+@Balanced[]s // each source must be started by specifying its file name; std extension .Ya could be ommitted and auto added by compiler
+
+// all types are prefixed by `
+// definition of anything new is prefixed by \, like \MakeNew_[]s and \len
+// MakeNew_[]s is Ok ident in Ya: _ starts sign part of ident, which must be ended by _ or alphanum
+`Char[^] \MakeNew_[]s(`Int+ \len) // `Char[^] and `Char[=] are arrays that owns their items, like it's usally in other langs;
+ // yet in assignment of `Char[^] to `Char[=] the allocated memory is moved from old to new owner, and old string becomes empty
+ // there are tabs at starts of many lines; these tabs specify what in C++ is {} blocks, just like in Python
+ len & 1 ==0 ! // it's a call to postfix function '!' which is an assert: len must be even
+ `Char[=] \r(len) // allocate new string of length len
+ // most statements are analogous to C++ but written starting by capital letter: For If Switch Ret
+ For `Char[] \eye = r; eye // // `Char[] is a simplest array of chars, which does not hold a memory used by array items; inc part of For loop is missed: it's Ok, and condition and init could also be missed
+ *eye++ = '['; *eye++ = '[' // fill r by "[][][]...". The only place with ; as statement delemiter: required because the statement is not started at new line.
+ // below is a shuffle of "[][][]..." array
+ For `Char[] \eye = r; ++eye // var eye is already defined, but being the same `Char[] it's Ok by using already exisiting var. ++eye is used: it allows use of eye[-1] inside
+ `Int+ \at = Random(eye/Length) // `Int+ is C++'s unsigned int. eye/Length: / is used for access to field, like in file path
+ eye[-1],eye[at] = eye[at],eye[-1] // swap using tuples; eye[-1] accesses char that is out of current array, yet it's allowed
+ Ret r // Ret is C's return
+`Bool \AreBalanced(`Char[] \brackets)
+ `Int+ \extra = 0
+ For ;brackets ;++brackets
+ Switch *brackets
+ '[' // it's a C++'s 'case': both 'case' and ':' are skipped being of no value; but the code for a case should be in block, which is here specifyed by tabs at next line start
+ ++extra
+ ']'
+ If !!extra // '!!' is `Bool not, like all other `Bool ops: && || ^^
+ Ret No // No and False are C's false; Yes and True are C's true
+ --extra
+ // There is no default case, which is written as ':' - so if no case is Ok then it will fail just like if being written as on the next line
+ // : { 0! } // C's default: assert(0);
+ Ret extra == 0
+// function ala 'main' is not used: all global code from all modules are executed; so below is what typically is in ala 'main'
+For `Int \n=10; n; --n
+ // below note that new var 'brackets' is created inside args of func call
+ //@Std/StdIO/ is used here to use Print function; else it maybe changed to Use @Std/StdIO at global level before this For loop
+ @Std/StdIO/Print(; "%s : %s\n" ;`Char[=] \brackets = MakeNew_[]s(10) /* all bracket strings are of length 10 */; AreBalanced(brackets) ? "Ok" : "bad")
+ // note that starting arg of Print is missed by using ';' - default arg value is allowed to use for any arg, even if next args are written
diff --git a/Task/Balanced-ternary/Glagol/balanced-ternary.glagol b/Task/Balanced-ternary/Glagol/balanced-ternary.glagol
new file mode 100644
index 0000000000..9824d54ccd
--- /dev/null
+++ b/Task/Balanced-ternary/Glagol/balanced-ternary.glagol
@@ -0,0 +1,113 @@
+PROGRAM Setun+;
+USES
+ Parameter IS "...\Departments\Exchange\"
+ Text IS "...\Departments\Numbers\"
+ Output IS "...\Departments\Exchange\";
+
+VAR
+ AF: RANGE 10 IS SIGN;
+ mfpos: INT;
+ number: INT;
+ memory ACCESS TO STRUCT
+ cell: RANGE 20 IS INT;
+ size: UZKEL;
+ negative: BOOL
+ END;
+
+PROC Create.Memory;
+BEGIN
+ CREATE(memory);
+ memory.size := 0;
+ memory.negative := FALSE
+END Create.Memory;
+
+PROC Add.Memory(that: INT)
+BEGIN
+ memory.cells[memory.size] := that;
+ ZOOM(memory.size)
+END Add.Memory;
+
+PROC Invert.Memory;
+VAR
+ zchsl: INT;
+ account: INT;
+BEGIN
+ FOR cq := 0 TO memory.size DIVIDE 2 - 1 DO
+ zchsl := memory.cells[cq];
+ memory.cells[cq] := memory.cells[memory.size-size-1];
+ memory.cells[memory.size-MF-1] := zchsl
+ END
+END Invert.Memory;
+
+PROC Withdraw.Memory;
+VAR
+ account: INT;
+BEGIN
+ FOR cq := 0 TO memory.size-1 DO
+ IF memory.cells[cq] < 0 THEN
+ Output.Append("-")
+ ANDIF memory.cells[cq] > 0 THEN
+ Output.Append("+")
+ ELSE Output.Append("0") END
+ END
+END Withdraw.Memory;
+
+PROC Remove.Memory;
+BEGIN
+ memory := Empty
+END Remove.Memory;
+
+PROC Translate(number: INT)
+VAR
+ about: INT;
+ s: BOOL;
+ PROC B.Memory(that: INT)
+ BEGIN
+ IF memory.negative THEN
+ IF that < 0 THEN Add.Memory(1)
+ ANDIF that > 0 THEN Add.Memory(1)
+ ELSE Add.Memory(0) END
+ ELSE
+ Add.Memory(that)
+ END
+ END B.Memory;
+BEGIN
+ IF number < 0 THEN memory.negative := TRUE END;
+ number := UNIT(number)
+ s := FALSE;
+ WHILE number > 0 DO
+ about := number BALANCE 3;
+ number := number DIVIDE 3;
+ IF s THEN
+ IF about = 2 THEN B.Memory(0) ANDIF about = 1 THEN B.Memory(1) ELSE B.Memory(1) s := FALSE END
+ ELSE
+ IF about = 2 THEN B.Memory(-1) s := TRUE ELSE B.Memory(a) END
+ END
+ END;
+ IF s THEN B.Memory(1) END;
+ Invert.Memory;
+ Withdraw.Memory(TRUE)
+END Translate;
+
+PROC InNumber(): INT;
+VAR
+ MF, MN: INT;
+ result: INT;
+BEGIN
+ result := 0
+ pl := 1;
+ FOR cq := 0 TO memory.size-1 DO
+ ZOOM(result, memory.Cells[memory.size-cq-1] * mn);
+ pl := pl * 3
+ END;
+ RETURN result;
+END InNumber;
+
+BEGIN
+ Parameter.Text(1, AF); mfpos := 0;
+ number := Text.Whole(AF, mfpos);
+ Create.Memory;
+ Translate(number);
+ Output.ChTarget(" = %d.", InNumber(), 0, 0, 0);
+ Remove.Memory
+END Setun.
diff --git a/Task/Balanced-ternary/Phix/balanced-ternary-1.phix b/Task/Balanced-ternary/Phix/balanced-ternary-1.phix
new file mode 100644
index 0000000000..c8a9fdbde0
--- /dev/null
+++ b/Task/Balanced-ternary/Phix/balanced-ternary-1.phix
@@ -0,0 +1,91 @@
+function bt2dec(string bt)
+integer res = 0
+ for i=1 to length(bt) do
+ res = 3*res+(bt[i]='+')-(bt[i]='-')
+ end for
+ return res
+end function
+
+function negate(string bt)
+ for i=1 to length(bt) do
+ if bt[i]!='0' then
+ bt[i] = '+'+'-'-bt[i]
+ end if
+ end for
+ return bt
+end function
+
+function dec2bt(integer n)
+string res = "0"
+integer neg, r
+ if n!=0 then
+ neg = n<0
+ if neg then n = -n end if
+ res = ""
+ while n!=0 do
+ r = mod(n,3)
+ res = "0+-"[r+1]&res
+ n = floor((n+(r=2))/3)
+ end while
+ if neg then res = negate(res) end if
+ end if
+ return res
+end function
+
+-- res,carry for a+b+carry lookup tables (not the fastest way to do it, I'm sure):
+constant {tadd,addres} = columnize({{"---","0-"},{"--0","+-"},{"--+","-0"},
+ {"-0-","+-"},{"-00","-0"},{"-0+","00"},
+ {"-+-","-0"},{"-+0","00"},{"-++","+0"},
+ {"0--","+-"},{"0-0","-0"},{"0-+","00"},
+ {"00-","-0"},{"000","00"},{"00+","+0"},
+ {"0+-","00"},{"0+0","+0"},{"0++","-+"},
+ {"+--","-0"},{"+-0","00"},{"+-+","+0"},
+ {"+0-","00"},{"+00","+0"},{"+0+","-+"},
+ {"++-","+0"},{"++0","-+"},{"+++","0+"}})
+
+
+function bt_add(string a, string b)
+integer pad = length(a)-length(b)
+integer carry = '0'
+ if pad!=0 then
+ if pad<0 then
+ a = repeat('0',-pad)&a
+ else
+ b = repeat('0',pad)&b
+ end if
+ end if
+ for i=length(a) to 1 by -1 do
+ {a[i],carry} = addres[find(a[i]&b[i]&carry,tadd)]
+ end for
+ if carry!='0' then
+ a = carry&a
+ else
+ while length(a)>1 and a[1]='0' do
+ a = a[2..$]
+ end while
+ end if
+ return a
+end function
+
+function bt_mul(string a, string b)
+string pos = a, neg = negate(a), res = "0"
+integer ch
+ for i=length(b) to 1 by -1 do
+ ch = b[i]
+ if ch='+' then
+ res = bt_add(res,pos)
+ elsif ch='-' then
+ res = bt_add(res,neg)
+ end if
+ pos = pos&'0'
+ neg = neg&'0'
+ end for
+ return res
+end function
+
+string a = "+-0++0+", b = dec2bt(-436), c = "+-++-"
+
+?{bt2dec(a),bt2dec(b),bt2dec(c)}
+
+string res = bt_mul(a,bt_add(b,negate(c)))
+?{res,bt2dec(res)}
diff --git a/Task/Balanced-ternary/Phix/balanced-ternary-2.phix b/Task/Balanced-ternary/Phix/balanced-ternary-2.phix
new file mode 100644
index 0000000000..e3191438a2
--- /dev/null
+++ b/Task/Balanced-ternary/Phix/balanced-ternary-2.phix
@@ -0,0 +1,16 @@
+atom t0 = time()
+string f999 = dec2bt(1)
+for i=2 to 999 do
+ f999 = bt_mul(f999,dec2bt(i))
+end for
+string f1000 = bt_mul(f999,dec2bt(1000))
+
+printf(1,"In balanced ternary, f999 has %d digits and f1000 has %d digits\n",{length(f999),length(f1000)})
+
+integer count = 0
+f999 = negate(f999)
+while f1000!="0" do
+ f1000 = bt_add(f1000,f999)
+ count += 1
+end while
+printf(1,"It took %d subtractions to reach 0. (%3.2fs)\n",{count,time()-t0})
diff --git a/Task/Benfords-law/FreeBASIC/benfords-law.freebasic b/Task/Benfords-law/FreeBASIC/benfords-law.freebasic
new file mode 100644
index 0000000000..90d6f8b2b5
--- /dev/null
+++ b/Task/Benfords-law/FreeBASIC/benfords-law.freebasic
@@ -0,0 +1,90 @@
+' version 27-10-2016
+' compile with: fbc -s console
+
+#Define max 1000 ' total number of Fibonacci numbers
+#Define max_sieve 15485863 ' should give 1,000,000
+
+#Include Once "gmp.bi" ' uses the GMP libary
+
+Dim As ZString Ptr z_str
+Dim As ULong n, d
+ReDim As ULong digit(1 To 9)
+Dim As Double expect, found
+
+Dim As mpz_ptr fib1, fib2
+fib1 = Allocate(Len(__mpz_struct)) : Mpz_init_set_ui(fib1, 0)
+fib2 = Allocate(Len(__mpz_struct)) : Mpz_init_set_ui(fib2, 1)
+
+digit(1) = 1 ' fib2
+For n = 2 To max
+ Swap fib1, fib2 ' fib1 = 1, fib2 = 0
+ mpz_add(fib2, fib1, fib2) ' fib1 = 1, fib2 = 1 (fib1 + fib2)
+ z_str = mpz_get_str(0, 10, fib2)
+ d = Val(Left(*z_str, 1)) ' strip the 1 digit on the left off
+ digit(d) = digit(d) +1
+Next
+
+mpz_clear(fib1) : DeAllocate(fib1)
+mpz_clear(fib2) : DeAllocate(fib2)
+
+Print
+Print "First 1000 Fibonacci numbers"
+Print "nr: total found expected difference"
+
+For d = 1 To 9
+ n = digit(d)
+ found = n / 10
+ expect = (Log(1 + 1 / d) / Log(10)) * 100
+ Print Using " ## ##### ###.## % ###.## % ##.### %"; _
+ d; n ; found; expect; expect - found
+Next
+
+
+ReDim digit(1 To 9)
+ReDim As UByte sieve(max_sieve)
+
+'For d = 4 To max_sieve Step 2
+' sieve(d) = 1
+'Next
+Print : Print "start sieve"
+For d = 3 To sqr(max_sieve)
+ If sieve(d) = 0 Then
+ For n = d * d To max_sieve Step d * 2
+ sieve(n) = 1
+ Next
+ End If
+Next
+
+digit(2) = 1 ' 2
+
+Print "start collecting first digits"
+For n = 3 To max_sieve Step 2
+ If sieve(n) = 0 Then
+ d = Val(Left(Trim(Str(n)), 1))
+ digit(d) = digit(d) +1
+ End If
+Next
+
+Dim As ulong total
+For n = 1 To 9
+ total = total + digit(n)
+Next
+
+Print
+Print "First";total; " primes"
+Print "nr: total found expected difference"
+
+For d = 1 To 9
+ n = digit(d)
+ found = n / total * 100
+ expect = (Log(1 + 1 / d) / Log(10)) * 100
+ Print Using " ## ######## ###.## % ###.## % ###.### %"; _
+ d; n ; found; expect; expect - found
+Next
+
+
+' empty keyboard buffer
+While InKey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Benfords-law/Phix/benfords-law-1.phix b/Task/Benfords-law/Phix/benfords-law-1.phix
new file mode 100644
index 0000000000..457a5fa409
--- /dev/null
+++ b/Task/Benfords-law/Phix/benfords-law-1.phix
@@ -0,0 +1,14 @@
+procedure main(sequence s, string title)
+sequence f = repeat(0,9)
+ for i=1 to length(s) do
+ f[sprint(s[i])[1]-'0'] += 1
+ end for
+ puts(1,title)
+ puts(1,"Digit Observed% Predicted%\n")
+ for i=1 to length(f) do
+ printf(1," %d %9.3f %8.3f\n", {i, f[i]/length(s)*100, log10(1+1/i)*100})
+ end for
+end procedure
+main(fib(1000),"First 1000 Fibonacci numbers\n")
+main(primes(10000),"First 10000 Prime numbers\n")
+main(threes(500),"First 500 powers of three\n")
diff --git a/Task/Benfords-law/Phix/benfords-law-2.phix b/Task/Benfords-law/Phix/benfords-law-2.phix
new file mode 100644
index 0000000000..cf89b3d84f
--- /dev/null
+++ b/Task/Benfords-law/Phix/benfords-law-2.phix
@@ -0,0 +1,39 @@
+function fib(integer lim)
+atom a=0, b=1
+sequence res = repeat(0,lim)
+ for i=1 to lim do
+ {res[i], a, b} = {b, b, b+a}
+ end for
+ return res
+end function
+
+function primes(integer lim)
+integer n = 1, k, p
+sequence res = {2}
+ while length(res) log10);
+} * 9;
+
+"%17s%17s\n".printf("Observed","Expected");
+{ |i|
+ "%d : %11s %%%15s %%\n".printf(
+ i, "%.2f".sprintf(100 * actuals[i - 1]),
+ "%.2f".sprintf(100 * expected[i - 1]),
+ );
+} * 9;
diff --git a/Task/Benfords-law/Visual-FoxPro/benfords-law.visual b/Task/Benfords-law/Visual-FoxPro/benfords-law.visual
new file mode 100644
index 0000000000..54cebaa6a5
--- /dev/null
+++ b/Task/Benfords-law/Visual-FoxPro/benfords-law.visual
@@ -0,0 +1,40 @@
+#DEFINE CTAB CHR(9)
+#DEFINE COMMA ","
+#DEFINE CRLF CHR(13) + CHR(10)
+LOCAL i As Integer, n As Integer, n1 As Integer, rho As Double, c As String
+n = 1000
+LOCAL ARRAY a[n,2], res[1]
+CLOSE DATABASES ALL
+CREATE CURSOR fibo(dig C(1))
+INDEX ON dig TAG dig COLLATE "Machine"
+SET ORDER TO 0
+*!* Populate the cursor with the leading digit of the first 1000 Fibonacci numbers
+a[1,1] = "1"
+a[1,2] = 1
+a[2,1] = "1"
+a[2,2] = 1
+FOR i = 3 TO n
+ a[i,2] = a[i-2,2] + a[i-1,2]
+ a[i,1] = LEFT(TRANSFORM(a[i,2]), 1)
+ENDFOR
+APPEND FROM ARRAY a FIELDS dig
+CREATE CURSOR results (digit I, count I, prob B(6), expected B(6))
+INSERT INTO results ;
+SELECT dig, COUNT(1), COUNT(1)/n, Pr(VAL(dig)) FROM fibo GROUP BY dig ORDER BY dig
+n1 = RECCOUNT()
+*!* Correlation coefficient
+SELECT (n1*SUM(prob*expected) - SUM(prob)*SUM(expected))/;
+(SQRT(n1*SUM(prob*prob) - SUM(prob)*SUM(prob))*SQRT(n1*SUM(expected*expected) - SUM(expected)*SUM(expected))) ;
+FROM results INTO ARRAY res
+rho = CAST(res[1] As B(6))
+SET SAFETY OFF
+COPY TO benford.txt TYPE CSV
+c = FILETOSTR("benford.txt")
+*!* Replace commas with tabs
+c = STRTRAN(c, COMMA, CTAB) + CRLF + "Correlation Coefficient: " + TRANSFORM(rho)
+STRTOFILE(c, "benford.txt", 0)
+SET SAFETY ON
+
+FUNCTION Pr(d As Integer) As Double
+RETURN LOG10(1 + 1/d)
+ENDFUNC
diff --git a/Task/Benfords-law/jq/benfords-law.jq b/Task/Benfords-law/jq/benfords-law.jq
new file mode 100644
index 0000000000..5281081453
--- /dev/null
+++ b/Task/Benfords-law/jq/benfords-law.jq
@@ -0,0 +1,107 @@
+# Generate the first n Fibonacci numbers: 1, 1, ...
+# Numerical accuracy is insufficient beyond about 1450.
+def fibonacci(n):
+ # input: [f(i-2), f(i-1), countdown]
+ def fib: (.[0] + .[1]) as $sum
+ | if .[2] <= 0 then empty
+ elif .[2] == 1 then $sum
+ else $sum, ([ .[1], $sum, .[2] - 1 ] | fib)
+ end;
+ [1, 0, n] | fib ;
+
+# is_prime is tailored to work with jq 1.4
+def is_prime:
+ if . == 2 then true
+ else 2 < . and . % 2 == 1 and
+ . as $in
+ | (($in + 1) | sqrt) as $m
+ | (((($m - 1) / 2) | floor) + 1) as $max
+ | reduce range(1; $max) as $i
+ (true; if . then ($in % ((2 * $i) + 1)) > 0 else false end)
+ end ;
+
+# primes in [m,n)
+def primes(m;n):
+ range(m;n) | select(is_prime);
+
+def runs:
+ reduce .[] as $item
+ ( [];
+ if . == [] then [ [ $item, 1] ]
+ else .[length-1] as $last
+ | if $last[0] == $item
+ then (.[0:length-1] + [ [$item, $last[1] + 1] ] )
+ else . + [[$item, 1]]
+ end
+ end ) ;
+
+# Inefficient but brief:
+def histogram: sort | runs;
+
+def benford_probability:
+ tonumber
+ | if . > 0 then ((1 + (1 /.)) | log) / (10|log)
+ else 0
+ end ;
+
+# benford takes a stream and produces an array of [ "d", observed, expected ]
+def benford(stream):
+ [stream | tostring | .[0:1] ] | histogram as $histogram
+ | reduce ($histogram | .[] | .[0]) as $digit
+ ([]; . + [$digit, ($digit|benford_probability)] )
+ | map(select(type == "number")) as $probabilities
+ | ([ $histogram | .[] | .[1] ] | add) as $total
+ | reduce range(0; $histogram|length) as $i
+ ([]; . + ([$histogram[$i] + [$total * $probabilities[$i]] ] ) ) ;
+
+# given an array of [value, observed, expected] values,
+# produce the χ² statistic
+def chiSquared:
+ reduce .[] as $triple
+ (0;
+ if $triple[2] == 0 then .
+ else . + ($triple[1] as $o | $triple[2] as $e | ($o - $e) | (.*.)/$e)
+ end) ;
+
+# truncate n places after the decimal point;
+# return a string since it can readily be converted back to a number
+def precision(n):
+ tostring as $s | $s | index(".")
+ | if . then $s[0:.+n+1] else $s end ;
+
+# Right-justify but do not truncate
+def rjustify(n):
+ length as $length | if n <= $length then . else " " * (n-$length) + . end;
+
+# Attempt to align decimals so integer part is in a field of width n
+def align(n):
+ index(".") as $ix
+ | if n < $ix then .
+ elif $ix then (.[0:$ix]|rjustify(n)) +.[$ix:]
+ else rjustify(n)
+ end ;
+
+# given an array of [value, observed, expected] values,
+# produce rows of the form: value observed expected
+def print_rows(prec):
+ .[] | map( precision(prec)|align(5) + " ") | add ;
+
+def report(heading; stream):
+ benford(stream) as $array
+ | heading,
+ " Digit Observed Expected",
+ ( $array | print_rows(2) ),
+ "",
+ " χ² = \( $array | chiSquared | precision(4))",
+ ""
+;
+
+def task:
+ report("First 100 fibonacci numbers:"; fibonacci( 100) ),
+ report("First 1000 fibonacci numbers:"; fibonacci(1000) ),
+ report("Primes less than 1000:"; primes(2;1000)),
+ report("Primes between 1000 and 10000:"; primes(1000;10000)),
+ report("Primes less than 100000:"; primes(2;100000))
+;
+
+task
diff --git a/Task/Bernoulli-numbers/Crystal/bernoulli-numbers.crystal b/Task/Bernoulli-numbers/Crystal/bernoulli-numbers.crystal
new file mode 100644
index 0000000000..f932ca814f
--- /dev/null
+++ b/Task/Bernoulli-numbers/Crystal/bernoulli-numbers.crystal
@@ -0,0 +1,62 @@
+# Taken from the 'Ada 99' project, https://marquisdegeek.com/code_ada99
+
+class Fraction
+ def initialize(n : Int64, d : Int64)
+ @numerator = n
+ @denominator = d
+ end
+
+ def numerator
+ @numerator
+ end
+
+ def denominator
+ @denominator
+ end
+
+ def subtract(rhs_fraction)
+ rhs_numerator = rhs_fraction.numerator * @denominator
+ rhs_denominator = rhs_fraction.denominator * @denominator
+ @numerator *= rhs_fraction.denominator
+ @denominator *= rhs_fraction.denominator
+ @numerator -= rhs_numerator
+ self.reduce
+ end
+
+ def multiply(value)
+ @numerator *= value
+ end
+
+ def reduce
+ gcd = gcd(@numerator, @denominator)
+ @numerator /= gcd
+ @denominator /= gcd
+ end
+
+ def to_s
+ @numerator == 0 ? 0 : @numerator.to_s + '/' + @denominator.to_s
+ end
+end
+
+def gcd(a, b)
+ # we need b>0 because b on its own isn't considered true
+ b > 0 ? gcd(b, a % b) : a
+end
+
+def calculate_bernoulli(bern)
+ row = [] of Fraction
+ 0_i64.step(bern) do |m|
+ row << Fraction.new(1_i64, m + 1)
+ m.step(1, -1) do |j|
+ row[j - 1].subtract(row[j])
+ row[j - 1].multiply(j)
+ row[j - 1].reduce
+ end
+ end
+
+ row[0]
+end
+
+1_i64.step(30_i64) do |bern|
+ puts "#{bern} : #{calculate_bernoulli(bern).to_s}"
+end
diff --git a/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-1.echolisp b/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-1.echolisp
new file mode 100644
index 0000000000..a428612fec
--- /dev/null
+++ b/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-1.echolisp
@@ -0,0 +1,24 @@
+(lib 'bigint) ;; lerge numbers
+(lib 'gloops) ;; classes
+
+(define-class Rational null ((a :initform #0) (b :initform #1)))
+(define-method tostring (Rational) (lambda (r) (format "%50d / %d" r.a r.b)))
+(define-method normalize (Rational) (lambda (r) ;; divide a and b by gcd
+ (let ((g (gcd r.a r.b)))
+ (set! r.a (/ r.a g)) (set! r.b (/ r.b g))
+ (when (< r.b 0) (set! r.a ( - r.a)) (set! r.b (- r.b))) ;; denominator > 0
+ r)))
+
+(define-method initialize (Rational) (lambda (r) (normalize r)))
+(define-method add (Rational) (lambda (r n) ;; + Rational any number
+ (normalize (Rational (+ (* (+ #0 n) r.b) r.a) r.b))))
+(define-method add (Rational Rational) (lambda (r q) ;;; + Rational Rational
+ (normalize (Rational (+ (* r.a q.b) (* r.b q.a)) (* r.b q.b)))))
+(define-method sub (Rational Rational) (lambda (r q)
+ (normalize (Rational (- (* r.a q.b) (* r.b q.a)) (* r.b q.b)))))
+(define-method mul (Rational Rational) (lambda (r q)
+ (normalize (Rational (* r.a q.a) (* r.b q.b)))))
+(define-method mul (Rational) (lambda (r n)
+ (normalize (Rational (* r.a (+ #0 n)) r.b ))))
+(define-method div (Rational Rational) (lambda (r q)
+ (normalize (Rational (* r.a q.b) (* r.b q.a)))))
diff --git a/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-2.echolisp b/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-2.echolisp
new file mode 100644
index 0000000000..bfa16a2b0c
--- /dev/null
+++ b/Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-2.echolisp
@@ -0,0 +1,47 @@
+;; Bernoulli numbers
+;; http://rosettacode.org/wiki/Bernoulli_numbers
+(define A (make-vector 100 0))
+
+(define (B n)
+(for ((m (1+ n))) ;; #1 creates a large integer
+ (vector-set! A m (Rational #1 (+ #1 m)))
+ (for ((j (in-range m 0 -1)))
+ (vector-set! A (1- j)
+ (mul (sub (vector-ref A (1- j)) (vector-ref A j)) j))))
+ (vector-ref A 0))
+
+ (for ((b (in-range 0 62 2))) (writeln b (B b))) →
+
+0 1 / 1
+2 1 / 6
+4 -1 / 30
+6 1 / 42
+8 -1 / 30
+10 5 / 66
+12 -691 / 2730
+14 7 / 6
+16 -3617 / 510
+18 43867 / 798
+20 -174611 / 330
+22 854513 / 138
+24 -236364091 / 2730
+26 8553103 / 6
+28 -23749461029 / 870
+30 8615841276005 / 14322
+32 -7709321041217 / 510
+34 2577687858367 / 6
+36 -26315271553053477373 / 1919190
+38 2929993913841559 / 6
+40 -261082718496449122051 / 13530
+42 1520097643918070802691 / 1806
+44 -27833269579301024235023 / 690
+46 596451111593912163277961 / 282
+48 -5609403368997817686249127547 / 46410
+50 495057205241079648212477525 / 66
+52 -801165718135489957347924991853 / 1590
+54 29149963634884862421418123812691 / 798
+56 -2479392929313226753685415739663229 / 870
+58 84483613348880041862046775994036021 / 354
+60 -1215233140483755572040304994079820246041491 / 56786730
+
+(B 1) → 1 / 2
diff --git a/Task/Bernoulli-numbers/FreeBASIC/bernoulli-numbers.freebasic b/Task/Bernoulli-numbers/FreeBASIC/bernoulli-numbers.freebasic
new file mode 100644
index 0000000000..1b963e3df4
--- /dev/null
+++ b/Task/Bernoulli-numbers/FreeBASIC/bernoulli-numbers.freebasic
@@ -0,0 +1,54 @@
+' version 08-10-2016
+' compile with: fbc -s console
+' uses gmp
+
+#Include Once "gmp.bi"
+
+#Define max 60
+
+Dim As Long n
+Dim As ZString Ptr gmp_str :gmp_str = Allocate(1000) ' 1000 char
+Dim Shared As Mpq_ptr tmp, big_j
+tmp = Allocate(Len(__mpq_struct)) :Mpq_init(tmp)
+big_j = Allocate(Len(__mpq_struct)) :Mpq_init(big_j)
+
+Dim Shared As Mpq_ptr a(max), b(max)
+For n = 0 To max
+ A(n) = Allocate(Len(__mpq_struct)) :Mpq_init(A(n))
+ B(n) = Allocate(Len(__mpq_struct)) :Mpq_init(B(n))
+Next
+
+Function Bernoulli(n As Integer) As Mpq_ptr
+
+ Dim As Long m, j
+
+ For m = 0 To n
+ Mpq_set_ui(A(m), 1, m + 1)
+ For j = m To 1 Step - 1
+ Mpq_sub(tmp, A(j - 1), A(j))
+ Mpq_set_ui(big_j, j, 1) 'big_j = j
+ Mpq_mul(A(j - 1), big_j, tmp)
+ Next
+ Next
+
+ Return A(0)
+End Function
+
+' ------=< MAIN >=------
+
+For n = 0 To max
+ Mpq_set(B(n), Bernoulli(n))
+ Mpq_get_str(gmp_str, 10, B(n))
+ If *gmp_str <> "0" Then
+ If *gmp_str = "1" Then *gmp_str = "1/1"
+ Print Using "B(##) = "; n;
+ Print Space(45 - InStr(*gmp_str, "/")); *gmp_str
+ End If
+Next
+
+
+' empty keyboard buffer
+While Inkey <> "" :Wend
+Print :Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Bernoulli-numbers/FunL/bernoulli-numbers.funl b/Task/Bernoulli-numbers/FunL/bernoulli-numbers.funl
new file mode 100644
index 0000000000..33269b88ed
--- /dev/null
+++ b/Task/Bernoulli-numbers/FunL/bernoulli-numbers.funl
@@ -0,0 +1,6 @@
+import integers.choose
+
+def B( n ) = sum( 1/(k + 1)*sum((if 2|r then 1 else -1)*choose(k, r)*(r^n) | r <- 0..k) | k <- 0..n )
+
+for i <- 0..60 if i == 1 or 2|i
+ printf( "B(%2d) = %s\n", i, B(i) )
diff --git a/Task/Bernoulli-numbers/Phix/bernoulli-numbers-1.phix b/Task/Bernoulli-numbers/Phix/bernoulli-numbers-1.phix
new file mode 100644
index 0000000000..e9ae562bd9
--- /dev/null
+++ b/Task/Bernoulli-numbers/Phix/bernoulli-numbers-1.phix
@@ -0,0 +1,41 @@
+include builtins\bigatom.e
+
+constant NUM = 1, DEN = 2
+
+type ba_frac(object r)
+ return sequence(r) and length(r)=2 and bigatom(r[NUM]) and bigatom(r[DEN])
+end type
+
+function ba_gcd(bigatom u, bigatom v)
+bigatom t
+ u = ba_floor(ba_abs(u))
+ v = ba_floor(ba_abs(v))
+ while v!=BA_ZERO do
+ t = u
+ u = v
+ v = ba_remainder(t, v)
+ end while
+ return u
+end function
+
+function ba_frac_normalise(bigatom n, bigatom d)
+bigatom g
+ if ba_compare(d,BA_ZERO)<0 then
+ n = ba_sub(0,n)
+ d = ba_sub(0,d)
+ end if
+ g = ba_gcd(n,d)
+ return {ba_idivide(n,g),ba_idivide(d,g)}
+end function
+
+function ba_frac_sub(ba_frac a, ba_frac b)
+bigatom {an,ad} = a,
+ {bn,bd} = b
+ return ba_frac_normalise(ba_sub(ba_multiply(an,bd),ba_multiply(bn,ad)),ba_multiply(ad,bd))
+end function
+
+function ba_frac_mul(ba_frac a, ba_frac b)
+bigatom {an,ad} = a,
+ {bn,bd} = b
+ return ba_frac_normalise(ba_multiply(an,bn),ba_multiply(ad,bd))
+end function
diff --git a/Task/Bernoulli-numbers/Phix/bernoulli-numbers-2.phix b/Task/Bernoulli-numbers/Phix/bernoulli-numbers-2.phix
new file mode 100644
index 0000000000..c4dc2bab3c
--- /dev/null
+++ b/Task/Bernoulli-numbers/Phix/bernoulli-numbers-2.phix
@@ -0,0 +1,10 @@
+sequence a = {}
+for m=0 to 60 do
+ a = append(a,{ba_new(1),ba_new(m+1)})
+ for j=m to 1 by -1 do
+ a[j] = ba_frac_mul({ba_new(j),ba_new(1)},ba_frac_sub(a[j+1],a[j]))
+ end for
+ if a[1][1]!=BA_ZERO then
+ printf(1,"B(%2d) = %44s / %s\n",{m,ba_sprint(a[1][1]),ba_sprint(a[1][2])})
+ end if
+end for
diff --git a/Task/Bernoulli-numbers/SPAD/bernoulli-numbers.spad b/Task/Bernoulli-numbers/SPAD/bernoulli-numbers.spad
new file mode 100644
index 0000000000..215ee3086e
--- /dev/null
+++ b/Task/Bernoulli-numbers/SPAD/bernoulli-numbers.spad
@@ -0,0 +1 @@
+for n in 0..60 | (b:=bernoulli(n)$INTHEORY; b~=0) repeat print [n,b]
diff --git a/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-1.sidef b/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-1.sidef
new file mode 100644
index 0000000000..f0fff579be
--- /dev/null
+++ b/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-1.sidef
@@ -0,0 +1,22 @@
+func bernoulli_number{}; # must be declared before first used
+
+func bern_helper(n, k) {
+ binomial(n, k) * (bernoulli_number(k) / (n - k + 1));
+}
+
+func bern_diff(n, k, d) {
+ n < k ? d : bern_diff(n, k + 1, d - bern_helper(n + 1, k));
+}
+
+bernoulli_number = func(n) is cached {
+
+ n.is_one && return 1/2;
+ n.is_odd && return 0;
+
+ n > 0 ? bern_diff(n - 1, 0, 1) : 1;
+}
+
+range(0, 60).each { |i|
+ var num = bernoulli_number(i) || next;
+ printf("B(%2d) = %44s / %s\n", i, num.parts);
+}
diff --git a/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-2.sidef b/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-2.sidef
new file mode 100644
index 0000000000..c7eb730784
--- /dev/null
+++ b/Task/Bernoulli-numbers/Sidef/bernoulli-numbers-2.sidef
@@ -0,0 +1,13 @@
+func bernoulli_print {
+ var a = []
+ range(0, 60).each { |m|
+ a << (m+1 -> inv)
+ m.downto(1).each { |j|
+ (a[j-1] -= a[j]) *= j
+ }
+ a[0] || next
+ printf("B(%2d) = %44s / %s\n", m, a[0].parts)
+ }
+}
+
+bernoulli_print()
diff --git a/Task/Bernoulli-numbers/jq/bernoulli-numbers-1.jq b/Task/Bernoulli-numbers/jq/bernoulli-numbers-1.jq
new file mode 100644
index 0000000000..bc826fc308
--- /dev/null
+++ b/Task/Bernoulli-numbers/jq/bernoulli-numbers-1.jq
@@ -0,0 +1,39 @@
+# def negate:
+# def lessOrEqual(x; y): # x <= y
+# def long_add(x;y): # x+y
+# def long_minus(x;y): # x-y
+# def long_multiply(x;y) # x*y
+# def long_divide(x;y): # x/y => [q,r]
+# def long_div(x;y) # integer division
+# def long_mod(x;y) # %
+
+# In all cases, x and y must be strings
+
+def negate: (- tonumber) | tostring;
+
+def lessOrEqual(num1; num2): (num1|tonumber) <= (num2|tonumber);
+
+def long_add(num1; num2): ((num1|tonumber) + (num2|tonumber)) | tostring;
+
+def long_minus(x;y): ((num1|tonumber) - (num2|tonumber)) | tostring;
+
+# multiply two decimal strings, which may be signed (+ or -)
+def long_multiply(num1; num2):
+ ((num1|tonumber) * (num2|tonumber)) | tostring;
+
+# return [quotient, remainder]
+# 0/0 = 1; n/0 => error
+def long_divide(xx;yy): # x/y => [q,r] imples x == (y * q) + r
+ def ld(x;y):
+ def abs: if . < 0 then -. else . end;
+ (x|abs) as $x | (y|abs) as $y
+ | (if (x >= 0 and y > 0) or (x < 0 and y < 0) then 1 else -1 end) as $sign
+ | (if x >= 0 then 1 else -1 end) as $sx
+ | [$sign * ($x / $y | floor), $sx * ($x % $y)];
+ ld( xx|tonumber; yy|tonumber) | map(tostring);
+
+def long_div(x;y):
+ long_divide(x;y) | .[0];
+
+def long_mod(x;y):
+ ((x|tonumber) % (y|tonumber)) | tostring;
diff --git a/Task/Bernoulli-numbers/jq/bernoulli-numbers-2.jq b/Task/Bernoulli-numbers/jq/bernoulli-numbers-2.jq
new file mode 100644
index 0000000000..520f9af5a4
--- /dev/null
+++ b/Task/Bernoulli-numbers/jq/bernoulli-numbers-2.jq
@@ -0,0 +1,54 @@
+# A fraction is represented by [numerator, denominator] in reduced form, with the sign on top
+
+# a and b should be BigInt; return a BigInt
+def gcd(a; b):
+ def long_abs: . as $in | if lessOrEqual("0"; $in) then $in else negate end;
+
+ # subfunction rgcd expects [a,b] as input
+ # i.e. a ~ .[0] and b ~ .[1]
+ def rgcd:
+ .[0] as $a | .[1] as $b
+ | if $b == "0" then $a
+ else [$b, long_mod($a ; $b ) ] | rgcd
+ end;
+
+ a as $a | b as $b
+ | [$a,$b] | rgcd | long_abs ;
+
+def normalize:
+ .[0] as $p | .[1] as $q
+ | if $p == "0" then ["0", "1"]
+ elif lessOrEqual($q ; "0") then [ ($p|negate), ($q|negate)] | normalize
+ else gcd($p; $q) as $g
+ | [ long_div($p;$g), long_div($q;$g) ]
+ end ;
+
+# a and b should be fractions expressed in the form [p, q]
+def add(a; b):
+ a as $a | b as $b
+ | if $a[1] == "1" and $b[1] == "1" then [ long_add($a[0]; $b[0]) , "1"]
+ elif $a[1] == $b[1] then [ long_add( $a[0]; $b[0]), $a[1] ] | normalize
+ elif $a[0] == "0" then $b
+ elif $b[0] == "0" then $a
+ else [ long_add( long_multiply($a[0]; $b[1]) ; long_multiply($b[0]; $a[1])),
+ long_multiply($a[1]; $b[1]) ]
+ | normalize
+ end ;
+
+# a and/or b may be BigInts, or [p,q] fractions
+def multiply(a; b):
+ a as $a | b as $b
+ | if ($a|type) == "string" and ($b|type) == "string" then [ long_multiply($a; $b), "1"]
+ else
+ if $a|type == "string" then [ long_multiply( $a; $b[0]), $b[1] ]
+ elif $b|type == "string" then [ long_multiply( $b; $a[0]), $a[1] ]
+ else [ long_multiply( $a[0]; $b[0]), long_multiply($a[1]; $b[1]) ]
+ end
+ | normalize
+ end ;
+
+def minus(a; b):
+ a as $a | b as $b
+ | if $a == $b then ["0", "1"]
+ else add($a; [ ($b[0]|negate), $b[1] ] )
+ end ;
diff --git a/Task/Bernoulli-numbers/jq/bernoulli-numbers-3.jq b/Task/Bernoulli-numbers/jq/bernoulli-numbers-3.jq
new file mode 100644
index 0000000000..129843183a
--- /dev/null
+++ b/Task/Bernoulli-numbers/jq/bernoulli-numbers-3.jq
@@ -0,0 +1,10 @@
+# Using the algorithm in the task description:
+def bernoulli(n):
+ reduce range(0; n+1) as $m
+ ( [];
+ .[$m] = ["1", long_add($m|tostring; "1")] # i.e. 1 / ($m+1)
+ | reduce ($m - range(0 ; $m)) as $j
+ (.;
+ .[$j-1] = multiply( [($j|tostring), "1"]; minus( .[$j-1] ; .[$j]) ) ))
+ | .[0] # (which is Bn)
+ ;
diff --git a/Task/Bernoulli-numbers/jq/bernoulli-numbers-4.jq b/Task/Bernoulli-numbers/jq/bernoulli-numbers-4.jq
new file mode 100644
index 0000000000..68c2b58035
--- /dev/null
+++ b/Task/Bernoulli-numbers/jq/bernoulli-numbers-4.jq
@@ -0,0 +1,2 @@
+range(0;61)
+| if . % 2 == 0 or . == 1 then "\(.): \(bernoulli(.) )" else empty end
diff --git a/Task/Bernoulli-numbers/jq/bernoulli-numbers-5.jq b/Task/Bernoulli-numbers/jq/bernoulli-numbers-5.jq
new file mode 100644
index 0000000000..8f552dfc7c
--- /dev/null
+++ b/Task/Bernoulli-numbers/jq/bernoulli-numbers-5.jq
@@ -0,0 +1,33 @@
+$ jq -n -r -f Bernoulli.jq
+0: ["1","1"]
+1: ["1","2"]
+2: ["1","6"]
+4: ["-1","30"]
+6: ["1","42"]
+8: ["-1","30"]
+10: ["5","66"]
+12: ["-691","2730"]
+14: ["7","6"]
+16: ["-3617","510"]
+18: ["43867","798"]
+20: ["-174611","330"]
+22: ["854513","138"]
+24: ["-236364091","2730"]
+26: ["8553103","6"]
+28: ["-23749461029","870"]
+30: ["8615841276005","14322"]
+32: ["-7709321041217","510"]
+34: ["2577687858367","6"]
+36: ["-26315271553053477373","1919190"]
+38: ["2929993913841559","6"]
+40: ["-261082718496449122051","13530"]
+42: ["1520097643918070802691","1806"]
+44: ["-27833269579301024235023","690"]
+46: ["596451111593912163277961","282"]
+48: ["-5609403368997817686249127547","46410"]
+50: ["495057205241079648212477525","66"]
+52: ["-801165718135489957347924991853","1590"]
+54: ["29149963634884862421418123812691","798"]
+56: ["-2479392929313226753685415739663229","870"]
+58: ["84483613348880041862046775994036021","354"]
+60: ["-1215233140483755572040304994079820246041491","56786730"]
diff --git a/Task/Best-shuffle/Phix/best-shuffle.phix b/Task/Best-shuffle/Phix/best-shuffle.phix
new file mode 100644
index 0000000000..686cd7878c
--- /dev/null
+++ b/Task/Best-shuffle/Phix/best-shuffle.phix
@@ -0,0 +1,15 @@
+constant tests = {"abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"}
+string s,t
+ for test=1 to length(tests) do
+ s = tests[test]
+ t = shuffle(s)
+ for i=1 to length(t) do
+ for j=1 to length(t) do
+ if i!=j and t[i]!=s[j] and t[j]!=s[i] then
+ {t[i], t[j]} = {t[j], t[i]}
+ exit
+ end if
+ end for
+ end for
+ printf(1,"%s -> %s (%d)\n",{s,t,sum(sq_eq(t,s))})
+ end for
diff --git a/Task/Best-shuffle/Sidef/best-shuffle.sidef b/Task/Best-shuffle/Sidef/best-shuffle.sidef
new file mode 100644
index 0000000000..2782238e66
--- /dev/null
+++ b/Task/Best-shuffle/Sidef/best-shuffle.sidef
@@ -0,0 +1,22 @@
+func best_shuffle(String orig) -> (String, Number) {
+
+ var s = orig.chars
+ var t = s.shuffle
+
+ s.range.each { |i|
+ s.range.each { |j|
+ if (i!=j && t[i]!=s[j] && t[j]!=s[i]) {
+ t[i, j] = t[j, i];
+ break;
+ }
+ }
+ }
+
+ var word = t.join;
+ (word, orig ^ word -> count("\0"));
+}
+
+.each { |word|
+ var (sword, score) = best_shuffle(word)
+ "%-12s %12s: %d\n".printf(word, sword, score)
+}
diff --git a/Task/Binary-digits/8th/binary-digits.8th b/Task/Binary-digits/8th/binary-digits.8th
new file mode 100644
index 0000000000..1df66b3a8e
--- /dev/null
+++ b/Task/Binary-digits/8th/binary-digits.8th
@@ -0,0 +1,2 @@
+2 base drop
+#50 . cr
diff --git a/Task/Binary-digits/Axe/binary-digits.axe b/Task/Binary-digits/Axe/binary-digits.axe
new file mode 100644
index 0000000000..92ca80e352
--- /dev/null
+++ b/Task/Binary-digits/Axe/binary-digits.axe
@@ -0,0 +1,11 @@
+Lbl BIN
+.Axe supports 16-bit integers, so 16 digits are enough
+L₁+16→P
+0→{P}
+While r₁
+ P--
+ {(r₁ and 1)▶Hex+3}→P
+ r₁/2→r₁
+End
+Disp P,i
+Return
diff --git a/Task/Binary-digits/EchoLisp/binary-digits.echolisp b/Task/Binary-digits/EchoLisp/binary-digits.echolisp
new file mode 100644
index 0000000000..54bd5a52f0
--- /dev/null
+++ b/Task/Binary-digits/EchoLisp/binary-digits.echolisp
@@ -0,0 +1,9 @@
+;; primitive : (number->string number [base]) - default base = 10
+
+(number->string 2 2)
+→ 10
+
+(for-each (compose writeln (rcurry number->string 2)) '( 5 50 9000)) →
+101
+110010
+10001100101000
diff --git a/Task/Binary-digits/FreeBASIC/binary-digits.freebasic b/Task/Binary-digits/FreeBASIC/binary-digits.freebasic
new file mode 100644
index 0000000000..6471f07add
--- /dev/null
+++ b/Task/Binary-digits/FreeBASIC/binary-digits.freebasic
@@ -0,0 +1,9 @@
+' FreeBASIC v1.05.0 win64
+Dim As String fmt = "#### -> &"
+Print Using fmt; 5; Bin(5)
+Print Using fmt; 50; Bin(50)
+Print Using fmt; 9000; Bin(9000)
+Print
+Print "Press any key to exit the program"
+Sleep
+End
diff --git a/Task/Binary-digits/FunL/binary-digits.funl b/Task/Binary-digits/FunL/binary-digits.funl
new file mode 100644
index 0000000000..3d0cc837e6
--- /dev/null
+++ b/Task/Binary-digits/FunL/binary-digits.funl
@@ -0,0 +1,2 @@
+for n <- [5, 50, 9000, 9000000000]
+ println( n, bin(n) )
diff --git a/Task/Binary-digits/Futhark/binary-digits.futhark b/Task/Binary-digits/Futhark/binary-digits.futhark
new file mode 100644
index 0000000000..daaaaceb8a
--- /dev/null
+++ b/Task/Binary-digits/Futhark/binary-digits.futhark
@@ -0,0 +1,6 @@
+fun main(x: i32): i64 =
+ loop (out = 0i64) = for i < 32 do
+ let digit = (x >> (31-i)) & 1
+ let out = (out * 10i64) + i64(digit)
+ in out
+ in out
diff --git a/Task/Binary-digits/Idris/binary-digits.idris b/Task/Binary-digits/Idris/binary-digits.idris
new file mode 100644
index 0000000000..c9165aeb41
--- /dev/null
+++ b/Task/Binary-digits/Idris/binary-digits.idris
@@ -0,0 +1,18 @@
+module Main
+
+binaryDigit : Integer -> Char
+binaryDigit n = if (mod n 2) == 1 then '1' else '0'
+
+binaryString : Integer -> String
+binaryString 0 = "0"
+binaryString n = pack (loop n [])
+ where loop : Integer -> List Char -> List Char
+ loop 0 acc = acc
+ loop n acc = loop (div n 2) (binaryDigit n :: acc)
+
+main : IO ()
+main = do
+ putStrLn (binaryString 0)
+ putStrLn (binaryString 5)
+ putStrLn (binaryString 50)
+ putStrLn (binaryString 9000)
diff --git a/Task/Binary-digits/LFE/binary-digits-1.lfe b/Task/Binary-digits/LFE/binary-digits-1.lfe
new file mode 100644
index 0000000000..7d1dc0f174
--- /dev/null
+++ b/Task/Binary-digits/LFE/binary-digits-1.lfe
@@ -0,0 +1 @@
+(: io format '"~.2B~n~.2B~n~.2B~n" (list 5 50 9000))
diff --git a/Task/Binary-digits/LFE/binary-digits-2.lfe b/Task/Binary-digits/LFE/binary-digits-2.lfe
new file mode 100644
index 0000000000..4546caec1c
--- /dev/null
+++ b/Task/Binary-digits/LFE/binary-digits-2.lfe
@@ -0,0 +1,6 @@
+(: lists foreach
+ (lambda (x)
+ (: io format
+ '"~s~n"
+ (list (: erlang integer_to_list x 2))))
+ (list 5 50 9000))
diff --git a/Task/Binary-digits/Nim/binary-digits.nim b/Task/Binary-digits/Nim/binary-digits.nim
new file mode 100644
index 0000000000..7b48bb7aa6
--- /dev/null
+++ b/Task/Binary-digits/Nim/binary-digits.nim
@@ -0,0 +1,24 @@
+proc binDigits(x: BiggestInt, r: int): int =
+ ## Calculates how many digits `x` has when each digit covers `r` bits.
+ result = 1
+ var y = x shr r
+ while y > 0:
+ y = y shr r
+ inc(result)
+
+proc toBin*(x: BiggestInt, len: Natural = 0): string =
+ ## converts `x` into its binary representation. The resulting string is
+ ## always `len` characters long. By default the length is determined
+ ## automatically. No leading ``0b`` prefix is generated.
+ var
+ mask: BiggestInt = 1
+ shift: BiggestInt = 0
+ len = if len == 0: binDigits(x, 1) else: len
+ result = newString(len)
+ for j in countdown(len-1, 0):
+ result[j] = chr(int((x and mask) shr shift) + ord('0'))
+ shift = shift + 1
+ mask = mask shl 1
+
+for i in 0..15:
+ echo toBin(i)
diff --git a/Task/Binary-digits/Panda/binary-digits.panda b/Task/Binary-digits/Panda/binary-digits.panda
new file mode 100644
index 0000000000..78fa950840
--- /dev/null
+++ b/Task/Binary-digits/Panda/binary-digits.panda
@@ -0,0 +1 @@
+0..15.radix:2 nl
diff --git a/Task/Binary-digits/Peloton/binary-digits.peloton b/Task/Binary-digits/Peloton/binary-digits.peloton
new file mode 100644
index 0000000000..9a6d13e539
--- /dev/null
+++ b/Task/Binary-digits/Peloton/binary-digits.peloton
@@ -0,0 +1,6 @@
+<@ defbaslit>2@>
+
+<@ saybaslit>0@>
+<@ saybaslit>5@>
+<@ saybaslit>50@>
+<@ saybaslit>9000@>
diff --git a/Task/Binary-digits/Phix/binary-digits.phix b/Task/Binary-digits/Phix/binary-digits.phix
new file mode 100644
index 0000000000..7327e4bab7
--- /dev/null
+++ b/Task/Binary-digits/Phix/binary-digits.phix
@@ -0,0 +1,3 @@
+printf(1,"%b\n",5)
+printf(1,"%b\n",50)
+printf(1,"%b\n",9000)
diff --git a/Task/Binary-digits/Ring/binary-digits.ring b/Task/Binary-digits/Ring/binary-digits.ring
new file mode 100644
index 0000000000..5f8c4b743a
--- /dev/null
+++ b/Task/Binary-digits/Ring/binary-digits.ring
@@ -0,0 +1,12 @@
+see "Number to convert : "
+give a
+n = 0
+while pow(2,n+1) < a
+ n = n + 1
+end
+
+for i = n to 0 step -1
+ x = pow(2,i)
+ if a >= x see 1 a = a - x
+ else see 0 ok
+next
diff --git a/Task/Binary-digits/SequenceL/binary-digits.sequencel b/Task/Binary-digits/SequenceL/binary-digits.sequencel
new file mode 100644
index 0000000000..5ee547d93d
--- /dev/null
+++ b/Task/Binary-digits/SequenceL/binary-digits.sequencel
@@ -0,0 +1,9 @@
+main := toBinaryString([5, 50, 9000]);
+
+toBinaryString(number(0)) :=
+ let
+ val := "1" when number mod 2 = 1 else "0";
+ in
+ toBinaryString(floor(number/2)) ++ val when floor(number/2) > 0
+ else
+ val;
diff --git a/Task/Binary-digits/Sidef/binary-digits.sidef b/Task/Binary-digits/Sidef/binary-digits.sidef
new file mode 100644
index 0000000000..f1a512a661
--- /dev/null
+++ b/Task/Binary-digits/Sidef/binary-digits.sidef
@@ -0,0 +1,3 @@
+[5, 50, 9000].each { |n|
+ say n.as_bin;
+}
diff --git a/Task/Binary-digits/SkookumScript/binary-digits.skookum b/Task/Binary-digits/SkookumScript/binary-digits.skookum
new file mode 100644
index 0000000000..f4815a4729
--- /dev/null
+++ b/Task/Binary-digits/SkookumScript/binary-digits.skookum
@@ -0,0 +1,3 @@
+println(5.binary)
+println(50.binary)
+println(9000.binary)
diff --git a/Task/Binary-digits/Swift/binary-digits.swift b/Task/Binary-digits/Swift/binary-digits.swift
new file mode 100644
index 0000000000..981a7395a1
--- /dev/null
+++ b/Task/Binary-digits/Swift/binary-digits.swift
@@ -0,0 +1,3 @@
+for num in [5, 50, 9000] {
+ println(String(num, radix: 2))
+}
diff --git a/Task/Binary-digits/Visual-FoxPro/binary-digits.visual b/Task/Binary-digits/Visual-FoxPro/binary-digits.visual
new file mode 100644
index 0000000000..46b5326186
--- /dev/null
+++ b/Task/Binary-digits/Visual-FoxPro/binary-digits.visual
@@ -0,0 +1,25 @@
+*!* Binary Digits
+CLEAR
+k = CAST(5 As I)
+? NToBin(k)
+k = CAST(50 As I)
+? NToBin(k)
+k = CAST(9000 As I)
+? NToBin(k)
+
+FUNCTION NTOBin(n As Integer) As String
+LOCAL i As Integer, b As String, v As Integer
+b = ""
+v = HiBit(n)
+FOR i = 0 TO v
+ b = IIF(BITTEST(n, i), "1", "0") + b
+ENDFOR
+RETURN b
+ENDFUNC
+
+FUNCTION HiBit(n As Double) As Integer
+*!* Find the highest power of 2 in n
+LOCAL v As Double
+v = LOG(n)/LOG(2)
+RETURN FLOOR(v)
+ENDFUNC
diff --git a/Task/Binary-digits/Wortel/binary-digits-1.wortel b/Task/Binary-digits/Wortel/binary-digits-1.wortel
new file mode 100644
index 0000000000..c2ed44e083
--- /dev/null
+++ b/Task/Binary-digits/Wortel/binary-digits-1.wortel
@@ -0,0 +1,3 @@
+\.toString 2
+; the following function also casts the string to a number
+^(@+ \.toString 2)
diff --git a/Task/Binary-digits/Wortel/binary-digits-2.wortel b/Task/Binary-digits/Wortel/binary-digits-2.wortel
new file mode 100644
index 0000000000..d1a07b911e
--- /dev/null
+++ b/Task/Binary-digits/Wortel/binary-digits-2.wortel
@@ -0,0 +1 @@
+@each ^(console.log \.toString 2) [5 50 900]
diff --git a/Task/Binary-digits/jq/binary-digits.jq b/Task/Binary-digits/jq/binary-digits.jq
new file mode 100644
index 0000000000..00ace576c2
--- /dev/null
+++ b/Task/Binary-digits/jq/binary-digits.jq
@@ -0,0 +1,10 @@
+def binary_digits:
+ if . == 0 then "0"
+ else [recurse( if . == 0 then empty else ./2 | floor end ) % 2 | tostring]
+ | reverse
+ | .[1:] # remove the leading 0
+ | join("")
+ end ;
+
+# The task:
+(5, 50, 9000) | binary_digits
diff --git a/Task/Binary-search/Axe/binary-search.axe b/Task/Binary-search/Axe/binary-search.axe
new file mode 100644
index 0000000000..ba50708932
--- /dev/null
+++ b/Task/Binary-search/Axe/binary-search.axe
@@ -0,0 +1,16 @@
+Lbl BSEARCH
+0→L
+r₃-1→H
+While L≤H
+ (L+H)/2→M
+ If {L+M}>r₂
+ M-1→H
+ ElseIf {L+M} as[i] for all i < low
+ -- value < as[i] for all i > high
+ let mid = (low+high) / 2
+ in if as[mid] > value
+ then (low, mid - 1)
+ else if as[mid] < value
+ then (mid + 1, high)
+ else (mid, mid-1) -- Force termination.
+ in low
diff --git a/Task/Binary-search/Nim/binary-search-1.nim b/Task/Binary-search/Nim/binary-search-1.nim
new file mode 100644
index 0000000000..da87d95250
--- /dev/null
+++ b/Task/Binary-search/Nim/binary-search-1.nim
@@ -0,0 +1,4 @@
+import algorithm
+
+let s = @[2,3,4,5,6,7,8,9,10,12,14,16,18,20,22,25,27,30]
+echo binarySearch(s, 10)
diff --git a/Task/Binary-search/Nim/binary-search-2.nim b/Task/Binary-search/Nim/binary-search-2.nim
new file mode 100644
index 0000000000..5c54b3bfc0
--- /dev/null
+++ b/Task/Binary-search/Nim/binary-search-2.nim
@@ -0,0 +1,7 @@
+proc binarySearch[T](a: openArray[T], key: T): int =
+ var b = len(a)
+ while result < b:
+ var mid = (result + b) div 2
+ if a[mid] < key: result = mid + 1
+ else: b = mid
+ if result >= len(a) or a[result] != key: result = -1
diff --git a/Task/Binary-search/Phix/binary-search-1.phix b/Task/Binary-search/Phix/binary-search-1.phix
new file mode 100644
index 0000000000..6c8719c37a
--- /dev/null
+++ b/Task/Binary-search/Phix/binary-search-1.phix
@@ -0,0 +1,16 @@
+function binary_search(sequence s, object val, integer low, integer high)
+ integer mid, cmp
+ if high < low then
+ return 0 -- not found
+ else
+ mid = floor( (low + high) / 2 )
+ cmp = compare(s[mid], val)
+ if cmp > 0 then
+ return binary_search(s, val, low, mid-1)
+ elsif cmp < 0 then
+ return binary_search(s, val, mid+1, high)
+ else
+ return mid
+ end if
+ end if
+end function
diff --git a/Task/Binary-search/Phix/binary-search-2.phix b/Task/Binary-search/Phix/binary-search-2.phix
new file mode 100644
index 0000000000..4ffa8d6cb3
--- /dev/null
+++ b/Task/Binary-search/Phix/binary-search-2.phix
@@ -0,0 +1,17 @@
+function binary_search(sequence s, object val)
+ integer low, high, mid, cmp
+ low = 1
+ high = length(s)
+ while low <= high do
+ mid = floor( (low + high) / 2 )
+ cmp = compare(s[mid], val)
+ if cmp > 0 then
+ high = mid - 1
+ elsif cmp < 0 then
+ low = mid + 1
+ else
+ return mid
+ end if
+ end while
+ return 0 -- not found
+end function
diff --git a/Task/Binary-search/Ring/binary-search.ring b/Task/Binary-search/Ring/binary-search.ring
new file mode 100644
index 0000000000..b52ffc3042
--- /dev/null
+++ b/Task/Binary-search/Ring/binary-search.ring
@@ -0,0 +1,20 @@
+decimals(0)
+array = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
+
+find= 42
+index = where(array, find, 0, len(array))
+if index >= 0
+ see "the value " + find+ " was found at index " + index
+else
+ see "the value " + find + " was not found"
+ok
+
+func where a, s, b, t
+ h = 2
+ while h<(t-b) h *= 2 end
+ h /= 2
+ while h != 0
+ if (b+h)<=t if s>=a[b+h] b += h ok ok
+ h /= 2
+ end
+ if s=a[b] return b-1 else return -1 ok
diff --git a/Task/Binary-search/SequenceL/binary-search.sequencel b/Task/Binary-search/SequenceL/binary-search.sequencel
new file mode 100644
index 0000000000..b4cde6f042
--- /dev/null
+++ b/Task/Binary-search/SequenceL/binary-search.sequencel
@@ -0,0 +1,11 @@
+binarySearch(A(1), value(0), low(0), high(0)) :=
+ let
+ mid := low + (high - low) / 2;
+ in
+ -1 when high < low //Not Found
+ else
+ binarySearch(A, value, low, mid - 1) when A[mid] > value
+ else
+ binarySearch(A, value, mid + 1, high) when A[mid] < value
+ else
+ mid;
diff --git a/Task/Binary-search/Sidef/binary-search-1.sidef b/Task/Binary-search/Sidef/binary-search-1.sidef
new file mode 100644
index 0000000000..3d61581f48
--- /dev/null
+++ b/Task/Binary-search/Sidef/binary-search-1.sidef
@@ -0,0 +1,14 @@
+func binary_search(a, i) {
+
+ var l = 0;
+ var h = a.end;
+
+ while (l <= h) {
+ var mid = (h+l / 2 -> int);
+ a[mid] > i && (h = mid-1; next);
+ a[mid] < i && (l = mid+1; next);
+ return mid;
+ }
+
+ return -1;
+}
diff --git a/Task/Binary-search/Sidef/binary-search-2.sidef b/Task/Binary-search/Sidef/binary-search-2.sidef
new file mode 100644
index 0000000000..b85b85becc
--- /dev/null
+++ b/Task/Binary-search/Sidef/binary-search-2.sidef
@@ -0,0 +1,13 @@
+func binary_search(arr, value, low=0, high=arr.end) {
+ high < low && return -1;
+ var middle = (high+low / 2 -> int);
+
+ if (value < arr[middle]) {
+ return binary_search(arr, value, low, middle-1);
+ }
+ elsif (value > arr[middle]) {
+ return binary_search(arr, value, middle+1, high);
+ }
+
+ return middle;
+}
diff --git a/Task/Binary-search/Sidef/binary-search-3.sidef b/Task/Binary-search/Sidef/binary-search-3.sidef
new file mode 100644
index 0000000000..e91102edcb
--- /dev/null
+++ b/Task/Binary-search/Sidef/binary-search-3.sidef
@@ -0,0 +1 @@
+say binary_search([34, 42, 55, 778], 55); #=> 2
diff --git a/Task/Binary-search/Swift/binary-search-1.swift b/Task/Binary-search/Swift/binary-search-1.swift
new file mode 100644
index 0000000000..c7727bed1f
--- /dev/null
+++ b/Task/Binary-search/Swift/binary-search-1.swift
@@ -0,0 +1,10 @@
+func binarySearch(xs: [T], x: T) -> Int? {
+ var recurse: ((Int, Int) -> Int?)!
+ recurse = {(low, high) in switch (low + high) / 2 {
+ case _ where high < low: return nil
+ case let mid where xs[mid] > x: return recurse(low, mid - 1)
+ case let mid where xs[mid] < x: return recurse(mid + 1, high)
+ case let mid: return mid
+ }}
+ return recurse(0, xs.count - 1)
+}
diff --git a/Task/Binary-search/Swift/binary-search-2.swift b/Task/Binary-search/Swift/binary-search-2.swift
new file mode 100644
index 0000000000..c3c2fcfe36
--- /dev/null
+++ b/Task/Binary-search/Swift/binary-search-2.swift
@@ -0,0 +1,11 @@
+func binarySearch(xs: [T], x: T) -> Int? {
+ var (low, high) = (0, xs.count - 1)
+ while low <= high {
+ switch (low + high) / 2 {
+ case let mid where xs[mid] > x: high = mid - 1
+ case let mid where xs[mid] < x: low = mid + 1
+ case let mid: return mid
+ }
+ }
+ return nil
+}
diff --git a/Task/Binary-search/Swift/binary-search-3.swift b/Task/Binary-search/Swift/binary-search-3.swift
new file mode 100644
index 0000000000..77a2318b30
--- /dev/null
+++ b/Task/Binary-search/Swift/binary-search-3.swift
@@ -0,0 +1,15 @@
+func testBinarySearch(n: Int) {
+ let odds = Array(stride(from: 1, through: n, by: 2))
+ let result = flatMap(0...n) {binarySearch(odds, $0)}
+ assert(result == Array(0..(source: [T], transform: (T) -> U?) -> [U] {
+ return source.reduce([]) {(var xs, x) in if let x = transform(x) {xs.append(x)}; return xs}
+}
diff --git a/Task/Binary-search/Wortel/binary-search.wortel b/Task/Binary-search/Wortel/binary-search.wortel
new file mode 100644
index 0000000000..745a5afd26
--- /dev/null
+++ b/Task/Binary-search/Wortel/binary-search.wortel
@@ -0,0 +1,24 @@
+; Recursive
+@var rec &[a v l h] [
+ @if < h l @return null
+ @var m @/ +h l 2
+ @? {
+ > `m a v @!rec[a v l -m 1]
+ < `m a v @!rec[a v +1 m h]
+ m
+ }
+]
+
+; Iterative
+@var itr &[a v] [
+ @vars{l 0 h #-a}
+ @while <= l h [
+ @var m @/ +l h 2
+ @iff {
+ > `m a v :h -m 1
+ < `m a v :l +m 1
+ @return m
+ }
+ ]
+ null
+]
diff --git a/Task/Binary-search/jq/binary-search-1.jq b/Task/Binary-search/jq/binary-search-1.jq
new file mode 100644
index 0000000000..791e261bd8
--- /dev/null
+++ b/Task/Binary-search/jq/binary-search-1.jq
@@ -0,0 +1,11 @@
+def binarySearch(value):
+ # To avoid copying the array, simply pass in the current low and high offsets
+ def binarySearch(low; high):
+ if (high < low) then (-1 - low)
+ else ( (low + high) / 2 | floor) as $mid
+ | if (.[$mid] > value) then binarySearch(low; $mid-1)
+ elif (.[$mid] < value) then binarySearch($mid+1; high)
+ else $mid
+ end
+ end;
+ binarySearch(0; length-1);
diff --git a/Task/Binary-search/jq/binary-search-2.jq b/Task/Binary-search/jq/binary-search-2.jq
new file mode 100644
index 0000000000..596bb1907d
--- /dev/null
+++ b/Task/Binary-search/jq/binary-search-2.jq
@@ -0,0 +1 @@
+[-1,-1.1,1,1,null,[null]] | binarySearch(1)
diff --git a/Task/Binary-strings/Nim/binary-strings.nim b/Task/Binary-strings/Nim/binary-strings.nim
new file mode 100644
index 0000000000..a6b541c6f4
--- /dev/null
+++ b/Task/Binary-strings/Nim/binary-strings.nim
@@ -0,0 +1,23 @@
+var # creation
+ x = "this is a string"
+ y = "this is another string"
+ z = "this is a string"
+
+if x == z: echo "x is z" # comparison
+
+z = "now this is another string too" # assignment
+
+y = z # copying
+
+if x.len == 0: echo "empty" # check if empty
+
+x.add('!') # append a byte
+
+echo x[5..8] # substring
+echo x[8 .. -1] # substring
+
+z = x & y # join strings
+
+import strutils
+
+echo z.replace('t', 'T') # replace occurences of t with T
diff --git a/Task/Binary-strings/Phix/binary-strings.phix b/Task/Binary-strings/Phix/binary-strings.phix
new file mode 100644
index 0000000000..54bb136206
--- /dev/null
+++ b/Task/Binary-strings/Phix/binary-strings.phix
@@ -0,0 +1,24 @@
+string s = "abc"
+ s = x"ef bb bf" -- explicit binary string (the utf8 BOM)
+ s[2] = 0
+ s[3] = 'z'
+ if s="\#EF\0z" then puts(1,"ok\n") end if
+string t = s
+ t[1..2] = "xy" -- s remains unaltered
+ ?t -- "xyz"
+ t = "food" ?t
+ t[2..3] = 'e' ?t -- "feed"
+ t[3..2] = "ast" ?t -- "feasted"
+ t[3..-2] = "" ?t -- "fed"
+ if length(t)=0 then puts(1,"t is empty\n") end if
+ if t!="" then puts(1,"t is not empty\n") end if
+ t = "be"
+ t &= 't' ?t -- bet
+ t = 'a'&t ?t -- abet
+ ?t[2..3] -- be
+ ?substitute(t,"be","bbo") -- abbot
+ ?substitute(t,"be","dep") -- adept
+ t = substitute(t,"be","dep") -- to actually modify t
+ ?join({"abc","def","ghi"}) -- "abc def ghi"
+ ?join({"abc","def","ghi"},"") -- "abcdefghi"
+ ?join({"abc","def","ghi"},"\n") -- "abc\ndef\nghi"
diff --git a/Task/Binary-strings/Ring/binary-strings.ring b/Task/Binary-strings/Ring/binary-strings.ring
new file mode 100644
index 0000000000..6e1ceaf603
--- /dev/null
+++ b/Task/Binary-strings/Ring/binary-strings.ring
@@ -0,0 +1,43 @@
+# string creation
+x = "hello world"
+
+# string destruction
+x = NULL
+
+# string assignment with a null byte
+x = "a"+char(0)+"b"
+see len(x) # ==> 3
+
+# string comparison
+if x = "hello"
+ See "equal"
+else
+ See "not equal"
+ok
+y = 'bc'
+if strcmp(x,y) < 0
+ See x + " is lexicographically less than " + y
+ok
+
+# string cloning
+xx = x
+See x = xx # true, same length and content
+
+# check if empty
+if x = NULL
+ See "is empty"
+ok
+
+# append a byte
+x += char(7)
+
+# substring
+x = "hello"
+x[1] = "H"
+See x + nl
+
+# join strings
+a = "hel"
+b = "lo w"
+c = "orld"
+See a + b + c
diff --git a/Task/Binary-strings/jq/binary-strings-1.jq b/Task/Binary-strings/jq/binary-strings-1.jq
new file mode 100644
index 0000000000..917ad8e045
--- /dev/null
+++ b/Task/Binary-strings/jq/binary-strings-1.jq
@@ -0,0 +1,10 @@
+# If the input is a valid representation of a binary string
+# then pass it along:
+def check_binary:
+ . as $a
+ | reduce .[] as $x
+ ($a;
+ if $x | (type == "number" and . == floor
+ and 0 <= . and . <= 255) then $a
+ else error("\(.) is an invalid representation of a byte")
+ end );
diff --git a/Task/Binary-strings/jq/binary-strings-2.jq b/Task/Binary-strings/jq/binary-strings-2.jq
new file mode 100644
index 0000000000..7659ea477a
--- /dev/null
+++ b/Task/Binary-strings/jq/binary-strings-2.jq
@@ -0,0 +1,70 @@
+## Creation of an entity representing an empty binary string
+
+[]
+
+## Assignment
+
+# Unless a check is appropriate, assignment can be done in the
+# usual ways, for example:
+
+[0] as $x # assignment to a variable, $x
+
+s as $x # assignment of s to a variable
+
+.key = s # assignment to a key in a JSON object
+
+# If s must be checked, these become:
+
+(s|check_binary) as $x
+
+.key = (s|check_binary)
+
+## Concatenation:
+
+str+str2
+
+## Comparison
+
+[72,101,108,108,111] == ("Hello"|explode) # evaluates to true
+
+# Other jq comparison operators (!=, <, >, <=, >=) can be used as well.
+
+## Cloning and copying
+# In jq, all entities are immutable and so the distinction between
+# copying and cloning is irrelevant in jq.
+# For example, consider the expression "$s[0] = 1"
+# in the following:
+
+[0] as $s | $s[0] = 1 | $s
+
+# The result is [0] because the expression "$s[0] = 1"
+# evaluates to [1] but does not alter $s. The value of
+# $s can be changed by assignment, e.g.
+
+[0] as $s | $s[0] = 1 | . as $s
+
+## Check if an entity represents the empty binary string
+
+length == 0
+# or
+s == []
+
+## append a byte, b
+
+s + [b] # if the byte, b, is known to be in range
+s + ([b]|check_binary) # if b is suspect
+
+## Extract a substring from a string
+
+# jq uses an index origin of 0 for both JSON arrays strings,
+# so to extract the substring with indices from m to (n-1)
+# inclusive, the expression s[m:n] can be used.
+
+# There are many other possibilities, such as s[m:], s[-1], etc.
+
+## Replace every occurrence of one byte, x, with
+## another sequence of bytes presented as an array, a,
+## of byte-valued integers:
+
+reduce .[] as $byte ([];
+ if $byte == x then . + a else . + [$byte] end)
diff --git a/Task/Bitmap-B-zier-curves-Cubic/FreeBASIC/bitmap-b-zier-curves-cubic.freebasic b/Task/Bitmap-B-zier-curves-Cubic/FreeBASIC/bitmap-b-zier-curves-cubic.freebasic
new file mode 100644
index 0000000000..fd1123319f
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/FreeBASIC/bitmap-b-zier-curves-cubic.freebasic
@@ -0,0 +1,65 @@
+' version 01-11-2016
+' compile with: fbc -s console
+
+' translation from Bitmap/Bresenham's line algorithm C entry
+Sub Br_line(x0 As Integer, y0 As Integer, x1 As Integer, y1 As Integer, _
+ Col As UInteger = &HFFFFFF)
+
+ Dim As Integer dx = Abs(x1 - x0), dy = Abs(y1 - y0)
+ Dim As Integer sx = IIf(x0 < x1, 1, -1)
+ Dim As Integer sy = IIf(y0 < y1, 1, -1)
+ Dim As Integer er = IIf(dx > dy, dx, -dy) \ 2, e2
+
+ Do
+ PSet(x0, y0), col
+ If (x0 = x1) And (y0 = y1) Then Exit Do
+ e2 = er
+ If e2 > -dx Then Er -= dy : x0 += sx
+ If e2 < dy Then Er += dx : y0 += sy
+ Loop
+
+End Sub
+
+' Bitmap/Bézier curves/Cubic BBC BASIC entry
+Sub beziercubic(x1 As Double, y1 As Double, x2 As Double, y2 As Double, _
+ x3 As Double, y3 As Double, x4 As Double, y4 As Double, _
+ n As ULong, col As UInteger = &HFFFFFF)
+
+ Type point_
+ x As Integer
+ y As Integer
+ End Type
+
+ Dim As ULong i
+ Dim As Double t, t1, a, b, c, d
+ Dim As point_ p(n)
+
+ For i = 0 To n
+ t = i / n
+ t1 = 1 - t
+ a = t1 ^ 3
+ b = t * t1 * t1 * 3
+ c = t * t * t1 * 3
+ d = t ^ 3
+ p(i).x = Int(a * x1 + b * x2 + c * x3 + d * x4 + .5)
+ p(i).y = Int(a * y1 + b * y2 + c * y3 + d * y4 + .5)
+ Next
+
+ For i = 0 To n -1
+ Br_line(p(i).x, p(i).y, p(i +1).x, p(i +1).y, col)
+ Next
+
+End Sub
+
+' ------=< MAIN >=------
+
+ScreenRes 250,250,32 ' 0,0 in top left corner
+
+beziercubic(160, 150, 10, 120, 30, 0, 150, 50, 20)
+
+
+' empty keyboard buffer
+While Inkey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Bitmap-B-zier-curves-Cubic/Phix/bitmap-b-zier-curves-cubic.phix b/Task/Bitmap-B-zier-curves-Cubic/Phix/bitmap-b-zier-curves-cubic.phix
new file mode 100644
index 0000000000..4abd1a98e4
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Cubic/Phix/bitmap-b-zier-curves-cubic.phix
@@ -0,0 +1,30 @@
+function cubic_bezier(sequence img, atom x1, atom y1, atom x2, atom y2, atom x3, atom y3, atom x4, atom y4, integer colour, integer segments)
+atom t, t1, a, b, c, d
+sequence pts = repeat(0,segments*2)
+
+ for i=0 to segments*2-1 by 2 do
+ t = i/segments
+ t1 = 1-t
+ a = power(t1,3)
+ b = 3*t*power(t1,2)
+ c = 3*power(t,2)*t1
+ d = power(t,3)
+ pts[i+1] = floor(a*x1+b*x2+c*x3+d*x4)
+ pts[i+2] = floor(a*y1+b*y2+c*y3+d*y4)
+ end for
+ for i=1 to segments*2-2 by 2 do
+ img = bresLine(img, pts[i], pts[i+1], pts[i+2], pts[i+3], colour)
+ end for
+ return img
+end function
+
+sequence img = new_image(300,200,black)
+ img = cubic_bezier(img, 0,100, 100,0, 200,200, 300,100, white, 40)
+ img = bresLine(img,0,100,100,0,green)
+ img = bresLine(img,100,0,200,200,green)
+ img = bresLine(img,200,200,300,100,green)
+ img[1][100] = red
+ img[100][1] = red
+ img[200][200] = red
+ img[300][100] = red
+ write_ppm("Bézier.ppm",img)
diff --git a/Task/Bitmap-B-zier-curves-Quadratic/FreeBASIC/bitmap-b-zier-curves-quadratic.freebasic b/Task/Bitmap-B-zier-curves-Quadratic/FreeBASIC/bitmap-b-zier-curves-quadratic.freebasic
new file mode 100644
index 0000000000..bea5511ac1
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Quadratic/FreeBASIC/bitmap-b-zier-curves-quadratic.freebasic
@@ -0,0 +1,63 @@
+' version 01-11-2016
+' compile with: fbc -s console
+
+' translation from Bitmap/Bresenham's line algorithm C entry
+Sub Br_line(x0 As Integer, y0 As Integer, x1 As Integer, y1 As Integer, _
+ Col As UInteger = &HFFFFFF)
+
+ Dim As Integer dx = Abs(x1 - x0), dy = Abs(y1 - y0)
+ Dim As Integer sx = IIf(x0 < x1, 1, -1)
+ Dim As Integer sy = IIf(y0 < y1, 1, -1)
+ Dim As Integer er = IIf(dx > dy, dx, -dy) \ 2, e2
+
+ Do
+ PSet(x0, y0), col
+ If (x0 = x1) And (y0 = y1) Then Exit Do
+ e2 = er
+ If e2 > -dx Then Er -= dy : x0 += sx
+ If e2 < dy Then Er += dx : y0 += sy
+ Loop
+
+End Sub
+
+' Bitmap/Bézier curves/Quadratic BBC BASIC entry
+Sub bezierquad(x1 As Double, y1 As Double, x2 As Double, y2 As Double, _
+ x3 As Double, y3 As Double, n As ULong, col As UInteger = &HFFFFFF)
+
+ Type point_
+ x As Integer
+ y As Integer
+ End Type
+
+ Dim As ULong i
+ Dim As Double t, t1, a, b, c, d
+ Dim As point_ p(n)
+
+ For i = 0 To n
+ t = i / n
+ t1 = 1 - t
+ a = t1 ^ 2
+ b = t * t1 * 2
+ c = t ^ 2
+ p(i).x = Int(a * x1 + b * x2 + c * x3 + .5)
+ p(i).y = Int(a * y1 + b * y2 + c * y3 + .5)
+ Next
+
+ For i = 0 To n -1
+ Br_line(p(i).x, p(i).y, p(i +1).x, p(i +1).y, col)
+ Next
+
+End Sub
+
+' ------=< MAIN >=------
+
+ScreenRes 250, 250, 32 ' 0,0 in top left corner
+
+bezierquad(10, 100, 250, 270, 150, 20, 20)
+
+
+' empty keyboard buffer
+While InKey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Bitmap-B-zier-curves-Quadratic/Phix/bitmap-b-zier-curves-quadratic.phix b/Task/Bitmap-B-zier-curves-Quadratic/Phix/bitmap-b-zier-curves-quadratic.phix
new file mode 100644
index 0000000000..77fd2f04c9
--- /dev/null
+++ b/Task/Bitmap-B-zier-curves-Quadratic/Phix/bitmap-b-zier-curves-quadratic.phix
@@ -0,0 +1,27 @@
+function quadratic_bezier(sequence img, atom x1, atom y1, atom x2, atom y2, atom x3, atom y3, integer colour, integer segments)
+atom t, t1, a, b, c
+sequence pts = repeat(0,segments*2)
+
+ for i=0 to segments*2-1 by 2 do
+ t = i/segments
+ t1 = 1-t
+ a = power(t1,2)
+ b = 2*t*t1
+ c = power(t,2)
+ pts[i+1] = floor(a*x1+b*x2+c*x3)
+ pts[i+2] = floor(a*y1+b*y2+c*y3)
+ end for
+ for i=1 to segments*2-2 by 2 do
+ img = bresLine(img, pts[i], pts[i+1], pts[i+2], pts[i+3], colour)
+ end for
+ return img
+end function
+
+sequence img = new_image(200,200,black)
+ img = quadratic_bezier(img, 0,100, 100,200, 200,0, white, 40)
+ img = bresLine(img,0,100,100,200,green)
+ img = bresLine(img,100,200,200,0,green)
+ img[1][100] = red
+ img[100][200] = red
+ img[200][1] = red
+ write_ppm("BézierQ.ppm",img)
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/ERRE/bitmap-bresenhams-line-algorithm.erre b/Task/Bitmap-Bresenhams-line-algorithm/ERRE/bitmap-bresenhams-line-algorithm.erre
new file mode 100644
index 0000000000..032fd979f3
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/ERRE/bitmap-bresenhams-line-algorithm.erre
@@ -0,0 +1,30 @@
+PROGRAM BRESENHAM
+
+!$INCLUDE="PC.LIB"
+
+PROCEDURE BRESENHAM
+! === Draw a line using graphic coordinates
+! Inputs are X1, Y1, X2, Y2: Destroys value of X1, Y1
+dx=ABS(x2-x1) sx=-1
+IF x1dy THEN er=dx
+er=INT(er/2)
+LOOP
+ PSET(x1,y1,1)
+ EXIT IF x1=x2 AND y1=y2
+ e2=er
+ IF e2>-dx THEN er=er-dy x1=x1+sx
+ IF e2 dy, dx, -dy) \ 2, e2
+
+ Do
+ PSet(x0, y0), col
+ If (x0 = x1) And (y0 = y1) Then Exit Do
+ e2 = er
+ If e2 > -dx Then Er -= dy : x0 += sx
+ If e2 < dy Then Er += dx : y0 += sy
+ Loop
+
+End Sub
+
+' ------=< MAIN >=------
+
+Dim As Double x0, y0, x1, y1
+
+ScreenRes 400, 400, 32
+WindowTitle" Press key to end demo"
+Randomize Timer
+
+Do
+ Cls
+ For a As Integer = 1 To 20
+ Br_line(Rnd*380+10, Rnd*380+10, Rnd*380+10, Rnd*380+10, Rnd*&hFFFFFF)
+ Next
+ Sleep 2000
+Loop Until InKey <> "" ' loop until a key is pressed
+
+End
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Nim/bitmap-bresenhams-line-algorithm.nim b/Task/Bitmap-Bresenhams-line-algorithm/Nim/bitmap-bresenhams-line-algorithm.nim
new file mode 100644
index 0000000000..22e54b0dc0
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Nim/bitmap-bresenhams-line-algorithm.nim
@@ -0,0 +1,26 @@
+import math
+
+proc line(img: var Image, p, q: Point) =
+ let
+ dx = abs(q.x - p.x)
+ sx = if p.x < q.x: 1 else: -1
+ dy = abs(q.y - p.y)
+ sy = if p.y < q.y: 1 else: -1
+
+ var
+ p = p
+ q = q
+ err = (if dx > dy: dx else: -dy) div 2
+ e2 = 0
+
+ while true:
+ img[p] = Black
+ if p == q:
+ break
+ e2 = err
+ if e2 > -dx:
+ err -= dy
+ p.x += sx
+ if e2 < dy:
+ err += dx
+ p.y += sy
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Phix/bitmap-bresenhams-line-algorithm.phix b/Task/Bitmap-Bresenhams-line-algorithm/Phix/bitmap-bresenhams-line-algorithm.phix
new file mode 100644
index 0000000000..0c65ae346e
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Phix/bitmap-bresenhams-line-algorithm.phix
@@ -0,0 +1,35 @@
+function bresLine(sequence screenData, integer x0, integer y0, integer x1, integer y1, integer colour)
+-- The line algorithm
+integer deltaX = abs(x1-x0),
+ deltaY = abs(y1-y0),
+ stepX = iff(x0deltaY,deltaX,-deltaY),
+ prevle
+
+ lineError = round(lineError/2,1)
+ while 1 do
+ if x0>=1 and x0<=length(screenData)
+ and y0>=1 and y0<=length(screenData[x0]) then
+ screenData[x0][y0] = colour
+ end if
+ if x0=x1 and y0=y1 then exit end if
+ prevle = lineError
+ if prevle>-deltaX then
+ lineError -= deltaY
+ x0 += stepX
+ end if
+ if prevle dy
+ x1 += sx e -= dy if e < 0 e += dx y1 += sy ok
+ else
+ y1 += sy e -= dx if e < 0 e += dy x1 += sx ok ok
+ end
+ next
+
+ endpaint()
+ }
+ label1 { setpicture(p1) show() }
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Sidef/bitmap-bresenhams-line-algorithm.sidef b/Task/Bitmap-Bresenhams-line-algorithm/Sidef/bitmap-bresenhams-line-algorithm.sidef
new file mode 100644
index 0000000000..84a2bac4e2
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Sidef/bitmap-bresenhams-line-algorithm.sidef
@@ -0,0 +1,53 @@
+func my_draw_line(img, x0, y0, x1, y1) {
+
+ var steep = (abs(y1 - y0) > abs(x1 - x0))
+
+ if (steep) {
+ (y0, x0) = (x0, y0)
+ (y1, x1) = (x1, y1)
+ }
+ if (x0 > x1) {
+ (x1, x0) = (x0, x1)
+ (y1, y0) = (y0, y1)
+ }
+
+ var deltax = (x1 - x0)
+ var deltay = abs(y1 - y0)
+ var error = (deltax / 2)
+ var y = y0
+ var ystep = (y0 < y1 ? 1 : -1)
+
+ x0.to(x1).each { |x|
+ img.draw_point(steep ? ((y, x)) : ((x, y)))
+ error -= deltay
+ if (error < 0) {
+ y += ystep
+ error += deltax
+ }
+ }
+}
+
+require('Image::Imlib2')
+
+var img = %s'Image::Imlib2'.new(160, 160)
+img.set_color(255, 255, 255, 255) # white
+img.fill_rectangle(0,0,160,160)
+
+img.set_color(0,0,0,255) # black
+my_draw_line(img, 10, 80, 80, 160)
+my_draw_line(img, 80, 160, 160, 80)
+my_draw_line(img, 160, 80, 80, 10)
+my_draw_line(img, 80, 10, 10, 80)
+
+img.save("test0.png");
+
+# let's try the same using its internal algo
+img.set_color(255, 255, 255, 255) # white
+img.fill_rectangle(0,0,160,160)
+img.set_color(0,0,0,255) # black
+img.draw_line(10, 80, 80, 160)
+img.draw_line(80, 160, 160, 80)
+img.draw_line(160, 80, 80, 10)
+img.draw_line(80, 10, 10, 80)
+
+img.save("test1.png")
diff --git a/Task/Bitmap-Bresenhams-line-algorithm/Wart/bitmap-bresenhams-line-algorithm.wart b/Task/Bitmap-Bresenhams-line-algorithm/Wart/bitmap-bresenhams-line-algorithm.wart
new file mode 100644
index 0000000000..8f035dc98c
--- /dev/null
+++ b/Task/Bitmap-Bresenhams-line-algorithm/Wart/bitmap-bresenhams-line-algorithm.wart
@@ -0,0 +1,22 @@
+# doesn't handle vertical lines
+def (line x0 y0 x1 y1)
+ let steep ((> abs) y1-y0 x1-x0)
+ when steep
+ swap! x0 y0
+ swap! x1 y1
+ when (x0 > x1)
+ swap! x0 x1
+ swap! y0 y1
+ withs (deltax x1-x0
+ deltay (abs y1-y0)
+ error deltax/2
+ ystep (if (y0 < y1) 1 -1)
+ y y0)
+ for x x0 (x <= x1) ++x
+ if steep
+ plot y x
+ plot x y
+ error -= deltay
+ when (error < 0)
+ y += ystep
+ error += deltax
diff --git a/Task/Bitmap-Flood-fill/ERRE/bitmap-flood-fill.erre b/Task/Bitmap-Flood-fill/ERRE/bitmap-flood-fill.erre
new file mode 100644
index 0000000000..f893d7b9c6
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/ERRE/bitmap-flood-fill.erre
@@ -0,0 +1,87 @@
+PROGRAM MYFILL_DEMO
+
+!VAR SP%
+
+!$INTEGER
+
+CONST IMAGE_WIDTH=320,IMAGE_HEIGHT=200
+
+DIM STACK[6000,1]
+
+FUNCTION QUEUE_COUNT(X)
+ QUEUE_COUNT=SP
+END FUNCTION
+
+!$INCLUDE="PC.LIB"
+
+PROCEDURE QUEUE_INIT
+ SP=0
+END PROCEDURE
+
+PROCEDURE QUEUE_POP(->XX,YY)
+ XX=STACK[SP,0]
+ YY=STACK[SP,1]
+ SP=SP-1
+END PROCEDURE
+
+PROCEDURE QUEUE_PUSH(XX,YY)
+ SP=SP+1
+ STACK[SP,0]=XX
+ STACK[SP,1]=YY
+END PROCEDURE
+
+PROCEDURE FLOOD_FILL(XSTART,YSTART,COLORE_PRIMA,COLORE_RIEMP)
+ LOCAL XEST,XWEST,YNORD,YSUD,X,Y
+ QUEUE_INIT
+ QUEUE_PUSH(XSTART,YSTART)
+ WHILE (QUEUE_COUNT(0)>0) DO
+ QUEUE_POP(->X,Y)
+ XWEST=X
+ XEST=X
+
+ IF Y>0 THEN
+ YNORD=Y-1
+ ELSE
+ YNORD=-1
+ END IF
+
+ IF YZC%)
+ EXIT IF NOT((XESTZC%)
+ EXIT IF NOT((XWEST>0) AND (ZC%=COLORE_PRIMA))
+ XWEST=XWEST-1
+ END LOOP
+
+ FOR X=XWEST TO XEST DO
+ PSET(X,Y,COLORE_RIEMP)
+ POINT(X,YNORD->ZC%)
+ IF YNORD>=0 AND ZC%=COLORE_PRIMA THEN
+ QUEUE_PUSH(X,YNORD)
+ END IF
+ POINT(X,YSUD->ZC%)
+ IF YSUD>=0 AND ZC%=COLORE_PRIMA THEN
+ QUEUE_PUSH(X,YSUD)
+ END IF
+ END FOR
+ END WHILE
+END PROCEDURE ! Flood_Fill
+
+BEGIN
+ SCREEN(1)
+ CIRCLE(100,100,75,2)
+ CIRCLE(120,120,20,2)
+ CIRCLE(80,80,15,2)
+ CIRCLE(120,80,10,2)
+ FLOOD_FILL(100,100,0,1)
+END PROGRAM
diff --git a/Task/Bitmap-Flood-fill/FreeBASIC/bitmap-flood-fill.freebasic b/Task/Bitmap-Flood-fill/FreeBASIC/bitmap-flood-fill.freebasic
new file mode 100644
index 0000000000..c918a66917
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/FreeBASIC/bitmap-flood-fill.freebasic
@@ -0,0 +1,55 @@
+' version 04-11-2016
+' compile with: fbc -s console
+
+' the flood_fill needs to know the boundries of the window/screen
+' without them the routine start to check outside the window
+' this leads to crashes (out of stack)
+' the Line routine has clipping it will not draw outside the window
+
+Sub flood_fill(x As Integer, y As Integer, target As UInteger, fill_color As UInteger)
+
+ Dim As Long x_max, y_max
+ ScreenInfo x_max, y_max
+
+ ' 0, 0 is top left corner
+ If Point(x,y) <> target Then Exit Sub
+
+ Dim As Long l = x, r = x
+
+ While Point(l -1, y) = target AndAlso l -1 > -1
+ l = l -1
+ Wend
+
+ While Point(r +1, y) = target AndAlso r +1 < x_max
+ r = r +1
+ Wend
+
+ Line (l,y) - (r,y), fill_color
+
+ For x = l To r
+ If y +1 < y_max Then flood_fill(x, y +1, target, fill_color)
+ If y -1 > -1 Then flood_fill(x, y -1, target, fill_color)
+ Next
+
+End Sub
+
+' ------=< MAIN >=------
+
+Dim As ULong i, col, x, y
+
+ScreenRes 400, 400, 32
+Randomize Timer
+
+For i As ULong = 1 To 5
+ Circle(Rnd * 400 ,Rnd * 400), i * 40, Rnd * &hFFFFFF
+Next
+
+' hit a key to end or close window
+Do
+ x = Rnd * 400
+ y = Rnd * 400
+ col = Point(x, y)
+ flood_fill(x, y, col, Rnd * &hFFFFFF )
+ Sleep 2000
+ If InKey <> "" OrElse InKey = Chr(255) + "k" Then End
+Loop
diff --git a/Task/Bitmap-Flood-fill/Lingo/bitmap-flood-fill.lingo b/Task/Bitmap-Flood-fill/Lingo/bitmap-flood-fill.lingo
new file mode 100644
index 0000000000..9c2b73f3db
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/Lingo/bitmap-flood-fill.lingo
@@ -0,0 +1 @@
+img.floodFill(x, y, rgb(r,g,b))
diff --git a/Task/Bitmap-Flood-fill/Phix/bitmap-flood-fill.phix b/Task/Bitmap-Flood-fill/Phix/bitmap-flood-fill.phix
new file mode 100644
index 0000000000..4e5e02200f
--- /dev/null
+++ b/Task/Bitmap-Flood-fill/Phix/bitmap-flood-fill.phix
@@ -0,0 +1,23 @@
+function ff(sequence img, integer x, integer y, integer colour, integer target)
+ if x>=1 and x<=length(img)
+ and y>=1 and y<=length(img[x])
+ and img[x][y]=target then
+ img[x][y] = colour
+ img = ff(img,x-1,y,colour,target)
+ img = ff(img,x+1,y,colour,target)
+ img = ff(img,x,y-1,colour,target)
+ img = ff(img,x,y+1,colour,target)
+ end if
+ return img
+end function
+
+function FloodFill(sequence img, integer x, integer y, integer colour)
+integer target = img[x][y]
+ return ff(img,x,y,colour,target)
+end function
+
+sequence img = read_ppm("Circle.ppm")
+ img = FloodFill(img, 200, 100, blue)
+ write_ppm("FloodIn.ppm",img)
+ img = FloodFill(img, 10, 10, green)
+ write_ppm("FloodOut.ppm",img)
diff --git a/Task/Bitmap-Histogram/Phix/bitmap-histogram.phix b/Task/Bitmap-Histogram/Phix/bitmap-histogram.phix
new file mode 100644
index 0000000000..4ff911b30a
--- /dev/null
+++ b/Task/Bitmap-Histogram/Phix/bitmap-histogram.phix
@@ -0,0 +1,38 @@
+function to_bw(sequence image)
+sequence color
+integer lum
+sequence hist = repeat(0,256)
+integer l = 1, r = 256
+integer ltot, rtot
+ for i=1 to length(image) do
+ for j=1 to length(image[i]) do
+ color = sq_div(sq_and_bits(image[i][j], {#FF0000,#FF00,#FF}),
+ {#010000,#0100,#01})
+ lum = floor(0.2126*color[1] + 0.7152*color[2] + 0.0722*color[3])
+ image[i][j] = lum
+ hist[lum+1] += 1
+ end for
+ end for
+ ltot = hist[l]
+ rtot = hist[r]
+ while l!=r do
+ if ltot=0 THEN
+ y%=y%-1
+ ddy%=ddy%+2
+ f%=f%+ddy%
+ END IF
+ x%=x%+1
+ ddx%=ddx%+2
+ f%=f%+ddx%+1
+ PSET(cx%+x%,cy%+y%,1)
+ PSET(cx%-x%,cy%+y%,1)
+ PSET(cx%+x%,cy%-y%,1)
+ PSET(cx%-x%,cy%-y%,1)
+ PSET(cx%+y%,cy%+x%,1)
+ PSET(cx%-y%,cy%+x%,1)
+ PSET(cx%+y%,cy%-x%,1)
+ PSET(cx%-y%,cy%-x%,1)
+ END WHILE
+END PROCEDURE
+
+BEGIN
+ SCREEN(1)
+ ! Draw circles
+ BCircle(100,100,40)
+ BCircle(100,100,80)
+END PROGRAM
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/FreeBASIC/bitmap-midpoint-circle-algorithm.freebasic b/Task/Bitmap-Midpoint-circle-algorithm/FreeBASIC/bitmap-midpoint-circle-algorithm.freebasic
new file mode 100644
index 0000000000..62044d4fa4
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/FreeBASIC/bitmap-midpoint-circle-algorithm.freebasic
@@ -0,0 +1,54 @@
+' version 15-10-2016
+' compile with: fbc -s gui
+
+' Variant with Integer-Based Arithmetic from Wikipedia page:
+' Midpoint circle algorithm
+Sub circle_(x0 As Integer, y0 As Integer , radius As Integer, Col As Integer)
+
+ Dim As Integer x = radius
+ Dim As Integer y
+ ' Decision criterion divided by 2 evaluated at x=r, y=0
+ Dim As Integer decisionOver2 = 1 - x
+
+ While(x >= y)
+ PSet(x0 + x, y0 + y), col
+ PSet(x0 - x, y0 + y), col
+ PSet(x0 + x, y0 - y), col
+ PSet(x0 - x, y0 - y), col
+ PSet(x0 + y, y0 + x), col
+ PSet(x0 - y, y0 + x), col
+ PSet(x0 + y, y0 - x), col
+ PSet(x0 - y, y0 - x), col
+ y = y +1
+ If decisionOver2 <= 0 Then
+ decisionOver2 += y * 2 +1 ' Change in decision criterion for y -> y +1
+ Else
+ x = x -1
+ decisionOver2 += (y - x) * 2 +1 ' Change for y -> y +1, x -> x -1
+ End If
+ Wend
+
+End Sub
+
+' ------=< MAIN >=------
+
+ScreenRes 600, 600, 32
+Dim As Integer w, h, depth
+Randomize Timer
+
+ScreenInfo w, h
+
+For i As Integer = 1 To 10
+ circle_(Rnd * w, Rnd * h , Rnd * 200 , Int(Rnd *&hFFFFFF))
+Next
+
+
+'save screen to BMP file
+BSave "Name.BMP", 0
+
+
+' empty keyboard buffer
+While Inkey <> "" : Wend
+WindowTitle "hit any key to end program"
+Sleep
+End
diff --git a/Task/Bitmap-Midpoint-circle-algorithm/Phix/bitmap-midpoint-circle-algorithm.phix b/Task/Bitmap-Midpoint-circle-algorithm/Phix/bitmap-midpoint-circle-algorithm.phix
new file mode 100644
index 0000000000..cdd23de844
--- /dev/null
+++ b/Task/Bitmap-Midpoint-circle-algorithm/Phix/bitmap-midpoint-circle-algorithm.phix
@@ -0,0 +1,40 @@
+constant red = 0xff2020,
+ yellow = 0xffdf20
+
+function SetPx(sequence img, atom x, atom y, integer colour)
+ if x>=1 and x<=length(img)
+ and y>=1 and y<=length(img[x]) then
+ img[x][y] = colour
+ end if
+ return img
+end function
+
+function Circle(sequence img, atom x, atom y, atom r, integer colour)
+atom x1 = -r,
+ y1 = 0,
+ err = 2-2*r
+ if r>=0 then
+ -- Bresenham algorithm
+ while 1 do
+ img = SetPx(img, x-x1, y+y1, colour)
+ img = SetPx(img, x-y1, y-x1, colour)
+ img = SetPx(img, x+x1, y-y1, colour)
+ img = SetPx(img, x+y1, y+x1, colour)
+ r = err
+ if r>x1 then
+ x1 += 1
+ err += x1*2 + 1
+ end if
+ if r<=y1 then
+ y1 += 1
+ err += y1*2 + 1
+ end if
+ if x1>=0 then exit end if
+ end while
+ end if
+ return img
+end function
+
+sequence img = new_image(400,300,yellow)
+ img = Circle(img, 200, 150, 100, red)
+ write_ppm("Circle.ppm",img)
diff --git a/Task/Bitmap-Read-a-PPM-file/Nim/bitmap-read-a-ppm-file.nim b/Task/Bitmap-Read-a-PPM-file/Nim/bitmap-read-a-ppm-file.nim
new file mode 100644
index 0000000000..09dc4b0e50
--- /dev/null
+++ b/Task/Bitmap-Read-a-PPM-file/Nim/bitmap-read-a-ppm-file.nim
@@ -0,0 +1,33 @@
+import strutils
+
+proc readPPM(f: TFile): Image =
+ if f.readLine != "P6":
+ raise newException(E_base, "Invalid file format")
+
+ var line = ""
+ while f.readLine(line):
+ if line[0] != '#':
+ break
+
+ var parts = line.split(" ")
+ result = img(parseInt parts[0], parseInt parts[1])
+
+ if f.readLine != "255":
+ raise newException(E_base, "Invalid file format")
+
+ var
+ arr: array[256, int8]
+ read = f.readBytes(arr, 0, 256)
+ pos = 0
+
+ while read != 0:
+ for i in 0 .. < read:
+ case pos mod 3
+ of 0: result.pixels[pos div 3].r = arr[i].uint8
+ of 1: result.pixels[pos div 3].g = arr[i].uint8
+ of 2: result.pixels[pos div 3].b = arr[i].uint8
+ else: discard
+
+ inc pos
+
+ read = f.readBytes(arr, 0, 256)
diff --git a/Task/Bitmap-Read-a-PPM-file/Phix/bitmap-read-a-ppm-file.phix b/Task/Bitmap-Read-a-PPM-file/Phix/bitmap-read-a-ppm-file.phix
new file mode 100644
index 0000000000..138e9e83f9
--- /dev/null
+++ b/Task/Bitmap-Read-a-PPM-file/Phix/bitmap-read-a-ppm-file.phix
@@ -0,0 +1,28 @@
+function read_ppm(sequence filename)
+sequence image, line
+integer dimx, dimy, maxcolor
+atom fn = open(filename, "rb")
+ if fn<0 then
+ return -1 -- unable to open
+ end if
+ line = gets(fn)
+ if line!="P6\n" then
+ return -1 -- only ppm6 files are supported
+ end if
+ line = gets(fn)
+ {{dimx,dimy}} = scanf(line,"%d %d%s")
+ line = gets(fn)
+ {{maxcolor}} = scanf(line,"%d%s")
+ image = repeat(repeat(0,dimy),dimx)
+ for y=1 to dimy do
+ for x=1 to dimx do
+ image[x][y] = getc(fn)*#10000 + getc(fn)*#100 + getc(fn)
+ end for
+ end for
+ close(fn)
+ return image
+end function
+
+sequence img = read_ppm("Lena.ppm")
+ img = to_gray(img)
+ write_ppm("LenaGray.ppm",img)
diff --git a/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-1.phix b/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-1.phix
new file mode 100644
index 0000000000..937d6753b7
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-1.phix
@@ -0,0 +1,13 @@
+constant dimx = 512, dimy = 512
+constant fn = open("first.ppm","wb") -- b - binary mode
+sequence color
+printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
+for y=0 to dimy-1 do
+ for x=0 to dimx-1 do
+ color = {remainder(x,256), -- red
+ remainder(y,256), -- green
+ remainder(x*y,256)} -- blue
+ puts(fn,color)
+ end for
+end for
+close(fn)
diff --git a/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-2.phix b/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-2.phix
new file mode 100644
index 0000000000..662c16d26b
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Phix/bitmap-write-a-ppm-file-2.phix
@@ -0,0 +1,16 @@
+procedure write_ppm(sequence filename, sequence image)
+integer fn,dimx,dimy
+sequence colour_triple
+ fn = open(filename,"wb")
+ dimx = length(image)
+ dimy = length(image[1])
+ printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
+ for y = 1 to dimy do
+ for x = 1 to dimx do
+ colour_triple = sq_div(sq_and_bits(image[x][y], {#FF0000,#FF00,#FF}),
+ {#010000,#0100,#01})
+ puts(fn, colour_triple)
+ end for
+ end for
+ close(fn)
+end procedure
diff --git a/Task/Bitmap-Write-a-PPM-file/Sidef/bitmap-write-a-ppm-file.sidef b/Task/Bitmap-Write-a-PPM-file/Sidef/bitmap-write-a-ppm-file.sidef
new file mode 100644
index 0000000000..57ba20217f
--- /dev/null
+++ b/Task/Bitmap-Write-a-PPM-file/Sidef/bitmap-write-a-ppm-file.sidef
@@ -0,0 +1,43 @@
+subset Int < Number {|n| n.is_int }
+subset Uint < Int {|n| n >= 0 }
+subset Uint8 < Int {|n| n ~~ ^256 }
+
+struct Pixel {
+ R < Uint8,
+ G < Uint8,
+ B < Uint8
+}
+
+class Bitmap(width < Uint, height < Uint) {
+ has data = []
+
+ method fill(Pixel p) {
+ data = (width*height -> of { Pixel(p.R, p.G, p.B) })
+ }
+
+ method setpixel(i < Uint, j < Uint, Pixel p) {
+
+ subset WidthLimit < Uint { |n| n ~~ ^width }
+ subset HeightLimit < Uint { |n| n ~~ ^height }
+
+ func (w < WidthLimit, h < HeightLimit) {
+ data[w*height + h] = p
+ }(i, j)
+ }
+
+ method p6 {
+ "P6\n#{width} #{height}\n255\n" +
+ data.map {|p| [p.R, p.G, p.B].pack('C3') }.join
+ }
+}
+
+var b = Bitmap(width: 125, height: 125)
+
+for i,j in (^b.height ~X ^b.width) {
+ b.setpixel(i, j, Pixel(2*i, 2*j, 255 - 2*i))
+}
+
+var file = File("palette.ppm")
+var fh = file.open('>:raw')
+fh.print(b.p6)
+fh.close
diff --git a/Task/Bitmap/Axe/bitmap.axe b/Task/Bitmap/Axe/bitmap.axe
new file mode 100644
index 0000000000..a9ef2763b5
--- /dev/null
+++ b/Task/Bitmap/Axe/bitmap.axe
@@ -0,0 +1,10 @@
+Buff(768)→Pic1
+Fill(Pic1,768,255)
+Pxl-Off(45,30,Pic1)
+
+.Display the bitmap to demonstrate
+Copy(Pic1)
+DispGraph
+Pause 4500
+
+Disp pxl-Test(50,50,Pic1)▶Dec,i
diff --git a/Task/Bitmap/EchoLisp/bitmap.echolisp b/Task/Bitmap/EchoLisp/bitmap.echolisp
new file mode 100644
index 0000000000..a79871517f
--- /dev/null
+++ b/Task/Bitmap/EchoLisp/bitmap.echolisp
@@ -0,0 +1,32 @@
+(lib 'plot)
+(define width 600)
+(define height 400)
+
+(plot-size width height) ;; set image size
+
+(define (blue x y) (rgb 0.0 0.0 1.0)) ;; a constant function
+(plot-rgb blue 1 1) ;; blue everywhere
+
+(lib 'types) ;; uint32 and uint8 vector types
+
+;; bit-map pixel access
+(define bitmap (pixels->uint32-vector)) ;; screen to vector of int32
+ → 240000
+
+(define (pix-at x y) (vector-ref bitmap (+ x (* y width))))
+(rgb->list (pix-at 100 200)) → (0 0 255 255) ;; rgb blue
+
+;; writing to bitmap
+(define (set-color-xy x y col) (vector-set! bitmap (+ x (* y width)) col))
+
+(for* ((x 100)(y 200)) (set-color-xy x y (rgb 1 1 0))) ;; to bitmap
+(vector->pixels bitmap) ;; bitmap to screen
+
+
+;; bit-map color components (r g b a) = index (0 1 2 3) access
+(define bitmap (pixels->uint8-clamped-vector)) ;; screen to vector of uint8
+(vector-length bitmap)
+ → 960000
+(define (blue-at-xy x y) (vector-ref bitmap (+ x 3 (* y width)))) ;; 3 = blue component
+(blue-at-xy 100 200)
+ → 255
diff --git a/Task/Bitmap/Lingo/bitmap.lingo b/Task/Bitmap/Lingo/bitmap.lingo
new file mode 100644
index 0000000000..ba6356d096
--- /dev/null
+++ b/Task/Bitmap/Lingo/bitmap.lingo
@@ -0,0 +1,11 @@
+-- Creates a new image object of size 640x480 pixel and 32-bit color depth
+img = image(640, 480, 32)
+
+-- Fills image with plain red
+img.fill(img.rect, rgb(255,0,0))
+
+-- Gets the color value of the pixel at point (320, 240)
+col = img.getPixel(320, 240)
+
+-- Changes the color of the pixel at point (320, 240) to black
+img.setPixel(320, 240, rgb(0,0,0))
diff --git a/Task/Bitmap/Nim/bitmap.nim b/Task/Bitmap/Nim/bitmap.nim
new file mode 100644
index 0000000000..c7a0318ac0
--- /dev/null
+++ b/Task/Bitmap/Nim/bitmap.nim
@@ -0,0 +1,61 @@
+{.experimental.}
+
+import unsigned
+
+type
+ Luminance = uint8
+ Index = int
+
+ Pixel = tuple
+ r, g, b: Luminance
+
+ Image = object
+ w, h: Index
+ pixels: seq[Pixel]
+
+ Point = tuple
+ x, y: Index
+
+proc px(r, g, b): Pixel =
+ result.r = r.uint8
+ result.g = g.uint8
+ result.b = b.uint8
+
+proc img(w, h: int): Image =
+ result.w = w
+ result.h = h
+ result.pixels.newSeq(w * h)
+
+const
+ Black = px( 0, 0, 0)
+ White = px(255, 255, 255)
+
+iterator indices(img: Image): tuple[x, y: int] =
+ for x in 0 .. < img.w:
+ for y in 0 .. < img.h:
+ yield (x,y)
+
+proc `[]`(img: Image, x, y: int): Pixel =
+ img.pixels[y * img.w + x]
+
+proc `[]=`(img: var Image, x, y: int, c: Pixel) =
+ img.pixels[y * img.w + x] = c
+
+proc fill(img: var Image, color: Pixel) =
+ for x,y in img.indices:
+ img[x,y] = color
+
+proc print(img: Image) =
+ using stdout
+ for x,y in img.indices:
+ if img[x,y] == White:
+ write ' '
+ else:
+ write 'H'
+ write "\n"
+
+when isMainModule:
+ var x = img(64, 64)
+ x.fill px(255,255,255)
+ x[1,2] = px(255, 0, 0)
+ x[3,4] = x[1,2]
diff --git a/Task/Bitmap/Phix/bitmap.phix b/Task/Bitmap/Phix/bitmap.phix
new file mode 100644
index 0000000000..c356e58d4a
--- /dev/null
+++ b/Task/Bitmap/Phix/bitmap.phix
@@ -0,0 +1,20 @@
+-- Some colour constants:
+constant black = #000000,
+-- blue = #0000FF,
+-- green = #00FF00,
+-- red = #FF0000,
+ white = #FFFFFF
+
+-- Create new image filled with some colour
+function new_image(integer width, integer height, integer fill_colour=black)
+ return repeat(repeat(fill_colour,height),width)
+end function
+
+-- Usage example:
+sequence image = new_image(800,600)
+
+-- Set pixel color:
+image[400][300] = white
+
+-- Get pixel color
+integer colour = image[400][300] -- Now colour is #FF0000
diff --git a/Task/Bitmap/SequenceL/bitmap.sequencel b/Task/Bitmap/SequenceL/bitmap.sequencel
new file mode 100644
index 0000000000..5facc762fe
--- /dev/null
+++ b/Task/Bitmap/SequenceL/bitmap.sequencel
@@ -0,0 +1,38 @@
+RGB ::= (R: int(0), G: int(0), B: int(0));
+
+newBitmap: int * int -> RGB(2);
+newBitmap(width, height)[y, x] :=
+ (R: 0, G: 0, B: 0)
+ foreach y within 1 ... height,
+ x within 1 ... width;
+
+fill: RGB(2) * RGB -> RGB(2);
+fill(bitmap(2), color)[y, x] :=
+ color
+ foreach y within 1 ... size(bitmap),
+ x within 1 ... size(bitmap[y]);
+
+setColorAt: RGB(2) * int * int * RGB -> RGB(2);
+setColorAt(bitmap(2), x, y, color)[Y, X] :=
+ color when Y = y and X = x
+ else
+ bitmap[Y, X];
+
+getColorAt: RGB(2) * int * int -> RGB;
+getColorAt(bitmap(2), x, y) := bitmap[y, x];
+
+lightGreen := (R: 51, G: 255, B: 51);
+lightRed := (R: 255, G: 51, B: 51);
+
+main(args(2)) :=
+ let
+ width := 1920;
+ height := 1200;
+
+ cleanImage := newBitmap(width, height);
+
+ filledGreen := fill(cleanImage, lightGreen);
+
+ redCenter := setColorAt(filledGreen, width / 2, height / 2, lightRed);
+ in
+ getColorAt(redCenter, width / 2, height / 2);
diff --git a/Task/Bitwise-IO/Lingo/bitwise-io-1.lingo b/Task/Bitwise-IO/Lingo/bitwise-io-1.lingo
new file mode 100644
index 0000000000..c674cf9cde
--- /dev/null
+++ b/Task/Bitwise-IO/Lingo/bitwise-io-1.lingo
@@ -0,0 +1,63 @@
+-- parent script "BitArray"
+
+property ancestor
+property bitSize
+property _pow2
+
+----------------------------------------
+-- @constructor
+-- @param {integer} [bSize=0]
+----------------------------------------
+on new (me, bSize)
+ if voidP(bitSize) then bitSize=0
+ me.bitSize = bSize
+ byteSize = bitSize/8 + (bitSize mod 8>0)
+ me._pow2 = [128,64,32,16,8,4,2,1] -- pow2 lookup list
+ me.ancestor = ByteArray(byteSize)
+ return me
+end
+
+----------------------------------------
+-- Sets bit at position to .
+-- @param {integer} bitPos - starts at 1, as ByteArray's native byte access functions
+-- @param {boolean} bitValue
+----------------------------------------
+on setBit (me, bitPos, bitValue)
+ bytePos = (bitPos-1)/8 + 1
+ bitPos = (bitPos-1) mod 8 + 1
+ if bitValue then
+ me[bytePos] = bitOr(me[bytePos], me._pow2[bitPos])
+ else
+ me[bytePos] = bitAnd(me[bytePos], bitNot(me._pow2[bitPos]))
+ end if
+end
+
+----------------------------------------
+-- Gets bit value at position .
+-- @param {integer} bitPos - starts at 1, as ByteArray's native byte access functions
+-- @return {boolean} bitValue
+----------------------------------------
+on getBit (me, bitPos)
+ bytePos = (bitPos-1)/8 + 1
+ bitPos = (bitPos-1) mod 8 + 1
+ return bitAnd(me[bytePos], me._pow2[bitPos])<>0
+end
+
+----------------------------------------
+-- Returns all bits as string. To be in accordance with ByteArray's native toHexString(),
+-- returned string is separated with SPACE (e.g. "0 1 1 0...")
+-- @param {integer} [bitSizeOnly=FALSE] - if TRUE, only bits without byte-padding
+-- @return {string}
+----------------------------------------
+on toBinString (me, bitSizeOnly)
+ res = ""
+ repeat with i = 1 to me.length
+ byte = me[i]
+ repeat with j = 1 to 8
+ put (bitAnd(byte, me._pow2[j])<>0)&" " after res
+ if bitSizeOnly and (i-1)*8+j=me.bitSize then exit repeat
+ end repeat
+ end repeat
+ delete the last char of res
+ return res
+end
diff --git a/Task/Bitwise-IO/Lingo/bitwise-io-2.lingo b/Task/Bitwise-IO/Lingo/bitwise-io-2.lingo
new file mode 100644
index 0000000000..00e9729390
--- /dev/null
+++ b/Task/Bitwise-IO/Lingo/bitwise-io-2.lingo
@@ -0,0 +1,37 @@
+----------------------------------------
+-- @param {string} str - ASCII string
+-- @return {instance} BitArray
+----------------------------------------
+on crunchASCII (str)
+ ba = script("BitArray").new(str.length * 7)
+ pow2 = [64,32,16,8,4,2,1]
+ pos = 1
+ repeat with i = 1 to str.length
+ n = chartonum(str.char[i])
+ repeat with j = 1 to 7
+ ba.setBit(pos, bitAnd(n, pow2[j])<>0)
+ pos = pos+1
+ end repeat
+ end repeat
+ return ba
+end
+
+----------------------------------------
+-- @param {instance} bitArray
+-- @return {string} ASCII string
+----------------------------------------
+on decrunchASCII (bitArray)
+ str = ""
+ pow2 = [64,32,16,8,4,2,1]
+ pos = 1
+ cnt = bitArray.bitSize/7
+ repeat with i = 1 to cnt
+ n = 0
+ repeat with j = 1 to 7
+ n = n + bitArray.getBit(pos)*pow2[j]
+ pos = pos+1
+ end repeat
+ put numtochar(n) after str
+ end repeat
+ return str
+end
diff --git a/Task/Bitwise-IO/Lingo/bitwise-io-3.lingo b/Task/Bitwise-IO/Lingo/bitwise-io-3.lingo
new file mode 100644
index 0000000000..808ec0942e
--- /dev/null
+++ b/Task/Bitwise-IO/Lingo/bitwise-io-3.lingo
@@ -0,0 +1,11 @@
+str = "ABC"
+ba = crunchASCII(str)
+
+put ba.toBinString()
+-- "1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 0"
+
+put ba.toBinString(TRUE)
+ -- "1 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 1"
+
+put decrunchASCII(ba)
+-- "ABC"
diff --git a/Task/Bitwise-operations/8051-Assembly/bitwise-operations.8051 b/Task/Bitwise-operations/8051-Assembly/bitwise-operations.8051
new file mode 100644
index 0000000000..9e8ca4e757
--- /dev/null
+++ b/Task/Bitwise-operations/8051-Assembly/bitwise-operations.8051
@@ -0,0 +1,52 @@
+; bitwise AND
+anl a, b
+
+; bitwise OR
+orl a, b
+
+; bitwise XOR
+xrl a, b
+
+; bitwise NOT
+cpl a
+
+; left shift
+inc b
+rrc a
+loop:
+rlc a
+clr c
+djnz b, loop
+
+; right shift
+inc b
+rlc a
+loop:
+rrc a
+clr c
+djnz b, loop
+
+; arithmetic right shift
+push 20
+inc b
+rlc a
+mov 20.0, c
+loop:
+rrc a
+mov c, 20.0
+djnz b, loop
+pop 20
+
+; left rotate
+inc b
+rr a
+loop:
+rl a
+djnz b, loop
+
+; right rotate
+inc b
+rl a
+loop:
+rr a
+djnz b, loop
diff --git a/Task/Bitwise-operations/Axe/bitwise-operations.axe b/Task/Bitwise-operations/Axe/bitwise-operations.axe
new file mode 100644
index 0000000000..736dca5909
--- /dev/null
+++ b/Task/Bitwise-operations/Axe/bitwise-operations.axe
@@ -0,0 +1,9 @@
+Lbl BITS
+r₁→A
+r₂→B
+Disp "AND:",A·B▶Dec,i
+Disp "OR:",AᕀB▶Dec,i
+Disp "XOR:",A▫B▶Dec,i
+Disp "NOT:",not(A)ʳ▶Dec,i
+.No language support for shifts or rotations
+Return
diff --git a/Task/Bitwise-operations/ECL/bitwise-operations.ecl b/Task/Bitwise-operations/ECL/bitwise-operations.ecl
new file mode 100644
index 0000000000..bff52b93db
--- /dev/null
+++ b/Task/Bitwise-operations/ECL/bitwise-operations.ecl
@@ -0,0 +1,29 @@
+BitwiseOperations(INTEGER A, INTEGER B) := FUNCTION
+ BitAND := A & B;
+ BitOR := A | B;
+ BitXOR := A ^ B;
+ BitNOT := BNOT A;
+ BitSL := A << B;
+ BitSR := A >> B;
+ DS := DATASET([{A,B,'Bitwise AND:',BitAND},
+ {A,B,'Bitwise OR:',BitOR},
+ {A,B,'Bitwise XOR',BitXOR},
+ {A,B,'Bitwise NOT A:',BitNOT},
+ {A,B,'ShiftLeft A:',BitSL},
+ {A,B,'ShiftRight A:',BitSR}],
+ {INTEGER AVal,INTEGER BVal,STRING15 valuetype,INTEGER val});
+ RETURN DS;
+END;
+
+BitwiseOperations(255,5);
+//right arithmetic shift, left and right rotate not implemented
+/*
+ OUTPUT:
+ 255 5 Bitwise AND: 5
+ 255 5 Bitwise OR: 255
+ 255 5 Bitwise XOR 250
+ 255 5 Bitwise NOT A: -256
+ 255 5 ShiftLeft A: 8160
+ 255 5 ShiftRight A: 7
+
+*/
diff --git a/Task/Bitwise-operations/FreeBASIC/bitwise-operations.freebasic b/Task/Bitwise-operations/FreeBASIC/bitwise-operations.freebasic
new file mode 100644
index 0000000000..5e1031fa62
--- /dev/null
+++ b/Task/Bitwise-operations/FreeBASIC/bitwise-operations.freebasic
@@ -0,0 +1,70 @@
+' FB 1.05.0 Win64 (Note the (U)Integer type is 64 bits)
+
+' FB doesn't have built-in logical shift right or rotation operators
+' but, as they're not difficult to implement, I've done so below.
+
+Function lsr(x As Const Integer, y As Const Integer) As Integer
+ Dim As UInteger z = x
+ Return z Shr y
+End Function
+
+Function rol(x As Const Integer, y As Const UInteger) As Integer
+ Dim z As Integer = x
+ Dim high As Integer
+ For i As Integer = 1 To y
+ high = Bit(z, 63)
+ For j As Integer = 62 To 0 Step -1
+ If Bit(z, j) Then
+ z = BitSet(z, j + 1)
+ Else
+ z = BitReset (z, j + 1)
+ End If
+ Next j
+ If high Then
+ z = BitSet(z, 0)
+ Else
+ z = BitReset(z, 0)
+ End If
+ Next i
+ Return z
+End Function
+
+Function ror(x As Const Integer, y As Const UInteger) As Integer
+ Dim z As Integer = x
+ Dim low As Integer
+ For i As Integer = 1 To y
+ low = Bit(z, 0)
+ For j As Integer = 1 To 63
+ If Bit(z, j) Then
+ z = BitSet(z, j - 1)
+ Else
+ z = BitReset (z, j - 1)
+ End If
+ Next j
+ If low Then
+ z = BitSet(z, 63)
+ Else
+ z = BitReset(z, 63)
+ End If
+ Next i
+ Return z
+End Function
+
+Sub bitwise(x As Integer, y As Integer)
+ Print "x = "; x
+ Print "y = "; y
+ Print "x AND y = "; x And y
+ Print "x OR y = "; x Or y
+ Print "x XOR y = "; x XOr y
+ Print "NOT x = "; Not x
+ Print "x SHL y = "; x Shl y
+ Print "x SHR y = "; x Shr y
+ Print "x LSR y = "; lsr(x, y)
+ Print "x ROL y = "; rol(x, y)
+ Print "x ROR y = "; ror(x, y)
+End Sub
+
+bitwise -15, 3
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Bitwise-operations/FutureBasic/bitwise-operations.futurebasic b/Task/Bitwise-operations/FutureBasic/bitwise-operations.futurebasic
new file mode 100644
index 0000000000..c99ae7cf17
--- /dev/null
+++ b/Task/Bitwise-operations/FutureBasic/bitwise-operations.futurebasic
@@ -0,0 +1,29 @@
+include "ConsoleWindow"
+
+// Set tab width for printing
+def tab 1
+
+local fn rotl( b as long, n as long ) as long
+end fn = ( ( 2^n * b) mod 256) or (b > 127)
+
+local fn rotr( b as long, n as long ) as long
+end fn = (b >> n mod 32) or ( b << (32-n) mod 32)
+
+local fn bitwise( a as long, b as long )
+print "Input: a = "; a; " b = "; b
+print
+print "AND :", "a && b = ", bin$(a && b), ": "; a && b
+print "NAND :", "a ^& b = ", bin$(a ^& b), ": "; a ^& b
+print "OR :", "a || b = ", bin$(a || b), ": "; a || b
+print "NOR :", "a ^| b = ", bin$(a ^| b), ": "; a ^| b
+print "XOR :", "a ^^ b = ", bin$(a ^^ b), ": "; a ^^ b
+print "NOT :", " not a = ", bin$( not a), ": "; not a
+print
+print "Left shift :", "a << b =", bin$(a << b), ": "; a << b
+print "Right shift :", "a >> b =", bin$(a >> b), ": "; a >> b
+print
+print "Rotate left :", "fn rotl( a, b ) = ", bin$(fn rotl( a, b)), ": "; fn rotl( a, b )
+print "Rotate right :", "fn rotr( a, b ) = ", bin$(fn rotr( a, b )),": "; fn rotr( a, b )
+end fn
+
+fn bitwise( 255, 2 )
diff --git a/Task/Bitwise-operations/HPPPL/bitwise-operations.hpppl b/Task/Bitwise-operations/HPPPL/bitwise-operations.hpppl
new file mode 100644
index 0000000000..e27aa5cbf8
--- /dev/null
+++ b/Task/Bitwise-operations/HPPPL/bitwise-operations.hpppl
@@ -0,0 +1,10 @@
+EXPORT BITOPS(a, b)
+BEGIN
+ PRINT(BITAND(a, b));
+ PRINT(BITOR(a, b));
+ PRINT(BITXOR(a, b));
+ PRINT(BITNOT(a));
+ PRINT(BITSL(a, b));
+ PRINT(BITSR(a, b));
+ // HPPPL has no builtin rotates or arithmetic right shift.
+END;
diff --git a/Task/Bitwise-operations/LFE/bitwise-operations-1.lfe b/Task/Bitwise-operations/LFE/bitwise-operations-1.lfe
new file mode 100644
index 0000000000..6fc988ceb0
--- /dev/null
+++ b/Task/Bitwise-operations/LFE/bitwise-operations-1.lfe
@@ -0,0 +1,25 @@
+(defun bitwise (a b)
+ (io:format '"~p~n" (list (band a b)))
+ (io:format '"~p~n" (list (bor a b)))
+ (io:format '"~p~n" (list (bxor a b)))
+ (io:format '"~p~n" (list (bnot a)))
+ (io:format '"~p~n" (list (bsl a b)))
+ (io:format '"~p~n" (list (bsr a b))))
+
+(defun d2b
+ (x) (integer_to_list x 2))
+
+(defun bitwise
+ ((a b 'binary)
+ (io:format '"(~s ~s ~s): ~s~n"
+ (list "band" (d2b a) (d2b b) (d2b (band a b))))
+ (io:format '"(~s ~s ~s): ~s~n"
+ (list "bor" (d2b a) (d2b b) (d2b (bor a b))))
+ (io:format '"(~s ~s ~s): ~s~n"
+ (list "bxor" (d2b a) (d2b b) (d2b (bxor a b))))
+ (io:format '"(~s ~s): ~s~n"
+ (list "bnot" (d2b a) (d2b (bnot a))))
+ (io:format '"(~s ~s ~s): ~s~n"
+ (list "bsl" (d2b a) (d2b b) (d2b (bsl a b))))
+ (io:format '"(~s ~s ~s): ~s~n"
+ (list "bsr" (d2b a) (d2b b) (d2b (bsr a b))))))
diff --git a/Task/Bitwise-operations/LFE/bitwise-operations-2.lfe b/Task/Bitwise-operations/LFE/bitwise-operations-2.lfe
new file mode 100644
index 0000000000..8d0832cc7b
--- /dev/null
+++ b/Task/Bitwise-operations/LFE/bitwise-operations-2.lfe
@@ -0,0 +1,17 @@
+> (bitwise 255 170)
+170
+255
+85
+-256
+381627307539845370001346183518875822092557105621893120
+0
+ok
+> (bitwise 255 170 'binary)
+(band 11111111 10101010): 10101010
+(bor 11111111 10101010): 11111111
+(bxor 11111111 10101010): 1010101
+(bnot 11111111): -100000000
+(bsl 11111111 10101010): 1111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+(bsr 11111111 10101010): 0
+ok
+>
diff --git a/Task/Bitwise-operations/Lingo/bitwise-operations.lingo b/Task/Bitwise-operations/Lingo/bitwise-operations.lingo
new file mode 100644
index 0000000000..b11dc9d054
--- /dev/null
+++ b/Task/Bitwise-operations/Lingo/bitwise-operations.lingo
@@ -0,0 +1,4 @@
+put bitAND(2,7)
+put bitOR(2,7)
+put bitXOR(2,7)
+put bitNOT(7)
diff --git a/Task/Bitwise-operations/LiveCode/bitwise-operations.livecode b/Task/Bitwise-operations/LiveCode/bitwise-operations.livecode
new file mode 100644
index 0000000000..65b2b8ec01
--- /dev/null
+++ b/Task/Bitwise-operations/LiveCode/bitwise-operations.livecode
@@ -0,0 +1,8 @@
+put "and:" && (255 bitand 2) & comma into bitops
+put " or:" && (255 bitor 2) & comma after bitops
+put " xor:" && (255 bitxor 2) & comma after bitops
+put " not:" && (bitnot 255) after bitops
+put bitops
+
+-- Ouput
+and: 2, or: 255, xor: 253, not: 4294967040
diff --git a/Task/Bitwise-operations/Nim/bitwise-operations.nim b/Task/Bitwise-operations/Nim/bitwise-operations.nim
new file mode 100644
index 0000000000..6932b12574
--- /dev/null
+++ b/Task/Bitwise-operations/Nim/bitwise-operations.nim
@@ -0,0 +1,7 @@
+proc bitwise(a, b) =
+ echo "a and b: " , a and b
+ echo "a or b: ", a or b
+ echo "a xor b: ", a xor b
+ echo "not a: ", not a
+ echo "a << b: ", a shl b
+ echo "a >> b: ", a shr b
diff --git a/Task/Bitwise-operations/Oforth/bitwise-operations.oforth b/Task/Bitwise-operations/Oforth/bitwise-operations.oforth
new file mode 100644
index 0000000000..1b75a9450c
--- /dev/null
+++ b/Task/Bitwise-operations/Oforth/bitwise-operations.oforth
@@ -0,0 +1,6 @@
+: bitwise(a, b)
+ a b bitAnd println
+ a b bitOr println
+ a b bitXor println
+ a bitLeft(b) println
+ a bitRight(b) println ;
diff --git a/Task/Bitwise-operations/Phix/bitwise-operations.phix b/Task/Bitwise-operations/Phix/bitwise-operations.phix
new file mode 100644
index 0000000000..b4f7eef951
--- /dev/null
+++ b/Task/Bitwise-operations/Phix/bitwise-operations.phix
@@ -0,0 +1,88 @@
+enum SHL, SAR, SHR, ROL, ROR
+function bitop(atom a, integer b, integer op)
+atom res
+ #ilASM{
+ [32]
+ mov eax,[a]
+ call :%pLoadMint
+ mov ecx,[b]
+ mov edx,[op]
+ cmp dl,SHL
+ jne @f
+ shl eax,cl
+ jmp :storeres
+ @@:
+ cmp dl,SAR
+ jne @f
+ sar eax,cl
+ jmp :storeres
+ @@:
+ cmp dl,SHR
+ jne @f
+ shr eax,cl
+ jmp :storeres
+ @@:
+ cmp dl,ROL
+ jne @f
+ rol eax,cl
+ jmp :storeres
+ @@:
+ cmp dl,ROR
+ jne @f
+ ror eax,cl
+ jmp :storeres
+ @@:
+ int3
+ ::storeres
+ lea edi,[res]
+ call :%pStoreMint
+ [64]
+ mov rax,[a]
+ mov rcx,[b]
+ mov edx,[op]
+ cmp dl,SHL
+ jne @f
+ shl rax,cl
+ jmp :storeres
+ @@:
+ cmp dl,SAR
+ jne @f
+ sar rax,cl
+ jmp :storeres
+ @@:
+ cmp dl,SHR
+ jne @f
+ shr rax,cl
+ jmp :storeres
+ @@:
+ cmp dl,ROL
+ jne @f
+ rol rax,cl
+ jmp :storeres
+ @@:
+ cmp dl,ROR
+ jne @f
+ ror eax,cl
+ jmp :storeres
+ @@:
+ int3
+ ::storeres
+ lea rdi,[res]
+ call :%pStoreMint
+ }
+ return res
+end function
+
+procedure bitwise(atom a, atom b)
+ printf(1,"and_bits(%b,%b) = %032b\n",{a,b,and_bits(a,b)})
+ printf(1," or_bits(%b,%b) = %032b\n",{a,b, or_bits(a,b)})
+ printf(1,"xor_bits(%b,%b) = %032b\n",{a,b,xor_bits(a,b)})
+ printf(1,"not_bits(%b) = %032b\n",{a,not_bits(a)})
+ printf(1," shl(%b,%b) = %032b\n",{a,b,bitop(a,b,SHL)})
+ printf(1," sar(%b,%b) = %032b\n",{a,b,bitop(a,b,SAR)})
+ printf(1," shr(%b,%b) = %032b\n",{a,b,bitop(a,b,SHR)})
+ printf(1," rol(%b,%b) = %032b\n",{a,b,bitop(a,b,ROL)})
+ printf(1," ror(%b,%b) = %032b\n",{a,b,bitop(a,b,ROR)})
+end procedure
+
+bitwise(0x800000FE,7)
diff --git a/Task/Bitwise-operations/Ring/bitwise-operations.ring b/Task/Bitwise-operations/Ring/bitwise-operations.ring
new file mode 100644
index 0000000000..18f76b3861
--- /dev/null
+++ b/Task/Bitwise-operations/Ring/bitwise-operations.ring
@@ -0,0 +1,9 @@
+x = 8
+y = 2
+
+see "x & y - Binary AND : " + (x & y) + nl
+see "x | y - Binary OR : " + (x | y) + nl
+see "x ^ y - Binary XOR : " + (x ^ y) +nl
+see "~x - Binary Ones Complement : " + (~x) + nl
+see "x << y - Binary Left Shift : " + (x << y) + nl
+see "x >> y - Binary Right Shift : " + (x >> y) + nl
diff --git a/Task/Bitwise-operations/Sidef/bitwise-operations.sidef b/Task/Bitwise-operations/Sidef/bitwise-operations.sidef
new file mode 100644
index 0000000000..4e17786922
--- /dev/null
+++ b/Task/Bitwise-operations/Sidef/bitwise-operations.sidef
@@ -0,0 +1,15 @@
+func bitwise(a, b) {
+
+ # Make sure they are integers
+ a.to_int!;
+ b.to_int!;
+
+ say ('a and b : ', a & b);
+ say ('a or b : ', a | b);
+ say ('a xor b : ', a ^ b);
+ say ('not a : ', ~a);
+ say ('a << b : ', a << b); # left shift
+ say ('a >> b : ', a >> b); # arithmetic right shift
+}
+
+bitwise(14,3)
diff --git a/Task/Bitwise-operations/Swift/bitwise-operations.swift b/Task/Bitwise-operations/Swift/bitwise-operations.swift
new file mode 100644
index 0000000000..51f4594d9e
--- /dev/null
+++ b/Task/Bitwise-operations/Swift/bitwise-operations.swift
@@ -0,0 +1,15 @@
+func bitwise(a: Int, b: Int) {
+ // All bitwise operations (including shifts)
+ // require both operands to be the same type
+ println("a AND b: \(a & b)")
+ println("a OR b: \(a | b)")
+ println("a XOR b: \(a ^ b)")
+ println("NOT a: \(~a)")
+ println("a << b: \(a << b)") // left shift
+ // for right shifts, if the operands are unsigned, Swift performs
+ // a logical shift; if signed, an arithmetic shift.
+ println("a >> b: \(a >> b)") // arithmetic right shift
+ println("a lsr b: \(Int(bitPattern: UInt(bitPattern: a) >> UInt(bitPattern: b)))") // logical right shift
+}
+
+bitwise(-15,3)
diff --git a/Task/Boolean-values/8051-Assembly/boolean-values.8051 b/Task/Boolean-values/8051-Assembly/boolean-values.8051
new file mode 100644
index 0000000000..dce9588ab1
--- /dev/null
+++ b/Task/Boolean-values/8051-Assembly/boolean-values.8051
@@ -0,0 +1,2 @@
+clr bit ; clears
+setb bit ; sets
diff --git a/Task/Boolean-values/EchoLisp/boolean-values.echolisp b/Task/Boolean-values/EchoLisp/boolean-values.echolisp
new file mode 100644
index 0000000000..851d238187
--- /dev/null
+++ b/Task/Boolean-values/EchoLisp/boolean-values.echolisp
@@ -0,0 +1,4 @@
+(not #t) → #f
+(not #f) → #t
+(not null) → #f
+(not 0) → #f
diff --git a/Task/Boolean-values/FreeBASIC/boolean-values.freebasic b/Task/Boolean-values/FreeBASIC/boolean-values.freebasic
new file mode 100644
index 0000000000..758530a724
--- /dev/null
+++ b/Task/Boolean-values/FreeBASIC/boolean-values.freebasic
@@ -0,0 +1,14 @@
+' FB 1.05.0 Win64
+
+Dim i As Integer = 23
+Dim s As String = "False"
+Dim b As Boolean
+b = i
+Print b
+b = CBool(s)
+Print b
+i = b
+Print i
+i = CInt(true)
+Print i
+Sleep
diff --git a/Task/Boolean-values/I/boolean-values.i b/Task/Boolean-values/I/boolean-values.i
new file mode 100644
index 0000000000..bc96255651
--- /dev/null
+++ b/Task/Boolean-values/I/boolean-values.i
@@ -0,0 +1,14 @@
+software {
+ if true
+ print("this prints")
+ end
+ if 1
+ print("this prints")
+ end
+ if false
+ print("this does not print")
+ end
+ if 0
+ print("this does not print")
+ end
+}
diff --git a/Task/Boolean-values/Idris/boolean-values.idris b/Task/Boolean-values/Idris/boolean-values.idris
new file mode 100644
index 0000000000..bb96e57dc4
--- /dev/null
+++ b/Task/Boolean-values/Idris/boolean-values.idris
@@ -0,0 +1,9 @@
+Idris> :doc Bool
+Data type Prelude.Bool.Bool : Type
+ Boolean Data Type
+
+Constructors:
+ False : Bool
+
+
+ True : Bool
diff --git a/Task/Boolean-values/LFE/boolean-values.lfe b/Task/Boolean-values/LFE/boolean-values.lfe
new file mode 100644
index 0000000000..350275e697
--- /dev/null
+++ b/Task/Boolean-values/LFE/boolean-values.lfe
@@ -0,0 +1,8 @@
+> 'true
+true
+> 'false
+false
+> (or 'false 'false)
+false
+> (or 'false 'true)
+true
diff --git a/Task/Boolean-values/Lasso/boolean-values-1.lasso b/Task/Boolean-values/Lasso/boolean-values-1.lasso
new file mode 100644
index 0000000000..e72f7cea1f
--- /dev/null
+++ b/Task/Boolean-values/Lasso/boolean-values-1.lasso
@@ -0,0 +1,11 @@
+!true
+// => false
+
+not false
+// => true
+
+var(x = true)
+$x // => true
+
+$x = false
+$x // => false
diff --git a/Task/Boolean-values/Lasso/boolean-values-2.lasso b/Task/Boolean-values/Lasso/boolean-values-2.lasso
new file mode 100644
index 0000000000..9a2b126389
--- /dev/null
+++ b/Task/Boolean-values/Lasso/boolean-values-2.lasso
@@ -0,0 +1,7 @@
+local(x = string)
+// size is 0
+#x->size ? 'yes' | 'no'
+
+local(x = '123fsfsd')
+// size is 8
+#x->size ? 'yes' | 'no'
diff --git a/Task/Boolean-values/Lingo/boolean-values.lingo b/Task/Boolean-values/Lingo/boolean-values.lingo
new file mode 100644
index 0000000000..d1a19d33fc
--- /dev/null
+++ b/Task/Boolean-values/Lingo/boolean-values.lingo
@@ -0,0 +1,6 @@
+put TRUE
+-- 1
+put FALSE
+-- 0
+if 23 then put "Hello"
+-- "Hello"
diff --git a/Task/Boolean-values/Monte/boolean-values.monte b/Task/Boolean-values/Monte/boolean-values.monte
new file mode 100644
index 0000000000..4ab9e9d08b
--- /dev/null
+++ b/Task/Boolean-values/Monte/boolean-values.monte
@@ -0,0 +1,4 @@
+def example(input :boolean):
+ if input:
+ return "Input was true!"
+ return "Input was false."
diff --git a/Task/Boolean-values/Nim/boolean-values.nim b/Task/Boolean-values/Nim/boolean-values.nim
new file mode 100644
index 0000000000..5dc47bf783
--- /dev/null
+++ b/Task/Boolean-values/Nim/boolean-values.nim
@@ -0,0 +1,5 @@
+if true: echo "yes"
+if false: echo "no"
+
+# Other objects never represent true or false:
+if 2: echo "compile error"
diff --git a/Task/Boolean-values/Ring/boolean-values.ring b/Task/Boolean-values/Ring/boolean-values.ring
new file mode 100644
index 0000000000..9b445a9b5b
--- /dev/null
+++ b/Task/Boolean-values/Ring/boolean-values.ring
@@ -0,0 +1,5 @@
+x = True
+y = False
+see "x and y : " + (x and y) + nl
+see "x or y : " + (x or y) + nl
+see "not x : " + (not x) + nl
diff --git a/Task/Boolean-values/Sidef/boolean-values-1.sidef b/Task/Boolean-values/Sidef/boolean-values-1.sidef
new file mode 100644
index 0000000000..d661db48b7
--- /dev/null
+++ b/Task/Boolean-values/Sidef/boolean-values-1.sidef
@@ -0,0 +1,2 @@
+var t = true;
+var f = false;
diff --git a/Task/Boolean-values/Sidef/boolean-values-2.sidef b/Task/Boolean-values/Sidef/boolean-values-2.sidef
new file mode 100644
index 0000000000..1efddf4d60
--- /dev/null
+++ b/Task/Boolean-values/Sidef/boolean-values-2.sidef
@@ -0,0 +1,5 @@
+if (0 || "0" || false || nil || "" || [] || :()) {
+ say "true"
+} else {
+ say "false";
+}
diff --git a/Task/Boolean-values/Ursa/boolean-values-1.ursa b/Task/Boolean-values/Ursa/boolean-values-1.ursa
new file mode 100644
index 0000000000..87f4627aa7
--- /dev/null
+++ b/Task/Boolean-values/Ursa/boolean-values-1.ursa
@@ -0,0 +1 @@
+decl boolean bool
diff --git a/Task/Boolean-values/Ursa/boolean-values-2.ursa b/Task/Boolean-values/Ursa/boolean-values-2.ursa
new file mode 100644
index 0000000000..62ddb46b87
--- /dev/null
+++ b/Task/Boolean-values/Ursa/boolean-values-2.ursa
@@ -0,0 +1,3 @@
+set bool true
+# same as
+set bool (= 2 2)
diff --git a/Task/Boolean-values/Ursa/boolean-values-3.ursa b/Task/Boolean-values/Ursa/boolean-values-3.ursa
new file mode 100644
index 0000000000..31bd10e4d0
--- /dev/null
+++ b/Task/Boolean-values/Ursa/boolean-values-3.ursa
@@ -0,0 +1,3 @@
+set bool false
+# same as
+set bool (not (= 2 2))
diff --git a/Task/Box-the-compass/FreeBASIC/box-the-compass.freebasic b/Task/Box-the-compass/FreeBASIC/box-the-compass.freebasic
new file mode 100644
index 0000000000..620d8ad6de
--- /dev/null
+++ b/Task/Box-the-compass/FreeBASIC/box-the-compass.freebasic
@@ -0,0 +1,32 @@
+' version 04-11-2016
+' compile with: fbc -s console
+
+Dim As String names(0 To ...) = { "North", "North by east", "North-northeast", _
+ "Northeast by north", "Northeast", "Northeast by east", "East-northeast", _
+ "East by north", "East", "East by south", "East-southeast", _
+ "Southeast by east", "Southeast", "Southeast by south", "South-southeast", _
+ "South by east", "South", "South by west", "South-southwest", _
+ "Southwest by south", "Southwest", "Southwest by west", "West-southwest", _
+ "West by south", "West", "West by north", "West-northwest", _
+ "Northwest by west", "Northwest", "Northwest by north", "North-northwest", _
+ "North by west", "North" }
+
+Dim As Double degrees(0 To ...) = { 0, 16.87, 16.88, 33.75, 50.62, 50.63, _
+ 67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135, 151.87, 151.88, 168.75, _
+ 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270, _
+ 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38 }
+
+Dim As ULong i, j
+
+For i = LBound(degrees) To UBound(degrees)
+ j = Int((degrees(i) + 5.625) / 11.25)
+ If j > 31 Then j = j - 32
+ Print Using "####.## ## "; degrees(i); j;
+ Print names(j)
+Next
+
+' empty keyboard buffer
+While Inkey <> "" : Wend
+Print : Print "hit any key to end program"
+Sleep
+End
diff --git a/Task/Box-the-compass/Lasso/box-the-compass.lasso b/Task/Box-the-compass/Lasso/box-the-compass.lasso
new file mode 100644
index 0000000000..7646159e5e
--- /dev/null
+++ b/Task/Box-the-compass/Lasso/box-the-compass.lasso
@@ -0,0 +1,52 @@
+define pointsarray() => {
+ local(points = array)
+ loop(-from=0,-to=32) => {
+ local(heading = loop_count * 11.25)
+ if(loop_count % 3 == 1) => {
+ #heading += 5.62
+ else(loop_count % 3 == 2)
+ #heading -= 5.62
+ }
+ #points->insert(#heading)
+ }
+ return #points
+}
+define compassShort => array(
+ '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')
+define compassLong(short::string) => {
+ local(o = string)
+ with i in #short->values do => { #o->append(compassLongProcessor(#i)) }
+ return #o
+}
+define compassLongProcessor(char::string) => {
+ #char == 'N' ? return #char + 'orth'
+ #char == 'S' ? return #char + 'outh'
+ #char == 'E' ? return #char + 'ast'
+ #char == 'W' ? return #char + 'est'
+ #char == 'b' ? return ' by '
+ #char == '-' ? return '-'
+}
+// test output points as decimals
+//pointsarray
+
+// test output the array of text values
+//compassShort
+
+// test output the long names of the text values
+//with s in compassShort do => {^ compassLong(#s) + '\r' ^}
+
+'angle | box | compass point
+---------------------------------
+'
+local(counter = 0)
+with p in pointsarray do => {^
+ local(pformatted = #p->asString(-precision=2))
+ while(#pformatted->size < 6) => { #pformatted->append(' ') }
+ #counter += 1
+ #counter > 32 ? #counter = 1
+ #pformatted + ' | ' + (#counter < 10 ? ' ') + #counter + ' | ' + compassLong(compassShort->get(#counter)) + '\r'
+
+^}
diff --git a/Task/Box-the-compass/Nim/box-the-compass.nim b/Task/Box-the-compass/Nim/box-the-compass.nim
new file mode 100644
index 0000000000..2bea7f535c
--- /dev/null
+++ b/Task/Box-the-compass/Nim/box-the-compass.nim
@@ -0,0 +1,18 @@
+import strfmt
+
+const names = [
+ "North", "North by east", "North-northeast", "Northeast by north",
+ "Northeast", "Northeast by east", "East-northeast", "East by north",
+ "East", "East by south", "East-southeast", "Southeast by east",
+ "Southeast", "Southeast by south","South-southeast", "South by east",
+ "South", "South by west", "South-southwest", "Southwest by south",
+ "Southwest", "Southwest by west", "West-southwest", "West by south",
+ "West", "West by north", "West-northwest", "Northwest by west",
+ "Northwest", "Northwest by north", "North-northwest", "North by west", "North"]
+
+for i in 0..32:
+ let j = i mod 32
+ var d = float(i) * 11.25
+ if i mod 3 == 1: d += 5.62
+ if i mod 3 == 2: d -= 5.62
+ printlnfmt "{:2} {:18} {:>6.2f}", j + 1, names[j], d
diff --git a/Task/Box-the-compass/Phix/box-the-compass.phix b/Task/Box-the-compass/Phix/box-the-compass.phix
new file mode 100644
index 0000000000..a6421412cb
--- /dev/null
+++ b/Task/Box-the-compass/Phix/box-the-compass.phix
@@ -0,0 +1,48 @@
+function get225(integer d, string p1, string p2, string p4)
+string p3
+ p3 = p1&'-'&lower(p2)
+ p2 &= " by "&lower(p1)
+ p1 &= " by "&lower(p4)
+ if d then
+ return {p1,p3,p2} -- eg {North by east,North-northeast,Northeast by north}
+ else
+ return {p2,p3,p1} -- eg {Northeast by east,East-northeast,East by north}
+ end if
+end function
+
+function get45(sequence res, integer d, string p1, string p2)
+string p3
+ res = append(res,p1) -- North/East/South/West
+ if d then
+ p3 = p1&lower(p2) -- Northeast/Southwest
+ else
+ p3 = p2&lower(p1) -- Southeast/Northwest
+ end if
+ res &= get225(1,p1,p3,p2) -- eg get225(1,North,Northeast,East)
+ -- -> {North by east,North-northeast,Northeast by north}
+ res = append(res,p3) -- Northeast/Southeast/Southwest/Northwest
+ res &= get225(0,p2,p3,p1) -- eg get225(0,East,Northeast,North)
+ -- -> {Northeast by east,East-northeast,East by north}
+ return res
+end function
+
+function get90(sequence points)
+sequence res = {}
+ for i=1 to length(points) do
+ res = get45(res,remainder(i,2),points[i],points[remainder(i,4)+1])
+ end for -- ie get45(1,North,East)
+ -- get45(0,East,South)
+ -- get45(1,South,West)
+ -- get45(0,West,North)
+ return res
+end function
+
+constant compass_points = get90({"North","East","South","West"})
+
+atom test_point
+integer compass_point
+for i = 1 to 33 do
+ test_point = (i-1)*11.25 + 5.62*(remainder(i,3)-1)
+ compass_point = remainder(floor(test_point*32/360+0.5),32)+1
+ printf(1, "%2d %-22s %6.2f\n", {compass_point, compass_points[compass_point], test_point})
+end for
diff --git a/Task/Box-the-compass/Sidef/box-the-compass.sidef b/Task/Box-the-compass/Sidef/box-the-compass.sidef
new file mode 100644
index 0000000000..af94563422
--- /dev/null
+++ b/Task/Box-the-compass/Sidef/box-the-compass.sidef
@@ -0,0 +1,15 @@
+func point (index) {
+ var ix = (index % 32);
+ if (ix & 1) { "#{point((ix + 1) & 28)} by #{point(((2 - (ix & 2)) * 4) + ix & 24)}" }
+ elsif (ix & 2) { "#{point((ix + 2) & 24)}-#{point((ix | 4) & 28)}" }
+ elsif (ix & 4) { "#{point((ix + 8) & 16)}#{point((ix | 8) & 24)}" }
+ else { [ix / 8] }
+}
+
+func test_angle (ix) { ix * 11.25 + [0, 5.62, -5.62][ ix % 3 ] };
+func angle_to_point(𝜽) { (𝜽 / 360 * 32) + 0.5 -> floor };
+
+for ix in range(0, 32) {
+ var 𝜽 = test_angle(ix);
+ printf(" %2d %6.2f° %s\n", ix % 32 + 1, 𝜽, point(angle_to_point(𝜽)).tc);
+}
diff --git a/Task/Break-OO-privacy/Nim/break-oo-privacy-1.nim b/Task/Break-OO-privacy/Nim/break-oo-privacy-1.nim
new file mode 100644
index 0000000000..33229c01fa
--- /dev/null
+++ b/Task/Break-OO-privacy/Nim/break-oo-privacy-1.nim
@@ -0,0 +1,7 @@
+type Foo* = object
+ a: string
+ b: string
+ c: int
+
+proc createFoo*(a, b, c): Foo =
+ Foo(a: a, b: b, c: c)
diff --git a/Task/Break-OO-privacy/Nim/break-oo-privacy-2.nim b/Task/Break-OO-privacy/Nim/break-oo-privacy-2.nim
new file mode 100644
index 0000000000..9deba1abe5
--- /dev/null
+++ b/Task/Break-OO-privacy/Nim/break-oo-privacy-2.nim
@@ -0,0 +1,3 @@
+var x = createFoo("this a", "this b", 12)
+
+echo x.a # compile time error
diff --git a/Task/Break-OO-privacy/Nim/break-oo-privacy-3.nim b/Task/Break-OO-privacy/Nim/break-oo-privacy-3.nim
new file mode 100644
index 0000000000..4c0f8d1995
--- /dev/null
+++ b/Task/Break-OO-privacy/Nim/break-oo-privacy-3.nim
@@ -0,0 +1 @@
+echo repr(x)
diff --git a/Task/Break-OO-privacy/Nim/break-oo-privacy-4.nim b/Task/Break-OO-privacy/Nim/break-oo-privacy-4.nim
new file mode 100644
index 0000000000..f169521e4b
--- /dev/null
+++ b/Task/Break-OO-privacy/Nim/break-oo-privacy-4.nim
@@ -0,0 +1,11 @@
+import typeinfo
+
+for key, val in fields(toAny(x)):
+ echo "Key ", key
+ case val.kind
+ of akString:
+ echo " is a string with value: ", val.getString
+ of akInt..akInt64, akUint..akUint64:
+ echo " is an integer with value: ", val.getBiggestInt
+ else:
+ echo " is an unknown with value: ", val.repr
diff --git a/Task/Break-OO-privacy/Sidef/break-oo-privacy.sidef b/Task/Break-OO-privacy/Sidef/break-oo-privacy.sidef
new file mode 100644
index 0000000000..bb90a8c406
--- /dev/null
+++ b/Task/Break-OO-privacy/Sidef/break-oo-privacy.sidef
@@ -0,0 +1,15 @@
+class Example {
+ has public = "foo"
+ method init {
+ self{:private} = "secret"
+ }
+}
+
+var obj = Example();
+
+# Access public attributes
+say obj.public; #=> "foo"
+say obj{:public}; #=> "foo"
+
+# Access private attributes
+say obj{:private}; #=> "secret"
diff --git a/Task/Brownian-tree/Phix/brownian-tree.phix b/Task/Brownian-tree/Phix/brownian-tree.phix
new file mode 100644
index 0000000000..5b338b9e68
--- /dev/null
+++ b/Task/Brownian-tree/Phix/brownian-tree.phix
@@ -0,0 +1,70 @@
+include ..\pGUI\pGUI.e
+
+Ihandle dlg, canvas
+cdCanvas cddbuffer, cdcanvas
+
+function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
+integer x,y,ox,oy
+integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
+sequence grid = repeat(repeat(0,width),height)
+integer xy = floor(width*height*0.8)
+--atom t = time()+1
+ grid[floor(width/2)][floor(height/2)] = 1
+ cdCanvasActivate(cddbuffer)
+ cdCanvasClear(cddbuffer)
+ for i=1 to xy do
+ x = rand(width) y = rand(height)
+ ox = x oy = y
+ while x>=1 and x<=width
+ and y>=1 and y<=height do
+ if grid[y][x] then
+ grid[oy][ox] = 1
+ cdCanvasPixel(cddbuffer, ox, oy, #00FF00)
+ exit
+ end if
+ ox = x x += rand(3)-2
+ oy = y y += rand(3)-2
+ end while
+-- -- if making the canvas bigger/resizeable,
+-- -- put this in so that you can kill it.
+-- if time()>=t then
+-- ?{i,xy}
+-- t = time()+1
+-- end if
+ end for
+ cdCanvasFlush(cddbuffer)
+ return IUP_DEFAULT
+end function
+
+function map_cb(Ihandle ih)
+ cdcanvas = cdCreateCanvas(CD_IUP, ih)
+ cddbuffer = cdCreateCanvas(CD_DBUFFER, cdcanvas)
+ cdCanvasSetBackground(cddbuffer, CD_WHITE)
+ cdCanvasSetForeground(cddbuffer, CD_RED)
+ return IUP_DEFAULT
+end function
+
+function esc_close(Ihandle /*ih*/, atom c)
+ if c=K_ESC then return IUP_CLOSE end if
+ return IUP_CONTINUE
+end function
+
+procedure main()
+ IupOpen("..\\pGUI\\")
+
+ canvas = IupCanvas(NULL)
+ IupSetAttribute(canvas, "RASTERSIZE", "200x200") -- fixed size
+ IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
+
+ dlg = IupDialog(canvas, "RESIZE=NO")
+ IupSetAttribute(dlg, "TITLE", "Brownian Tree")
+ IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
+ IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
+
+ IupMap(dlg)
+ IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
+ IupMainLoop()
+ IupClose()
+end procedure
+
+main()
diff --git a/Task/Bulls-and-cows-Player/Phix/bulls-and-cows-player.phix b/Task/Bulls-and-cows-Player/Phix/bulls-and-cows-player.phix
new file mode 100644
index 0000000000..4f74485223
--- /dev/null
+++ b/Task/Bulls-and-cows-Player/Phix/bulls-and-cows-player.phix
@@ -0,0 +1,70 @@
+constant line = " +---------+-----------------------------+-------+------+\n"
+constant digits = "123456789"
+
+function mask(integer ch)
+ return power(2,ch-'1')
+end function
+
+function score(sequence guess, sequence goal)
+integer bits = 0, bulls = 0, cows = 0
+ for i=1 to length(guess) do
+ if guess[i]=goal[i] then
+ bulls += 1
+ else
+ bits += mask(goal[i])
+ end if
+ end for
+ for i=1 to length(guess) do
+ cows += (and_bits(bits,mask(guess[i]))!=0)
+ end for
+ return {bulls, cows}
+end function
+
+sequence list = {}
+
+procedure pick(integer n, integer got, integer marker, sequence buf)
+integer bits = 1
+ if got>=n then
+ list = append(list,buf)
+ else
+ for i=0 to length(digits)-1 do
+ if not and_bits(marker,bits) then
+ buf[got+1] = i+'1'
+ pick(n, got+1, or_bits(marker,bits), buf)
+ end if
+ bits *= 2
+ end for
+ end if
+end procedure
+
+procedure filter_list(sequence guess, integer bulls, integer cows)
+integer l = length(list), idx = 0
+sequence bc = {bulls,cows}
+ for i=1 to l do
+ if score(guess,list[i])=bc then
+ idx += 1
+ list[idx] = list[i]
+ end if
+ end for
+ list = list[1..idx]
+end procedure
+
+procedure game(sequence tgt)
+integer n = length(tgt), attempt = 1, bulls = 0, cows
+sequence guess
+ pick(n,0,0,repeat(0,n))
+ while bulls grep {|n| !("#{n}" =~ /0 | (\d) .*? \1 /x) }.map{.digits});
+
+# Repeatedly prompt for input until the user supplies a reasonable score.
+# The regex validates the user's input and then returns two numbers.
+func read_score(guess) {
+ loop {
+ "My guess: %s (from %d possibilities)\n" \
+ -> printf(guess.join, candidates.len);
+
+ if (var m = (Sys.scanln("bulls cows: ") =~ /^\h*(\d)\h*(\d)\h*$/)) {
+ var (bulls, cows) = m.cap.map{.to_i}...;
+ bulls+cows <= 4 && return(bulls, cows);
+ }
+
+ say "Please specify the number of bulls and the number of cows";
+ }
+}
+
+func score_correct(a, b, bulls, cows) {
+ var (exact, loose) = (0, 0);
+
+ for i in ^4 {
+ a[i] == b[i] ? ++exact
+ : (a[i]~~b && ++loose)
+ }
+
+ (bulls == exact) && (cows == loose)
+}
+
+# Pick a number, display it, get the score, and discard candidates
+# that don't match the score:
+loop {
+ var guess = candidates.pick;
+ var (bulls, cows) = read_score(guess);
+ candidates.grep!{|n| score_correct(n, guess, bulls, cows) }
+ candidates.len > 1 || break
+}
+
+# Print the secret number or the error message
+(
+ candidates.len == 1 ? ("Your secret number is: %d" % candidates[0].join)
+ : ("I think you made a mistake with your scoring")
+)->say
diff --git a/Task/Bulls-and-cows/Ceylon/bulls-and-cows.ceylon b/Task/Bulls-and-cows/Ceylon/bulls-and-cows.ceylon
new file mode 100644
index 0000000000..ad4c6a1040
--- /dev/null
+++ b/Task/Bulls-and-cows/Ceylon/bulls-and-cows.ceylon
@@ -0,0 +1,70 @@
+import ceylon.random {
+
+ DefaultRandom
+}
+
+shared void run() {
+
+ value random = DefaultRandom();
+
+ function generateDigits() =>
+ random.elements(1..9).distinct.take(4).sequence();
+
+ function validate(String guess) {
+ variable value ok = true;
+ if(!guess.every((Character element) => element.digit)) {
+ print("numbers only, please");
+ ok = false;
+ }
+ if('0' in guess) {
+ print("only 1 to 9, please");
+ ok = false;
+ }
+ if(guess.distinct.shorterThan(guess.size)) {
+ print("no duplicates, please");
+ ok = false;
+ }
+ if(guess.size != 4) {
+ print("4 digits please");
+ ok = false;
+ }
+ return ok;
+ }
+
+ function score({Integer*} target, {Integer*} guess) {
+ variable value bulls = 0;
+ variable value cows = 0;
+ for([a, b] in zipPairs(target, guess)) {
+ if(a == b) {
+ bulls++;
+ } else if(target.contains(b)) {
+ cows++;
+ }
+ }
+ return [bulls, cows];
+ }
+
+ while(true) {
+ value digits = generateDigits();
+ print("I have chosen my four digits, please guess what they are.
+ Use only the digits 1 to 9 with no duplicates and enter them with no spaces. eg 1234
+ Enter q or Q to quit.");
+ while(true) {
+ if(exists line = process.readLine()) {
+ if(line.uppercased == "Q") {
+ return;
+ }
+ if(validate(line)) {
+ value guessDigits = line.map((Character element) => parseInteger(element.string)).coalesced;
+ value [bulls, cows] = score(digits, guessDigits);
+ if(bulls == 4) {
+ print("You win!");
+ break;
+ } else {
+ print("Bulls: ``bulls``, Cows: ``cows``");
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Task/Bulls-and-cows/Coco/bulls-and-cows-1.coco b/Task/Bulls-and-cows/Coco/bulls-and-cows-1.coco
new file mode 100644
index 0000000000..5187a60597
--- /dev/null
+++ b/Task/Bulls-and-cows/Coco/bulls-and-cows-1.coco
@@ -0,0 +1,4 @@
+say = print
+prompt = (str) ->
+ putstr str
+ readline! ? quit!
diff --git a/Task/Bulls-and-cows/Coco/bulls-and-cows-2.coco b/Task/Bulls-and-cows/Coco/bulls-and-cows-2.coco
new file mode 100644
index 0000000000..dfd5c0ad34
--- /dev/null
+++ b/Task/Bulls-and-cows/Coco/bulls-and-cows-2.coco
@@ -0,0 +1,22 @@
+const SIZE = 4
+
+secret = _.sample ['1' to '9'], SIZE
+
+for ever
+ var guess
+ for ever
+ guess := _.uniq prompt 'Enter a guess: '
+ if guess.length === SIZE and not _.difference guess, ['1' to '9'] .length
+ break
+ say 'Malformed guess; try again.'
+ bulls = cows = 0
+ for i til SIZE
+ if guess[i] === secret[i]
+ ++bulls
+ else if _.contains secret, guess[i]
+ ++cows
+ if bulls === SIZE
+ break
+ say "#bulls bull#{[if bulls !== 1 then 's']}, #cows cow#{[if cows !== 1 then 's']}."
+
+say 'A winner is you!'
diff --git a/Task/Bulls-and-cows/Hy/bulls-and-cows.hy b/Task/Bulls-and-cows/Hy/bulls-and-cows.hy
new file mode 100644
index 0000000000..41f690d9eb
--- /dev/null
+++ b/Task/Bulls-and-cows/Hy/bulls-and-cows.hy
@@ -0,0 +1,26 @@
+(import random)
+
+(def +size+ 4)
+(def +digits+ "123456789")
+(def +secret+ (random.sample +digits+ +size+))
+
+(while True
+ (while True
+ (setv guess (list (distinct (raw-input "Enter a guess: "))))
+ (when (and
+ (= (len guess) +size+)
+ (all (map (fn [c] (in c +digits+)) guess)))
+ (break))
+ (print "Malformed guess; try again"))
+ (setv bulls 0)
+ (setv cows 0)
+ (for [i (range +size+)] (cond
+ [(= (get guess i) (get +secret+ i)) (setv bulls (inc bulls))]
+ [(in (get guess i) +secret+) (setv cows (inc cows))]))
+ (when (= bulls +size+)
+ (break))
+ (print (.format "{} bull{}, {} cows"
+ bulls (if (= bulls 1) "" "s")
+ cows (if (= cows 1) "" "s"))))
+
+(print "A winner is you!")
diff --git a/Task/Bulls-and-cows/Lasso/bulls-and-cows.lasso b/Task/Bulls-and-cows/Lasso/bulls-and-cows.lasso
new file mode 100644
index 0000000000..853c7ce890
--- /dev/null
+++ b/Task/Bulls-and-cows/Lasso/bulls-and-cows.lasso
@@ -0,0 +1,70 @@
+[
+define randomizer() => {
+ local(n = string)
+ while(#n->size < 4) => {
+ local(r = integer_random(1,9)->asString)
+ #n !>> #r ? #n->append(#r)
+ }
+ return #n
+}
+define cowbullchecker(n::string,a::string) => {
+ integer(#n) == integer(#a) ? return (:true,map('cows'=0,'bulls'=4,'choice'=#a))
+ local(cowbull = map('cows'=0,'bulls'=0,'choice'=#a),'checked' = array)
+ loop(4) => {
+ if(#checked !>> integer(#a->values->get(loop_count))) => {
+ #checked->insert(integer(#a->values->get(loop_count)))
+ if(integer(#n->values->get(loop_count)) == integer(#a->values->get(loop_count))) => {
+ #cowbull->find('bulls') += 1
+ else(#n->values >> #a->values->get(loop_count))
+ #cowbull->find('cows') += 1
+ }
+ }
+ }
+ #cowbull->find('bulls') == 4 ? return (:true,map('cows'=0,'bulls'=4,'choice'=#a))
+ return (:true,#cowbull)
+}
+session_start('user')
+session_addvar('user', 'num')
+session_addvar('user', 'historic_choices')
+// set up rand
+var(num)->isNotA(::string) ? var(num = randomizer)
+var(historic_choices)->isNotA(::array) ? var(historic_choices = array)
+local(success = false)
+// check answer
+if(web_request->param('a')->asString->size) => {
+ local(success,result) = cowbullchecker($num,web_request->param('a')->asString)
+ $historic_choices->insert(#result)
+}
+if(web_request->params->asStaticArray >> 'restart') => {
+ $num = randomizer
+ $historic_choices = array
+}
+]
+Bulls and Cows
+Guess the 4-digit number...
+Your win if the guess is the same as the randomly chosen number.
+- A score of one bull is accumulated for each digit in your guess that equals the corresponding digit in the randomly chosen initial number.
+- A score of one cow is accumulated for each digit in your guess that also appears in the randomly chosen number, but in the wrong position.
+
+[
+local(win = false)
+if($historic_choices->size) => {
+ with c in $historic_choices do => {^
+ ''+#c->find('choice')+': Bulls: '+#c->find('bulls')+', Cows: '+#c->find('cows')
+ if(#c->find('bulls') == 4) => {^
+ ' - YOU WIN!'
+ #win = true
+ ^}
+ '
'
+ ^}
+}
+if(not #win) => {^
+]
+
+[else
+ 'Restart'
+^}]
diff --git a/Task/Bulls-and-cows/Nim/bulls-and-cows.nim b/Task/Bulls-and-cows/Nim/bulls-and-cows.nim
new file mode 100644
index 0000000000..450113a078
--- /dev/null
+++ b/Task/Bulls-and-cows/Nim/bulls-and-cows.nim
@@ -0,0 +1,35 @@
+import random, strutils, rdstdin
+randomize()
+
+proc random(a: string): char = a[random(0..a.len)]
+
+const
+ digits = "123456789"
+ size = 4
+
+var digitsSet: set[char] = {}
+for d in digits: digitsSet.incl d
+
+var chosen = newString(size)
+for i in 0..chosen.high: chosen[i] = random(digits)
+
+echo """I have chosen a number from $# unique digits from 1 to 9 arranged in a random order.
+You need to input a $# digit, unique digit number as a guess at what I have chosen""".format(size, size)
+
+var guesses = 0
+while true:
+ inc guesses
+ var guess = ""
+ while true:
+ guess = readLineFromStdin("\nNext guess [$#]: ".format(guesses)).strip()
+ if guess.len == size and allCharsInSet(guess, digitsSet):
+ break
+ echo "Problem, try again. You need to enter $# unique digits from 1 to 9".format(size)
+ if guess == chosen:
+ echo "\nCongratulations you guessed correctly in ",guesses," attempts"
+ break
+ var bulls, cows = 0
+ for i in 0 .. numbers
+ while(numbers size 4 <>) [ 9 rand dup numbers include ifFalse: [ numbers add ] else: [ drop ] ]
+
+ while(true) [
+ "Enter a number of 4 different digits between 1 and 9 : " print
+ System.Console askln ->digits
+ digits asInteger isNull digits size 4 <> or ifTrue: [ "Number of four digits needed" println continue ]
+ digits map(#asDigit) ->guess
+
+ guess numbers zipWith(#==) occurrences(true) ->bulls
+ bulls 4 == ifTrue: [ "You won !" println return ]
+
+ guess filter(#[numbers include]) size bulls - ->cows
+ System.Out "Bulls = " << bulls << ", cows = " << cows << cr
+ ] ;
diff --git a/Task/Bulls-and-cows/Phix/bulls-and-cows.phix b/Task/Bulls-and-cows/Phix/bulls-and-cows.phix
new file mode 100644
index 0000000000..37a97d28f2
--- /dev/null
+++ b/Task/Bulls-and-cows/Phix/bulls-and-cows.phix
@@ -0,0 +1,50 @@
+constant N = 4
+
+function mask(integer ch)
+ return power(2,ch-'1')
+end function
+
+function score(sequence guess, sequence goal)
+integer bits = 0, bulls = 0, cows = 0, b
+ for i=1 to N do
+ b = goal[i]
+ if guess[i]=b then
+ bulls += 1
+ else
+ bits += mask(b)
+ end if
+ end for
+ for i=1 to N do
+ b = mask(guess[i])
+ if and_bits(bits,b)!=0 then
+ cows += 1
+ bits -= b
+ end if
+ end for
+ return {bulls, cows}
+end function
+
+procedure game()
+sequence tgt = shuffle("123456789")[1..N]
+integer attempt = 1, bulls = 0, cows
+sequence guess
+ while bulls
+
+put crc32.toHexString(1, crc32.length)
+-- "41 4f a3 39"
diff --git a/Task/CRC-32/Lingo/crc-32-2.lingo b/Task/CRC-32/Lingo/crc-32-2.lingo
new file mode 100644
index 0000000000..f25d1f4b8a
--- /dev/null
+++ b/Task/CRC-32/Lingo/crc-32-2.lingo
@@ -0,0 +1,67 @@
+--****************************************************************************
+-- @desc CRC-32 Class
+-- @file parent script "CRC"
+-- @version 0.1
+--****************************************************************************
+
+property _CRC32Table
+
+----------------------------------------
+-- @constructor
+----------------------------------------
+on new me
+
+ -- used for fast CRC32 calculation
+ me._CRC32Table = [\
+ 0, 1996959894, -301047508, -1727442502, 124634137, 1886057615, -379345611, -1637575261, 249268274, 2044508324,\
+ -522852066, -1747789432, 162941995, 2125561021, -407360249, -1866523247, 498536548, 1789927666, -205950648,\
+ -2067906082, 450548861, 1843258603, -187386543, -2083289657, 325883990, 1684777152, -43845254, -1973040660,\
+ 335633487, 1661365465, -99664541, -1928851979, 997073096, 1281953886, -715111964, -1570279054, 1006888145,\
+ 1258607687, -770865667, -1526024853, 901097722, 1119000684, -608450090, -1396901568, 853044451, 1172266101,\
+ -589951537, -1412350631, 651767980, 1373503546, -925412992, -1076862698, 565507253, 1454621731, -809855591,\
+ -1195530993, 671266974, 1594198024, -972236366, -1324619484, 795835527, 1483230225, -1050600021, -1234817731,\
+ 1994146192, 31158534, -1731059524, -271249366, 1907459465, 112637215, -1614814043, -390540237, 2013776290,\
+ 251722036, -1777751922, -519137256, 2137656763, 141376813, -1855689577, -429695999, 1802195444, 476864866,\
+ -2056965928, -228458418, 1812370925, 453092731, -2113342271, -183516073, 1706088902, 314042704, -1950435094,\
+ -54949764, 1658658271, 366619977, -1932296973, -69972891, 1303535960, 984961486, -1547960204, -725929758,\
+ 1256170817, 1037604311, -1529756563, -740887301, 1131014506, 879679996, -1385723834, -631195440, 1141124467,\
+ 855842277, -1442165665, -586318647, 1342533948, 654459306, -1106571248, -921952122, 1466479909, 544179635,\
+ -1184443383, -832445281, 1591671054, 702138776, -1328506846, -942167884, 1504918807, 783551873, -1212326853,\
+ -1061524307, -306674912, -1698712650, 62317068, 1957810842, -355121351, -1647151185, 81470997, 1943803523,\
+ -480048366, -1805370492, 225274430, 2053790376, -468791541, -1828061283, 167816743, 2097651377, -267414716,\
+ -2029476910, 503444072, 1762050814, -144550051, -2140837941, 426522225, 1852507879, -19653770, -1982649376,\
+ 282753626, 1742555852, -105259153, -1900089351, 397917763, 1622183637, -690576408, -1580100738, 953729732,\
+ 1340076626, -776247311, -1497606297, 1068828381, 1219638859, -670225446, -1358292148, 906185462, 1090812512,\
+ -547295293, -1469587627, 829329135, 1181335161, -882789492, -1134132454, 628085408, 1382605366, -871598187,\
+ -1156888829, 570562233, 1426400815, -977650754, -1296233688, 733239954, 1555261956, -1026031705, -1244606671,\
+ 752459403, 1541320221, -1687895376, -328994266, 1969922972, 40735498, -1677130071, -351390145, 1913087877,\
+ 83908371, -1782625662, -491226604, 2075208622, 213261112, -1831694693, -438977011, 2094854071, 198958881,\
+ -2032938284, -237706686, 1759359992, 534414190, -2118248755, -155638181, 1873836001, 414664567, -2012718362,\
+ -15766928, 1711684554, 285281116, -1889165569, -127750551, 1634467795, 376229701, -1609899400, -686959890,\
+ 1308918612, 956543938, -1486412191, -799009033, 1231636301, 1047427035, -1362007478, -640263460, 1088359270,\
+ 936918000, -1447252397, -558129467, 1202900863, 817233897, -1111625188, -893730166, 1404277552, 615818150,\
+ -1160759803, -841546093, 1423857449, 601450431, -1285129682, -1000256840, 1567103746, 711928724, -1274298825,\
+ -1022587231, 1510334235, 755167117]
+ return me
+end
+
+----------------------------------------
+-- Calculates CRC-32 checksum of string or bytearray
+-- @param {bytearray|string} input
+-- @return {bytearray} (4 bytes)
+----------------------------------------
+on crc32 (me, input)
+ if stringP(input) then input = bytearray(input)
+ crc = -1
+ len = input.length
+ repeat with i = 1 to len
+ if (crc>0) then bitShift8 = crc/256
+ else bitShift8 = bitAnd(crc,2147483647)/256+8388608
+ crc = bitXor(bitShift8,me._CRC32Table[bitAnd(bitXor(crc,input[i]),255)+1])
+ end repeat
+ ba = bytearray()
+ ba.endian = #bigEndian
+ ba.writeInt32(bitXOr(crc,-1))
+ ba.position = 1
+ return ba
+end
diff --git a/Task/CRC-32/Lingo/crc-32-3.lingo b/Task/CRC-32/Lingo/crc-32-3.lingo
new file mode 100644
index 0000000000..dea14e581b
--- /dev/null
+++ b/Task/CRC-32/Lingo/crc-32-3.lingo
@@ -0,0 +1,3 @@
+cx = Xtra("Crypto").new()
+put cx.cx_crc32_string("The quick brown fox jumps over the lazy dog")
+-- "414fa339"
diff --git a/Task/CRC-32/Nim/crc-32.nim b/Task/CRC-32/Nim/crc-32.nim
new file mode 100644
index 0000000000..1f5a8399cc
--- /dev/null
+++ b/Task/CRC-32/Nim/crc-32.nim
@@ -0,0 +1,23 @@
+import unsigned, strutils
+
+type TCrc32* = uint32
+const InitCrc32* = TCrc32(-1)
+
+proc createCrcTable(): array[0..255, TCrc32] =
+ for i in 0..255:
+ var rem = TCrc32(i)
+ for j in 0..7:
+ if (rem and 1) > 0: rem = (rem shr 1) xor TCrc32(0xedb88320)
+ else: rem = rem shr 1
+ result[i] = rem
+
+# Table created at compile time
+const crc32table = createCrcTable()
+
+proc crc32(s: string): TCrc32 =
+ result = InitCrc32
+ for c in s:
+ result = (result shr 8) xor crc32table[(result and 0xff) xor ord(c)]
+ result = not result
+
+echo crc32("The quick brown fox jumps over the lazy dog").int64.toHex(8)
diff --git a/Task/CRC-32/Phix/crc-32-1.phix b/Task/CRC-32/Phix/crc-32-1.phix
new file mode 100644
index 0000000000..f2ef5d796b
--- /dev/null
+++ b/Task/CRC-32/Phix/crc-32-1.phix
@@ -0,0 +1,37 @@
+sequence table
+integer have_table = 0
+
+procedure make_crc()
+atom rem
+ if have_table=0 then
+ have_table = 1
+ table = repeat(0,256)
+ for i=0 to 255 do
+ rem = i
+ for j=1 to 8 do
+ if and_bits(rem,1) then
+ rem = xor_bits(floor(rem/2),#EDB88320)
+ else
+ rem = floor(rem/2)
+ end if
+ if rem<0 then
+ rem += #100000000
+ end if
+ end for
+ table[i+1] = rem
+ end for
+ end if
+end procedure
+
+function crc32(string s)
+atom crc = #FFFFFFFF
+ if have_table=0 then make_crc() end if
+ for i=1 to length(s) do
+ crc = xor_bits(floor(crc/#100),table[xor_bits(and_bits(crc,0xff),s[i])+1])
+ if crc<0 then
+ crc += #100000000
+ end if
+ end for
+-- return not_bits(crc)
+ return and_bits(not_bits(crc),#FFFFFFFF)
+end function
diff --git a/Task/CRC-32/Phix/crc-32-2.phix b/Task/CRC-32/Phix/crc-32-2.phix
new file mode 100644
index 0000000000..34e71dc11b
--- /dev/null
+++ b/Task/CRC-32/Phix/crc-32-2.phix
@@ -0,0 +1,2 @@
+string s = "The quick brown fox jumps over the lazy dog"
+printf(1,"The CRC of %s is %08x\n",{s,crc32(s)})
diff --git a/Task/CRC-32/Swift/crc-32.swift b/Task/CRC-32/Swift/crc-32.swift
new file mode 100644
index 0000000000..f101179f5c
--- /dev/null
+++ b/Task/CRC-32/Swift/crc-32.swift
@@ -0,0 +1,7 @@
+import Foundation
+
+let strData = "The quick brown fox jumps over the lazy dog".dataUsingEncoding(NSUTF8StringEncoding,
+ allowLossyConversion: false)
+let crc = crc32(uLong(0), UnsafePointer(strData!.bytes), uInt(strData!.length))
+
+println(NSString(format:"%2X", crc))
diff --git a/Task/CSV-data-manipulation/ECL/csv-data-manipulation.ecl b/Task/CSV-data-manipulation/ECL/csv-data-manipulation.ecl
new file mode 100644
index 0000000000..b69c763781
--- /dev/null
+++ b/Task/CSV-data-manipulation/ECL/csv-data-manipulation.ecl
@@ -0,0 +1,21 @@
+// Assumes a CSV file exists and has been sprayed to a Thor cluster
+MyFileLayout := RECORD
+STRING Field1;
+STRING Field2;
+STRING Field3;
+STRING Field4;
+STRING Field5;
+END;
+
+MyDataset := DATASET ('~Rosetta::myCSVFile', MyFileLayout,CSV(SEPARATOR(',')));
+
+MyFileLayout Appended(MyFileLayout pInput):= TRANSFORM
+ SELF.Field1 := pInput.Field1 +'x';
+ SELF.Field2 := pInput.Field2 +'y';
+ SELF.Field3 := pInput.Field3 +'z';
+ SELF.Field4 := pInput.Field4 +'a';
+ SELF.Field5 := pInput.Field5 +'b';
+END ;
+
+MyNewDataset := PROJECT(MyDataset,Appended(LEFT));
+OUTPUT(myNewDataset,,'~Rosetta::myNewCSVFile',CSV,OVERWRITE);
diff --git a/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-1.echolisp b/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-1.echolisp
new file mode 100644
index 0000000000..9afa63c6bb
--- /dev/null
+++ b/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-1.echolisp
@@ -0,0 +1,21 @@
+;; CSV -> LISTS
+(define (csv->row line) (map (lambda(x) (or (string->number x) x)) (string-split line ",")))
+(define (csv->table csv) (map csv->row (string-split csv "\n")))
+
+;; LISTS -> CSV
+(define (row->csv row) (string-join row ","))
+(define (table->csv header rows)
+ (string-join (cons (row->csv header) (for/list ((row rows)) (row->csv row))) "\n"))
+
+
+(define (task file)
+ (let*
+ ((table (csv->table file))
+ (header (first table))
+ (rows (rest table)))
+
+ (table->csv
+ (append header "SUM") ;; add last column
+ (for/list ((row rows)) (append row (apply + row))))))
+
+
diff --git a/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-2.echolisp b/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-2.echolisp
new file mode 100644
index 0000000000..a7bec1d064
--- /dev/null
+++ b/Task/CSV-data-manipulation/EchoLisp/csv-data-manipulation-2.echolisp
@@ -0,0 +1,15 @@
+(define file.csv #<<
+C1,C2,C3,C4,C5
+1,5,9,13,17
+2,6,10,14,18
+3,7,11,15,19
+4,8,12,16,20
+>>#)
+
+(task file.csv)
+
+ → "C1,C2,C3,C4,C5,SUM
+1,5,9,13,17,45
+2,6,10,14,18,50
+3,7,11,15,19,55
+4,8,12,16,20,60"
diff --git a/Task/CSV-data-manipulation/FreeBASIC/csv-data-manipulation.freebasic b/Task/CSV-data-manipulation/FreeBASIC/csv-data-manipulation.freebasic
new file mode 100644
index 0000000000..d5e83a2542
--- /dev/null
+++ b/Task/CSV-data-manipulation/FreeBASIC/csv-data-manipulation.freebasic
@@ -0,0 +1,20 @@
+' FB 1.05.0 Win64
+
+Open "manip.csv" For Input As #1 ' existing CSV file
+Open "manip2.csv" For Output As #2 ' new CSV file for writing changed data
+
+Dim header As String
+Line Input #1, header
+header += ",SUM"
+Print #2, header
+
+Dim As Integer c1, c2, c3, c4, c5, sum
+
+While Not Eof(1)
+ Input #1, c1, c2, c3, c4, c5
+ sum = c1 + c2 + c3 + c4 + c5
+ Write #2, c1, c2, c3, c4, c5, sum
+Wend
+
+Close #1
+Close #2
diff --git a/Task/CSV-data-manipulation/FunL/csv-data-manipulation.funl b/Task/CSV-data-manipulation/FunL/csv-data-manipulation.funl
new file mode 100644
index 0000000000..17cee74435
--- /dev/null
+++ b/Task/CSV-data-manipulation/FunL/csv-data-manipulation.funl
@@ -0,0 +1,45 @@
+import io.{lines, PrintWriter}
+
+data Table( header, rows )
+
+def read( file ) =
+ l = lines( file )
+
+ def next = vector( l.next().split(',') )
+
+ if l.isEmpty() then
+ return Table( vector(), [] )
+
+ header = next()
+ rows = seq()
+
+ while l.hasNext()
+ rows += next()
+
+ Table( header, rows.toList() )
+
+def write( table, out ) =
+ w = if out is String then PrintWriter( out ) else out
+
+ w.println( table.header.mkString(',') )
+
+ for r <- table.rows
+ w.println( r.mkString(',') )
+
+ if out is String
+ w.close()
+
+def updateRow( header, row, updates ) =
+ r = dict( (header(i), row(i)) | i <- 0:header.length() )
+ updates( r )
+ vector( r(f) | f <- header )
+
+def update( table, updates ) =
+ Table( table.header, (updateRow(table.header, r, updates) | r <- table.rows).toList() )
+
+def addColumn( table, column, updates ) =
+ Table( table.header + [column], (updateRow(table.header + [column], r + [null], updates) | r <- table.rows).toList() )
+
+t = addColumn( read('test.csv'), 'SUM', r -> r('SUM') = sum(int(v) | (_, v) <- r if v != null) )
+write( t, 'test_out.csv' )
+write( t, System.out )
diff --git a/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-1.lingo b/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-1.lingo
new file mode 100644
index 0000000000..a3dd6d0afb
--- /dev/null
+++ b/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-1.lingo
@@ -0,0 +1,99 @@
+----------------------------------------
+-- Simplified CSV parser (without escape character support etc.).
+-- First line is interrepted as header with column names.
+-- @param {string} csvStr
+-- @param {string} [sep=","] - single char as string
+-- @param {string} [eol=RETURN]
+-- @return {propList}
+----------------------------------------
+on parseSimpleCSVString (csvStr, sep, eol)
+ if voidP(sep) then sep=","
+ if voidP(eol) then eol = RETURN
+ lines = explode(eol, csvStr)
+ if lines.getLast()="" then lines.deleteAt(lines.count)
+ res = [:]
+ res[#header] = explode(sep, lines[1])
+ res[#data] = []
+ cnt = lines.count
+ repeat with i = 2 to cnt
+ res[#data].append(explodeBySingleChar(sep, lines[i]))
+ end repeat
+ return res
+end
+
+----------------------------------------
+-- Simplified CSV creater (without escape character support etc.).
+-- @param {propList} csvData
+-- @param {string} [sep=","]
+-- @param {string} [eol=RETURN]
+-- @return {string}
+----------------------------------------
+on createSimpleCSVString (csvData, sep, eol)
+ if voidP(sep) then sep=","
+ if voidP(eol) then eol = RETURN
+ res = ""
+ put implode(sep, csvData[#header])&eol after res
+ cnt = csvData[#data].count
+ repeat with i = 1 to cnt
+ put implode(sep, csvData[#data][i])&eol after res
+ end repeat
+ return res
+end
+
+----------------------------------------
+-- Explodes string into list
+-- @param {string} delim
+-- @param {string} str
+-- @return {list}
+----------------------------------------
+on explode (delim, str)
+ if delim.length=1 then return explodeBySingleChar(delim, str)
+ l = []
+ if voidP(str) then return l
+ dl = delim.length
+ repeat while true
+ pos = offset(delim, str)
+ if pos=0 then exit repeat
+ l.add(str.char[1..pos-1])
+ delete char 1 to pos+dl-1 of str
+ end repeat
+ if pos=0 then pos = 1-dl
+ l.add(str.char[pos+dl..str.length])
+ return l
+end
+
+----------------------------------------
+-- Explode string into list based on single char delimiter
+-- (uses Lingo's build-in 'item' support, therefor faster)
+-- @param {string} delim
+-- @param {string} str
+-- @return {list}
+----------------------------------------
+on explodeBySingleChar (delim, str)
+ l = []
+ if voidP(str) then return l
+ od = _player.itemDelimiter
+ _player.itemDelimiter = delim
+ cnt = str.item.count
+ repeat with i = 1 to cnt
+ l.add(str.item[i])
+ end repeat
+ _player.itemDelimiter = od
+ return l
+end
+
+----------------------------------------
+-- Implodes list into string
+-- @param {string} delim
+-- @param {list} l
+-- @return {string}
+----------------------------------------
+on implode (delim, l)
+ str = ""
+ cnt = l.count
+ repeat with i = 1 to cnt
+ put l[i]&delim after str
+ end repeat
+ delete char (str.length-delim.length+1) to str.length of str
+ return str
+end
diff --git a/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-2.lingo b/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-2.lingo
new file mode 100644
index 0000000000..88f70e1352
--- /dev/null
+++ b/Task/CSV-data-manipulation/Lingo/csv-data-manipulation-2.lingo
@@ -0,0 +1,44 @@
+sep = ","
+eol = numtochar(10)
+
+-- load CSV string from file
+fn = _movie.path & "file.csv"
+fp = xtra("fileIO").new()
+fp.openFile(fn, 1)
+csvStr = fp.readFile()
+fp.closeFile()
+
+-- parse CSV string into propList
+csvData = parseSimpleCSVString(csvStr, sep, eol)
+
+-- add SUM column
+csvData[#header].append("SUM")
+repeat with row in csvData[#data]
+ sum = 0
+ repeat with cell in row
+ sum = sum+integer(cell)
+ end repeat
+ row.append(sum)
+end repeat
+
+-- create CSV string from updated propList
+csvString = createSimpleCSVString(csvData, sep, eol)
+
+-- save CSV string to file
+fn = _movie.path & "file.csv"
+fp.openFile(fn, 2)
+if not fp.status() then fp.delete()
+fp.createFile(fn)
+fp.openFile(fn, 2)
+fp.writeString(csvString)
+fp.closeFile()
+
+-- show the CSV string
+put csvString
+
+-- "C1,C2,C3,C4,C5,SUM
+1,5,9,13,17,45
+2,6,10,14,18,50
+3,7,11,15,19,55
+4,8,12,16,20,60
+"
diff --git a/Task/CSV-data-manipulation/Nim/csv-data-manipulation.nim b/Task/CSV-data-manipulation/Nim/csv-data-manipulation.nim
new file mode 100644
index 0000000000..61636bc177
--- /dev/null
+++ b/Task/CSV-data-manipulation/Nim/csv-data-manipulation.nim
@@ -0,0 +1,25 @@
+import strutils, streams
+
+let
+ csv = newFileStream("data.csv", fmRead)
+ outf = newFileStream("data-out.csv", fmWrite)
+
+var lineNumber = 1
+
+while true:
+ if atEnd(csv):
+ break
+ var line = readLine(csv)
+
+ if lineNumber == 1:
+ line.add(",SUM")
+ else:
+ var tmp = 0
+ for n in split(line, ","):
+ tmp += parseInt(n)
+ line.add(",")
+ line.add($tmp)
+
+ outf.writeLn($line)
+
+ inc lineNumber
diff --git a/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-1.sidef b/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-1.sidef
new file mode 100644
index 0000000000..9956636bef
--- /dev/null
+++ b/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-1.sidef
@@ -0,0 +1,12 @@
+# Read
+var csvfile = %f'data.csv';
+var fh = csvfile.open_r;
+var header = fh.line.trim_end.split(',');
+var csv = fh.lines.map { .trim_end.split(',').map{.to_num} };
+fh.close;
+
+# Write
+var out = csvfile.open_w;
+out.say([header..., 'SUM'].join(','));
+csv.each { |row| out.say([row..., row.sum].join(',')) };
+out.close;
diff --git a/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-2.sidef b/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-2.sidef
new file mode 100644
index 0000000000..0b321bd251
--- /dev/null
+++ b/Task/CSV-data-manipulation/Sidef/csv-data-manipulation-2.sidef
@@ -0,0 +1,24 @@
+var csv = require('Text::CSV').new(
+ Hash(eol => "\n")
+);
+
+# Open
+var csvfile = %f'data.csv';
+var fh = csvfile.open_r;
+
+# Read
+var rows = [];
+var header = csv.getline(fh);
+while (var row = csv.getline(fh)) {
+ rows.append(row.map{.to_num});
+}
+
+# Process
+header.append('SUM');
+rows.each { |row| row.append(row.sum) };
+
+# Write
+var out = csvfile.open_w;
+[header, rows...].each { |row|
+ csv.print(out, row);
+};
diff --git a/Task/CSV-data-manipulation/Ursa/csv-data-manipulation.ursa b/Task/CSV-data-manipulation/Ursa/csv-data-manipulation.ursa
new file mode 100644
index 0000000000..a43f4b5c54
--- /dev/null
+++ b/Task/CSV-data-manipulation/Ursa/csv-data-manipulation.ursa
@@ -0,0 +1,42 @@
+#
+# csv data manipulation
+#
+
+# declare a string stream to hold lines
+decl string<> lines
+
+# open the file specified on the command line, halting
+# execution if they didn't enter one. it will be created if
+# it doesn't exist yet
+decl file f
+if (< (size args) 2)
+ out "error: please specify a csv file" endl console
+ stop
+end if
+f.create args<1>
+f.open args<1>
+
+# read in all lines from the file
+set lines (f.readlines)
+
+# append sum column to header
+set lines<0> (+ lines<0> ",SUM")
+
+# determine sums and append them
+decl int i sum
+for (set i 1) (< i (size lines)) (inc i)
+ set sum 0
+ for (decl int j) (< j (size (split lines ","))) (inc j)
+ set sum (int (+ sum (int (split lines ","))))
+ end for
+ set lines (+ lines (+ "," sum))
+end for
+
+# delete the file, then create it again
+f.delete args<1>
+f.create args<1>
+
+# output all lines to the file
+for (set i 0) (< i (size lines)) (inc i)
+ out lines endl f
+end for
diff --git a/Task/CSV-data-manipulation/Visual-FoxPro/csv-data-manipulation.visual b/Task/CSV-data-manipulation/Visual-FoxPro/csv-data-manipulation.visual
new file mode 100644
index 0000000000..f20a5d9e98
--- /dev/null
+++ b/Task/CSV-data-manipulation/Visual-FoxPro/csv-data-manipulation.visual
@@ -0,0 +1,11 @@
+CLOSE DATABASES ALL
+SET SAFETY OFF
+MODIFY FILE file1.csv NOEDIT
+*!* Create a cursor with integer columns
+CREATE CURSOR tmp1 (C1 I, C2 I, C3 I, C4 I, C5 I)
+APPEND FROM file1.csv TYPE CSV
+SELECT C1, C2, C3, C4, C5, C1+C2+C3+C4+C5 As sum ;
+FROM tmp1 INTO CURSOR tmp2
+COPY TO file2.csv TYPE CSV
+MODIFY FILE file2.csv NOEDIT IN SCREEN
+SET SAFETY ON
diff --git a/Task/CSV-data-manipulation/jq/csv-data-manipulation.jq b/Task/CSV-data-manipulation/jq/csv-data-manipulation.jq
new file mode 100644
index 0000000000..b87fbf55ad
--- /dev/null
+++ b/Task/CSV-data-manipulation/jq/csv-data-manipulation.jq
@@ -0,0 +1,15 @@
+# Omit empty lines
+def read_csv:
+ split("\n")
+ | map(if length>0 then split(",") else empty end) ;
+
+# add_column(label) adds a summation column (with the given label) to
+# the matrix representation of the CSV table, and assumes that all the
+# entries in the body of the CSV file are, or can be converted to,
+# numbers:
+def add_column(label):
+ [.[0] + [label],
+ (reduce .[1:][] as $line
+ ([]; ($line|map(tonumber)) as $line | . + [$line + [$line|add]]))[] ] ;
+
+read_csv | add_column("SUM") | map(@csv)[]
diff --git a/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-1.echolisp b/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-1.echolisp
new file mode 100644
index 0000000000..a7a16c05df
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-1.echolisp
@@ -0,0 +1,30 @@
+;; CSV -> LISTS
+(define (csv->row line) (string-split line ","))
+(define (csv->table csv) (map csv->row (string-split csv "\n")))
+
+;; LISTS->HTML
+(define html 'html)
+(define (emit-tag tag html-proc content )
+ (if (style tag)
+ (push html (format "<%s style='%a'>" tag (style tag)))
+ (push html (format "<%s>" tag )))
+ (html-proc content)
+ (push html (format "%s> " tag )))
+
+;; html procs : 1 tag, 1 proc
+(define (h-raw content)
+ (push html (format "%s" content)))
+(define (h-header headers)
+ (for ((h headers)) (emit-tag 'th h-raw h)))
+(define (h-row row)
+ (for ((item row)) (emit-tag 'td h-raw item)))
+(define (h-table table )
+ (emit-tag 'tr h-header (first table))
+ (for ((row (rest table))) (emit-tag 'tr h-row row)))
+
+(define (html-dump) (string-join (stack->list html) " "))
+
+;; STYLES
+(style 'td "text-align:left")
+(style 'table "border-spacing: 10px;border:28px ridge orange") ;; special biblical border
+(style 'th "color:blue;")
diff --git a/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-2.echolisp b/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-2.echolisp
new file mode 100644
index 0000000000..777daf9665
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/EchoLisp/csv-to-html-translation-2.echolisp
@@ -0,0 +1,17 @@
+;; changed to to show that html tags inside text are correctly transmitted.
+(define MontyPython #<<
+ 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!
+>>#)
+
+(define (task speech)
+ (define table (csv->table speech))
+ (stack html)
+ (emit-tag 'table h-table table)
+ (html-dump))
+
+(task MontyPython)
diff --git a/Task/CSV-to-HTML-translation/Nim/csv-to-html-translation.nim b/Task/CSV-to-HTML-translation/Nim/csv-to-html-translation.nim
new file mode 100644
index 0000000000..10504cf702
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Nim/csv-to-html-translation.nim
@@ -0,0 +1,23 @@
+import cgi, strutils
+
+const csvtext = """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!"""
+
+proc row2tr(row): string =
+ result = ""
+ let cols = xmlEncode(row).split(",")
+ for col in cols:
+ result.add "| "&col&" | "
+ result.add "
"
+
+proc csv2html(txt): string =
+ result = "\n"
+ for row in txt.splitLines():
+ result.add " "&row2tr(row)&"\n"
+ result.add "
"
+
+echo csv2html(csvtext)
diff --git a/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-1.phix b/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-1.phix
new file mode 100644
index 0000000000..6ab63d1683
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-1.phix
@@ -0,0 +1,20 @@
+constant input = "Character,Speech\n" &
+ "The multitude,The messiah! Show us the messiah!\n" &
+ "Brians mother,Now you listen here! He's not the messiah; " &
+ "he's a very naughty boy! Now go away!\n" &
+ "The multitude,Who are you?\n" &
+ "Brians mother,I'm his mother; that's who!\n" &
+ "The multitude,Behold his mother! Behold his mother!"
+
+puts(1,"\n| ")
+for i = 1 to length(input) do
+ switch input[i] do
+ case '\n' then puts(1," |
\n| ")
+ case ',' then puts(1," | ")
+ case '<' then puts(1,"<")
+ case '>' then puts(1,">")
+ case '&' then puts(1,"&")
+ case else puts(1,input[i])
+ end switch
+end for
+puts(1," |
\n
")
diff --git a/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-2.phix b/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-2.phix
new file mode 100644
index 0000000000..0964db10ff
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Phix/csv-to-html-translation-2.phix
@@ -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/Sidef/csv-to-html-translation-1.sidef b/Task/CSV-to-HTML-translation/Sidef/csv-to-html-translation-1.sidef
new file mode 100644
index 0000000000..a591fd9ef7
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Sidef/csv-to-html-translation-1.sidef
@@ -0,0 +1,30 @@
+func escape(str) { str.trans(« & < > », « & < > ») }
+func tag(t, d) { "<#{t}>#{d}#{t}>" }
+
+func csv2html(str) {
+
+ var template = <<'-EOT'
+
+
+ Some Text
+
+ EOT
+
+ template.sprintf(escape(str).lines.map{ |line|
+ tag('tr', line.split(',').map{|cell| tag('td', cell) }.join)
+ }.join("\n")
+ )
+}
+
+var str = <<'EOT';
+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!
+EOT
+
+print csv2html(str)
diff --git a/Task/CSV-to-HTML-translation/Sidef/csv-to-html-translation-2.sidef b/Task/CSV-to-HTML-translation/Sidef/csv-to-html-translation-2.sidef
new file mode 100644
index 0000000000..ac4dc68bd0
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/Sidef/csv-to-html-translation-2.sidef
@@ -0,0 +1,11 @@
+
+
+Some Text
+
+| 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/jq/csv-to-html-translation-1.jq b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-1.jq
new file mode 100644
index 0000000000..25c90cf686
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-1.jq
@@ -0,0 +1 @@
+jq -R . csv2html.csv | jq -r -s -f csv2html.jq
diff --git a/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-2.jq b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-2.jq
new file mode 100644
index 0000000000..3e740a9593
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-2.jq
@@ -0,0 +1,22 @@
+def headerrow2html:
+ [" "]
+ + (split(",") | map(" | \(@html) | "))
+ + [ "
" ]
+;
+
+def row2html:
+ [" "]
+ + (split(",") | map(" | \(@html) | "))
+ + [ "
" ]
+;
+
+def csv2html:
+ def rows: reduce .[] as $row
+ ([]; . + ($row | row2html));
+ [""]
+ + (.[0] | headerrow2html)
+ + (.[1:] | rows)
+ + [ "
"]
+;
+
+csv2html | .[]
diff --git a/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-3.jq b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-3.jq
new file mode 100644
index 0000000000..1c2fc2040c
--- /dev/null
+++ b/Task/CSV-to-HTML-translation/jq/csv-to-html-translation-3.jq
@@ -0,0 +1,26 @@
+
+
+ | 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/ERRE/caesar-cipher.erre b/Task/Caesar-cipher/ERRE/caesar-cipher.erre
new file mode 100644
index 0000000000..8a7c4b6184
--- /dev/null
+++ b/Task/Caesar-cipher/ERRE/caesar-cipher.erre
@@ -0,0 +1,29 @@
+PROGRAM CAESAR
+
+!$INCLUDE="PC.LIB"
+
+PROCEDURE CAESAR(TEXT$,KY%->CY$)
+ LOCAL I%,C%
+ FOR I%=1 TO LEN(TEXT$) DO
+ C%=ASC(MID$(TEXT$,I%))
+ IF (C% AND $1F)>=1 AND (C% AND $1F)<=26 THEN
+ C%=(C% AND $E0) OR (((C% AND $1F)+KY%-1) MOD 26+1)
+ CHANGE(TEXT$,I%,CHR$(C%)->TEXT$)
+ END IF
+ END FOR
+ CY$=TEXT$
+END PROCEDURE
+
+BEGIN
+ RANDOMIZE(TIMER)
+ PLAINTEXT$="Pack my box with five dozen liquor jugs"
+ PRINT(PLAINTEXT$)
+
+ KY%=1+INT(25*RND(1)) ! generates random between 1 and 25
+ CAESAR(PLAINTEXT$,KY%->CYPHERTEXT$)
+ PRINT(CYPHERTEXT$)
+
+ CAESAR(CYPHERTEXT$,26-KY%->DECYPHERED$)
+ PRINT(DECYPHERED$)
+
+END PROGRAM
diff --git a/Task/Caesar-cipher/FreeBASIC/caesar-cipher.freebasic b/Task/Caesar-cipher/FreeBASIC/caesar-cipher.freebasic
new file mode 100644
index 0000000000..2a84d19c00
--- /dev/null
+++ b/Task/Caesar-cipher/FreeBASIC/caesar-cipher.freebasic
@@ -0,0 +1,41 @@
+' FB 1.05.0 Win64
+
+Sub Encrypt(s As String, key As Integer)
+ Dim c As Integer
+ For i As Integer = 0 To Len(s)
+ Select Case As Const s[i]
+ Case 65 To 90
+ c = s[i] + key
+ If c > 90 Then c -= 26
+ s[i] = c
+ Case 97 To 122
+ c = s[i] + key
+ If c > 122 Then c -= 26
+ s[i] = c
+ End Select
+ Next
+End Sub
+
+Sub Decrypt(s As String, key As Integer)
+ Dim c As Integer
+ For i As Integer = 0 To Len(s)
+ Select Case As Const s[i]
+ Case 65 To 90
+ c = s[i] - key
+ If c < 65 Then c += 26
+ s[i] = c
+ Case 97 To 122
+ c = s[i] - key
+ If c < 97 Then c += 26
+ s[i] = c
+ End Select
+ Next
+End Sub
+
+Dim As String s = "Bright vixens jump; dozy fowl quack."
+Print "Plain text : "; s
+Encrypt s, 8
+Print "Encrypted : "; s
+Decrypt s, 8
+Print "Decrypted : "; s
+Sleep
diff --git a/Task/Caesar-cipher/GFA-Basic/caesar-cipher.gfa b/Task/Caesar-cipher/GFA-Basic/caesar-cipher.gfa
new file mode 100644
index 0000000000..e2b61ed01b
--- /dev/null
+++ b/Task/Caesar-cipher/GFA-Basic/caesar-cipher.gfa
@@ -0,0 +1,36 @@
+'
+' Caesar cypher
+'
+OPENW 1 ! Creates a window for handling input/output
+CLEARW 1
+INPUT "string to encrypt ";text$
+INPUT "encryption key ";key%
+encrypted$=@encrypt$(UPPER$(text$),key%)
+PRINT "Encrypted: ";encrypted$
+PRINT "Decrypted: ";@decrypt$(encrypted$,key%)
+'
+PRINT "(Press any key to end program.)"
+~INP(2)
+CLOSEW 1
+'
+FUNCTION encrypt$(text$,key%)
+ LOCAL result$,i%,c%
+ result$=""
+ FOR i%=1 TO LEN(text$)
+ c%=ASC(MID$(text$,i%))
+ IF c%ASC("Z") ! don't encrypt non A-Z
+ result$=result$+CHR$(c%)
+ ELSE
+ c%=c%+key%
+ IF c%>ASC("Z")
+ c%=c%-26
+ ENDIF
+ result$=result$+CHR$(c%)
+ ENDIF
+ NEXT i%
+ RETURN result$
+ENDFUNC
+'
+FUNCTION decrypt$(text$,key%)
+ RETURN @encrypt$(text$,26-key%)
+ENDFUNC
diff --git a/Task/Caesar-cipher/LiveCode/caesar-cipher.livecode b/Task/Caesar-cipher/LiveCode/caesar-cipher.livecode
new file mode 100644
index 0000000000..beb1e58b2b
--- /dev/null
+++ b/Task/Caesar-cipher/LiveCode/caesar-cipher.livecode
@@ -0,0 +1,16 @@
+function caesarCipher rot phrase
+ local rotPhrase, lowerLetters, upperLetters
+ put "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" into lowerLetters
+ put "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" into upperLetters
+ repeat for each char letter in phrase
+ get charTonum(letter)
+ if it >= 65 and it <= 90 then
+ put char ((it + rot) - 64) of upperLetters after rotPhrase
+ else if it >= 97 and it <= 122 then
+ put char ((it + rot) - 96) of lowerLetters after rotPhrase
+ else
+ put letter after rotPhrase
+ end if
+ end repeat
+ return rotPhrase
+end caesarCipher
diff --git a/Task/Caesar-cipher/Nim/caesar-cipher.nim b/Task/Caesar-cipher/Nim/caesar-cipher.nim
new file mode 100644
index 0000000000..981e1ad518
--- /dev/null
+++ b/Task/Caesar-cipher/Nim/caesar-cipher.nim
@@ -0,0 +1,14 @@
+import strutils
+
+proc caesar(s: string, k: int, decode = false): string =
+ var k = if decode: 26 - k else: k
+ result = ""
+ for i in toUpper(s):
+ if ord(i) >= 65 and ord(i) <= 90:
+ result.add(chr((ord(i) - 65 + k) mod 26 + 65))
+
+let msg = "The quick brown fox jumped over the lazy dogs"
+echo msg
+let enc = caesar(msg, 11)
+echo enc
+echo caesar(enc, 11, decode = true)
diff --git a/Task/Caesar-cipher/Oforth/caesar-cipher.oforth b/Task/Caesar-cipher/Oforth/caesar-cipher.oforth
new file mode 100644
index 0000000000..1aef744942
--- /dev/null
+++ b/Task/Caesar-cipher/Oforth/caesar-cipher.oforth
@@ -0,0 +1,6 @@
+: ceasar(c, key)
+ c dup isLetter ifFalse: [ return ]
+ isUpper ifTrue: [ 'A' ] else: [ 'a' ] c key + over - 26 mod + ;
+
+: cipherE(s, key) s map(#[ key ceasar ]) charsAsString ;
+: cipherD(s, key) cipherE(s, 26 key - ) ;
diff --git a/Task/Caesar-cipher/Phix/caesar-cipher.phix b/Task/Caesar-cipher/Phix/caesar-cipher.phix
new file mode 100644
index 0000000000..3ebce5329e
--- /dev/null
+++ b/Task/Caesar-cipher/Phix/caesar-cipher.phix
@@ -0,0 +1,19 @@
+sequence alpha_b = repeat(0,255)
+ alpha_b['A'..'Z'] = 'A'
+ alpha_b['a'..'z'] = 'a'
+
+function caesar(string s, integer key)
+integer ch, base
+ for i=1 to length(s) do
+ ch = s[i]
+ base = alpha_b[ch]
+ if base then
+ s[i] = base+remainder(ch-base+key,26)
+ end if
+ end for
+ return s
+end function
+string s = "One fine day in the middle of the night, two dead men got up to fight. \n"&
+ "Back to back they faced each other, drew their swords and shot each other. %^&*()[",
+ e = caesar(s,5),
+ r = caesar(e,26-5) ?e ?r
diff --git a/Task/Caesar-cipher/SSEM/caesar-cipher.ssem b/Task/Caesar-cipher/SSEM/caesar-cipher.ssem
new file mode 100644
index 0000000000..0daec42427
--- /dev/null
+++ b/Task/Caesar-cipher/SSEM/caesar-cipher.ssem
@@ -0,0 +1,19 @@
+00101000000000100000000000000000 0. -20 to c
+11001000000000010000000000000000 1. Sub. 19
+10101000000001100000000000000000 2. c to 21
+10101000000000100000000000000000 3. -21 to c
+00000000000000110000000000000000 4. Test
+10001000000000000000000000000000 5. 17 to CI
+10101000000001100000000000000000 6. c to 21
+10101000000000100000000000000000 7. -21 to c
+01001000000000010000000000000000 8. Sub. 18
+10101000000001100000000000000000 9. c to 21
+10101000000000100000000000000000 10. -21 to c
+00000000000001110000000000000000 11. Stop
+01001000000000010000000000000000 12. Sub. 18
+00000000000000110000000000000000 13. Test
+00000000000001110000000000000000 14. Stop
+10101000000000100000000000000000 15. -21 to c
+00000000000001110000000000000000 16. Stop
+11010000000000000000000000000000 17. 11
+01011000000000000000000000000000 18. 26
diff --git a/Task/Caesar-cipher/SequenceL/caesar-cipher.sequencel b/Task/Caesar-cipher/SequenceL/caesar-cipher.sequencel
new file mode 100644
index 0000000000..3e23c88d8f
--- /dev/null
+++ b/Task/Caesar-cipher/SequenceL/caesar-cipher.sequencel
@@ -0,0 +1,32 @@
+import ;
+import ;
+
+lowerAlphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+upperAlphabet := "abcdefghijklmnopqrstuvwxyz";
+
+caesarEncrypt(ch, key) :=
+ let
+ correctAlphabet :=
+ lowerAlphabet when some(ch = lowerAlphabet)
+ else
+ upperAlphabet;
+
+ index := Sequence::firstIndexOf(correctAlphabet, ch);
+
+ newIndex := (index + key - 1) mod 26 + 1;
+ in
+ ch when not(some(ch = lowerAlphabet) or some(ch = upperAlphabet))
+ else
+ correctAlphabet[newIndex];
+
+caesarDecrypt(ch, key) := caesarEncrypt(ch, 26 - key);
+
+main(args(2)) :=
+ let
+ key := Conversion::stringToInt(args[2]);
+ encrypted := caesarEncrypt(args[1], key);
+ decrypted := caesarDecrypt(encrypted, key);
+ in
+ "Input: \t" ++ args[1] ++ "\n" ++
+ "Encrypted:\t" ++ encrypted ++ "\n" ++
+ "Decrypted:\t" ++ decrypted;
diff --git a/Task/Caesar-cipher/Sidef/caesar-cipher.sidef b/Task/Caesar-cipher/Sidef/caesar-cipher.sidef
new file mode 100644
index 0000000000..91a62b3dc1
--- /dev/null
+++ b/Task/Caesar-cipher/Sidef/caesar-cipher.sidef
@@ -0,0 +1,13 @@
+func caesar(msg, key, decode=false) {
+ decode && (key = (26 - key));
+ msg.gsub(/([A-Z])/i, {|c| ((c.uc.ord - 65 + key) % 26) + 65 -> chr});
+};
+
+var msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY';
+
+var enc = caesar(msg, 10);
+var dec = caesar(enc, 10, true);
+
+say "msg: #{msg}";
+say "enc: #{enc}";
+say "dec: #{dec}";
diff --git a/Task/Caesar-cipher/TypeScript/caesar-cipher.type b/Task/Caesar-cipher/TypeScript/caesar-cipher.type
new file mode 100644
index 0000000000..2721324997
--- /dev/null
+++ b/Task/Caesar-cipher/TypeScript/caesar-cipher.type
@@ -0,0 +1,14 @@
+function replace(input: string, key: number) : string {
+ return input.replace(/([a-z])/g,
+ ($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 97) % 26 + 97)
+ ).replace(/([A-Z])/g,
+ ($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 65) % 26 + 65));
+}
+
+// test
+var str = 'The five boxing wizards jump quickly';
+var encoded = replace(str, 3);
+var decoded = replace(encoded, -3);
+
+console.log('Enciphered: ' + encoded);
+console.log('Deciphered: ' + decoded);
diff --git a/Task/Caesar-cipher/Ursa/caesar-cipher.ursa b/Task/Caesar-cipher/Ursa/caesar-cipher.ursa
new file mode 100644
index 0000000000..0039e259da
--- /dev/null
+++ b/Task/Caesar-cipher/Ursa/caesar-cipher.ursa
@@ -0,0 +1,28 @@
+decl string mode
+while (not (or (= mode "encode") (= mode "decode")))
+ out "encode/decode: " console
+ set mode (lower (in string console))
+end while
+
+decl string message
+out "message: " console
+set message (upper (in string console))
+
+decl int key
+out "key: " console
+set key (in int console)
+if (or (> key 26) (< key 0))
+ out endl "invalid key" endl console
+ stop
+end if
+
+if (= mode "decode")
+ set key (int (- 26 key))
+end if
+
+for (decl int i) (< i (size message)) (inc i)
+ if (and (> (ord message) 64) (< (ord message) 91))
+ out (chr (int (+ (mod (int (+ (- (ord message) 65) key)) 26) 65))) console
+ end if
+end for
+out endl console
diff --git a/Task/Caesar-cipher/Wortel/caesar-cipher.wortel b/Task/Caesar-cipher/Wortel/caesar-cipher.wortel
new file mode 100644
index 0000000000..745df1d0ce
--- /dev/null
+++ b/Task/Caesar-cipher/Wortel/caesar-cipher.wortel
@@ -0,0 +1,18 @@
+@let {
+ ; this function only replaces letters and keeps case
+ ceasar &[s n] !!s.replace &"[a-z]"gi &[x] [
+ @vars {
+ t x.charCodeAt.
+ l ?{
+ && > t 96 < t 123 97
+ && > t 64 < t 91 65
+ 0
+ }
+ }
+ !String.fromCharCode ?{
+ l +l ~% 26 -+ n t l
+ t
+ }
+ ]
+ !!ceasar "abc $%^ ABC" 10
+}
diff --git a/Task/Caesar-cipher/XLISP/caesar-cipher-1.xlisp b/Task/Caesar-cipher/XLISP/caesar-cipher-1.xlisp
new file mode 100644
index 0000000000..02f34734c6
--- /dev/null
+++ b/Task/Caesar-cipher/XLISP/caesar-cipher-1.xlisp
@@ -0,0 +1,16 @@
+(defun caesar-encode (text key)
+ (defun encode (ascii-code)
+ (defun rotate (character alphabet)
+ (define code (+ character key))
+ (cond
+ ((> code (+ alphabet 25)) (- code 26))
+ ((< code alphabet) (+ code 26))
+ (t code)))
+ (cond
+ ((and (>= ascii-code 65) (<= ascii-code 90)) (rotate ascii-code 65))
+ ((and (>= ascii-code 97) (<= ascii-code 122)) (rotate ascii-code 97))
+ (t ascii-code)))
+ (list->string (mapcar integer->char (mapcar encode (mapcar char->integer (string->list text))))))
+
+(defun caesar-decode (text key)
+ (caesar-encode text (- 26 key)))
diff --git a/Task/Caesar-cipher/XLISP/caesar-cipher-2.xlisp b/Task/Caesar-cipher/XLISP/caesar-cipher-2.xlisp
new file mode 100644
index 0000000000..7fd3af68d1
--- /dev/null
+++ b/Task/Caesar-cipher/XLISP/caesar-cipher-2.xlisp
@@ -0,0 +1,9 @@
+[1] (define caesar-test (caesar-encode "CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry 'Caesar!' Speak; Caesar is turn'd to hear." 14))
+
+CAESAR-TEST
+[2] caesar-test
+
+"QOSGOF: Kvc wg wh wb hvs dfsgg hvoh qozzg cb as? W vsof o hcbuis, gvfwzzsf hvob ozz hvs aigwq, Qfm 'Qosgof!' Gdsoy; Qosgof wg hifb'r hc vsof."
+[3] (caesar-decode caesar-test 14)
+
+"CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry 'Caesar!' Speak; Caesar is turn'd to hear."
diff --git a/Task/Calendar---for-REAL-programmers/FreeBASIC/calendar---for-real-programmers.freebasic b/Task/Calendar---for-REAL-programmers/FreeBASIC/calendar---for-real-programmers.freebasic
new file mode 100644
index 0000000000..c3274505cf
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/FreeBASIC/calendar---for-real-programmers.freebasic
@@ -0,0 +1,97 @@
+' VERSION 16-03-2016
+' COMPILE WITH: FBC -S CONSOLE
+
+' TRUE/FALSE ARE BUILT-IN CONSTANTS SINCE FREEBASIC 1.04
+' BUT WE HAVE TO DEFINE THEM FOR OLDER VERSIONS.
+#IFNDEF TRUE
+ #DEFINE FALSE 0
+ #DEFINE TRUE NOT FALSE
+#ENDIF
+
+FUNCTION WD(M AS INTEGER, D AS INTEGER, Y AS INTEGER) AS INTEGER
+ ' ZELLERISH
+ ' 0 = SUNDAY, 1 = MONDAY, 2 = TUESDAY, 3 = WEDNESDAY
+ ' 4 = THURSDAY, 5 = FRIDAY, 6 = SATURDAY
+
+ IF M < 3 THEN ' IF M = 1 OR M = 2 THEN
+ M += 12
+ Y -= 1
+ END IF
+ RETURN (Y + (Y \ 4) - (Y \ 100) + (Y \ 400) + D + ((153 * M + 8) \ 5)) MOD 7
+END FUNCTION
+
+FUNCTION LEAPYEAR(Y AS INTEGER) AS INTEGER
+
+ IF (Y MOD 4) <> 0 THEN RETURN FALSE
+ IF (Y MOD 100) = 0 ANDALSO (Y MOD 400) <> 0 THEN RETURN FALSE
+ RETURN TRUE
+END FUNCTION
+
+' ------=< MAIN >=------
+' HARD CODED FOR 132 CHARACTERS PER LINE
+
+DIM AS STRING WDN = "MO TU WE TH FR SA SU" ' WEEKDAY NAMES
+DIM AS STRING MO(1 TO 12) => {"JANUARY", "FEBRUARY", "MARCH", "APRIL", _
+ "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", _
+ "OCTOBER", "NOVEMBER", "DECEMBER"}
+DIM AS STRING TMP1, TMP2, D(1 TO 12)
+
+DIM AS UINTEGER ML(1 TO 12) => {31,28,31,30,31,30,31,31,30,31,30,31}
+DIM AS UINTEGER I, I1, J, K, Y = 1969
+
+'SCREENRES 1080,600,8
+
+IF LEAPYEAR(Y) = TRUE THEN ML(2) = 29
+
+TMP1 = ""
+FOR I = 1 TO 31
+ TMP1 = TMP1 + RIGHT((" " + STR(I)), 3)
+NEXT I
+
+
+FOR I = 1 TO 12
+ TMP2 = ""
+ J = WD(I,1, Y)
+ IF J = 0 THEN J = 7
+ J = J - 1
+ TMP2 = SPACE(J * 3) + LEFT(TMP1, ML(I) * 3) + SPACE(21)
+ D(I) = TMP2
+NEXT I
+
+PRINT
+TMP1 = "INSERT YOUR SNOOPY PICTURE HERE"
+PRINT SPACE((132 - LEN(TMP1)) \ 2); TMP1
+PRINT
+TMP1 = STR(Y)
+PRINT SPACE((132 - LEN(TMP1)) \ 2); TMP1
+PRINT
+
+' 6 MONTH ON A ROW
+TMP2 = " "
+FOR I = 1 TO 6
+ TMP2 = TMP2 + WDN
+ IF I < 6 THEN TMP2 = TMP2 + " "
+NEXT I
+
+FOR I = 1 TO 12 STEP 6
+ TMP1 = ""
+ FOR J = I TO I + 4
+ TMP1 = TMP1 + LEFT(SPACE((22 - LEN(MO(J))) \ 2) + MO(J) + SPACE(11), 22)
+ NEXT J
+ TMP1 = TMP1 + SPACE((22 - LEN(MO(I + 5))) \ 2) + MO(I + 5)
+ PRINT TMP1
+ PRINT TMP2
+ FOR J = 1 TO 85 STEP 21
+ FOR K = I TO I + 4
+ PRINT MID(D(K), J ,21); " ";
+ NEXT K
+ PRINT MID(D(I + 5), J ,21)
+ NEXT J
+ PRINT
+NEXT I
+
+' EMPTY KEYBOARD BUFFER
+WHILE INKEY <> "" : WEND
+PRINT : PRINT "HIT ANY KEY TO END PROGRAM"
+SLEEP
+END
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-1.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-1.phix
new file mode 100644
index 0000000000..da67b56dcb
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-1.phix
@@ -0,0 +1 @@
+return repeat(' ',left)&s&repeat(' ',right)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-2.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-2.phix
new file mode 100644
index 0000000000..295c0ec9b1
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-2.phix
@@ -0,0 +1 @@
+return repeat(' ',left)&upper(s)&repeat(' ',right)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-3.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-3.phix
new file mode 100644
index 0000000000..eceb689391
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-3.phix
@@ -0,0 +1 @@
+initialSymEntry("integer", S_Type,"TI",opInt, E_none) -- #01 / 0b0001 integer
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-4.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-4.phix
new file mode 100644
index 0000000000..ded00ddce7
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-4.phix
@@ -0,0 +1 @@
+Alias("INTEGER",symlimit)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-5.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-5.phix
new file mode 100644
index 0000000000..0ccfe7de01
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-5.phix
@@ -0,0 +1,4 @@
+procedure tt_stringA(sequence text, integer alias)
+ tt_string(text,-2)
+ tt[pcurr] = alias
+end procedure
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-6.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-6.phix
new file mode 100644
index 0000000000..dfa2785c51
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-6.phix
@@ -0,0 +1 @@
+global constant T_include = 596 tt_stringF("include",T_include)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-7.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-7.phix
new file mode 100644
index 0000000000..094c74dc41
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-7.phix
@@ -0,0 +1 @@
+tt_stringA("INCLUDE",T_include)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-8.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-8.phix
new file mode 100644
index 0000000000..0f05908769
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-8.phix
@@ -0,0 +1 @@
+Ch = find(Ch,escchar)
diff --git a/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-9.phix b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-9.phix
new file mode 100644
index 0000000000..144f9bf053
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Phix/calendar---for-real-programmers-9.phix
@@ -0,0 +1 @@
+Ch = find(lower(Ch),escchar)
diff --git a/Task/Calendar---for-REAL-programmers/Sidef/calendar---for-real-programmers.sidef b/Task/Calendar---for-REAL-programmers/Sidef/calendar---for-real-programmers.sidef
new file mode 100644
index 0000000000..b2dbb5ef12
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/Sidef/calendar---for-real-programmers.sidef
@@ -0,0 +1,59 @@
+-> DT { ('DATE'.("\LWC") + 'TIME'.("\LWC")).("\LREQUIRE") }
+
+-> MONTHS_PER_COL { 6 }
+-> WEEK_DAY_NAMES { }
+-> MONTH_NAMES { }
+
+-> FMT_MONTH (YEAR, MONTH, STR="", WEEK_DAY=0) {
+ STR = "%11\LS\E%9\LS\E\12".("\LSPRINTF")(MONTH_NAMES()[MONTH-1],'')
+ STR += (WEEK_DAY_NAMES().("\LJOIN")(' ') + "\12")
+
+ -> DATE { DT().("\LNEW")("\LYEAR" => YEAR, "\LMONTH" => MONTH) }
+
+ WEEK_DAY = DATE().("\LDAY_OF_WEEK")
+ STR += ([" "] * WEEK_DAY-1 -> ("\LJOIN")(" "))
+
+ -> LAST_DAY {
+ DT().("\LLAST_DAY_OF_MONTH")(
+ "\LYEAR" => YEAR, "\LMONTH" => MONTH
+ ).("\LDAY")
+ }
+
+ (DATE().("\LDAY") .. LAST_DAY()).("\LEACH")({ |DAY|
+ (WEEK_DAY ~~ (2..7)) && (STR += " ")
+
+ (WEEK_DAY == 8) && (
+ STR += "\12"
+ WEEK_DAY = 1
+ )
+ STR += ("%2\LD" % DAY)
+ ++WEEK_DAY
+ })
+ (WEEK_DAY < 8) && (STR += " ")
+ STR += ([" "] * 8-WEEK_DAY -> ("\LJOIN")(" "))
+ STR += "\12"
+}
+
+-> FMT_YEAR (YEAR, STR="", MONTH_STRS=[]) {
+ MONTH_STRS = 12.("\LOF")({|I| FMT_MONTH(YEAR, I).("\LLINES") })
+
+ STR += (' '*(MONTHS_PER_COL()*10 + 2) + YEAR + "\12")
+ (0..11 -> ("\LBY")(MONTHS_PER_COL())).("\LEACH")({ |MONTH|
+ MONTH_STRS[MONTH] && ->() {
+ { |I|
+ MONTH_STRS[MONTH + I - 1] && (
+ STR += MONTH_STRS[MONTH + I - 1].("\LSHIFT")
+ STR += ' '*2
+ )
+ } * MONTHS_PER_COL()
+
+ STR += "\12"
+ MONTH_STRS[MONTH] && __FUNC__()
+ }()
+ STR += "\12"
+ })
+
+ STR
+}
+
+FMT_YEAR(ARGV ? ARGV[0].("\LTO_I") : 1969).("\LPRINT")
diff --git a/Task/Calendar---for-REAL-programmers/XLISP/calendar---for-real-programmers.xlisp b/Task/Calendar---for-REAL-programmers/XLISP/calendar---for-real-programmers.xlisp
new file mode 100644
index 0000000000..9e9c64da31
--- /dev/null
+++ b/Task/Calendar---for-REAL-programmers/XLISP/calendar---for-real-programmers.xlisp
@@ -0,0 +1,36 @@
+(SETQ YR 1969)
+(SETQ M #("JANUARY" "FEBRUARY" "MARCH" "APRIL" "MAY" "JUNE" "JULY" "AUGUST" "SEPTEMBER" "OCTOBER" "NOVEMBER" "DECEMBER"))
+(SETQ ML #(31 28 31 30 31 30 31 31 30 31 30 31))
+(SETQ WD #("SU" "MO" "TU" "WE" "TH" "FR" "SA"))
+(IF (AND (= (REM YR 4) 0) (OR (/= (REM YR 100) 0) (= (REM YR 400) 0))) (VECTOR-SET! ML 1 29))
+(SETQ D (REM (+ 1 (+ (* 5 (REM (- YR 1) 4)) (* 4 (REM (- YR 1) 100)) (* 6 (REM (- YR 1) 400)))) 7))
+(TERPRI)
+(DO ((I 0 (+ I 1))) ((> I 60))
+(PRINC " "))
+(PRINC "SNOOPY CALENDAR ")
+(PRINC YR)
+(TERPRI)
+(DO ((I 0 (+ I 1))) ((> I 11))
+(TERPRI)
+(DO ((J 0 (+ J 1))) ((> J 65))
+(PRINC " "))
+(PRINC (VECTOR-REF M I))
+(TERPRI)
+(PRINC " ")
+(DO ((J 0 (+ J 1))) ((> J 6))
+(DO ((K 0 (+ K 1))) ((> K 14))
+(PRINC " "))
+(PRINC (VECTOR-REF WD J))
+(PRINC " "))
+(TERPRI)
+(DO ((J 0 (+ J 1))) ((> J 6))
+(IF (< J D) (DO ((K 0 (+ K 1))) ((> K 18)) (PRINC " "))))
+(DO ((J 1 (+ J 1))) ((> J (VECTOR-REF ML I)))
+(PRINC " ")
+(IF (< J 10) (PRINC " "))
+(DO ((K 0 (+ K 1))) ((> K 14))
+(PRINC " "))
+(PRINC J)
+(SETQ D (+ D 1))
+(IF (> D 6) (TERPRI))
+(IF (> D 6) (SETQ D 0))))
diff --git a/Task/Calendar/FreeBASIC/calendar.freebasic b/Task/Calendar/FreeBASIC/calendar.freebasic
new file mode 100644
index 0000000000..53fd7963d0
--- /dev/null
+++ b/Task/Calendar/FreeBASIC/calendar.freebasic
@@ -0,0 +1,125 @@
+' version 17-02-2016
+' compile with: fbc -s console
+
+' TRUE/FALSE are built-in constants since FreeBASIC 1.04
+' For older versions they have to be defined.
+#Ifndef TRUE
+ #Define FALSE 0
+ #Define TRUE Not FALSE
+#EndIf
+
+Function WD(m As Integer, d As Integer, y As Integer) As Integer
+ ' Zellerish
+ ' 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday
+ ' 4 = Thursday, 5 = Friday, 6 = Saturday
+
+ If m < 3 Then ' if m = 1 or m = 2 then
+ m += 12
+ y -= 1
+ End If
+ Return (y + (y \ 4) - (y \ 100) + (y \ 400) + d + ((153 * m + 8) \ 5)) Mod 7
+End Function
+
+Function LEAPYEAR(y As Integer) As Integer
+ If (y Mod 4) <> 0 Then Return FALSE
+ If (y Mod 100) = 0 AndAlso (y Mod 400) <> 0 Then Return FALSE
+ Return TRUE
+End Function
+
+' ------=< main >=------
+
+Dim As String wdn = "Mo Tu We Th Fr Sa Su" ' weekday names
+Dim As String mo(1 To 12) => {"January", "February", "March", "April", _
+ "May", "June", "July", "August", "September", _
+ "October", "November", "December"}
+Dim As String tmp1, tmp2, d(1 To 12)
+
+Dim As UInteger ml(1 To 12) => {31,28,31,30,31,30,31,31,30,31,30,31}
+Dim As UInteger i, i1, j, k, y = 1969
+Dim As UInteger m_row = 6
+
+Do
+ While InKey <> "" : Wend ' clear keyboard buffer
+ Print : Print " For wich year do want a calendar"
+ Print " Year must be greater then 1752"
+ Input " Input year (enter = 1969)";tmp1
+ If tmp1 = "" Then Exit Do
+ i = Val(tmp1)
+ If i < 1752 Then
+ Print
+ Print " Can only make a calendar for a year after 1752"
+ Beep : Sleep 5000, 1 : Print
+ Else
+ y = i : Exit Do
+ End If
+Loop
+
+Cls
+Do
+ While InKey <> "" : Wend ' clear keyboard buffer
+ Print : Print " Make device choice"
+ Print " 132 characters Line printer, 6x2 months (Enter or 1)"
+ Print " 80x43 display, 3x4 months (2)"
+ Do
+ tmp1 = InKey
+ If tmp1 = Chr(13) Or tmp1 = "1" Then Exit Do, Do
+ If tmp1 = "2" Then
+ m_row = 3
+ Exit Do, Do
+ End If
+ Loop Until tmp1 <> ""
+ Print : Print " Enter, 1 or 2 only"
+ Beep : Sleep 5000, 1 : Print
+Loop
+Cls
+
+Dim As UInteger char_line = m_row * 22 - 1
+If LEAPYEAR(y) = TRUE Then ml(2) = 29
+
+tmp1 = ""
+For i = 1 To 31
+ tmp1 = tmp1 + Right((" " + Str(i)), 3)
+Next
+
+For i = 1 To 12
+ tmp2 = ""
+ j = WD(i,1, y)
+ If j = 0 Then j = 7
+ j = j - 1
+ tmp2 = Space(j * 3) + Left(tmp1, ml(i) * 3) + Space(21)
+ d(i) = tmp2
+Next
+
+Print
+tmp1 = Str(y)
+Print Space((char_line + (char_line And 1) - Len(tmp1)) \ 2); tmp1
+Print
+
+tmp2 = " " ' make the weekday names line
+For i = 1 To m_row
+ tmp2 = tmp2 + wdn
+ If i < m_row Then tmp2 = tmp2 + " "
+Next
+
+For i = 1 To 12 Step m_row
+ tmp1 = ""
+ For j = i To i + m_row -2 ' make the month names line
+ tmp1 = tmp1 + Left(Space((22 - Len(mo(j))) \ 2) + mo(j) + Space(21), 22)
+ Next
+ tmp1 = tmp1 + Space((22 - Len(mo(i + m_row -1))) \ 2) + mo(i + m_row -1)
+ Print tmp1
+ Print tmp2
+ For j = 1 To 85 Step 21
+ For k = i To i + m_row -2
+ Print Mid(d(k), j ,21); " ";
+ Next
+ Print Mid(d(i + m_row -1), j ,21)
+ Next
+ Print
+Next
+
+' empty keyboard buffer
+While InKey <> "" : Wend
+'Print : Print "hit any key to end program
+Sleep
+End
diff --git a/Task/Calendar/FutureBasic/calendar.futurebasic b/Task/Calendar/FutureBasic/calendar.futurebasic
new file mode 100644
index 0000000000..d5160a7925
--- /dev/null
+++ b/Task/Calendar/FutureBasic/calendar.futurebasic
@@ -0,0 +1,10 @@
+include "ConsoleWindow"
+
+dim as Str255 a
+
+open "UNIX", 1,"cal 1969"
+ do
+ line input #1, a
+ print a
+ until eof(1)
+close 1
diff --git a/Task/Calendar/Lingo/calendar-1.lingo b/Task/Calendar/Lingo/calendar-1.lingo
new file mode 100644
index 0000000000..05158158ac
--- /dev/null
+++ b/Task/Calendar/Lingo/calendar-1.lingo
@@ -0,0 +1,57 @@
+----------------------------------------
+-- @desc Class "Calendar"
+-- @file parent script "Calendar"
+----------------------------------------
+property _months
+property _weekdayStr
+property _refDateObj
+property _year
+property _calStr
+
+on new (me)
+ me._months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
+ me._weekdayStr = "Mo Tu We Th Fr Sa Su"
+ me._refDateObj = date(1905,1,2)
+ return me
+end
+
+on make (me, year)
+ me._year = year
+ me._calStr = ""
+ -- prefill cal string with spaces
+ emptyLine = bytearray(68,32).readRawString(68)&RETURN
+ repeat with i = 1 to 38
+ put emptyLine after _calStr
+ end repeat
+ me._write (string(year), 32, 1)
+ repeat with i = 1 to 12
+ me._writeMonth(i)
+ end repeat
+ return me._calStr
+end
+
+on _writeMonth (me, monthNum)
+ xOffset = (monthNum-1) mod 3 * 24
+ yOffset = (monthNum-1)/3 * 9 + 2
+ pre = (20 - me._months[monthNum].length)/2
+ me._write(me._months[monthNum], 1+xOffset+pre, 1+yOffset)
+ me._write(me._weekdayStr, 1+xOffset, 2+yOffset)
+ y = 3
+ x = ((date(me._year, monthNum, 1) - me._refDateObj) mod 7)+1
+ repeat with i = 1 to 31
+ if date(me._year, monthNum, i).month<>monthNum then exit repeat
+ dayStr = string(i)
+ if i<10 then put " " before dayStr
+ me._write(dayStr, x*3-2+xOffset, y+yOffset)
+ if x=7 then
+ y = y+1
+ x = 1
+ else
+ x = x+1
+ end if
+ end repeat
+end
+
+on _write (me, str, x, y)
+ put str into char x to x+str.length-1 of line y of _calStr
+end
diff --git a/Task/Calendar/Lingo/calendar-2.lingo b/Task/Calendar/Lingo/calendar-2.lingo
new file mode 100644
index 0000000000..68983c6c33
--- /dev/null
+++ b/Task/Calendar/Lingo/calendar-2.lingo
@@ -0,0 +1,3 @@
+calObj = script("Calendar").new()
+calStr = calObj.make(1969)
+put calStr
diff --git a/Task/Calendar/Phix/calendar.phix b/Task/Calendar/Phix/calendar.phix
new file mode 100644
index 0000000000..85eb2e4b72
--- /dev/null
+++ b/Task/Calendar/Phix/calendar.phix
@@ -0,0 +1,66 @@
+include builtins\timedate.e
+
+function centre(string s, integer width)
+integer pad = width-length(s),
+ left = floor(pad/2),
+ right = pad-left
+ return repeat(' ',left)&s&repeat(' ',right)
+end function
+
+function one_month(integer year, integer month)
+integer dow = day_of_week(year,month,1)
+sequence ldm = adjust_timedate(iff(month=12?{year+1,1,1,0,0,0,0,0}
+ :{year,month+1,1,0,0,0,0,0}),
+ timedelta(days:=-1))
+sequence res = {centre(format_timedate(ldm,"Mmmm"),20),"Su Mo Tu We Th Fr Sa"}
+integer lastday = ldm[DT_DAY]
+string line = repeat(' ',20)
+integer p = dow*3-2
+ for d=1 to lastday do
+ line[p..p+1] = sprintf("%2d",d)
+ p += 3
+ if dow=7 or d=lastday then
+ res = append(res,line)
+ line = repeat(' ',20)
+ dow = 1
+ p = 1
+ else
+ dow += 1
+ end if
+ end for
+ return res
+end function
+
+procedure print_calendar(integer year, integer width)
+sequence months = repeat(0,12)
+integer wide = floor((width+2)/22)
+ printf(1,centre("[Spot Reserved For Snoopy]",width)&"\n")
+ printf(1,centre(sprintf("%d",year),width)&"\n")
+ for month=1 to 12 do
+ months[month] = one_month(year,month)
+ end for
+ for month=1 to 12 by wide do
+ for k=1 to 9 do -- (more than enough)
+ integer any = 0
+ string line = "", this
+ for j=0 to wide-1 do
+ if length(line) then
+ line &= " "
+ end if
+ if k>length(months[month+j]) then
+ line &= repeat(' ',20)
+ else
+ line &= months[month+j][k]
+ any = 1
+ end if
+ end for
+ if any=0 then exit end if
+ printf(1,centre(line,width)&"\n")
+ end for
+ end for
+end procedure
+
+print_calendar(1969,80)
+printf(1,join(repeat("1234567890",8),"")&"\n")
+print_calendar(1969,132)
+printf(1,join(repeat("1234567890",13),"")&"12\n")
diff --git a/Task/Calendar/Sidef/calendar.sidef b/Task/Calendar/Sidef/calendar.sidef
new file mode 100644
index 0000000000..1445acdb80
--- /dev/null
+++ b/Task/Calendar/Sidef/calendar.sidef
@@ -0,0 +1,52 @@
+require('DateTime')
+
+define months_per_col = 3
+define week_day_names =
+define month_names =
+
+func fmt_month (year, month) {
+ var str = sprintf("%-20s\n", month_names[month-1])
+ str += week_day_names.join(' ')+"\n"
+
+ var dt = %s'DateTime'
+ var date = dt.new(year => year, month => month)
+ var week_day = date.day_of_week
+ str += ([" "] * week_day-1 -> join(" "))
+
+ var last_day = dt.last_day_of_month(year => year, month => month).day
+ for day in range(date.day, last_day) {
+ date = dt.new(year => year, month => month, day => day)
+
+ str += " " if (week_day ~~ range(2,7))
+ if (week_day == 8) {
+ str += "\n"
+ week_day = 1
+ }
+ str += sprintf("%2d", day)
+ ++week_day
+ }
+ str += " " if (week_day < 8)
+ str += ([" "] * 8-week_day -> join(" "))
+ str += "\n"
+}
+
+func fmt_year (year) {
+ var month_strs = 12.of { |i| fmt_month(year, i).lines }
+
+ var str = (' '*30 + year + "\n")
+ for month in range(0, 11, months_per_col) {
+ while (month_strs[month]) {
+ months_per_col.times { |i|
+ month_strs[month + i - 1] || next
+ str += month_strs[month + i - 1].shift
+ str += ' '*3
+ }
+ str += "\n"
+ }
+ str += "\n"
+ }
+
+ return str
+}
+
+print fmt_year(ARGV.is_empty ? 1969 : ARGV[0].to_i)
diff --git a/Task/Calendar/XLISP/calendar.xlisp b/Task/Calendar/XLISP/calendar.xlisp
new file mode 100644
index 0000000000..20b13d633b
--- /dev/null
+++ b/Task/Calendar/XLISP/calendar.xlisp
@@ -0,0 +1,58 @@
+(defun calendar (year)
+ (define months-list '(("JANUARY" 31) ("FEBRUARY" 28) ("MARCH" 31) ("APRIL" 30) ("MAY" 31) ("JUNE" 30) ("JULY" 31) ("AUGUST" 31) ("SEPTEMBER" 30) ("OCTOBER" 31) ("NOVEMBER" 30) ("DECEMBER" 31)))
+ (define days #(" Sunday " "Monday " "Tuesday " "Wednesday " "Thursday " "Friday " "Saturday"))
+ (defun gauss-algorithm (a)
+ (rem (+ 1 (+ (* 5 (rem (- a 1) 4)) (* 4 (rem (- a 1) 100)) (* 6 (rem (- a 1) 400)))) 7))
+ (defun range (start end)
+ (if (<= start end)
+ (cons start (range (+ start 1) end))))
+ (defun string-repeat (s n)
+ (if (= n 0)
+ ""
+ (string-append s (string-repeat s (- n 1)))))
+ (defun print-month (number-of-days start-day)
+ (defun print-days (day day-of-week end-day)
+ (if (= day-of-week 7)
+ (begin
+ (newline)
+ (define day-of-week 0)))
+ (display (string-repeat " " 8))
+ (if (= day-of-week 0)
+ (display (string-repeat " " 6)))
+ (if (< day 10)
+ (display " "))
+ (display day)
+ (display (string-repeat " " 8))
+ (if (= day end-day)
+ (begin
+ (fresh-line)
+ (+ day-of-week 1))
+ (print-days (+ day 1) (+ day-of-week 1) end-day)))
+ (mapcar (lambda (n) (display (vector-ref days n))) (range 0 6))
+ (newline)
+ (display (string-repeat (string-repeat " " 18) start-day))
+ (print-days 1 start-day number-of-days))
+ (defun leap-yearp (y)
+ (and (= (mod year 4) 0) (or (/= (mod year 100) 0) (= (mod year 400) 0))))
+ (define months (make-table))
+ (mapcar (lambda (month) (table-set! months (car month) (cadr month))) months-list)
+ (if (leap-yearp year)
+ (table-set! months "FEBRUARY" 29))
+ (defun print-calendar (calendar-months weekday)
+ (newline)
+ (newline)
+ (display (string-repeat " " 60))
+ (display (caar calendar-months))
+ (newline)
+ (define next-month-starts (print-month (table-ref months (caar calendar-months)) weekday))
+ (if (cdr calendar-months)
+ (print-calendar (cdr calendar-months) next-month-starts)))
+ (display (string-repeat " " 60))
+ (display "******** SNOOPY CALENDAR ")
+ (display year)
+ (display " ********")
+ (newline)
+ (newline)
+ (print-calendar months-list (gauss-algorithm year)))
+
+(calendar 1969)
diff --git a/Task/Call-a-foreign-language-function/8th/call-a-foreign-language-function.8th b/Task/Call-a-foreign-language-function/8th/call-a-foreign-language-function.8th
new file mode 100644
index 0000000000..9a8f38bc9e
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/8th/call-a-foreign-language-function.8th
@@ -0,0 +1,8 @@
+\ tell 8th what the function expects:
+"ZZ" "strdup" func: strdup
+"VZ" "free" func: free
+\ call the external funcs
+"abc" dup \ now we have two strings "abc" on the stack
+strdup .s cr \ after strdup, you'll have the new (but duplicate) string on the stack
+\ the ".s" will show both strings and you can see they are different items on the stack
+free \ let the c library free the string
diff --git a/Task/Call-a-foreign-language-function/FreeBASIC/call-a-foreign-language-function.freebasic b/Task/Call-a-foreign-language-function/FreeBASIC/call-a-foreign-language-function.freebasic
new file mode 100644
index 0000000000..a9c8c4986c
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/FreeBASIC/call-a-foreign-language-function.freebasic
@@ -0,0 +1,20 @@
+' FB 1.05.0 Win64
+
+'Using StrDup function in Shlwapi.dll
+Dim As Any Ptr library = DyLibLoad("Shlwapi")
+Dim strdup As Function (ByVal As Const ZString Ptr) As ZString Ptr
+strdup = DyLibSymbol(library, "StrDupA")
+
+'Using LocalFree function in kernel32.dll
+Dim As Any Ptr library2 = DyLibLoad("kernel32")
+Dim localfree As Function (ByVal As Any Ptr) As Any Ptr
+localfree = DyLibSymbol(library2, "LocalFree")
+
+Dim As ZString * 10 z = "duplicate" '' 10 characters including final zero byte
+Dim As Zstring Ptr pcz = strdup(@z) '' pointer to the duplicate string
+Print *pcz '' print duplicate string by dereferencing pointer
+localfree(pcz) '' free the memory which StrDup allocated internally
+pcz = 0 '' set pointer to null
+DyLibFree(library) '' unload first dll
+DyLibFree(library2) '' unload second fll
+End
diff --git a/Task/Call-a-foreign-language-function/Luck/call-a-foreign-language-function.luck b/Task/Call-a-foreign-language-function/Luck/call-a-foreign-language-function.luck
new file mode 100644
index 0000000000..6f6c65e244
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Luck/call-a-foreign-language-function.luck
@@ -0,0 +1,7 @@
+import "stdio.h";;
+import "string.h";;
+
+let s1:string = "Hello World!";;
+let s2:char* = strdup(cstring(s1));;
+puts(s2);;
+free(s2 as void*)
diff --git a/Task/Call-a-foreign-language-function/Nim/call-a-foreign-language-function.nim b/Task/Call-a-foreign-language-function/Nim/call-a-foreign-language-function.nim
new file mode 100644
index 0000000000..a604fff047
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Nim/call-a-foreign-language-function.nim
@@ -0,0 +1,8 @@
+proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
+echo strcmp("abc", "def")
+echo strcmp("hello", "hello")
+
+proc printf(formatstr: cstring) {.header: "", varargs.}
+
+var x = "foo"
+printf("Hello %d %s!\n", 12, x)
diff --git a/Task/Call-a-foreign-language-function/Phix/call-a-foreign-language-function.phix b/Task/Call-a-foreign-language-function/Phix/call-a-foreign-language-function.phix
new file mode 100644
index 0000000000..17df5c3945
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Phix/call-a-foreign-language-function.phix
@@ -0,0 +1,9 @@
+constant shlwapi = open_dll("shlwapi.dll")
+constant xStrDup = define_c_func(shlwapi,"StrDupA",{C_PTR},C_PTR)
+constant kernel32 = open_dll("kernel32.dll")
+constant xLocalFree = define_c_func(kernel32,"LocalFree",{C_PTR},C_PTR)
+constant HelloWorld = "Hello World!"
+
+atom pMem = c_func(xStrDup,{HelloWorld})
+?peek_string(pMem)
+if c_func(xLocalFree,{pMem})!=NULL then ?9/0 end if
diff --git a/Task/Call-a-foreign-language-function/Swift/call-a-foreign-language-function.swift b/Task/Call-a-foreign-language-function/Swift/call-a-foreign-language-function.swift
new file mode 100644
index 0000000000..0149429857
--- /dev/null
+++ b/Task/Call-a-foreign-language-function/Swift/call-a-foreign-language-function.swift
@@ -0,0 +1,5 @@
+import Foundation
+
+let hello = "Hello, World!"
+let fromC = strdup(hello)
+let backToSwiftString = String.fromCString(fromC)
diff --git a/Task/Call-a-function-in-a-shared-library/FreeBASIC/call-a-function-in-a-shared-library.freebasic b/Task/Call-a-function-in-a-shared-library/FreeBASIC/call-a-function-in-a-shared-library.freebasic
new file mode 100644
index 0000000000..4bdc97d568
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/FreeBASIC/call-a-function-in-a-shared-library.freebasic
@@ -0,0 +1,23 @@
+' FB 1.05.0 Win64
+
+' Attempt to call Beep function in Win32 API
+Dim As Any Ptr library = DyLibLoad("kernel32.dll") '' load dll
+
+If library = 0 Then
+ Print "Unable to load kernel32.dll - calling built in Beep function instead"
+ Beep : Beep : Beep
+Else
+ Dim beep_ As Function (ByVal As ULong, ByVal As ULong) As Long '' declare function pointer
+ beep_ = DyLibSymbol(library, "Beep")
+ If beep_ = 0 Then
+ Print "Unable to retrieve Beep function from kernel32.dll - calling built in Beep function instead"
+ Beep : Beep : Beep
+ Else
+ For i As Integer = 1 To 3 : beep_(1000, 250) : Next
+ End If
+ DyLibFree(library) '' unload library
+End If
+
+Print
+Print "Press any key to quit"
+Sleep
diff --git a/Task/Call-a-function-in-a-shared-library/Lingo/call-a-function-in-a-shared-library.lingo b/Task/Call-a-function-in-a-shared-library/Lingo/call-a-function-in-a-shared-library.lingo
new file mode 100644
index 0000000000..b0b972ce1b
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Lingo/call-a-function-in-a-shared-library.lingo
@@ -0,0 +1,18 @@
+-- calculate CRC-32 checksum
+str = "The quick brown fox jumps over the lazy dog"
+
+-- is shared library (in Director called "Xtra", a DLL in windows, a sharedLib in
+-- OS X) available?
+if ilk(xtra("Crypto"))=#xtra then
+
+ -- use shared library
+ cx = xtra("Crypto").new()
+ crc = cx.cx_crc32_string(str)
+
+else
+
+ -- otherwise use (slower) pure lingo solution
+ crcObj = script("CRC").new()
+ crc = crcObj.crc32(str)
+
+end if
diff --git a/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-1.nim b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-1.nim
new file mode 100644
index 0000000000..5bbcde8b3b
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-1.nim
@@ -0,0 +1,5 @@
+proc openimage(s: cstring): cint {.importc, dynlib: "./fakeimglib.so".}
+
+echo openimage("foo")
+echo openimage("bar")
+echo openimage("baz")
diff --git a/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-2.nim b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-2.nim
new file mode 100644
index 0000000000..468a48fc06
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-2.nim
@@ -0,0 +1,8 @@
+#include
+/* gcc -shared -nostartfiles fakeimglib.c -o fakeimglib.so */
+int openimage(const char *s)
+{
+ static int handle = 100;
+ fprintf(stderr, "opening %s\n", s);
+ return handle++;
+}
diff --git a/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-3.nim b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-3.nim
new file mode 100644
index 0000000000..0b5fb57256
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-3.nim
@@ -0,0 +1,5 @@
+proc openimage(s: string): int {.importc, dynlib: "./libfakeimg.so".}
+
+echo openimage("foo")
+echo openimage("bar")
+echo openimage("baz")
diff --git a/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-4.nim b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-4.nim
new file mode 100644
index 0000000000..e0b78e5195
--- /dev/null
+++ b/Task/Call-a-function-in-a-shared-library/Nim/call-a-function-in-a-shared-library-4.nim
@@ -0,0 +1,7 @@
+# nim c --app:lib fakeimg.nim
+var handle = 100
+
+proc openimage*(s: string): int {.exportc, dynlib.} =
+ stderr.writeln "opening ", s
+ result = handle
+ inc(handle)
diff --git a/Task/Call-a-function/AntLang/call-a-function-1.antlang b/Task/Call-a-function/AntLang/call-a-function-1.antlang
new file mode 100644
index 0000000000..c3fbe9424f
--- /dev/null
+++ b/Task/Call-a-function/AntLang/call-a-function-1.antlang
@@ -0,0 +1 @@
+2*2+9
diff --git a/Task/Call-a-function/AntLang/call-a-function-2.antlang b/Task/Call-a-function/AntLang/call-a-function-2.antlang
new file mode 100644
index 0000000000..6aa8c2241c
--- /dev/null
+++ b/Task/Call-a-function/AntLang/call-a-function-2.antlang
@@ -0,0 +1,3 @@
+*[2;+[2;9]]
+echo["Hello!"]
+time[]
diff --git a/Task/Call-a-function/Axe/call-a-function-1.axe b/Task/Call-a-function/Axe/call-a-function-1.axe
new file mode 100644
index 0000000000..ad2786815b
--- /dev/null
+++ b/Task/Call-a-function/Axe/call-a-function-1.axe
@@ -0,0 +1,2 @@
+NOARG()
+ARGS(1,5,42)
diff --git a/Task/Call-a-function/Axe/call-a-function-2.axe b/Task/Call-a-function/Axe/call-a-function-2.axe
new file mode 100644
index 0000000000..d4934ac1cb
--- /dev/null
+++ b/Task/Call-a-function/Axe/call-a-function-2.axe
@@ -0,0 +1,3 @@
+OPARG(1,2,3,4,5,6)
+OPARG(1,2,3)
+OPARG()
diff --git a/Task/Call-a-function/Axe/call-a-function-3.axe b/Task/Call-a-function/Axe/call-a-function-3.axe
new file mode 100644
index 0000000000..2cd6c5cf47
--- /dev/null
+++ b/Task/Call-a-function/Axe/call-a-function-3.axe
@@ -0,0 +1,2 @@
+MATHS(2,4)→A
+Disp GETSTR()
diff --git a/Task/Call-a-function/Axe/call-a-function-4.axe b/Task/Call-a-function/Axe/call-a-function-4.axe
new file mode 100644
index 0000000000..5427f37aab
--- /dev/null
+++ b/Task/Call-a-function/Axe/call-a-function-4.axe
@@ -0,0 +1,2 @@
+USER()
+axeFunc()
diff --git a/Task/Call-a-function/I/call-a-function.i b/Task/Call-a-function/I/call-a-function.i
new file mode 100644
index 0000000000..c8dcf48c77
--- /dev/null
+++ b/Task/Call-a-function/I/call-a-function.i
@@ -0,0 +1,5 @@
+software {
+ var line = read() //Calling a function with no arguments and getting a return value.
+ var t = text(10) //Calling a function with fixed arguments.
+ print(1,2,3,4,5,6,7,8,9,0,line,t) //Calling a variadic function.
+}
diff --git a/Task/Call-a-function/LFE/call-a-function-1.lfe b/Task/Call-a-function/LFE/call-a-function-1.lfe
new file mode 100644
index 0000000000..bb85364f2b
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-1.lfe
@@ -0,0 +1,2 @@
+(defun my-func()
+ (: io format '"I get called with NOTHING!~n"))
diff --git a/Task/Call-a-function/LFE/call-a-function-2.lfe b/Task/Call-a-function/LFE/call-a-function-2.lfe
new file mode 100644
index 0000000000..0b06ae0837
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-2.lfe
@@ -0,0 +1,3 @@
+> (my-func)
+I get called with NOTHING!
+ok
diff --git a/Task/Call-a-function/LFE/call-a-function-3.lfe b/Task/Call-a-function/LFE/call-a-function-3.lfe
new file mode 100644
index 0000000000..07d4bcffa9
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-3.lfe
@@ -0,0 +1,2 @@
+(defun my-func(a b)
+ (: io format '"I got called with ~p and ~p~n" (list a b)))
diff --git a/Task/Call-a-function/LFE/call-a-function-4.lfe b/Task/Call-a-function/LFE/call-a-function-4.lfe
new file mode 100644
index 0000000000..44862f5544
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-4.lfe
@@ -0,0 +1,3 @@
+> (my-func '"bread" '"cheese")
+I got called with "bread" and "cheese"
+ok
diff --git a/Task/Call-a-function/LFE/call-a-function-5.lfe b/Task/Call-a-function/LFE/call-a-function-5.lfe
new file mode 100644
index 0000000000..9dc471411c
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-5.lfe
@@ -0,0 +1,14 @@
+(defmodule args
+ (export all))
+
+(defun my-func ()
+ (my-func () () ()))
+
+(defun my-func (a)
+ (my-func a () ()))
+
+(defun my-func (a b)
+ (my-func a b ()))
+
+(defun my-func (a b c)
+ (: io format '"~p ~p ~p~n" (list a b c)))
diff --git a/Task/Call-a-function/LFE/call-a-function-6.lfe b/Task/Call-a-function/LFE/call-a-function-6.lfe
new file mode 100644
index 0000000000..9bb756728f
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-6.lfe
@@ -0,0 +1,16 @@
+> (slurp '"args.lfe")
+#(ok args)
+> (my-func)
+[] [] []
+ok
+> (my-func '"apple")
+"apple" [] []
+ok
+> (my-func '"apple" '"banana")
+"apple" "banana" []
+ok
+> (my-func '"apple" '"banana" '"cranberry")
+"apple" "banana" "cranberry"
+ok
+> (my-func '"apple" '"banana" '"cranberry" '"bad arg")
+exception error: #(unbound_func #(my-func 4))
diff --git a/Task/Call-a-function/LFE/call-a-function-7.lfe b/Task/Call-a-function/LFE/call-a-function-7.lfe
new file mode 100644
index 0000000000..88f4b9031b
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-7.lfe
@@ -0,0 +1,4 @@
+...
+ (cond ((== count limit) (hit-limit-func arg-1 arg-2))
+ ((/= count limit) (keep-going-func count)))
+ ...
diff --git a/Task/Call-a-function/LFE/call-a-function-8.lfe b/Task/Call-a-function/LFE/call-a-function-8.lfe
new file mode 100644
index 0000000000..b7a4eb1836
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-8.lfe
@@ -0,0 +1,2 @@
+> (>= 0.5 (: math sin 0.5))
+true
diff --git a/Task/Call-a-function/LFE/call-a-function-9.lfe b/Task/Call-a-function/LFE/call-a-function-9.lfe
new file mode 100644
index 0000000000..afa27f6c01
--- /dev/null
+++ b/Task/Call-a-function/LFE/call-a-function-9.lfe
@@ -0,0 +1,2 @@
+(let ((x (: math sin 0.5)))
+ ...)
diff --git a/Task/Call-a-function/Lingo/call-a-function-1.lingo b/Task/Call-a-function/Lingo/call-a-function-1.lingo
new file mode 100644
index 0000000000..90633ef80d
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-1.lingo
@@ -0,0 +1,3 @@
+foo()
+-- or alternatively:
+call(#foo, _movie)
diff --git a/Task/Call-a-function/Lingo/call-a-function-10.lingo b/Task/Call-a-function/Lingo/call-a-function-10.lingo
new file mode 100644
index 0000000000..da3776df1c
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-10.lingo
@@ -0,0 +1,17 @@
+on getAllUserFunctions ()
+ res = []
+ repeat with i = 1 to _movie.castlib.count
+ c = _movie.castlib(i)
+ repeat with j = 1 to c.member.count
+ m = c.member[j]
+ if m.type<>#script then next repeat
+ if m.scripttype=#movie then
+ functions = m.script.handlers()
+ repeat with f in functions
+ res.append(f)
+ end repeat
+ end if
+ end repeat
+ end repeat
+ return res
+end
diff --git a/Task/Call-a-function/Lingo/call-a-function-11.lingo b/Task/Call-a-function/Lingo/call-a-function-11.lingo
new file mode 100644
index 0000000000..8662ba60ff
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-11.lingo
@@ -0,0 +1,2 @@
+put getAllUserFunctions()
+-- [#sum, #double, #getAllUserFunctions]
diff --git a/Task/Call-a-function/Lingo/call-a-function-12.lingo b/Task/Call-a-function/Lingo/call-a-function-12.lingo
new file mode 100644
index 0000000000..4272649770
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-12.lingo
@@ -0,0 +1,6 @@
+on double (someList)
+ cnt = someList.count
+ repeat with i = 1 to cnt
+ someList[i] = someList[i] * 2
+ end repeat
+end
diff --git a/Task/Call-a-function/Lingo/call-a-function-13.lingo b/Task/Call-a-function/Lingo/call-a-function-13.lingo
new file mode 100644
index 0000000000..4c1b346533
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-13.lingo
@@ -0,0 +1,9 @@
+l = [1,2,3]
+double(l)
+put l
+-- [2, 4, 6]
+
+l = [1,2,3]
+double(l.duplicate())
+put l
+-- [1, 2, 3]
diff --git a/Task/Call-a-function/Lingo/call-a-function-2.lingo b/Task/Call-a-function/Lingo/call-a-function-2.lingo
new file mode 100644
index 0000000000..23a37bb11c
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-2.lingo
@@ -0,0 +1,3 @@
+foo(1,2,3)
+-- or alternatively:
+call(#foo, _movie, 1, 2, 3)
diff --git a/Task/Call-a-function/Lingo/call-a-function-3.lingo b/Task/Call-a-function/Lingo/call-a-function-3.lingo
new file mode 100644
index 0000000000..9682b4906d
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-3.lingo
@@ -0,0 +1,4 @@
+on foo (a, b)
+ if voidP(b) then b = 1
+ return a * b
+end
diff --git a/Task/Call-a-function/Lingo/call-a-function-4.lingo b/Task/Call-a-function/Lingo/call-a-function-4.lingo
new file mode 100644
index 0000000000..d2befdcb8d
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-4.lingo
@@ -0,0 +1,4 @@
+put foo(23, 2)
+-- 46
+put foo(23)
+-- 23
diff --git a/Task/Call-a-function/Lingo/call-a-function-5.lingo b/Task/Call-a-function/Lingo/call-a-function-5.lingo
new file mode 100644
index 0000000000..b96bda2ee8
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-5.lingo
@@ -0,0 +1,7 @@
+on sum ()
+ res = 0
+ repeat with i = 1 to the paramCount
+ res = res + param(i)
+ end repeat
+ return res
+end
diff --git a/Task/Call-a-function/Lingo/call-a-function-6.lingo b/Task/Call-a-function/Lingo/call-a-function-6.lingo
new file mode 100644
index 0000000000..a23677e28a
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-6.lingo
@@ -0,0 +1,2 @@
+put sum (1,2,3)
+-- 6
diff --git a/Task/Call-a-function/Lingo/call-a-function-7.lingo b/Task/Call-a-function/Lingo/call-a-function-7.lingo
new file mode 100644
index 0000000000..852715d3b0
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-7.lingo
@@ -0,0 +1,20 @@
+----------------------------------------
+-- One of the five native iterative methods defined in ECMAScript 5
+-- @param {list} tList
+-- @param {symbol} cbFunc
+-- @param {object} [cbObj=_movie]
+-- @return {list}
+----------------------------------------
+on map (tList, cbFunc, cbObj)
+ if voidP(cbObj) then cbObj = _movie
+ res = []
+ cnt = tList.count
+ repeat with i = 1 to cnt
+ res[i] = call(cbFunc, cbObj, tList[i], i, tList)
+ end repeat
+ return res
+end
+
+on doubleInt (n)
+ return n*2
+end
diff --git a/Task/Call-a-function/Lingo/call-a-function-8.lingo b/Task/Call-a-function/Lingo/call-a-function-8.lingo
new file mode 100644
index 0000000000..09694e63d6
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-8.lingo
@@ -0,0 +1,3 @@
+l = [1,2,3]
+put map(l, #doubleInt)
+-- [2, 4, 6]
diff --git a/Task/Call-a-function/Lingo/call-a-function-9.lingo b/Task/Call-a-function/Lingo/call-a-function-9.lingo
new file mode 100644
index 0000000000..e73d956474
--- /dev/null
+++ b/Task/Call-a-function/Lingo/call-a-function-9.lingo
@@ -0,0 +1 @@
+x = foo(1,2)
diff --git a/Task/Call-a-function/Luck/call-a-function.luck b/Task/Call-a-function/Luck/call-a-function.luck
new file mode 100644
index 0000000000..db9a946772
--- /dev/null
+++ b/Task/Call-a-function/Luck/call-a-function.luck
@@ -0,0 +1,43 @@
+/* Calling a function that requires no arguments */
+f();;
+
+/* Calling a function with a fixed number of arguments */
+f(1,2);;
+
+/* Calling a function with optional arguments
+ Note: defining the function is cumbersome but will get easier in future versions. */
+f(1,2,new {default with x=3, y=4});;
+
+/* Calling a function with a variable number of arguments */
+printf("%d %d %d %d":char*,2,3,4,5);;
+
+/* Calling a function with named arguments
+ Note: may get syntax sugar in future versions */
+f(1,2,new {default with x=3, y=4});;
+
+/* Using a function in statement context (what?) */
+f();f();f();;
+
+/* Using a function in first-class context within an expression */
+[1,2,3].map(string);;
+
+/* Obtaining the return value of a function */
+let x:int = f();;
+
+/* Distinguishing built-in functions and user-defined functions */
+/* Builtin function i.e. custom calling convention: */
+(@ binop "==" l r);;
+/* User defined function i.e. normal function */
+f(l)(r);;
+
+/* Distinguishing subroutines and functions: both are supported, but compiler is not aware of difference */
+sub();;
+fun();;
+
+/* Stating whether arguments are passed by value or by reference */
+f(value);; /* by value */
+f(&value);; /* by pointer reference */
+f(ref(value));; /* by managed reference */
+
+/* Is partial application possible and how */
+tasty_curry(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);;
diff --git a/Task/Call-a-function/Nim/call-a-function.nim b/Task/Call-a-function/Nim/call-a-function.nim
new file mode 100644
index 0000000000..d57793a55d
--- /dev/null
+++ b/Task/Call-a-function/Nim/call-a-function.nim
@@ -0,0 +1,43 @@
+proc no_args() =
+ discard
+# call
+no_args()
+
+proc fixed_args(x, y) =
+ echo x
+ echo y
+# calls
+fixed_args(1, 2) # x=1, y=2
+fixed_args 1, 2 # same call
+1.fixed_args(2) # same call
+
+
+proc opt_args(x=1.0) =
+ echo x
+# calls
+opt_args() # 1
+opt_args(3.141) # 3.141
+
+proc var_args(v: varargs[string, `$`]) =
+ for x in v: echo x
+# calls
+var_args(1, 2, 3) # (1, 2, 3)
+var_args(1, (2,3)) # (1, (2, 3))
+var_args() # ()
+
+## Named arguments
+fixed_args(y=2, x=1) # x=1, y=2
+
+## As a statement
+if true:
+ no_args()
+
+proc return_something(x): int =
+ x + 1
+
+var a = return_something(2)
+
+## First-class within an expression
+let x = return_something(19) + 10
+let y = 19.return_something() + 10
+let z = 19.return_something + 10
diff --git a/Task/Call-a-function/Oforth/call-a-function-1.oforth b/Task/Call-a-function/Oforth/call-a-function-1.oforth
new file mode 100644
index 0000000000..b8115dadaf
--- /dev/null
+++ b/Task/Call-a-function/Oforth/call-a-function-1.oforth
@@ -0,0 +1 @@
+a b c f
diff --git a/Task/Call-a-function/Oforth/call-a-function-2.oforth b/Task/Call-a-function/Oforth/call-a-function-2.oforth
new file mode 100644
index 0000000000..8f00e3db90
--- /dev/null
+++ b/Task/Call-a-function/Oforth/call-a-function-2.oforth
@@ -0,0 +1 @@
+f(a, b, c)
diff --git a/Task/Call-a-function/Oforth/call-a-function-3.oforth b/Task/Call-a-function/Oforth/call-a-function-3.oforth
new file mode 100644
index 0000000000..285488c1c9
--- /dev/null
+++ b/Task/Call-a-function/Oforth/call-a-function-3.oforth
@@ -0,0 +1,4 @@
+a b c f
+a b f(c)
+a f(b, c)
+f(a, b, c)
diff --git a/Task/Call-a-function/Oforth/call-a-function-4.oforth b/Task/Call-a-function/Oforth/call-a-function-4.oforth
new file mode 100644
index 0000000000..da4ca51af2
--- /dev/null
+++ b/Task/Call-a-function/Oforth/call-a-function-4.oforth
@@ -0,0 +1 @@
+a b c r m
diff --git a/Task/Call-a-function/Oforth/call-a-function-5.oforth b/Task/Call-a-function/Oforth/call-a-function-5.oforth
new file mode 100644
index 0000000000..76d4b38d2e
--- /dev/null
+++ b/Task/Call-a-function/Oforth/call-a-function-5.oforth
@@ -0,0 +1 @@
+r m(a, b, c)
diff --git a/Task/Call-a-function/Phix/call-a-function-1.phix b/Task/Call-a-function/Phix/call-a-function-1.phix
new file mode 100644
index 0000000000..2d80fa163e
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-1.phix
@@ -0,0 +1 @@
+{} = myfunction()
diff --git a/Task/Call-a-function/Phix/call-a-function-2.phix b/Task/Call-a-function/Phix/call-a-function-2.phix
new file mode 100644
index 0000000000..adfa8a5037
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-2.phix
@@ -0,0 +1,4 @@
+{cities,populations} = columize(muncipalities)
+{{},populations} = columize(muncipalities) -- discard result[1]
+{cities,{}} = columize(muncipalities) -- discard result[2]
+{cities} = columize(muncipalities) -- ""
diff --git a/Task/Call-a-function/Phix/call-a-function-3.phix b/Task/Call-a-function/Phix/call-a-function-3.phix
new file mode 100644
index 0000000000..e43f52fe9f
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-3.phix
@@ -0,0 +1,6 @@
+function myfunction(integer a, string b="default")
+ return {a,b}
+end function
+--? myfunction() -- illegal, compile-time error
+?myfunction(1) -- displays {1,"default"}
+?myfunction(2,"that") -- displays {2,"that"}
diff --git a/Task/Call-a-function/Phix/call-a-function-4.phix b/Task/Call-a-function/Phix/call-a-function-4.phix
new file mode 100644
index 0000000000..ddfe6ed9f0
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-4.phix
@@ -0,0 +1,2 @@
+?myfunction(b:="then",a:=3) -- displays {3,"then"}
+--?myfunction(b:="though") -- compile-time error
diff --git a/Task/Call-a-function/Phix/call-a-function-5.phix b/Task/Call-a-function/Phix/call-a-function-5.phix
new file mode 100644
index 0000000000..e5cefb5306
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-5.phix
@@ -0,0 +1,2 @@
+constant integer r_my_func = routine_id("myroutine")
+?call_func(r_my_func,{1}) -- displays {1,"default"}
diff --git a/Task/Call-a-function/Phix/call-a-function-6.phix b/Task/Call-a-function/Phix/call-a-function-6.phix
new file mode 100644
index 0000000000..52309d3d70
--- /dev/null
+++ b/Task/Call-a-function/Phix/call-a-function-6.phix
@@ -0,0 +1 @@
+s = append(s,item)
diff --git a/Task/Call-a-function/Ring/call-a-function-1.ring b/Task/Call-a-function/Ring/call-a-function-1.ring
new file mode 100644
index 0000000000..eeb75607c7
--- /dev/null
+++ b/Task/Call-a-function/Ring/call-a-function-1.ring
@@ -0,0 +1,3 @@
+hello()
+func hello
+ see "Hello from function" + nl
diff --git a/Task/Call-a-function/Ring/call-a-function-2.ring b/Task/Call-a-function/Ring/call-a-function-2.ring
new file mode 100644
index 0000000000..78342f361f
--- /dev/null
+++ b/Task/Call-a-function/Ring/call-a-function-2.ring
@@ -0,0 +1,3 @@
+first() second()
+func first see "message from the first function" + nl
+func second see "message from the second function" + nl
diff --git a/Task/Call-a-function/Ring/call-a-function-3.ring b/Task/Call-a-function/Ring/call-a-function-3.ring
new file mode 100644
index 0000000000..498ad5096d
--- /dev/null
+++ b/Task/Call-a-function/Ring/call-a-function-3.ring
@@ -0,0 +1,2 @@
+sum(3,5) sum(1000,2000)
+func sum x,y see x+y+nl
diff --git a/Task/Call-a-function/Ring/call-a-function-4.ring b/Task/Call-a-function/Ring/call-a-function-4.ring
new file mode 100644
index 0000000000..564d04c138
--- /dev/null
+++ b/Task/Call-a-function/Ring/call-a-function-4.ring
@@ -0,0 +1,4 @@
+# this program will print the hello world message first then execute the main function
+See "Hello World!" + nl
+func main
+ see "Message from the main function" + nl
diff --git a/Task/Call-a-function/SSEM/call-a-function.ssem b/Task/Call-a-function/SSEM/call-a-function.ssem
new file mode 100644
index 0000000000..22027ba81b
--- /dev/null
+++ b/Task/Call-a-function/SSEM/call-a-function.ssem
@@ -0,0 +1,4 @@
+00110000000000100000000000000000 10. -12 to c
+10110000000000000000000000000000 11. 13 to CI
+11001111111111111111111111111111 12. -13
+11001000000000000000000000000000 13. 19
diff --git a/Task/Call-a-function/Sidef/call-a-function-1.sidef b/Task/Call-a-function/Sidef/call-a-function-1.sidef
new file mode 100644
index 0000000000..6ede3a3662
--- /dev/null
+++ b/Task/Call-a-function/Sidef/call-a-function-1.sidef
@@ -0,0 +1,10 @@
+foo(); # without arguments
+foo(1, 2); # with two arguments
+foo(args...); # with a variable number of arguments
+foo(name: 'Bar', age: 42); # with named arguments
+
+var f = foo; # store the function foo inside 'f'
+var result = f(); # obtain the return value of a function
+
+var arr = [1,2,3];
+foo(arr); # the arguments are passed by object-reference
diff --git a/Task/Call-a-function/Sidef/call-a-function-2.sidef b/Task/Call-a-function/Sidef/call-a-function-2.sidef
new file mode 100644
index 0000000000..b978026379
--- /dev/null
+++ b/Task/Call-a-function/Sidef/call-a-function-2.sidef
@@ -0,0 +1,12 @@
+func curry(f, *args1) {
+ func (*args2) {
+ f(args1..., args2...);
+ }
+}
+
+func add(a, b) {
+ a + b
+}
+
+var adder = curry(add, 1);
+say adder(3); #=>4
diff --git a/Task/Call-a-function/Swift/call-a-function.swift b/Task/Call-a-function/Swift/call-a-function.swift
new file mode 100644
index 0000000000..650f53726c
--- /dev/null
+++ b/Task/Call-a-function/Swift/call-a-function.swift
@@ -0,0 +1,35 @@
+// call a function with no args
+noArgs()
+
+// call a function with one arg with no external name
+oneArgUnnamed(1)
+
+// call a function with one arg with external name
+oneArgNamed(arg: 1)
+
+// call a function with two args with no external names
+twoArgsUnnamed(1, 2)
+
+// call a function with two args and external names
+twoArgsNamed(arg1: 1, arg2: 2)
+
+// call a function with an optional arg
+// with arg
+optionalArguments(arg: 1)
+// without
+optionalArguments() // defaults to 0
+
+// function that takes another function as arg
+funcArg(noArgs)
+
+// variadic function
+variadic(opts: "foo", "bar")
+
+// getting a return value
+let foo = returnString()
+
+// getting a bunch of return values
+let (foo, bar, baz) = returnSomeValues()
+
+// getting a bunch of return values, discarding second returned value
+let (foo, _, baz) = returnSomeValues()
diff --git a/Task/Call-a-function/XLISP/call-a-function.xlisp b/Task/Call-a-function/XLISP/call-a-function.xlisp
new file mode 100644
index 0000000000..aa0aa2469c
--- /dev/null
+++ b/Task/Call-a-function/XLISP/call-a-function.xlisp
@@ -0,0 +1,19 @@
+; call a function (procedure) with no arguments:
+(foo)
+
+; call a function (procedure) with arguments:
+(foo bar baz)
+; the first symbol after "(" is the name of the function
+; the other symbols are the arguments
+
+; call a function on a list of arguments formed at run time:
+(apply foo bar)
+
+; In a REPL, the return value will be printed.
+; In other contexts, it can be fed as argument into a further function:
+(foo (bar baz))
+; this calls bar on the argument baz and then calls foo on the return value
+
+; or it can simply be discarded
+(foo bar)
+; nothing is done with the return value
diff --git a/Task/Call-an-object-method/Apex/call-an-object-method.apex b/Task/Call-an-object-method/Apex/call-an-object-method.apex
new file mode 100644
index 0000000000..03cc43e8a9
--- /dev/null
+++ b/Task/Call-an-object-method/Apex/call-an-object-method.apex
@@ -0,0 +1,5 @@
+// Static
+MyClass.method(someParameter);
+
+// Instance
+myInstance.method(someParameter);
diff --git a/Task/Call-an-object-method/ChucK/call-an-object-method.chuck b/Task/Call-an-object-method/ChucK/call-an-object-method.chuck
new file mode 100644
index 0000000000..ca6f0e7946
--- /dev/null
+++ b/Task/Call-an-object-method/ChucK/call-an-object-method.chuck
@@ -0,0 +1,2 @@
+MyClass myClassObject;
+myClassObject.myFunction(some parameter);
diff --git a/Task/Call-an-object-method/FreeBASIC/call-an-object-method.freebasic b/Task/Call-an-object-method/FreeBASIC/call-an-object-method.freebasic
new file mode 100644
index 0000000000..26db418aa7
--- /dev/null
+++ b/Task/Call-an-object-method/FreeBASIC/call-an-object-method.freebasic
@@ -0,0 +1,24 @@
+' FB 1.05.0 Win64
+
+Type MyType
+ Public:
+ Declare Sub InstanceMethod(s As String)
+ Declare Static Sub StaticMethod(s As String)
+ Private:
+ dummy_ As Integer ' types cannot be empty in FB
+End Type
+
+Sub MyType.InstanceMethod(s As String)
+ Print s
+End Sub
+
+Static Sub MyType.StaticMethod(s As String)
+ Print s
+End Sub
+
+Dim t As MyType
+t.InstanceMethod("Hello world!")
+MyType.Staticmethod("Hello static world!")
+Print
+Print "Press any key to quit the program"
+Sleep
diff --git a/Task/Call-an-object-method/LFE/call-an-object-method-1.lfe b/Task/Call-an-object-method/LFE/call-an-object-method-1.lfe
new file mode 100644
index 0000000000..506165c927
--- /dev/null
+++ b/Task/Call-an-object-method/LFE/call-an-object-method-1.lfe
@@ -0,0 +1,93 @@
+(defmodule aquarium
+ (export all))
+
+(defun fish-class (species)
+ "
+ This is the constructor that will be used most often, only requiring that
+ one pass a 'species' string.
+
+ When the children are not defined, simply use an empty list.
+ "
+ (fish-class species ()))
+
+(defun fish-class (species children)
+ "
+ This contructor is mostly useful as a way of abstracting out the id
+ generation from the larger constructor. Nothing else uses fish-class/2
+ besides fish-class/1, so it's not strictly necessary.
+
+ When the id isn't know, generate one.
+ "
+ (let* (((binary (id (size 128))) (: crypto rand_bytes 16))
+ (formatted-id (car
+ (: io_lib format
+ '"~32.16.0b" (list id)))))
+ (fish-class species children formatted-id)))
+
+(defun fish-class (species children id)
+ "
+ This is the constructor used internally, once the children and fish id are
+ known.
+ "
+ (let ((move-verb '"swam"))
+ (lambda (method-name)
+ (case method-name
+ ('id
+ (lambda (self) id))
+ ('species
+ (lambda (self) species))
+ ('children
+ (lambda (self) children))
+ ('info
+ (lambda (self)
+ (: io format
+ '"id: ~p~nspecies: ~p~nchildren: ~p~n"
+ (list (get-id self)
+ (get-species self)
+ (get-children self)))))
+ ('move
+ (lambda (self distance)
+ (: io format
+ '"The ~s ~s ~p feet!~n"
+ (list species move-verb distance))))
+ ('reproduce
+ (lambda (self)
+ (let* ((child (fish-class species))
+ (child-id (get-id child))
+ (children-ids (: lists append
+ (list children (list child-id))))
+ (parent-id (get-id self))
+ (parent (fish-class species children-ids parent-id)))
+ (list parent child))))
+ ('children-count
+ (lambda (self)
+ (: erlang length children)))))))
+
+(defun get-method (object method-name)
+ "
+ This is a generic function, used to call into the given object (class
+ instance).
+ "
+ (funcall object method-name))
+
+; define object methods
+(defun get-id (object)
+ (funcall (get-method object 'id) object))
+
+(defun get-species (object)
+ (funcall (get-method object 'species) object))
+
+(defun get-info (object)
+ (funcall (get-method object 'info) object))
+
+(defun move (object distance)
+ (funcall (get-method object 'move) object distance))
+
+(defun reproduce (object)
+ (funcall (get-method object 'reproduce) object))
+
+(defun get-children (object)
+ (funcall (get-method object 'children) object))
+
+(defun get-children-count (object)
+ (funcall (get-method object 'children-count) object))
diff --git a/Task/Call-an-object-method/LFE/call-an-object-method-2.lfe b/Task/Call-an-object-method/LFE/call-an-object-method-2.lfe
new file mode 100644
index 0000000000..e7a6c85631
--- /dev/null
+++ b/Task/Call-an-object-method/LFE/call-an-object-method-2.lfe
@@ -0,0 +1,45 @@
+; Load the file and create a fish-class instance:
+
+> (slurp '"object.lfe")
+#(ok object)
+> (set mommy-fish (fish-class '"Carp"))
+#Fun
+
+; Execute some of the basic methods:
+
+> (get-species mommy-fish)
+"Carp"
+> (move mommy-fish 17)
+The Carp swam 17 feet!
+ok
+> (get-id mommy-fish)
+"47eebe91a648f042fc3fb278df663de5"
+
+; Now let's look at "modifying" state data (e.g., children counts):
+
+> (get-children mommy-fish)
+()
+> (get-children-count mommy-fish)
+0
+> (set (mommy-fish baby-fish-1) (reproduce mommy-fish))
+(#Fun #Fun)
+> (get-id mommy-fish)
+"47eebe91a648f042fc3fb278df663de5"
+> (get-id baby-fish-1)
+"fdcf35983bb496650e558a82e34c9935"
+> (get-children-count mommy-fish)
+1
+> (set (mommy-fish baby-fish-2) (reproduce mommy-fish))
+(#Fun #Fun