diff --git a/.gitignore b/.gitignore index ada8be9..ccf6d7f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,8 @@ Cargo.lock **/*.rs.bk # MSVC Windows builds of rustc generate these, which store debugging information -*.pdb \ No newline at end of file +*.pdb + +# Added by cargo + +/target diff --git a/2023/01-trebuchet/src/main.rs b/2023/01-trebuchet/src/main.rs deleted file mode 100644 index e072d03..0000000 --- a/2023/01-trebuchet/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod part_one; -mod part_two; - -fn main() { - //part_one::part_one(); - part_two::part_two(); -} diff --git a/2023/02-cube-conundrum/Cargo.toml b/2023/02-cube-conundrum/Cargo.toml deleted file mode 100644 index e660896..0000000 --- a/2023/02-cube-conundrum/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "cube-conundrum" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/2023/02-cube-conundrum/src/main.rs b/2023/02-cube-conundrum/src/main.rs deleted file mode 100644 index e072d03..0000000 --- a/2023/02-cube-conundrum/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod part_one; -mod part_two; - -fn main() { - //part_one::part_one(); - part_two::part_two(); -} diff --git a/2023/03-gear-ratios/Cargo.toml b/2023/03-gear-ratios/Cargo.toml deleted file mode 100644 index e44941d..0000000 --- a/2023/03-gear-ratios/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "gear-ratios" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/2023/03-gear-ratios/src/main.rs b/2023/03-gear-ratios/src/main.rs deleted file mode 100644 index 71d7c6a..0000000 --- a/2023/03-gear-ratios/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod part_one; -//mod part_two; - -fn main() { - part_one::part_one(); - //part_two::part_two(); -} diff --git a/2023/03-gear-ratios/src/part_one.rs b/2023/03-gear-ratios/src/part_one.rs deleted file mode 100644 index e7c5ad1..0000000 --- a/2023/03-gear-ratios/src/part_one.rs +++ /dev/null @@ -1,145 +0,0 @@ -use std::fs::File; -use std::io::{self, BufRead}; -use std::path::Path; - -enum Engine { - Symbol(char), - Number(u32), - Empty, -} - -pub fn part_one() { - if let Ok(lines) = read_lines("./input.txt") { - let matrix = create_matrix(lines); - let result = process_matrix(&matrix); - - println!("{}", result); - } -} - -fn read_lines

(filename: P) -> io::Result>> -where - P: AsRef, -{ - let file = File::open(filename)?; - Ok(io::BufReader::new(file).lines()) -} - -fn create_matrix(lines: io::Lines>) -> Vec> { - let mut matrix: Vec> = Vec::new(); - - for (i, line) in lines.enumerate() { - matrix.push(Vec::new()); - - let line = line.unwrap(); - - for ch in line.chars() { - if ch == '.' { - matrix[i].push(Engine::Empty); - } else if ch.is_digit(10) { - matrix[i].push(Engine::Number(ch.to_digit(10).unwrap())); - } else { - matrix[i].push(Engine::Symbol(ch)); - } - } - } - - return matrix; -} - -fn process_matrix(matrix: &Vec>) -> u32 { - let mut result = 0; - - for i in 0..matrix.len() { - let mut is_num = false; - let mut num = 0; - let mut found_symbol = false; - - for j in 0..matrix[i].len() { - match matrix[i][j] { - Engine::Number(value) => { - if !found_symbol { - found_symbol = check_symbol(&matrix, i, j); - } - - if is_num { - num = num * 10 + value; - } else { - num = value; - } - - is_num = true; - } - _ => { - if is_num && found_symbol { - result += num; - } - - is_num = false; - found_symbol = false; - num = 0; - } - } - } - - if is_num && found_symbol { - result += num; - } - } - - return result; -} - -fn check_symbol(matrix: &Vec>, x: usize, y: usize) -> bool { - // There's probably a better way - - if x > 0 { - if let Engine::Symbol(_) = matrix[x - 1][y] { - return true; - } - - if y > 0 { - if let Engine::Symbol(_) = matrix[x - 1][y - 1] { - return true; - } - } - - if y < matrix[x - 1].len() - 1 { - if let Engine::Symbol(_) = matrix[x - 1][y + 1] { - return true; - } - } - } - - if y > 0 { - if let Engine::Symbol(_) = matrix[x][y - 1] { - return true; - } - } - - if y < matrix[x].len() - 1 { - if let Engine::Symbol(_) = matrix[x][y + 1] { - return true; - } - } - - if x < matrix.len() - 1 { - if let Engine::Symbol(_) = matrix[x + 1][y] { - return true; - } - - if y > 0 { - if let Engine::Symbol(_) = matrix[x + 1][y - 1] { - return true; - } - } - - if y < matrix[x + 1].len() - 1 { - if let Engine::Symbol(_) = matrix[x + 1][y + 1] { - return true; - } - } - } - - return false; -} diff --git a/2023/04-scratchcards/Cargo.toml b/2023/04-scratchcards/Cargo.toml deleted file mode 100644 index 89ee6ef..0000000 --- a/2023/04-scratchcards/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "scratchcards" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/2023/04-scratchcards/src/main.rs b/2023/04-scratchcards/src/main.rs deleted file mode 100644 index d52adb4..0000000 --- a/2023/04-scratchcards/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod part_one; - -fn main() { - part_one::part_one(); -} diff --git a/2023/06-wait-for-it/Cargo.toml b/2023/06-wait-for-it/Cargo.toml deleted file mode 100644 index 49c02f8..0000000 --- a/2023/06-wait-for-it/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "wait-for-it" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/2023/06-wait-for-it/src/main.rs b/2023/06-wait-for-it/src/main.rs deleted file mode 100644 index df0b383..0000000 --- a/2023/06-wait-for-it/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -//mod part_one; -mod part_two; - -fn main() { - //part_one::part_one(); - part_two::part_two(); -} diff --git a/2023/01-trebuchet/Cargo.toml b/Cargo.toml similarity index 86% rename from 2023/01-trebuchet/Cargo.toml rename to Cargo.toml index 5d49fb2..cb161c1 100644 --- a/2023/01-trebuchet/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "trebuchet" +name = "advent-of-code" version = "0.1.0" edition = "2021" diff --git a/2023/01-trebuchet/input.txt b/input/2023/01-trebuchet/input.txt similarity index 100% rename from 2023/01-trebuchet/input.txt rename to input/2023/01-trebuchet/input.txt diff --git a/2023/01-trebuchet/input_test.txt b/input/2023/01-trebuchet/input_test.txt similarity index 100% rename from 2023/01-trebuchet/input_test.txt rename to input/2023/01-trebuchet/input_test.txt diff --git a/2023/02-cube-conundrum/input.txt b/input/2023/02-cube-conundrum/input.txt similarity index 100% rename from 2023/02-cube-conundrum/input.txt rename to input/2023/02-cube-conundrum/input.txt diff --git a/2023/02-cube-conundrum/input_test.txt b/input/2023/02-cube-conundrum/input_test.txt similarity index 100% rename from 2023/02-cube-conundrum/input_test.txt rename to input/2023/02-cube-conundrum/input_test.txt diff --git a/2023/03-gear-ratios/input.txt b/input/2023/03-gear-ratios/input.txt similarity index 100% rename from 2023/03-gear-ratios/input.txt rename to input/2023/03-gear-ratios/input.txt diff --git a/2023/03-gear-ratios/input_test.txt b/input/2023/03-gear-ratios/input_test.txt similarity index 100% rename from 2023/03-gear-ratios/input_test.txt rename to input/2023/03-gear-ratios/input_test.txt diff --git a/2023/04-scratchcards/input.txt b/input/2023/04-scratchcards/input.txt similarity index 100% rename from 2023/04-scratchcards/input.txt rename to input/2023/04-scratchcards/input.txt diff --git a/2023/04-scratchcards/input_test.txt b/input/2023/04-scratchcards/input_test.txt similarity index 100% rename from 2023/04-scratchcards/input_test.txt rename to input/2023/04-scratchcards/input_test.txt diff --git a/2023/06-wait-for-it/input.txt b/input/2023/06-wait-for-it/input.txt similarity index 100% rename from 2023/06-wait-for-it/input.txt rename to input/2023/06-wait-for-it/input.txt diff --git a/2023/06-wait-for-it/input_test.txt b/input/2023/06-wait-for-it/input_test.txt similarity index 100% rename from 2023/06-wait-for-it/input_test.txt rename to input/2023/06-wait-for-it/input_test.txt diff --git a/2023/01-trebuchet/src/part_one.rs b/src/2023/01-trebuchet/part_one.rs similarity index 100% rename from 2023/01-trebuchet/src/part_one.rs rename to src/2023/01-trebuchet/part_one.rs diff --git a/2023/01-trebuchet/src/part_two.rs b/src/2023/01-trebuchet/part_two.rs similarity index 100% rename from 2023/01-trebuchet/src/part_two.rs rename to src/2023/01-trebuchet/part_two.rs diff --git a/2023/02-cube-conundrum/src/part_one.rs b/src/2023/02-cube-conundrum/part_one.rs similarity index 100% rename from 2023/02-cube-conundrum/src/part_one.rs rename to src/2023/02-cube-conundrum/part_one.rs diff --git a/2023/02-cube-conundrum/src/part_two.rs b/src/2023/02-cube-conundrum/part_two.rs similarity index 100% rename from 2023/02-cube-conundrum/src/part_two.rs rename to src/2023/02-cube-conundrum/part_two.rs diff --git a/src/2023/03-gear-ratios/input.txt b/src/2023/03-gear-ratios/input.txt new file mode 100644 index 0000000..f4ced43 --- /dev/null +++ b/src/2023/03-gear-ratios/input.txt @@ -0,0 +1,140 @@ +......644............612.......254..638..............802.................................118.....................................317.691.... +.....*......321..176....+........&...=...906........*.......=518................994..938.*.....579....35....155...........320...........$... +...939.@225........*......................$........41......................./.....+......102....*.....*...............603....*.413=......... +............470.128...288...+......442-.......191.....%....&........360....218...............916.....552.171..747.51......111............... +.........................*.176...........62%...*......715.831.........*.........937....782...............*...*..../..............645........ +.688.......469&...=....284.....................49................318..182..............-........200......480.182....257...........%......... +...*....#..........197..........611....................#..159.71.*......../947..............190....................=....33..158......252.... +....537.900......................*......404%.........172......*.....+741...................*..................299......*.......*............ +...............908.............354............#............15..881....................@.939...................+.....286...945..767.......... +...........749....*...811..........*667......257.+309.477-.*..............212......746.........275*.............264......*..........720..... +.....-827.*....279....*.........319........................257.150.118.....#.......................979...377...%..........167......*.....793 +...........197.....298.....782.................................-.......87......534.......182+.....................................546...*... +...............................756....@............609................./..363.*..............................459....77................450... +....255.........................$......324.........-..............@...........486...191......947...........................$161..218........ +..........993...............73....523..................832...71....639..............*...736*....-.367...............109$..........#......370 +............-........................&.......254..712....*....*.....................945.....260.....@.......97.......................+...... +..............................569..............-.....&.82..512..............................................+............913..&888..695.%... +......221.146...*....../.............$..@............................../417........571................481#.....687.157..*...............926. +......./...-..897......621.....885..247.506.............&........221..............-..........464.513............*........340.*.............. +...........................715*...............456......445...992*...............................*.....475....132..638.........171.340....561 +.................839..........................=....528...................-.........785............626....*.......*.....850-................. +....$.........&.........975....278...................$..............997...992.........*485.....84*......923...397..259...................... +..328.207......509.........*.....*.529.846......$..*............%...$............%386.......................$.........*..157.....994........ +........-..........352...184...707....*......454....512....208.926....188......%............573*....731....19....566.757...*....*....348.... +.....%..............#...................404.................&...........*..255.317..-..991......126............$.*..........704.788.....*... +.....992.....*979.................264...*..........@...........242#..171....*......888......35.......39......978.955....25/.........%.256... +..........760............904..155../..492...........306...................456...............=.......+............................694........ +................158.............@.........@..115................*922..651.................................................#.............297. +...677....46....*..........573......243.595....*....446......121...........748.868....................835.........621..-...300...22......... +...........*.635..............*....&..........910.&........................*...-.....-.........907.......#......$...*...43......*.......791. +.140.....218......17..........246.................705...............@......445.......471......*......-........623...326..................... +...=.126.........*.......411........979.630.............81.419...131.......................241........660................................... +.....*........540..*..........858@....*.*.................*....................................733.56......816..........243....984......=... +........546.........518.............21...834..@641.............46#.........471....................*...675.+.....................&......521.. +...........*..................65.....................978....&........................548#....749......*.....106.........246................. +.......899..593.........420-....*..258.798*814...#...*...336....................360.........+......238.......*........../........354........ +..........&...................485....*.........361.520........742...683..........@....136................=.......=.................#.....76. +......$.........575...............220....#.......................*....*...800...........=.....545.....178....*.604.+....659*670.........*... +.......959....@......175....*825.......838..........547*..........346.553..*....867..........*.............60.......130................517.. +.............121.737*....773....................124.....609...$............16......%..........359..90.............................627....... +....485.........................*884.194../.........485......489..............138.......426..........*527.620..-600...99.....778............ +..........510*236........344/.51......*...766..588.@.....66*............$665....%.......-....366..........%..............999..%............. +......259........................../..525.......*...........447..128..............961........................752....797.$.......+872..739... +......*.....................771.840.......*537...493....@..........*.404*376..759....=.....287..................*....#....614.........*..... +......896.......513...........*........208.............4..11.....475............*.........*...........346.171...104........*..........34.... +..........292...............@................570+...58.....*..&.......@455.......275......781..162.87.*......*....../.....927..+220......883 +...........*..390........937.............680..........+.845....998..........890....................*...240...128....102.............788.#... +....365/..914..*....988.........439@......*...$472...................10./....*......*....894.......475...........@.......................... +.........................192..............851..........332...........*...868..351..160......*830................776............608...-...52. +.......542.+.....966...............................114*......345...984...........................708*...264.......................*.611.*... +.......*....45....*....@.......@344.........................*..........809*958........$..............86...........-727.........359......700. +.......45.........111...285...........23...306*755........720......727..............383.....65.250.......943...........@651................. +............98................192......*............*...........................*.......503..@..*.....=.......48..............814........... +...............932.918..............787......13&.918.326......545...............857.....*........175...682......*939..552.707..*............ +......@....663*....#..............................................39..................265...................328.......*......*..810.....=186 +295....97...............654..774.........505..........857..-8.......*613.....................734...$....382*........%.....591............... +..................62......*....%..........*....110...$...................928....393.789*69....#....470.......977.904................898..... +........405...819.........514..............201....*....*806.....196......*........*............../...........@..................644....*195. +........*......*.................@.....276......538.992...........*....720.692..880........+117.266..207.........+.......................... +........67....478..675*861...80..34.....*..+777..................313........*.......................*.........445.........200..*...@........ +..938......75..................*.....155.................................985..#........285.....181...160.....................$.872..595..... +....*..997*....................31.............148......946...........803.......195.......*.944...*.......551+........*...867................ +...233..........553.596...........436..........*..........*437..559-..*.............@..521.*......606..........519.226..........@........... +.....................*..268......%.....200..276....@...................793........22........773........./....1............*....603.@927.-... +..527..843...906..511.........$....698.*..........39......692&...............158$......912..............168............645...............264 +...&.........=..........152....849...*.667............365.........%.69*...............*......955...................................568...... +.......88........@25.......+.......104...............@.....474..210....788.-910.862...............728.%........876.......980..........*..... +446.....................$.................................*.....................*...#..../........@...544.........*.........*980...872...... +...*.........960=.....609...372..516....797*652...179......337.........*864..457..315.....207..............177..666......................... +.456..283..................*.......................*...51...........798.....................................#...........796.880............. +.....*.........%...+......341...........320.....410...*......767..........81+.953.........#.....51.......8.....@.........*...+.............. +.....704..48.407...864.........718..........606.......375.....%....$...........*...818.@...621..=....769*.....522.375...585..............389 +.746.....*................$.............&.....*..................225......=........*...887.................................................. +....../...67..............429...........569....355..58#.550.299......676.904.......29........787.817....@.....*....940........537....*...... +.....894..............564..........52+.....................*.....69.*..........773..........$........398......283...@....283........105..... +......................*...672.../........996.....171..*567...902*...290....324..@..............844.......#.................................. +...935...128*........892.....*...497................$..............................170................789..*........620...........484....... +....../......495..........612..................251*.......811.............660.........=....@669.............840.413.*.........#......@...... +..506............................-..../....=.......147.44.*...$............=......177..............539...............384......743.......24.. +...../...........818.505......962....777....180.........*...330......................*........895...*...........989...............13....%... +..................*.....*749..........................225......................136...295.433...*....612..$386..+.............907.*....=..... +....108..911.......230........449*499...........875..............211&..851.742.../.......*.....266..................293....../....854.548... +...........+..............61............&..........@..../....989.......#...............916.403.........................*........*........... +..690..........$..=553...*......202....312..............753.*....372...........268............/.......973...&.881...558..........58..321.... +...........=..997........452....%...........................629.....@..........*..........................495..*../......-..............*... +..142..55..98................................80-......528...................532.....69.........691@...........186..388.342............163... +......./........280.@.............350.............818*.................$..............*..............142....................248/............ +..896....$........*.893......350./............918.........158......%..574...444......297.656..........%............%..............369....... +.....*...191...264........+...%.....566.824....*..621........#..532...........#..904........*.....134...139..420...811....444*160..&........ +....112..................663...../..*....*..987......*...................896....&...........996......+..*.....*......................236.... +..............................434..57...79.........904....+...740.%.....*..............................72....447....................@....... +....#........474...480....................................307..*...447..612.....490......325.......715.............853...859................ +..424......................624*....../.../.......176...........714.................*..........184..............874*....................687.. +........81.944..748..............=.343.643......*.......=...................=.....735....../..*........................748........743....... +261/......*.....*........@....574..............119......650................298.43........954...202...314................#....589....%....... +...............773....729...-.....361.884%.......................743.............*885...................*..&......746..................262.. +...@.330....44.............349....*.........140*875.............*........................787....582...257.401........-.......219......*..... +499...*.....*.....977..........629..130.691...........629.....392.........*......23......$...................................*.......113.... +....929.383..616..*..................&...@.....&...................910.....820..*......................................926..54...80*........ +...........*......60.....755.........../....105..........521...254*.............667.......956.......-...............*..=............232..... +.........667.-795....292*..............299...............*................560....................750.........107...157...................... +...........................200/..619.......225....986.67.....................=..386...................#62.......*..................827*242.. +.........134..528.....416.........@..........*.......*............18.............*.....489.396..384.......735.424.....528................... +.....326........*..98...+.....306.....+.....147............*.....#........391.....210.....*....*.....#.....*......754....................... +...........884.313...*...........*378..498...........844....738.......926.*...........809......562...108.391.........*567...748..../........ +.....857..*..........758.............................*............../...@..738....198..........................190..................470..... +......*....586..855.........*77.412*13....113..413..810.......513..266............./...@556.650...............$............................. +...487.........-.........434................&./..............*............631.................*.......................434................... +...............................660......848..............................*............+........316....105...679.......*....289..700......... +.62*523........../.............&.......*.....433...328.................474....194...868................*...%........753....*.....*.......... +................31........116...........897....*..%...........406............%.........................33.....453=......636..580.649..520... +...66......#..............@....732....+.............71...857...../..645...................#.......71.......&.......450......&........=...... +.....*815...387......677............395.....365.928....................*300.........633....347....*..791..37......&......................... +................898...*.....823.................................................621.*...........764.*........285@.......743......+..645..... +..............*.....946................................563.....................*.....848............716...................*.......8...$..... +.....770...281.710......756..305........709*......#..../................245....572...........788.............-112....994.522................ +........@.....................*.....648.....351....679..........624........*................&...........-............*...................... +..546*......................333....@....-...............*..........*...778.546...........=........=.....957......#....522......734.......... +......270...959...108..569...............616.........417.246.......25.+........237....909.........10..............607......=...+...711...... +...........@.........*...@...*...244.301......................................*.......................................713.59................ +.114..717...........807.....501..#...*...................+.63..369..986..137...831...../584...@350...........61.=923...........82........... +....*....*............................479.........#....141...%..*..@........*............................419*.................*............. +.........607..+609.....952.........................287...................730..945...&..-...986.........$.........#...........876....806..... +...................102*....................................+97...608..........*...541..221.........592.165.....266...742.................... +..................................414...............................*439....684.@..................................=...*.....325.621....831. +........924.918.325...........248*.......986..595*601...........................434......499...801.....586......395...251.....&...*......... +..............*..+..32....73*.........&.../.............772.......271.404..403......791...........*...*.....920..................20....136.. +..529....610.935...+.........589....265..............................*.......*......*...........884....849.....*............#.........*..... +..........*................................694........292.629..............967.....744..........................452......290........818..... +886.......206..............*6.......595=.....*.85........*..............................286..$...23.....436................................. +.....406.........61*68..960................689....916........887....908....217....$.....*....997.*.........%................501....912...... +.....-...412...$................632...............+..........@...............*....412..602........830..............856*.............#....... +........*.....407......32......=..............%.........670......3...272......78............................853........862...428..........4. +....747....97.......................585*312..664...731*...@.&426.*.......243.....894...............896.......&...287...........*.839..724... +......*..%.../..........948.......................................67.....@.........*..598...........*....#..................5.88.*....%..... +...287..634.....359....................439......251.............7....961......#..139.*...........746......760....682.............136........ +............493*................410............*...........618..*...*....85..189......81............................$...568................. +.........................627../.........355.....258........*........738....*........................&..................+..............259... +......515*357............*...509..205.....*................203..7*........353.....209..........790...81.........................695.....*... +........................313............444....................................662..........................956.....714...................935 \ No newline at end of file diff --git a/src/2023/03-gear-ratios/input_test.txt b/src/2023/03-gear-ratios/input_test.txt new file mode 100644 index 0000000..624ea4f --- /dev/null +++ b/src/2023/03-gear-ratios/input_test.txt @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. \ No newline at end of file diff --git a/2023/04-scratchcards/src/part_one.rs b/src/2023/04-scratchcards/part_one.rs similarity index 100% rename from 2023/04-scratchcards/src/part_one.rs rename to src/2023/04-scratchcards/part_one.rs diff --git a/2023/06-wait-for-it/src/part_one.rs b/src/2023/06-wait-for-it/part_one.rs similarity index 100% rename from 2023/06-wait-for-it/src/part_one.rs rename to src/2023/06-wait-for-it/part_one.rs diff --git a/2023/06-wait-for-it/src/part_two.rs b/src/2023/06-wait-for-it/part_two.rs similarity index 100% rename from 2023/06-wait-for-it/src/part_two.rs rename to src/2023/06-wait-for-it/part_two.rs diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}