I have found that solution (thanks Python !) :
Red : 1, 2, 4, 8, 11, 16, 22
Green : 3, 5, 6, 7, 19, 21, 23
Blue : 9, 10, 12, 13, 14, 15, 17, 18, 20
Here is my code if you're curious !
# Tells for each color if it is available for this number
def getColorsAvailabilities(n):
av = [True] * 3
for i in range(1, (n+1) // 2): # Only iterate up to half the number
if (colors[i] == colors[n-i]):
# If i and (n-i) have same color, n cannot be of that color
av[colors[i]] = False
return av
# Main recursive function
def test(n):
if (n >= 24):
return True
colorsAvailabilities = getColorsAvailabilities(n)
# Try each available color, in order
for color in range(3):
if colorsAvailabilities[color]:
colors[n] = color
if test(n+1):
return True # Stop when we found a solution
# If every available color results in a failure, backtrack
return False
# First try : 1 and 2 have same colors
colors = [-1] * 24
colors[1] = 0
colors[2] = 0
print(test(3)) # It works !
print(colors) # My solution (with Red = 0, Green = 1, Blue = 2)
# Second try : 1 and 2 have different colors
colors = [-1] * 24
colors[1] = 0
colors[2] = 1
print(test(3)) # Doesn't work (stops at 22)
print(colors)