summaryrefslogtreecommitdiff
path: root/2024/go
diff options
context:
space:
mode:
authoromagdy <omar.professional8777@gmail.com>2024-12-09 20:09:16 +0200
committeromagdy <omar.professional8777@gmail.com>2024-12-09 20:09:16 +0200
commit9efb5b409fa624c40aaca777a41ff3fddf0da3f5 (patch)
tree0532522a8a99d206f3d5e09b794d80256d8abd97 /2024/go
parent01c6b2cb42a4144a573ec43e9e25c6718741a272 (diff)
downloadaoc-9efb5b409fa624c40aaca777a41ff3fddf0da3f5.tar.xz
aoc-9efb5b409fa624c40aaca777a41ff3fddf0da3f5.zip
Horrible solution for day9 but it works I guess.
Diffstat (limited to '2024/go')
-rw-r--r--2024/go/input/day9.prod1
-rw-r--r--2024/go/input/day9.test1
-rw-r--r--2024/go/src/day8/main.go26
-rw-r--r--2024/go/src/day9/main.go172
-rw-r--r--2024/go/src/log.txt193677
5 files changed, 193862 insertions, 15 deletions
diff --git a/2024/go/input/day9.prod b/2024/go/input/day9.prod
new file mode 100644
index 0000000..b632cf8
--- /dev/null
+++ b/2024/go/input/day9.prod
@@ -0,0 +1 @@
+8344894997247919706132254734322836346242207378552420699813367551416968491319512518592646626569964818974774915246474191615273835822122155863392343212388744802787509799317530256568863245614923305254301264433187808740258581391832216685255339465627821626616160796945678659742070505679162048351230462662134657336289125134609127637587179556211660248637174420289644745168422036297546281549714924698458874741151732877249461472972669785854652059743054161990184821114157695754917385788865696479538349175585329885343058959381137281419831724581867380443739887240649848497322891016775379905054433583235160808342443451429574552368601424932361247614871595742215112932129063537419107597154373762065534521923013699876168357613257215173576498973275143516765579884554871346649196969343219716736881915813332919372978425457289315465050792727931114482510927152306049917116203314407165241180253046975177829098509817168556923844454053506150402070986528277083357373192284318798115868758477312710272286968949561558747783545346702177445768789511682385238564696917682372236758392745584411349227834926896633403087456985715425934058858250394764475853507528229071851939383621481792629933878667906284878978952571939423328470793169422018932186215466816755205244172257179759441239627953614252511392161669478728616032624275786479837918134323306153943213904623341544476241748937683319124569491629166317588063205760641948298341226389538843931096428279691316198655935487902711173289234237874965432867729988157114833613512833721677315222145552241514356668773229416599524726822943338163359869508668724182183371299797566779143327945481583361985720626090649592266346853696546371595972364395978644595279339213495113764756151995923791623523831066659719963394897642771499479751426319264195658172779354688586274370705645805018842028675628739369718951257769855549399554252756163658262884535172664478298867172112605274494015775743793359761829419567938312725097941247923814546318206777436058622760309317361650577362671745809282184098485097275511811824542364858831241020763830479122616066184693717694196456632460267270818870208099266528101212696746801264565893423367732419387472945566714796546295475448386795883079416961256624245633516217267658559318993394384091698853692727955946123829533932315191907552587652197659238859364847465396312763436296572051884046863352492568181167697418391750421990107951929843274285793781233572631841501239594434423797264730325846441268663014826117806310653838634551948576815789185676235067998828287091282240235360148989699931702454679776941344239174833865461428542129774513122545454477345639816612847021681414461014895528749970122833781915254795355466237210672420522419362214458771833088784516195557276082323054496857985769842252223947403242595638923562438862777447557145868254376344413182467179877547245927663563534823835320186844969246577155852965273213788755544263195154716384752485997350446216262511694992616744622847791941672112973235446567188367475360357318822392272885641883523770466256714739976173743980816271905235834473613338326551266986635496106378448940779285252478283212935255144386466939174148991636754545825158137076879239839057756443996167131486181074658428636349951270885161599797567224274890431234597715461654993241129078451727888313533895509575219572137264369374416920908871782546369144198991218649216032376225716090756184993418275766768058167129389182757513738663957110985078233164178819232567836626529177711814916925152771411657621524477365336459364781212474336763292032829276668110652937904039414654916710506897663897788624983288392724267699305992939991191515241117247957351213374468639254333058667240142879254847543516409710812438484652875730885826496019439435184626304920567470616525569954439386147764389618259288301694821733754528272564371589689581324547183356767849376158996122178812756422922365345760802064579291495549337611641937114391372530136631511183696546203382178741676245899213662599181219279899792465265148264318962032137932924095468847159826227048788449243255846943717933118360528920942017271164354280546079643432506432722253677815104298748867838332121963621553602472848163745952472450833915204264534689938115456825646497161477691545769935844585115881952791588798711442144120226670146163228691622122377084191813953092346566317269262211351346624342964145255786226762437344282255191946137596344295945462955319374831646980148247159752376144914963746894687377795814849167624174239121132177251547109061655569609612308730883548438681369623389371881499139051593311964033293474795343768113673422997354186044546348203151859523913462255716772424527367478838418883237942888367173588809125946247998298642674308225937821522878183152371062148146526140128979878773486356709011378011599731697637736984321044693145574422388589598671437083351096321633241637891159924652561834633523613517419677259885379151484846527569435186157071933818449566474793725614497187593626448599916961391632593681397354857591498396415531233937477858543594228734282814328439359358667579728876281543909970499678882540634370934942694518798158632251863332161192454015298943418470352537507891711669351510491929149341492384658353489111675432141731814816486810471640204438893552455716895474288350595695773461425140984391648096337354398582302736948020432515373150781652426562247229765682251446519461805284786848162774288170204566353711151163371347563642135729387095349227937940797037848831208064371781986678895075601449715099566198594229298141336937734820465113459911227920817092233082913636259867937623661853802724221849163931728541156411219587427492621083734820695294784834253297679681787837395220578338793028957195134414174864329958743138859234495396628125501542815114266992646760562855865739516774793021249323872171135766544315311856209547851284659329783441314944377563384717996016232011886143967557971287938551987245334734772051905269476384145322199271431844444165235972679776862886218280201420903971837631942082934151884935885416153022652657823529936237618175514592459921126312443254321527441396386988167777366816836754825483142476275134649881243011651755841225683592719477636092841270355927969662556898509859742911507445637377718399876535972098812751883098383631683980704423139081646299943264406720383294252667435564818026802125261991712736625814965623829837903421201387285083122618989127982659614818401192259382586168248885805331245557997340521255782733888156471766709982979753915925907511531728273341702248597176563551814647193141222429888866441096437830173630292638442987417232406410683020562192134464464436975367408821135979363116627210152184663967303765505723539392459254807285497331794783828292956795407859599469108788156181371133853021491993155569944472112275701281894785422045491844426723706345944759222719741250224761128859902764622155673964396744685355612259468974381660207347145224164761812194291245883223171474553918559230661639624922341214901739879617897879325318866074625740417869205890797899873143428751778435507487586060107911742185573460344512265633645121413961261956968461131654215646378525995971497342101733654767694089696315891656858925208924862889847258812765516277649847277448992975737481688752408164459611764410586297362535363829146929598589585218205066534911414872851059253893919060751065441172627171917065309263324045114713623192141338679420486344894399498564259487491312529911924366624856808055113441217232425528888815118288339090218070644096878812488855858557102541757860938728755223256518843453606524923550782161272450263097235223876685486394553471709611464684671867438382668670921193692159992136856353544521891247569228403695114774461151157118612071103526764114156743782825374780639350744696988848822741677496109010841447745521895844884987411676512131775183988760896495926432899779308757172073926681944552932351972233748359316063452624364977312869926185857242344619483631744986621156616798881687949355705555399958595558818789264181276742145768119555117710217715639779435828392213197644597554242172522917428989968661529570467150478073646123471296117727375088112576153725961995514225863040456138146820481125727141269112318076906387344836753770451954307549764676533255445051607883576570993228237714692667781555791087909553364250218950147265232438497352574217651521841571664888489454789069562997721597468697235879569355746046462477867874512297598439577291546320423747465962223072165411797941806524113791469174248829633923685779606193909937708268145733794921285945713329284687595236899472209246371829214164969748628924562633934987951753378768967034701248919532612227202119997678937930967529825665443387492334944792555633694267288091414123648382756649699538396999415840786560205132981447461189583399915369861016187338242664207892242468875036692022736022186317976966727234469756817160639195442118391690802035941391993617267880972350148795986950903920263938909928968974433443645337517273462195566561963975203659283688227792445753142782585723751481917441996077256285747275548455285074886998674130487967825587889027519257875092111727868222183136428652121225385821412986253641142927654169544074623872437972253613656229888221304520664260443399358929211272982824417564562950857165142343252392976831988879214811345988604867819090525196913585659689568993964736712917439432427141495147149053817733244174278032209761581361411324487089239214565923387485174617749244864274557744591784487322623656502948409512417588398016982472162271768412283099466683755050206685889836824868194068409554648265573437953828389872189931944035566263625157686449424877904744346991754436871374579472656239172797849371497443598592369083895680526059178338848354666365142861915966734937839231735444796621875454912317673876931073231762346316349069479337633767569581168275497393145342765935324332435112231947597722483582165285871975581493397093536790681278729385231315976598645437254134303444188928856239402438158538896871925117692565439884594019698088261122726919311188149484891576778536613257453623207794844166557616738582366829311062496466335676495693612675515298779321929868794580528246558014721070423017508036353144631943533752877566792746442475435481292283424383891783833642774183163619873925963349586042945360618950737342297486709369181558813521707753418177113985239753278571771516473817151022501418124696114628673149884075467151792128426345898917951240204121739059307711415692862431542127253683281751571443454754518557422786162440877830117524273117485125812146874457418634397976221340594067811831723381698318934867423347489190829228195854447289608821987751615787414410391579135738648766758292686554177321355531225357337768865842468678414767611672443684269662237773502429135754376885432310586794506931867134796782221859527491745010449459423946809514772116576846135780891780444194904720171857612842989754754488757727469885608888762139426126278640621492808833644641786530984585604767988652608340751892297037923738707931745489661561299850423916331256678829659437602999914559102178626278665173712198774096721563948174163315965219347526165037505153271471905731992750162452999273279898552887676460921252207254659142154140408873133474796872982682542880324691248879457295271240996142702178287727309884828343347336428145484339106073991492405936186480924758621086827886354782362045616915661517851912105949698324719615256113929138938665877765615667677854989418612151552937159255677931433437732312597280105571149582769413966981923182346466278065225733109639821710455284182068887382332054974616927080792359911642219129648648172333628217178388727431992232124437667420786267912275954430392443156751656210498788217644501095127241773759906155166960259898938114149999396914257834561673341790626360849288674718868936149449244789423337187078331239579395823619895157477865241331332630683265167177686223209832342913122556556266338113133777775853686828284620207566332165277079345146128956907311688255547384883993964627813597208381811171768140457861107044106343962946356485323099303523216824661544759251549130226524918326417515432678611415827239564385287868709074948145776343394586579265772455531577946016414148781060377436259461372213132983935111106686961574569198693253373179166592946321299818417985112590512499605734814172363027245660839574646162561365555390534391406278221463833915561091335534913315181045591119745892561173844195132591743768481043138729169911985519537710334075285810503546232240352483571549876112741124603067903382489975436373794445625121746773751010473815899527454142992293952667831329422217964328632176749948345825228944235254169029649381462164177840519815936146642834468386452435602357257767972984917161639467101717395498688321373777584831311168833696563665966549739298861183212722844997439386953845528813161346427380113944641412701345858394351068717145108428118087532876448330142094601776638177374336387587632963566880234582909354916611777173852066205553216251507782781754534115299453351526826979307269874784467453989317195580889340191526779181676014816478223036988454669210661268294845677799753043547812871687668057845311589495599769342463394270432553944428928774754689246017238278314754538783588894902170918768773870167481758222416766646489174859296393237643759161275073684885722242589534585474908688567380161914945967737739352556839824472430459930874039556212868670167273298223766854767398876023745886901922521049959661867377439499235276392492488737512436473120752796834781812863497710287999522721516474793755631243183353396657275828572255696092535417946266746210201275946628786619898533882799962050223095525258939373637620991444738791646395125232936426496758745277437284904886149553243169478692215999141570188215506839523958323316579423754631185767919488994852287996939441348387321868975789383159243036968459556026807884163447732497489388944826174667259721863548546037406719887572132168795019168585492522899929384368569431674024926213754193614236102661718544285480444586265567879538789856174014765296543897638785367979773914556723673719234565471952778945995313719224726627873950975128771876301665564150159487881156822188814451948921612461766593396288156288604334369179489222743521351392904390945353909230537068739360898777361184611421933852288091657214166364435596979175346789401612605499177111928691693438164363424618801745161057418410664428775472973489973814637981612723389234119743805780892591829088578869455855353597484263844833575298973996706854312079933653201261152235482763768078423288958292407143971512123218782956488433947393498749621977443337585824213614165142696388559215678289499467211872204663906055426824983715735766917395683853698999419750231250487531285177372426601564799581245224698786688152276342325310378931749671177161563780701333296577525632173520697623993789418234188142403515924651789631326116185195247744805888115668601244795776597696987086267380413071749097285850622876577564188888463131782356971596692997567898904277405169488069604522896451726630816786387092613074633133765446701679294896885592665935905032719470467690681668142161332679183729102627728172828655963715116653939932567367552277982794596736338265665021601035846625329222675445791022414426662935613816379990785532591139949232434219931033533765883783642273381921596961715366278136101451594543787171969563651222851738239448343178358263733486793195175998384062777457869620996070708894663452431623378478915889591420777921391859472760915347393784494746654446681118516799802642219774524471655980528269498093691537972010988396605425816053168335548455332983132858135736831548525265894155885019917995456555928573496578467320334746312133622226919688732355146670548477767762596820694783893077372641562613675561291778463339432530876738982474281688824436439179307183405380526777659463874998386963228764494473402866134579876831326858529849616261433417873243794614354391112379832734146262319540955572324126445696542023557366883598224228917244196273344195313818296246504529839492583039323568205475597124796117495648614148934821563450783225281928658167823055248215175765997099901257925674948769409398574397468688688296192018463189912839662186792196164133526556676735799186649124545310995840136955713170432266747243968331204682114893374482424923432247592776492362675098155246214358537538433012178113163135476026949521393870283097608064283940336489472186441344391134111297348269253937732770847767132718709293667654796867277744552121794414855649261334402168382444114272585525149938178693335572293143503118727724736829683942302447357314984741747193691079809320584928381928409248856817514396227567389686135540664924559596676951567223923638764032634629917117433879794280181943373752537879114599947482266596736314941097289450924633882851395152795836416175774522313715903755657798516979572566313555237239958272869941123199665674566361254688325446589148185234266173466989107363944192798620541611209019911974142793433556892292319252348110311119773494859599531018909999481561168763821479215553993493493997203442573090643927667894225582161665927917197867812256212149179054772275523299382385732196957012661024629759802732628769577862692775977616645155978797407118304080311314193590521193463333299129144219448461545235351398203292811131997519403253506075826118779646513631176193831335765893587813653690324995214319967491299829107352403213752139136720559138282559272337745221943843533611492151736233769556183542369341173927782139409069868571534079601545891962631862598987811560966060482871793345669692426333317242864716387654588531721777132011617119523098753310916621288840967062255145204110925862115166971771381653982733613969715121137975621788502690497799742497942647274968441898433849925693854673788237614922425917211839757446928161133465264941246951276992366965302962524377681758892756498070769112953691959849567936931074598428432662872798265296356676146324179073799763612190325990956399226256756255495413427058182753252952975335557826981710951465612935109567962311319031694592419825765392348854714651131984818258806258181575158370204732749625559080959032354611423338717913776273469689994622314781186948399943528823842675463052838864778278121278651015998625221840786252259282932284892386696830962462994994396073736270729946722428661473101958451168628954489583691116336039429951125017687726595494373671163867328688864552762960481137787491154756957391361537368581738229468838645380396840174882701091537972907884563968907964972899482612357011836678479788959229844133787274312067711365736440281989989373502560547043407418753571976515931114387491198669338942686041307949505461422768734376175873568278374220806757467113881916113686774095788176652379187875658873196827796686347787934489212542288660439090731785642397778877807241353791881085221511859724212142909175353482738986501051835556784027184975839369168416343951902263223714569329911259457831495493771722114494163240264074799479954342791877935417732610651110512221365412518791256495611586418148915286306072142067196869625732881873898517248858602373346653471081567270556369795740678720282866569611618265682414642017824363509025468696415233881742121641761335158415159768195045583616411913894819923353964768921520561518997651571437888124283569766714345781358555126441957472244677825585178022291464805672592081931999464560447884157928784171413165677542979831558425374971619790321511211184327249189875825183853346745852184640936572684359209238747797995557897490166611771682669180395999943078142898182843519039844047439414246872142787979314712840642592871493628533138483191164605220312864131513516082347721511768454875639984114746874915398899352926566813676662299518213064598618368290924312228758378232493858436388696532863712603919664361903350587449595188514084262292586957392854154239777228715472828139912048561994661646424153792690346750862587511619515984481188389138769883456587397820982248377657793940616668936634572085409516661055134380321215793642209011492063381915753332198038652832709441189689562589865577945419416810854853867974892154621485257926766072507298823585697921538473481324114692791881875699857794215917558036462396675014118336182570206713107930316152611574942351385680732132948932911432143124414960312845127143135299439861759098114576334147375981265924804512151510949430823637365643681041775623581475539198479
diff --git a/2024/go/input/day9.test b/2024/go/input/day9.test
new file mode 100644
index 0000000..f96c390
--- /dev/null
+++ b/2024/go/input/day9.test
@@ -0,0 +1 @@
+2333133121414131402
diff --git a/2024/go/src/day8/main.go b/2024/go/src/day8/main.go
index ab5901d..e801340 100644
--- a/2024/go/src/day8/main.go
+++ b/2024/go/src/day8/main.go
@@ -49,21 +49,17 @@ type Points = [][2]int
func getPosMap(grid *Grid) map[rune]Points {
n, m := len(*grid), len((*grid)[0])
- posMap := make(map[rune]Points)
+ antinodes := make(map[rune]Points)
for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
curPos := Point{i, j}
curRune := (*grid)[i][j]
if curRune != '.' {
- if _, exists := posMap[curRune]; exists {
- posMap[curRune] = append(posMap[curRune], curPos)
- } else {
- posMap[curRune] = [][2]int{curPos}
- }
+ antinodes[curRune] = append(antinodes[curRune], curPos)
}
}
}
- return posMap
+ return antinodes
}
func isValidAntenna(grid *Grid, i, j int) bool {
@@ -76,9 +72,9 @@ func isValidAntenna(grid *Grid, i, j int) bool {
func solve_part_one(data string) int {
grid := parseInput(data)
- posMap := getPosMap(&grid)
- set := make(map[Point]struct{})
- for _, val := range posMap {
+ antennas := getPosMap(&grid)
+ antinodes := make(map[Point]struct{})
+ for _, val := range antennas {
for i := 0; i < len(val); i++ {
curPosI := val[i]
for j := i + 1; j < len(val); j++ {
@@ -88,22 +84,22 @@ func solve_part_one(data string) int {
firstAntennaPos := [2]int{curPosI[0] + diffOne[0], curPosI[1] + diffOne[1]}
secondAntennaPos := [2]int{curPosJ[0] + diffTwo[0], curPosJ[1] + diffTwo[1]}
if isValidAntenna(&grid, firstAntennaPos[0], firstAntennaPos[1]) {
- set[firstAntennaPos] = struct{}{}
+ antinodes[firstAntennaPos] = struct{}{}
}
if isValidAntenna(&grid, secondAntennaPos[0], secondAntennaPos[1]) {
- set[secondAntennaPos] = struct{}{}
+ antinodes[secondAntennaPos] = struct{}{}
}
}
}
}
- return len(set)
+ return len(antinodes)
}
func solve_part_two(data string) int {
grid := parseInput(data)
- posMap := getPosMap(&grid)
+ antennas := getPosMap(&grid)
cnt := 0
- for _, val := range posMap {
+ for _, val := range antennas {
for i := 0; i < len(val); i++ {
curPosI := val[i]
for j := i + 1; j < len(val); j++ {
diff --git a/2024/go/src/day9/main.go b/2024/go/src/day9/main.go
new file mode 100644
index 0000000..83351b4
--- /dev/null
+++ b/2024/go/src/day9/main.go
@@ -0,0 +1,172 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+)
+
+func InsertAt(arr *[]FileBlock, index int, value FileBlock) error {
+ if index < 0 || index > len(*arr) {
+ return fmt.Errorf("index out of range")
+ }
+ *arr = append((*arr)[:index], append([]FileBlock{value}, (*arr)[index:]...)...)
+ return nil
+}
+
+func RemoveAt(arr *[]FileBlock, index int) (FileBlock, error) {
+ if index < 0 || index >= len(*arr) {
+ return FileBlock{}, fmt.Errorf("index out of range")
+ }
+ ele := (*arr)[index]
+ *arr = append((*arr)[:index], (*arr)[index+1:]...)
+ return ele, nil
+}
+
+func FileRead(path string) string {
+ file, err := os.ReadFile(path)
+ if err != nil {
+ fmt.Println("Couldn't Read file: ", err)
+ }
+ return string(file)
+
+}
+
+func parseInput(data string) string {
+ return data
+}
+
+func genereateBlockMap(diskMap string) []string {
+ var blockMap []string
+ id := 0
+ for i, ch := range diskMap {
+ rep, _ := strconv.Atoi(string(ch))
+ if i%2 == 0 {
+ for i := 0; i < rep; i++ {
+ blockMap = append(blockMap, strconv.Itoa(id))
+ }
+ id += 1
+ } else {
+ for i := 0; i < rep; i++ {
+ blockMap = append(blockMap, ".")
+ }
+ }
+ }
+ return blockMap
+}
+
+func genereateFileBlocks(diskMap string) []FileBlock {
+ var fileBlocks []FileBlock
+ id := 0
+ for i, ch := range diskMap {
+ rep, _ := strconv.Atoi(string(ch))
+ if i%2 == 0 {
+ block := FileBlock{id: id, space: rep}
+ fileBlocks = append(fileBlocks, block)
+ id += 1
+ } else {
+ block := FileBlock{id: -1, space: rep}
+ if rep > 0 {
+ fileBlocks = append(fileBlocks, block)
+ }
+ }
+ }
+ return fileBlocks
+}
+
+func moveBlocks(blockMap []string) {
+ i := 0
+ j := len(blockMap) - 1
+ for i < j {
+ if blockMap[i] == "." {
+ if blockMap[j] != "." {
+ blockMap[i], blockMap[j] = blockMap[j], blockMap[i]
+ i++
+ }
+ j--
+ } else {
+ i++
+ }
+ }
+}
+
+type FileBlock struct {
+ id int // id -1 will be the free block '.'
+ space int
+}
+
+// i = 1 j=12
+// [{0 2} {-1 3} {-1,1} {1 3} {-1 3} {2 1} {-1 3} {3 3} {-1 1} {4 2} {-1 1} {5 4} {-1 1} {6 4} {-1 1} {7 3} {-1 1} {8 4} {9 2}]
+
+func moveBlocksPartTwo(fileBlocks []FileBlock) []string {
+ for i := 0; i < len(fileBlocks); i++ {
+ if fileBlocks[i].id != -1 {
+ continue
+ }
+ for j := len(fileBlocks) - 1; j >= i; j-- {
+ if fileBlocks[j].id == -1 {
+ continue
+ }
+ if fileBlocks[i].space == fileBlocks[j].space {
+ fileBlocks[i], fileBlocks[j] = fileBlocks[j], fileBlocks[i]
+ i++
+ j--
+ break
+ } else if fileBlocks[i].space > fileBlocks[j].space {
+ _ = InsertAt(&fileBlocks, i+1, FileBlock{id: -1, space: fileBlocks[i].space - fileBlocks[j].space})
+ spaceJ := fileBlocks[j+1].space
+ fileBlocks[i], fileBlocks[j+1] = fileBlocks[j+1], fileBlocks[i]
+ fileBlocks[j+1].id = -1
+ fileBlocks[j+1].space = spaceJ
+ break
+ }
+ }
+ }
+ var blocks []string
+ for _, block := range fileBlocks {
+ if block.id == -1 {
+ for i := 0; i < block.space; i++ {
+ blocks = append(blocks, ".")
+ }
+ } else {
+ for i := 0; i < block.space; i++ {
+ blocks = append(blocks, strconv.Itoa(block.id))
+ }
+ }
+ }
+ return blocks
+}
+
+func checkSum(blockMap []string) int64 {
+ var sum int64 = 0
+ for i, ch := range blockMap {
+ if ch == "." {
+ continue
+ }
+ id, _ := strconv.Atoi(ch)
+ sum += int64(id) * int64(i)
+ }
+ return sum
+}
+func solve_part_one(data string) int64 {
+ diskMap := parseInput(data)
+ blockMap := genereateBlockMap(diskMap)
+ moveBlocks(blockMap)
+ return checkSum(blockMap)
+}
+
+func solve_part_two(data string) int64 {
+ diskMap := parseInput(data)
+ fileBlocks := genereateFileBlocks(diskMap)
+ blocks := moveBlocksPartTwo(fileBlocks)
+ return checkSum(blocks)
+}
+
+func main() {
+ test := FileRead("../input/day9.test")
+ prod := FileRead("../input/day9.prod")
+ fmt.Println("Part_1 test: ", solve_part_one(test))
+ fmt.Println("Part_1 prod: ", solve_part_one(prod))
+ fmt.Println("Part_2 test: ", solve_part_two(test))
+ fmt.Println("Part_2 prod: ", solve_part_two(prod))
+}
diff --git a/2024/go/src/log.txt b/2024/go/src/log.txt
new file mode 100644
index 0000000..64192c6
--- /dev/null
+++ b/2024/go/src/log.txt
@@ -0,0 +1,193677 @@
+bytes: 0099811188827773336446555566..............
+0 * 0 = 0
+0 * 1 = 0
+9 * 2 = 18
+9 * 3 = 27
+8 * 4 = 32
+1 * 5 = 5
+1 * 6 = 6
+1 * 7 = 7
+8 * 8 = 64
+8 * 9 = 72
+8 * 10 = 80
+2 * 11 = 22
+7 * 12 = 84
+7 * 13 = 91
+7 * 14 = 98
+3 * 15 = 45
+3 * 16 = 48
+3 * 17 = 51
+6 * 18 = 108
+4 * 19 = 76
+4 * 20 = 80
+6 * 21 = 126
+5 * 22 = 110
+5 * 23 = 115
+5 * 24 = 120
+5 * 25 = 125
+6 * 26 = 156
+6 * 27 = 162
+Part_1 test: 1928
+bytes: 00000000999111199992222222299999999933339999999994444444449999999559999666666689998999879998999798888888999999910101097111199979121212129979997131313999714141499151597999799161616979996171717999618181818181899191919199620202121212121212199922222222222222699969992323232323699962424999625252626262626269996999592727272727272727279959995928995292929999599303030303030309499931313131314323232329333333333333994999499343434343434949994993535353594999399936299379299929993838383838239399992940991999194141414141990999099424290999043434343999099444444444444994545454545458999846464646464699989998947474747474747474799899948484848899989984989988998505050505050505050899889951515151789968952525252525252968953535353535353535395454545454685555555599689956565656689968957575757958585858585858585855959595959598606060606099616161616161615896262626262626262958636363636399589948646499654866669676767676794899686868686868686848994869696999370707070707070707089717171938972727293738974747492899289757575757575757592899187676767699187777777777777777787899189907979797979797979899089980808080808181818181818181810899089828282828282828282908990899838383084848484848484899088585858686999798787878787879979988888888888897998799898989898989898987998790909099919191918799892929292929279393939399879987994949879595959696969696999797979797879998989899771001001001001001009977101101101101997102102102710310310310310310310310399779971041041041041041041041041051051051051051051051057997799106106106106107107779971081081081081081081081087997710910910910910910910910991101101109679957991114799379911211211227113113911411411411411411492799211511511511511511511511579927116116991791171171171171179171181181189917991791191191191199179911201201201201207991791211219179907122122122122122122122122991230799961241249996991251251251251251259126126126126126126612712712712712712712812812812812812812899969996912912912912912912998699869913013013013076997131131131131131131699769913213213213213213213213276997613313313313313399769976913413413413413413413497691351351361361361361361361361371371371371371381381381381389669961391391391391391391396996699661409966991411411421421421425699569914314314356994144691451451451461461461469469941471476994691481481481481481489314969915015015015036993615115115115115199369921521521526991531531531531531532615415415415415415415415499269916915591156156156156156615715715799161581581581581581581591591591591591591591591599160160916991616116116116116116199116216216216216216216269916163163163163163163163163990699016469906991651651651651651651651651650699916616616616616659985916716791688599851691691691691691691701709985171171171171171171171171998599172172172859985917398599851741741741749975175175176176997599751771771771771771771771771779975991781781781787599179179179179179179179759918018018018018071811811811811811815997599718218218218259183183184184184965996185185599659965186186186186186186186996591871871871879659961881885995599518959955190190190190995599559191191191191191191191919219219219255994599419319359941941941941941941945994599451951951951951951951951959945196196196196196994599451971971971971971971971979945993198198198198599359919919919919932005993520199259922022022025920320320320320320320320392599252042042042042042042049920520520520525992599220620620620659925920792592082082082082082082089120920920920920920920920920959915992102101599152112112112112112119915990592122122122122122122129949994921321321321321399499949214214214214214984921521521521521521598499216216217217217217217849984998218218218218218218218499821921921922022022022022049982214997492229649964992232232232232232232232232232246499649922522522522554995499226226422742282282282289229229229229229944994423023023023023023099349934923123123123123193499342322322322322329934233233233233233233233233233923423423423423423423493423523523523523523523523599249236236236236236236236924992492372372372372372372372379249914923823823823823823891499239239239239239239149914990240240240240240240499024124124124124124124149993999324224224224224299924324324324324324324324339924424424424483997399724539973992462462462462466399524724724724724724724724739953248248248992492492492492492492492492495399539925025025025025025025025053995251251251399525225225225325325325325339953995254254254254254254254254254399432552552552552552552552552559942562562562562562562562563257994258258258258258258258392592592592592592592592599260260260260326126126126126126126126126139933993262262262326326326326326326326399264264264264339932652652652652652652652653266266266266266266266266993399267267267267267267267339268268268268268268268268269269269269933927027027092399232712712719923992392722722722722722722722729239923927327327327327327327392274274274274275275275275275275399227627627627627627627627627639923991277277277277399139912782782782783990399032792792792792792792799992802802928128128128128128128128199299929928228392999228428428428428428428499929992852852852852852992862862862862862862868299829982872872872872872872872872872882882882882882892892892892892998290290290290299291291291829982922922922922922922922922992932938292942942942942949295295295295295295296296296296296296296296297297297297297297297297829298298298298972992992992992997300300300299730130130130130123023023023029930330330330330330330330330372997304304304304304304304299630530530530530529962306306996307307307307307307299529953083083083083083083092995310310299531131131131131131131131131129931231252931331331331331331393143144299315315315315315315315429932316993231731731731731731731731799329933182993231931931931931931931931931999329320320320320320320320932932132193322299323239324324922992299325325325223269932732732732732732732732732732832832832832832822932932932932932992233033033033033033033099223319922991293323333333333333333333339029933433433433433433433433433402990293359029933633633633602933733733733733733733790233833833833833833833899919933933934034034034034034091999341341341341341199342342342342919993433431344344344344344344344344344993453453453468193473473473473473479819981993483483483483483483483483488199819934934934934934934934981997135099719935135135135135135135135171935235235235235296199613533533533533533539354354354963553553553553551995199356356535735735735735713583583583583583583589953593593593593591995199360360360360360360519936136136136136136136136136151995199362362362362362362362362362419931936336336392364364364364364364364199213659921366366366992193679219923683683683683683683681991193693693693693699119937037037037037037037001990199037137137137137137137137119901990372372372372199013733733733733739901374374374374374374374374999099937509937637637637680997037737737737737737799703783783783783783783783783789379379379379379379379379379970996380380380380380380380380380099609381381381381381381381381381960382382382382996383383038438438438438438438438438499609963850996093863863863863863863869603873873873873873879950994038838838838838838838838893893893893893893893893893899390390390390390309930993913093923923929303933939930992093949209920993953953952099209396396920991099397397397397397397397109910993983983983981039939939939939999104004004004004009910991401401099109914024024024024024024024024020994030099040440440440409999840540540540540540640640640640640740740740740740740799989998940840899898984094099898989410410410410410410410410410897411941289794134134134138979897941441489798415416416416416416416416416416974174174174174174174179418418418418418894194194194204204204204204204214214214217989798964224224224224224224224224229423423423423423423423842496989642542542642642698942769894284284284284294294294294294294296430430430430430430989594314318949432843343343343343343343343343443494989435435435436436436436498949437437437437437437437437437894989343843843843843894394394394394394394398939892440440440440440440440440984414414414414414414414414414424424424424424424424424429298929844344344344344344444444444444444444444444492989298445929892944689298944744744744744744744744729891448448448448448989198449449449449449449449449449914504504509891989145145145145198914524524524529891945345345345345445445445445489045545545545545545645645645645645694574574574574574584584584584594594604604604604604604604614614614614614614614614618909890946246246246246246289098463463909890984644649098909465465465465465465465466466466466466466466466899467467467889984684684684684684684688994694694694694694694698894709889988994714718847247247247247247247247299884734734739474474474474474474474474988998847547547547547547547547547598889888476947747747747747788898889478478478478478478888978894794794794794794794797889748048048048048048048048088974814814814814814814818897889482482482748348388978894844854857889688486486964874874874874874874874878896884884884884884884884884884889688964894894894894894894894898896889684904904904908968895884914914914914919488944928894849349349349349389488948494494494494494494494894849549549549549549549589488934964964964964964964964968894974974974974973889498498498498498388499499499499938893500500500500500500500501501850250250250250250250289388935035035035038893504504504504504889388950550550550550550528892889506506506506506506506288928895075075075075075075075075071889050885095095095095095098908899751051089851151151151151151151151178987512512898513513513513513513513513789875145145145145145148977515515515515515515897789778516516516516516516977897789517778977851851851851851851896789678519519967520520520520520520520895215216785225225225225225229678967523523523523523896789675245245248957895785255259578957526526526526895785275275275275279478947852852852852893785299530530530378953153153153153153153153153137532532893789353353353353353353353353378953453453453437893789253553578927853653653653653653653653692789278953753753753753753727892753853853889153953953953954054054054154154154154154154154178917895425425425421789154354354354354354378917891754454454454454454454454489178545545545545545545545954654654654654617895475470789054854854854854854854854854878954954954954955055055055055007899689551551551551551551551551968995525525525525525525525526855355355355355355455455499689968955555555555596899685565565565565565569968557557557557986898655855855855855889868986559559559559559898560560560560560561561561561561561561689865625628986898656356389564564564564564564564564564565565565565565565565856656656656656656656656668976567897689768568568568976897689569569569768976895705705706689665715718572572572572966896685739668956574574574574574574574574574895755755755755755755657657657657657657657657657689568956857757757795657857857857857857857857889568955795795795795795795795796894685805805805805805809468946581581581581581581581581581582582582582582582895835835835835835835835834689584584584584584584584584468946858558558558558558558558593689368958658658658658658658636893689587587587587587587587587587368935885886893658958958958958958958985905905905905905905905905909265915915915915915915915915918926592592891593593593685945945945945945945945949168595595595595595595595596596596596596596596916891689597597597159859859859859859868916891659959959959989600600601068906896026026026026026026026026029586036039604604604604604604604604958995605605860660660660660699586076076076076076079958996086086086086086086086085609609609609609609899589961061061061061058985611611612612612612612896136136136137589614758975861561597616616616616616589758961775896586186186186186186186186186189658965619619619619619896589658620620620620955862195622622622589458945623623623623623623896246246246246246246244589458946256256256256255896266266266266266264627627627627586286286286286289462962962962962956308946316316316316316316316316315863293589363358935863463463463463463493589358963563563563535893586366366366366366366366369258925637637892589256386386386386386388639639639639639639640640640926416416416416416415864264264264292643643643643643643643589256446446446446446446448915891564564564564564564589156466466466466466466468915891586476476476476476476476479156486486486486486486488915891586499058905865090565165165165189065265258965365365365465465465465465406556556556556555896566566566566566566566566569489657657657946588996596596596596596596596596596606606606604899486616619846626626628984663898486646646646649848665665665665984898466666666666666666689667667667667866866866866866866866848986696696696696696696696694897489646706706708964896671671671671671671489648966726726724896736489548956744867567567567595489676676676676676676548944893677677677677489348934678893489679679348924892680489248681681681681681681924682892489268368368368368348924892684684684684684684684684685685685685685685489686686687687687687687248914868868868868868868868968968968968968991486909148914896916916916911489148969269214890489069369369369369369369369348969469469469406956954869669669669669669690469769769769769769769769789048993869869869869869899369969969969969969969969989938993700700700700899701701701701701701701701701389702703703703703703703703703703938993704704704704897057057057057057057057059370670670670670670670689838983870770770770770770798389838970883870998389871038983897371171171171171171171171189738971271271271271263896713713713713713713713713713389714714714714714638971571571571571571571571563896387167167167167167167167167167177179538953718871995389537207207208972172172172172172172172153895389572272238972372372372353724724724894389472572572572572572572572538943897267267267264389438947277277277277277273894372872872872889472972938943893730730730730730730389238973173173173173173173123732732732732732732732732732892389238733733733733733733733733913891387349138973573573573573573573517363891737737737737737737737737389738738738138913739891740740740740740374174189138903742742742890743743743743743743743387449038907457457457457457457453890389746746746074774774774774738748748907493899750750750750750289927517517517517518975275292897538289875428977557557552897275675675675675675689728975775775775775775772897289758758758758758758758728962875975975996760760289628952761761761761876276276276276276295289763763763763763763763763763528952895764764764764764287657657657659528952766766895289767767767767767767767767427687688932893287697697697699327707707708927717717717717717717717712772772772772772772892773773773289227747747747747747747747747748912891277577577577577577589128912877677677677677677777777777777777777777791289177877877877877877828912890779779779779779779779287807807807809781781781781781781781781917828981898178378378389878478478478478478478417857858971897187867867867867867867867867869718971787787787787787787787787787897189778878878878878818961878978978978978978996189517907907907907907907908951895187919518792792792941793793893189379479479479479479479479479418937957957957957951893796796796796796796796796179779779779779789318931798798798893799799799799799799180080080080080080080080080089318931801801801801801892189280280280380380380380380318804804804804804804805805805805805805805805805806806806806806806911880780780780780780780780780791189808808808808808808808808808118098098911898108108108108108100188118118118119018908128128128128128128128121899081381381389908981481481481481481481481481490899081581581581581589908168168168168168168998178178178178178178170818818818818818899089808819819819819819970896089820820820820820820820608218218218960898228228228225088238238238238238238238238239508982482482482482482482482482450895088258258258258258258258259508958268268268260895827827827827827089508940828828828828828898298298298298298298294089408948308308300898318318318318318318318318313083289283383383383308920892083483483483483488359208368368368368368368368920898378378378371089008838838838838838900890839089008408900890088418418418418418418418418419997984284284284284284284284284289843843843798979884484484484484484484484484498458458458458458457984684684689798847847979848848848848848848848848897849850850850850850850989798851851851851851851979898528528528528528528528528527979797853979797979854854854854854854854854854796979855855855697856856856856856856856856856969785785785785785785785785796979697985885885885885885885869796985985985985979860860860860860860860697959786195978628628628628628628628628629497949798638638638634979497864864864864864864864864864949793986586586586586578668668668669386786786786786786797986839792979286986997929787087087087098718718718718718718718718712979287287287287287287297929873873873873873873873873787487487487487487487491875875875875875875875979197987687687687687687687687687619787787787787787791978788788788788788789197919787987987987987987987987991979880880880880880880880880197919881881790979088288288288297988388388388388388388388488488488488488488488588588588588509790988688688688679097887887887887887887887887888888888888888889909799878908908908908908908908909987891891892892998799878938938938938938939987998894894894894894798879895895887988798968968968968968968968878978978978978978978978978979888988988988988988987988797878998998998998998998999900900900900900900900900787978797901901901901901890290279687903903903903903903903968796890490490490490490479587958790590590590590590590590595879906906906906906587959079079079078795879589089089087948794879099099099099099099099099099487991091091091091048799119114879391291287938799139139139139133879389147938799159159153879389169169169169167928792891791779287991891818791879919919919919919919919919187992092092092092018792192192192192199229229229229229229220892392392392392392379087992492492492497799259259259259259259259779977992692697799779992792792792792792792792777997799928928928928928928779977992987798779309309931779329329329329329329339339339339337993493493493493493493477799359359359357779777979369369369369377797793893893893893893893879777969399399399399397796779940940940940677941941941941941941941957795779942942942577943943943943943957795779944944944944944944944577957945795779479469467947794779479479479479948948948948948948948948948477949499499499499499497794779950950950950950950950950950377951951951951951951951951937952799539539539539539539533795495495495495495595595595595595595595595579377929569569569569569569569569567792957779589589589589277927959959959959959959959959959799609609602779277996127799629629629629622779963963963963963963177964917791779659659669669669669669669177917967967967967967967967791779196896896896877996996996996996996997097097097097017791779971971971971971971079729727907790973973973973973973974974974975975975975975975975975975779976077907797797797790779097877996797997997997997998098098098098099679969819819819819819819817989829829829829829826798398398398398398398679869847986798985985985985679869869869869869869869869869879879879879879879879879877998898898898898898898898886989798679869909909909909919919919919919919919919917976797699299299299279767966993993993993993994994994994994994994994994796679699599567966799969969969969966679699769989989989989989989989987999966796671000100095671001100110011001100194671002100294610031003100310031003100379461004100410041004100410041004100479467100510051005100510051005100510059367936710061006100691007100736791008100910091010101010101010101010101010367936101110111011793679361012101210121013101310131013793679210141014101410141014101410141014101461015101579101610161016101610161016210171017101710171017101710181018101810181018101867926710199267926710201020102010209167911021102110211021102110211021102110216791022102210221022102210221022110231023102310231023102310236791671024102410241024102410241024102410249167102590679957910261026102610261026102685791027102710271027102785798510281028102810281028102879810291029579810301030103010301030103010311031579757103210321032103210321032103297103310331033103310331033103310341034103410341034103410341034510351035103510351035103510351035797579751036103610361036103610361036103710371038103810381038103810381038103810391039103910391039103910391039103979757975710401040975797104110411041104110411041579651042104279657955104310447910455510461046104610461046104679557955710471047104710471047104795579551048104810481048795579104910491049104910491049104910491050551051105110511051105110517945105210521052105210527945791053105310531053105345794579105410541054105410541054105410541054457105510551055105593105610561056579105710571057105710571057357935710581058105810581058105810589351059105979351060793579257106110611061925792571062106210621062106210621062915710631063106310631063106310639110641064106410641064106410641064106457911065106510651065106557915106610661066106610661066791579106710671067106710671067106711068106810681068579157910691069106910691069106910691069106915791510701070107010701070790510711071107110711071107179107210721072107210721072107210721072057991073107310731073479947910741074107410741074947910751075107510759479947910761076107694799479107710771077107710771077847984710781078107810781078107810781078107898479107910791079107910791079107910798479847910801080108010811081108110811081108110817479747971082108210821082410831083108310831083108379747964710841084108410841084108491085108564796108610861086108610861086479647108710879547108810889547108910891089108910899547951090109010904791091109110911091109141092109210921092109210924710939347934109410947934791095109510951095109510951095347934109610961096109610967934792410971097109710971097792471098109810981098109810981098109810989241099792479241100110011001100110011001100110011007924792471101110111019241102110211021102110211021102110211027924110311031103791479041104110411041104110511051105110511051105110511051105711061106110611061106110690479047911071107110711071107110711071107047904791108110811081108110893711091109110911091109110999379937911101110937983711111111983797311121112111211121112111211121112111279737111311131113111311139737973791114111411141114737973111579111611161116737973791117111773796379611181118111811181118379111911191119637953795112011201120371121112111219112211221122112211225112311231123112311231123112311231123311241124112411241124112411241124112411251125112511251125112511257953711261126112611261126951127112711271127112737953795112811281128112811281128112837953711291129112911291129941130379437943113111311131113111311131113179437911321132113211321132437943794113311333791134113411341134113411341134113443793379113511351135113511353379337931136113611363793371137113711371137933793371138113811381138923792311391139113911397923791140114011401140114023711411141114111411141114111411141114192379111421142114231143114379137911144114411441144114411443791145114511451145137114611461146114611461146911147114711471147114711471147114711473791371148114811481148114891379031149114911501150115011501150711511151115111511151115111511151903799271152115211521152115311531153115399279911541154115411541154115411541154279927115511551155992115611561156115611567911571157115711579279927981158115827982115911591159115911591159798279821160798279821161711621162116211621162116298279721163116311631163116311637972797271164116411641164116411641164962711659627962711661166116696279527911674279427116811681168116811681169116911691169941170279427942117111711171117111711171117111711171117211731173117311731173117311737932793271174117411741174117491175117511751175117511751175117511752211761176117611761176117611761176117679227922117711771177117779111781178279127911791179117911791211801180118011801180118011801180791271181118111811181118111811181912790279118211821182027902711831183118311831183118311831183911841184027118511851185902791186118611861186118611861186021187118711871187118711877991188179917991189118911891189111901190119011901190119179119211921192917991798119311931193119311931798179811194119411941194798111951195119