Skip to content

Commit a0c401c

Browse files
committed
add day[8,9,10]
1 parent 1396e5e commit a0c401c

File tree

9 files changed

+2497
-0
lines changed

9 files changed

+2497
-0
lines changed

Day10/in.txt

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
noop
2+
noop
3+
addx 5
4+
addx 3
5+
noop
6+
addx 14
7+
addx -12
8+
noop
9+
addx 5
10+
addx 1
11+
noop
12+
addx 19
13+
addx -15
14+
noop
15+
noop
16+
noop
17+
addx 7
18+
addx -1
19+
addx 4
20+
noop
21+
noop
22+
addx 5
23+
addx 1
24+
addx -38
25+
noop
26+
addx 21
27+
addx -18
28+
addx 2
29+
addx 2
30+
noop
31+
addx 3
32+
addx 5
33+
addx -6
34+
addx 11
35+
noop
36+
addx 2
37+
addx 19
38+
addx -18
39+
noop
40+
addx 8
41+
addx -3
42+
addx 2
43+
addx 5
44+
addx 2
45+
addx 3
46+
addx -2
47+
addx -38
48+
noop
49+
addx 3
50+
addx 4
51+
addx 5
52+
noop
53+
addx -2
54+
addx 5
55+
addx -8
56+
addx 12
57+
addx 3
58+
addx -2
59+
addx 5
60+
addx 11
61+
addx -31
62+
addx 23
63+
addx 4
64+
noop
65+
noop
66+
addx 5
67+
addx 3
68+
addx -2
69+
addx -37
70+
addx 1
71+
addx 5
72+
addx 2
73+
addx 12
74+
addx -10
75+
addx 3
76+
addx 4
77+
addx -2
78+
noop
79+
addx 6
80+
addx 1
81+
noop
82+
noop
83+
noop
84+
addx -2
85+
addx 7
86+
addx 2
87+
noop
88+
addx 3
89+
addx 3
90+
addx 1
91+
noop
92+
addx -37
93+
addx 2
94+
addx 5
95+
addx 2
96+
addx 32
97+
addx -31
98+
addx 5
99+
addx 2
100+
addx 9
101+
addx 9
102+
addx -15
103+
noop
104+
addx 3
105+
addx 2
106+
addx 5
107+
addx 2
108+
addx 3
109+
addx -2
110+
addx 2
111+
addx 2
112+
addx -37
113+
addx 5
114+
addx -2
115+
addx 2
116+
addx 5
117+
addx 2
118+
addx 16
119+
addx -15
120+
addx 4
121+
noop
122+
addx 1
123+
addx 2
124+
noop
125+
addx 3
126+
addx 5
127+
addx -1
128+
addx 5
129+
noop
130+
noop
131+
noop
132+
noop
133+
addx 3
134+
addx 5
135+
addx -16
136+
noop

Day10/p1.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
3+
path = os.getcwd() + "\in.txt"
4+
5+
inst = open(path).read().splitlines()
6+
7+
stops = [20,60, 100,140,180,220]
8+
signal_strengths=[]
9+
X=1
10+
cycle=0
11+
12+
m = {
13+
"noop":1,
14+
"addx":2
15+
}
16+
17+
for item in inst:
18+
z = item.split(" ")
19+
ins = z[0]
20+
add = 0 if len(z)==1 else int(z[1])
21+
temp = m[ins]
22+
while temp:
23+
cycle+=1
24+
if cycle in stops:
25+
signal_strengths.append(X*(cycle))
26+
temp-=1
27+
X+=add
28+
29+
print(signal_strengths)
30+
print(sum(signal_strengths))

Day10/p2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
3+
path = os.getcwd() + "\in.txt"
4+
5+
inst = open(path).read().splitlines()
6+
7+
CRT = [[" " for c in range(40)] for r in range(6)]
8+
print(CRT)
9+
cur_crt_row_n = 0
10+
11+
X=1
12+
cycle=0
13+
14+
m = {
15+
"noop":1,
16+
"addx":2
17+
}
18+
19+
for item in inst:
20+
z = item.split(" ")
21+
ins = z[0]
22+
add = 0 if len(z)==1 else int(z[1])
23+
temp = m[ins]
24+
while temp:
25+
if cycle%40 in [X-1, X, X+1]:
26+
CRT[cur_crt_row_n][cycle%40] = "#"
27+
cycle+=1
28+
if cycle%40==0:
29+
cur_crt_row_n+=1
30+
temp-=1
31+
X+=add
32+
33+
print(CRT)
34+
for r in CRT:
35+
for c in r:
36+
print(c, end="")
37+
print()

