First day and template
This commit is contained in:
1 parent
897400f921
commit
f617998624
7 files changed
+1114
No files matched your search
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, re
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
words = [line.strip('\n') for line in open(sys.argv[1])]
|
||||
nums = [int(re.sub('[abcdefghijklmnopqrstuvwxyz]','',line)) for line in words]
|
||||
|
||||
# challenge 1
|
||||
res1 = 0
|
||||
for n in nums:
|
||||
if 9 < n < 100: res1 += n
|
||||
elif n < 10: res1 += n * 11
|
||||
else: res1 += int(''.join(re.findall(r'(\d).*(\d)',str(n))[0]))
|
||||
|
||||
res1 = str(res1)
|
||||
print("challenge 1:" + "\n" + res1 + "\n")
|
||||
|
||||
# challenge 2
|
||||
|
||||
## reformat, but keep in mind there may be overlap!!
|
||||
words = [re.sub('one','o1e',line) for line in words]
|
||||
words = [re.sub('two','t2o',line) for line in words]
|
||||
words = [re.sub('three','t3e',line) for line in words]
|
||||
words = [re.sub('four','f4r',line) for line in words]
|
||||
words = [re.sub('five','f5e',line) for line in words]
|
||||
words = [re.sub('six','s6x',line) for line in words]
|
||||
words = [re.sub('seven','s7n',line) for line in words]
|
||||
words = [re.sub('eight','e8t',line) for line in words]
|
||||
words = [re.sub('nine','n9e',line) for line in words]
|
||||
|
||||
## same as above
|
||||
nums = [int(re.sub('[abcdefghijklmnopqrstuvwxyz]','',line)) for line in words]
|
||||
|
||||
res2 = 0
|
||||
for n in nums:
|
||||
if 9 < n < 100: res2 += n
|
||||
elif n < 10: res2 += n * 11
|
||||
else: res2 += int(''.join(re.findall(r'(\d).*(\d)',str(n))[0]))
|
||||
|
||||
res2 = str(res2)
|
||||
print("challenge 2:" + "\n" + res2 + "\n")
|
||||
|
||||
Reference in new issue
Block a user