#!/usr/bin/env python3
from fractions import Fraction
from pathlib import Path
x=(Path(__file__).parent/'interval-beads-q548.txt').read_text().split();assert x[0]=='AP_INTERVAL_BEADS_V1' and x[1]=='beads';q=int(x[2]);assert x[3]=='colors';c=x[4];assert len(c)==q
assert x[5]=='claimed_weighted_mono';claimed=int(x[6]);assert x[7]=='claimed_continuous';fc=Fraction(x[8]);assert x[9]=='claimed_delta';fd=Fraction(x[10]);assert len(x)==11
score=0
for i in range(q):
 for j in range(q):
  if (i+j)%2==0:
   h=(i+j)//2;score+=2*(c[i]==c[j]==c[h])
  else:
   h=(i+j)//2;score+=(c[i]==c[j]==c[h])+(c[i]==c[j]==c[h+1])
assert score==claimed and fc==Fraction(score,2*q*q)==Fraction(117,548) and fd==Fraction(score,8*q*q)==Fraction(117,2192)
# Independently check the advertised 12 run lengths.
runs=[]
for z in c:
 if not runs or runs[-1][0]!=z:runs.append([z,1])
 else:runs[-1][1]+=1
assert [n for _,n in runs]==[28,6,28,37,59,116,116,59,37,28,6,28]
print('interval-bead cross-check PASS: score',score,'delta',fd)
