Last active
June 22, 2016 03:23
-
-
Save aw31/65426fb110647912331e76a9f0ba81c4 to your computer and use it in GitHub Desktop.
Solution for problem L: Luxor Catch-ya! of IPSC 2016. (https://ipsc.ksp.sk/2016/real/problems/l.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from sklearn import svm | |
LENGTH = 6 | |
ROWS = 70 | |
COLS = 100 | |
def get_answers(s): | |
with open(s) as f: | |
return f.read().split() | |
def get_catchyas(s): | |
catchyas = [] | |
for i in range(1, 801): | |
catchya = [[] for j in range(LENGTH)] | |
with open(s % i) as f: | |
for line in f: | |
rows = map(int, line.split()) | |
for j in range(LENGTH): | |
catchya[j] += rows[COLS * j : COLS * (j + 1)] | |
catchyas.append(catchya) | |
return catchyas | |
ANSWERS = get_answers('l2/sample.out') | |
CATCHYAS = get_catchyas('l2/%03d.in') | |
LABELLED = range(0, 200) | |
ALL = range(0, 800) | |
X, y = [], [] | |
for i in LABELLED: | |
for j in range(LENGTH): | |
X.append(CATCHYAS[i][j]) | |
y.append(ANSWERS[i][j]) | |
clf = svm.SVC(kernel='linear', C=1e-3) | |
clf.fit(X, y) | |
X_all = [] | |
for i in ALL: | |
for j in range(LENGTH): | |
X_all.append(CATCHYAS[i][j]) | |
predicted = clf.predict(X_all) | |
answers = numpy.split(predicted, len(ALL)) | |
for answer in answers: | |
print(''.join(answer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment