Rust-advent - Learning Rust by solving advent of code challenges (Streaming live on Twitch every Monday)


Rust advent ๐Ÿฆ€ ๐Ÿš


Learning Rust by implementing solutions for Advent of Code problems.

๐ŸŽฅ HEY, we are live-streaming our attempts to solve the exercises in this repo! Check us out on:

Eugen, Roberto and Luciano trying to solve Advent of Code in Rust

And remember to follow and subscribe! ๐Ÿ˜Ž ๐Ÿ˜‹

How to run tests for all exercises

Simply execute:

cargo test

If you want to run only one test for a given part of an exercise you can run something like this:

cargo test --package ex01 --lib --all-features -- tests::part_2

Create a new exercise

Cd into the specific year folder (e.g. y2020) and run:

cargo new --lib exNN

Replace NN with the number of exercise for the given year. For instance:

cargo new --lib ex01

Finally add the new subproject in the workspace by editing the main Cargo.toml. For instance, assuming you just created y2020/ex10:

members = [
  # ...
  "y2020/ex10" # <- new entry


Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.


Licensed under MIT License. ยฉ Luciano Mammino, Roberto Gambuzzi, Eugen Serbanescu, Stefano Abalsamo.

  • Y2021 ex4

    Y2021 ex4

    Solution for ex4.

    Part 2 was not too hard from a logical perspective but it took me forever to figure out a decent way to filter out the Boards while they were winning without having to keep cloning things around.

    I figured out I could keep a Vec of mutable references and keep removing (the references) from that one as a given board win...

    Filtering a Vec of mutable references proved to be... quite tricky...

    Eventually i figured out that you can overcome all the mutability and reference issues with:

    let mut bb: Vec<&mut Board> = boards.iter_mut().collect();
    bb = bb
                .filter_map(|x| if x.mark(num) { None } else { Some(x) })

    filter_map feels unnecessary here, but it's actually conveniente because it will give you a plain &mut Board in the closure and not a weird &&mut Board...

    I don't know if there's any better solution to this!

    opened by lmammino 12
  • Y2021 ex15

    Y2021 ex15

    Using Dijkstra algorithm to solve this one. I also used const generics to be able to generalise how data is loaded into an arbitrary grid (everything else is filled with 0s). Then there's a generic method to expand the map based on a given tile size.

    โš ๏ธ TODO:

    • [x] Add README
    opened by lmammino 9
  • feat: y2021 ex18

    feat: y2021 ex18

    Implemented part1 & part2 for day 18 y2021.

    For part2 we have 3 different ways of calculating all the permutations:

    1. nested for loops
    2. our own custom iterator
    3. using the crate itertools

    We added benchmarks for all the 3 of them and (surprisingly) number 2 is the fastest.

    opened by lmammino 8
  • Y2021 ex9

    Y2021 ex9

    Nothing too special about this implementation except a few small things I discovered:

    • The Rust standard library contains a built implementation of priority queues that we can use to easily keep track of the 3 biggest basin sizes: BinaryHeap
    • We have been trying many times to convert a char (containing a number) to a u8 and we have been doing ASCII maths to do that. I just discovered we can simply do: c.to_digit(10).unwrap() as u8
    • When we create a wrapper type (like Space here) we can automatically proxy all the method calls to the wrapped type by implementing the Deref trait.
    opened by lmammino 8
  • Y2021 ex2

    Y2021 ex2

    My impl for ex2 of 2021.

    I took the opportunity to play around with the FromIterator trait. I am pretty happy with the result.

    There is a bit of code duplication but I think we can reduce that a bit by creating a Movable trait and a blanket implementation for FromIterator<Istr> for T where T: Movable.

    Something that could be interesting to explore together.

    Let me know what you think.

    opened by lmammino 8
  • Y2021 ex13

    Y2021 ex13

    Nothing particularly interesting in terms of implementation.

    It was weird to see for the first time that part 2 required us to "visualize" the output to be able to give an answer.

    To handle this i did change the test for part 2 to only count the dots and i left some commented piece of code to draw the grid if needed.

    Let me know if you have any better idea on how we could handle this!

    opened by lmammino 7
  • Y2021 ex3

    Y2021 ex3

    My implementation. Nothing particularly fancy about the solution except that i tried to reduce the number of allocations and clone/copy as much as i could.

    opened by lmammino 7
  • Y2021 ex16

    Y2021 ex16

    This one was a bit tricky and I am really bad at dealing with binary parsing.

    I was initially trying to use a lazy approach where I constructed an iterator of bytes (u8) and I would be using bit shifting over bytes. It proved to be a little complicated (for my skills) to manage the alignment that way. I ended up simplifying this by using a proper sequence of 1 and 0.

    This is all abstracted in the BinaryString struct. So we can potentially refactor that one and come up with a more efficient approach if we want to.

    Another small improvement that we could do would be to use an Enum for the packet types.

    opened by lmammino 6
  • Y2021 ex14

    Y2021 ex14

    I tried 3 different approaches (strings, nested linked list, flat linked list) on this one trying to expand the string for realz without realising that it would require terabytes of memory ๐Ÿ™ˆ

    Thanks to a few suggestions by @gambuzzi I managed to come up with a better approach based only on segments counting.

    โš ๏ธ TODO:

    • [x] Add README
    opened by lmammino 6
  • Y2021 ex6

    Y2021 ex6

    • Using FromIterator to parse input
    • Using Iterator to simulate the passing of days. The iterator keeps the internal state and has a method to count the current number of fishes available. The iterator is effectively implementing all the simulation business logic.
    opened by lmammino 6
  • Cleans up and improves ex17 y2020

    Cleans up and improves ex17 y2020

    This revisited solution introduces a new struct called Game. This struct creates and retains a vector of relative neighbours which effectively acts as a cache, so we don't need to recompute all the neighbours over and over.

    Moreover Game implements Iterator so you can easily compute a number of game ticks and count the active cells.

    Finally Game can be initialized from an input string which provides a generalisation on parsing input.

    This solution seems slightly faster (or at least on par) with the previous non-generalised solutions:

    Screenshot 2021-09-11 at 16 58 04

    If you like this approach, I would suggest that, before merging this, we remove the non generalised solutions so we can keep the code a bit cleaner and more organised.

    opened by lmammino 6
  • Solved y2022 day 12

    Solved y2022 day 12

    Solved using dijkstra.

    ~~Part 2 could be optimised~~

    Part 2 was optimized by running a reverse Dijkstra (from the end to all possible paths). This way Dijkstra is run only once and then we look at all the paths to the possible scenic points and select the shortest.

    This resulted in -99.529% performance improvement. From ~200ms in non-debug mode to about 1ms!

    opened by lmammino 0
Luciano Mammino
FullStack โ˜๏ธ developer, entrepreneur, fighter, butterfly maker! ๐Ÿ“— Co-author ๐Ÿ’Œ maintainer
Luciano Mammino
Generate perfect Vyper compatible code headers every time.

headers-vy Generate perfect Vyper-compatible code headers every time. Build You need Rust and Cargo installed on your machine. See the installation gu

t11s 15 Feb 12, 2023
Learning Rust through Advent of Code 2021 - probably not very clean!

AoC 2021 ======== I'm using AoC2021 as an excuse to learn Rust (and maybe some other languages). Please do *not* use this repository as a good source

Andrew Zhu 0 Dec 8, 2021
Fast package resolver written in Rust (CDCL based SAT solving)

Resolvo: Fast package resolver written in Rust Resolvo implements a fast package resolution algorithm based on CDCL SAT solving. If resolvo is unable

Mamba 17 Sep 27, 2023
Repository for solving puzzles

Advent Of Code ?? This is a repository for any Otovista that wants to participate in the advent of code christmas calendar challenges. Advent of Code

Otovo 4 Dec 20, 2022
Solving context limits when working with AI LLM models by implementing a "chunkable" attribute on your prompt structs.

Promptize Promptize attempts to solve the issues with context limits when working with AI systems. It allows a user to add an attribute to their struc

Dan Nelson 5 Jul 18, 2023
A Twitch OAuth token revoker written in Rust.

Revoker - A Twitch OAuth Token Revoker Details Revoker is a small CLI tool written in Rust, made so you can easily and urgently remove a Twitch OAuth

Mykola 4 May 20, 2022
Twitch Bot Project (Rust)

This is a Twitch bot written in Rust that connects to the Twitch IRC server and allows users to interact with the bot via chat messages. The bot can join multiple Twitch channels and respond to commands.

icsboyx 4 Aug 17, 2023
Twitch chat in the terminal.

Twitch Chat IRC, in the terminal. What it looks like: Keybinds: Normal mode Key Description ? Have the keybinds window appear. i Enter insert mode for

null 172 Dec 30, 2022
Twitch chat in the terminal.

Twitch chat in the terminal. What it looks like: Keybinds: Normal mode Key Description c Go to the chat window chat. i Enter input mode for sending me

null 176 Jan 5, 2023
LL Cool Twitch Tools

LL Cool Twitch Tools Hit me up on my twitch channel This project is a playground twitch API playground for me.

Christopher N. KATOYI 9 Dec 23, 2022
A multi-threaded Twitch chat archiving and downloading tool.

Twitch Chat Downloader ??๏ธ tcd is a multi-threaded Twitch Chat Downloader built in Rust ?? . Usage: tcd [OPTIONS] <--channel <CHANNEL>|--video <VIDEO>

Matthew Polak 6 Dec 19, 2022
A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

Sebastiรกn Romero Cruz 1 Apr 10, 2022
A Rust CLI that makes mechanical keyboard sound effects on every key press

Rustyvibes A Rust CLI that makes mechanical keyboard sound effects on every key press Rustyvibes.mp4 Installation macOS: brew install kb24x7/rustyvibe

Kunal Bagaria 95 Dec 14, 2022
๐Ÿ‘€Little program I made in ๐Ÿฆ€Rust that reminds me every 20 minutes to look away from my computer ๐Ÿ–ฅscreen.

?? eye break Little program I made in ?? Rust that reminds me every 20 minutes to look away from my computer ?? screen. I stay way too long on the com

Goldy 3 Apr 9, 2023
Crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains

crunch ยท crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains. Why use crunch To automate payout

null 39 Dec 8, 2022
A diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to retain every change.

Docchi is a diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to save very often. User'

juzy 21 Sep 19, 2022
CIEBII - Check if every bit is intact

CIEBII Checks If Every Byte Is Intact CIEBII is an image file format that checks if every single byte is intact. What does it do if it finds that a by

Codingsquirrel 2 Oct 7, 2022
Same procedure as every yearโ€ฆ right?

Advent of Code 2022 solutions What this repository is This repository contains solutions to Eric Wastls Advent of Code 2022. Thank you, Eric! While th

Patrick 3 Dec 15, 2022
Uses the cardano mini-protocols to receive every block and transaction, and save them to a configurable destination

cardano-slurp Connects to one or more cardano-node's, streams all available transactions, and saves them to disk (or to S3) in raw cbor format. Usage

Pi Lanningham 16 Jan 31, 2023