Skip to content

fortunatodeangelis/advent-of-code-2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Clarifications

I participated in this challenge programming in Rust, I've never worked with this language, but reading the documentation has always fascinated me. Below, you will also find some logic that I have implemented, absolutely improvable.

πŸŽ„ Advent of Code

Day 01 / Part 1

In the first puzzle you are asked to locate the elf🧝 with the most calories 🍬 carried. The list received as input is represented by integer numbers divided into lines indicating the calories transported. These lines are further divided by empty lines. When an empty line is encountered it will mean that the next set of calories is being carried 🚚 by a different elf.

Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Get Input Dataβ”œβ”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚Define index = 0    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚                    β”‚
                   β”Œβ”€β”€β”€β”€β”€Define 🧝elf vect   β”‚
                   β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β–Ό
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚LOOP LINES│◄────────────────────┐
             β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜                     β”‚
                   β”‚                          β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€ Line is Empty?β”œβ”€β”€β”€β”€β”€β”€β”           β”‚
    β–Ό      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β–Ό           β”‚
   NO                            YES          β”‚
    β”‚                             β”‚           β”‚
    β”‚                             β–Ό           β”‚
    β”‚                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
    β”‚                        β”‚Index++; β”‚      β”‚
    β”‚                        β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜      β”‚
    β”‚                             β”‚           β”‚
    β”‚                             β”‚           β”‚
    β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚           β”‚
    └────►│Exist elf[index]?β”‚β—„β”€β”€β”€β”€β”˜           β”‚
          β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜                 β”‚
              β”‚        β”‚                      β”‚
    β”Œβ”€β”€β”€β”€YESβ—„β”€β”˜        └──►NO ────┐           β”‚
    β”‚                             β”‚           β”‚
    β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
    β”‚                  β”‚Push 0 at elf[index]β”‚ β”‚
    β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
    β”‚                             β”‚           β”‚
    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚           β”‚
    β””β–Ίβ”‚Add calories line at     β”‚β—„β”˜           β”‚
      β”‚elf[index]               β”‚             β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
                  β”‚                           β”‚
            β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”                      β”‚
            β”‚ END LOOP β”œβ”€β”€β”€β”€β”€β–ΊNOβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
                 YES
                  β”‚
                  β”‚
                  β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚Get elf with max valueβ”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Day 01 / Part 2

The elf🧝 with the most calories🍬 may have run out of stash, the challenge. in addition to the previous one, he asks to find the three elves who have the most calories.

Flow

The flow is similar to part 1, only the result should be: take the three elves🧝 that have the most calories🍬 and add the result