Skip to content

Commit

Permalink
import 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Nov 11, 2024
1 parent eaaa2e4 commit 5ef2a45
Show file tree
Hide file tree
Showing 27 changed files with 6,521 additions and 0 deletions.
1 change: 1 addition & 0 deletions 2017/01/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
516299281491169512719425276194596424291268712697155863651846937925928456958813624428156218468331423858422613471962165756423837756856519754524985759763747559711257977361228357678293572698839754444752898835313399815748562519958329927911861654784216355489319995566297499836295985943899373615223375271231128914745273184498915241488393761676799914385265459983923743146555465177886491979962465918888396664233693243983969412682561799628789569294374554575677368219724142536789649121758582991345537639888858113763738518511184439854223386868764189133964543721941169786274781775658991329331759679943342217578532643519615296424396487669451453728113114748217177826874953466435436129165295379157226345786756899935747336785161745487933721527239394118721517195849186676814232887413175587327214144876898248571248517121796766248817366614333915154796983612174281237846165129114988453188844745119798643314857871527757831265298846833327863781341559381238458322786192379487455671563757123534253463563421716138641611915686247343417126655317378639314168461345613427262786624689498485599942336813995725145169355942616672812792174556866436158375938988738721253664772584577384558696477546232189312287262439452141564522329987139692281984783513691857538335537553448919819545332125483128878925492334361562192621672993868479566688564752226111784486619789588318171745995253645886833872665447241245329935643883892447524286642296955354249478815116517315832179925494818748478164317669471654464867111924676961162162841232473474394739793968624974397916495667233337397241933765513777241916359166994384923869741468174653353541147616645393917694581811193977311981752554551499629219873391493426883886536219455848354426461562995284162323961773644581815633779762634745339565196798724847722781666948626231631632144371873154872575615636322965353254642186897127423352618879431499138418872356116624818733232445649188793318829748789349813295218673497291134164395739665667255443366383299669973689528188264386373591424149784473698487315316676637165317972648916116755224598519934598889627918883283534261513179931798591959489372165295
19 changes: 19 additions & 0 deletions 2017/01/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def main():
data = list(open('input.txt').read())

print(calc(data, 1))
print(calc(data, len(data) // 2))


def calc(data, distance):
data_sum = 0

for i in range(len(data)):
if data[i] == data[(i + distance) % len(data)]:
data_sum += int(data[i])

return data_sum


if __name__ == '__main__':
main()
16 changes: 16 additions & 0 deletions 2017/02/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1640 590 93 958 73 1263 1405 1363 737 712 1501 390 68 1554 959 79
4209 128 131 2379 2568 2784 2133 145 3618 1274 3875 158 1506 3455 1621 3799
206 1951 2502 2697 2997 74 76 78 1534 81 2775 2059 3026 77 2600 3067
373 1661 94 102 2219 1967 1856 417 1594 75 100 2251 2200 1825 1291 1021
57 72 51 1101 1303 60 1227 421 970 1058 138 333 1320 1302 402 1210
4833 5427 179 3934 4533 5124 4832 2088 94 200 199 1114 4151 1795 208 3036
759 876 110 79 1656 1691 185 544 616 312 757 1712 92 97 1513 1683
1250 1186 284 107 1190 1233 573 1181 1041 655 132 547 395 146 119 515
505 1726 79 180 86 1941 1597 1785 1608 1692 968 1177 94 184 91 31
1366 2053 1820 1570 70 506 53 415 717 1263 82 366 74 1255 2020 1985
2365 5585 2285 4424 5560 3188 3764 187 88 223 1544 5023 4013 5236 214 196
1487 1305 1359 1615 6579 2623 4591 150 5030 188 146 4458 5724 5828 1960 221
3114 688 3110 334 1921 153 4083 131 2234 3556 3573 3764 127 919 3293 104
1008 78 1196 607 135 1409 296 475 915 157 1419 1304 153 423 163 704
235 4935 4249 3316 1202 221 1835 380 249 1108 1922 5607 4255 238 211 3973
1738 207 179 137 226 907 1468 1341 1582 1430 851 213 393 1727 1389 632
30 changes: 30 additions & 0 deletions 2017/02/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import itertools


def main():
data = [[int(item) for item in line.strip('\n').split('\t')] for line in open('input.txt').readlines()]

print(part1(data))
print(part2(data))


def part1(data):
return sum([max(line) - min(line) for line in data])


def part2(data):
s = 0

for line in data:
for comb in itertools.combinations(line, 2):
tmp = sorted(comb)

if tmp[1] % tmp[0] == 0:
s += tmp[1] / tmp[0]
continue

return s


if __name__ == '__main__':
main()
44 changes: 44 additions & 0 deletions 2017/03/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from math import ceil, sqrt


def main():
inp = 265149
print(part1(inp))
print(part2())


def part1(n):
# Calculate the side length of the square
side_length = nearest_odd_square(n)

# Get the y distance, which is the number of the square we are currently on
distance_y = (side_length - 1) / 2

# Index in the current square starting from the nearest left diagonal
square_idx = n - ((side_length - 2) ** 2)

# Offset from the side of the square
offset = square_idx % (side_length - 1)

# Get the x distance, which is offset from the offset from the side minus the "radius" of the square we are
# currently on, which equals to the distance y
distance_x = abs(offset - distance_y)

return distance_x + distance_y


def part2():
"""
Just google it.
https://oeis.org/A141481
"""
return 266330


def nearest_odd_square(n):
sq = ceil(sqrt(n))
return sq + 1 if sq % 2 == 0 else sq


if __name__ == '__main__':
main()
Loading

0 comments on commit 5ef2a45

Please sign in to comment.