This commit is contained in:
Stefan Harmuth 2021-12-13 06:51:26 +01:00
parent 53c472b912
commit 9fdfcf4682
4 changed files with 941 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from time import sleep from time import sleep
from tools.datafiles import JSONFile from tools.datafiles import JSONFile
from tools.irc import Client from tools.irc import Client, ServerMessage
from tools.schedule import Scheduler from tools.schedule import Scheduler
from tools.tools import human_readable_time_from_delta from tools.tools import human_readable_time_from_delta
@ -35,10 +35,10 @@ class IrcBot:
self.__session_id = open(".session", "r").readlines()[0].strip() self.__session_id = open(".session", "r").readlines()[0].strip()
self.irc_client = Client(IRC_SERVER, IRC_PORT, IRC_NICK, IRC_USER, IRC_REALNAME) self.irc_client = Client(IRC_SERVER, IRC_PORT, IRC_NICK, IRC_USER, IRC_REALNAME)
self.irc_client.join(IRC_CHANNEL) self.irc_client.join(IRC_CHANNEL)
self.irc_client.register('PRIVMSG', self.on_privmsg) self.irc_client.subscribe(ServerMessage.MSG_PRIVMSG, self.on_privmsg)
self.irc_client.subscribe(ServerMessage.RAW, self.on_raw)
self.update_leaderboard() self.update_leaderboard()
self.scheduler = Scheduler() self.scheduler = Scheduler()
self.scheduler.schedule('irc-receive', timedelta(seconds=10), self.irc_client.receive)
self.scheduler.schedule('leaderboard', timedelta(minutes=15), self.update_leaderboard) self.scheduler.schedule('leaderboard', timedelta(minutes=15), self.update_leaderboard)
def on_privmsg(self, msg_from: str, msg_to: str, message: str): def on_privmsg(self, msg_from: str, msg_to: str, message: str):
@ -101,6 +101,9 @@ class IrcBot:
self.irc_client.quit() self.irc_client.quit()
sys.exit(0) sys.exit(0)
def on_raw(self, msg_from: str, msg_type: str, msg_to: str, message: str):
print("[%s] <%s> (%s) -> <%s>: %s" % (datetime.now().strftime("%H:%M:%S"), msg_from, msg_type, msg_to, message))
def calc_scores(self): def calc_scores(self):
member_count = len([x for x in self.cache.keys() if not x.startswith("__")]) member_count = len([x for x in self.cache.keys() if not x.startswith("__")])
for day in map(str, range(1, 26)): for day in map(str, range(1, 26)):
@ -182,7 +185,8 @@ class IrcBot:
def run(self): def run(self):
while 1: while 1:
self.scheduler.run_pending() self.scheduler.run_pending()
sleep(1) self.irc_client.receive()
sleep(0.1)
if __name__ == '__main__': if __name__ == '__main__':

59
day13.py Normal file
View File

@ -0,0 +1,59 @@
from tools.aoc import AOCDay
from typing import Any
from tools.coordinate import Coordinate
from tools.grid import Grid
def buildGrid(coords: str) -> Grid:
grid = Grid(0)
for c in coords.split(";"):
x, y = map(int, c.split(","))
grid.set(Coordinate(x, y), 1)
return grid
def fold(grid: Grid, direction: str, axis: int):
if direction == "y":
for y in range(axis + 1, grid.maxY + 1):
targetY = axis - (y - axis)
for x in range(grid.minX, grid.maxX + 1):
grid.add(Coordinate(x, targetY), grid.get(Coordinate(x, y)))
grid.maxY = axis - 1
elif direction == "x":
for x in range(axis + 1, grid.maxX + 1):
targetX = axis - (x - axis)
for y in range(grid.minY, grid.maxY + 1):
grid.add(Coordinate(targetX, y), grid.get(Coordinate(x, y)))
grid.maxX = axis - 1
class Day(AOCDay):
test_solutions_p1 = [17]
test_solutions_p2 = []
def part1(self) -> Any:
coords, folds = self.getMultiLineInputAsArray(join_char=";")
grid = buildGrid(coords)
fold_1 = folds.split(";")[0]
direction, axis = fold_1.split()[-1].split("=")
fold(grid, direction, int(axis))
onCount = 0
for x in range(grid.minX, grid.maxX + 1):
for y in range(grid.minY, grid.maxY + 1):
onCount += grid.get(Coordinate(x, y)) > 0
return onCount
def part2(self) -> Any:
coords, folds = self.getMultiLineInputAsArray(join_char=";")
grid = buildGrid(coords)
for thisFold in folds.split(";"):
direction, axis = thisFold.split()[-1].split("=")
fold(grid, direction, int(axis))
grid.print(true_char='#')
return "see image above"

