Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
1
Task/Dot-product/8th/dot-product.8th
Normal file
1
Task/Dot-product/8th/dot-product.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1,3,-5] [4,-2,-1] ' n:* ' n:+ a:dot . cr
|
||||
10
Task/Dot-product/EchoLisp/dot-product.echolisp
Normal file
10
Task/Dot-product/EchoLisp/dot-product.echolisp
Normal 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
|
||||
7
Task/Dot-product/FunL/dot-product.funl
Normal file
7
Task/Dot-product/FunL/dot-product.funl
Normal 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]) )
|
||||
9
Task/Dot-product/Idris/dot-product.idris
Normal file
9
Task/Dot-product/Idris/dot-product.idris
Normal 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]
|
||||
3
Task/Dot-product/LFE/dot-product.lfe
Normal file
3
Task/Dot-product/LFE/dot-product.lfe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(defun dot-product (a b)
|
||||
(: lists foldl #'+/2 0
|
||||
(: lists zipwith #'*/2 a b)))
|
||||
9
Task/Dot-product/Nim/dot-product.nim
Normal file
9
Task/Dot-product/Nim/dot-product.nim
Normal 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])
|
||||
1
Task/Dot-product/Oforth/dot-product.oforth
Normal file
1
Task/Dot-product/Oforth/dot-product.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: dotProduct zipWith(#*) sum ;
|
||||
1
Task/Dot-product/Phix/dot-product.phix
Normal file
1
Task/Dot-product/Phix/dot-product.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
?sum(sq_mul({1,3,-5},{4,-2,-1}))
|
||||
10
Task/Dot-product/Ring/dot-product.ring
Normal file
10
Task/Dot-product/Ring/dot-product.ring
Normal 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
|
||||
4
Task/Dot-product/Sidef/dot-product.sidef
Normal file
4
Task/Dot-product/Sidef/dot-product.sidef
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
func dot_product(a, b) {
|
||||
(a »*« b)«+»;
|
||||
};
|
||||
say dot_product([1,3,-5], [4,-2,-1]); # => 3
|
||||
5
Task/Dot-product/Swift/dot-product.swift
Normal file
5
Task/Dot-product/Swift/dot-product.swift
Normal 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]))
|
||||
2
Task/Dot-product/Wart/dot-product.wart
Normal file
2
Task/Dot-product/Wart/dot-product.wart
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def (dot_product x y)
|
||||
(sum+map (*) x y)
|
||||
2
Task/Dot-product/jq/dot-product-1.jq
Normal file
2
Task/Dot-product/jq/dot-product-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def dot(x; y):
|
||||
reduce range(0;x|length) as $i (0; . + x[$i] * y[$i]);
|
||||
1
Task/Dot-product/jq/dot-product-2.jq
Normal file
1
Task/Dot-product/jq/dot-product-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def SIGMA( f ): reduce .[] as $o (0; . + ($o | f )) ;
|
||||
4
Task/Dot-product/jq/dot-product-3.jq
Normal file
4
Task/Dot-product/jq/dot-product-3.jq
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue