def extract(s): s = s.replace('O', '0').replace('o', '0').replace('l', '1') s = [ x for x in list(s.upper()) if m('[0-9A-Z]', x) ] d = [] for i, e in enumerate(zip(s, s[1:])): if e == ('1', '0'): s[i] = '10' d.append(i+1) for e in d[::-1]: del s[e] if any(map(lambda x: not m(r'^[4-9SM]|10$', x), s)): return None return s
def extract(s): s = s.replace('O', '0').replace('o', '0').replace('l', '1') s = [x for x in list(s.upper()) if m('[0-9A-Z]', x)] d = [] for i, e in enumerate(zip(s, s[1:])): if e == ('1', '0'): s[i] = '10' d.append(i + 1) for e in d[::-1]: del s[e] if any(map(lambda x: not m(r'^[4-9SM]|10$', x), s)): return None return s
def extract(s): z = [] l = [] for x in p(r'[-,.\'\\\s]', '', s).replace('l', '1').replace('O', '0'): z.append(x) for i in range(1,len(z)): if z[i-1] is '1' and z[i] is '0': z[i-1] = '10' z[i] = '' for x in list(filter(None, z)): if x.isdigit() and ((int(x) >= 4 or int(x) >= 10)): l.append(x) elif m('[MSms]+', x): l += x.upper() else: return None return l
from collections import OrderedDict as o from re import match as m r = response a = [ v if v == 1 else 0 for (k, v) in o( sorted({str(k): v for (k, v) in next(r.samples()).items()}.items(), reverse=True)).items() if m('a[0-9]', k) ] b = [ v if v == 1 else 0 for (k, v) in o( sorted({str(k): v for (k, v) in next(r.samples()).items()}.items(), reverse=True)).items() if m('b[0-9]', k) ] p = [ v if v == 1 else 0 for (k, v) in o( sorted({str(k): v for (k, v) in next(r.samples()).items()}.items(), reverse=True)).items() if m('p[0-9]', k) ] a = int("".join(str(i) for i in a), 2) b = int("".join(str(i) for i in b), 2) p = int("".join(str(i) for i in p), 2) print("a = {}".format(a)) print("b = {}".format(b)) print("p = {} (should be {})".format(p, a * b))
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from collections import OrderedDict as o from re import match as m r = response a=[v if v==1 else 0 for (k,v) in o(sorted({str(k):v for (k,v) in next(r.samples()).items()}.items(),reverse=True)).items() if m('a[0-9]',k)] b=[v if v==1 else 0 for (k,v) in o(sorted({str(k):v for (k,v) in next(r.samples()).items()}.items(),reverse=True)).items() if m('b[0-9]',k)] p=[v if v==1 else 0 for (k,v) in o(sorted({str(k):v for (k,v) in next(r.samples()).items()}.items(),reverse=True)).items() if m('p[0-9]',k)] a = int("".join(str(i) for i in a), 2) b = int("".join(str(i) for i in b), 2) p = int("".join(str(i) for i in p), 2) print("a = {}".format(a)) print("b = {}".format(b)) print("p = {} (should be {})".format(p, a * b)) valid = [False] * len(list(r.samples())) for e, sample in enumerate(r.samples()): a = [v if v == 1 else 0 for (k, v) in o(sorted({str(k): v for (k, v) in sample.items()}.items(), reverse=True)).items() if m('a[0-9]', k)] b = [v if v == 1 else 0 for (k, v) in o(sorted({str(k): v for (k, v) in sample.items()}.items(), reverse=True)).items() if m('b[0-9]', k)]
def golf2(t): for i in r(1,len(t)-1): for j in r(len(t[i])-2): if m('\S \S', t[i][j:j+3]) and m('\S{3}',t[i-1][j:j+3]) and m('\S{3}',t[i+1][j:j+3]): print i, j
#!/usr/bin/env python # -*- coding: utf-8 -*- ##################################################### # # File: text_hole # Created: 2014-09-07 17:31:44 # Last Modified: # # Author: 杨秀隆 sndnyang <*****@*****.**> # sndnyang.github.io # Description: # ##################################################### from re import match as m golf3=lambda t,r=range,l=len:sum(1 for i in r(1,l(t)-1) for j in r(l(t[i])-2) if m('\S \S', t[i][j:j+3]) and m('\S{3}',t[i-1][j:j+3]) and m('\S{3}',t[i+1][j:j+3])) golf=lambda t,r=range,l=len:sum(1 for i in r(1,l(t)-1)for j in r(l(t[i])-2)if t[i][j+1]==' ' and ''.join(t[i-1+p][j:j+3]for p in r(3)).count(' ')==1) r=range def golf2(t): for i in r(1,len(t)-1): for j in r(len(t[i])-2): if m('\S \S', t[i][j:j+3]) and m('\S{3}',t[i-1][j:j+3]) and m('\S{3}',t[i+1][j:j+3]): print i, j def golf(t): c = 0 for i in r(1,len(t)-1): for j in r(len(t[i])-2):