# convert the presented test-sequence with winner to characteristic field
# $1: presented symbol  $2: winner neuron
# separate occuring sequences by COLSEP
#

BEGIN {
  if(qlen <= 0) qlen = 8
}

{
  gsub(/\r/,"")

  queue[NR%qlen] = "" $1

  if(NR < qlen) next

  result = ""

  for(i = qlen; i > 0; i--)
    result = result ((i==qlen)?"":COLSEP) queue[(i+NR) % qlen]

  ++strings[$2,result]
  ++cnt[$2]

}

END {

  for(ind in strings) {
    split(ind, separate, SUBSEP)
    print separate[1], separate[2], strings[ind]
  }
  for(ind in cnt)
    print ind, cnt[ind]/NR
}
