A
A
Alexander Alexandrov2015-09-10 18:29:28
Python
Alexander Alexandrov, 2015-09-10 18:29:28

How to identify dependencies between elements of a list?

Suppose there is a list [24, 22, 81, 4, 72, 2355, 2, 3, 2358],
How to check that there is a relationship between its elements? (sum, difference. product..)
Ie . 24 * 3 = 72
2358 = 2355 + 3?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly, 2015-09-10
@pyhamster

Inefficient solution

from itertools import combinations
import operator

operators = [
    (operator.add, "+"),
    (operator.mul, "*"),
    (operator.sub, "-"),
    (operator.truediv, "/")
]

numbers = [24, 22, 81, 4, 72, 2355, 2, 3, 2358]

for n1, n2 in combinations(numbers, 2):
    for oper in operators:
        result = oper[0](n1, n2)
        if result in numbers:
            print("{}{}{}={}".format(n1, oper[1], n2, result))

D
Dimonchik, 2015-09-10
@dimonchik2013

42

S
s0ci0pat, 2015-09-10
@s0ci0pat

First, you need to choose a model and a learning algorithm. Then train the model, check the quality, and finally identify the pattern. It is advisable to check the revealed patterns, and if it is not correct, start over.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question