Created
April 8, 2012 09:56
-
-
Save vickyg3/2336370 to your computer and use it in GitHub Desktop.
kid vs programmer
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
#! /usr/bin/python | |
import numpy.linalg as lin | |
def get_values(s): | |
lhs, rhs = s.split("=") | |
sparts = map(int, lhs) | |
freq = dict((i, sparts.count(i)) for i in set(sparts)) | |
return ([freq.get(i,0) for i in range(10)], int(rhs)) | |
inputs = [ | |
'8810=5', | |
'8809=6', | |
'7111=0', | |
'2172=0', | |
'6666=4', | |
'1111=0', | |
'3213=0', | |
'7662=2', | |
'9313=1', | |
'0000=4', | |
'2222=0', | |
'3333=0', | |
'5555=0', | |
'8193=3', | |
'8096=5', | |
'7777=0', | |
'9999=4', | |
'7756=1', | |
'6855=3', | |
'9881=5', | |
'5531=0' | |
] | |
coefficients = [] | |
constants = [] | |
for input in inputs: | |
lhs, rhs = get_values(input) | |
coefficients.append(lhs) | |
constants.append(rhs) | |
solution = lin.lstsq(coefficients, constants) | |
print ['%d maps to %d' % (i, val) for i, val in enumerate(map(int, solution[0]))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment