Guest User

Untitled

a guest
Sep 2nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.46 KB | None | 0 0
  1. %% F1 = {["A"], [2], [0.7, 0.3]}.
  2. %% F2 = {["B"], [3], [0.2, 0.7, 0.1]}.
  3. %% F1 * F2 = {["A", "B"], [2, 3], [0.7 * 0.2, 0.7 * 0.7, 0.7 * 0.1,
  4. %% 0.3 * 0.2, 0.3 * 0.7, 0.3 * 0.1]}
  5.  
  6. %% factor multiplication
  7. mul({VarsA, CardsA, ValsA}, {VarsB, CardsB, ValsB}) ->
  8.     ValsC =
  9.         lists:foldl(
  10.           fun(AElem, Acc) ->
  11.               [lists:map(fun(BElem) -> AElem * BElem end, ValsB)|Acc]
  12.           end, [], lists:reverse(ValsA)),
  13.     {VarsA ++ VarsB, CardsA ++ CardsB, lists:flatten(ValsC)}.
Add Comment
Please, Sign In to add comment