File tree 2 files changed +2259
-0
lines changed
2 files changed +2259
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ #initial
4
+ def findDeclarations (text ):
5
+ declarations = {}
6
+ for line in text :
7
+ line = line [:- 1 ]
8
+ for i in range (len (line )):
9
+ declarations [line [i ]] = True
10
+
11
+ return len (declarations .keys ())
12
+
13
+ with open ("6.txt" ) as file :
14
+ total = 0
15
+ groups = 0
16
+
17
+ lines = file .readlines ()
18
+ text = []
19
+ for line in lines :
20
+ if len (line ) < 2 :
21
+ groups = groups + 1
22
+ total = total + findDeclarations (text )
23
+ text = []
24
+ else :
25
+ text .append (line )
26
+ groups = groups + 1
27
+ total = total + findDeclarations (text )
28
+
29
+ print (total , groups )
30
+
31
+ #part2
32
+ def findUniqueDeclarations (text ):
33
+ declarations = {}
34
+ for line in text :
35
+ line = line [:- 1 ]
36
+ for i in range (len (line )):
37
+ if line [i ] in declarations :
38
+ declarations [line [i ]] = declarations [line [i ]] + 1
39
+ else :
40
+ declarations [line [i ]] = 1
41
+ all = []
42
+ for key in declarations :
43
+ if declarations [key ] == len (text ):
44
+ all .append (key )
45
+
46
+ return len (all )
47
+
48
+ with open ("6.txt" ) as file :
49
+ total = 0
50
+ groups = 0
51
+
52
+ lines = file .readlines ()
53
+ text = []
54
+ for line in lines :
55
+ if len (line ) < 2 :
56
+ groups = groups + 1
57
+ total = total + findUniqueDeclarations (text )
58
+ text = []
59
+ else :
60
+ text .append (line )
61
+ groups = groups + 1
62
+ total = total + findUniqueDeclarations (text )
63
+
64
+ print (total , groups )
You can’t perform that action at this time.
0 commit comments