Syncing z2

This commit is contained in:
Jed
2021-12-12 10:22:52 -05:00
parent a95a96ad74
commit 42f2be833f
9 changed files with 1890 additions and 1002 deletions

View File

@@ -51,10 +51,10 @@ for one_item in working_list:
if one_item['ecl'] in ['amb', 'blu', 'brn', 'gry', 'grn','hzl', 'oth']:
test_check += 1
test_str = test_str + "eye|"
if set('0123456789').issubset(one_item['pid']) and len(one_item['pid']) == 9:
if len(one_item['pid']) == 9:
test_check += 1
test_str = test_str + "passport|"
if test_check == 8:
if test_check == 7:
valid_count += 1
print(test_check)
print(test_str)

File diff suppressed because it is too large Load Diff

49
2021/04-1.py Normal file
View File

@@ -0,0 +1,49 @@
class Board:
def __init__(self, board):
self.board = board
self.width = len(self.board[0])
self.height = len(self.board)
self.matches = [[False] * self.width for _ in range(self.height)]
self.last_number = 0
def check_number(self, number):
self.last_number = number
for i in range(self.width):
for j in range(self.height):
if self.board[i][j] == number:
self.matches[i][j] = True
def check_win(self):
return (any(all(row) for row in self.matches) or
any(all(col) for col in zip(*self.matches)))
def sum_score(self):
match_sum = 0
for i in range(self.width):
for j in range(self.height):
if not self.matches[i][j]:
match_sum += int(self.board[i][j])
return match_sum
with open('2021/04.input') as f:
numbers, *boards = f.read().rstrip().split('\n\n')
numbers = [int(num) for num in numbers.split(',')]
boards = [[line.split() for line in board.split('\n')] for board in boards]
boards = [[[int(elt) for elt in line] for line in board] for board in boards]
boards = [Board(board) for board in boards]
winners = []
for number in numbers:
for i in range(len(boards) - 1, -1, -1):
boards[i].check_number(number)
if boards[i].check_win():
winners.append(boards[i])
boards.pop(i)
first = winners[0]
last = winners[-1]
print(first.sum_score() * first.last_number)
print(last.sum_score() * last.last_number)

601
2021/04.input Normal file
View File

