# -*- coding: utf-8 -*-
#
# Usage: python check-colouring.py [K] [colouring]
# [K] denotes the number of colours used in the initial colouring.
# [colouring] is the file that specifies a colouring algorithm for
#             K-coloured graphs
#
# 9 April 2011. 

import sys

K = int(sys.argv[1])

nhoods = dict() # Stores the neighbourhoods that are mapped to colours
used_colours = set() # Keeps track of the different output colours

for line in open(sys.argv[2]):
    values = map(int, line.split())
    nhood = tuple(values[:3])
    col = values[3]
    nhoods[nhood] = col
    used_colours.add(col)

print "The output consisted of the following colours: %s." % (",".join( map(str, sorted(used_colours)) ))

# Generator for the test cases
colours = range(0, K)
test_cases = ( (i,j,k,l) for i in colours for j in colours for k in colours for l in colours 
               if i != j and j != k and k != l )

iterations = 0
for (i,j,k,l) in test_cases:
    v = (i,j,k)
    u = (j,k,l)
    if nhoods[v] == nhoods[u]:
        print "Fail: ", v, u
    iterations += 1

print "%i cases checked (%i-coloured neighbourhoods)." % (iterations, K)
print "OK."