Skip to content

Advent of Code solution for year 2023, in F# language

Notifications You must be signed in to change notification settings

kodfodrasz/advent-of-code-2023

Repository files navigation

Kodfodrasz.Advent-Of-Code-2023

Advent of code solver program logo

What is this? My solutions for the Advent of Code programming challenge in year 2023. If you would like to know more about it, you can read about it here: https://adventofcode.com/

CI workflow status

It is that time of the year again...

... maybe this year I'll be patient enough to solve all the puzzles.

Previous years

How to run it?

Compile it yourself

  1. ensure you have at least .Net SDK 8.0 installed
  2. clone the repository
  3. change directory to the cloned repository root
  4. set two environment variables:
  • AOC_DATA_DIR to a directory path where the downloaded puzzle inputs will be cached.
  • AOC_SESSION_COOKIE is needed to download the puzzle inputs if not found in the cache. You can get it from your browser using web inspector after logging in to the AoC site.
  1. dotnet run -c Release --project .\Kodfodrasz.AoC.Cli\Kodfodrasz.AoC.Cli.fsproj

Run a precompiled version

No CI releases are planned now.

Compile a single file binary

This mostly a note to self at the moment

  1. ensure you have at least .Net SDK 8.0 installed

  2. clone the repository

  3. change directory to the cloned repository root

  4. build a single file binary

    # This example is for powershell
    # You may need to change the platform identifier [RID](https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/rid-graph). 
    $target_rid="win-x64"
    dotnet publish -c Release `
      -f net8.0 -r $target_rid `
      --self-contained true `
      -p:PublishSingleFile=true `
      -p:EnableCompressionInSingleFile=true `
      -p:IncludeAllContentForSelfExtract=yes `
      .\Kodfodrasz.AoC.Cli\Kodfodrasz.AoC.Cli.fsproj
    
    $result_dir="Kodfodrasz.AoC.Cli\bin\Release\net8.0\$target_rid\publish\"
    echo "The binary is in $result_dir" 
  5. You can now run the binary on another computer, and it doesn't need to have the relevant .Net Runtime/SDK installed! The environment variables AOC_DATA_DIR and AOC_SESSION_COOKIE mentioned above will still needed to be set up on the target machine

TODO

There are lots of stuff missing from the library used to solve the puzzles.

  • CI

Missing algorithms from the library

Memoization

  • Memoization helper based on System.Runtime.Caching.MemoryCache

Array2D

  • Transpose
  • Rotate CW/CCW 90°, 180°
  • Mirror X
  • Mirror Y
  • Sequential iterator by row
  • Sequential iterator by column
  • Extend in each dimension with default value
  • Apply convolution matrix 3x3
  • Apply convolution matrix 5x5

Handy comparison combinators

  • Between (inclusive, exclusive, upper/lower inclusive)

String operations

Edit Distances:

  • Hamming distance (same length)
  • Lewenstein distance (any length)
  • Longest Common Substring

Coordinate Systems / Metrics

  • Manhattan distance
  • Chebyshev distance
  • Eucledian distance
  • Haversine formula (great-circle distance on surface of a sphere)

Graph algorithms

Shortest path

  • Dijkstra
  • Floyd-Warschal
  • Bellman-Ford (shortest path, generates all paths from one node as a byproduct)

Circle detection

  • Floyd

Topological Sorting

  • Kahn's algorithm

Lists

  • Shuffle

Sets

  • Power set
  • Cartesian product1
  • Cartesian product of single set on itself, except diagonal (Does this have a fancy name?)
  • Cartesian product single set on itself, only top triangular matrix, except diagonal (Does this have a fancy name?)

Number Theory

  • Largest Common Denominator
  • Least Common Multiple
  • Prime factorization
  • Prime sequence generation
  • Primality test
  • Coprimality test

Combinatorics

  • K-Combination
  • Power set
  • Binomial

Optimization

  • Hungarian method
  • Backtracking

Footnotes

  1. Magyarul/In Hungarian: Descartes-szorzat

About

Advent of Code solution for year 2023, in F# language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published