@@ -0,0 +1,601 @@
6,69,28,50,36,84,49,13,48,90,1,33,71,0,94,59,53,58,60,96,30,34,29,91,11,41,77,95,17,80,85,93,7,9,74,89,18,25,26,8,87,38,68,5,12,43,27,46,62,73,16,55,22,4,65,76,54,52,83,10,21,67,15,47,45,40,35,66,79,51,75,39,64,24,37,72,3,44,82,32,78,63,57,2,86,31,19,92,14,97,20,56,88,81,70,61,42,99,23,98
22 59 7 10 6
33 36 96 55 23
13 85 18 29 28
75 46 83 73 58
34 40 87 56 98
73 96 47 14 10
28 11 79 84 20
74 30 0 59 71
80 93 42 22 17
44 2 81 29 15
73 32 37 93 39
2 87 38 99 97
15 12 42 49 33
9 23 25 94 19
57 4 18 70 79
43 79 59 71 78
51 97 37 28 26
46 21 84 8 86
96 30 17 34 49
55 90 99 75 61
43 86 35 51 24
16 25 29 21 3
2 13 4 36 54
89 27 8 85 34
96 59 65 14 56
5 57 43 4 1
86 80 67 30 20
22 16 99 0 14
40 25 59 91 54
82 95 96 37 24
97 20 87 66 21
25 40 9 78 89
52 75 95 63 62
32 43 13 47 69
53 48 56 29 4
24 4 65 12 8
76 3 81 99 49
45 33 31 66 34
17 94 75 35 88
64 10 7 93 95
88 20 99 15 83
81 40 5 6 98
49 74 18 27 9
43 69 28 37 71
87 82 90 14 47
21 97 92 42 60
11 65 98 95 29
2 49 75 20 74
56 40 78 66 81
68 4 46 77 61
26 14 39 76 11
41 74 34 91 4
51 9 97 29 75
83 86 23 35 77
90 2 49 30 89
34 97 0 22 15
65 60 82 66 47
30 9 49 95 48
54 73 67 17 78
33 96 44 1 32
90 29 10 49 63
8 26 95 61 0
54 13 51 12 44
32 48 16 47 84
55 46 93 14 3
68 55 46 16 54
97 59 49 6 21
52 32 15 96 70
57 56 61 51 0
40 31 62 24 48
75 56 70 42 14
77 9 23 62 25
29 27 54 17 2
55 72 43 15 96
45 30 88 86 1
65 12 22 6 51
77 81 15 91 19
80 71 27 89 52
75 92 41 83 57
40 44 66 84 98
89 80 73 59 18
74 55 67 71 10
78 27 37 57 3
92 26 17 5 72
52 83 28 76 51
64 0 87 4 13
14 43 42 62 31
17 84 72 91 83
53 80 59 61 74
47 22 38 28 77
65 49 91 94 19
25 81 64 57 9
50 95 82 12 66
53 54 85 36 11
31 56 83 18 60
6 12 76 37 33
14 96 16 31 40
17 82 27 94 83
1 50 49 9 54
29 70 59 91 77
85 0 33 41 16
7 86 80 53 65
94 19 28 35 32
4 55 93 97 63
83 22 67 56 36
28 70 65 17 19
88 51 15 73 12
11 49 80 23 42
26 54 90 75 29
74 77 91 86 66
88 22 83 10 43
57 34 15 23 8
94 42 68 67 37
84 3 6 71 62
89 45 72 55 38
68 27 93 7 15
85 96 1 56 6
32 2 30 55 17
99 90 37 80 50
77 78 58 98 57
5 95 22 13 97
19 2 52 92 20
75 49 86 31 41
51 63 56 33 10
82 27 79 94 57
15 44 91 26 4
41 78 53 95 86
90 92 46 56 33
80 93 68 66 70
36 10 38 0 6
11 47 52 64 17
16 60 39 55 78
46 18 33 83 35
13 92 4 23 50
40 5 29 6 90
20 60 2 23 74
43 39 91 75 12
58 67 50 29 79
10 40 92 95 25
13 24 53 72 36
69 64 15 53 86
61 11 48 71 27
26 93 38 70 73
96 29 30 98 45
13 7 31 59 84
13 55 50 54 57
32 24 45 5 77
82 86 0 4 99
75 72 14 40 56
76 94 89 17 30
66 71 86 41 0
80 64 3 29 78
23 21 42 99 87
96 60 75 61 49
2 83 85 12 1
78 96 4 82 6
73 36 57 99 8
11 83 15 35 30
85 87 25 22 66
32 64 16 50 43
6 39 55 2 4
1 61 99 71 80
46 88 22 31 60
62 66 37 97 76
74 34 10 52 24
42 38 13 65 12
4 39 60 62 21
81 99 1 69 40
59 15 11 95 53
91 78 72 30 73
43 68 82 72 2
34 92 33 97 89
63 70 9 0 45
69 10 12 65 21
40 20 55 57 49
41 22 8 16 49
71 64 19 65 92
17 10 26 36 29
30 88 7 54 11
77 55 70 72 47
15 94 90 6 39
99 55 16 54 91
18 7 82 44 51
25 34 83 14 12
30 2 77 27 66
44 50 74 97 58
87 42 56 92 28
49 82 52 17 78
54 89 63 77 27
83 14 24 16 84
47 32 8 55 22
19 14 24 82 4
76 73 9 10 64
40 6 92 67 17
68 44 43 3 54
26 10 9 92 81
46 98 13 0 14
68 99 35 18 72
74 33 22 61 93
80 38 71 6 75
17 23 54 55 22
10 8 60 76 24
71 28 16 62 82
13 12 21 78 39
26 66 89 64 79
72 12 91 79 99
84 18 37 98 41
10 71 88 23 24
11 34 26 83 74
58 27 77 5 8
9 90 13 0 46
6 58 74 92 8
75 77 56 76 80
55 60 44 68 91
67 28 96 66 18
14 26 54 21 35
69 67 16 76 62
78 45 87 44 94
27 89 39 85 28
3 81 93 64 74
10 28 35 84 76
40 11 95 59 57
53 4 24 50 45
7 43 78 17 81
1 74 82 16 27
6 26 72 53 52
51 91 80 11 18
20 63 74 25 33
79 4 8 59 67
3 13 55 81 83
98 85 27 84 42
90 15 17 61 34
40 64 86 96 45
59 47 53 5 35
11 7 41 80 13
47 48 54 31 76
99 32 98 20 15
61 41 30 94 37
34 59 86 55 45
9 83 92 53 3
3 80 24 94 25
17 23 64 76 71
20 97 0 56 72
95 73 28 59 21
14 81 46 67 88
2 95 5 38 90
63 62 11 24 34
19 31 57 84 80
47 86 36 85 74
13 39 73 94 42
28 6 60 34 15
63 36 51 30 92
43 10 7 88 49
78 76 31 19 66
22 20 35 45 79
19 42 49 57 73
99 50 97 93 43
67 52 40 16 33
2 55 0 71 46
21 75 59 66 83
19 86 30 25 3
32 39 65 54 29
38 6 85 52 13
43 95 18 44 15
53 70 16 31 71
68 73 74 83 70
56 15 12 78 4
43 87 63 90 86
41 16 23 17 77
80 14 61 30 50
88 28 45 80 65
64 11 68 33 27
29 70 44 82 37
42 66 9 32 87
10 24 15 3 46
99 81 5 62 97
4 36 23 38 35
42 16 37 98 54
34 41 25 30 48
8 60 63 89 72
25 33 94 23 14
45 10 79 30 3
22 28 95 27 11
74 13 39 84 83
72 88 56 53 97
31 92 91 84 71
54 90 89 80 0
98 96 65 66 68
35 39 70 11 82
15 34 42 52 2
68 71 86 82 37
28 48 12 34 54
62 55 10 25 89
60 4 50 21 22
3 2 18 40 84
18 96 95 47 45
14 51 2 88 43
94 56 19 15 8
48 65 62 6 75
35 28 25 72 30
43 85 69 92 26
61 75 5 73 66
16 87 4 99 48
18 19 79 23 83
37 88 31 38 40
23 10 89 84 76
45 39 62 55 66
25 73 79 43 60
12 69 36 93 71
9 77 14 58 49
9 24 26 53 79
99 15 30 50 16
14 95 12 25 33
54 40 58 46 66
5 23 39 29 48
64 67 11 10 92
59 99 80 97 66
45 51 88 47 82
35 27 72 85 16
54 58 2 1 52
10 97 27 54 66
89 85 39 99 98
8 68 95 51 19
4 17 79 87 3
72 43 76 58 33
95 72 0 18 17
3 42 24 86 34
52 79 46 58 98
76 77 78 19 10
81 61 88 85 54
74 70 15 80 72
77 89 11 19 22
34 59 56 65 91
58 6 50 40 16
93 30 95 26 85
47 62 57 6 25
40 79 22 95 29
42 11 70 10 92
60 53 84 96 17
75 86 74 89 18
30 42 4 19 92
40 58 72 7 70
17 98 45 76 50
93 57 65 79 2
56 94 73 84 62
51 0 14 7 53
63 36 48 81 84
50 22 11 88 6
83 99 21 31 91
86 17 72 42 94
83 0 20 26 7
42 24 37 86 65
73 82 63 21 27
30 35 9 47 80
79 53 3 14 84
50 99 83 86 42
81 36 24 4 76
0 71 66 41 57
7 54 94 78 97
12 8 82 45 31
4 91 57 50 37
22 46 86 24 26
39 54 48 7 42
2 45 95 29 12
38 25 52 0 72
51 94 46 44 62
95 60 0 48 61
38 13 85 32 8
22 56 53 30 80
43 65 58 68 88
49 76 41 43 51
57 46 45 82 90
48 33 36 5 23
81 30 3 61 75
56 70 29 91 59
58 74 50 47 84
2 1 62 36 60
32 16 95 43 27
79 12 39 56 11
9 33 4 25 61
23 84 16 51 39
72 19 53 64 43
9 44 10 52 26
45 68 29 56 74
62 42 46 95 0
16 83 27 85 56
13 41 49 79 53
18 63 7 60 3
45 15 48 69 29
46 86 35 34 32
85 2 96 15 43
33 30 29 53 98
21 55 61 73 40
31 4 66 75 59
26 32 91 38 80
69 81 65 30 77
82 22 83 0 38
2 3 29 47 94
42 55 9 18 97
53 45 90 31 44
23 86 0 35 84
27 80 3 64 12
1 96 48 93 85
69 24 61 15 22
91 72 62 13 76
81 51 67 60 16
65 48 86 39 97
92 93 49 77 59
15 94 88 52 19
80 83 23 61 4
47 84 46 79 55
92 38 65 42 76
9 58 26 95 86
30 49 56 69 59
94 4 25 89 44
73 10 29 0 48
56 40 19 84 61
52 31 25 86 21
79 55 53 51 5
81 9 35 72 15
41 95 30 58 73
26 80 4 21 96
61 92 76 93 74
2 69 60 8 20
46 98 70 72 83
1 99 31 4 86
93 64 8 43 61
33 36 75 90 50
52 13 3 42 34
22 65 60 18 76
17 63 6 66 92
51 67 86 88 18
82 83 32 74 30
5 33 9 28 61
72 75 25 23 60
43 28 40 53 52
54 12 77 10 83
21 44 63 0 1
15 22 33 49 2
80 41 3 46 55
1 97 75 37 4
47 33 13 21 40
27 62 15 90 30
11 83 63 36 35
0 12 60 91 42
0 45 17 88 18
66 10 63 62 8
36 5 47 39 67
21 3 61 29 19
82 58 33 6 59
37 92 69 56 52
46 66 20 78 13
83 99 16 31 0
36 35 2 68 9
70 82 94 96 29
62 65 85 37 3
74 95 34 96 58
15 33 49 21 93
19 83 66 6 25
81 84 23 0 76
95 84 71 92 52
54 36 66 59 82
0 76 32 45 83
69 27 25 88 38
81 96 63 4 61
73 51 28 48 40
3 38 11 14 35
66 91 86 20 81
53 39 46 71 1
97 60 21 93 23
92 70 4 60 95
58 49 20 15 25
55 68 21 84 80
56 41 82 23 19
30 74 65 27 29
81 97 68 46 75
62 73 63 36 41
1 5 91 84 37
45 92 20 49 7
25 26 3 88 56
25 9 94 37 26
44 58 84 91 38
39 46 57 98 50
96 42 73 24 70
71 32 53 48 13
98 72 25 96 77
80 64 88 53 23
21 37 45 24 18
41 86 59 68 5
76 50 36 26 12
77 79 88 74 12
21 9 85 26 68
11 62 64 4 5
47 33 76 63 87
55 19 2 60 95
74 79 30 14 35
90 52 17 29 63
18 69 78 34 26
92 42 85 71 56
12 2 5 0 98

100
2021/04.py Normal file
View File

@@ -0,0 +1,100 @@
import json
def test_winner(board, drawn_numbers):
for one_combination in board['winning_combinations']:
total = 0
if set(one_combination).issubset(set(drawn_numbers)):
for one_number in one_bingo['numbers']:
if one_number not in drawn_numbers:
total += int(one_number)
return int(total) * int(drawn_numbers[-1])
return -1
with open('./2021/04.input', 'r') as input_file:
# with open('./2021/04.test', 'r') as input_file:
input_data = input_file.read()
number_list = input_data.split('\n\n')[0].split(',')
print(number_list)
bingo_boards = input_data.split('\n\n')[1:]
bingo_dicts = []
for one_board in bingo_boards:
one_bingo = {}
one_bingo['numbers'] = []
one_bingo['winning_combinations'] = []
rows = one_board.split('\n')
for row in range(len(rows)):
columns = rows[row].split(' ')
columns = list(filter("".__ne__, columns))
one_bingo['numbers'].extend(columns)
one_bingo['winning_combinations'].append(columns)
for column in range(len(columns)):
winning_column = []
for row in range(len(rows)):
print(row, column, row * column)
winning_column.append(one_bingo['numbers'][row * len(columns) + column])
print(winning_column)
one_bingo['winning_combinations'].append(winning_column)
bingo_dicts.append(one_bingo)
# Find a winning board.
winner_found = False
for i in range(4, len(number_list)):
drawn_numbers = number_list[:i]
print("Drawn numbers", drawn_numbers)
for one_bingo in bingo_dicts:
for one_combination in one_bingo['winning_combinations']:
total = 0
if set(one_combination).issubset(set(drawn_numbers)):
# Get the board
print("Winning Combination", one_combination)
print("Winning Board", one_bingo['numbers'])
one_bingo['numbers'].sort()
print("Winning Sorted", one_bingo['numbers'])
for one_number in one_bingo['numbers']:
if one_number not in drawn_numbers:
total += int(one_number)
print(total)
winner_found = True
print(total, drawn_numbers[-1], int(total) * int(drawn_numbers[-1]))
if winner_found:
break
if winner_found:
break
if winner_found:
break
boards_left = bingo_dicts.copy()
for i in range(4, len(number_list)):
drawn_numbers = number_list[:i]
# Test for winner. If winner, eliminate.
for one_board in range(len(boards_left) - 1, 0, -1):
total = 0
for one_combination in boards_left[one_board]:
if set(one_combination).issubset(set(drawn_numbers)) and len(boards_left) > 1:
# Remove the board
del boards_left[one_board]
for one_number in one_bingo['numbers']:
if one_number not in drawn_numbers:
total += int(one_number)
print(len(boards_left))
print(total)
winner_found = True
print(total, drawn_numbers[-1], int(total) * int(drawn_numbers[-1]))

