M
M
Mikhail2018-10-04 09:45:22
Python
Mikhail, 2018-10-04 09:45:22

How to find all combinations of sum of elements of subarrays?

mas = [[1,2], [1,2,3], [1,2]

Visually
5bb5b68154dc6049487451.png

As an example, it is necessary to find all possible combinations of the sum of the number 6 from various subarrays.
6:
1) 1, 3, 2
2) 2, 2, 2
3) 2, 3 1
...
So far, I imagine it in the form of vectors with finding all possible options, but I can’t figure out the implementation. I understand that it is necessary to dig towards recursive functions. I would be very grateful for your help :)

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
GreatRash, 2018-10-04
@GreatRash

https://www.youtube.com/watch?v=p8SDPaX1wgw

A
Alexander Skusnov, 2018-10-06
@AlexSku

You need to run a monadic evaluation on the list. If the Pythonists don't answer, then ask the Haskellists. (I myself decided to take a course on Stepik on Haskell for the third time, because monads are a quiet horror).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question