Last active
December 13, 2018 03:26
-
-
Save adiamb/7e610aae3ae252d3cf0fafbc481c6367 to your computer and use it in GitHub Desktop.
AdventOfCode_Day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import math | |
import sys | |
## Part 1 | |
FileIn = 'D1_INPUT.txt' | |
CurFreq =0 | |
with open(FileIn) as FreqIn: | |
for line in FreqIn: | |
FreqAdju = int(line.strip()) | |
CurFreq += FreqAdju | |
print CurFreq | |
## Part 2 | |
FileIn = 'D1_INPUT_P2.txt' | |
CurFreq =0 | |
FreqDic ={} | |
ReadFile = True | |
while ReadFile is True: | |
with open(FileIn) as FreqIn: | |
for line in FreqIn: | |
FreqAdju = int(line.strip()) | |
if CurFreq not in FreqDic: | |
FreqDic[CurFreq] =0 | |
CurFreq += FreqAdju | |
else: | |
print CurFreq | |
ReadFile =False | |
break | |
#print line.strip(), CurFreq | |
#print CurFreq | |
## Day 2 | |
def RetreiveChksum(g): | |
chksum_3, chksum_2 = 0,0 | |
gdic ={} | |
for i in g: | |
if i in gdic: | |
get_count = gdic.get(i) | |
gdic[i] = get_count+1 | |
else: | |
gdic[i] = 1 | |
print gdic | |
if 2 in gdic.values() and 3 in gdic.values(): | |
chksum_3 = 1 | |
chksum_2 = 1 | |
print 'yeay', g | |
elif 2 in gdic.values() and 3 not in gdic.values(): | |
chksum_2 = 1 | |
elif 3 in gdic.values() and 2 not in gdic.values(): | |
chksum_3 = 1 | |
return[chksum_3, chksum_2] | |
FileIn = 'AD_DAY2.txt' | |
chksum_2 = 0 | |
chksum_3 = 0 | |
with open(FileIn) as Finput: | |
for line in Finput: | |
LineParse = line.strip() | |
out_temp=RetreiveChksum(g=LineParse) | |
print out_temp | |
chksum_3 += out_temp[0] | |
chksum_2 += out_temp[1] | |
#Day 2 part 2 | |
def RetreiveMatch(a, b): | |
match = 0 | |
MisStr ='' | |
StrLength = len(a) | |
assert len(a) == len(b) | |
n =0 | |
StrMisIndex= 0 | |
for i, j in zip(a, b): | |
n +=1 | |
if i == j: | |
match += 1 | |
else: | |
MisStr = i+'<>'+j | |
StrMisIndex = n | |
if match == StrLength-1: | |
print ' STRING 1 {} \n STRING 2 {} \n MISMATCH AT {} {} \n THE INPUT TO PUZZLE IS {} '.format(a, b, MisStr, StrMisIndex, a[:StrMisIndex-1]+a[StrMisIndex:]) | |
FileIn = 'DAY2_P2_INPUT.txt' | |
BoxID =[] | |
with open(FileIn) as InPut: | |
for n, line in enumerate(InPut): | |
LineParse= line.strip() | |
BoxID.append(LineParse) | |
for Id in BoxID: | |
RetreiveMatch(Id, LineParse) | |
def ProcessClaim(Claim): | |
ClaimParse=Claim.split(' ') | |
ClaimID = ClaimParse[0] | |
ColID = int(ClaimParse[2].split(',')[0]) | |
RowID = int(ClaimParse[2].split(',')[1].replace(':','')) | |
ColCov = int(ClaimParse[-1].split('x')[0]) | |
RowCov = int(ClaimParse[-1].split('x')[0]) | |
print ' The Claim ID is {} \n Starting from {} th Column and {} th row \n until {} columns and until {} rows '.format(ClaimID, ColID, RowID, ColID+ColCov, RowID+RowCov) | |
RowCoords=[i for i in range(RowID, RowID+RowCov)] | |
ColCoords=[i for i in range(ColID, ColID+ColCov)] | |
assert len(RowCoords) == len(ColCoords) | |
OutCoords=[str(X)+','+str(Y) for X, Y in zip(ColCoords, RowCoords)] | |
return OutCoords | |
TrackDic ={} | |
#TrackDic = SquareMatrix | |
overlap =0 | |
FileIn = 'DAY3_P1_INPUT.txt' | |
with open(FileIn) as InPut: | |
for line in InPut: | |
if line: | |
Claim = line.strip() | |
MarkCoords = ProcessClaim(Claim = Claim) | |
for key in MarkCoords: | |
if key in TrackDic: | |
overlap += 1 | |
get_claim = TrackDic.get(key) | |
TrackDic[key] = get_claim + '$' +Claim#.split(' ')[0] | |
else: | |
TrackDic[key] = Claim#.split(' ')[0] | |
overlap = 0 | |
for k, v in TrackDic.items(): | |
if len(v.split('$')) > 1: | |
print k, v | |
overlap += 1 | |
#SI= Max(0, Min(XA2, XB2) - Max(XA1, XB1)) * Max(0, Min(YA2, YB2) - Max(YA1, YB1)) | |
Claim='#13 @ 18,241: 10x13' | |
ClaimParse=Claim.split(' ') | |
ClaimID = ClaimParse[0] | |
ColID = int(ClaimParse[2].split(',')[0]) | |
RowID = int(ClaimParse[2].split(',')[1].replace(':','')) | |
ColCov = int(ClaimParse[-1].split('x')[0]) | |
RowCov = int(ClaimParse[-1].split('x')[0]) | |
print ' The Claim ID is {} \n Starting from {} th Column and {} th row \n until {} columns and until {} rows '.format(ClaimID, ColID, RowID, ColID+ColCov, RowID+RowCov) | |
### generate 1000*1000 coordinates to fill with claimIDS | |
SquareMatrix ={} | |
for i in xrange(1, 1000): | |
for j in xrange(1, 1000): | |
MakeKey = str(i)+','+str(j) | |
if MakeKey in SquareMatrix: | |
print 'Fuck' | |
else: | |
SquareMatrix[MakeKey] = '' | |
## generate keys from claimID text file | |
RowCoords=[i for i in range(RowID, RowID+RowCov)] | |
ColCoords=[i for i in range(ColID, ColID+ColCov)] | |
CleanDic={} | |
assert len(RowCoords) == len(ColCoords) | |
for X, Y in zip(ColCoords, RowCoords): | |
MakeKey = str(X)+','+str(Y) | |
if MakeKey in CleanDic: | |
overlap += 1 | |
else: | |
CleanDic[MakeKey] = ClaimID | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment