first commit

This commit is contained in:
Deni 2020-12-02 12:34:15 +01:00
parent e7158639f6
commit f4c3aeabee
13 changed files with 1421 additions and 0 deletions

16
2017/1.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
#a = "7385764686251444473997915123782972536343732657517834671759462795461213782428342931896181695578996274321317419242359534783957372932953774336338118488967172727651862498838195317654289797558683458511126996217953322817229372373455862177844478443391835484591525235651863464891177927244954925827786799436536592561374269299474738321293575385899438446558569241236278779779983587912431395475244796538888373287186921647426866237756737342731976763959499149996315591584716122199183295277439872911371313924594486766479438544417416529743495114819825984524437367225234184772617942525954961136976875325182725754768372684531972614455134523596338355374444273522115362238734383164778129376628621497662965456761631796178353599629887665939521892447361219479646483978798392716119793282717739524897385958273726776318154977675546287789874265339688753977185129334929715486381875286278528247696464162297691698154712775589541945263574897266575996455547625537947927972497979333932115165151462742216327321116291372396585618664475715321298122335789262942284571328414569375464386446824882551918843185195829547373915482687534432942778312542752798313434628498295216692646713137244198123219531693559848915834623825919191532658735422176965451741869666714874158492556445954852299161868651448123825821775363219246244515946392686275545561989355573946924767442253465342753995764791927951158771231944177692469531494559697911176613943396258141822244578457498361352381518166587583342233816989329544415621127397996723997397219676486966684729653763525768655324443991129862129181215339947555257279592921258246646215764736698583211625887436176149251356452358211458343439374688341116529726972434697324734525114192229641464227986582845477741747787673588848439713619326889624326944553386782821633538775371915973899959295232927996742218926514374168947582441892731462993481877277714436887597223871881149693228928442427611664655772333471893735932419937832937953495929514837663883938416644387342825836673733778119481514427512453357628396666791547531814844176342696362416842993761919369994779897357348334197721735231299249116477"
a = "738576468625144447"
#print vhod[1]
from operator import eq
print sum(map(eq, a, a[1:])) + (int(a[0]) if int(a[0]) == int(a[-1]) else 0)
print map(eq, a, a[1:])

30
2017/2.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python
import csv
crimefile = open('input2.txt', 'r')
#ireader = csv.reader(crimefile)
allRows = [line.strip('\n').split('\t') for line in crimefile.readlines()]
chk = 0
for line in allRows:
hi = max([int(i) for i in line])
lo = min([int(i) for i in line])
chk = chk + (hi-lo)
print chk
chk = 0
for line in allRows:
hi = max([int(i) for i in line])
lo = min([int(i) for i in line])
chk = chk + (hi-lo)
print chk

24
2017/alt1.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
myfile = open('input.txt', 'r')
contents = myfile.read()
myfile.close()
contents = contents.strip()
part_one = 0
part_two = 0
for i in range(len(contents) - 1):
if contents[i] == contents[i + 1]:
part_one += int(contents[i])
if contents[-1] == contents[0]:
part_one += int(contents[-1])
for i in range(len(contents)):
if contents[i] == contents[int(i + len(contents) / 2) % len(contents)]:
part_two += int(contents[i])
print("Part One:", part_one)
print("Part Two:", part_two)

27
2017/alt2.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
import itertools
with open('input2.txt') as f:
data = []
for line in f.read().splitlines():
data.append(list(map(int, line.split())))
def part1():
checksum = 0
for row in data:
checksum += max(row) - min(row)
return checksum
def part2():
checksum = 0
for row in data:
combos = list(itertools.combinations(row, 2))
for c in combos:
a, b = max(c), min(c)
if a % b == 0:
checksum += a//b
return checksum
print(part1())
print(part2())

1
2017/input.txt Normal file
View File

@ -0,0 +1 @@
7385764686251444473997915123782972536343732657517834671759462795461213782428342931896181695578996274321317419242359534783957372932953774336338118488967172727651862498838195317654289797558683458511126996217953322817229372373455862177844478443391835484591525235651863464891177927244954925827786799436536592561374269299474738321293575385899438446558569241236278779779983587912431395475244796538888373287186921647426866237756737342731976763959499149996315591584716122199183295277439872911371313924594486766479438544417416529743495114819825984524437367225234184772617942525954961136976875325182725754768372684531972614455134523596338355374444273522115362238734383164778129376628621497662965456761631796178353599629887665939521892447361219479646483978798392716119793282717739524897385958273726776318154977675546287789874265339688753977185129334929715486381875286278528247696464162297691698154712775589541945263574897266575996455547625537947927972497979333932115165151462742216327321116291372396585618664475715321298122335789262942284571328414569375464386446824882551918843185195829547373915482687534432942778312542752798313434628498295216692646713137244198123219531693559848915834623825919191532658735422176965451741869666714874158492556445954852299161868651448123825821775363219246244515946392686275545561989355573946924767442253465342753995764791927951158771231944177692469531494559697911176613943396258141822244578457498361352381518166587583342233816989329544415621127397996723997397219676486966684729653763525768655324443991129862129181215339947555257279592921258246646215764736698583211625887436176149251356452358211458343439374688341116529726972434697324734525114192229641464227986582845477741747787673588848439713619326889624326944553386782821633538775371915973899959295232927996742218926514374168947582441892731462993481877277714436887597223871881149693228928442427611664655772333471893735932419937832937953495929514837663883938416644387342825836673733778119481514427512453357628396666791547531814844176342696362416842993761919369994779897357348334197721735231299249116477

16
2017/input2.txt Normal file
View File

@ -0,0 +1,16 @@
278 1689 250 1512 1792 1974 175 1639 235 1635 1690 1947 810 224 928 859
160 50 55 81 68 130 145 21 211 136 119 78 174 155 149 72
4284 185 4499 273 4750 4620 4779 4669 2333 231 416 1603 197 922 5149 2993
120 124 104 1015 1467 110 299 320 1516 137 1473 132 1229 1329 1430 392
257 234 3409 2914 2993 3291 368 284 259 3445 245 1400 3276 339 2207 233
1259 78 811 99 2295 1628 3264 2616 116 3069 2622 1696 1457 1532 268 82
868 619 139 522 168 872 176 160 1010 200 974 1008 1139 552 510 1083
1982 224 3003 234 212 1293 1453 3359 326 3627 3276 3347 1438 2910 248 2512
4964 527 5108 4742 4282 4561 4070 3540 196 228 3639 4848 152 1174 5005 202
1381 1480 116 435 980 1022 155 1452 1372 121 128 869 1043 826 1398 137
2067 2153 622 1479 2405 1134 2160 1057 819 99 106 1628 1538 108 112 1732
4535 2729 4960 241 4372 3960 248 267 230 5083 827 1843 3488 4762 2294 3932
3245 190 2249 2812 2620 2743 2209 465 139 2757 203 2832 2454 177 2799 2278
1308 797 498 791 1312 99 1402 1332 521 1354 1339 101 367 1333 111 92
149 4140 112 3748 148 815 4261 138 1422 2670 32 334 2029 4750 4472 2010
114 605 94 136 96 167 553 395 164 159 284 104 530 551 544 18

14
2020/01/01.py Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 1
filename = "input.txt"
with open(filename) as f:
content = f.readlines()
content = [x.strip() for x in content]
for i in content:
for j in content:
if ( int(i)+int(j) == 2020 ):
print (int(i)*int(j))

15
2020/01/01b.py Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 1 - Part 2
filename = "input.txt"
with open(filename) as f:
content = f.readlines()
content = [x.strip() for x in content]
for i in content:
for j in content:
for k in content:
if ( int(i)+int(j)+int(k) == 2020 ):
print (int(i)*int(j)*int(k))

200
2020/01/input.txt Normal file
View File

@ -0,0 +1,200 @@
1228
1584
1258
1692
1509
1927
1177
1854
1946
1815
1925
1531
1529
1920
1576
1392
1744
1937
1636
1615
1944
1949
1931
1253
1587
1860
1874
1611
2008
1182
1900
1515
1978
1996
116
1588
1322
1680
1174
1712
1513
1778
1443
1569
1453
708
1783
1926
1959
2001
1776
1643
1654
1934
1983
1630
1382
1486
1422
1836
1728
1315
1843
1521
1995
1403
1897
1280
1981
1901
1870
1519
1945
1857
591
1329
1954
1679
1726
1846
1709
1695
1293
1602
1665
1940
1921
1861
1710
1524
1303
1849
1742
1892
1913
1530
1484
1903
1545
1609
1652
1908
1923
1188
1649
1994
1790
1832
140
867
1664
1598
1371
1018
35
1833
1161
1898
1482
1767
1252
1882
1448
1032
1459
1661
1391
1770
1806
1465
1295
1546
1355
1358
1321
1368
1514
1756
1775
1957
1468
1975
631
1812
1151
1167
1251
1960
1991
1972
1936
1552
1419
1577
1549
1580
1974
1830
1813
1893
1492
1389
1454
1522
1556
1172
1653
1822
1328
1907
1999
1281
1912
1919
1896
1722
1341
1720
1201
1512
1298
1254
1947
1505
1594
1334
1592
1943
1405
1589
1263
1930
1736
1180
1984
1401
1340
1292
1979
1876

36
2020/02/02.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 2
"""
1-5 k: kkkkhkkkkkkkkkk
5-7 k: blkqhtxfgktdkxzkksk
"""
filename = "input.txt"
with open(filename) as f:
content = f.readlines()
#content = [x.strip() for x in content]
validPasswords = 0
for i in content:
line = i.split()
xMin = int(line[0].split("-")[0])
xMax = int(line[0].split("-")[1])
character = line[1].rstrip(":")
password = line[2]
count = 0
for c in password:
if c == character:
count = count + 1
if (count >= xMin) and (count <= xMax):
validPasswords = validPasswords + 1
print (validPasswords)

39
2020/02/02b.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python3
# Advent Of Code 2020 - Day 2
"""
1-5 k: kkkkhkkkkkkkkkk
5-7 k: blkqhtxfgktdkxzkksk
"""
filename = "input.txt"
def logical_xor(str1, str2):
return bool(str1) ^ bool(str2)
with open(filename) as f:
content = f.readlines()
#content = [x.strip() for x in content]
validPasswords = 0
for i in content:
line = i.split()
pos1 = int(line[0].split("-")[0])-1
pos2 = int(line[0].split("-")[1])-1
character = line[1].rstrip(":")
password = line[2]
p1 = password[pos1]
p2 = password[pos2]
# (a and not b) or (not a and b)
if ( (p1 == character) and (p2 != character) ) or ( (p1 != character) and (p2 == character) ):
validPasswords = validPasswords + 1
print (validPasswords)

1000
2020/02/input.txt Normal file

File diff suppressed because it is too large Load Diff

3
2020/02/inputShort.txt Normal file
View File

@ -0,0 +1,3 @@
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc