Compare commits

...

2 commits

Author SHA1 Message Date
e9a47c1863 2021 day7/python: add solution 2021-12-07 06:24:59 +01:00
eb8110c355 2021 day7: add data 2021-12-07 06:24:31 +01:00
3 changed files with 18 additions and 0 deletions

2
2021/data/day7.expected Normal file
View file

@ -0,0 +1,2 @@
342641
93006301

1
2021/data/day7.input Normal file
View file

@ -0,0 +1 @@
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,775,180,473,1346,1189,1553,196,427,788,25,159,204,851,24,1404,91,308,1096,747,278,1185,36,752,57,54,583,570,260,735,1192,72,552,103,693,383,202,78,1050,453,116,333,182,765,60,372,201,291,1642,49,80,918,98,1443,36,577,696,1289,56,220,56,51,550,1666,651,652,1508,70,40,1473,57,1065,32,6,537,1053,315,711,163,476,1006,3,1092,18,1304,237,358,457,888,36,639,39,1051,723,590,1242,210,1217,473,488,1554,729,776,307,375,243,186,436,94,451,1230,495,861,480,28,323,529,92,65,43,564,143,183,81,965,82,168,303,331,99,921,583,1349,182,353,626,150,475,1388,381,539,1190,664,923,1579,564,31,186,171,415,69,82,621,579,636,787,154,384,463,124,213,270,318,16,21,429,1285,1052,755,248,67,1021,20,165,789,7,456,18,1432,1379,3,108,96,40,42,1148,665,526,392,616,405,633,399,152,388,9,1078,159,454,945,330,2,455,288,288,72,313,827,521,939,186,680,253,386,917,317,346,1897,520,662,558,919,31,1141,1025,29,80,601,1001,199,128,1721,1221,367,29,722,186,344,136,415,718,122,7,879,195,1430,250,65,391,1296,154,39,647,861,175,18,448,131,568,322,20,290,828,844,135,622,409,236,40,341,767,31,917,5,335,27,205,63,18,1262,615,1819,291,1263,179,206,686,102,18,483,525,331,303,932,664,337,774,1080,22,177,891,780,523,362,38,219,281,72,861,48,1382,1497,249,343,404,292,1252,1,532,370,421,155,1728,110,1778,804,944,142,1508,155,967,1201,1066,706,613,1222,40,1000,558,616,693,378,124,35,91,514,1445,7,280,775,744,421,236,597,143,380,91,1564,111,1359,711,453,73,247,427,119,182,508,598,514,543,297,182,397,24,1317,107,766,428,877,580,1135,13,266,568,369,570,5,214,1222,150,225,93,1168,7,793,346,17,70,127,734,1428,1513,274,409,1291,498,958,535,37,268,994,165,662,59,125,267,557,28,259,77,1226,588,499,105,15,238,272,272,100,329,642,68,356,782,90,674,608,431,1,442,835,3,780,51,394,146,71,231,582,81,595,921,913,398,831,1107,491,801,371,407,746,1337,196,7,86,427,72,217,3,98,717,1268,991,187,103,256,616,172,125,831,1380,935,281,1534,435,868,1291,51,894,91,527,443,868,1300,72,1108,259,641,381,1103,580,422,310,953,97,8,198,1249,1069,342,953,464,66,648,683,184,702,1488,440,389,408,0,47,1023,45,63,999,131,73,135,256,1586,798,61,43,708,138,500,952,10,170,1287,956,1454,886,1117,405,1064,252,1218,334,316,1116,485,63,336,1218,528,309,86,833,168,955,45,993,841,480,336,512,835,296,285,340,81,1291,61,51,5,284,1114,120,794,1444,889,28,0,327,134,71,1040,230,48,49,837,1191,558,3,26,760,1038,104,320,87,464,270,115,357,277,285,488,1649,477,972,423,524,657,20,395,958,528,13,125,391,90,334,314,1022,1147,200,1357,1092,559,610,193,296,60,188,0,2,277,540,365,79,278,199,1327,573,615,95,677,285,143,182,226,12,661,492,189,526,75,1358,923,228,59,417,535,544,270,1040,197,2,216,1217,372,1034,84,16,725,1798,352,147,290,528,1091,105,476,725,137,474,75,1313,644,92,43,286,47,118,11,865,1316,1464,1189,673,67,612,183,379,309,464,207,31,64,1375,34,413,618,131,1459,178,179,81,245,316,223,230,697,337,977,188,1335,811,163,592,181,93,108,865,112,20,497,986,1124,73,128,96,107,1288,179,229,145,1293,1224,1308,748,768,143,38,33,1842,64,45,1209,984,269,371,1451,876,1372,65,275,173,1569,298,187,91,522,133,39,709,878,2,123,195,1435,1569,482,1047,322,382,796,38,903,24,950,387,510,460,570,499,545,561,158,383,213,978,1329,380,938,280,267,762,841,713,111,357,71,19,121,581,91,177,869,1138,173,14,145,155,21,353,340,1145,113,594,685,91,781,558,500,10,33,300,270,457,675,850,64,49,81,311,906,404,207,176,309,45,855,16,9,881,428,194,300,329,715,985,559,656,66,184,1529,8,1131,610,78,522,338,492,1378,47,163,448,111,700,3,19,796,876,224,212,51,524,273,597,980,0,10,205,8,985,38,876,6,91,435,1273,38,147,214,362,1,95,87,724,1126,807,378,105,89,276,1076,107,552,1082,32,896,202,177,946,753,1106,464,72,61,225,55

15
2021/day7/day7.py Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env python
import sys
if __name__ == '__main__':
inp = [int(i) for i in sys.stdin.readline().split(',')]
def calc(f):
return min([
sum(f(abs(crab-i)) for crab in inp)
for i in range(min(inp), max(inp)+1)
])
print(calc(lambda n: n))
print(calc(lambda n: n * (n+1)//2))