19
2021/04.test Normal file
View File

@@ -0,0 +1,19 @@
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
9 18 13 17 5
19 8 7 25 23
20 11 10 24 4
14 21 16 12 6
14 21 17 24 4
10 16 15 9 19
18 8 23 26 20
22 11 13 6 5
2 0 12 3 7

500
2021/05.input Normal file
View File

@@ -0,0 +1,500 @@
445,187 -> 912,654
820,46 -> 25,841
216,621 -> 458,379
955,898 -> 67,10
549,572 -> 549,520
796,107 -> 109,794
729,698 -> 338,698
11,987 -> 968,30
381,840 -> 381,409
80,467 -> 80,48
132,197 -> 132,92
343,96 -> 343,710
42,854 -> 346,550
503,56 -> 804,56
599,206 -> 60,206
702,920 -> 474,920
496,790 -> 223,517
969,579 -> 583,579
897,66 -> 604,66
484,754 -> 640,910
330,49 -> 949,49
908,132 -> 714,132
517,153 -> 97,573
317,865 -> 678,504
800,61 -> 800,51
179,242 -> 179,202
529,757 -> 529,838
288,953 -> 393,953
372,15 -> 925,568
100,85 -> 654,639
663,562 -> 737,636
576,981 -> 245,981
347,240 -> 347,928
91,119 -> 413,441
637,397 -> 330,90
534,257 -> 950,257
155,636 -> 694,97
539,274 -> 539,327
329,795 -> 824,300
103,51 -> 961,909
87,868 -> 168,787
21,250 -> 157,386
591,316 -> 670,395
722,670 -> 630,670
28,167 -> 28,489
480,210 -> 68,622
573,700 -> 354,919
186,59 -> 700,59
121,186 -> 670,186
797,985 -> 671,985
836,804 -> 335,804
701,835 -> 104,238
456,718 -> 456,964
694,891 -> 694,839
205,637 -> 205,318
40,958 -> 773,225
151,391 -> 151,779
693,894 -> 417,894
418,700 -> 656,700
196,985 -> 896,985
357,509 -> 608,258
552,558 -> 552,482
184,412 -> 170,412
122,746 -> 643,225
268,930 -> 247,930
979,820 -> 407,248
755,893 -> 845,893
706,843 -> 706,225
162,726 -> 895,726
140,888 -> 289,888
614,432 -> 903,721
272,725 -> 272,598
529,672 -> 967,234
903,989 -> 785,871
422,355 -> 422,360
313,722 -> 713,322
460,121 -> 460,151
55,944 -> 946,944
795,744 -> 221,744
816,953 -> 471,953
865,186 -> 557,186
94,976 -> 747,323
302,961 -> 811,452
361,966 -> 921,406
197,988 -> 571,988
310,905 -> 722,493
699,91 -> 272,518
295,306 -> 84,95
220,116 -> 395,291
183,364 -> 523,364
16,986 -> 16,319
54,980 -> 635,399
340,110 -> 651,421
788,76 -> 788,635
933,375 -> 458,375
12,434 -> 494,916
253,892 -> 962,183
240,508 -> 240,234
763,934 -> 506,677
308,135 -> 239,66
117,649 -> 751,15
95,535 -> 428,868
16,937 -> 902,51
547,404 -> 547,830
128,581 -> 970,581
959,810 -> 564,415
971,738 -> 378,145
919,210 -> 295,210
737,43 -> 231,43
82,577 -> 455,204
821,337 -> 570,337
688,753 -> 538,753
891,844 -> 124,844
74,957 -> 946,85
43,942 -> 43,210
100,391 -> 100,142
975,527 -> 175,527
510,844 -> 395,959
558,231 -> 558,858
839,915 -> 262,338
784,290 -> 875,199
644,824 -> 812,824
899,657 -> 500,657
263,668 -> 263,964
157,374 -> 820,374
530,301 -> 530,67
15,688 -> 15,572
216,844 -> 479,581
973,59 -> 68,964
104,92 -> 104,547
421,472 -> 421,176
887,805 -> 231,149
140,980 -> 852,980
248,602 -> 346,602
334,961 -> 334,471
892,892 -> 958,958
270,83 -> 270,135
950,105 -> 404,651
979,476 -> 930,427
416,430 -> 879,430
796,937 -> 796,415
670,679 -> 72,679
733,884 -> 733,302
745,196 -> 306,196
174,353 -> 667,846
285,978 -> 254,978
10,63 -> 936,989
242,107 -> 242,725
238,341 -> 238,800
975,102 -> 174,903
530,474 -> 530,853
931,47 -> 467,47
86,141 -> 821,141
263,15 -> 654,15
688,542 -> 378,232
826,793 -> 989,793
729,285 -> 729,192
587,915 -> 587,79
548,667 -> 877,667
15,836 -> 783,68
662,673 -> 71,82
312,681 -> 910,83
760,418 -> 491,418
175,502 -> 443,502
817,878 -> 29,90
798,569 -> 811,582
703,141 -> 743,181
941,849 -> 941,778
63,24 -> 500,461
697,183 -> 119,761
705,672 -> 152,672
150,567 -> 656,567
158,411 -> 965,411
702,872 -> 276,446
141,179 -> 741,779
533,886 -> 817,886
569,949 -> 285,949
699,764 -> 699,780
333,863 -> 805,391
861,804 -> 524,467
791,501 -> 718,501
976,265 -> 976,713
129,342 -> 339,132
322,738 -> 212,738
700,534 -> 622,456
68,314 -> 14,314
146,112 -> 215,181
170,211 -> 482,211
159,412 -> 159,32
312,939 -> 312,95
232,18 -> 912,698
950,114 -> 950,826
620,848 -> 620,11
624,288 -> 544,208
752,479 -> 752,577
784,796 -> 784,872
130,55 -> 974,899
434,82 -> 434,481
988,230 -> 892,134
159,252 -> 159,291
462,14 -> 462,977
553,981 -> 553,390
231,936 -> 51,936
58,759 -> 60,759
572,891 -> 584,891
705,303 -> 124,303
144,894 -> 970,68
865,275 -> 865,956
492,491 -> 470,491
971,15 -> 977,15
750,521 -> 33,521
913,947 -> 387,421
368,677 -> 570,677
795,186 -> 882,186
404,840 -> 678,840
187,488 -> 403,488
824,706 -> 642,706
330,541 -> 330,195
564,531 -> 774,531
271,857 -> 20,606
976,975 -> 976,843
323,341 -> 21,39
575,643 -> 267,643
827,295 -> 827,854
749,486 -> 749,780
656,716 -> 656,470
635,187 -> 417,187
503,488 -> 503,393
592,688 -> 592,567
515,408 -> 128,795
608,158 -> 780,158
677,96 -> 11,762
127,452 -> 339,452
117,985 -> 291,811
157,371 -> 157,916
640,758 -> 983,758
906,413 -> 906,776
224,842 -> 627,439
903,728 -> 903,459
358,138 -> 822,602
30,16 -> 929,915
440,900 -> 294,900
809,73 -> 987,73
55,410 -> 304,161
441,672 -> 315,672
939,40 -> 234,40
334,698 -> 309,698
572,738 -> 572,226
445,71 -> 445,468
225,660 -> 427,458
390,320 -> 449,320
507,635 -> 507,169
47,116 -> 738,807
127,14 -> 689,14
316,760 -> 316,432
831,101 -> 250,682
370,807 -> 370,898
678,186 -> 491,186
866,83 -> 539,83
518,848 -> 518,962
188,135 -> 81,28
378,226 -> 597,226
646,534 -> 141,534
275,672 -> 275,854
67,421 -> 676,421
386,323 -> 988,323
903,984 -> 10,91
37,348 -> 529,840
872,134 -> 358,648
42,826 -> 42,822
688,922 -> 21,922
47,539 -> 942,539
739,483 -> 375,847
23,217 -> 800,217
589,512 -> 589,953
292,229 -> 107,229
873,678 -> 873,770
794,295 -> 739,240
464,559 -> 936,559
685,736 -> 368,736
114,941 -> 114,307
571,643 -> 74,643
281,185 -> 273,177
497,937 -> 497,469
152,815 -> 702,815
76,43 -> 980,947
272,149 -> 101,149
934,945 -> 107,118
532,476 -> 759,476
955,942 -> 397,942
31,918 -> 931,18
790,420 -> 389,420
36,496 -> 215,317
252,209 -> 139,209
704,148 -> 719,133
413,571 -> 165,571
690,433 -> 864,607
976,417 -> 517,876
803,568 -> 443,568
335,558 -> 335,334
405,807 -> 691,521
194,482 -> 486,190
377,856 -> 377,802
313,842 -> 313,254
449,961 -> 198,710
197,916 -> 197,797
82,965 -> 959,88
371,239 -> 829,697
471,70 -> 596,70
835,144 -> 835,950
283,486 -> 506,486
147,29 -> 147,747
187,485 -> 187,195
781,144 -> 480,144
801,839 -> 925,715
415,960 -> 415,442
877,939 -> 29,91
22,118 -> 22,439
460,315 -> 450,315
982,960 -> 71,49
105,231 -> 105,331
98,174 -> 551,174
721,978 -> 38,295
167,290 -> 167,133
218,158 -> 218,908
819,812 -> 758,812
123,92 -> 123,132
66,721 -> 66,906
478,441 -> 967,930
284,58 -> 464,58
958,15 -> 37,936
310,337 -> 359,288
212,763 -> 212,373
101,279 -> 101,267
622,409 -> 106,925
318,657 -> 318,432
938,631 -> 938,650
142,881 -> 254,881
848,987 -> 848,451
686,223 -> 481,223
124,248 -> 812,248
246,267 -> 246,148
96,670 -> 324,442
645,888 -> 385,628
417,555 -> 417,858
543,495 -> 543,150
73,350 -> 440,717
459,704 -> 459,179
871,493 -> 871,764
911,34 -> 64,881
544,791 -> 703,791
447,218 -> 62,218
202,649 -> 396,649
935,916 -> 55,36
124,408 -> 477,761
608,850 -> 484,850
935,876 -> 582,876
377,612 -> 269,612
413,727 -> 365,679
64,451 -> 850,451
684,807 -> 357,807
323,364 -> 372,364
887,300 -> 419,300
837,831 -> 837,927
294,255 -> 768,729
878,23 -> 141,760
36,627 -> 157,627
824,703 -> 824,968
356,109 -> 657,109
799,266 -> 313,752
71,600 -> 650,21
564,863 -> 564,54
36,720 -> 109,720
318,488 -> 682,488
249,350 -> 979,350
560,502 -> 255,502
132,327 -> 132,246
287,906 -> 791,906
818,110 -> 818,882
937,17 -> 113,841
50,710 -> 673,87
702,952 -> 702,533
666,552 -> 611,552
612,962 -> 112,462
260,529 -> 351,529
440,313 -> 440,663
605,341 -> 405,141
277,287 -> 461,287
268,890 -> 268,92
764,526 -> 877,639
165,697 -> 832,697
240,716 -> 801,155
872,429 -> 578,429
88,816 -> 338,816
981,881 -> 981,138
457,351 -> 457,679
850,526 -> 850,447
139,449 -> 165,449
127,544 -> 127,934
160,890 -> 745,305
526,113 -> 303,336
17,500 -> 17,621
796,311 -> 181,926
260,218 -> 787,218
536,989 -> 536,261
257,826 -> 257,180
531,37 -> 531,493
961,942 -> 206,187
536,668 -> 536,868
154,967 -> 154,931
808,317 -> 808,873
487,258 -> 599,258
59,962 -> 802,219
322,945 -> 322,837
378,973 -> 33,628
668,556 -> 691,556
819,728 -> 787,728
484,261 -> 484,874
333,271 -> 278,271
733,515 -> 741,523
775,854 -> 523,602
67,215 -> 616,215
951,685 -> 951,433
372,105 -> 372,494
917,788 -> 917,23
890,584 -> 245,584
748,276 -> 893,276
733,721 -> 733,747
225,908 -> 897,908
437,140 -> 423,140
456,513 -> 136,833
413,135 -> 413,596
143,245 -> 879,981
870,639 -> 942,639
28,175 -> 696,843
393,303 -> 393,197
169,986 -> 458,986
43,44 -> 952,953
236,405 -> 60,229
266,845 -> 292,845
529,98 -> 95,532
95,658 -> 695,658
368,454 -> 112,710
506,776 -> 662,776
928,494 -> 604,170
179,138 -> 900,859
45,560 -> 408,197
655,654 -> 37,36
56,432 -> 56,456
844,614 -> 844,898
240,191 -> 240,112
639,911 -> 213,911
47,887 -> 830,104
57,50 -> 977,970
899,928 -> 111,928
962,676 -> 962,518
129,585 -> 469,245
988,775 -> 988,553
417,344 -> 842,769
468,110 -> 506,72
687,204 -> 687,345
828,553 -> 765,490
75,894 -> 75,93
26,798 -> 11,783
967,44 -> 967,478
240,481 -> 947,481
794,254 -> 162,254
502,944 -> 812,944
331,417 -> 410,417
850,275 -> 850,980
671,130 -> 671,941
240,99 -> 240,381
771,399 -> 318,399
946,11 -> 28,929
731,939 -> 824,846
268,71 -> 832,635
968,37 -> 968,642
935,365 -> 515,365
199,792 -> 932,792
32,116 -> 371,116
324,67 -> 941,67
453,181 -> 453,128
958,982 -> 115,139
962,168 -> 154,976
474,215 -> 333,215
458,675 -> 458,315
577,302 -> 300,302
704,493 -> 704,876
887,549 -> 887,439
81,328 -> 724,328
575,490 -> 670,490
576,17 -> 576,218
21,46 -> 963,988
532,235 -> 532,615
796,213 -> 796,407
55,948 -> 980,23
775,471 -> 272,471
26,138 -> 344,138
635,518 -> 915,518
727,365 -> 727,216

8
2021/05.py Normal file
View File

@@ -0,0 +1,8 @@
import sys
from collections import Counter
with open('./2021/05.input', 'r') as f:
# with open('./2021/05.test', 'r') as f:
f = [[list(map(int, y.split(','))) for y in x.split("->")] for x in f.read().splitlines()]
print(sum([1 for k, v in Counter([item for sublist in [[(x, y) for x in range(min(x0, x1), max(x0, x1) + 1) for y in range(min(y0, y1), max(y0, y1) + 1) if ((x - x0) * (y1 - y0) - (y - y0) * (x1 - x0)) == 0] for (x0, y0), (x1, y1) in f if x0 == x1 or y0 == y1] for item in sublist]).items() if v >= 2]))
print(sum([1 for k, v in Counter([item for sublist in [[(x, y) for x in range(min(x0, x1), max(x0, x1) + 1) for y in range(min(y0, y1), max(y0, y1) + 1) if ((x - x0) * (y1 - y0) - (y - y0) * (x1 - x0)) == 0] for (x0, y0), (x1, y1) in f] for item in sublist]).items() if v >= 2]))

10
2021/05.test Normal file
View File

@@ -0,0 +1,10 @@
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2