853
inputs/input13 Normal file
View File

@ -0,0 +1,853 @@
792,394
1124,850
1208,850
721,173
1057,252
1119,182
1017,402
485,58
773,880
1171,197
661,546
218,628
574,693
673,316
393,157
1071,822
898,826
152,574
1114,791
107,777
669,264
1292,54
1092,628
415,31
387,733
234,576
652,742
599,40
308,327
147,640
219,635
831,310
246,604
725,49
103,761
756,0
562,352
47,17
725,364
70,310
218,180
68,453
1310,100
1134,175
738,340
586,5
902,610
1064,540
900,803
1002,392
151,282
1174,357
464,406
560,385
656,732
585,754
805,189
813,197
669,581
816,322
191,712
396,495
643,394
956,462
341,182
591,372
654,856
174,571
955,352
678,268
162,754
92,318
231,544
681,425
683,640
698,271
756,217
69,306
1054,544
591,820
1168,632
293,868
70,584
796,44
607,60
639,494
47,381
984,431
248,864
915,432
151,476
84,628
924,77
1305,703
246,156
1161,252
1250,686
177,301
351,731
1228,773
743,290
928,266
1258,749
771,633
701,218
386,525
315,534
557,176
1230,610
846,14
671,481
561,546
97,88
629,148
1017,625
684,749
1133,700
244,803
1241,754
678,593
956,432
749,58
895,415
969,805
156,93
738,380
518,537
989,546
815,138
190,425
354,432
1213,168
8,627
175,870
792,842
812,530
982,431
1218,679
852,567
607,821
244,106
15,323
738,513
658,742
711,696
490,243
674,105
1295,123
1230,121
812,205
512,607
1053,770
166,124
18,54
354,462
130,852
1089,260
949,868
102,436
514,850
969,294
515,249
894,166
321,796
1228,65
0,319
831,472
567,256
259,14
1208,44
1087,285
572,737
494,180
346,327
574,816
739,14
1054,360
159,586
1289,784
1227,14
313,294
830,324
224,281
731,722
1084,252
1047,225
1049,280
1241,724
833,252
97,168
810,674
0,78
798,607
1039,422
1079,817
1191,411
1178,456
69,276
955,800
503,724
995,534
1230,773
641,40
995,170
783,397
52,145
1120,425
218,266
341,406
989,572
1046,588
798,847
308,565
468,850
689,44
353,298
1302,575
1241,276
184,849
654,879
874,189
242,236
798,728
348,38
314,362
185,222
189,329
639,379
933,777
97,768
1006,828
1203,777
756,677
909,700
308,329
75,172
703,60
1205,186
1235,274
328,185
1283,248
0,812
574,793
524,791
190,388
119,483
20,856
771,261
12,847
1099,274
637,871
661,309
753,768
1213,840
557,54
55,441
895,31
1255,483
905,868
100,448
1001,578
425,54
585,364
492,306
490,94
684,145
567,514
759,313
107,35
982,157
498,364
82,592
775,483
960,716
716,830
1031,610
591,746
716,840
815,756
1006,77
874,628
927,259
720,408
820,778
1213,768
1241,618
1231,882
629,597
1136,324
422,161
835,494
58,390
949,381
656,856
420,766
1111,397
162,530
579,172
989,479
1235,172
875,323
736,688
1247,148
144,567
239,72
341,145
525,599
1299,394
267,385
68,47
15,571
950,7
304,828
970,850
569,868
1029,852
889,388
263,673
584,103
479,472
715,609
144,327
502,403
107,117
164,116
49,777
244,66
560,161
668,47
656,879
222,436
244,408
1120,388
410,829
1292,567
341,600
92,576
753,270
1266,511
803,133
846,388
594,840
465,329
1121,565
1235,620
606,826
1154,801
479,310
560,509
219,873
1252,390
321,770
668,831
913,618
813,479
407,432
888,733
721,273
391,221
436,33
1283,808
1302,627
497,124
1151,586
326,463
1033,777
0,100
719,746
1158,570
1123,197
1081,54
421,388
184,837
539,485
551,133
72,715
141,248
980,70
1066,408
1131,761
894,728
479,24
1235,243
970,44
271,472
835,718
825,164
731,875
166,180
224,165
1213,880
142,632
293,298
157,645
263,221
1047,359
962,38
818,588
950,887
579,203
377,117
833,28
798,632
13,761
721,721
586,441
1148,82
654,364
955,542
1160,735
1037,658
47,205
574,649
1150,124
1300,768
504,607
1042,212
1039,472
644,403
324,852
848,530
463,182
584,758
1057,194
1092,413
375,732
1068,236
813,322
400,491
13,133
82,554
1148,100
328,431
410,106
458,119
571,880
45,478
848,476
656,127
585,845
1133,301
507,472
242,864
239,516
673,871
436,180
813,170
1178,438
1171,25
386,56
426,38
436,628
999,805
142,680
549,708
1052,889
1168,831
1297,294
711,521
743,828
42,271
788,8
1181,564
1295,323
187,697
982,610
579,143
895,863
264,588
1134,607
1285,746
875,635
477,28
833,866
749,721
667,276
750,665
433,858
621,492
1169,646
999,89
1266,831
572,65
726,794
43,187
550,593
557,768
0,261
989,25
805,705
321,255
1168,383
1279,147
639,413
386,838
1240,346
960,178
45,676
462,530
812,364
141,646
1176,754
1223,72
293,65
753,840
151,394
572,380
383,787
1159,758
585,140
570,628
673,764
566,504
661,863
792,264
273,684
748,679
1150,322
1156,743
102,44
1043,285
1146,116
914,495
785,599
726,100
1284,460
326,157
79,208
1208,14
465,777
134,413
656,767
1263,513
127,3
464,506
253,194
413,250
711,5
490,564
689,850
1238,43
383,259
175,724
335,143
734,42
915,686
157,724
1223,378
410,381
724,889
808,491
989,869
704,68
676,568
1006,716
890,548
60,830
170,577
1159,418
268,369
169,282
877,858
1077,500
807,700
65,721
847,182
1245,88
590,856
494,770
1168,680
855,137
915,208
1255,889
621,596
1115,523
1088,514
360,7
127,845
266,830
1159,164
218,842
151,730
792,182
1154,241
82,302
681,148
1293,871
520,140
877,708
388,837
80,793
1203,117
590,38
253,700
572,554
1305,31
1205,708
647,255
388,178
807,724
1056,403
10,768
0,816
458,775
1228,605
1202,413
1043,161
1261,777
406,30
68,889
711,373
361,868
1071,68
816,770
147,400
574,773
184,57
1242,47
79,882
654,486
1057,700
939,259
561,58
1210,448
293,401
293,268
1285,148
151,500
1042,682
1216,217
1265,478
923,733
626,537
431,733
1053,796
599,889
537,880
890,766
505,257
87,290
909,642
333,137
177,28
835,133
435,635
134,637
1163,494
1277,492
518,52
654,38
495,756
628,14
1176,413
75,243
914,5
522,886
28,749
1044,126
1263,821
522,438
60,208
1059,722
989,255
629,425
681,597
75,620
315,360
373,404
398,437
621,850
494,124
924,212
1146,800
321,415
42,623
927,787
455,3
25,746
1017,401
555,785
231,817
816,180
2,600
1088,436
1285,597
232,161
97,880
753,176
271,295
26,460
0,651
654,767
401,252
55,779
1049,614
44,383
937,490
1305,863
498,812
841,222
903,432
684,537
795,645
924,525
562,215
634,568
989,757
105,186
527,891
488,572
835,581
720,856
1071,516
758,880
93,642
328,463
790,413
1088,458
875,123
321,25
1255,779
190,889
830,570
261,280
1250,830
1148,794
490,116
1302,267
920,588
1163,400
721,621
340,44
1124,551
1052,271
1002,567
561,721
355,103
689,420
664,319
0,162
592,329
80,773
428,194
1176,140
1044,840
576,42
927,821
69,124
1165,316
663,255
1071,72
1076,410
1265,218
1145,514
93,194
982,289
397,618
326,737
129,564
797,248
433,708
520,418
898,266
350,178
436,861
179,761
977,869
1217,642
812,812
1154,93
1277,599
552,880
790,476
156,129
676,326
186,850
20,38
626,145
261,621
1225,868
0,530
957,298
222,514
725,845
375,162
682,686
935,162
408,380
85,868
475,581
902,514
435,21
557,278
271,422
803,176
888,161
1126,849
514,467
139,249
1124,343
477,642
527,845
551,581
820,330
176,175
1245,806
256,534
142,383
140,663
539,633
512,632
390,588
232,677
1039,73
403,751
584,584
567,520
900,856
498,530
996,810
594,656
954,649
1240,310
763,329
621,44
6,129
1217,252
738,604
1263,60
1290,326
682,432
673,130
25,148
152,324
65,544
1171,249
17,316
199,399
654,548
393,737
fold along x=655
fold along y=447
fold along x=327
fold along y=223
fold along x=163
fold along y=111
fold along x=81
fold along y=55
fold along x=40
fold along y=27
fold along y=13
fold along y=6

21
inputs/test_input13_1_0 Normal file
View File

@ -0,0 +1,21 @@
6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
10,12
3,4
3,0
8,4
1,10
2,14
8,10
9,0
fold along y=7
fold along x=5