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 @@
[1,3,-5] [4,-2,-1] ' n:* ' n:+ a:dot . cr

View file

@ -0,0 +1,10 @@
(define a #(1 3 -5))
(define b #(4 -2 -1))
;; function definition
(define ( ⊗ a b) (for/sum ((x a)(y b)) (* x y)))
(⊗ a b) → 3
;; library
(lib 'math)
(dot-product a b) → 3

View file

@ -0,0 +1,7 @@
import lists.zipWith
def dot( a, b )
| a.length() == b.length() = sum( zipWith((*), a, b) )
| otherwise = error( "Vector sizes must match" )
println( dot([1, 3, -5], [4, -2, -1]) )

View file

@ -0,0 +1,9 @@
module Main
import Data.Vect
dotProduct : (Num a) => Vect n a -> Vect n a -> a
dotProduct = (sum .) . zipWith (*)
main : IO ()
main = printLn $ dotProduct [1,2,3] [1,2,3]

View file

@ -0,0 +1,3 @@
(defun dot-product (a b)
(: lists foldl #'+/2 0
(: lists zipwith #'*/2 a b)))

View file

@ -0,0 +1,9 @@
# Compile time error when a and b are differently sized arrays
# Runtime error when a and b are differently sized seqs
proc dotp[T](a,b: T): int =
assert a.len == b.len
for i in a.low..a.high:
result += a[i] * b[i]
echo dotp([1,3,-5], [4,-2,-1])
echo dotp(@[1,2,3],@[4,5,6])

View file

@ -0,0 +1 @@
: dotProduct zipWith(#*) sum ;

View file

@ -0,0 +1 @@
?sum(sq_mul({1,3,-5},{4,-2,-1}))

View file

@ -0,0 +1,10 @@
aVector = [2, 3, 5]
bVector = [4, 2, 1]
sum = 0
see dotProduct(aVector, bVector)
func dotProduct cVector, dVector
for n = 1 to len(aVector)
sum = sum + cVector[n] * dVector[n]
next
return sum

View file

@ -0,0 +1,4 @@
func dot_product(a, b) {
(a »*« b)«+»;
};
say dot_product([1,3,-5], [4,-2,-1]); # => 3

View file

@ -0,0 +1,5 @@
func dot(v1: [Double], v2: [Double]) -> Double {
return reduce(lazy(zip(v1, v2)).map(*), 0, +)
}
println(dot([1, 3, -5], [4, -2, -1]))

View file

@ -0,0 +1,2 @@
def (dot_product x y)
(sum+map (*) x y)

View file

@ -0,0 +1,2 @@
def dot(x; y):
reduce range(0;x|length) as $i (0; . + x[$i] * y[$i]);

View file

@ -0,0 +1 @@
def SIGMA( f ): reduce .[] as $o (0; . + ($o | f )) ;

View file

@ -0,0 +1,4 @@
dot( [1, 3, -5]; [4, -2, -1]) # => 3
[ {"x": 1, "y": 4}, {"x": 3, "y": -2}, {"x": -5, "y": -1} ]
| SIGMA( .x * .y ) # => 3