Kronecker product: Difference between revisions
Content added Content deleted
(→JS ES6: Changed top level of kprod to concatMap - a little cleaner) |
(→{{header|Haskell}}: (slight reformulation for fewer maps)) |
||
Line 36: | Line 36: | ||
:: Num a |
:: Num a |
||
=> [[a]] -> [[a]] -> [[a]] |
=> [[a]] -> [[a]] -> [[a]] |
||
kprod xs ys = |
kprod xs ys = |
||
let f = fmap . fmap . (*) -- Multiplication by n over list of lists |
|||
where |
|||
in (concat <$>) . transpose =<< fmap (`f` ys) <$> xs |
|||
f = fmap . fmap . (*) |
|||
main :: IO () |
main :: IO () |
||
Line 65: | Line 64: | ||
[0,0,0,0,1,0,0,1,0,0,0,0] |
[0,0,0,0,1,0,0,1,0,0,0,0] |
||
[0,0,0,0,1,1,1,1,0,0,0,0]</pre> |
[0,0,0,0,1,1,1,1,0,0,0,0]</pre> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
===Imperative=== |
===Imperative=== |