mirror of
https://gitlab.com/MisterBiggs/aoc-2023-rust.git
synced 2025-06-15 06:26:51 +00:00
omg I did day 3
This commit is contained in:
parent
d78aee48a7
commit
e5203321eb
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -4,9 +4,9 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
@ -16,6 +16,7 @@ name = "aoc_2022"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"regex",
|
||||
"scan_fmt",
|
||||
]
|
||||
|
||||
@ -36,15 +37,27 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
version = "2.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.0"
|
||||
version = "1.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -53,9 +66,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.28"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "scan_fmt"
|
||||
|
@ -7,3 +7,4 @@ edition = "2021"
|
||||
[dependencies]
|
||||
itertools = "0.12.0"
|
||||
scan_fmt = "0.2.6"
|
||||
regex = "1.10.2"
|
||||
|
140
inputs/day3.txt
Normal file
140
inputs/day3.txt
Normal file
@ -0,0 +1,140 @@
|
||||
...........................775.651...............887....79...946...921...493.....942..942.....151....155....................................
|
||||
......240...................*.....-......................$..*...................*.......%.....+....................956.549.*290.......834...
|
||||
.485...+............437......906......%..608.805.725..72.....242....745..61......440................................*..*.........515...*....
|
||||
..........917.......&....146........790.....*......*....*..........*.....*...............207*......................796..116......../...924..
|
||||
722...323.-................./...410.............72..748.442............384.708...............849..%............................470..........
|
||||
.....*..........................*.....271..691....-...............4*...........388.................448......&........*....848&......751.....
|
||||
....370..$....639.748.......*...467....*.....*........921*909.....................*...32.....................165..452.30....................
|
||||
........984....*.....*...782........711.....50.172...............61&..........415.803.*.........524.......................203.......106*643.
|
||||
...............57..433.........390....................&../.............*122...........674.........*.........................................
|
||||
379..................../.........*........908..477...305.876..*..............297.415*......+.......94........../.....@378.......226..56*....
|
||||
...*..-......82.......167...936.17..958...=....*...............196......+......*.......-...380.992.............989.........29......*....301.
|
||||
..124..317.....*....................*..........839.......................191.882......231.........+......976.................+......469.....
|
||||
............643................*........778............541........655..............*............*........./............*.................515
|
||||
.....&............498#...&....726.774..............111....*378..................723.221.......473............752....523.638.......789...*...
|
||||
.....353................518..........-.........../....*...............*88.........................*..@280..=..-....................-..297...
|
||||
...........279...........................*816.....286.975.&319.....614......694.......799.......503.......861...569.............+...........
|
||||
..474........*.228..............308......................................................*............207........................838..408...
|
||||
...........226./....*................82.........................268/......814.........640.............../..489........719..=..........*.....
|
||||
....83............88.544....250.......=...87..............199.........115*....................................*...377.@.....643........658..
|
||||
........-...651.............*................&..............................*379.....411...686.397............202.*....../........217.......
|
||||
.....781.......*897......630................330.....117.961..........61..543.....#...*.....*.......323.............996.603.......*..........
|
||||
.......................................................*........473....*.....739.184.511..........+......43.833.................953...@.....
|
||||
....110......@471...........*464....@.347......779................/.....205.*.......................681.....@.........................694...
|
||||
.........................203......158.-....310./...449...726*982.............437.....+....259...................185......940*702............
|
||||
.....465....*.......747....................*..........*...............................238..&......./..963...755....*........................
|
||||
.....*....687..104..%.........645........959..497..732........988........733.....12...........417.176....$..........176.323....657..........
|
||||
...566........*...........938*......418......*............925....*28..............-.156........*................................*..#........
|
||||
.............933.......................*....988........../............................*........813.................868*674...375...839......
|
||||
.....................804.......464..452...................................47......324.789..........692*288..................................
|
||||
...959...........792....*10.....=......................*455.77...827.99....*.........................................166.......8...586......
|
||||
.....*...607......*..............................12.764......*.......*..905....590.236...#.677...823......972..204............*......*......
|
||||
..661....*........776....938..901.............@.*.........$...216...995...........*....382..*....#....546*.....#...........564........707...
|
||||
......755................*.......*698......315..291.......964................-.......=.....865........................521........150........
|
||||
........................323............./............973.........*35..........318.....204...........546..+667....214%..*..............973...
|
||||
........143......&725...........619....149..............*235..650.........604..........................*..............195..............*....
|
||||
................................*.................................926...................@240......+...433..302..672.........977....149..335.
|
||||
.......880.......&...............301.512.$.....876......331.897...#..............#...............464......+...........938.........*.........
|
||||
......@....942...603....&....879..........117..........*.....*.............562..905....377*862..............*56.........%........352..*165..
|
||||
.726......*..........239....*.....915..............@...661...905..............*...................466....223.................730............
|
||||
....*......97..839.......308.........*....115....512..........................497.392.....563........=...............448...........462*884..
|
||||
....122.........*...471*...........52...&..=...................=..................@.........*...............................531.............
|
||||
.........*..522...&.....274...........116......*572...........907..........................161..670@..@....................=........57*.....
|
||||
.........28.*.....606.......................925...............................908...86...............78..............712.....813*......16...
|
||||
....549.....512....................................825.....797.......224..660*........@.425*656.........=536..256.......*........599........
|
||||
...*.............963..................842..704.............+....425..*..............................102.......$....565.179..774/........576.
|
||||
...................*..........................*..............=...*....922........50...262....%............603......*........................
|
||||
.......636.......349...&...224...$............899.........983..319.............#........&...663....*575..%.......95.....383*................
|
||||
......=...............928........218................84.............964.........953..+...........212.........................857.............
|
||||
............................179.......68......................&....*.................787.............92&.72....455..969...........846..40...
|
||||
.993=..../..........110.407*...........%.............164..#....306.215...................552..............*....=...#.....69.602...#...*.....
|
||||
......322..........#...........561..............968..*....913............%..........@586...=.330...........166.............*........863.....
|
||||
............810...........157.*....557.....30.*.....774...................968.601*...........*....491..........557.....83*..................
|
||||
.......*368.*.......842...*...435.-...........65.-................................680.....913....#.......793....*.........87.262....34.-....
|
||||
....896......875.....*...........................581.957..758............$................................@..981..............#......*.844..
|
||||
..................957...150.......503................@....*......89....59......261..........653....................................372......
|
||||
...731...-129..+........*........-......................718.713....*.......197..*......30......+...476............872.......................
|
||||
....*...........671....917.......................800.&......=....197..763....*...96......#.........*......%......*..........739......290....
|
||||
.....234..............................814*251....../.755.............../...375.....................309.914..816...877..=.......$......$.....
|
||||
.........543.378.....74.%608.25...755..........237..............834..................431..................../..........585..................
|
||||
....408...&...*..............*................*.............214*.....................*.........89.475*.......................@..939..824....
|
||||
...*..........526..........713..&.....132...899..108.75..#..................521....428....97../.......603.....248.........878...&...*.......
|
||||
....383...............873......1....................*....850....862....%......#.=................533.........*.......................863....
|
||||
.............852.........*................578%....................*..492.........905.145.927........*........437.107.....@....29............
|
||||
......604.......#./531.179..&........56.........921..233.......943......................*..........174...........*.......271.*...32.........
|
||||
........*..619.............588......*............*...*..............918*837.....120.128......508...........536...............558...*638.....
|
||||
523....794...-....................451..544....648..365.778.....@.............@.....*............$..%414...*............453#.................
|
||||
..................&......124*...........*...............*...259........696...424...........*...............322..534................*519.....
|
||||
........201*.30...474........567.526..363............%.963......287+......*.........939.964.....994.............*.....-........287.......657
|
||||
........................709*......=.........854...527................50..591...859....%..........*....196.......188..395..157...*...........
|
||||
.281*....878................354.......*221...*............308....309...*.........$..@...72#......577.........................*...734.....481
|
||||
.....9....*.............658........235......767..12..548...=...#.......585..830....609........................603.130.....884...........*...
|
||||
........324........@...*........................*....*........628.............................................*...$...........=......658....
|
||||
..................139.206....$.....768*........986....311..........967...15...174....100-.....7$..............962....=.........561..........
|
||||
......521.....154.............318......622...................-.............%...@.................856.......60.........24..481.......520.772.
|
||||
.825..#.......*.............................180.............228.11.....173.......128......428.........405.+...68...........=..882......*....
|
||||
....*.......657...........27....798*460...................@............-..............31.*.....840...........*................@.............
|
||||
.965...931............974...*...........................798.................455*.........856......*...809...97..934.740$..570...............
|
||||
........*..511.$427....../..652..-297............296........$........552..........884..................*........%........*........128.......
|
||||
..........-..........207............................=....641.........+..........-..*....43..........329................990...........*......
|
||||
.10...................=..11....&............................./.143........875..732....&.......&............................349.....265...858
|
||||
...*......222....495%...*...618..322.......%.........116...833....*........*.........776....288....760.........-............-...............
|
||||
....291......*..........453.........*...811...398..............515........365..445....................*.....961.........433......743...$....
|
||||
.............33..................543.........@..........................=...../.....793*...........266..............668...........#.....804.
|
||||
................701....................17*.................449*741.....961......814..........................*245......*...809*.............
|
||||
.......206......*....668..728$............529..........*93........................-...833.713..............69.......292........157...224*...
|
||||
..........*585...969............810..522............866..............254.....570........*....*.....588..................+113.......-.....752
|
||||
................................/......../......257.............119...-..844...*..979..442....169.....=.259......+.............752..401.....
|
||||
...726...967........&.234.................326.....*....590*636...*............130.../.........................933.....652*439...*...........
|
||||
.....*......*12..332...-...........500#..........944..............747.......$.....................203....513.......................%864.....
|
||||
....389.&....................*...............938.......893....970.........864........538.755&.258..*........#...............717.96......+...
|
||||
.65.....180...&.............864.....169.........*................*...390............*.........*....904.........................*...354...478
|
||||
....620......472.726.931...............*.......150../.......@....960....................*928.812...........................428......*.......
|
||||
...*................*.................463..........323.....478..........964..........175.........324%........=827......66.......193..303....
|
||||
313.......................@...705.214.....174&........................-.....271........................818...............*.........+........
|
||||
........171+..830...328..158...*..%..................17....721.....568......../...........949.............*.............608.....90......570.
|
||||
....327..........*....*.......44......................*..................193-.......67.................970......966.503................#....
|
||||
669*..........386..306....+............105............443...........................*........490..130...........*....$..........$62.........
|
||||
......454...............&..954...38....*..........229....................643......388.671....@.......*...8......506....66*148.........$.....
|
||||
......*................259.........*.................*756.......596.........*........................638..+....................%....854.....
|
||||
...700......895..............................757................*.........847..............630*612..................854..606....38..........
|
||||
...............*.....93.....573......274........*...952..336...................562..................+...637............*.*..................
|
||||
945........../.814..=..........*....*...........38..=............-....&........*..................118......*.........745..855.........367...
|
||||
......676..688..................604..153...............671......513...690....891.%.....101.728..........767......28...................../...
|
||||
.........=.......700..222.443............114.....................................458...../....#...................*.........=...............
|
||||
...........660.%...&.....*.....98.232.......*............308.......650..267/..........$............................417.....806.....502......
|
||||
.......276*....500............@.............63.......621*.....520...-........913.....225.........620.597...709*632.............663*.........
|
||||
...................232...149............65.......................&........................228.....%.....-................467............800.
|
||||
..........118........+....*....@.........-.458...737.....-247.........425................/..................574......424*.........421..*....
|
||||
......158.-....*........564.599......128......*...#..........................419.............764*156.............................*......996.
|
||||
............577.563.....................*...777.......................508..............*827............................*465.....306.........
|
||||
.........................*..............848......996*......688....154...*.......%...780......51...410......357.148..856.....................
|
||||
...648.............835.713....*...609.......................&........*..885....494..........*..........661....*.............................
|
||||
...-.....477./693..*........938.....*./...........642..149......465.502......$............=.523.........#.......892................=824.....
|
||||
....................296...........44...707..........+.....*...................462......476........@...............*..........388............
|
||||
.....58...321..............127................................446...............................965....446........114.........*.............
|
||||
.........*........951...3....*.................623.263.............=.-....122..........................=....519*...........692.......%313...
|
||||
........943.......*......$....990.......795..../......*..135.....815.483....*..937*.............................634..............771........
|
||||
............460....757.....@......511/..*............564..-..............340.......109.206.......%785..148...21....................*....&...
|
||||
.47.........&...............102........265......555..................182......12*.........................*...%.................788..200....
|
||||
.../............=..................#82..........$.......207.............*863.....751.........251.....641.702.......141..640.................
|
||||
..........23..902.......174...............*.............=.....314...........................*..........*.....*667...........*...............
|
||||
.........*...............*.......*766..842.35.......243..........*......@..................57..435....501.285.............964.....*.........
|
||||
..165...100.@512.........292.......................%......79..@...726....341.511*.............*...................573..........602.74.......
|
||||
...*..................................596#...&...............769........................314.397..&31................%..855..................
|
||||
...6.....673....................898..........836.......827.......+.....-..............................133*766..........*..............290...
|
||||
..........*.........799........*.........629.......634........%.188.103.......594......464.799*295.............895...930.........-....$.....
|
||||
.....908..504.......*......603..800..936...*......*.........768..........973...*.......*...............904*16.*................358..........
|
||||
.....@............825..%......&.........*...963.294.74...........%........*....102...967...-343.................#..................94.698...
|
||||
.810...................968..............429...........*....950..313..482..397...................33.........@..297..198...114.......*...*....
|
||||
.....-............................554..................................-.......245.$...............991..282.........-...*....161..894..78...
|
||||
..705.....177.....*..872@.285........*.../813.........235....729..........*287..*...472.788.645........................144..................
|
||||
.............*..984.......*........722............496*..........*990....79......715........*............456...................812..470......
|
||||
............518......@.....950.........712..............981...........................238....579.533........373.466...615/......$.....*907..
|
||||
..716..907.......761..471..............*......../...........823..+............978*......=.....*.....#......&....*...........................
|
||||
....*...............*........990.331...46....871...........*.....447.723...@...............594...............801......................#757..
|
||||
...312...*.........211..........*.................90.860...970.........*...375...........*.....-....*779.........&..........................
|
||||
.......692..............602.............................*.............595.............841...166..327......-444....154.......................
|
||||
..............$....316..=.............+978.843........42....135/.+332.........454.........................................707.../......295..
|
||||
.........$....743..../.......-................+........................*990..................343......#.....*...............*....684........
|
||||
......651.....................644....................887.812........187.................783........749...928.291...........131...........293
|
83
src/day3.rs
Normal file
83
src/day3.rs
Normal file
@ -0,0 +1,83 @@
|
||||
use std::{fs, vec};
|
||||
|
||||
use itertools::Itertools;
|
||||
use regex::Regex;
|
||||
|
||||
pub fn run() {
|
||||
println!("Day 1:");
|
||||
let input = fs::read_to_string("./inputs/day3.txt").expect("Could not read file");
|
||||
|
||||
println!("\tPart 1: {}", part1(&input));
|
||||
// println!("\tPart 2: {}", part2(&input));
|
||||
}
|
||||
|
||||
fn part1(schematic: &str) -> usize {
|
||||
let mut sum_of_parts = 0;
|
||||
let padded_schematic = format!(".\n{schematic}\n.");
|
||||
let re = Regex::new(r"\d+").unwrap();
|
||||
let windows = padded_schematic
|
||||
.lines()
|
||||
.tuple_windows::<(_, _, _)>()
|
||||
.collect::<Vec<_>>();
|
||||
for (top, middle, bottom) in windows {
|
||||
for number in re.find_iter(middle) {
|
||||
let search_range = std::ops::Range {
|
||||
start: number.range().start.saturating_sub(1),
|
||||
end: number.range().end + 1,
|
||||
};
|
||||
|
||||
let mut search_values: Vec<char> = vec![];
|
||||
for index in search_range {
|
||||
search_values.push(top.chars().nth(index).unwrap_or('.'));
|
||||
search_values.push(middle.chars().nth(index).unwrap_or('.'));
|
||||
search_values.push(bottom.chars().nth(index).unwrap_or('.'));
|
||||
}
|
||||
if search_values
|
||||
.into_iter()
|
||||
.filter(|c| !c.is_ascii_digit())
|
||||
.filter(|c| c != &'.')
|
||||
.count()
|
||||
!= 0
|
||||
{
|
||||
sum_of_parts += number.as_str().parse::<usize>().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
sum_of_parts
|
||||
}
|
||||
|
||||
// fn part2(calibration_input: &str) -> usize {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_1() {
|
||||
let input = "467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..";
|
||||
|
||||
assert_eq!(part1(input), 4361);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_2() {
|
||||
// let input = "two1nine
|
||||
// eightwothree
|
||||
// abcone2threexyz
|
||||
// xtwone3four
|
||||
// 4nineeightseven2
|
||||
// zoneight234
|
||||
// 7pqrstsixteen";
|
||||
|
||||
// assert_eq!(part2(input), 281);
|
||||
// }
|
||||
}
|
@ -3,9 +3,11 @@ extern crate scan_fmt;
|
||||
|
||||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
|
||||
fn main() {
|
||||
println!("Running Advent of Code 2023");
|
||||
day1::run();
|
||||
day2::run();
|
||||
day3::run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user