Skip to content

Commit 75d937d

Browse files
committed
Add day08b
1 parent 6e77a47 commit 75d937d

File tree

5 files changed

+193
-0
lines changed

5 files changed

+193
-0
lines changed

day08b/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

day08b/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "day08b"
3+
version = "0.1.0"
4+
authors = ["Tim Visee <3a4fb3964f@sinenomine.email>"]
5+
edition = "2021"
6+
7+
[lib]
8+
path = "src/main.rs"

day08b/input.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
300030213213113240234210203330153124541151003015456312312442524531405533542450111443312103110220211
2+
133000004421300341005340432514034555543556261543410250030436135103304323425502113341331442032311030
3+
213121312230422241205230130541010120012561656126511652636160154566425231221254515542342023142010133
4+
210020103232311410025023513110540633654032560666266266442224400244155120504322112255323444432301210
5+
300221311013444150512444105105055122104524660253365233115442634642236455351502043504233200041232000
6+
000000011130235121555143014441555205423003555504400645452656322632050035240315440035451003103431431
7+
012142333141321404105321351332544222551046221101044054031533500165110422142125530252401331243211232
8+
020213033022012453014033014405001564353352011316633456214232621532251606161624054400501054130430422
9+
042314012030233125141141244243333123002627374716422264424361631360462131201236611502353523210122300
10+
211224020402441314100154352420322456122364263545772174674761655261311042611615130513350241030243433
11+
314424032332214322125462603406635133652272743472434161773175755665106156425610245350415311352303020
12+
430442043211531134103213404455524724321332213636522224572442553173311265220261503235505013340341232
13+
001001325232413003110430361654232165433226632435251776357256175725724566400520111500101504331132114
14+
334412500412200403511523220032572737752127755542727442166375451622531763242464326501020110104340144
15+
121243523444032105062316052754715461676111661333423221122752355145371142754413605365235134243015313
16+
242330445052105423412660066474767425155231852584272588286671442475372464535465114141632114402431330
17+
122050043214212560234014261446673143437367834853285853825877263146536255554162263165412530555001012
18+
310254352155555362305652565245733333847537568334443567664745527772362543753627625001150411055105112
19+
025031121433111201225651315747477674878824738825265832254676344282526441156537710545602456542112210
20+
105541425514161020436715372516214235452255778656548556525666534284848751622646711602335633004210430
21+
120403544243300210571653423576358224736356674473762873838666826244548367625153434754030101342121403
22+
432020535536321653451132344347283847864642562823856582222257783373625252524642355422611066341041555
23+
105515504230051446254242173357243344432244287653558393463636636527332375861462227252610460111541451
24+
424315140455252444231317616735826624757676779939449898765575452676252735247362276562636111623005500
25+
021423534431553132473112715725478325366953865554356694548876447733778524336511267122410032353204044
26+
445423066641156261422146768782747848378447486547353679545953363787428372464325267535533614266344140
27+
152411666100126757726562222726546749954446865366696449877979478486373233467373175176717065434502141
28+
140202601300054474441768586442348397689388764774948539945648798559996563788746555346275261454103223
29+
544203021060377313252177225245274373949438556349734495443338667684563463227487637566451205231151234
30+
225400103300571274173335762334287864949875576664869759876374397685438976626326425644665160321405114
31+
230314645445261324544678872478778643594945995976689844475579675835534645236636838337776723535345500
32+
150534014520772265552634657365463588877484555578696496798458453663473396824266754637171242001256124
33+
501401625205514213726356888877344586367477569695884664945598775858874867554835685452612772106263532
34+
003545414654644264168635752867577699868859699658765954768468556893987864886348334776371465025135140
35+
251042560617345355567763755683459686855588797756945758776799955744646686687652842535676751665034401
36+
302210131663435613688532374877833645976757884777578755957476749797784636464388672831672655516160250
37+
111065246313516415337376337787538574959786899487589688777994584659853384389926247746333354700561235
38+
110414613452245538424336745356686988599756856889899665657755876955474687659467286778227144340035665
39+
412353204671232672374342364957877787589988865788855789958795889895469566379993753537827253655122163
40+
220455060636641757662657656485887468555667756998687885558888697575769544353438542486665473665353031
41+
061302402574166188357244985755358964658897589996959669756655586556668978665737857647731571412663614
42+
451215265723364666667225569887469777655996787798658577588667964644965767693668287254634774752440436
43+
301215542714677435434258733978685986666878695679857768798658676786669569956767732852857361576404432
44+
154623106155526744253836847466987985777579987895579899887867686679478588489549787628542237217621402
45+
016326557476722738858767965394776546697557589788987986685897875855497888993584977357781252535652100
46+
516434443771523825524465875344974794885887577968879977777596685889766469448884476765464722367346613
47+
663333275643147748552476447559494596988869978768877866788776955886649886647734953675545514515635060
48+
564446265661363787884698458539864897955876879789888686667667695889588654946548558665552464445515100
49+
444635271445544486468235896595657574556796676868879879878987585894795697656985562654886247765264633
50+
462165473462113357828755539386966448779857797769787979697957598754959785656563752733766632117233453
51+
324114033531125766355764993645548777979758996876999867877675777569547846779389355565826361114230641
52+
224200317716278667488649555774497597689687678896896677969958769969794969974689727365357612457234644
53+
402622076242363764226695388365948877677669866868687967866668896555954488854868827247567131532732161
54+
351431525533425423868437845597564857555568597698676776879667799897879746844566636356646565257121003
55+
225616611661632445584357877765956764697568598699686698997669677996868665573893357436745717575725454
56+
464505117521646733487884876599599666866788675666888876875979598579854747435497874323277332541546013
57+
052114137625735662285578885579794999468569858977677679667685665987955489696478687578266127111546664
58+
316613323223637567683247984347647849968985558977789767985598956679896995585799768687622276617221641
59+
150200045167123286782287837679577787677797988695867797789687586558667574856533357756471257515363540
60+
252244417323233175887456579833456748749996686798597998557665769755856789834546748233733443273254100
61+
356160635747716144466869844679547594648877886665966889699566759455979998476485752287252722716164416
62+
425166022644275152644747799869954648746958878589556668589768447767896344585634858425817452170565306
63+
345366062117166733576545864397534485854779888658678987596689784695568398698547735888734716543316365
64+
533535636242332164847587898599999846566885656697676699688759667965889473655654364846464567176441222
65+
145156433556112342733574868953399368585597766648768658747699944777476969449428537232155673534436334
66+
054406066337214353545756523343684448899669455797588778689784798466937584849358665356646637313111401
67+
254230005511427461268747424696354657897679767675549867458844878496487636435757334231367213603232112
68+
555355424332316775464478853457754765559478879676449464477968898464959946683563372221445526535034024
69+
414023123606577152476576548378794456898548667574545479875668799757679333543655778735436732625602102
70+
103425425660432324255388475439558538899897884857688985496679573943943844375486647275716474356544432
71+
452130224302617716756636522262934655383939784956995477695867446373399748438345254577364313526363420
72+
000042112640363475341785644528248693738497465445788948789539367488865954668672787612122734016622455
73+
023111166642052271313457755228576545698943896555698897675589438943493564742233477111247522056555041
74+
204431055441351336464513762857847353357853376696786639733989764484974246522527515321225331245432343
75+
411113064641332752327456644465236399895559367589866764738365755795443834767856231524273551544613205
76+
002003415151314635554646457575673343677789786935595493666738344866563385573637543752334431304230033
77+
232000241320312557743676572825328454583544756367648459896978649838474485587354722365706253422641104
78+
140032334604361016614454563867878852473268539588353455546354984764388862653617247612502644151343100
79+
230313534421421354553535613177284354853423658747835975969372246355755687417111117262662010635050245
80+
455442045443411622436616447216784738377874843272575735853775463446344736154635424345111430260111355
81+
015553515233634200652274644243776752756254628443363283782332853857876372453144557606024162435425502
82+
414231425344640401425671247313254225752325627774572863823427628435276621555353276003524346445135344
83+
444014215230466136522431711445473522537227372726657772534226483275376766662531115626523414452105414
84+
433450111244440640533563144151113117278453728882746574687858827886235133216737041020563315330400051
85+
043413224423155241164263423653444422516645633847447523577743865447652437564632624466116150042552500
86+
034343233153545155011601574561726663612576786744276243622471222711311674626123164654601253202230221
87+
334424544214152026360221522751357747561434577416644336551153665531545226246342213505320031201441042
88+
444213310102503010334251632366652423612713524641262137252252513732611325223401240210534434334020134
89+
113234310313013130034263432336443446455536236436221526156612252522132633100613031453230501112202424
90+
142402332004051013660101510101263126711727662153761423762243333777317301206400030653210431512111444
91+
411034340051512350022551420314334411275415543216224154457677376654154362121625361111251523342230021
92+
401212212311255150514520514410354360022337233263271545513775531712533425164554033545254524043033243
93+
040034023233143153232242654250224010246422671266544421771125320425056106225340103411544104041430023
94+
202210233034441525003330614323226104160433060432454154126634040116105426512145204401511210203422322
95+
011431432013322542545215145526600364414641235513425454443064214552663664101101323545031512031302333
96+
020023210301103025401200032420642652143243335333016204055261530250106466135400230513140242434444003
97+
310203111441432251152455421244135150164323516554016042002411655305545265404525521215102013341240121
98+
012320311100031143153052200224256541012135453345356532252242115324133425054343145333123421144111230
99+
311310344433212432240252542030050542510636225454204032233645040015025321421052152330422440232330022

day08b/src/main.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pub fn main() {
2+
let d = include_bytes!("../input.txt");
3+
let s = d.iter().position(|b| b == &b'\n').unwrap();
4+
let g: Vec<&[u8]> = d.split(|b| b == &b'\n').filter(|l| !l.is_empty()).collect();
5+
6+
let mut max = 0;
7+
for x in 0..s {
8+
for y in 0..s {
9+
let cur = g[y][x];
10+
if cur <= 1 {
11+
continue;
12+
}
13+
max = max.max(
14+
((1..y)
15+
.map(|yy| g[y - yy][x])
16+
.position(|h| h >= cur)
17+
.unwrap_or_else(|| y.wrapping_sub(1))
18+
.wrapping_add(1))
19+
* ((y + 1..s)
20+
.map(|y| g[y][x])
21+
.position(|h| h >= cur)
22+
.unwrap_or_else(|| (s - y).wrapping_sub(2))
23+
.wrapping_add(1))
24+
* ((1..x)
25+
.map(|xx| g[y][x - xx])
26+
.position(|h| h >= cur)
27+
.unwrap_or_else(|| x.wrapping_sub(1))
28+
.wrapping_add(1))
29+
* ((x + 1..s)
30+
.map(|x| g[y][x])
31+
.position(|h| h >= cur)
32+
.unwrap_or_else(|| (s - x).wrapping_sub(2))
33+
.wrapping_add(1)),
34+
);
35+
}
36+
}
37+
38+
println!("{}", max);
39+
}

day08b/src/main_raw.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Implementation querying raw input, doesn't seem to be faster.
2+
3+
pub fn main() {
4+
let d = include_bytes!("../input.txt");
5+
let s = d.iter().position(|b| b == &b'\n').unwrap();
6+
println!(
7+
"{}",
8+
(0..s * s)
9+
.map(|i| {
10+
let icur = i + i / s;
11+
let c = d[icur];
12+
if c <= b'1' {
13+
return 0;
14+
}
15+
16+
((1..(i / s))
17+
.map(|ii| d[icur - ii * (s + 1)])
18+
.position(|h| h >= c)
19+
.unwrap_or_else(|| (i / s).wrapping_sub(1))
20+
.wrapping_add(1))
21+
* ((1..s - (i / s))
22+
.map(|ii| d[icur + ii * (s + 1)])
23+
.position(|h| h >= c)
24+
.unwrap_or_else(|| (s - (i / s)).wrapping_sub(2))
25+
.wrapping_add(1))
26+
* ((1..(i % s))
27+
.map(|ii| d[icur - ii])
28+
.position(|h| h >= c)
29+
.unwrap_or_else(|| (i % s).wrapping_sub(1))
30+
.wrapping_add(1))
31+
* ((1..s - (i % s))
32+
.map(|ii| d[icur + ii])
33+
.position(|h| h >= c)
34+
.unwrap_or_else(|| (s - (i % s)).wrapping_sub(2))
35+
.wrapping_add(1))
36+
})
37+
.max()
38+
.unwrap()
39+
);
40+
}

0 commit comments

Comments
 (0)