Mar-19-2023, 09:10 PM
(This post was last modified: Mar-21-2023, 01:29 PM by Paul_Maillet.)
Hello ! I need someone to quickly run a program that takes time...
I am French and I am in high school, I'm researching anti-sum drawers, i.e., drawers whose sum of two elements does not give the value of another element in the same drawer.
(a + b !=c, a b and c in the same drawer)
In this program, there are three drawers, it tests all the possible combinations which make it possible to go up to a given number (n) and checks at the same time if these are anti-sums. This program allows you to prove which is the best combination for three drawers.
By observing the time the program took for small numbers, I deduced that the program was exponentially complex, and therefore it would take several days for it to find the solution.
(7 days for n = 23 with my computer (not very powerful) according to my calculations )
That's why I will need someone to test with a more powerful computer to have a result before
the day of the mathematics congress (23 march), which would therefore be faster the program with the value 23 then 24.
The program should return several solutions for 23 and nothing for 24, which would prove that 23 is the maximum. It would help me a lot!
I am attaching the program, the function to run is combi(n):
I am French and I am in high school, I'm researching anti-sum drawers, i.e., drawers whose sum of two elements does not give the value of another element in the same drawer.
(a + b !=c, a b and c in the same drawer)
In this program, there are three drawers, it tests all the possible combinations which make it possible to go up to a given number (n) and checks at the same time if these are anti-sums. This program allows you to prove which is the best combination for three drawers.
By observing the time the program took for small numbers, I deduced that the program was exponentially complex, and therefore it would take several days for it to find the solution.
(7 days for n = 23 with my computer (not very powerful) according to my calculations )
That's why I will need someone to test with a more powerful computer to have a result before
the day of the mathematics congress (23 march), which would therefore be faster the program with the value 23 then 24.
The program should return several solutions for 23 and nothing for 24, which would prove that 23 is the maximum. It would help me a lot!
I am attaching the program, the function to run is combi(n):
import time def gen_combinations(numbers, n): if n == 0: yield [] else: for i in range(3): for sub_comb in gen_combinations(numbers, n-1): yield [i] + sub_comb def combi(n): start_time = time.time() # démarrer le chronomètre numbers = list(range(1, n+1)) combinaisons = [] for combinaison in gen_combinations(numbers, n): tiroir1 = [] tiroir2 = [] tiroir3 = [] for i in range(n): if combinaison[i] == 0: tiroir1.append(numbers[i]) elif combinaison[i] == 1: tiroir2.append(numbers[i]) else: tiroir3.append(numbers[i]) if est_anti_somme(tiroir1) and est_anti_somme(tiroir2) and est_anti_somme(tiroir3): combinaisons.append((tuple(tiroir1), tuple(tiroir2), tuple(tiroir3))) if combinaisons == []: print("Il n'y a pas de solutions allant jusqu'à", n) else : print("il y a", len(combinaisons), 'possibilités') # Convertir les tuples en sous-listes result = [[list(tiroir1), list(tiroir2), list(tiroir3)] for (tiroir1, tiroir2, tiroir3) in combinaisons] end_time = time.time() # arrêter le chronomètre print(f"Temps d'exécution : {end_time - start_time:.4f} secondes") return result def est_anti_somme(tab): ''' Renvoie True si on NE peut PAS obtenir un élément du tableau en ajoutant deux élements de ce tableau et False sinon : param tab (list) tableau d'entiers : return (bool) >>> est_anti_somme([1, 2, 3]) False >>> est_anti_somme([1, 2, 4, 5]) False >>> est_anti_somme([2, 3, 7, 11]) True >>> est_anti_somme([]) True >>> est_anti_somme([0, 0, 0, 0]) False >>> est_anti_somme([0]) True ''' if len(tab) < 2: return True return all(tab[i]+tab[j] not in tab for i in range(len(tab)) for j in range(i+1, len(tab))) return result