Day8/in.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
000101002102003121323241144233304242044444224322555122224111442430042002422404011033200102312010222
2+
221001210320111200023341022214223134031413111451532412355524552433013131441430430230031133003002220
3+
122221231000323320200234443123410222443555111531251244245532551533102324231134241400331231103311202
4+
002101002220302234344333042430134115513332123415135441434515521411543331101323034131002231322012200
5+
012103211131230310231112144234315535452455525223214133132235223543125544102124134031231131222210112
6+
111130002131003013423030312121141451112312221535313252455443343322525321202043441240023211102333110
7+
010101133203222432223112115322531452121232111514435241332455323133154311225111113101042100133231220
8+
212312122201423311012344443454341224424241453264363522215552425444132445311420002412240101220213301
9+
101023311332333312310042312545121541355232566342466654642446644123243354413142100010434411303120123
10+
120130020344442212321452432111214314224425462535564426355544623222244543342221430323224303412123123
11+
100122201433440301022421212153344326335254336332362524455255536253422121511215542111404434333203131
12+
013302033043421031435312253135354263224222465554566325364566463622366241143414135130441301243233112
13+
313033320031421022413344311554263463336555324665326464442663522563423242343515255141042434110313302
14+
202110330220024351355553524343353263452564662444652264664644263222422343351433313245204140031042233
15+
231222130003131521443531513223263225523646546245776476552252433532343423256211415521111332211400213
16+
130301412331245422242144423232442666343543766554565376667543646343245233345431144424351220201130311
17+
101001302033443322332135463532426243534743745555757373435546545622644225322621145412552200003023222
18+
323141130033535331332232634266266252456763755766745543637336575766635662566255111541542153120403433
19+
301333142311131441252324455553552564677635545757576667435747446367555243356243565213424252034403411
20+
113341013301322433454225565463624376657556766453476655643365434767354462224366636431132214233311340
21+
244103023113455431143263324442576666454737757434543647745477733644635432526565242223252243244013342
22+
033402244215534225426664224435664574357764644644574655653436455444346474435465652435225543122102043
23+
122420435144215434324225642344476473673735775544685778446555534774736746346526462321413112121431124
24+
340144412411145312554534434574536376545388774855574488858586543335733453562435324346154542245241101
25+
404120334311531362625543547577756437446548767457867758444558847555645775665242263625423435215332442
26+
212010435132212524655246557635374434847867584574475567446777865456536755745536535663553324141520120
27+
330104233414152326256363475457776454854787865557558584875774464888664577563345564542526431152314144
28+
204424552413353456325435464573447454586888444477657468877554586448477357557777242465555115454242234
29+
100003132443552563452674364555647688778574657658657657677845556856874446765775346664235453321514311
30+
421122231134136624523375774567546567777455768765958787894557575564788753335766552646453554553244313
31+
220231254234454666263733633553445867457848695756678898897967856856886766755656654226425642314324424
32+
303314254151456442346637464335864467866659665796967655766576845457844884466665643466554342325231511
33+
001554112513566332436573643778566784647665875985896999587879587768647847644467736744333526555422114
34+
032222531135645356643363454846585667657775788588967687579955596787755586685634747724256635155514341
35+
200335551244366554375647558667858488687875677867666567569699898898555448586575767755664335355453351
36+
015523555256545653574455635766645567977578969879669769675787686968848578587654453573623436523313245
37+
122413154354345427477464686665766857766769897656999766988969599558668445557475444456442236225341342
38+
232513331242556236476736346484477865755576796987968796787788559898768868447645667575522623645115255
39+
155115513343454246674563554667866686757789699968997766878696957587787758887774663634662336425245425
40+
121211421234625477775653687648849788956656689799787769677866858596885865867544747433766266522234243
41+
125411412463453653644666878877599555886769968966879976797787797978556785776554666554434625544243533
42+
125111332362525545467465486567588567887686776779799888897866768588888978867566653363634662422511142
43+
431451425222366656557648858455877665869898788877889796998886899879677657488656657747565525252113115
44+
431443443346432366667346846584967789989877668669779797898886687767766876777457674646666425654132532
45+
351525545656354663336584775556676995579686688898989899776767867766779884868888536664345366662431313
46+
215332512532553563577757477476698965776678889889998889989888786967876586458688477763365456436143133
47+
155354365362542537756778665676557859686996777798978778998787877768568767544754756454754233345311422
48+
221224222534246553774375775559859578888779669898977878797876989675576998775846876733676454264214353
49+
452432453264654634334555468575558985777666668797977987798996997766796899845846747447375442252542342
50+
453231335553424444456675545687877565888789789798997899797878778788877956755774667337344546636414343
51+
253541162525564676777357876478995885677968699987798898877776689689557958475676766377575455565452321
52+
555414542536465736673775475585875888788686697777889798989789976996767666768666433465457362532214555
53+
224124236446626436764764757489579765868786769889888888987899998898687798646555433474645224663454322
54+
255332526246362477757378867446686577679698689788797889999866999668587757647565675545445662662644541
55+
542554463433564545674688477658899896789686869779898778798879786887788587748545774757566323426521322
56+
221323525535234333533747467755867587689697668999799988879989977889995855676865636566336652636314324
57+
142153344255424535563586565776896769779776789877777789866876979765668578846455464774754332352322524
58+
455144143466266766646775486464988766577986796786697768977888769997759854458674376354744434355325132
59+
354233542542533574435477786674658756989969689678798978799776788677766957554777337575342543332134352
60+
314322226552423445674367656855895795668776799786997677996697869586899654684578754337566343326231531
61+
355312142422322275343775868876686577879567966888998687679797895997658576765468677537326552546444241
62+
235252535422554667366453848674855795788758989778996697897687756897975468564885543353334455522152242
63+
333225422342666554374433848546779957575589768877978766696697557796967654757684337557645522551215134
64+
335131235555563267745455668544875859998796897986697976968957778675957454488463546357346424234511434
65+
011321545432264363565367448576765668977958667969889687676775855687565885857543473335443255313122512
66+
441241131563254445343775336845667467996589697665958687599865868695546774845375675644535364613435113
67+
233555434234644565356456646578587488855989888688997866886896878798678874688774734662543336422325124
68+
134522142112446634267673373557544644659978866577667965576768677674468548753467576525264422111551342
69+
440234232512665242564476655578678656487596765595696667857989598876886764845366633334634223522135241
70+
201123333231534434645554553345674677578459779677766777796967754477556567573445673452334543541151510
71+
331012113351662624255336766457454768788587599588887796985895674445654444344454447444566452522343332
72+
224012511135142432346456767563366674884584644587886776855566748864458766673533573456233245552422412
73+
421232255423364256455266364355455648588764788688845588874684858757485445334773543635446244323145424
74+
331100535315256343462563743673435647856476874866766446444688644458853564565376526535334242254241402
75+
400432141313355423443444365547654648867855766448755555464655678768873734374346635434535515143521112
76+
213114035441542566342554455546334346665844775767666674784577564756557664663523534245442351121140413
77+
312140151134432266252456356334566444765484474474558866876844845676576747533623525435642352244422240
78+
110114304524111124366532554457435454544484465464856774577678647737467576566322635652224211142340114
79+
403241244335214551236434554433646643576756567846588688444557736377353773433664266641143511414003022
80+
043144141425434212534355224455365656433467644534357666337353746556337337245654223625412235551412312
81+
200002122031442244224635656325475445555445433366543353437343753457455774435355225321145535314024004
82+
233033222223234153532456455545223466657375346755437344776365673634365324265543662545444355310011220
83+
104213032434143353122226465342645644374547656637375755737345765775642563455244343522235122143414010
84+
221300210103225231221546342643362332765663733473436476474653674475562542564226511453141450432410403
85+
001002433444133154432122523226462532323563455334576776633564535436442654644352242532124500411122020
86+
101010412133301314252131146332265343536245455476553635775564564366264265243244235545351244314302223
87+
331004130041211314354353312663325253233356525255433474245422625254344335334555152353241431032122220
88+
110332302424241311542132245535522443545463445562656552523542653563655453233323211354413334431440300
89+
310002133122112114243524142251355565455635626653464462352555243446665634435455153541131122100231031
90+
221013034340101121242214455253355264252445654446356363346466542323322543155321353123012012143020031
91+
312323031223321240445311424525241136554543353544655543356324424422242433155433424302134412202103103
92+
200331103222232430312311523131422215242546524354452645243226455523552531141134121044420021303230321
93+
003221032320334231323434311543313544421256366626336545533532523324253534255554211110432320030001320
94+
002001213030410031121111131121142322452354113122332235334411233453234411341431423400413112032130321
95+
211203331323114322411142421234424555315432344243254512433312122524311443215320300420443410312313330
96+
121203030210303443004134242331354225425411412153223454424423453455445411531200340243140321330132300
97+
020013203133203122033341422142241334225534114115433111122135152521211322332333111230111303313301011
98+
100122131000211034223301034012415322234122154143522313235545255134155143122000321242010032132112010
99+
022210130000131121100420203411431312433123144335254451454421435455333142200104132010113111122222121

