コード例 #1
0
ファイル: matrix.py プロジェクト: tatianeforster/Pense-Bem
def main(argv):
	numeric = 0

	# I'm too lazy too look up getopt documentation
	if len(sys.argv) > 1:
		if sys.argv[1] == '-n':
			numeric = 1

	maxbook = 0
	maxquestiosn = 0

	m = samples.dict()
	for book,q in m.keys():
		if maxbook < book:
			maxbook = book
		if q > maxquestiosn:
			maxquestiosn = q

	for b in range(1, maxbook+1):
		sys.stdout.write('%02d ' % (b))
		for q in range(1,maxquestiosn+1):
			a = m.get( (b,q), ' ')
			outa = a

			if a != ' ':
				if numeric:
					outa = str(ord(a)-ord('a'))

				assert len(outa) == 1

				# check for known patterns
				for function,color in checkers:
					r = function(m, b, q, a)

					# doesn't match pattern?
					if r > 0:
						outa = "\x1b[%sm%s\x1b[0m" % (color, outa)
						break

			sys.stdout.write(outa)
			if (q % 15) == 0:
				sys.stdout.write(' ')
		sys.stdout.write('\n')
コード例 #2
0
	pattern_number = (question - 1) / 15 # For each 15 questions the pattern changes (1-15 != 16-30 != ...)
	question = (question % 15) if (question % 15) > 0 else 15 # Need question numbers ranging from 1 to 15

	#print 'pattern_number', pattern_number
	#print 'new_question', question
	#print 'calc_candidate', ((book+question)%16)

	pattern = pattern_list[pattern_number]

	return pattern[(book+question)%16]
	
correct = 0
unknown = 0
errors = 0
m = samples.dict()
for b,q in m.keys():
	print 'book', b
	a = m[b,q]
	expected = answer(b, q)
	if expected:
		if a == expected:
			correct += 1
		else:
			print "ERROR: b%d, q%d. collected sample: %s. calculated answer: %s" % (b, q, a, expected)
			errors += 1
	else:
		unknown += 1

print "Correct answers: %d. Unknown answers: %d" % (correct, unknown)
if errors: