From 6068855fa1d0e14c5c6f9f2bf561615e96f44efe Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 4 Dec 2019 08:40:52 -0600 Subject: [PATCH] 2019 Day 04 Done --- 2019/day04/main.go | 60 ++ 2019/day04/output | 1717 ++++++++++++++++++++++++++++++++++++++++++++ 2019/day04/problem | 65 ++ 3 files changed, 1842 insertions(+) create mode 100644 2019/day04/main.go create mode 100644 2019/day04/output create mode 100644 2019/day04/problem diff --git a/2019/day04/main.go b/2019/day04/main.go new file mode 100644 index 0000000..df92f86 --- /dev/null +++ b/2019/day04/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "bytes" + "fmt" + "os" +) + +func main() { + beg, end := []byte("165432"), []byte("707912") + if len(os.Args) == 3 { + beg, end = []byte(os.Args[1]), []byte(os.Args[2]) + } + var count int + for { + if validate(beg) { + count++ + } + if bytes.Equal(beg, end) { + break + } + beg = inc(beg) + } + fmt.Println(count) +} + +func inc(num []byte) []byte { + if len(num) == 0 { + return []byte{'1'} + } else if num[len(num)-1] == '9' { + return append(inc(num[:len(num)-1]), '0') + } else { + num[len(num)-1]++ + } + return num +} + +func validate(num []byte) bool { + var dup bool + for k := range num { + if countSeq(num, k) == 2 { + dup = true + } + if len(num) > k+1 && num[k] > num[k+1] { + return false + } + } + return dup +} + +func countSeq(num []byte, idx int) int { + ret := 1 + if len(num) > idx+1 && num[idx+1] == num[idx] { + ret += countSeq(num[idx+1:], 0) + } + if idx >= 1 && num[idx-1] == num[idx] { + ret += countSeq(num[:idx], idx-1) + } + return ret +} diff --git a/2019/day04/output b/2019/day04/output new file mode 100644 index 0000000..3703d7a --- /dev/null +++ b/2019/day04/output @@ -0,0 +1,1717 @@ +166666 +166667 +166668 +166669 +166677 +166678 +166679 +166688 +166689 +166699 +166777 +166778 +166779 +166788 +166789 +166799 +166888 +166889 +166899 +166999 +167777 +167778 +167779 +167788 +167789 +167799 +167888 +167889 +167899 +167999 +168888 +168889 +168899 +168999 +169999 +177777 +177778 +177779 +177788 +177789 +177799 +177888 +177889 +177899 +177999 +178888 +178889 +178899 +178999 +179999 +188888 +188889 +188899 +188999 +189999 +199999 +222222 +222223 +222224 +222225 +222226 +222227 +222228 +222229 +222233 +222234 +222235 +222236 +222237 +222238 +222239 +222244 +222245 +222246 +222247 +222248 +222249 +222255 +222256 +222257 +222258 +222259 +222266 +222267 +222268 +222269 +222277 +222278 +222279 +222288 +222289 +222299 +222333 +222334 +222335 +222336 +222337 +222338 +222339 +222344 +222345 +222346 +222347 +222348 +222349 +222355 +222356 +222357 +222358 +222359 +222366 +222367 +222368 +222369 +222377 +222378 +222379 +222388 +222389 +222399 +222444 +222445 +222446 +222447 +222448 +222449 +222455 +222456 +222457 +222458 +222459 +222466 +222467 +222468 +222469 +222477 +222478 +222479 +222488 +222489 +222499 +222555 +222556 +222557 +222558 +222559 +222566 +222567 +222568 +222569 +222577 +222578 +222579 +222588 +222589 +222599 +222666 +222667 +222668 +222669 +222677 +222678 +222679 +222688 +222689 +222699 +222777 +222778 +222779 +222788 +222789 +222799 +222888 +222889 +222899 +222999 +223333 +223334 +223335 +223336 +223337 +223338 +223339 +223344 +223345 +223346 +223347 +223348 +223349 +223355 +223356 +223357 +223358 +223359 +223366 +223367 +223368 +223369 +223377 +223378 +223379 +223388 +223389 +223399 +223444 +223445 +223446 +223447 +223448 +223449 +223455 +223456 +223457 +223458 +223459 +223466 +223467 +223468 +223469 +223477 +223478 +223479 +223488 +223489 +223499 +223555 +223556 +223557 +223558 +223559 +223566 +223567 +223568 +223569 +223577 +223578 +223579 +223588 +223589 +223599 +223666 +223667 +223668 +223669 +223677 +223678 +223679 +223688 +223689 +223699 +223777 +223778 +223779 +223788 +223789 +223799 +223888 +223889 +223899 +223999 +224444 +224445 +224446 +224447 +224448 +224449 +224455 +224456 +224457 +224458 +224459 +224466 +224467 +224468 +224469 +224477 +224478 +224479 +224488 +224489 +224499 +224555 +224556 +224557 +224558 +224559 +224566 +224567 +224568 +224569 +224577 +224578 +224579 +224588 +224589 +224599 +224666 +224667 +224668 +224669 +224677 +224678 +224679 +224688 +224689 +224699 +224777 +224778 +224779 +224788 +224789 +224799 +224888 +224889 +224899 +224999 +225555 +225556 +225557 +225558 +225559 +225566 +225567 +225568 +225569 +225577 +225578 +225579 +225588 +225589 +225599 +225666 +225667 +225668 +225669 +225677 +225678 +225679 +225688 +225689 +225699 +225777 +225778 +225779 +225788 +225789 +225799 +225888 +225889 +225899 +225999 +226666 +226667 +226668 +226669 +226677 +226678 +226679 +226688 +226689 +226699 +226777 +226778 +226779 +226788 +226789 +226799 +226888 +226889 +226899 +226999 +227777 +227778 +227779 +227788 +227789 +227799 +227888 +227889 +227899 +227999 +228888 +228889 +228899 +228999 +229999 +233333 +233334 +233335 +233336 +233337 +233338 +233339 +233344 +233345 +233346 +233347 +233348 +233349 +233355 +233356 +233357 +233358 +233359 +233366 +233367 +233368 +233369 +233377 +233378 +233379 +233388 +233389 +233399 +233444 +233445 +233446 +233447 +233448 +233449 +233455 +233456 +233457 +233458 +233459 +233466 +233467 +233468 +233469 +233477 +233478 +233479 +233488 +233489 +233499 +233555 +233556 +233557 +233558 +233559 +233566 +233567 +233568 +233569 +233577 +233578 +233579 +233588 +233589 +233599 +233666 +233667 +233668 +233669 +233677 +233678 +233679 +233688 +233689 +233699 +233777 +233778 +233779 +233788 +233789 +233799 +233888 +233889 +233899 +233999 +234444 +234445 +234446 +234447 +234448 +234449 +234455 +234456 +234457 +234458 +234459 +234466 +234467 +234468 +234469 +234477 +234478 +234479 +234488 +234489 +234499 +234555 +234556 +234557 +234558 +234559 +234566 +234577 +234588 +234599 +234666 +234667 +234668 +234669 +234677 +234688 +234699 +234777 +234778 +234779 +234788 +234799 +234888 +234889 +234899 +234999 +235555 +235556 +235557 +235558 +235559 +235566 +235567 +235568 +235569 +235577 +235578 +235579 +235588 +235589 +235599 +235666 +235667 +235668 +235669 +235677 +235688 +235699 +235777 +235778 +235779 +235788 +235799 +235888 +235889 +235899 +235999 +236666 +236667 +236668 +236669 +236677 +236678 +236679 +236688 +236689 +236699 +236777 +236778 +236779 +236788 +236799 +236888 +236889 +236899 +236999 +237777 +237778 +237779 +237788 +237789 +237799 +237888 +237889 +237899 +237999 +238888 +238889 +238899 +238999 +239999 +244444 +244445 +244446 +244447 +244448 +244449 +244455 +244456 +244457 +244458 +244459 +244466 +244467 +244468 +244469 +244477 +244478 +244479 +244488 +244489 +244499 +244555 +244556 +244557 +244558 +244559 +244566 +244567 +244568 +244569 +244577 +244578 +244579 +244588 +244589 +244599 +244666 +244667 +244668 +244669 +244677 +244678 +244679 +244688 +244689 +244699 +244777 +244778 +244779 +244788 +244789 +244799 +244888 +244889 +244899 +244999 +245555 +245556 +245557 +245558 +245559 +245566 +245567 +245568 +245569 +245577 +245578 +245579 +245588 +245589 +245599 +245666 +245667 +245668 +245669 +245677 +245688 +245699 +245777 +245778 +245779 +245788 +245799 +245888 +245889 +245899 +245999 +246666 +246667 +246668 +246669 +246677 +246678 +246679 +246688 +246689 +246699 +246777 +246778 +246779 +246788 +246799 +246888 +246889 +246899 +246999 +247777 +247778 +247779 +247788 +247789 +247799 +247888 +247889 +247899 +247999 +248888 +248889 +248899 +248999 +249999 +255555 +255556 +255557 +255558 +255559 +255566 +255567 +255568 +255569 +255577 +255578 +255579 +255588 +255589 +255599 +255666 +255667 +255668 +255669 +255677 +255678 +255679 +255688 +255689 +255699 +255777 +255778 +255779 +255788 +255789 +255799 +255888 +255889 +255899 +255999 +256666 +256667 +256668 +256669 +256677 +256678 +256679 +256688 +256689 +256699 +256777 +256778 +256779 +256788 +256799 +256888 +256889 +256899 +256999 +257777 +257778 +257779 +257788 +257789 +257799 +257888 +257889 +257899 +257999 +258888 +258889 +258899 +258999 +259999 +266666 +266667 +266668 +266669 +266677 +266678 +266679 +266688 +266689 +266699 +266777 +266778 +266779 +266788 +266789 +266799 +266888 +266889 +266899 +266999 +267777 +267778 +267779 +267788 +267789 +267799 +267888 +267889 +267899 +267999 +268888 +268889 +268899 +268999 +269999 +277777 +277778 +277779 +277788 +277789 +277799 +277888 +277889 +277899 +277999 +278888 +278889 +278899 +278999 +279999 +288888 +288889 +288899 +288999 +289999 +299999 +333333 +333334 +333335 +333336 +333337 +333338 +333339 +333344 +333345 +333346 +333347 +333348 +333349 +333355 +333356 +333357 +333358 +333359 +333366 +333367 +333368 +333369 +333377 +333378 +333379 +333388 +333389 +333399 +333444 +333445 +333446 +333447 +333448 +333449 +333455 +333456 +333457 +333458 +333459 +333466 +333467 +333468 +333469 +333477 +333478 +333479 +333488 +333489 +333499 +333555 +333556 +333557 +333558 +333559 +333566 +333567 +333568 +333569 +333577 +333578 +333579 +333588 +333589 +333599 +333666 +333667 +333668 +333669 +333677 +333678 +333679 +333688 +333689 +333699 +333777 +333778 +333779 +333788 +333789 +333799 +333888 +333889 +333899 +333999 +334444 +334445 +334446 +334447 +334448 +334449 +334455 +334456 +334457 +334458 +334459 +334466 +334467 +334468 +334469 +334477 +334478 +334479 +334488 +334489 +334499 +334555 +334556 +334557 +334558 +334559 +334566 +334567 +334568 +334569 +334577 +334578 +334579 +334588 +334589 +334599 +334666 +334667 +334668 +334669 +334677 +334678 +334679 +334688 +334689 +334699 +334777 +334778 +334779 +334788 +334789 +334799 +334888 +334889 +334899 +334999 +335555 +335556 +335557 +335558 +335559 +335566 +335567 +335568 +335569 +335577 +335578 +335579 +335588 +335589 +335599 +335666 +335667 +335668 +335669 +335677 +335678 +335679 +335688 +335689 +335699 +335777 +335778 +335779 +335788 +335789 +335799 +335888 +335889 +335899 +335999 +336666 +336667 +336668 +336669 +336677 +336678 +336679 +336688 +336689 +336699 +336777 +336778 +336779 +336788 +336789 +336799 +336888 +336889 +336899 +336999 +337777 +337778 +337779 +337788 +337789 +337799 +337888 +337889 +337899 +337999 +338888 +338889 +338899 +338999 +339999 +344444 +344445 +344446 +344447 +344448 +344449 +344455 +344456 +344457 +344458 +344459 +344466 +344467 +344468 +344469 +344477 +344478 +344479 +344488 +344489 +344499 +344555 +344556 +344557 +344558 +344559 +344566 +344567 +344568 +344569 +344577 +344578 +344579 +344588 +344589 +344599 +344666 +344667 +344668 +344669 +344677 +344678 +344679 +344688 +344689 +344699 +344777 +344778 +344779 +344788 +344789 +344799 +344888 +344889 +344899 +344999 +345555 +345556 +345557 +345558 +345559 +345566 +345567 +345568 +345569 +345577 +345578 +345579 +345588 +345589 +345599 +345666 +345667 +345668 +345669 +345677 +345688 +345699 +345777 +345778 +345779 +345788 +345799 +345888 +345889 +345899 +345999 +346666 +346667 +346668 +346669 +346677 +346678 +346679 +346688 +346689 +346699 +346777 +346778 +346779 +346788 +346799 +346888 +346889 +346899 +346999 +347777 +347778 +347779 +347788 +347789 +347799 +347888 +347889 +347899 +347999 +348888 +348889 +348899 +348999 +349999 +355555 +355556 +355557 +355558 +355559 +355566 +355567 +355568 +355569 +355577 +355578 +355579 +355588 +355589 +355599 +355666 +355667 +355668 +355669 +355677 +355678 +355679 +355688 +355689 +355699 +355777 +355778 +355779 +355788 +355789 +355799 +355888 +355889 +355899 +355999 +356666 +356667 +356668 +356669 +356677 +356678 +356679 +356688 +356689 +356699 +356777 +356778 +356779 +356788 +356799 +356888 +356889 +356899 +356999 +357777 +357778 +357779 +357788 +357789 +357799 +357888 +357889 +357899 +357999 +358888 +358889 +358899 +358999 +359999 +366666 +366667 +366668 +366669 +366677 +366678 +366679 +366688 +366689 +366699 +366777 +366778 +366779 +366788 +366789 +366799 +366888 +366889 +366899 +366999 +367777 +367778 +367779 +367788 +367789 +367799 +367888 +367889 +367899 +367999 +368888 +368889 +368899 +368999 +369999 +377777 +377778 +377779 +377788 +377789 +377799 +377888 +377889 +377899 +377999 +378888 +378889 +378899 +378999 +379999 +388888 +388889 +388899 +388999 +389999 +399999 +444444 +444445 +444446 +444447 +444448 +444449 +444455 +444456 +444457 +444458 +444459 +444466 +444467 +444468 +444469 +444477 +444478 +444479 +444488 +444489 +444499 +444555 +444556 +444557 +444558 +444559 +444566 +444567 +444568 +444569 +444577 +444578 +444579 +444588 +444589 +444599 +444666 +444667 +444668 +444669 +444677 +444678 +444679 +444688 +444689 +444699 +444777 +444778 +444779 +444788 +444789 +444799 +444888 +444889 +444899 +444999 +445555 +445556 +445557 +445558 +445559 +445566 +445567 +445568 +445569 +445577 +445578 +445579 +445588 +445589 +445599 +445666 +445667 +445668 +445669 +445677 +445678 +445679 +445688 +445689 +445699 +445777 +445778 +445779 +445788 +445789 +445799 +445888 +445889 +445899 +445999 +446666 +446667 +446668 +446669 +446677 +446678 +446679 +446688 +446689 +446699 +446777 +446778 +446779 +446788 +446789 +446799 +446888 +446889 +446899 +446999 +447777 +447778 +447779 +447788 +447789 +447799 +447888 +447889 +447899 +447999 +448888 +448889 +448899 +448999 +449999 +455555 +455556 +455557 +455558 +455559 +455566 +455567 +455568 +455569 +455577 +455578 +455579 +455588 +455589 +455599 +455666 +455667 +455668 +455669 +455677 +455678 +455679 +455688 +455689 +455699 +455777 +455778 +455779 +455788 +455789 +455799 +455888 +455889 +455899 +455999 +456666 +456667 +456668 +456669 +456677 +456678 +456679 +456688 +456689 +456699 +456777 +456778 +456779 +456788 +456799 +456888 +456889 +456899 +456999 +457777 +457778 +457779 +457788 +457789 +457799 +457888 +457889 +457899 +457999 +458888 +458889 +458899 +458999 +459999 +466666 +466667 +466668 +466669 +466677 +466678 +466679 +466688 +466689 +466699 +466777 +466778 +466779 +466788 +466789 +466799 +466888 +466889 +466899 +466999 +467777 +467778 +467779 +467788 +467789 +467799 +467888 +467889 +467899 +467999 +468888 +468889 +468899 +468999 +469999 +477777 +477778 +477779 +477788 +477789 +477799 +477888 +477889 +477899 +477999 +478888 +478889 +478899 +478999 +479999 +488888 +488889 +488899 +488999 +489999 +499999 +555555 +555556 +555557 +555558 +555559 +555566 +555567 +555568 +555569 +555577 +555578 +555579 +555588 +555589 +555599 +555666 +555667 +555668 +555669 +555677 +555678 +555679 +555688 +555689 +555699 +555777 +555778 +555779 +555788 +555789 +555799 +555888 +555889 +555899 +555999 +556666 +556667 +556668 +556669 +556677 +556678 +556679 +556688 +556689 +556699 +556777 +556778 +556779 +556788 +556789 +556799 +556888 +556889 +556899 +556999 +557777 +557778 +557779 +557788 +557789 +557799 +557888 +557889 +557899 +557999 +558888 +558889 +558899 +558999 +559999 +566666 +566667 +566668 +566669 +566677 +566678 +566679 +566688 +566689 +566699 +566777 +566778 +566779 +566788 +566789 +566799 +566888 +566889 +566899 +566999 +567777 +567778 +567779 +567788 +567789 +567799 +567888 +567889 +567899 +567999 +568888 +568889 +568899 +568999 +569999 +577777 +577778 +577779 +577788 +577789 +577799 +577888 +577889 +577899 +577999 +578888 +578889 +578899 +578999 +579999 +588888 +588889 +588899 +588999 +589999 +599999 +666666 +666667 +666668 +666669 +666677 +666678 +666679 +666688 +666689 +666699 +666777 +666778 +666779 +666788 +666789 +666799 +666888 +666889 +666899 +666999 +667777 +667778 +667779 +667788 +667789 +667799 +667888 +667889 +667899 +667999 +668888 +668889 +668899 +668999 +669999 +677777 +677778 +677779 +677788 +677789 +677799 +677888 +677889 +677899 +677999 +678888 +678889 +678899 +678999 +679999 +688888 +688889 +688899 +688999 +689999 +699999 +1716 diff --git a/2019/day04/problem b/2019/day04/problem new file mode 100644 index 0000000..7ae07ab --- /dev/null +++ b/2019/day04/problem @@ -0,0 +1,65 @@ +Advent of Code + +--- Day 4: Secure Container --- + + You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the + password on a sticky note, but someone threw it out. + + However, they do remember a few key facts about the password: + + • It is a six-digit number. + • The value is within the range given in your puzzle input. + • Two adjacent digits are the same (like 22 in 122345). + • Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or + 135679). + + Other than the range rule, the following are true: + + • 111111 meets these criteria (double 11, never decreases). + • 223450 does not meet these criteria (decreasing pair of digits 50). + • 123789 does not meet these criteria (no double). + + How many different passwords within the range given in your puzzle input meet these criteria? + + Your puzzle answer was 1716. + +--- Part Two --- + + An Elf just remembered one more important detail: the two adjacent matching digits are not part of a larger group + of matching digits. + + Given this additional criterion, but still ignoring the range rule, the following are now true: + + • 112233 meets these criteria because the digits never decrease and all repeated digits are exactly two digits + long. + • 123444 no longer meets the criteria (the repeated 44 is part of a larger group of 444). + • 111122 meets the criteria (even though 1 is repeated more than twice, it still contains a double 22). + + How many different passwords within the range given in your puzzle input meet all of the criteria? + + Your puzzle answer was 1163. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should return to your Advent calendar and try another puzzle. + + Your puzzle input was 165432-707912. + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2019/about + . https://adventofcode.com/2019/events + . https://adventofcode.com/2019/settings + . https://adventofcode.com/2019/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2019/support + . https://adventofcode.com/2019 + . https://adventofcode.com/2019 + . https://adventofcode.com/2019/support + . https://adventofcode.com/2019/sponsors + . https://adventofcode.com/2019/leaderboard + . https://adventofcode.com/2019/stats + . https://adventofcode.com/2019/sponsors + . https://adventofcode.com/2019