Given an integer(n) denoting the no. of particles initially and array of sizes of these particles.
These particles can go into any number of simulations (possibly none).
In one simulation, two particles combine to give another particle with size as the difference between the size of them (possibly 0).
Find the smallest particle that can be formed.
30 10 8
10 – 8 is the smallest we can achieve.
1 2 4 8
We cannot make another 1 so as to get 0 so smallest without any simulation is 1
30 27 26 10 6
import itertools as iter def particles(li): global m if len(li)>1: for i in iter.combinations(li, 2): temp = abs(i - i) if m > temp: m = temp k = li.copy() k.remove(i) k.remove(i) k.append(temp) particles(k) n = int(input()) lst = list() for i in range(n): lst.append(int(input())) m = min(lst) particles(lst) print(m)