def triangle_sequence(creation_sequence):
 cs = creation_sequence
 seq = []
 dr = cs.count('d')
 dcur = (((dr - 1) * (dr - 2)) // 2)
 irun = 0
 drun = 0
 for (i, sym) in enumerate(cs):
  if (sym == 'd'):
   drun += 1
   tri = (dcur + ((dr - 1) * irun))
  else:
   if (prevsym == 'd'):
    dcur += ((dr - 1) * irun)
    irun = 0
    dr -= drun
    drun = 0
   irun += 1
   tri = ((dr * (dr - 1)) // 2)
  seq.append(tri)
  prevsym = sym
 return seq

def triangle_sequence ( creation_sequence ) : cs = creation_sequence seq = [ ] dr = cs . count ( 'd' ) dcur = ( ( ( dr - 1 ) * ( dr - 2 ) ) // 2 ) irun = 0 drun = 0 for ( i , sym ) in enumerate ( cs ) : if ( sym == 'd' ) : drun += 1 tri = ( dcur + ( ( dr - 1 ) * irun ) ) else : if ( prevsym == 'd' ) : dcur += ( ( dr - 1 ) * irun ) irun = 0 dr -= drun drun = 0 irun += 1 tri = ( ( dr * ( dr - 1 ) ) // 2 ) seq . append ( tri ) prevsym = sym return seq
return triangle sequence for the given threshold graph creation sequence .