Skip to content

Complete 2023 to 2015 entries written in Rust for the annual Advent of Code challenge, solving 450 stars in less than 1 second.

License

Notifications You must be signed in to change notification settings

maneatingape/advent-of-code-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code checks-badge docs-badge

Complete 2023 to 2015 entries written in Rust for the annual Advent of Code challenge, solving 450 stars in less than 1 second.

Features

  • Each solution uses the most efficient algorithms to the best of my knowledge.
  • Self contained depending only on the std Rust library. No use of unsafe features.
  • Consistently formatted with rustfmt and linted by clippy.
  • Thoroughly commented with rustdoc generated documentation online.
  • Test coverage with continuous integration provided by GitHub Actions.

Quickstart

Show details

Input

Place input files in input/yearYYYY/dayDD.txt including leading zeroes. For example:

  • input/year2015/day23.txt
  • input/year2023/day02.txt

Run

  • Everything cargo run
  • Specific year cargo run year2023
  • Specific day cargo run year2023::day01
  • Release profile (faster) cargo run --release
  • Optimized for current CPU architecture (fastest) RUSTFLAGS="-C target-cpu=native" cargo run --release

Test

  • Everything cargo test
  • Specific year cargo test year2023
  • Specific day cargo test year2023::day01
  • Show STDOUT for debugging cargo test -- --nocapture

Benchmark

  • Everything cargo bench
  • Specific year cargo bench year2023
  • Specific day cargo bench year2023::day01

Document

  • Build docs including private items cargo doc --document-private-items
  • Build doc then open HTML landing page cargo doc --document-private-items --open

Miscellaneous

  • Code quality lints cargo clippy
  • Consistent code formatting cargo fmt

Performance

Benchmarks are measured using the built-in cargo bench tool run on an Apple M2 Max. All 225 solutions from 2023 to 2015 complete sequentially in 579 milliseconds. Interestingly 84% of the total time is spent on just 9 solutions. Performance is reasonable even on older hardware, for example a 2011 MacBook Pro with an Intel i7-2720QM processor takes 3.5 seconds to run the same 225 solutions.

pie-all

Year Benchmark (ms)
2023 6
2022 8
2021 9
2020 272
2019 16
2018 35
2017 89
2016 120
2015 24

2023

pie-2023

Day Problem Solution Benchmark (μs)
1 Trebuchet?! Source 37
2 Cube Conundrum Source 9
3 Gear Ratios Source 53
4 Scratchcards Source 20
5 If You Give A Seed A Fertilizer Source 18
6 Wait For It Source 1
7 Camel Cards Source 71
8 Haunted Wasteland Source 34
9 Mirage Maintenance Source 18
10 Pipe Maze Source 41
11 Cosmic Expansion Source 12
12 Hot Springs Source 440
13 Point of Incidence Source 66
14 Parabolic Reflector Dish Source 632
15 Lens Library Source 84
16 The Floor Will Be Lava Source 826
17 Clumsy Crucible Source 2289
18 Lavaduct Lagoon Source 17
19 Aplenty Source 100
20 Pulse Propagation Source 6
21 Step Counter Source 182
22 Sand Slabs Source 54
23 A Long Walk Source 640
24 Never Tell Me The Odds Source 95
25 Snowverload Source 179

2022

pie-2022

Day Problem Solution Benchmark (μs)
1 Calorie Counting Source 14
2 Rock Paper Scissors Source 3
3 Rucksack Reorganization Source 13
4 Camp Cleanup Source 8
5 Supply Stacks Source 14
6 Tuning Trouble Source 3
7 No Space Left On Device Source 14
8 Treetop Tree House Source 51
9 Rope Bridge Source 107
10 Cathode-Ray Tube Source 2
11 Monkey in the Middle Source 1173
12 Hill Climbing Algorithm Source 57
13 Distress Signal Source 15
14 Regolith Reservoir Source 205
15 Beacon Exclusion Zone Source 2
16 Proboscidea Volcanium Source 59
17 Pyroclastic Flow Source 71
18 Boiling Boulders Source 121
19 Not Enough Minerals Source 74
20 Grove Positioning System Source 3785
21 Monkey Math Source 64
22 Monkey Map Source 61
23 Unstable Diffusion Source 1521
24 Blizzard Basin Source 62
25 Full of Hot Air Source 3

2021

pie-2021

Day Problem Solution Benchmark (μs)
1 Sonar Sweep Source 6
2 Dive! Source 12
3 Binary Diagnostic Source 20
4 Giant Squid Source 12
5 Hydrothermal Venture Source 181
6 Lanternfish Source 1
7 The Treachery of Whales Source 8
8 Seven Segment Search Source 14
9 Smoke Basin Source 64
10 Syntax Scoring Source 25
11 Dumbo Octopus Source 55
12 Passage Pathing Source 25
13 Transparent Origami Source 22
14 Extended Polymerization Source 11
15 Chiton Source 2403
16 Packet Decoder Source 6
17 Trick Shot Source 7
18 Snailfish Source 501
19 Beacon Scanner Source 615
20 Trench Map Source 2066
21 Dirac Dice Source 278
22 Reactor Reboot Source 378
23 Amphipod Source 1714
24 Arithmetic Logic Unit Source 4
25 Sea Cucumber Source 551

2020

pie-2020

Day Problem Solution Benchmark (μs)
1 Report Repair Source 12
2 Password Philosophy Source 35
3 Toboggan Trajectory Source 12
4 Passport Processing Source 49
5 Binary Boarding Source 11
6 Custom Customs Source 35
7 Handy Haversacks Source 69
8 Handheld Halting Source 8
9 Encoding Error Source 9
10 Adapter Array Source 1
11 Seating System Source 4537
12 Rain Risk Source 12
13 Shuttle Search Source 1
14 Docking Data Source 83
15 Rambunctious Recitation Source 147000
16 Ticket Translation Source 120
17 Conway Cubes Source 443
18 Operation Order Source 24
19 Monster Messages Source 362
20 Jurassic Jigsaw Source 42
21 Allergen Assessment Source 45
22 Crab Combat Source 5911
23 Crab Cups Source 110000
24 Lobby Layout Source 4320
25 Combo Breaker Source 20

2019

pie-2019

Day Problem Solution Benchmark (μs)
1 The Tyranny of the Rocket Equation Source 1
2 1202 Program Alarm Source 1
3 Crossed Wires Source 17
4 Secure Container Source 12
5 Sunny with a Chance of Asteroids Source 3
6 Universal Orbit Map Source 29
7 Amplification Circuit Source 79
8 Space Image Format Source 4
9 Sensor Boost Source 1008
10 Monitoring Station Source 1092
11 Space Police Source 341
12 The N-Body Problem Source 1309
13 Care Package Source 2510
14 Space Stoichiometry Source 17
15 Oxygen System Source 360
16 Flawed Frequency Transmission Source 1956
17 Set and Forget Source 338
18 Many-Worlds Interpretation Source 1157
19 Tractor Beam Source 688
20 Donut Maze Source 189
21 Springdroid Adventure Source 1785
22 Slam Shuffle Source 12
23 Category Six Source 670
24 Planet of Discord Source 232
25 Cryostasis Source 2047

2018

pie-2018

