init day3
This commit is contained in:
7
2023/day3/Cargo.lock
generated
Normal file
7
2023/day3/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day3"
|
||||
version = "0.1.0"
|
||||
6
2023/day3/Cargo.toml
Normal file
6
2023/day3/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "day3"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
35
2023/day3/README.md
Normal file
35
2023/day3/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
--- Day 3: Gear Ratios ---
|
||||
|
||||
You and the Elf eventually reach a gondola lift station; he says the gondola lift will take you up to the water source, but this is as far as he can bring you. You go inside.
|
||||
|
||||
It doesn't take long to find the gondolas, but there seems to be a problem: they're not moving.
|
||||
|
||||
"Aaah!"
|
||||
|
||||
You turn around to see a slightly-greasy Elf with a wrench and a look of surprise. "Sorry, I wasn't expecting anyone! The gondola lift isn't working right now; it'll still be a while before I can fix it." You offer to help.
|
||||
|
||||
The engineer explains that an engine part seems to be missing from the engine, but nobody can figure out which one. If you can add up all the part numbers in the engine schematic, it should be easy to work out which part is missing.
|
||||
|
||||
The engine schematic (your puzzle input) consists of a visual representation of the engine. There are lots of numbers and symbols you don't really understand, but apparently any number adjacent to a symbol, even diagonally, is a "part number" and should be included in your sum. (Periods (.) do not count as a symbol.)
|
||||
|
||||
Here is an example engine schematic:
|
||||
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
|
||||
In this schematic, two numbers are not part numbers because they are not adjacent to a symbol: 114 (top right) and 58 (middle right). Every other number is adjacent to a symbol and so is a part number; their sum is 4361.
|
||||
|
||||
Of course, the actual engine schematic is much larger. What is the sum of all of the part numbers in the engine schematic?
|
||||
|
||||
To begin, get your puzzle input.
|
||||
|
||||
Answer:
|
||||
You can also [Shareon Twitter Mastodon] this puzzle.
|
||||
140
2023/day3/input
Normal file
140
2023/day3/input
Normal file
@@ -0,0 +1,140 @@
|
||||
...........441.................367................296........................................567..47.....45.................947.............
|
||||
...606..........888.....................508..........*892................+..=138.381..967...............*....%......926...........218.......
|
||||
....*......116..*..............747............-....................777..460..........*.......549......127...595.......*..290........*.968...
|
||||
..902..........425................+..........730..........#...........*.....196.............-.......................512.*....@...994..%.....
|
||||
..........................924.....................%...*...139..............*............/......458......................10..155.............
|
||||
...318.......825.......+.....*201................793.143.......522.%...568.....&.........558....*.......583....792..........................
|
||||
....*................971............448....653..............79..@..792....*.105....115.........200.....+.........*.............*........380.
|
||||
.850....269................775*........*......@.......%................921........#........................812....793....22.460.305.........
|
||||
..........&..414@...824........129.....816......*..560...421......955/................141......336........*.................................
|
||||
.........................59....................201......$...............@651.........*...........+..937...732...549-....284....544..........
|
||||
...........................*..178.125*808....................919..............246....400.53......................................$.+........
|
||||
.....=.....964.238..116.722.....*............624..............*...........209...............312....670.....953.....#....265.710.....414.....
|
||||
...966.152*.........*........375....*........*.........663....639............................&....*.........*.....424......*....%...........
|
||||
..................-..68.206......812.601......874..651...+..........857*686.........*.....33......825......497...............402............
|
||||
862*766......@...545.......*4............706.....................................887.395....=.731......47.........................942.949...
|
||||
..........900..........390........5-........*345.....................724.......%..........................+........778..761........%........
|
||||
..............887..985...*.......................141...................$.......64......&...334.278..896...572.....*.....*.....804...........
|
||||
......184....*..........596...$.....................*.-764....494....$....54............35....*................900...750..$.....*...........
|
||||
.....#.....322......979.....447............542.61..52.................880..........................*718............-.......926..659.........
|
||||
.......91.......793....*.@.............215*............@.........585......+....126..............102.......207..&....762.............&703....
|
||||
.....................751..87..$........................117.......*.......778...*.....363...=157......351.....*..577.........................
|
||||
..483=...374*823.............512...835.551.....333..........978........#.......954.....*.............*.....140..........634.....357......473
|
||||
......................................*.........#...223.....*.........79...............275..........24..........310............+....390=....
|
||||
755.255.#....751....#...342....51..........507.....*.....764....220..........909../.............................../.........................
|
||||
.....&...320..=..293.....*.....@......204.....*.956.............*......485....#...866..765..973..668......476.............772.....463.479...
|
||||
..........................53.............*.............+410...667.-103..&..%...................*....*......*..995#.........-..75.......*....
|
||||
.......289.......995..............33...714.......366........................556.......518......95.....................836.....*......699....
|
||||
......./............/...31.........................&...............&....................*...........220.814............$....658.............
|
||||
.....=...10...............*.....+852.....%98...........838......652..........11.125..488......799...*.....*.................................
|
||||
...470......102......889.250..................209..118..#...........729........*..................159..799..417.140....762......588.629.....
|
||||
........@...*...844....*........900...507....*......#...............=......*...........878.....................*......*.....539*............
|
||||
...756.769.426..*......94.........#......*....997...........#793........115.685..........*.....973.869.................12............596....
|
||||
.....=..........2......................698........416...$.........302...............530...315...@...@.......-.....605.........542.....*.....
|
||||
.711....373........................358...............&..820..........*......#243...=........................148...../...$........*...581....
|
||||
...........$...727.......314...57..*.............*..................762......................524..346$...................581.....120........
|
||||
......=568..........@844.&.....*...257.485......593.....*................................30..*.........740.....709*.........................
|
||||
................................75......*............194.675.420*282.....967..552.............850..................789..=.....-........223..
|
||||
..910.....$.............562..=..........56..............................-....*......194..................................425...789.....*....
|
||||
...-......618.716#...........233.............................828...........301......................190....#120....................360.232..
|
||||
.......................587..........766.812............178...-........929...................../.......*...........707.949....465..$.........
|
||||
..........191...=....................-...................................*378............766..456......605...............*....*........593..
|
||||
.481...#.%......267.....729.................619......116*164....................505....+....*.....531...................498...47...789*.....
|
||||
.....625............579*.......914.997=.....*...............................456*....632..133......*......751...%..631.......................
|
||||
..........=415.481.........979.............318.......=.............942.855...................512...985..*....865./..........................
|
||||
.................*...........@..................436-..542.........*.....*..$631........108.....%........619........194..............825..329
|
||||
..333.............624......................=.................795-..818.431.......702...*..............................=........+....%.......
|
||||
.../......................312.....666.......785.198......719....................&.......837........838..551.175..........368....557.........
|
||||
.....581.........986......*........+................268.....*...445............................*..*.......-...*.......99*...............=...
|
||||
.................@....793..............868......935....*..415.....*.430....253....@...........678..............420............%.46#..679....
|
||||
........................*....70*239......*............824.......499....*...*...965...696..532............405.........90....306..............
|
||||
.........................34...........152...216$.381.................373..22......../........*.............&...........-.........976........
|
||||
.................132.........448....................$.............*..........585.............321...............+...66....741.......*........
|
||||
.......194........&..669.......*................*..............460.465.54.......+........763.......738......444..........*....791..776......
|
||||
...978.....839......*........808...669.......864.30...................../...........439..*......*.....*...........441.....278...=...........
|
||||
.......971*.....*.....................*......................................43....*....778..329.711.136....................................
|
||||
............792.182..21............81..545...398&...........................*.....763....................181............*506....736..141.933
|
||||
........282*..........*......=............................41*982......237..166.............678..718=.656..*...........87.........*..........
|
||||
...................684........5......220*697.......259............347....*.............*.....*.........*.832.............388.....192........
|
||||
..395........=............838......................+.....693....#.....784...469*334.....870.464......572........875.....*...............152.
|
||||
......362.....693.........+...859......183..479...........*......969.......................................811..&....171.........284...=....
|
||||
.....*.............../...................*.........606..187..........644..........401.=984...98....760....*..............54.................
|
||||
...505.............806....249..........327....821.....@.................*....211..*.........*........*.422.................*......*902.863..
|
||||
............................*...................*..........219..........571....*...284...272......477.........938.....312...981..7..........
|
||||
.688...=....................544...766...........346..........................923.............................*........+............923......
|
||||
......779..=281...419..............+.................308....51...................836.........537../....931....97.........................952
|
||||
..................*......312...834.....................*........../.............*....83.262....*...748...............873.....46.4...........
|
||||
......355.......728.........*....%....................56..........752..296-....386.....*......53...........................-...*........@...
|
||||
....-.................483/..192.........714*248.................-.........................621.........*............926.....244.........867..
|
||||
...878...........#641...........................832.72.........877.......=..793............@........676.696.........*.......................
|
||||
.............853.............&614.......#699......*.......*29..........900.....*718..%369....#.$919........$....*....791.381......624.......
|
||||
................*255..........................758.604...........985.......................811................955.745.......*................
|
||||
...........9............276.393.76............$.............952......................947............385...*.............620....875..........
|
||||
...........*..755...210...#..*..*................/............/.........774..=............315..........$.750...........................@.381
|
||||
........975..*...../........168..472.....662.....308..............996........685..................77.........424..188...............639.....
|
||||
..............173.........#..............*...........740.............*372...........................*...............*.......................
|
||||
........................991.........*769..651.36.+12...*......861&............897.....749..859....271...96..........248.667.................
|
||||
.............%..............518..624...........*.......475.........183*.......%...............*...........-.....658.......*..+..............
|
||||
.29..........25...688..346.....*.........720.29....162.................502....................414...616........*........52..698..........453
|
||||
........286%.........-....*....359.........*......*........................881.........634..........+....=.....932..519...........765.......
|
||||
.................&........280....................282..209...519...........................*............970...........*.....@.....&.....*....
|
||||
.....448...216..204.190........108*868...*408......../.......*..=............824.........344..................29.....254..139.......811.656.
|
||||
.310..................*................................$..449....159...731.....*...154................107.......*279........................
|
||||
...*...194...........307.817.........................314....................208.....*................*.......+.......................871*...
|
||||
254...@............$.......@..#17..............284.........757......................921..#479..933.414....308......@154............*.....222
|
||||
..................817.................555.389....*............@.151...........................&................143..............348.448.....
|
||||
....20......321..........303............*.....873.....%..899...................226*.....*830.....................=........@.................
|
||||
....@....*...*......698...*.............363........189......*...192.&................890...............@814...............830......300..48..
|
||||
.......907..207.......*...284.......24+....................346.+....867.....808..43......397....363................254.........178......*...
|
||||
.................$................$............772...............+..........-...........*.......-...............#...%..................246..
|
||||
......332....855.250..........*....692.....968...............212..297...........223.....725.............419.....213...316.822...............
|
||||
..290....&..*.........108.....577....................133.87...=..............$...+.............&.........................*..............917.
|
||||
.......@.....701.......*..476....................806../..*.........216.5+.834......174..........597...............617......222..............
|
||||
...-...618.........992.47...*............497.............428.....@.*..............*.........276........521.../.......*......*........234....
|
||||
.465...............%........438.%627.727......................949...258.....927....365........*.....%..@...93.......186..535..........-.....
|
||||
...........557..........................*66......456.....+........*........+............539..95..790............220..........$...........95.
|
||||
117..........*.......869...........................@..943..133.249.364..............806*................=...342...*.......817....667........
|
||||
.............490.641*...........273.786..507.................@...............244......................71....*......717...........*.......871
|
||||
...236.70...............$.........*.*....%....................................*..386=...503..................778.=.........419...7..........
|
||||
.......*....$905..660...287....654..634........934.............344..........322............*............702......745..........*.............
|
||||
........950.........*............................#..906..118..*.....553.694.....191.....682.........412*.........................801........
|
||||
.............186....175...607................330....@.......*..931.*....*......@...............618............14........851&.567*...../.....
|
||||
............/...........+........156.449.334*....*....888..951.....559...144.........%.................................................16...
|
||||
....835..................96..751..*...........409.365....*...........................736........................310$......583...............
|
||||
......$........47...744........*.68.........*..........634..-..589........250..370...........644.....693...13*.............*...&............
|
||||
..470.....775...=..+.....&..234..........538.597...$.......391...........................179*.................524.......232..79.............
|
||||
....*.....=.............72..........................493..............=...............$.............................828...........583.*......
|
||||
..207...........312..........867..806......224..123...............616......76.......777./200..232..149.48...716..@...=..........&.....7.....
|
||||
......48.................277..........755=....*..........735.................*.................@....-...*..*....590..........+......-.......
|
||||
........*787.....82........*.....208...........359......................766.11.............%..........31...60..............731...928........
|
||||
...................@.......265..........333.........................781.@...................991...#............93...........................
|
||||
.........................................+...........................*..........................848....691.97...*..........539..............
|
||||
.507..238.........384......#.......&.....................987......@..395.844*......949*608.460......29...*.*.....955........*.........#734..
|
||||
........*./910..........607.........411.................*........102........................=...169...*....74........846..382.533/..........
|
||||
.....221........................742.......%...267.491.357...544......+...846.973....................66........440...........................
|
||||
..............-................/....833.103...$....*..............369........*.......519.....4.........-........*................809.942....
|
||||
.833..48..523..281.................&...................................442.958......*....951..-.........856.=..............49...&...../.....
|
||||
.......*.....*.......275.......259.....$.........-.175...662.697.307................169....*................33.....955.....*......+......68.
|
||||
...388.......231.994....@.........*.934........889.*.........*.............................668....*878......................353.560.....*...
|
||||
....@................%.........806..................708...221.......................498.....................79..385...................112...
|
||||
451.....555&........463.........................%.........................80*494...$.........976..487.......*.....=....801........781.......
|
||||
...*.99.......766@.........751.........174..760..169....479*368.382..281.............&........*.....*......179........=..........=.......51.
|
||||
.670..&..565.......577.$......+...=583........-......=............*....=......173#....732....9...221............*979....*....=..............
|
||||
...............551..&..235..............204*....@...65.......735..664................................966.918$........247.945..237...........
|
||||
.....920....42..*............844&.364@......823.801...........*.............&.995...344...688..178............560....................658*680
|
||||
.271...#........339.142.................921.................219..748......727.*.....*............@...........*.................131..........
|
||||
............./......#......260.....%851...*......................*.............910...535................657..996.%499..625........*.........
|
||||
....@363......785...........*.............795........31.........213.443....................................*...........+........244.....=806
|
||||
.........390.........320...553...84@.................*..........................45....547.........376.......206.............................
|
||||
54...................*................131..........*..32...............469........=..*.....665......&.........................427......349..
|
||||
..................193......894.....*.....*442...589.....................&............124...=.............405.........636......*...#.........
|
||||
..............................-.950.457.......................................-...................39.875...*.....230*......191..349.........
|
||||
.../.........863..........334...........90..199........184....................421.....979...666..+....*.....145.......#.....................
|
||||
...288..............568..#....501........*.....................$.....677.+.............*......*....959..............302..=875..821@.....531.
|
||||
...................*.........*....625..621.....689........405..247..#.....351..659..162....942............349.304...........................
|
||||
.......851.........742...&...478.....*.........#....523.........................=................$.......*.........589....758......371......
|
||||
...$........745........593...........181...835......*......794....=...502..381@...................973...77..433.....=....&........#.........
|
||||
.932........*................-.............%..........147........316..*..........%..........................*................323............
|
||||
.........283...+......100...486....4.............52..*...............977.......472.*....262................298......=894..........128.93....
|
||||
.............953.......*........................*....719....$......................473.....=...523......-.......723..................*......
|
||||
....................571.......................720..........269...........885.............................902...........80...738..........975
|
||||
44
2023/day3/src/main.rs
Normal file
44
2023/day3/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use std::{fs::File, io::{self, BufRead}, path::Path, process::exit};
|
||||
#[derive(Debug)]
|
||||
struct Coord{
|
||||
line_index: usize,
|
||||
char_index: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let symbol_ignore_list = ".123456789";
|
||||
let mut result = 0;
|
||||
// symbol_array is a list of a list of coords.
|
||||
// each list this array represents a line
|
||||
// inside the line is the list of the coords of each symbol
|
||||
let mut symbol_array: Vec<Vec<Coord>> = Vec::new();
|
||||
// File hosts.txt must exist in the current path
|
||||
if let Ok(lines) = read_lines("./input") {
|
||||
// Consumes the iterator, returns an (Optional) String
|
||||
let lines_array = lines.flatten().collect::<Vec<String>>();
|
||||
// collect a list of all symbols
|
||||
for line_index in 0..lines_array.len(){
|
||||
let mut line_symbol_array: Vec<Coord> = Vec::new();
|
||||
for char_index in 0..lines_array[line_index].len(){
|
||||
let cur_char = lines_array[line_index].chars().collect::<Vec<char>>()[char_index];
|
||||
if !symbol_ignore_list.contains(cur_char){
|
||||
let c = Coord{line_index:line_index,char_index:char_index};
|
||||
line_symbol_array.push(c);
|
||||
}
|
||||
}
|
||||
symbol_array.push(line_symbol_array);
|
||||
}
|
||||
|
||||
for line_index in 0..lines_array.len(){
|
||||
for char_index in 0..lines_array[line_index].len(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The output is wrapped in a Result to allow matching on errors.
|
||||
// Returns an Iterator to the Reader of the lines of the file.
|
||||
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
||||
where P: AsRef<Path>, {
|
||||
let file = File::open(filename)?;
|
||||
Ok(io::BufReader::new(file).lines())
|
||||
}
|
||||
Reference in New Issue
Block a user