Day8/p1.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
3+
path = os.getcwd() + "\in.txt"
4+
5+
lines = open(path).read().splitlines()
6+
lines = [list(map(int, line)) for line in lines]
7+
visible = 0
8+
9+
for r in range(len(lines)):
10+
if r==0 or r == len(lines)-1:
11+
visible+=len(lines[r])
12+
else:
13+
for c in range(len(lines[r])):
14+
if c==0 or c==len(lines[r])-1:
15+
visible+=1
16+
else:
17+
current = int(lines[r][c])
18+
le = lines[r][c-1::-1]# look left
19+
ri = lines[r][c+1:] #look right
20+
up = [lines[x][c] for x in range(r)]
21+
down = [lines[x][c] for x in range(r+1, len(lines))]
22+
23+
if all([x<current for x in le]) or \
24+
all([x<current for x in ri]) or \
25+
all([x<current for x in up]) or\
26+
all([x<current for x in down]):
27+
visible+=1
28+
29+
30+
print(visible)
31+

Day8/p2.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
3+
path = os.getcwd() + "\in.txt"
4+
5+
lines = open(path).read().splitlines()
6+
lines = [list(map(int, line)) for line in lines]
7+
scenic_scores = []
8+
9+
for r in range(len(lines)):
10+
if r==0 or r == len(lines)-1:
11+
pass
12+
else:
13+
for c in range(len(lines[r])):
14+
if c==0 or c==len(lines[r])-1:
15+
pass
16+
else:
17+
current = lines[r][c]
18+
le = lines[r][c-1::-1] # look left
19+
ri = lines[r][c+1:] #look right
20+
up = [lines[x][c] for x in range(r)] # stores from top to bottom
21+
down = [lines[x][c] for x in range(r+1, len(lines))]
22+
23+
24+
s_up = 0
25+
#while looking up we need to look from bottom to top
26+
for item in up[::-1]:
27+
s_up+=1
28+
if item >= current:
29+
break
30+
31+
s_down = 0
32+
for item in down:
33+
s_down+=1
34+
if item >= current:
35+
break
36+
37+
s_le = 0
38+
for item in le:
39+
s_le+=1
40+
if item >= current:
41+
break
42+
43+
s_ri = 0
44+
for item in ri:
45+
s_ri+=1
46+
if item >= current:
47+
break
48+
49+
50+
#print(f"\n{s_up=},{s_down=},{s_le=},{s_ri=}")
51+
#scenic_scores.append((s_up*s_down*s_le*s_ri, f"{s_up=},{s_down=},{s_le=},{s_ri=}", (r,c)))
52+
scenic_scores.append(s_up*s_down*s_le*s_ri)
53+
54+
print(max(scenic_scores))
55+
56+

0 commit comments

Comments
 (0)