๐ŸŽ„
Advent of Code
๐ŸŽ„

Level up your programming skills

Hi, I'm Elke!

Who am I?

  • ๐Ÿ‘ฉโ€๐Ÿ’ป Fullstack JS consultant
  • ๐Ÿ“ธ Photography
  • ๐Ÿค˜ Rock and metal shows/festivals
  • ๐Ÿƒโ€โ™€๏ธ Half-marathons

I like to do weird things...

1st of December 2022: 62.19% of Ghent completed

๐ŸŽ„
What is the Advent of Code?

What is an advent calendar?

  • โ›ช๏ธ Christian tradition
  • #๏ธโƒฃ Counting down
  • 4๏ธโƒฃ 4 Sundays before Christmas
  • ๐Ÿ“† November 27th - December 3rd
  • ๐Ÿ˜Ž Easy mode: December 1st
  • ๐Ÿค‘ Commercialised

Food advent calendars

Toy advent calendars

The Advent of Code

  • โœ๏ธ Story set in 25 days before Christmas
  • ๐Ÿงฉ 25 programming puzzles
  • ๐ŸŒ… Every morning at 6am
  • โฐ Each day = 2 parts
  • โญ๏ธ Each part = 1 star
  • ๐Ÿคฉ Goal: 50 stars

The Advent of Code

  • ๐Ÿ‘จโ€๐Ÿ’ป Eric Wastl
  • ๐ŸŽฌ 2015
  • ๐Ÿ“… 2015: 15k participants
  • โ˜๏ธ 2021: 240k+

How/why people participate

  • ๐Ÿƒ Speed run
  • ๐Ÿง‘โ€๐Ÿซ Education
  • ๐Ÿ™‹ Preparation interviews
  • ๐Ÿ‹๏ธโ€โ™‚๏ธ Company training

Sometimes, you just have to challenge yourself...

๐Ÿƒ
Why should you participate?

Challenge yourself

  • ๐Ÿ“š Learn a new language
  • ๐Ÿ‹๏ธโ€โ™€๏ธ Exercise your knowledge
  • ๐Ÿ•ต๏ธโ€โ™€๏ธ Find creative solutions
  • ๐Ÿง  Learn algorithms

๐Ÿงฉ
Puzzle examples

Day 1

After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.

The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room. To save your vacation, you need to get all fifty stars by December 25th.

Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.

Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together. For example, suppose your expense report contained the following:

1721
979
366
299
675
1456

In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579.

Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?

How do you start?

  • ๐Ÿค“ Read the text thoroughly
  • ๐Ÿง  Understand everything
  • ๐Ÿ•ต๏ธโ€โ™€๏ธ What is the problem we try to solve?
  • โฌ‡๏ธ What is the input?
  • โฌ†๏ธ What is the output?
  • ๐Ÿฅธ Write some pseudocode

Finding the algorithm

1721
979
366
299
675
1456

  • ๐Ÿคจ The problem = find 2 entries that sum to 2020
  • โฌ‡๏ธ The input = list of numbers
  • โฌ†๏ธ The output = multiply the two entries

The algorithm

1721
979
366
299
675
1456

  • ๐Ÿ”„ Loop over entries
  • ๐Ÿ”„ Loop over other entries
  • ๐Ÿคจ Entry 1 + entry 2 = 2020
  • ๐ŸŽ‰ Result = entry 1 * entry 2
  • ๐Ÿ˜ซ Continue search

Day 1 solution

				  
const data = [1721, 979, 366, 299, 675, 1456];

for (let i = 0; i < data.length; i++) {
  for (let j = 0; j < data.length; j++) {
    if (data[i] + data[j] === 2020) {
      console.log(data[i] * data[j]);
    }
  }
}
            
			

if statement is true for 1721 + 299

1721 * 299 = 514579

Day 1 input

1632 1438 1811 1943 1883 1698 1976 1972 1794 1726 1850 1789 1524 1701 1454 1594 1655 1018 1828 1867 1959 1541 1596 1998 1916 1894 1727 1812 1800 1897 1534 1712 1825 1629 1827 81 1855 1621 1694 1663 1793 1685 1616 1899 1688 1652 1719 1589 1649 1742 1905 922 1695 1747 1989 1968 1678 1709 1938 1920 1429 1556 2005 1728 1484 1746 1702 1456 1917 1670 1433 1538 1806 1667 1505 963 1478 2003 1955 1689 1490 1523 1615 1784 1624 583 1465 1443 1489 1873 1485 1773 1704 352 505 1705 1844 1599 1778 1846 1533 1535 1965 1987 828 1755 1823 1639 1981 1763 1758 1819 1569 1580 358 1786 1964 1604 1805 1822 1941 1993 1939 1975 1966 1852 1310 1687 1718 641 1715 1995 1603 1444 1641 1961 1536 1771 1267 1749 1944 1519 1445 1818 1558 1922 1452 1901 1915 1957 1840 1785 1946 1683 1918 1847 1690 1716 1627 1571 1985 1455 435 1856 1527 1660 1555 1557 1591 1906 1646 1656 1620 1618 1598 1606 1808 1509 1551 1723 1835 1610 1820 1942 1767 1549 1607 1781 1612 1864 2007 1908 1650 1449 1886 1878 1895 1869 1469 1507
https://adventofcode.com/2020/day/1/input

๐Ÿค” 200 input numbers

Day 1 solution

				  
function runPartA() {
	const fileData = readFile("01", "a");
	const data = fileData.map((value) => Number.parseInt(value));
  
	for (let i = 0; i < data.length; i++) {
		for (let j = 0; j < data.length; j++) {
			if (data[i] + data[j] === 2020) {
				return data[i] * data[j];
			}
		}
	}
}
            
			

if statement true for: 81 + 1939 = 2020

Puzzle solution = 81 * 1939 = 157059

Time for part 2!

The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.

Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.

In your expense report, what is the product of the three entries that sum to 2020?

Updating the algorithm

  • ๐Ÿ”„ Loop over entries
  • ๐Ÿ”„ Loop second time over entries
  • ๐Ÿ”„ Loop third time over entries
  • ๐Ÿคจ Entry 1 + entry 2 + entry 3 = 2020
  • ๐ŸŽ‰ Result = entry 1 * entry 2 * entry 3
  • ๐Ÿ˜ซ Continue search

Part 2 solution

				  
function runPartB() {
	const fileData = readFile("01", "a");
	const data = fileData.map((value) => Number.parseInt(value));
  
	for (let i = 0; i < data.length; i++) {
		for (let j = 0; j < data.length; j++) {
      for (let k = 0; k < data.length; k++) {
        if (data[i] + data[j] + data[k] === 2020) {
          return data[i] * data[j] * data[k];
        }
      }
		}
	}
}
            
			

if statement true for: 352 + 358 + 1310 = 2020

Puzzle solution = 352 * 358 * 1310 = 165080960

What have we learned/used?

  • ๐Ÿค” If statements
  • ๐Ÿง› Basic arithmetic operations
  • ๐Ÿ‘ฏ Arrays
  • ๐Ÿ”„ Looping over arrays
  • ๐Ÿ‘“ Reading a file

The end result

๐Ÿ‘ต
My experience with the Advent of Code

๐Ÿฅ‡
First time participating:
Scheme

Language for 2018: Scheme


(define (fib n)
  (cond
    ((= n 0) 0)
    ((= n 1) 1)
    (else
      (+ (fib (- n 1))
         (fib (- n 2))))))
  • ๐Ÿ“… 1975
  • ๐Ÿ‘ฉโ€๐Ÿซ Learned at university
  • ๐Ÿ“š Research and teaching
  • ๐Ÿฆธ General purpose language

2018: Scheme

  • ๐Ÿ‹๏ธโ€โ™€๏ธ Exercise my old Scheme knowledge
  • ๐Ÿ“† Same day solve
  • โณ Performance and time
  • โฉ Skipped 2 days
  • ๐Ÿ˜จ Never completed
  • ๐Ÿคฉ 31 stars

https://github.com/ElkeCodes/AdventOfCode2018

Retro on 2018

  • ๐ŸŽ“ Scheme = nostalgia
  • ๐Ÿ‘ฉโ€๐Ÿซ Practiced old techniques
  • ๐ŸŒ Not the fastest language
  • ๐Ÿฅณ Fun and accomplished feeling

7/10 would recommend

๐Ÿฅˆ
Second time participating:
TypeScript

Language for 2020: TypeScript


const fib = (n: number): number => {
  if (n < 1)
    return 0;
  if (n < 2)
    return 1;
  return fib(n - 2) + fib(n - 1);
};
  • ๐Ÿญ Microsoft
  • ๐Ÿง‚ JavaScript + types
  • โš™๏ธ Compiled
  • ๐Ÿ— Web development

2020: TypeScript

  • ๐ŸŽ Daily driver
  • ๐Ÿง˜โ€โ™€๏ธ Less harsh on myself
  • ๐Ÿคฉ 50 stars

https://github.com/ElkeCodes/AdventOfCode2020

