Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,23 @@
PROGRAM ETHIOPIAN_MULT
FUNCTION EVEN(A)
EVEN=(A+1) MOD 2
END FUNCTION
FUNCTION HALF(A)
HALF=INT(A/2)
END FUNCTION
FUNCTION DOUBLE(A)
DOUBLE=2*A
END FUNCTION
BEGIN
X=17 Y=34 TOT=0
WHILE X>=1 DO
PRINT(X,)
IF EVEN(X)=0 THEN TOT=TOT+Y PRINT(Y) ELSE PRINT END IF
X=HALF(X) Y=DOUBLE(Y)
END WHILE
PRINT("=",TOT)
END PROGRAM

View file

@ -0,0 +1,15 @@
proc halve(x): int = x div 2
proc double(x): int = x * 2
proc even(x): bool = x mod 2 == 0
proc ethiopian(x, y): int =
var x = x
var y = y
while x >= 1:
if not even x:
result += y
x = halve x
y = double y
echo ethiopian(17, 34)

View file

@ -0,0 +1,7 @@
: halve 2 / ;
: double 2 * ;
: ethiopian
dup ifZero: [ nip return ]
over double over halve ethiopian
swap isEven ifTrue: [ nip ] else: [ + ] ;

View file

@ -0,0 +1,23 @@
function emHalf(integer n)
return floor(n/2)
end function
function emDouble(integer n)
return n*2
end function
function emIsEven(integer n)
return (remainder(n,2)=0)
end function
function emMultiply(integer a, integer b)
integer sum = 0
while a!=0 do
if not emIsEven(a) then sum += b end if
a = emHalf(a)
b = emDouble(b)
end while
return sum
end function
printf(1,"emMultiply(%d,%d) = %d\n",{17,34,emMultiply(17,34)})

View file

@ -0,0 +1,28 @@
public function boolean wf_iseven (long al_arg);return mod(al_arg, 2 ) = 0
end function
public function long wf_halve (long al_arg);RETURN int(al_arg / 2)
end function
public function long wf_double (long al_arg);RETURN al_arg * 2
end function
public function long wf_ethiopianmultiplication (long al_multiplicand, long al_multiplier);// calculate result
long ll_product
DO WHILE al_multiplicand >= 1
IF wf_iseven(al_multiplicand) THEN
// do nothing
ELSE
ll_product += al_multiplier
END IF
al_multiplicand = wf_halve(al_multiplicand)
al_multiplier = wf_double(al_multiplier)
LOOP
return ll_product
end function
// example call
long ll_answer
ll_answer = wf_ethiopianmultiplication(17,34)

View file

@ -0,0 +1,18 @@
x = 17
y = 34
p = 0
while x != 0
if not even(x)
p += y
see "" + x + " " + " " + y + nl
else
see "" + x + " ---" + nl ok
x = halve(x)
y = double(y)
end
see " " + " ===" + nl
see " " + p
func double n return (n * 2)
func halve n return floor(n / 2)
func even n return ((n & 1) = 0)

View file

@ -0,0 +1,14 @@
func double (n) { n * 2 };
func halve (n) { int(n / 2) };
func ethiopic_mult(a, b) {
var r = 0;
while (a > 0) {
a.is_even || (r += b);
a = halve(a);
b = double(b);
};
return r;
}
say ethiopic_mult(17, 34);

View file

@ -0,0 +1,26 @@
import Darwin
func ethiopian(var #int1:Int, var #int2:Int) -> Int {
var lhs = [int1], rhs = [int2]
func isEven(#n:Int) -> Bool {return n % 2 == 0}
func double(#n:Int) -> Int {return n * 2}
func halve(#n:Int) -> Int {return n / 2}
while int1 != 1 {
lhs.append(halve(n: int1))
rhs.append(double(n: int2))
int1 = halve(n: int1)
int2 = double(n: int2)
}
var returnInt = 0
for (a,b) in zip(lhs, rhs) {
if (!isEven(n: a)) {
returnInt += b
}
}
return returnInt
}
println(ethiopian(int1: 17, int2: 34))