-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing.py
44 lines (34 loc) · 1.01 KB
/
missing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
script that determines which problems I have solved but only in a different language than the given language
"""
import sys
import os
import re
from collections import defaultdict
if len(sys.argv) == 1:
sys.stderr.write('You must specify the language extension\n')
sys.exit(1)
else:
lang = sys.argv[1]
pattern = re.compile(r'^(\d{4}-[a-z0-9\-]+)(\.[a-z]{2,4})$')
ignored_extensions = (
'js', # because of JS-only problems
'sh',
'sql',
'md' # not a programming language
)
files = [
file for file in os.listdir(os.getcwd())
if re.fullmatch(pattern, file) and
not any(file.endswith(x) for x in ignored_extensions)
]
langs = defaultdict(set)
for file in files:
match = re.fullmatch(pattern, file)
if not match:
sys.stderr.write(f'{file} did not match pattern\n')
continue
langs[match.group(2)[1:]].add(file[:match.end(1)])
from functools import reduce
sol = reduce(lambda x, y: x | y, (x for x in langs.values() if x != lang))
print(sol - langs[lang])