Day Problem Solution Benchmark (μs)
1 Chronal Calibration Source 16
2 Inventory Management System Source 78
3 No Matter How You Slice It Source 55
4 Repose Record Source 46
5 Alchemical Reduction Source 390
6 Chronal Coordinates Source 41
7 The Sum of Its Parts Source 8
8 Memory Maneuver Source 24
9 Marble Mania Source 909
10 The Stars Align Source 11
11 Chronal Charge Source 1404
12 Subterranean Sustainability Source 77
13 Mine Cart Madness Source 382
14 Chocolate Charts Source 24000
15 Beverage Bandits Source 583
16 Chronal Classification Source 37
17 Reservoir Research Source 151
18 Settlers of The North Pole Source 384
19 Go With The Flow Source 1
20 A Regular Map Source 36
21 Chronal Conversion Source 66
22 Mode Maze Source 3396
23 Experimental Emergency Teleportation Source 506
24 Immune System Simulator 20XX Source 2056
25 Four-Dimensional Adventure Source 323

2017

pie-2017

Day Problem Solution Benchmark (μs)
1 Inverse Captcha Source 1
2 Corruption Checksum Source 2
3 Spiral Memory Source 2
4 High-Entropy Passphrases Source 98
5 A Maze of Twisty Trampolines, All Alike Source 22000
6 Memory Reallocation Source 81
7 Recursive Circus Source 93
8 I Heard You Like Registers Source 47
9 Stream Processing Source 23
10 Knot Hash Source 66
11 Hex Ed Source 18
12 Digital Plumber Source 61
13 Packet Scanners Source 1
14 Disk Defragmentation Source 438
15 Dueling Generators Source 26000
16 Permutation Promenade Source 68
17 Spinlock Source 85
18 Duet Source 7
19 A Series of Tubes Source 19
20 Particle Swarm Source 245
21 Fractal Art Source 5
22 Sporifica Virus Source 36000
23 Coprocessor Conflagration Source 55
24 Electromagnetic Moat Source 275
25 The Halting Problem Source 3698

2016

pie-2016

Day Problem Solution Benchmark (μs)
1 No Time for a Taxicab Source 3
2 Bathroom Security Source 29
3 Squares With Three Sides Source 24
4 Security Through Obscurity Source 79
5 How About a Nice Game of Chess? Source 37000
6 Signals and Noise Source 4
7 Internet Protocol Version 7 Source 364
8 Two-Factor Authentication Source 9
9 Explosives in Cyberspace Source 6
10 Balance Bots Source 16
11 Radioisotope Thermoelectric Generators Source 719
12 Leonardo's Monorail Source 1
13 A Maze of Twisty Little Cubicles Source 3
14 One-Time Pad Source 77000
15 Timing is Everything Source 1
16 Dragon Checksum Source 1
17 Two Steps Forward Source 3858
18 Like a Rogue Source 728
19 An Elephant Named Joseph Source 1
20 Firewall Rules Source 21
21 Scrambled Letters and Hash Source 10
22 Grid Computing Source 28
23 Safe Cracking Source 1
24 Air Duct Spelunking Source 337
25 Clock Signal Source 1

2015

pie-2015

Day Problem Solution Benchmark (μs)
1 Not Quite Lisp Source 2
2 I Was Told There Would Be No Math Source 8
3 Perfectly Spherical Houses in a Vacuum Source 95
4 The Ideal Stocking Stuffer Source 14000
5 Doesn't He Have Intern-Elves For This? Source 38
6 Probably a Fire Hazard Source 6572
7 Some Assembly Required Source 27
8 Matchsticks Source 12
9 All in a Single Night Source 34
10 Elves Look, Elves Say Source 15
11 Corporate Policy Source 1
12 JSAbacusFramework.io Source 83
13 Knights of the Dinner Table Source 37
14 Reindeer Olympics Source 28
15 Science for Hungry People Source 53
16 Aunt Sue Source 20
17 No Such Thing as Too Much Source 45
18 Like a GIF For Your Yard Source 154
19 Medicine for Rudolph Source 187
20 Infinite Elves and Infinite Houses Source 1667
21 RPG Simulator 20XX Source 2
22 Wizard Simulator 20XX Source 235
23 Opening the Turing Lock Source 6
24 It Hangs in the Balance Source 380
25 Let It Snow Source 1