Retro on 2020

  • ๐Ÿ’ช TypeScript = confidence
  • ๐Ÿ“š So much documentation
  • ๐Ÿ™‡โ€โ™€๏ธ Learned new things about the language
  • ๐Ÿฅณ Easier than 2018 and more fun

10/10 would definitely recommend

๐Ÿฅ‰
Third time participating:
Rust

Language for 2021: Rust


pub fn fib(n: i32) -> u64 {
  if n < 0 {
    panic!("{} is negative!", n);
  }
  match n {
    0     => panic!("zero is not a valid argument to fib()!"),
    1 | 2 => 1,
    3     => 2,
    _     => fib(n - 1) + fib(n - 2)
  }
}
              
  • ๐Ÿญ Mozilla
  • ๐Ÿ‘ทโ€โ™€๏ธ Memory safe
  • โš™๏ธ Compiled
  • ๐Ÿš€ Popular

2021: Rust

  • ๐Ÿฃ Never written a single line of Rust before
  • ๐Ÿ“– Bought a book
  • ๐Ÿ’โ€โ™€๏ธ Used a starter
  • ๐Ÿคฉ 36 stars

https://github.com/ElkeCodes/AdventOfCode2021

Retro on 2021

  • ๐Ÿคฏ So much to learn!
  • ๐Ÿ“– Book was a great help
  • ๐Ÿ™‡โ€โ™€๏ธ Hardest part: how to write it
  • ๐Ÿฅณ Learned a lot about Rust

9/10 hard recommend

๐Ÿ™‡โ€โ™€๏ธ
What I've learned over all the years

Programming languages

  • Refreshing = fun and interesting
  • Daily = easier
  • New = hard but feeling of accomplishment

Algorithms and data structures

  • Parsing
  • String manipulations
  • Stacks
  • Queues
  • Hashmaps
  • Linked List
  • Graphs
  • Breadth-first search
  • Depth-first search
  • Binary search
  • A*
  • Dijkstra
  • Floodfill
  • Memoization
  • Sorting
  • ...

๐ŸŽ„
Advent of Code 2022

How I'm participating

  • ๐Ÿ‘ฉโ€๐Ÿ’ป Rust
  • ๐Ÿ’†โ€โ™€๏ธ Taking my time
  • ๐Ÿ“š Book

My first day

  • ๐Ÿ‘ทโ€โ™€๏ธ I had work today
  • โฐ Woke up at 5am
  • ๐Ÿง Looked at 6am
  • โœ๏ธ Wrote at work

My first day: an evaluation

  • ๐Ÿฃ It's been almost a year
  • ๐Ÿคทโ€โ™€๏ธ Rust is confusing
  • ๐Ÿ’ช I can do this
  • ๐Ÿ˜Ž Rust is awesome

โžก It's exciting!

๐ŸŽฌ
How can you start the Advent of Code

Creating an account

Log in with:

  • Google
  • GitHub
  • Twitter
  • Reddit

Choosing a technology

  • ๐Ÿฅ… What's your goal?
  • โ˜‘๏ธ All technologies are valid!
  • ๐Ÿ’ฏ Don't limit yourself to 1
  • ๐Ÿ•ต๏ธโ€โ™€๏ธ More popular = more resources

Pick your fighter!

  • Java
  • C#
  • Scheme
  • JavaScript
  • Fortran
  • F#
  • C++
  • Rust
  • PHP
  • Erlang
  • Python
  • Progress 4GL
  • Elixir
  • Kotlin
  • Go
  • Ruby
  • D
  • Haskell
  • Clojure
  • Swift
  • C
  • Scala
  • Assembly
  • R
  • Bash
  • Perl
  • COBOL
  • VBA

And so many more options...!

Top 15 languages in 2018

Or just go weird....

Use a starter template

https://github.com/Bogdanp/awesome-advent-of-code

Add dayXX.rs and start coding!

When should you enter?

  • ๐Ÿ’†โ€โ™€๏ธ Whenever you want!
  • โฐ It's ok to start later

Getting help

  • ๐Ÿ’ป Wikipedia
  • ๐ŸŒ /r/AdventOfCode
  • ๐Ÿฆ Twitter
  • ๐Ÿ—ฃ The women.code(be) discord!

Share notes

Do I have to complete it?

๐Ÿ’ญ
Things to remember

  • ๐Ÿ˜ฐ Don't put time pressure on you
  • ๐Ÿ‘Œ Every technology is valid
  • ๐Ÿ™‹ Ask for help
  • ๐Ÿ”จ Break it into smaller problems
  • โœ๏ธ Make notes and diagrams
  • ๐Ÿ“š Use libraries

๐Ÿง  You'll learn a lot!