diff --git a/.github/workflows/update-docs.yaml b/.github/workflows/update-docs.yaml new file mode 100644 index 000000000..62acdb9ae --- /dev/null +++ b/.github/workflows/update-docs.yaml @@ -0,0 +1,53 @@ +name: Update Docs + +on: + push: + branches: + - master + +jobs: + update-docs: + runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure Git + run: | + # Configure Git + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' # Update based on your project's requirements + + - name: Build + run: | + cd docs; + npm install + cd .. + ls -la + node docs/build.js + + + - name: Checkout docs repository + uses: actions/checkout@v3 + with: + path: distr + ref: docs + + - name: Deploy docs + run: | + rsync -av --exclude='.git/' --del build/ distr/ + cd distr + git add . + git commit -m "Update docs on $(date)" + git push --force origin docs diff --git a/.gitignore b/.gitignore index 7f6661789..f96db2252 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ bin obj aoc-crypt.key +docs/node_modules +build diff --git a/.vscode/launch.json b/.vscode/launch.json index 75419e564..86b12f55e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net8.0/adventofcode.dll", + "program": "${workspaceFolder}/bin/Debug/net9.0/adventofcode.dll", "args": ["${relativeFileDirname}"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window diff --git a/2015/Day01/README.md b/2015/Day01/README.md index 8b729b0e2..e6654b029 100644 --- a/2015/Day01/README.md +++ b/2015/Day01/README.md @@ -3,4 +3,4 @@ Santa was hoping for a white Christmas, but his weather machine's "snow" functio Collect stars by helping Santa solve 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! -Read the [full puzzle](https://adventofcode.com/2015/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2015/day/1) description._ diff --git a/2015/Day01/illustration.jpeg b/2015/Day01/illustration.jpeg new file mode 100644 index 000000000..999d41141 Binary files /dev/null and b/2015/Day01/illustration.jpeg differ diff --git a/2015/Day02/illustration.jpeg b/2015/Day02/illustration.jpeg new file mode 100644 index 000000000..23432437a Binary files /dev/null and b/2015/Day02/illustration.jpeg differ diff --git a/2015/Day03/illustration.jpeg b/2015/Day03/illustration.jpeg new file mode 100644 index 000000000..60cacbd93 Binary files /dev/null and b/2015/Day03/illustration.jpeg differ diff --git a/2015/Day04/illustration.jpeg b/2015/Day04/illustration.jpeg new file mode 100644 index 000000000..243d89a1b Binary files /dev/null and b/2015/Day04/illustration.jpeg differ diff --git a/2015/Day05/illustration.jpeg b/2015/Day05/illustration.jpeg new file mode 100644 index 000000000..8ba151e3c Binary files /dev/null and b/2015/Day05/illustration.jpeg differ diff --git a/2015/Day06/illustration.jpeg b/2015/Day06/illustration.jpeg new file mode 100644 index 000000000..3b62f677b Binary files /dev/null and b/2015/Day06/illustration.jpeg differ diff --git a/2015/README.md b/2015/README.md index e642371f9..a98cc6d87 100644 --- a/2015/README.md +++ b/2015/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2015) Check out https://adventofcode.com/2015. - diff --git a/2015/SplashScreen.cs b/2015/SplashScreen.cs index 1277b4ae5..64c664e9c 100644 --- a/2015/SplashScreen.cs +++ b/2015/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2015; @@ -9,491 +8,507 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ $year = 2015\n "); - Write(0xcc00, false, "\n "); - Write(0xffff66, true, "| \n \\|/ "); - Write(0xffff66, true, "\n --*-- "); - Write(0xcccccc, true, "25 "); - Write(0xffff66, true, "**\n "); - Write(0x9900, false, " >"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "24 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<< "); - Write(0xcccccc, false, "23 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "22 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<< "); - Write(0xcccccc, false, "21 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, "20 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "19 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<< "); - Write(0xcccccc, false, "18 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "17 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "16 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, "15 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "14 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<< "); - Write(0xcccccc, false, "13 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<< "); - Write(0xcccccc, false, "12 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, "11 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, "10 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, " 9 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, " 8 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, " 7 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<< "); - Write(0xcccccc, false, " 6 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<< "); - Write(0xcccccc, false, " 5 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, " 4 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<< "); - Write(0xcccccc, false, " 3 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, " >>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<< "); - Write(0xcccccc, false, " 2 "); - Write(0xffff66, false, "**\n "); - Write(0x9900, false, ">>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>>"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<<"); - Write(0xff9900, true, "o"); - Write(0x9900, false, ">>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, ">>>"); - Write(0xffff66, true, "*"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">>>"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<<<< "); - Write(0xcccccc, false, " 1 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, " | | \n | | "); - Write(0xcccccc, false, " \n _ _ __ ___|___|___ __ _ _ \n "); - Write(0xcccccc, false, " \n"); - + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ {:year 2015}\n "); + Write(0xcc00, false, "\n "); + Write(0xffff66, true, "| \n \\|/ "); + Write(0xffff66, true, "\n --*-- "); + Write(0xcccccc, true, "25 "); + Write(0xffff66, true, "**\n "); + Write(0x9900, false, " >"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "24 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "23 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "22 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "21 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<< "); + Write(0xcccccc, false, "20 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<<< "); + Write(0xcccccc, false, "19 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "18 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "17 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "16 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<< "); + Write(0xcccccc, false, "15 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "14 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "13 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "12 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, "11 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, "10 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, " 9 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, " 8 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, " 7 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, " 6 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, " 5 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<<< "); + Write(0xcccccc, false, " 4 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, " 3 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, " >>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, " 2 "); + Write(0xffff66, false, "**\n "); + Write(0x9900, false, ">>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">>"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, ">>"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<< "); + Write(0xcccccc, false, " 1 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, " | | \n | | "); + Write(0xcccccc, false, " \n _ _ __ ___|___|___ __ _ _ \n "); + Write(0xcccccc, false, " \n"); + Console.ForegroundColor = color; Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2015/calendar.svg b/2015/calendar.svg index 433f90f6f..40356baaa 100644 --- a/2015/calendar.svg +++ b/2015/calendar.svg @@ -1,51 +1,51 @@ - - + + ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ █▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ -█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  $year = 2015 +█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  {:year 2015}                           |                                                       \|/                               -                      --*--                        25 ** -                       >o<                         24 ** -                      >O<<<                        23 ** -                     >>*<<O<                       22 ** -                    >>@<o<<<<                      21 ** -                   >*>>o>@>*<<                     20 ** -                  >>o>o<O<o<<@<                    19 ** -                 >>o>O<O>@<<*<<<                   18 ** -                >o<O<O>>o<@<<O<*<                  17 ** -               >O>>*<@<o>@>>>O<<O<                 16 ** -              >>O>>>@>>*>>o>>>@<O<<                15 ** -             >>o>>o>o>o<<<o>*<<<@>*<               14 ** -            >>O<<<o<o>>O<@<<o>>>*<<<<              13 ** -           >>o>o>>@<<O>>*<<@<O>>>@<<<<             12 ** -          >>o>@>*>>*>>>o<<<O>>>o<o>>>O<            11 ** -         >O<<*>*>>@<<<*>>o<*<<<*<o>>>O<<           10 ** -        >>O>o<*>O<@>>o<*>>>@>>>@<<<*>>@<<           9 ** -       >@>>o<<o>>*>o<o<<O>>*<<<O<o>>>o<o<<          8 ** -      >>*>>*<<O>>>@<o<O>>>@<<<O<@>>O>>O>>o<         7 ** -     >>o>*>>>*<*>*<<<@<<<*>>>o<<*>>@>o>>@<<<        6 ** -    >>o>>>@<<<o>>O<<<*<<*>>o>O>>o>o>>O<<<O<<<       5 ** -   >@<*>@>@>o<<*>@<*<<O<<<*<<o<<<O>o<<<*<<<o<<      4 ** -  >@<<<*<<o>>>*>>>*>>>o<<<*<<o>o>>*<<o<<@>>O<<<     3 ** - >>@<*>>*>@<o>>>@>>>*<o<<<o<<O<<<@>>O<<<@>>O<O<<    2 ** ->>@<o<<<*<*>>o>@>o<<<o>>>@>>*<<o>>*>>>*<@>>>O<<<<   1 ** +                      --*--                        25 ** +                       >o<                         24 ** +                      >>O<<                        23 ** +                     >o>>>@<                       22 ** +                    >@<<*<O<<                      21 ** +                   >>o>>O>@<<<                     20 ** +                  >o>o>O>>@<<<<                    19 ** +                 >>o<<<O<o>*<*<<                   18 ** +                >@>>>o>>>@>o<<O<<                  17 ** +               >>*>>O>@>>>*<<<o>O<                 16 ** +              >>@>>o>*>>>@<<<O<O<<<                15 ** +             >>@<<o<<<@>>*<<@>@>@>O<               14 ** +            >*<<O>>>*<<*<@<O<<<O<<O<<              13 ** +           >@>>>o>>>@<o>>@<<O>>>O<<<o<             12 ** +          >o>O<@<<<o<*>@<<O<<<O>>>*>O<<            11 ** +         >@>*>>>o>>@<O>o>@<O>>>@>*>o<<O<           10 ** +        >>@>>>*>>o<O>>>o>o>>o>O<<<*<<<O<<           9 ** +       >>@<o>>O>O<*<<O>O>>*<*<o<<<*>*<o>o<          8 ** +      >>O<O<o<<o>>@>>o<<*<<<o>>>O<o<<o>*<@<         7 ** +     >>@<o>>>O>O<o>>O<<<*<o<<o<<*<<O<<@>>>o<        6 ** +    >>@>>>O>@>*<<<o>*>o<o>>@<<<@<<*>>@<O<<*<<       5 ** +   >>O<<O<<<*<*<<<*<<O<<@<<o>>*>>@<O<<o<<@<<<<      4 ** +  >@<<O<@>>O>>>*<<o>>>*>@<<O>O>*<O>>>O>>o>>>@<<     3 ** + >>@<@>o<<o<<<o>>>O<@<<*>*>>>*<@<@>>>*<*>O<@>>O<    2 ** +>>*>>@>*<<<*<<@>>O<*<<*<<*>>>o>>>@<<O<*<*>>*<<o<<   1 **                       |   |                                                    |   |                              -           _  _ __ ___|___|___ __ _  _                   +           _  _ __ ___|___|___ __ _  _                   - \ No newline at end of file + \ No newline at end of file diff --git a/2016/Day01/README.md b/2016/Day01/README.md index 2478c94c2..4c302f2ce 100644 --- a/2016/Day01/README.md +++ b/2016/Day01/README.md @@ -3,4 +3,4 @@ Santa's sleigh uses a very high-precision clock to guide its movements, and the 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! -Read the [full puzzle](https://adventofcode.com/2016/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2016/day/1) description._ diff --git a/2016/README.md b/2016/README.md index 8212cc07f..d3ef6bd90 100644 --- a/2016/README.md +++ b/2016/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2016) Check out https://adventofcode.com/2016. - diff --git a/2016/SplashScreen.cs b/2016/SplashScreen.cs index 33cb596bf..04fac5852 100644 --- a/2016/SplashScreen.cs +++ b/2016/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2016; @@ -9,258 +8,258 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ // 2016\n \n "); - Write(0xcc00, false, " "); - Write(0xffff66, true, "( ( ( ( ((*)) ) ) ) ) \n "); - Write(0x666666, false, " | \n +-|---+ "); - Write(0x666666, false, " \n / | /| \n "); - Write(0x666666, false, " +-----+ | \n |"); - Write(0x333333, false, "::"); - Write(0xffff66, true, ":"); - Write(0x333333, false, "::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "25 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " +----+ |"); - Write(0x333333, false, "::"); - Write(0x9900, true, ":"); - Write(0x333333, false, "::"); - Write(0x666666, false, "| |---+ +-----------+ "); - Write(0xcccccc, false, "24 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " / / \\ |"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":::"); - Write(0x333333, false, ":"); - Write(0x666666, false, "| | /| / \\\\\\\\\\\\ [] /| "); - Write(0xcccccc, false, "23 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " / / / \\|"); - Write(0x9900, true, ":::::"); - Write(0x666666, false, "| | / | / \\\\\\\\\\\\ [] / | "); - Write(0xcccccc, false, "22 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " / / / / \\"); - Write(0x333333, false, "::"); - Write(0x553322, true, ":"); - Write(0x333333, false, "::"); - Write(0x666666, false, "|/ / | +-----------+ | "); - Write(0xcccccc, false, "21 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " +----+ / / / \\------+ ------|"); - Write(0x333333, false, "::::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "20 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |-----\\ / / / \\=====| ------|"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "19 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |------\\ / / / \\====| | |"); - Write(0x66ff, true, ":::"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":::"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "18 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |-------\\ / / / +===| | |"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "17 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |--------\\ / / /|===| | |"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "16 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |---------\\ / / |===| | /|"); - Write(0x66ff, true, ":::"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":::"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":::"); - Write(0x666666, false, "| | "); - Write(0xcccccc, false, "15 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |----------\\ / |===| / //|"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":"); - Write(0x666666, false, "| / "); - Write(0xcccccc, false, "14 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " +-----------+ |===| / //||"); - Write(0x333333, false, "::::"); - Write(0x66ff, true, ":"); - Write(0x333333, false, ":"); - Write(0x66ff, true, ":"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "|/ "); - Write(0xcccccc, false, "13 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, "::::::::"); - Write(0x666666, false, "| |===|/__//___________________ "); - Write(0xcccccc, false, "12 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0xff0000, true, ":::"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":::"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "| |______//|_____...._________ "); - Write(0xcccccc, false, "11 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "| | //| ____/ /_/___ "); - Write(0xcccccc, false, "10 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ---|"); - Write(0x333333, false, "::::"); - Write(0x9900, true, ":::"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "| |--------|[][]|_|[][]_\\------ "); - Write(0xcccccc, false, " 9 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "----|"); - Write(0x333333, false, "::"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, "::::::"); - Write(0x666666, false, "| |--------------------------- "); - Write(0xcccccc, false, " 8 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " || |"); - Write(0x333333, false, "::"); - Write(0xff0000, true, ":::"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":::"); - Write(0x333333, false, "::"); - Write(0x666666, false, "| | //| || / / / || || "); - Write(0xcccccc, false, " 7 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " || |"); - Write(0x333333, false, "::"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x333333, false, "::"); - Write(0x666666, false, "| | //| || / / || "); - Write(0xffff66, true, "*"); - Write(0x666666, false, " || "); - Write(0xcccccc, false, " 6 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0x333333, false, "::::::"); - Write(0x9900, true, ":::"); - Write(0x333333, false, "::"); - Write(0x666666, false, "| |//| / / / "); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "< "); - Write(0xcccccc, false, " 5 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0x333333, false, "::::"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, "::::"); - Write(0x666666, false, "| //| / / ___"); - Write(0x9900, false, ">"); - Write(0xff0000, true, "@"); - Write(0x9900, false, ">"); - Write(0x66ff, true, "O"); - Write(0x9900, false, "<"); - Write(0x666666, false, "____ "); - Write(0xcccccc, false, " 4 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0x333333, false, "::::"); - Write(0xff0000, true, ":::"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":::"); - Write(0x666666, false, "| //| / / / / "); - Write(0x9900, false, ">"); - Write(0x66ff, true, "O"); - Write(0x9900, false, ">"); - Write(0xff9900, true, "o"); - Write(0x9900, false, "<"); - Write(0xff0000, true, "@"); - Write(0x9900, false, "<"); - Write(0x666666, false, " / "); - Write(0xcccccc, false, " 3 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0x333333, false, "::::"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0xff0000, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x333333, false, ":"); - Write(0x9900, true, ":"); - Write(0x666666, false, "| //| / / / "); - Write(0xaaaaaa, false, "_| |_"); - Write(0x666666, false, " / "); - Write(0xcccccc, false, " 2 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " |"); - Write(0x333333, false, "::::::::"); - Write(0x9900, true, ":::"); - Write(0x666666, false, "|//| / / / /___________/ "); - Write(0xcccccc, false, " 1 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ==============//======+...+==================== \n - - - - - - -// - - -/ / - -"); - Write(0x666666, false, " - - - - - - - - \n ==============//|============================== \n "); - Write(0x666666, false, " //| \n \n"); - + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ // 2016\n \n "); + Write(0xcc00, false, " "); + Write(0xffff66, true, "( ( ( ( ((*)) ) ) ) ) \n "); + Write(0x666666, false, " | \n +-|---+ "); + Write(0x666666, false, " \n / | /| \n "); + Write(0x666666, false, " +-----+ | \n |"); + Write(0x333333, false, "::"); + Write(0xffff66, true, ":"); + Write(0x333333, false, "::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "25 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " +----+ |"); + Write(0x333333, false, "::"); + Write(0x9900, true, ":"); + Write(0x333333, false, "::"); + Write(0x666666, false, "| |---+ +-----------+ "); + Write(0xcccccc, false, "24 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " / / \\ |"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":::"); + Write(0x333333, false, ":"); + Write(0x666666, false, "| | /| / \\\\\\\\\\\\ [] /| "); + Write(0xcccccc, false, "23 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " / / / \\|"); + Write(0x9900, true, ":::::"); + Write(0x666666, false, "| | / | / \\\\\\\\\\\\ [] / | "); + Write(0xcccccc, false, "22 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " / / / / \\"); + Write(0x333333, false, "::"); + Write(0x553322, true, ":"); + Write(0x333333, false, "::"); + Write(0x666666, false, "|/ / | +-----------+ | "); + Write(0xcccccc, false, "21 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " +----+ / / / \\------+ ------|"); + Write(0x333333, false, "::::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "20 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |-----\\ / / / \\=====| ------|"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "19 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |------\\ / / / \\====| | |"); + Write(0x66ff, true, ":::"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":::"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "18 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |-------\\ / / / +===| | |"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "17 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |--------\\ / / /|===| | |"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "16 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |---------\\ / / |===| | /|"); + Write(0x66ff, true, ":::"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":::"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":::"); + Write(0x666666, false, "| | "); + Write(0xcccccc, false, "15 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |----------\\ / |===| / //|"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":"); + Write(0x666666, false, "| / "); + Write(0xcccccc, false, "14 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " +-----------+ |===| / //||"); + Write(0x333333, false, "::::"); + Write(0x66ff, true, ":"); + Write(0x333333, false, ":"); + Write(0x66ff, true, ":"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "|/ "); + Write(0xcccccc, false, "13 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, "::::::::"); + Write(0x666666, false, "| |===|/__//___________________ "); + Write(0xcccccc, false, "12 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0xff0000, true, ":::"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":::"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "| |______//|_____...._________ "); + Write(0xcccccc, false, "11 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "| | //| ____/ /_/___ "); + Write(0xcccccc, false, "10 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ---|"); + Write(0x333333, false, "::::"); + Write(0x9900, true, ":::"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "| |--------|[][]|_|[][]_\\------ "); + Write(0xcccccc, false, " 9 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "----|"); + Write(0x333333, false, "::"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, "::::::"); + Write(0x666666, false, "| |--------------------------- "); + Write(0xcccccc, false, " 8 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " || |"); + Write(0x333333, false, "::"); + Write(0xff0000, true, ":::"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":::"); + Write(0x333333, false, "::"); + Write(0x666666, false, "| | //| || / / / || || "); + Write(0xcccccc, false, " 7 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " || |"); + Write(0x333333, false, "::"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x333333, false, "::"); + Write(0x666666, false, "| | //| || / / || "); + Write(0xffff66, true, "*"); + Write(0x666666, false, " || "); + Write(0xcccccc, false, " 6 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0x333333, false, "::::::"); + Write(0x9900, true, ":::"); + Write(0x333333, false, "::"); + Write(0x666666, false, "| |//| / / / "); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0xcccccc, false, " 5 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0x333333, false, "::::"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, "::::"); + Write(0x666666, false, "| //| / / ___"); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "<"); + Write(0x666666, false, "____ "); + Write(0xcccccc, false, " 4 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0x333333, false, "::::"); + Write(0xff0000, true, ":::"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":::"); + Write(0x666666, false, "| //| / / / / "); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0x666666, false, " / "); + Write(0xcccccc, false, " 3 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0x333333, false, "::::"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0xff0000, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x333333, false, ":"); + Write(0x9900, true, ":"); + Write(0x666666, false, "| //| / / / "); + Write(0xaaaaaa, false, "_| |_"); + Write(0x666666, false, " / "); + Write(0xcccccc, false, " 2 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " |"); + Write(0x333333, false, "::::::::"); + Write(0x9900, true, ":::"); + Write(0x666666, false, "|//| / / / /___________/ "); + Write(0xcccccc, false, " 1 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ==============//======+...+==================== \n - - - - - - -// - - -/ / - -"); + Write(0x666666, false, " - - - - - - - - \n ==============//|============================== \n "); + Write(0x666666, false, " //| \n \n"); + Console.ForegroundColor = color; Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2016/calendar.svg b/2016/calendar.svg index cf103d895..001a5323e 100644 --- a/2016/calendar.svg +++ b/2016/calendar.svg @@ -1,15 +1,15 @@ - - + + ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ █▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ @@ -20,36 +20,36 @@                   +-|---+                                                 /  |  /|                                                +-----+ |                                -                |:::::| |                          25 ** -        +----+  |:::::| |---+      +-----------+   24 ** -       /    / \ |:::::| |  /|     / \\\\\\ [] /|   23 ** -      /    / / \|:::::| | / |    / \\\\\\ [] / |   22 ** -     /    / / / \:::::|/ /  |   +-----------+  |   21 ** -    +----+ / / / \------+ ------|:::::::::::|  |   20 ** -    |-----\ / / / \=====| ------|:::::::::::|  |   19 ** -    |------\ / / / \====|   |   |:::::::::::|  |   18 ** -    |-------\ / / / +===|   |   |:::::::::::|  |   17 ** -    |--------\ / / /|===|   |   |:::::::::::|  |   16 ** -    |---------\ / / |===|   |  /|:::::::::::|  |   15 ** -    |----------\ /  |===|  /  //|:::::::::::| /    14 ** -    +-----------+   |===| /  //||:::::::::::|/     13 ** -    |:::::::::::|   |===|/__//___________________  12 ** -    |:::::::::::|   |______//|_____...._________   11 ** -    |:::::::::::|   |     //| ____/ /_/___         10 ** - ---|:::::::::::|   |--------|[][]|_|[][]_\------   9 ** -----|:::::::::::|   |---------------------------    8 ** - || |:::::::::::|   |  //| ||  / / / ||      ||     7 ** - || |:::::::::::|   | //|  || /   /  ||  *   ||     6 ** -    |:::::::::::|   |//|     / / /      >o<         5 ** -    |:::::::::::|   //|     /   /   ___>@>O<____    4 ** -    |:::::::::::|  //|     / / /   /  >O>o<@<  /    3 ** -    |:::::::::::| //|     /   /   /    _| |_  /     2 ** -    |:::::::::::|//|     / / /   /___________/      1 ** +                |:::::| |                          25 ** +        +----+  |:::::| |---+      +-----------+   24 ** +       /    / \ |:::::| |  /|     / \\\\\\ [] /|   23 ** +      /    / / \|:::::| | / |    / \\\\\\ [] / |   22 ** +     /    / / / \:::::|/ /  |   +-----------+  |   21 ** +    +----+ / / / \------+ ------|:::::::::::|  |   20 ** +    |-----\ / / / \=====| ------|:::::::::::|  |   19 ** +    |------\ / / / \====|   |   |:::::::::::|  |   18 ** +    |-------\ / / / +===|   |   |:::::::::::|  |   17 ** +    |--------\ / / /|===|   |   |:::::::::::|  |   16 ** +    |---------\ / / |===|   |  /|:::::::::::|  |   15 ** +    |----------\ /  |===|  /  //|:::::::::::| /    14 ** +    +-----------+   |===| /  //||:::::::::::|/     13 ** +    |:::::::::::|   |===|/__//___________________  12 ** +    |:::::::::::|   |______//|_____...._________   11 ** +    |:::::::::::|   |     //| ____/ /_/___         10 ** + ---|:::::::::::|   |--------|[][]|_|[][]_\------   9 ** +----|:::::::::::|   |---------------------------    8 ** + || |:::::::::::|   |  //| ||  / / / ||      ||     7 ** + || |:::::::::::|   | //|  || /   /  ||  *   ||     6 ** +    |:::::::::::|   |//|     / / /      >o<         5 ** +    |:::::::::::|   //|     /   /   ___>@>O<____    4 ** +    |:::::::::::|  //|     / / /   /  >O>o<@<  /    3 ** +    |:::::::::::| //|     /   /   /    _| |_  /     2 ** +    |:::::::::::|//|     / / /   /___________/      1 **   ==============//======+...+====================          - - - - - - -// - - -/   / - - - - - - - - - -         ==============//|==============================          -             //|                                         +             //|                                         - \ No newline at end of file + \ No newline at end of file diff --git a/2017/Day01/README.md b/2017/Day01/README.md index e03493275..ceb540a18 100644 --- a/2017/Day01/README.md +++ b/2017/Day01/README.md @@ -3,4 +3,4 @@ The night before Christmas, one of Santa's Elves calls you in a panic. "The prin When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th. -Read the [full puzzle](https://adventofcode.com/2017/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2017/day/1) description._ diff --git a/2017/README.md b/2017/README.md index 0d7fa30de..33861dcbc 100644 --- a/2017/README.md +++ b/2017/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2017) Check out https://adventofcode.com/2017. - diff --git a/2017/SplashScreen.cs b/2017/SplashScreen.cs index 1ee0b2d44..fb4ba3fb2 100644 --- a/2017/SplashScreen.cs +++ b/2017/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2017; @@ -9,209 +8,210 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ 0x0000 | 2017\n "); - Write(0xcc00, false, " \n "); - Write(0x999999, false, "|O| "); - Write(0xcccccc, false, " Naughty | Nice "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "-------------------+------------------- "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "The Easter Bunny | encse "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "lizthegrey | Kevin Yap "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "Mihai Maruseac | Jean-Noël Monette "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "jweinberg | Joe LeGasse "); - Write(0x999999, false, "|O| \n |O| "); - Write(0xcccccc, false, "zenithlight | Christopher Lorton "); - Write(0x999999, false, "|O| \n "); - Write(0xcccccc, false, ".-----------------------------------------------. \n | "); - Write(0x666666, false, "o──────┬───────"); - Write(0xaaaaaa, false, "[─]"); - Write(0x666666, false, "──────┐┌┬──o┌─────────"); - Write(0x9900, false, "oTo"); - Write(0x666666, false, "─"); - Write(0xffff66, true, "* "); - Write(0xcccccc, false, "| 25 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "┌──────┘┌─────────┬────o││└───┘o┐"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "────"); - Write(0x9900, false, "oTo"); - Write(0x666666, false, "───┘ "); - Write(0xcccccc, false, "| 24 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "├─────┐o┴────────┐└─────┘│o──┬──┘└───"); - Write(0xff0000, false, "┤|├"); - Write(0x666666, false, "────"); - Write(0xffff66, true, "* "); - Write(0xcccccc, false, "| 23 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└────o└────────┐o┴──────o└┐┌─┘"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "─────────────┘ "); - Write(0xcccccc, false, "| 22 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "┌───────────"); - Write(0x66ff, false, "|("); - Write(0x666666, false, "─┘┌─────────┘└─┐└────"); - Write(0x66ff, false, "|("); - Write(0x666666, false, "───────"); - Write(0xffff66, true, "* "); - Write(0xcccccc, false, "| 21 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "├───────────"); - Write(0x990099, false, "┤[]├"); - Write(0x666666, false, "┴────────────┴───o"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "───"); - Write(0x66ff, false, "|("); - Write(0x666666, false, "────┤ "); - Write(0xcccccc, false, "| 20 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└───────┬┴┴┴┬o"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "──────────"); - Write(0xff0000, false, "┤|├"); - Write(0x666666, false, "──────┘┌───┬───o│ "); - Write(0xcccccc, false, "| 19 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0xffff66, true, "*"); - Write(0x666666, false, "───────┤ ├┐└─────"); - Write(0x66ff, false, "|("); - Write(0x666666, false, "─────────┐┌──┘o─┐└────┘ "); - Write(0xcccccc, false, "| 18 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└──────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "┤ ├└───┐┌──"); - Write(0xff9900, false, "∧∧∧"); - Write(0x666666, false, "─"); - Write(0xff0000, false, "┤|├"); - Write(0x666666, false, "───┘└─────┴┐o───┐ "); - Write(0xcccccc, false, "| 17 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "┌─"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "────┘┤ ├───┬┘├┴┴┴┴┬──"); - Write(0xaaaaaa, false, "[─]"); - Write(0x666666, false, "────┐┌───o└─┐┌─┘ "); - Write(0xcccccc, false, "| 16 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└o└─────┴┬┬┬┴──"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "└─┤ ├─┬┴┴┴┴┴┬─┘└────┐┌┘└─┐ "); - Write(0xcccccc, false, "| 15 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0xffff66, true, "*"); - Write(0x666666, false, "──────────────┘┌─┤NAND├─┤ 4├─┐┌──┬─┘└───┤ "); - Write(0xcccccc, false, "| 14 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└──────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "o───────┴─┤GATE├─┤ 3├─┼┴┴┴┤┌─────┘ "); - Write(0xcccccc, false, "| 13 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0xffff66, true, "*"); - Write(0x666666, false, "──"); - Write(0xff0000, false, "┤|├"); - Write(0x666666, false, "─┘┌─────────┴┬┬┬┬┘┌┤ V0├o┤ ├└┐┌──┬o "); - Write(0xcccccc, false, "| 12 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "├──────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "└───────┬───┴o└┐└┤ R0├─┤ A├o│├─o└┐ "); - Write(0xcccccc, false, "| 11 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└─────o└───────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "└─┐┌───┴o┤ ├─┤ L├─┘=┌──┘ "); - Write(0xcccccc, false, "| 10 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0xffff66, true, "*"); - Write(0x666666, false, "────┬┴┴┴┴┬────┘┌─┘└─────┴┬┬┬┬┬┴┐┤ U├──┐└──┐ "); - Write(0xcccccc, false, "| 9 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "├────┤ ├─"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "o──┴─┐┌─────────┴─┐└┴┬┬┬┴──┘┌──┘ "); - Write(0xcccccc, false, "| 8 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└─o"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "─┤PR2A├┐└────┐=└┐o──────┬──┘o┐┌┘o────┴──┐ "); - Write(0xcccccc, false, "| 7 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "┌──┘┌┤ 03G├┴─────┘┌"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "└─────┬┐└────┤└─────────┤ "); - Write(0xcccccc, false, "| 6 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "├───┴┴┬┬┬┬┴───"); - Write(0xff9900, false, "∧∧∧"); - Write(0x666666, false, "─┘└─"); - Write(0x990099, false, "┤[]├"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "│└──┐o─┴─────────o│ "); - Write(0xcccccc, false, "| 5 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└┐o┐"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "─────────"); - Write(0xff9900, false, "∧∧∧"); - Write(0x666666, false, "────────┘└┐o┐└─────────────┘ "); - Write(0xcccccc, false, "| 4 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "o┴─┘└──────────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "┌────┬────o└─┴┐┌──────┐o────┐ "); - Write(0xcccccc, false, "| 3 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0xffff66, true, "*"); - Write(0x666666, false, "──────────────┘└───o└─┬─────┐│└─┐┌──┐└─────┤ "); - Write(0xcccccc, false, "| 2 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "| "); - Write(0x666666, false, "└───────────"); - Write(0x66ff, false, "|("); - Write(0x666666, false, "─"); - Write(0xff9900, false, "∧∧∧"); - Write(0x666666, false, "────"); - Write(0xffff66, true, "*"); - Write(0x666666, false, "└────o└┴──┘└─o└──────┘ "); - Write(0xcccccc, false, "| 1 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "'-----------------------------------------------' \n \n"); - + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ {'year': 2017}\n "); + Write(0xcc00, false, " \n "); + Write(0x999999, false, "|O| "); + Write(0xcccccc, false, " Naughty | Nice "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "-------------------+------------------- "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "The Easter Bunny | encse "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "Martin Galese | Szabolcs Sipos "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "Balázs Dankó | wesen "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "Gábor Gyebnár | Daniel Willenson "); + Write(0x999999, false, "|O| \n |O| "); + Write(0xcccccc, false, "Woodrow Hedberg | gkatai "); + Write(0x999999, false, "|O| \n "); + Write(0xcccccc, false, ".-----------------------------------------------. \n | "); + Write(0x666666, false, "┌───────────────o┌"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "───────"); + Write(0xaaaaaa, false, "[─]"); + Write(0x666666, false, "────┐o─────────┐ "); + Write(0xcccccc, false, "| 25 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└──────"); + Write(0x9900, false, "oTo"); + Write(0x666666, false, "───────┘└────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "┌o┌────┐┌┘┌─────────┤ "); + Write(0xcccccc, false, "| 24 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xffff66, true, "*"); + Write(0x666666, false, "───────────────────"); + Write(0x66ff, false, "|("); + Write(0x666666, false, "─┘├─┘┌──o└┘┌┴──────┐o─┘ "); + Write(0xcccccc, false, "| 23 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└───"); + Write(0xff0000, false, "┤|├"); + Write(0x666666, false, "───┬┴┴┴┴┬────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "┌─o│o─┴─────┴──────o└──┐ "); + Write(0xcccccc, false, "| 22 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xffff66, true, "*"); + Write(0x666666, false, "─"); + Write(0xaaaaaa, false, "[─]"); + Write(0x666666, false, "─"); + Write(0xaaaaaa, false, "[─]"); + Write(0x666666, false, "─┤ DY├────┘└──┴────"); + Write(0xff9900, false, "∧∧∧"); + Write(0x666666, false, "────────────┤ "); + Write(0xcccccc, false, "| 21 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "├─────────┤ EP├─────┐┌──"); + Write(0xff9900, false, "∧∧∧"); + Write(0x666666, false, "──"); + Write(0x990099, false, "┤[]├"); + Write(0x666666, false, "───┐┌─"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "o──┘ "); + Write(0xcccccc, false, "| 20 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└─────────┤ CT├────┬┘│V┌────┬──────o└┴o└───"); + Write(0xffff66, true, "* "); + Write(0xcccccc, false, "| 19 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌─────────┤ RR├o───┘┌┘└┴──o┌┘"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "─────┬┴┴┴┬───┘ "); + Write(0xcccccc, false, "| 18 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "├─────────┤ ├─────┘o┬────┘┌┘┌────┤ 30├───"); + Write(0xffff66, true, "* "); + Write(0xcccccc, false, "| 17 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "│o┬─┐"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "────┼┬┬┬┬┴───"); + Write(0xff9900, false, "∧∧∧"); + Write(0x666666, false, "─┘┌───┐└─┴────┤ 29├┐┌─┘ "); + Write(0xcccccc, false, "| 16 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└─┘┌┘└───"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "└┬┴┴┴┴┬───────┘o──┴──────┐┤ 83├┘└─┐ "); + Write(0xcccccc, false, "| 15 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌──┘┌───o└─┤ ├──┐┌───────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "o─────┴┤ P6├───┘ "); + Write(0xcccccc, false, "| 14 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└┬──┘┌─"); + Write(0x9900, false, "oTo"); + Write(0x666666, false, "─┤ ├─o└┘┌─────o└───────┴┬┬┬┴───"); + Write(0xffff66, true, "* "); + Write(0xcccccc, false, "| 13 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "o┘┌──┘┌────┤ v17├────┴─┐"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "──"); + Write(0xaaaaaa, false, "[─]"); + Write(0x666666, false, "─────────┐┌───┤ "); + Write(0xcccccc, false, "| 12 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌─┘┌┴┴┴┴┴┬─┴┬┬┬┬┴──"); + Write(0x66ff, false, "|("); + Write(0x666666, false, "──┘└──────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "┌─o┌───┘└─┐V│ "); + Write(0xcccccc, false, "| 11 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└──┤ ├"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "──────"); + Write(0xff9900, false, "∧∧∧"); + Write(0x666666, false, "───────────┘└──┴──────┘└┘ "); + Write(0xcccccc, false, "| 10 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌──┤ ├┘┌─────"); + Write(0xff9900, false, "∧∧∧"); + Write(0x666666, false, "───────┐┌───────────────"); + Write(0xffff66, true, "* "); + Write(0xcccccc, false, "| 9 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└──┤ 5 ├─┴─────o"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "───────┐└┴o┌─────────"); + Write(0x66ff, false, "|("); + Write(0x666666, false, "──┤ "); + Write(0xcccccc, false, "| 8 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "─┤ 1P├────────┘o──"); + Write(0x66ff, false, "|("); + Write(0x666666, false, "──┴───┘o─────┬─o┌───┘ "); + Write(0xcccccc, false, "| 7 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "│└─┤ 2B├────────────────────────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "┌─┘┌─┘o──┐ "); + Write(0xcccccc, false, "| 6 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└──┴┬┬┬┬┬┴───┐┌──o┌──────┐"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "───────┘└──┴─────┘ "); + Write(0xcccccc, false, "| 5 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "V┌───────────┘└───┴───o┌─┘└──────┐┌────────"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "o "); + Write(0xcccccc, false, "| 4 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└┴───"); + Write(0xff0000, false, "┤|├"); + Write(0x666666, false, "──────────────┐└──┬───o┌─┘└┐"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "─┐┌──┐└┐ "); + Write(0xcccccc, false, "| 3 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "┌─────────────o┌──────┴───┘"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "──┐└───┘└┐│└─┐└─┤ "); + Write(0xcccccc, false, "| 2 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x666666, false, "└──────────────┴─────o"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "────┘o─┴──────┘└──┘o─┘ "); + Write(0xcccccc, false, "| 1 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "'-----------------------------------------------' \n \n"); + Console.ForegroundColor = color; Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2017/calendar.svg b/2017/calendar.svg index 8d60d9172..8c532d567 100644 --- a/2017/calendar.svg +++ b/2017/calendar.svg @@ -1,55 +1,55 @@ - - - + + + ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ █▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ -█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  0x0000 | 2017 +█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  {'year': 2017}   -|O|        Naughty      |        Nice         |O|        -|O|  -------------------+-------------------  |O|        -|O|  The Easter Bunny   | encse               |O|        -|O|  lizthegrey         | Kevin Yap           |O|        -|O|  Mihai Maruseac     | Jean-Noël Monette   |O|        -|O|  jweinberg          | Joe LeGasse         |O|        -|O|  zenithlight        | Christopher Lorton  |O|        -.-----------------------------------------------.        -| o[]ooTo* |  25 ** -| oo*oTo |  24 ** -| oo|* |  23 ** -| ooo* |  22 ** -| |(|(* |  21 ** -| []o*|( |  20 ** -| o*|o |  19 ** -| *   |(o |  18 ** -| *   |o |  17 ** -| *   []o |  16 ** -| o*     |  15 ** -| *NAND    4 |  14 ** -| *oGATE    3 |  13 ** -| *|   V0o   o |  12 ** -| *o   R0  Aoo |  11 ** -| o*o       L= |  10 ** -| *  U |   9 ** -|     *o |   8 ** -| o*PR2A=ooo |   7 ** -|  03G* |   6 ** -| []*oo |   5 ** -| o*o |   4 ** -| o*oo |   3 ** -| *o |   2 ** -| |(*oo |   1 ** -'-----------------------------------------------'        +|O|        Naughty      |        Nice         |O|        +|O|  -------------------+-------------------  |O|        +|O|  The Easter Bunny   | encse               |O|        +|O|  Martin Galese      | Szabolcs Sipos      |O|        +|O|  Balázs Dankó       | wesen               |O|        +|O|  Gábor Gyebnár      | Daniel Willenson    |O|        +|O|  Woodrow Hedberg    | gkatai              |O|        +.-----------------------------------------------.        +| o*[]o |  25 ** +| oTo*o |  24 ** +| *|(oo |  23 ** +| |*ooo |  22 ** +| *[][]  DY |  21 ** +|   EP[]*o |  20 ** +|   CTVoo* |  19 ** +|   RRoo* |  18 ** +|     o 30* |  17 ** +| o* 29 |  16 ** +| *o 83 |  15 ** +| o    *o P6 |  14 ** +| oTo    oo* |  13 ** +| o v17*[] |  12 ** +| |(*oV |  11 ** +|      * |  10 ** +|      * |   9 ** +|    5 o*o|( |   8 ** +| *   1Po|(oo |   7 ** +|    2B*o |   6 ** +| o* |   5 ** +| Vo*o |   4 ** +| |o* |   3 ** +| o* |   2 ** +| o*oo |   1 ** +'-----------------------------------------------'        - \ No newline at end of file + \ No newline at end of file diff --git a/2018/Day01/README.md b/2018/Day01/README.md index f6c7e948e..8ccecebb9 100644 --- a/2018/Day01/README.md +++ b/2018/Day01/README.md @@ -3,4 +3,4 @@ "The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice." -Read the [full puzzle](https://adventofcode.com/2018/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2018/day/1) description._ diff --git a/2018/Day21/Solution.cs b/2018/Day21/Solution.cs index c762cecca..f7ed345ae 100644 --- a/2018/Day21/Solution.cs +++ b/2018/Day21/Solution.cs @@ -1,112 +1,65 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; -using System.Runtime.Loader; -using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; namespace AdventOfCode.Y2018.Day21; [ProblemName("Chronal Conversion")] class Solution : Solver { - public object PartOne(string input) => Run("one", input).First(); - public object PartTwo(string input) => Run("two", input).Last(); + public object PartOne(string input) => Run(input).First(); + public object PartTwo(string input) => Run(input).Last(); - IEnumerable Run(string name, string input) { - var run = Compile>(name, input, new int[]{28}); + public IEnumerable Run(string input) { + var breakpoint = 28; + var seen = new List(); - var seen = new List(); - foreach(var r in run(new int[] { 0, 0, 0, 0, 0, 0 })){ - if (seen.Contains(r[3])) { + foreach (var regs in Trace(input, breakpoint)) { + if (seen.Contains(regs[3])) { break; } - seen.Add(r[3]); - yield return r[3]; + seen.Add(regs[3]); + yield return regs[3]; } } - public Func Compile(string name, string input, int[] breakpoints) { - var code = CompileToCSharp(input, breakpoints); - var tree = SyntaxFactory.ParseSyntaxTree(code); - var systemRefLocation = typeof(object).GetTypeInfo().Assembly.Location; - var systemReference = MetadataReference.CreateFromFile(systemRefLocation); - var compilation = CSharpCompilation.Create(name) - .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)) - .AddReferences(systemReference) - .AddSyntaxTrees(tree); + public IEnumerable Trace(string input, int breakpoint) { + var lines = input.Split("\n"); + var ipReg = int.Parse(lines.First().Split(" ")[1]); + var program = lines.Skip(1).Select(Compile).ToArray(); + var regs = new long[] { 0, 0, 0, 0, 0, 0 }; - var ms = new MemoryStream(); - EmitResult compilationResult = compilation.Emit(ms); - if (compilationResult.Success) { - ms.Seek(0, SeekOrigin.Begin); - var asm = AssemblyLoadContext.Default.LoadFromStream(ms); - var m = asm.GetType("RoslynCore.Helper").GetMethod("Run"); - return (Func)Delegate.CreateDelegate(typeof(Func), null, m); - } else { - foreach (Diagnostic codeIssue in compilationResult.Diagnostics) { - string issue = $"ID: {codeIssue.Id}, Message: {codeIssue.GetMessage()}, Location: { codeIssue.Location.GetLineSpan()}, Severity: { codeIssue.Severity}"; - Console.WriteLine(issue); + while (true) { + if (regs[ipReg] == breakpoint) { + yield return regs; } - - throw new Exception(); + program[regs[ipReg]](regs); + regs[ipReg]++; } } - string CompileToCSharp(string input, int[] breakpoints) { - var ipReg = int.Parse(input.Split("\n").First().Substring("#ip ".Length)); - var srcLines = input.Split("\n").Skip(1).ToArray(); - - var compiledStatements = new StringBuilder(); - - for (var ip = 0; ip < srcLines.Length; ip++) { - var line = srcLines[ip]; - var parts = line.Split(";")[0].Trim().Split(" "); - var stm = parts.Skip(1).Select(int.Parse).ToArray(); - var compiledStm = parts[0] switch { - "addr" => $"r[{stm[2]}] = r[{stm[0]}] + r[{stm[1]}]", - "addi" => $"r[{stm[2]}] = r[{stm[0]}] + {stm[1]}", - "mulr" => $"r[{stm[2]}] = r[{stm[0]}] * r[{stm[1]}]", - "muli" => $"r[{stm[2]}] = r[{stm[0]}] * {stm[1]}", - "banr" => $"r[{stm[2]}] = r[{stm[0]}] & r[{stm[1]}]", - "bani" => $"r[{stm[2]}] = r[{stm[0]}] & {stm[1]}", - "borr" => $"r[{stm[2]}] = r[{stm[0]}] | r[{stm[1]}]", - "bori" => $"r[{stm[2]}] = r[{stm[0]}] | {stm[1]}", - "setr" => $"r[{stm[2]}] = r[{stm[0]}]", - "seti" => $"r[{stm[2]}] = {stm[0]}", - "gtir" => $"r[{stm[2]}] = {stm[0]} > r[{stm[1]}] ? 1 : 0", - "gtri" => $"r[{stm[2]}] = r[{stm[0]}] > {stm[1]} ? 1 : 0", - "gtrr" => $"r[{stm[2]}] = r[{stm[0]}] > r[{stm[1]}] ? 1 : 0", - "eqir" => $"r[{stm[2]}] = {stm[0]} == r[{stm[1]}] ? 1 : 0", - "eqri" => $"r[{stm[2]}] = r[{stm[0]}] == {stm[1]} ? 1 : 0", - "eqrr" => $"r[{stm[2]}] = r[{stm[0]}] == r[{stm[1]}] ? 1 : 0", - _ => throw new ArgumentException() - }; - var brk = breakpoints.Contains(ip) ? "yield return r;" : ""; - compiledStatements.AppendLine($"\t\tcase {ip}: {brk} {compiledStm}; r[{ipReg}]++; break;"); - } - - return $@" - using System; - using System.Collections.Generic; - namespace RoslynCore - {{ - public static class Helper - {{ - public static IEnumerable Run(int[] r) {{ - while(true) {{ - switch (r[{ipReg}]) {{ - {compiledStatements.ToString()} - }} - }} - }} - }} - }} - "; + Action Compile(string line) { + var parts = line.Split(" "); + var op = parts[0]; + var args = parts.Skip(1).Select(long.Parse).ToArray(); + return op switch { + "addr" => regs => regs[args[2]] = regs[args[0]] + regs[args[1]], + "addi" => regs => regs[args[2]] = regs[args[0]] + args[1], + "mulr" => regs => regs[args[2]] = regs[args[0]] * regs[args[1]], + "muli" => regs => regs[args[2]] = regs[args[0]] * args[1], + "banr" => regs => regs[args[2]] = regs[args[0]] & regs[args[1]], + "bani" => regs => regs[args[2]] = regs[args[0]] & args[1], + "borr" => regs => regs[args[2]] = regs[args[0]] | regs[args[1]], + "bori" => regs => regs[args[2]] = regs[args[0]] | args[1], + "setr" => regs => regs[args[2]] = regs[args[0]], + "seti" => regs => regs[args[2]] = args[0], + "gtir" => regs => regs[args[2]] = args[0] > regs[args[1]] ? 1 : 0, + "gtri" => regs => regs[args[2]] = regs[args[0]] > args[1] ? 1 : 0, + "gtrr" => regs => regs[args[2]] = regs[args[0]] > regs[args[1]] ? 1 : 0, + "eqir" => regs => regs[args[2]] = args[0] == regs[args[1]] ? 1 : 0, + "eqri" => regs => regs[args[2]] = regs[args[0]] == args[1] ? 1 : 0, + "eqrr" => regs => regs[args[2]] = regs[args[0]] == regs[args[1]] ? 1 : 0, + _ => throw new ArgumentException() + }; } - } diff --git a/2018/README.md b/2018/README.md index ad9b93160..1d7ec08e1 100644 --- a/2018/README.md +++ b/2018/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2018) Check out https://adventofcode.com/2018. - diff --git a/2018/SplashScreen.cs b/2018/SplashScreen.cs index 144ab8e5d..56bcdf187 100644 --- a/2018/SplashScreen.cs +++ b/2018/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2018; @@ -9,163 +8,163 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ $year = 2018\n "); - Write(0xcc00, false, "\n "); - Write(0xcccccc, false, ". . . . . 25 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". . . . "); - Write(0x886655, false, "\\ / "); - Write(0xcccccc, false, ". 24 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". . "); - Write(0x886655, false, "\\_\\_\\|_/__/ "); - Write(0xcccccc, false, "23 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". . . "); - Write(0xff0000, true, "o"); - Write(0x886655, false, "-_/"); - Write(0xcccccc, false, ".()"); - Write(0x886655, false, "__------- "); - Write(0xcccccc, false, "22 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". . "); - Write(0xffff66, true, "* "); - Write(0x886655, false, "\\____ "); - Write(0xcccccc, false, "21 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". "); - Write(0xff0000, false, "|"); - Write(0xcccccc, false, "\\| \\_"); - Write(0x886655, false, "\\_ "); - Write(0xcccccc, false, "___ / 20 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". |"); - Write(0xff0000, false, "\\| "); - Write(0x886655, false, "/ | || "); - Write(0xcccccc, false, "19 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ". "); - Write(0x66ff, false, "_________"); - Write(0xff0000, false, "|"); - Write(0xcccccc, false, "\\|"); - Write(0x66ff, false, "_________ "); - Write(0x886655, false, "/ | || "); - Write(0xcccccc, false, "18 "); - Write(0xffff66, false, "**\n "); - Write(0x66ff, false, "___----- "); - Write(0xcccccc, false, "########### ##### "); - Write(0x66ff, false, "-----___ "); - Write(0xcccccc, false, "17 "); - Write(0xffff66, false, "**\n "); - Write(0x66ff, false, "___--- "); - Write(0xcccccc, false, "### ##### ######### ##### "); - Write(0x66ff, false, "---___ "); - Write(0xcccccc, false, "16 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, ") )) ) ) __"); - Write(0xff0000, false, "__ "); - Write(0xcccccc, false, "15 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, ".-"); - Write(0xcccccc, false, "("); - Write(0xff0000, false, "-"); - Write(0xcccccc, false, "(("); - Write(0xff0000, false, "-. "); - Write(0x9900, false, ".--"); - Write(0xcccccc, false, "("); - Write(0x9900, false, "-"); - Write(0xcccccc, false, "("); - Write(0x9900, false, "-. "); - Write(0xff0000, false, "/ "); - Write(0xcccccc, false, "_"); - Write(0xff0000, false, "\\ "); - Write(0xcccccc, false, "\\ 14 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "'------'_ "); - Write(0x9900, false, "'------'_ "); - Write(0xff0000, false, "|"); - Write(0xcccccc, false, "/| |/"); - Write(0xff0000, false, "| "); - Write(0xcccccc, false, "13 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "| | ) "); - Write(0x9900, false, "| | ) "); - Write(0xcccccc, false, "|_| "); - Write(0xff0000, false, "|/"); - Write(0xcccccc, false, "| 12 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "| |/ "); - Write(0x9900, false, "| |/ "); - Write(0xcccccc, false, "|/"); - Write(0xff0000, false, "| "); - Write(0xcccccc, false, "11 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "'------' "); - Write(0x9900, false, "'------' "); - Write(0xff0000, false, "|/"); - Write(0xcccccc, false, "| 10 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "_ __ "); - Write(0xcccccc, false, "|/"); - Write(0xff0000, false, "| "); - Write(0xcccccc, false, " 9 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, ".---_ _ "); - Write(0x880000, false, "| "); - Write(0xff0000, false, "|\\__"); - Write(0x880000, false, "/"); - Write(0xff0000, false, "_/) |/"); - Write(0xcccccc, false, "| 8 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "/ "); - Write(0x880000, false, "/ "); - Write(0xff0000, false, "/\\| "); - Write(0x999999, false, "__ "); - Write(0x880000, false, ") "); - Write(0xff0000, false, ")__ "); - Write(0x880000, false, "_|"); - Write(0xff0000, false, "_| / "); - Write(0xcccccc, false, "|/"); - Write(0xff0000, false, "| "); - Write(0xcccccc, false, " 7 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "/ "); - Write(0x880000, false, "/ | "); - Write(0xff0000, false, "\\ "); - Write(0xffff66, true, "* "); - Write(0x999999, false, "/ / \\ "); - Write(0x880000, false, "( "); - Write(0xff0000, false, "( \\_"); - Write(0x880000, false, "/"); - Write(0xff0000, false, "_/ / |/"); - Write(0xcccccc, false, "| 6 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "/ "); - Write(0x880000, false, "/ \\ "); - Write(0xff0000, false, "\\ "); - Write(0x999999, false, "| | \\/ "); - Write(0x880000, false, "\\_"); - Write(0xff0000, false, "\\____________/ "); - Write(0xcccccc, false, "|_| 5 "); - Write(0xffff66, false, "**\n "); - Write(0xff0000, false, "/ "); - Write(0x880000, false, "/ / \\ "); - Write(0xff0000, false, "\\ "); - Write(0x999999, false, "\\_\\______X_____X_____X_, "); - Write(0xcccccc, false, " 4 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "./~~~~~~~~~~~\\. 3 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "( .\",^. -\". '.~ ) 2 "); - Write(0xffff66, false, "**\n "); - Write(0xcccccc, false, "_'~~~~~~~~~~~~~'_________ ___ __ _ _ _ _ 1 "); - Write(0xffff66, false, "**\n \n"); - + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ 0x0000 | 2018\n "); + Write(0xcc00, false, " \n "); + Write(0xcccccc, false, ". . . . . 25 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". . . . "); + Write(0x886655, false, "\\ / "); + Write(0xcccccc, false, ". 24 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". . "); + Write(0x886655, false, "\\_\\_\\|_/__/ "); + Write(0xcccccc, false, "23 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". . . "); + Write(0xff0000, true, "o"); + Write(0x886655, false, "-_/"); + Write(0xcccccc, false, ".()"); + Write(0x886655, false, "__------- "); + Write(0xcccccc, false, "22 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". . "); + Write(0xffff66, true, "* "); + Write(0x886655, false, "\\____ "); + Write(0xcccccc, false, "21 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". "); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "\\| \\_"); + Write(0x886655, false, "\\_ "); + Write(0xcccccc, false, "___ / 20 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". |"); + Write(0xff0000, false, "\\| "); + Write(0x886655, false, "/ | || "); + Write(0xcccccc, false, "19 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ". "); + Write(0x66ff, false, "_________"); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "\\|"); + Write(0x66ff, false, "_________ "); + Write(0x886655, false, "/ | || "); + Write(0xcccccc, false, "18 "); + Write(0xffff66, false, "**\n "); + Write(0x66ff, false, "___----- "); + Write(0xcccccc, false, "########### ##### "); + Write(0x66ff, false, "-----___ "); + Write(0xcccccc, false, "17 "); + Write(0xffff66, false, "**\n "); + Write(0x66ff, false, "___--- "); + Write(0xcccccc, false, "### ##### ######### ##### "); + Write(0x66ff, false, "---___ "); + Write(0xcccccc, false, "16 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ") )) ) ) __"); + Write(0xff0000, false, "__ "); + Write(0xcccccc, false, "15 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, ".-"); + Write(0xcccccc, false, "("); + Write(0xff0000, false, "-"); + Write(0xcccccc, false, "(("); + Write(0xff0000, false, "-. "); + Write(0x9900, false, ".--"); + Write(0xcccccc, false, "("); + Write(0x9900, false, "-"); + Write(0xcccccc, false, "("); + Write(0x9900, false, "-. "); + Write(0xff0000, false, "/ "); + Write(0xcccccc, false, "_"); + Write(0xff0000, false, "\\ "); + Write(0xcccccc, false, "\\ 14 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "'------'_ "); + Write(0x9900, false, "'------'_ "); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "/| |/"); + Write(0xff0000, false, "| "); + Write(0xcccccc, false, "13 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "| | ) "); + Write(0x9900, false, "| | ) "); + Write(0xcccccc, false, "|_| "); + Write(0xff0000, false, "|/"); + Write(0xcccccc, false, "| 12 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "| |/ "); + Write(0x9900, false, "| |/ "); + Write(0xcccccc, false, "|/"); + Write(0xff0000, false, "| "); + Write(0xcccccc, false, "11 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "'------' "); + Write(0x9900, false, "'------' "); + Write(0xff0000, false, "|/"); + Write(0xcccccc, false, "| 10 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "_ __ "); + Write(0xcccccc, false, "|/"); + Write(0xff0000, false, "| "); + Write(0xcccccc, false, " 9 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, ".---_ _ "); + Write(0x880000, false, "| "); + Write(0xff0000, false, "|\\__"); + Write(0x880000, false, "/"); + Write(0xff0000, false, "_/) |/"); + Write(0xcccccc, false, "| 8 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "/ "); + Write(0x880000, false, "/ "); + Write(0xff0000, false, "/\\| "); + Write(0x999999, false, "__ "); + Write(0x880000, false, ") "); + Write(0xff0000, false, ")__ "); + Write(0x880000, false, "_|"); + Write(0xff0000, false, "_| / "); + Write(0xcccccc, false, "|/"); + Write(0xff0000, false, "| "); + Write(0xcccccc, false, " 7 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "/ "); + Write(0x880000, false, "/ | "); + Write(0xff0000, false, "\\ "); + Write(0xffff66, true, "* "); + Write(0x999999, false, "/ / \\ "); + Write(0x880000, false, "( "); + Write(0xff0000, false, "( \\_"); + Write(0x880000, false, "/"); + Write(0xff0000, false, "_/ / |/"); + Write(0xcccccc, false, "| 6 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "/ "); + Write(0x880000, false, "/ \\ "); + Write(0xff0000, false, "\\ "); + Write(0x999999, false, "| | \\/ "); + Write(0x880000, false, "\\_"); + Write(0xff0000, false, "\\____________/ "); + Write(0xcccccc, false, "|_| 5 "); + Write(0xffff66, false, "**\n "); + Write(0xff0000, false, "/ "); + Write(0x880000, false, "/ / \\ "); + Write(0xff0000, false, "\\ "); + Write(0x999999, false, "\\_\\______X_____X_____X_, "); + Write(0xcccccc, false, " 4 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "./~~~~~~~~~~~\\. 3 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "( .\",^. -\". '.~ ) 2 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "_'~~~~~~~~~~~~~'_________ ___ __ _ _ _ _ 1 "); + Write(0xffff66, false, "**\n \n"); + Console.ForegroundColor = color; Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2018/calendar.svg b/2018/calendar.svg index dcce84fe2..341b34a67 100644 --- a/2018/calendar.svg +++ b/2018/calendar.svg @@ -1,46 +1,46 @@ - - - + + + ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ █▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ -█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  $year = 2018 +█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  0x0000 | 2018   -     .         .         .        .        .       25 ** - .        .         .        .       \  /      .   24 ** -              .         .         \_\_\|_/__/      23 ** -       .         .            .  o-_/.()__-------  22 ** -   .       .            *         \____            21 ** -               .       |\|            \_\_ ___  /  20 ** -       .               |\|              / |   ||   19 ** -  .           _________|\|_________    /  |   ||   18 ** -      ___-----  ###########  ##### -----___        17 ** -___---  ###  #####    #########  #####     ---___  16 ** -      ) ))          ) )                    ____    15 ** -   .-(-((-.     .--(-(-.                  / _\ \   14 ** -   '------'_    '------'_                |/|  |/|  13 ** -   |      | )   |      | )               |_|  |/|  12 ** -   |      |/    |      |/                     |/|  11 ** -   '------'     '------'                      |/|  10 ** -                                   _     __   |/|   9 ** -        .---_             _       | |\__/_/)  |/|   8 ** -       / / /\|      __   ) )__   _|_|     /   |/|   7 ** -     / / | \ *    / / \ ( (   \_/_/      /    |/|   6 ** -    /  /  \ \    | | \/  \_\____________/     |_|   5 ** -   / /  / \  \    \_\______X_____X_____X_,          4 ** - ./~~~~~~~~~~~\.                                    3 ** -( .",^. -". '.~ )                                   2 ** -_'~~~~~~~~~~~~~'_________ ___ __ _  _   _    _      1 ** +     .         .         .        .        .       25 ** + .        .         .        .       \  /      .   24 ** +              .         .         \_\_\|_/__/      23 ** +       .         .            .  o-_/.()__-------  22 ** +   .       .            *         \____            21 ** +               .       |\|            \_\_ ___  /  20 ** +       .               |\|              / |   ||   19 ** +  .           _________|\|_________    /  |   ||   18 ** +      ___-----  ###########  ##### -----___        17 ** +___---  ###  #####    #########  #####     ---___  16 ** +      ) ))          ) )                    ____    15 ** +   .-(-((-.     .--(-(-.                  / _\ \   14 ** +   '------'_    '------'_                |/|  |/|  13 ** +   |      | )   |      | )               |_|  |/|  12 ** +   |      |/    |      |/                     |/|  11 ** +   '------'     '------'                      |/|  10 ** +                                   _     __   |/|   9 ** +        .---_             _       | |\__/_/)  |/|   8 ** +       / / /\|      __   ) )__   _|_|     /   |/|   7 ** +     / / | \ *    / / \ ( (   \_/_/      /    |/|   6 ** +    /  /  \ \    | | \/  \_\____________/     |_|   5 ** +   / /  / \  \    \_\______X_____X_____X_,          4 ** + ./~~~~~~~~~~~\.                                    3 ** +( .",^. -". '.~ )                                   2 ** +_'~~~~~~~~~~~~~'_________ ___ __ _  _   _    _      1 ** - \ No newline at end of file + \ No newline at end of file diff --git a/2019/Day01/README.md b/2019/Day01/README.md index c17785a59..0cca1558b 100644 --- a/2019/Day01/README.md +++ b/2019/Day01/README.md @@ -3,4 +3,4 @@ Santa has become stranded at the edge of the Solar System while delivering prese 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! -Read the [full puzzle](https://adventofcode.com/2019/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2019/day/1) description._ diff --git a/2019/README.md b/2019/README.md index 4bd1241ac..27bdfaccb 100644 --- a/2019/README.md +++ b/2019/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2019) Check out https://adventofcode.com/2019. - diff --git a/2019/SplashScreen.cs b/2019/SplashScreen.cs index 9e68101b8..9025b076f 100644 --- a/2019/SplashScreen.cs +++ b/2019/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2019; @@ -9,185 +8,178 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ $year = 2019\n "); - Write(0xcc00, false, "\n "); - Write(0x666666, false, " ''.. ':. '. "); - Write(0x333333, false, ". "); - Write(0xcccccc, false, "25 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "....... "); - Write(0x333333, false, ".."); - Write(0x666666, false, " ''. '. "); - Write(0x333333, false, ". "); - Write(0xbebcbc, true, ". "); - Write(0xcccccc, false, "24 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " '''''... "); - Write(0x333333, false, "."); - Write(0x666666, false, " ''. '. "); - Write(0x333333, false, "."); - Write(0x666666, false, " ' "); - Write(0xcccccc, false, "23 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, "."); - Write(0x666666, false, " ''.. '. '. "); - Write(0xffffff, true, ". "); - Write(0xcccccc, false, "22 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "...... ''. '. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. "); - Write(0xcccccc, false, "21 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, ".."); - Write(0x666666, false, " ''''... '. '."); - Write(0x333333, false, "."); - Write(0x666666, false, " : "); - Write(0xcdc1b2, true, ". "); - Write(0xcccccc, false, "20 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ''.. "); - Write(0x333333, false, ". ."); - Write(0x666666, false, "'. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. "); - Write(0x333333, false, "."); - Write(0x666666, false, "'. "); - Write(0xcccccc, false, "19 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "..... ''. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. "); - Write(0x333333, false, "."); - Write(0x666666, false, "'. '"); - Write(0x456efe, true, "o "); - Write(0xcccccc, false, "18 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, "."); - Write(0x666666, false, " ''''... '. '. ': '. "); - Write(0xcccccc, false, "17 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, "."); - Write(0x666666, false, " '.. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. '. "); - Write(0xbee4e7, true, "o"); - Write(0x666666, false, " : "); - Write(0xcccccc, false, "16 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " '. '. '. : : "); - Write(0xcccccc, false, "15 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "'''''... '. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. "); - Write(0xebc982, true, "(O)"); - Write(0x666666, false, " : '. "); - Write(0xcccccc, false, "14 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ''.. '. '. '. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. :"); - Write(0x333333, false, ". "); - Write(0xcccccc, false, "13 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "''''..."); - Write(0x333333, false, "."); - Write(0x666666, false, " '. "); - Write(0x333333, false, "."); - Write(0x666666, false, " '. '"); - Write(0xd2beab, true, "O"); - Write(0x666666, false, " '. : : "); - Write(0xcccccc, false, "12 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ''. '. : '. : '. : "); - Write(0xcccccc, false, "11 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "'''''.. '. '. "); - Write(0x333333, false, ". "); - Write(0xbabdb6, true, "."); - Write(0x333333, false, ". ."); - Write(0x666666, false, " : '. : '. "); - Write(0xcccccc, false, "10 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, ".."); - Write(0x666666, false, " '. '. '. '. : : : : "); - Write(0xcccccc, false, " 9 "); - Write(0xffff66, false, "**\n "); - Write(0x333333, false, ". ."); - Write(0x666666, false, " : '. "); - Write(0x333333, false, ". "); - Write(0xf7a859, true, ". "); - Write(0x333333, false, "."); - Write(0x666666, false, " : : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : : "); - Write(0xcccccc, false, " 8 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "'''. "); - Write(0x333333, false, ".."); - Write(0x666666, false, " : : : : : : "); - Write(0x333333, false, ". ."); - Write(0x666666, false, ": : "); - Write(0xcccccc, false, " 7 "); - Write(0xffff66, false, "**\n "); - Write(0xffff66, true, "* "); - Write(0xbebcbe, true, ". "); - Write(0x333333, false, "."); - Write(0x666666, false, ": : : "); - Write(0x333333, false, "."); - Write(0x666666, false, ": : : "); - Write(0x333333, false, "."); - Write(0x666666, false, ": : "); - Write(0xcccccc, false, " 6 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, "...' : : : : : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : "); - Write(0xcccccc, false, " 5 "); - Write(0xffff66, false, "**\n "); - Write(0xe3e2e0, true, "."); - Write(0x666666, false, " .' : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : : "); - Write(0x333333, false, "."); - Write(0x666666, false, " : : : "); - Write(0xcccccc, false, " 4 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " .' .' "); - Write(0x333333, false, "."); - Write(0x666666, false, ".' .' : : : : "); - Write(0xcccccc, false, " 3 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, ".....'' "); - Write(0x333333, false, "."); - Write(0x91a5bd, true, "."); - Write(0x666666, false, "' "); - Write(0x333333, false, "."); - Write(0x666666, false, " .' : :"); - Write(0x333333, false, "."); - Write(0x666666, false, " .' : "); - Write(0x333333, false, "."); - Write(0x666666, false, " .' "); - Write(0xcccccc, false, " 2 "); - Write(0xffff66, false, "**\n "); - Write(0x666666, false, " ..' .' :"); - Write(0x333333, false, "."); - Write(0x666666, false, " .' "); - Write(0x333333, false, "."); - Write(0x666666, false, " : .' : "); - Write(0xcccccc, false, " 1 "); - Write(0xffff66, false, "**\n \n"); - + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ sub y{2019}\n \n"); + Write(0xcc00, false, " "); + Write(0x666666, false, " ''.. ':. '. "); + Write(0xcccccc, false, "25 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "....... "); + Write(0x333333, false, "."); + Write(0x666666, false, " ''. '. "); + Write(0xbebcbc, true, ". "); + Write(0xcccccc, false, "24 "); + Write(0xffff66, false, "**\n "); + Write(0x333333, false, "."); + Write(0x666666, false, " '''''... ''. '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " ' "); + Write(0xcccccc, false, "23 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ''.. '. '. "); + Write(0xffffff, true, ". "); + Write(0xcccccc, false, "22 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "...... "); + Write(0x333333, false, "."); + Write(0x666666, false, " ''."); + Write(0x333333, false, ". ."); + Write(0x666666, false, " '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " '. "); + Write(0xcccccc, false, "21 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ''''... "); + Write(0x333333, false, "."); + Write(0x666666, false, "'. "); + Write(0x333333, false, "."); + Write(0x666666, false, " '. : "); + Write(0xcdc1b2, true, ". "); + Write(0x333333, false, ". "); + Write(0xcccccc, false, "20 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ''.. '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " '."); + Write(0x333333, false, "."); + Write(0x666666, false, " '. "); + Write(0xcccccc, false, "19 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "..... ''. '. '. '"); + Write(0x456efe, true, "o "); + Write(0x333333, false, ". "); + Write(0xcccccc, false, "18 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ''''... '. '. ': '."); + Write(0x333333, false, ". "); + Write(0xcccccc, false, "17 "); + Write(0xffff66, false, "**\n "); + Write(0x333333, false, "."); + Write(0x666666, false, " '.. '. '. "); + Write(0xbee4e7, true, "o"); + Write(0x333333, false, "."); + Write(0x666666, false, " : "); + Write(0xcccccc, false, "16 "); + Write(0xffff66, false, "**\n "); + Write(0x333333, false, ". ."); + Write(0x666666, false, " '. '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " : : "); + Write(0xcccccc, false, "15 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "'''''... '. "); + Write(0x333333, false, ". ."); + Write(0x666666, false, " '. "); + Write(0xebc982, true, "(O)"); + Write(0x666666, false, " : '. "); + Write(0xcccccc, false, "14 "); + Write(0xffff66, false, "**\n "); + Write(0x333333, false, "."); + Write(0x666666, false, " ''.. '. '. "); + Write(0x333333, false, ".."); + Write(0x666666, false, " '. '. : "); + Write(0xcccccc, false, "13 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "''''... '. '. '"); + Write(0xd2beab, true, "O"); + Write(0x666666, false, " '. : :"); + Write(0x333333, false, ". "); + Write(0xcccccc, false, "12 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ''. '."); + Write(0x333333, false, ". ."); + Write(0x666666, false, " : '. : '. : "); + Write(0xcccccc, false, "11 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "'''''.. '. '. "); + Write(0x333333, false, ". . "); + Write(0xbabdb6, true, "."); + Write(0x666666, false, " : "); + Write(0x333333, false, "."); + Write(0x666666, false, " '. : '. "); + Write(0xcccccc, false, "10 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " '. '. '. '. "); + Write(0x333333, false, "."); + Write(0x666666, false, " : : : : "); + Write(0xcccccc, false, " 9 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " : '."); + Write(0x333333, false, ". "); + Write(0xf7a859, true, ". "); + Write(0x333333, false, "."); + Write(0x666666, false, " : :"); + Write(0x333333, false, "."); + Write(0x666666, false, " : : : "); + Write(0xcccccc, false, " 8 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "'''. "); + Write(0x333333, false, "."); + Write(0x666666, false, ":"); + Write(0x333333, false, "."); + Write(0x666666, false, " : :"); + Write(0x333333, false, "."); + Write(0x666666, false, " : : : : : "); + Write(0xcccccc, false, " 7 "); + Write(0xffff66, false, "**\n "); + Write(0xffff66, true, "* "); + Write(0xbebcbe, true, "."); + Write(0x666666, false, " : : : : : : "); + Write(0x333333, false, "."); + Write(0x666666, false, " : : "); + Write(0xcccccc, false, " 6 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, "...' "); + Write(0x333333, false, "."); + Write(0x666666, false, ": : : : "); + Write(0x333333, false, "."); + Write(0x666666, false, ": : "); + Write(0x333333, false, "."); + Write(0x666666, false, ": : "); + Write(0xcccccc, false, " 5 "); + Write(0xffff66, false, "**\n "); + Write(0x333333, false, ". "); + Write(0xe3e2e0, true, "."); + Write(0x333333, false, "."); + Write(0x666666, false, " .' : : : : : : "); + Write(0xcccccc, false, " 4 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " .' .' .' "); + Write(0x333333, false, "."); + Write(0x666666, false, " .' : : : : "); + Write(0xcccccc, false, " 3 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, ".....'' "); + Write(0x91a5bd, true, "."); + Write(0x666666, false, "' .' : : .' "); + Write(0x333333, false, "."); + Write(0x666666, false, " : .' "); + Write(0xcccccc, false, " 2 "); + Write(0xffff66, false, "**\n "); + Write(0x666666, false, " ..' .' : "); + Write(0x333333, false, "."); + Write(0x666666, false, " .' : .'"); + Write(0x333333, false, "."); + Write(0x666666, false, " : "); + Write(0xcccccc, false, " 1 "); + Write(0xffff66, false, "**\n \n"); + Console.ForegroundColor = color; Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2019/calendar.svg b/2019/calendar.svg index 80ce35dab..171bad8d6 100644 --- a/2019/calendar.svg +++ b/2019/calendar.svg @@ -1,46 +1,46 @@ - - - + + + ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ █▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ -█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  $year = 2019 +█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  sub y{2019}   -                   ''..     ':.              '. .  25 ** -.......  ..            ''.     '.      .       .   24 ** -       '''''...    .      ''.    '.      .      '  23 ** -  .            ''..          '.    '. .            22 ** -......             ''.         '.  . '.            21 ** - ..   ''''...         '.         '..   : .         20 ** -             ''..  .   .'.       . '.  .'.         19 ** -.....            ''.    . '.       .'.   'o        18 ** -.    ''''...        '.      '.       ':   '.       17 ** - .          '..     . '.      '.       o    :      16 ** -               '.       '.     '.       :    :     15 ** -'''''...         '.    . '.     (O)      :   '.    14 ** -        ''..       '.     '.     '.  .   '.   :.   13 ** -''''....    '.    . '.     'O     '.      :    :   12 ** -       ''.    '.      :     '.     :      '.   :   11 ** -'''''..   '.   '.   .  .. .  :     '.      :   '.  10 ** -    .. '.  '.   '.     '.     :     :      :    :   9 ** -. .      :  '. . .   .  :     :  .  :     . :   :   8 ** -'''.  ..  :  :   :      :     :     : .    .:   :   7 ** - * .     .:  :   :     .:     :     :      .:   :   6 ** -...'      :  :   :      :     :   . :       : . :   5 ** -         .  .'   :  .   :     :  .  :       :   :   4 ** -       .'  .'  ..'     .'     :     :      :    :   3 ** -.....''  ... .'      :     :.    .'      : . .'   2 ** -       ..'    .'      :.    .' .   :      .'   :    1 ** +                   ''..     ':.              '.    25 ** +.......    .           ''.     '.              .   24 ** +.      '''''...           ''.    '.  .          '  23 ** +               ''..          '.    '. .            22 ** +......      .      ''.. .      '. .  '.            21 ** +      ''''...        .'.       . '.    : .  .      20 ** +             ''..       '.    .    '..  '.         19 ** +.....            ''.      '.        '.   'o    .   18 ** +     ''''...        '.      '.       ':   '..      17 ** + .          '..       '.      '.       o.   :      16 ** +        .   .  '.       '.   . '.   .   :    :     15 ** +'''''...         '.  . . '.     (O)      :   '.    14 ** +    .   ''..       '.     '.  .. '.      '.   :    13 ** +''''...     '.      '.     'O     '.      :    :.  12 ** +       ''.    '.. .   :     '.     :      '.   :   11 ** +'''''..   '.   '. .  . .     :  .  '.      :   '.  10 ** +       '.  '.   '.     '.  .  :     :      :    :   9 ** +         :  '..  . .    :     :.    :       :   :   8 ** +'''.     .:. :   :.     :     :     :       :   :   7 ** + * .      :  :   :      :     :     :   .   :   :   6 ** +...'     .:  :   :      :    .:     :      .:   :   5 ** +       . .. .'   :      :     :     :       :   :   4 ** +       .'  .'   .'  .  .'     :     :      :    :   3 ** +.....''   .'   .'      :     :     .' .    :   .'   2 ** +       ..'    .'      :  .  .'     :      .'.  :    1 ** - \ No newline at end of file + \ No newline at end of file diff --git a/2020/Day01/README.md b/2020/Day01/README.md index 9197ad1e0..afa2c5f0e 100644 --- a/2020/Day01/README.md +++ b/2020/Day01/README.md @@ -3,4 +3,4 @@ After saving Christmas [five years in a row](/events), you've decided to take a 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. -Read the [full puzzle](https://adventofcode.com/2020/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2020/day/1) description._ diff --git a/2020/README.md b/2020/README.md index 909ac8d77..6e92a1b05 100644 --- a/2020/README.md +++ b/2020/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2020) Check out https://adventofcode.com/2020. - diff --git a/2020/SplashScreen.cs b/2020/SplashScreen.cs index cbd79a46e..0152b71a8 100644 --- a/2020/SplashScreen.cs +++ b/2020/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2020; @@ -9,8 +8,8 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ 0x0000 | 2020\n "); - Write(0xcc00, false, " \n "); + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /* 2020 */\n \n "); + Write(0xcc00, false, " "); Write(0xccccff, false, ".........."); Write(0xff0000, false, "|"); Write(0xccccff, false, ".......... "); @@ -233,7 +232,7 @@ public void Show() { Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2020/calendar.svg b/2020/calendar.svg index e81df0d3f..645d8f67e 100644 --- a/2020/calendar.svg +++ b/2020/calendar.svg @@ -1,4 +1,4 @@ - + stars. -Read the [full puzzle](https://adventofcode.com/2021/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2021/day/1) description._ diff --git a/2021/README.md b/2021/README.md index 692c54269..c0b9cc240 100644 --- a/2021/README.md +++ b/2021/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2021) Check out https://adventofcode.com/2021. - diff --git a/2021/SplashScreen.cs b/2021/SplashScreen.cs index f8a0e3fb1..525ef555c 100644 --- a/2021/SplashScreen.cs +++ b/2021/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2021; @@ -9,35 +8,35 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /* 2021 */\n \n "); - Write(0xcc00, false, " "); + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ int y = 2021;\n "); + Write(0xcc00, false, " \n "); Write(0xc8ff, false, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); Write(0xcccccc, false, " 1 "); Write(0xffff66, false, "**\n "); - Write(0xb5ed, false, " . . . "); - Write(0xffffff, false, ". "); - Write(0xff00ff, true, ". "); + Write(0xb5ed, false, " . . . . '.. . . ... "); + Write(0xffffff, false, ". "); + Write(0xb5ed, false, " ."); + Write(0x9933, true, ". "); Write(0xa47a4d, false, "..'''' "); Write(0xcccccc, false, " 2 "); Write(0xffff66, false, "**\n "); - Write(0xa2db, false, ". . . "); + Write(0xa2db, false, " . . . . ' "); Write(0xffffff, false, ". "); - Write(0xa2db, false, ". ."); - Write(0xff00ff, true, ". "); - Write(0x66ff, true, "."); - Write(0xa2db, false, ". "); + Write(0xa2db, false, " '"); + Write(0x66ff, true, ". "); + Write(0x9933, true, ". "); Write(0xa47a4d, false, ": "); Write(0xcccccc, false, " 3 "); Write(0xffff66, false, "**\n "); - Write(0x91cc, false, ". . .. . . .. . . "); - Write(0xff0000, true, ". "); + Write(0x91cc, false, " . . .. . . ."); + Write(0x9933, true, ". "); Write(0xffffff, false, ".' "); - Write(0xff00ff, true, ". "); + Write(0xff9900, true, ". "); Write(0xa47a4d, false, "....' "); Write(0xcccccc, false, " 4 "); Write(0xffff66, false, "**\n "); - Write(0x85c0, false, " ' . . "); - Write(0xff0000, true, ". "); + Write(0x85c0, false, " . . . ."); + Write(0xff00ff, true, ". "); Write(0xc74c30, false, "."); Write(0xff0000, false, "."); Write(0xffffff, false, "|\\"); @@ -46,112 +45,117 @@ public void Show() { Write(0xa47a4d, false, "'' "); Write(0xcccccc, false, " 5 "); Write(0xffff66, false, "**\n "); - Write(0x79b5, false, ". . ' ~ .. "); - Write(0xff00ff, true, ". "); + Write(0x79b5, false, ".'~ ' . . . "); + Write(0xff0000, true, ". "); Write(0xa47a4d, false, ": "); Write(0xcccccc, false, " 6 "); Write(0xffff66, false, "**\n "); - Write(0x6daa, false, " ' . "); - Write(0xff9900, true, "."); + Write(0x6daa, false, " ' . . ' . . . "); + Write(0xff0000, true, "."); Write(0xa47a4d, false, ":' "); Write(0xcccccc, false, " 7 "); Write(0xffff66, false, "**\n "); - Write(0x619f, false, ". . . . . "); - Write(0x66ff, true, "."); + Write(0x619f, false, "' . . .. .' .. "); + Write(0xff9900, true, "."); Write(0xa47a4d, false, "'''''..... .."); Write(0xc74c30, false, "."); Write(0xff0000, false, ". "); Write(0xcccccc, false, " 8 "); Write(0xffff66, false, "**\n "); - Write(0x5a98, false, " .. . . '. "); + Write(0x5a98, false, " ' . . . . "); Write(0xa47a4d, false, ":'.."); - Write(0xff00ff, true, ". "); + Write(0x9933, true, ". "); Write(0xa47a4d, false, ".."); - Write(0x66ff, true, ". "); - Write(0xff00ff, true, "."); + Write(0x9933, true, ". "); + Write(0x66ff, true, "."); Write(0xa47a4d, false, "''"); - Write(0xff00ff, true, ". "); + Write(0x66ff, true, ". "); Write(0xff0000, false, "': "); Write(0xcccccc, false, " 9 "); Write(0xffff66, false, "**\n "); - Write(0x5291, false, " . . .' . . . "); + Write(0x5291, false, " . '. "); Write(0xa47a4d, false, ": '' ''''.. "); - Write(0x66ff, true, ". ."); + Write(0xff9900, true, ". "); + Write(0x66ff, true, "."); Write(0xc74c30, false, "'"); Write(0xa47a4d, false, ". "); Write(0xcccccc, false, "10 "); Write(0xffff66, false, "**\n "); - Write(0x4a8a, false, " ... . . . . "); + Write(0x4a8a, false, " . . ' . "); Write(0xa47a4d, false, ": '..'."); - Write(0xff00ff, true, "."); + Write(0x9933, true, "."); Write(0xa47a4d, false, ": "); Write(0xcccccc, false, "11 "); Write(0xffff66, false, "**\n "); - Write(0x4282, false, " .. . . . . "); + Write(0x4282, false, " ' . .. "); Write(0xa47a4d, false, ": :'''.. ..'"); - Write(0xff9900, true, "."); + Write(0x9933, true, "."); Write(0xa47a4d, false, ": "); Write(0xcccccc, false, "12 "); Write(0xffff66, false, "**\n "); - Write(0x3b7b, false, " '~ . . . "); + Write(0x3b7b, false, "' ' . . . . "); Write(0xa47a4d, false, ".' ..''"); - Write(0x66ff, true, ". "); - Write(0x9933, true, ". "); + Write(0xff9900, true, ". "); + Write(0xff00ff, true, ". "); Write(0xa47a4d, false, "'''"); - Write(0xff0000, true, "."); + Write(0xff9900, true, "."); Write(0xa47a4d, false, "...: "); Write(0xcccccc, false, "13 "); Write(0xffff66, false, "**\n "); - Write(0x3374, false, " . . "); + Write(0x3374, false, "' . .' . . ' "); Write(0xa47a4d, false, ": ...''"); - Write(0x66ff, true, ". "); + Write(0xff9900, true, ". "); Write(0xa47a4d, false, "..': "); Write(0xff0000, false, "."); Write(0xc74c30, false, "."); Write(0xa47a4d, false, "..' "); Write(0xcccccc, false, "14 "); Write(0xffff66, false, "**\n "); - Write(0x2e6f, false, " '' . "); - Write(0x66ff, true, "."); - Write(0x2e6f, false, " ."); + Write(0x2e6f, false, " ' . .. . "); + Write(0xff9900, true, "."); + Write(0x2e6f, false, ". "); Write(0x66ff, true, ". "); Write(0xa47a4d, false, ":'"); - Write(0xff9900, true, "."); + Write(0xff0000, true, "."); Write(0xa47a4d, false, "...''' "); Write(0xc74c30, false, "'"); Write(0xff0000, false, "'' "); Write(0xcccccc, false, "15 "); Write(0xffff66, false, "**\n "); Write(0xa47a4d, false, "'.'. "); - Write(0x296b, false, " .' ."); - Write(0x9933, true, "."); + Write(0x296b, false, " . "); + Write(0xff9900, true, "."); Write(0xa47a4d, false, ":'. ....' "); Write(0xcccccc, false, "16 "); Write(0xffff66, false, "**\n "); Write(0xa47a4d, false, ": "); - Write(0x2566, false, "' . "); - Write(0xff0000, true, ". "); + Write(0x2566, false, " . "); + Write(0x66ff, true, "."); + Write(0x2566, false, ". "); Write(0xa47a4d, false, ": ' "); Write(0xcccccc, false, "17 "); Write(0xffff66, false, "**\n "); Write(0x584338, false, ": "); - Write(0x2062, false, " . . "); - Write(0xff00ff, true, ". "); + Write(0x2062, false, " . "); + Write(0xff9900, true, ". "); Write(0x584338, false, "..' "); Write(0xcccccc, false, "18 "); Write(0xffff66, false, "**\n "); - Write(0x584338, false, "'. "); - Write(0xff00ff, true, ". "); + Write(0x584338, false, "'. "); + Write(0x1b5e, false, " . "); + Write(0xff0000, true, ". "); Write(0x584338, false, ": "); Write(0xcccccc, false, "19 "); Write(0xffff66, false, "**\n "); - Write(0x584338, false, "'. "); + Write(0x584338, false, "'. "); + Write(0x1759, false, ". . "); Write(0x66ff, true, ". "); Write(0x584338, false, ": "); Write(0xcccccc, false, "20 "); Write(0xffff66, false, "**\n "); - Write(0x584338, false, ": "); - Write(0xff00ff, true, ". "); + Write(0x584338, false, ": "); + Write(0x1255, false, ". "); + Write(0x66ff, true, ". "); Write(0x584338, false, ": "); Write(0xcccccc, false, "21 "); Write(0xffff66, false, "**\n "); @@ -161,14 +165,13 @@ public void Show() { Write(0x584338, false, ": "); Write(0xcccccc, false, "22 "); Write(0xffff66, false, "**\n "); - Write(0x584338, false, ": "); - Write(0x94c, false, ". "); - Write(0x9933, true, "."); + Write(0x584338, false, ": "); + Write(0xff9900, true, "."); Write(0x584338, false, ".' "); Write(0xcccccc, false, "23 "); Write(0xffff66, false, "**\n "); Write(0x584338, false, ": "); - Write(0x66ff, true, ". "); + Write(0xff9900, true, ". "); Write(0x584338, false, ".' "); Write(0xcccccc, false, "24 "); Write(0xffff66, false, "**\n "); @@ -180,7 +183,7 @@ public void Show() { Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2021/calendar.svg b/2021/calendar.svg index 28b14d767..00500cbb7 100644 --- a/2021/calendar.svg +++ b/2021/calendar.svg @@ -1,4 +1,4 @@ - + fifty stars by December 25th. Although the Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case. -Read the [full puzzle](https://adventofcode.com/2022/day/1). \ No newline at end of file +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2022/day/1) description._ diff --git a/2022/README.md b/2022/README.md index c5f2bc5cb..d43fe552e 100644 --- a/2022/README.md +++ b/2022/README.md @@ -1,6 +1,4 @@ - # Advent of Code (2022) Check out https://adventofcode.com/2022. - diff --git a/2022/SplashScreen.cs b/2022/SplashScreen.cs index 0f4a54a0a..115bf10cc 100644 --- a/2022/SplashScreen.cs +++ b/2022/SplashScreen.cs @@ -1,4 +1,3 @@ - using System; namespace AdventOfCode.Y2022; @@ -9,8 +8,8 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ int y = 2022;\n "); - Write(0xcc00, false, " \n "); + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ $year = 2022\n "); + Write(0xcc00, false, "\n "); Write(0x630031, false, " - "); Write(0xffffff, false, "/\\"); Write(0x630031, false, " - - - - - - - \n "); @@ -26,424 +25,431 @@ public void Show() { Write(0xcccccc, false, "25 "); Write(0xffff66, false, "**\n "); Write(0xaaaaaa, false, "/"); - Write(0x7fbd39, false, "@@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); Write(0xaaaaaa, false, "\\ /\\"); - Write(0x4d8b03, false, "#"); - Write(0xaaaaaa, false, "\\"); - Write(0x427322, false, "#@"); Write(0x488813, false, "@"); + Write(0xaaaaaa, false, "\\"); Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@@##"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "#"); Write(0x427322, false, "@"); - Write(0x7fbd39, false, "##@"); - Write(0x1461f, false, "@"); - Write(0x427322, false, "@@"); + Write(0x7fbd39, false, "#"); Write(0x488813, false, "@"); - Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@@#@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "#"); Write(0x427322, false, "#"); - Write(0x488813, false, "@@"); + Write(0x7fbd39, false, "#"); Write(0x1461f, false, "@"); - Write(0x488813, false, "@@"); + Write(0x427322, false, "#"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "#"); Write(0x427322, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x488813, false, "#"); - Write(0x4d8b03, false, "## "); + Write(0x1461f, false, "#"); + Write(0x4d8b03, false, "@@"); + Write(0x427322, false, "@"); + Write(0x1461f, false, "@#"); + Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@"); + Write(0x4d8b03, false, "#@"); + Write(0x488813, false, "##"); + Write(0x1461f, false, "@ "); Write(0xcccccc, false, "24 "); Write(0xffff66, false, "**\n "); - Write(0x488813, false, "@#"); - Write(0x7fbd39, false, "@."); - Write(0x1461f, false, "' "); - Write(0x4d8b03, false, "'"); - Write(0x7fbd39, false, "."); - Write(0x427322, false, "#"); - Write(0x488813, false, "@"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x427322, false, "#"); + Write(0x1461f, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@#"); - Write(0x488813, false, "@@"); + Write(0x4d8b03, false, "."); + Write(0x427322, false, "'"); + Write(0x7fbd39, false, " '."); + Write(0x1461f, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); - Write(0x488813, false, "@"); + Write(0x488813, false, "##@"); + Write(0x7fbd39, false, "@"); + Write(0x1461f, false, "@"); + Write(0x488813, false, "#"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@"); Write(0x488813, false, "#"); - Write(0x427322, false, "#"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#@#"); - Write(0x488813, false, "@"); + Write(0x427322, false, "@"); Write(0x1461f, false, "@"); + Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@@"); + Write(0x427322, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x427322, false, "@@@"); Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "#"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); - Write(0x427322, false, "##"); - Write(0x4d8b03, false, "@@@"); - Write(0x427322, false, "@# "); + Write(0x1461f, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "##@"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#"); + Write(0x427322, false, "@ "); Write(0xcccccc, false, "23 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "@@"); + Write(0x4d8b03, false, "@"); Write(0x488813, false, "@"); - Write(0x427322, false, "'"); - Write(0x488813, false, ". "); - Write(0x4d8b03, false, "."); - Write(0x427322, false, "'"); - Write(0x4d8b03, false, "#@"); Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); + Write(0x7fbd39, false, "'. "); + Write(0x4d8b03, false, ".'"); + Write(0x1461f, false, "@"); + Write(0x427322, false, "@"); + Write(0x4d8b03, false, "@@"); Write(0xd0b376, false, "."); - Write(0x1461f, false, "#"); - Write(0x427322, false, "#"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "#"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x1461f, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "#@"); + Write(0x488813, false, "@@"); Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@#"); + Write(0x7fbd39, false, "@#"); Write(0x488813, false, "@"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@@"); + Write(0x4d8b03, false, "#"); + Write(0x427322, false, "#"); Write(0x7fbd39, false, "#"); Write(0x1461f, false, "@"); - Write(0x488813, false, "#"); + Write(0x4d8b03, false, "@"); Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "@"); + Write(0x488813, false, "@@"); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@#"); + Write(0x4d8b03, false, "@@"); Write(0xffffff, false, "()))"); - Write(0x427322, false, "@@"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@ "); + Write(0x4d8b03, false, "@ "); Write(0xcccccc, false, "22 "); Write(0xffff66, false, "**\n "); - Write(0x488813, false, "@#"); - Write(0x427322, false, "@@"); - Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@@"); Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "#"); + Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "#"); - Write(0x488813, false, "@"); - Write(0x1461f, false, "#"); - Write(0x488813, false, "#"); + Write(0x427322, false, "#"); Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0xd0b376, false, "."); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@@"); + Write(0x488813, false, "#"); Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "#@"); Write(0x427322, false, "#"); + Write(0x1461f, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0xd0b376, false, "."); Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x427322, false, "#"); + Write(0x488813, false, "#"); Write(0x4d8b03, false, "#"); - Write(0x427322, false, "#"); + Write(0x1461f, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "@"); Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@#"); + Write(0x488813, false, "@"); + Write(0x427322, false, "#"); Write(0x1461f, false, "@"); - Write(0x488813, false, "#@"); - Write(0x4d8b03, false, "@"); + Write(0x488813, false, "#"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@##"); + Write(0x488813, false, "@@"); Write(0x427322, false, "#"); - Write(0x4d8b03, false, "@@"); - Write(0x7fbd39, false, "@ "); + Write(0x488813, false, "@"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "##"); + Write(0x427322, false, "#"); + Write(0x7fbd39, false, "@"); + Write(0x685c46, false, "|"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "# "); Write(0xcccccc, false, "21 "); Write(0xffff66, false, "**\n "); - Write(0x7fbd39, false, "@@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "#"); Write(0xd0b376, false, "."); + Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x427322, false, "#"); + Write(0x1461f, false, "@"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "#"); Write(0x488813, false, "#"); + Write(0x427322, false, "#@"); Write(0x7fbd39, false, "@"); - Write(0x427322, false, "@@"); - Write(0x4d8b03, false, "#"); - Write(0x427322, false, "@@"); - Write(0x488813, false, "@"); - Write(0x1461f, false, "@"); - Write(0x488813, false, "@##"); - Write(0x427322, false, "#"); - Write(0x1461f, false, "@"); + Write(0x427322, false, "@"); Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "#"); + Write(0x488813, false, "@"); Write(0xd0b376, false, "."); - Write(0x7fbd39, false, "#@"); Write(0x1461f, false, "#"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@"); Write(0x5eabb4, false, "~~"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); + Write(0x7fbd39, false, "@#"); Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "#"); - Write(0x4d8b03, false, "#"); + Write(0x427322, false, "@"); Write(0x1461f, false, "@"); Write(0x488813, false, "#"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "##"); - Write(0x427322, false, "#"); + Write(0x427322, false, "#@#"); Write(0x488813, false, "#"); - Write(0x7fbd39, false, "@ "); - Write(0xcccccc, false, "20 "); - Write(0xffff66, false, "**\n "); - Write(0x427322, false, "@"); + Write(0x1461f, false, "#"); Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "#@"); + Write(0x427322, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x1461f, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x488813, false, "#"); + Write(0x488813, false, "@# "); + Write(0xcccccc, false, "20 "); + Write(0xffff66, false, "**\n "); + Write(0x488813, false, "@@"); Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "#"); + Write(0x685c46, false, "|"); Write(0x7fbd39, false, "@"); - Write(0x427322, false, "##"); - Write(0x488813, false, "@"); + Write(0x488813, false, "@#"); + Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x427322, false, "@"); + Write(0x488813, false, "#"); Write(0x5eabb4, false, "."); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@@"); - Write(0x4d8b03, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@"); Write(0x427322, false, "@"); Write(0x488813, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@@"); + Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x5eabb4, false, "~~~~ "); - Write(0xaaaaaa, false, ".~'"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@"); - Write(0x488813, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x427322, false, "#"); - Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@@#"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@@"); + Write(0x5eabb4, false, "~~~~ "); + Write(0xaaaaaa, false, ".~'"); + Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@ "); + Write(0x1461f, false, "@"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "#@"); + Write(0x4d8b03, false, "#@#"); + Write(0x488813, false, "@@"); + Write(0x1461f, false, "#"); + Write(0x427322, false, "@ "); Write(0xcccccc, false, "19 "); Write(0xffff66, false, "**\n "); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "##"); - Write(0x488813, false, "#"); + Write(0x427322, false, "#"); + Write(0x7fbd39, false, "@@"); + Write(0x4d8b03, false, "#"); Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#@"); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@@"); Write(0x488813, false, "#"); - Write(0x1461f, false, "#"); - Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@@#"); - Write(0x5eabb4, false, "."); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); - Write(0x427322, false, "@"); Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x4d8b03, false, "#@"); - Write(0x7fbd39, false, "#"); + Write(0x5eabb4, false, "."); + Write(0x4d8b03, false, "@@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); Write(0x427322, false, "@"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@#"); + Write(0x427322, false, "@@@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#@"); + Write(0x7fbd39, false, "@"); Write(0x5eabb4, false, "~~ "); Write(0xaaaaaa, false, "/"); Write(0xe6410b, false, "~"); Write(0xaaaaaa, false, "\\ "); - Write(0x488813, false, "#"); - Write(0x7fbd39, false, "#"); - Write(0x427322, false, "@"); - Write(0x7fbd39, false, "@@"); - Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@"); - Write(0x427322, false, "#"); - Write(0x488813, false, "#@"); + Write(0x488813, false, "@@"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); Write(0x488813, false, "#"); - Write(0x4d8b03, false, "@ "); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#@@"); + Write(0x7fbd39, false, "@#"); + Write(0x427322, false, "@#@ "); Write(0xcccccc, false, "18 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "@@"); - Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "#@"); + Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); Write(0xd0b376, false, "."); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "#@"); + Write(0x1461f, false, "#"); Write(0x427322, false, "@"); - Write(0x1461f, false, "@"); - Write(0x488813, false, "#@"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@"); + Write(0x427322, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@"); Write(0x5eabb4, false, ".."); + Write(0x4d8b03, false, "@@"); + Write(0x7fbd39, false, "#@"); Write(0x488813, false, "#"); - Write(0x427322, false, "#"); - Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); Write(0x427322, false, "#"); - Write(0x1461f, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "#"); + Write(0x488813, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x488813, false, "# "); + Write(0x7fbd39, false, "#"); + Write(0x427322, false, "@"); + Write(0x488813, false, "@ "); Write(0xaaaaaa, false, "/ "); Write(0xe6410b, false, "/ "); Write(0xaaaaaa, false, "\\ "); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "#"); + Write(0x488813, false, "@"); Write(0x427322, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@#"); + Write(0x4d8b03, false, "@"); Write(0x488813, false, "#"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x427322, false, "@# "); + Write(0x1461f, false, "#@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@@# "); Write(0xcccccc, false, "17 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "#"); - Write(0x488813, false, "#"); Write(0x427322, false, "@"); - Write(0x7fbd39, false, "@@"); + Write(0x7fbd39, false, "#"); + Write(0x488813, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@#"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@@@@"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); - Write(0x7fbd39, false, "#@"); - Write(0x488813, false, "#@"); - Write(0x427322, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x1461f, false, "#"); Write(0x7fbd39, false, "@"); Write(0x5eabb4, false, ".."); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "##"); - Write(0x7fbd39, false, "@"); Write(0x488813, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "#"); + Write(0x4d8b03, false, "@@"); + Write(0x427322, false, "@"); Write(0x1461f, false, "@"); + Write(0x488813, false, "@"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@"); Write(0xaaaaaa, false, "/ "); Write(0xe6410b, false, "/ \\ "); Write(0xaaaaaa, false, "\\"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); - Write(0x4d8b03, false, "#"); - Write(0x427322, false, "@@"); - Write(0x1461f, false, "@@"); - Write(0x488813, false, "@"); - Write(0x427322, false, "@@"); - Write(0x1461f, false, "#"); - Write(0x427322, false, "# "); - Write(0xcccccc, false, "16 "); - Write(0xffff66, false, "**\n "); - Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@@"); + Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "#"); Write(0x427322, false, "#"); Write(0x7fbd39, false, "#"); Write(0x427322, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@"); - Write(0x427322, false, "@#"); Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "#@"); + Write(0x4d8b03, false, "@ "); + Write(0xcccccc, false, "16 "); + Write(0xffff66, false, "**\n "); Write(0x488813, false, "#"); - Write(0x427322, false, "_"); - Write(0x5eabb4, false, ".~."); - Write(0x4d8b03, false, "_"); - Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#"); Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x1461f, false, "@"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "#"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "@"); + Write(0x1461f, false, "@"); + Write(0x4d8b03, false, "_"); + Write(0x5eabb4, false, ".~."); + Write(0x427322, false, "_"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); Write(0x427322, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "#"); + Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "@#"); Write(0xaaaaaa, false, ".'"); Write(0xe6410b, false, "/\\"); Write(0xaaaaaa, false, ".'"); Write(0xe6410b, false, "~"); Write(0xaaaaaa, false, ". "); - Write(0x488813, false, "#"); - Write(0x427322, false, "@@"); - Write(0x7fbd39, false, "#@"); - Write(0x1461f, false, "#"); - Write(0x7fbd39, false, "##"); - Write(0x427322, false, "###"); - Write(0x1461f, false, "@ "); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@@"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@"); + Write(0x4d8b03, false, "@@# "); Write(0xcccccc, false, "15 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "#@"); - Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "@@"); + Write(0x488813, false, "@"); Write(0xd0b376, false, "."); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); Write(0x1461f, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); + Write(0x488813, false, "@"); + Write(0x427322, false, "@"); + Write(0x1461f, false, "#"); Write(0x488813, false, "#"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "#"); - Write(0x427322, false, "@@ "); + Write(0x4d8b03, false, "#"); + Write(0x1461f, false, "@ "); Write(0xffffff, false, "||| "); Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "#@"); + Write(0x488813, false, "@#"); + Write(0x4d8b03, false, "@"); Write(0x427322, false, "@"); - Write(0x685c46, false, "|"); - Write(0x488813, false, "@"); - Write(0x427322, false, "@@"); - Write(0x7fbd39, false, "@"); Write(0xaaaaaa, false, "'."); Write(0xe6410b, false, "~"); Write(0xaaaaaa, false, ".'"); @@ -451,201 +457,205 @@ public void Show() { Write(0xaaaaaa, false, ". "); Write(0xe6410b, false, "\\"); Write(0xaaaaaa, false, "'."); - Write(0x488813, false, "@@#"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x427322, false, "#"); Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); + Write(0x1461f, false, "@"); + Write(0x427322, false, "#"); + Write(0x488813, false, "@"); Write(0x427322, false, "@"); - Write(0x1461f, false, "@@@"); - Write(0x4d8b03, false, "@ "); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "# "); Write(0xcccccc, false, "14 "); Write(0xffff66, false, "**\n "); - Write(0x7fbd39, false, "@@"); - Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "@"); Write(0x427322, false, "@"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "##"); - Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x1461f, false, "@#"); + Write(0x4d8b03, false, "@"); Write(0x488813, false, "#"); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@@"); - Write(0x7fbd39, false, "#"); + Write(0x1461f, false, "@"); + Write(0x427322, false, "@@"); + Write(0x488813, false, "@"); Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "#"); Write(0xffffff, false, "~~~"); - Write(0x7fbd39, false, "@"); - Write(0x427322, false, "##"); - Write(0x488813, false, "@"); - Write(0x685c46, false, "|"); - Write(0x427322, false, "@@"); + Write(0x1461f, false, "#"); + Write(0x427322, false, "@"); Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@#"); + Write(0x488813, false, "#"); Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "@"); Write(0xaaaaaa, false, "' ..'.'."); Write(0xe6410b, false, "\\"); Write(0xaaaaaa, false, ". . "); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "#"); Write(0x427322, false, "@"); - Write(0x488813, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@ "); - Write(0xcccccc, false, "13 "); - Write(0xffff66, false, "**\n "); - Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x4d8b03, false, "@@"); - Write(0x1461f, false, "@"); Write(0x427322, false, "#"); - Write(0x4d8b03, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "@@ "); + Write(0xcccccc, false, "13 "); + Write(0xffff66, false, "**\n "); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "#@"); - Write(0x7fbd39, false, "@"); - Write(0x427322, false, "#"); - Write(0x5eabb4, false, ".~~."); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "#"); + Write(0x1461f, false, "@"); + Write(0x488813, false, "#@"); + Write(0x4d8b03, false, "@@@@"); Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x5eabb4, false, ".~~."); + Write(0x427322, false, "@"); + Write(0x488813, false, "#@"); + Write(0x1461f, false, "#"); + Write(0x7fbd39, false, "#"); Write(0x488813, false, "@"); Write(0x7fbd39, false, "#@"); - Write(0x4d8b03, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "##"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); Write(0x1461f, false, "@"); Write(0xaaaaaa, false, " .'."); Write(0xe6410b, false, "~~~"); Write(0xaaaaaa, false, "' "); - Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); Write(0xaaaaaa, false, "'"); - Write(0x4d8b03, false, "@"); Write(0x1461f, false, "@"); - Write(0x427322, false, "@#"); - Write(0x4d8b03, false, "# "); + Write(0x4d8b03, false, "#"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "#@ "); Write(0xcccccc, false, "12 "); Write(0xffff66, false, "**\n "); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@@"); - Write(0xd0b376, false, "."); - Write(0x488813, false, "@"); - Write(0x427322, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); Write(0x1461f, false, "@"); - Write(0x427322, false, "@"); - Write(0x4d8b03, false, "#"); + Write(0xd0b376, false, "."); Write(0x7fbd39, false, "@"); - Write(0x5eabb4, false, ".~~."); - Write(0x4d8b03, false, "@@"); - Write(0x488813, false, "@"); + Write(0x427322, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x488813, false, "#"); - Write(0x7fbd39, false, "#@"); + Write(0x1461f, false, "@"); Write(0x427322, false, "@"); Write(0x4d8b03, false, "@"); + Write(0x5eabb4, false, ".~~."); Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "#"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "@@"); + Write(0x427322, false, "#"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "@@"); + Write(0x427322, false, "##"); + Write(0x1461f, false, "@"); Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); - Write(0x427322, false, "@"); - Write(0x7fbd39, false, "@@ "); + Write(0x4d8b03, false, "#"); + Write(0x427322, false, "##"); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@ "); Write(0xe6410b, false, "~~~~~"); Write(0xaaaaaa, false, ".."); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x427322, false, "#"); Write(0x7fbd39, false, "@"); - Write(0x427322, false, "@@ "); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "##"); + Write(0x7fbd39, false, "#"); + Write(0x1461f, false, "# "); Write(0xcccccc, false, "11 "); Write(0xffff66, false, "**\n "); - Write(0x4d8b03, false, "#"); - Write(0x7fbd39, false, "#@"); + Write(0x7fbd39, false, "##"); + Write(0x488813, false, "#"); Write(0xd0b376, false, "."); - Write(0x7fbd39, false, "#@@@@"); - Write(0x427322, false, "@"); + Write(0x1461f, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x427322, false, "@"); + Write(0x1461f, false, "@"); + Write(0x427322, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "#"); Write(0x5eabb4, false, ".~~."); - Write(0x488813, false, "#@"); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "@#"); + Write(0x427322, false, "#@"); + Write(0x488813, false, "##"); Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); - Write(0x488813, false, "@"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "#"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x427322, false, "@@"); + Write(0x488813, false, "#"); + Write(0x427322, false, "#"); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@@"); + Write(0x4d8b03, false, "#"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@"); Write(0xaaaaaa, false, ".'"); Write(0xe6410b, false, "/ ~~~ \\"); Write(0xaaaaaa, false, "' "); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "#"); + Write(0x488813, false, "@#"); Write(0x427322, false, "@"); - Write(0x488813, false, "@# "); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "@ "); Write(0xcccccc, false, "10 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "@"); + Write(0x1461f, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x488813, false, "@#"); - Write(0xd0b376, false, "."); + Write(0x427322, false, "#"); Write(0x488813, false, "#"); - Write(0x1461f, false, "@ "); + Write(0xd0b376, false, "."); + Write(0x488813, false, "@"); + Write(0x427322, false, "@ "); Write(0xaaaaaa, false, "_"); Write(0xd0b376, false, "|%%%=%%|"); Write(0xaaaaaa, false, "_ "); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "#@"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "#"); - Write(0x488813, false, "@@"); - Write(0x427322, false, "#"); - Write(0x488813, false, "@"); + Write(0x488813, false, "@#"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "#@"); Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@#"); Write(0x488813, false, "@"); Write(0x427322, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#"); Write(0xaaaaaa, false, ". "); Write(0xe6410b, false, "~ /"); Write(0xaaaaaa, false, "' .'"); Write(0xe6410b, false, "/\\"); Write(0xaaaaaa, false, "."); Write(0x488813, false, "@"); - Write(0x427322, false, "@"); - Write(0x488813, false, "#@@ "); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "# "); Write(0xcccccc, false, " 9 "); Write(0xffff66, false, "**\n "); - Write(0x7fbd39, false, "@"); - Write(0x488813, false, "#@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@"); + Write(0x4d8b03, false, "#@"); + Write(0x488813, false, "@@"); + Write(0x1461f, false, "#"); Write(0xd0b376, false, ".."); Write(0xaaaaaa, false, "/ \\"); Write(0x5eabb4, false, ".~~."); Write(0xaaaaaa, false, "/ \\"); Write(0xd0b376, false, "....."); - Write(0x4d8b03, false, "#"); - Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@@"); + Write(0x427322, false, "#"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "#"); + Write(0x488813, false, "#"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@#"); - Write(0x1461f, false, "#"); + Write(0x427322, false, "@@"); Write(0xaaaaaa, false, "' "); Write(0xe6410b, false, "/\\"); Write(0xaaaaaa, false, ".''"); @@ -653,37 +663,36 @@ public void Show() { Write(0xaaaaaa, false, "' "); Write(0xe6410b, false, "\\"); Write(0xaaaaaa, false, "' "); - Write(0x4d8b03, false, "#"); - Write(0x7fbd39, false, "## "); + Write(0x427322, false, "@"); + Write(0x1461f, false, "@"); + Write(0x7fbd39, false, "# "); Write(0xcccccc, false, " 8 "); Write(0xffff66, false, "**\n "); - Write(0x1461f, false, "#"); - Write(0x427322, false, "#"); - Write(0x488813, false, "#"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); - Write(0x4d8b03, false, "@"); Write(0x1461f, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x488813, false, "@#"); - Write(0x4d8b03, false, "#"); - Write(0x5eabb4, false, ".~~."); Write(0x488813, false, "@"); Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@"); + Write(0x7fbd39, false, "@#@"); + Write(0x427322, false, "@@"); + Write(0x488813, false, "@"); + Write(0x1461f, false, "@"); + Write(0x5eabb4, false, ".~~."); + Write(0x4d8b03, false, "#"); + Write(0x427322, false, "#"); + Write(0x1461f, false, "#"); + Write(0x488813, false, "@"); Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); Write(0x427322, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); Write(0xd0b376, false, "."); - Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@"); + Write(0x4d8b03, false, "@@"); Write(0x1461f, false, "@"); - Write(0x427322, false, "@"); - Write(0x488813, false, "@#"); + Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); Write(0xaaaaaa, false, "'."); Write(0xe6410b, false, "/"); Write(0xaaaaaa, false, "."); @@ -695,29 +704,30 @@ public void Show() { Write(0xaaaaaa, false, " '. "); Write(0xcccccc, false, " 7 "); Write(0xffff66, false, "**\n "); - Write(0x1461f, false, "@"); + Write(0x427322, false, "@"); Write(0x488813, false, "@"); - Write(0x7fbd39, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "##"); - Write(0x488813, false, "@"); + Write(0x427322, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x427322, false, "#"); + Write(0x488813, false, "@#"); Write(0x427322, false, "@"); - Write(0x1461f, false, "@"); + Write(0x1461f, false, "#"); + Write(0x7fbd39, false, "@@"); + Write(0x5eabb4, false, ".~~."); + Write(0x7fbd39, false, "@@"); Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x5eabb4, false, ".~~."); - Write(0x7fbd39, false, "@@"); Write(0x488813, false, "@"); - Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "@#"); - Write(0x685c46, false, "|"); Write(0xd0b376, false, ".."); - Write(0x488813, false, "@"); - Write(0x1461f, false, "@"); - Write(0x488813, false, "@@"); - Write(0x427322, false, "#"); Write(0x4d8b03, false, "@"); + Write(0x685c46, false, "|"); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x488813, false, "@"); + Write(0x1461f, false, "#"); Write(0xaaaaaa, false, "' "); Write(0xe6410b, false, "~"); Write(0xaaaaaa, false, ". "); @@ -729,48 +739,49 @@ public void Show() { Write(0xaaaaaa, false, ". "); Write(0xcccccc, false, " 6 "); Write(0xffff66, false, "**\n "); + Write(0x488813, false, "@"); + Write(0x1461f, false, "@"); Write(0x488813, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "#"); - Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@"); + Write(0x4d8b03, false, "#"); Write(0x488813, false, "@"); + Write(0x7fbd39, false, "##"); + Write(0x4d8b03, false, "#"); Write(0x7fbd39, false, "@"); - Write(0x1461f, false, "@@"); - Write(0x427322, false, "@"); - Write(0x488813, false, "#"); - Write(0x427322, false, "@#"); - Write(0x5eabb4, false, ".~~."); Write(0x4d8b03, false, "@"); + Write(0x1461f, false, "@"); + Write(0x427322, false, "@@"); + Write(0x5eabb4, false, ".~~."); + Write(0x7fbd39, false, "#"); Write(0x427322, false, "@"); Write(0xd0b376, false, "."); Write(0xeeeeee, false, "/\\"); Write(0xd0b376, false, ".'"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "#"); - Write(0x1461f, false, "@"); + Write(0x427322, false, "@@"); + Write(0x1461f, false, "#"); + Write(0x488813, false, "##"); Write(0x4d8b03, false, "@"); Write(0x488813, false, "@"); - Write(0x427322, false, "@"); - Write(0x1461f, false, "#"); - Write(0x488813, false, "#"); + Write(0x1461f, false, "@"); Write(0xaaaaaa, false, "'.' .'"); Write(0xe6410b, false, "/"); Write(0xaaaaaa, false, "."); - Write(0x4d8b03, false, "@"); + Write(0x488813, false, "@"); Write(0xaaaaaa, false, ". "); Write(0xe6410b, false, "/"); Write(0xaaaaaa, false, "'."); Write(0xe6410b, false, "~~~ "); Write(0xcccccc, false, " 5 "); Write(0xffff66, false, "**\n "); - Write(0x4d8b03, false, "@#@"); - Write(0x488813, false, "@"); - Write(0x4d8b03, false, "@#"); + Write(0x7fbd39, false, "#"); + Write(0x685c46, false, "|"); + Write(0x4d8b03, false, "@"); Write(0x427322, false, "@"); + Write(0x1461f, false, "@"); Write(0x4d8b03, false, "@"); - Write(0x427322, false, "@@"); - Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "@@"); + Write(0x488813, false, "#"); + Write(0x7fbd39, false, "@"); Write(0xd0b376, false, ".'"); Write(0x5eabb4, false, " ~ "); Write(0xd0b376, false, "'."); @@ -778,12 +789,10 @@ public void Show() { Write(0xd0b376, false, "'."); Write(0xeeeeee, false, "/\\"); Write(0xd0b376, false, "' ."); - Write(0x4d8b03, false, "@"); - Write(0x488813, false, "@"); Write(0x7fbd39, false, "@"); - Write(0x4d8b03, false, "@@"); - Write(0x427322, false, "@"); - Write(0x7fbd39, false, "#"); + Write(0x4d8b03, false, "#@"); + Write(0x427322, false, "@@"); + Write(0x7fbd39, false, "@@"); Write(0xaaaaaa, false, "' "); Write(0xe6410b, false, "/\\"); Write(0xaaaaaa, false, " . "); @@ -791,24 +800,23 @@ public void Show() { Write(0xaaaaaa, false, "'. ..' "); Write(0xcccccc, false, " 4 "); Write(0xffff66, false, "**\n "); - Write(0x427322, false, "@@"); - Write(0x1461f, false, "@"); - Write(0x488813, false, "#"); - Write(0x4d8b03, false, "#@"); + Write(0x4d8b03, false, "@"); Write(0x7fbd39, false, "#"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "#"); + Write(0x4d8b03, false, "@"); + Write(0x7fbd39, false, "#@@"); Write(0xd0b376, false, "_/"); Write(0x5eabb4, false, " ~ ~ "); Write(0xd0b376, false, "\\ ' '. '.'."); - Write(0x7fbd39, false, "#@"); - Write(0x427322, false, "#"); - Write(0x4d8b03, false, "# "); + Write(0x1461f, false, "#"); + Write(0x4d8b03, false, "@@@ "); Write(0xe6410b, false, "/ \\ \\ "); - Write(0x488813, false, "@"); Write(0x427322, false, "@"); - Write(0x4d8b03, false, "@"); - Write(0x7fbd39, false, "@ "); + Write(0x488813, false, "@"); + Write(0x7fbd39, false, "@"); + Write(0x427322, false, "@ "); Write(0xcccccc, false, " 3 "); Write(0xffff66, false, "**\n "); Write(0xd0b376, false, "-~------'"); @@ -824,7 +832,7 @@ public void Show() { Console.WriteLine(); } - private static void Write(int rgb, bool bold, string text){ + private static void Write(int rgb, bool bold, string text){ Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); - } -} + } +} \ No newline at end of file diff --git a/2022/calendar.svg b/2022/calendar.svg index fe3a33d50..7b4b0c60b 100644 --- a/2022/calendar.svg +++ b/2022/calendar.svg @@ -1,4 +1,4 @@ - + fifty stars by December 25th. -Wait a minute, huhh... what is this? _Oneight?_ What does this even mean? Usually such weird -cases are mentioned in the example input, but not this time! Is it '1', '8' or '18'? Depending on -how one interpreted the problem statement he could spent quite a lot of time on figuring this out. - -I think this was a little bit of an oversight for day 1, but let's see what's up for tomorrow! +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2023/day/1) description._ diff --git a/2023/Day01/illustration.jpeg b/2023/Day01/illustration.jpeg new file mode 100644 index 000000000..2764a9495 Binary files /dev/null and b/2023/Day01/illustration.jpeg differ diff --git a/2023/Day02/illustration.jpeg b/2023/Day02/illustration.jpeg new file mode 100644 index 000000000..78bdd14ad Binary files /dev/null and b/2023/Day02/illustration.jpeg differ diff --git a/2023/Day03/illustration.jpeg b/2023/Day03/illustration.jpeg new file mode 100644 index 000000000..c31a3973a Binary files /dev/null and b/2023/Day03/illustration.jpeg differ diff --git a/2023/Day04/illustration.jpeg b/2023/Day04/illustration.jpeg new file mode 100644 index 000000000..04e0b6e6d Binary files /dev/null and b/2023/Day04/illustration.jpeg differ diff --git a/2023/Day05/illustration.jpeg b/2023/Day05/illustration.jpeg new file mode 100644 index 000000000..228173ece Binary files /dev/null and b/2023/Day05/illustration.jpeg differ diff --git a/2023/Day06/illustration.jpeg b/2023/Day06/illustration.jpeg new file mode 100644 index 000000000..04ff19cd6 Binary files /dev/null and b/2023/Day06/illustration.jpeg differ diff --git a/2023/Day07/illustration.jpeg b/2023/Day07/illustration.jpeg new file mode 100644 index 000000000..beb93d335 Binary files /dev/null and b/2023/Day07/illustration.jpeg differ diff --git a/2023/Day08/illustration.jpeg b/2023/Day08/illustration.jpeg new file mode 100644 index 000000000..f4243ea87 Binary files /dev/null and b/2023/Day08/illustration.jpeg differ diff --git a/2023/Day09/illustration.jpeg b/2023/Day09/illustration.jpeg new file mode 100644 index 000000000..aa73a2304 Binary files /dev/null and b/2023/Day09/illustration.jpeg differ diff --git a/2023/Day10/illustration.jpeg b/2023/Day10/illustration.jpeg new file mode 100644 index 000000000..032b77df4 Binary files /dev/null and b/2023/Day10/illustration.jpeg differ diff --git a/2023/Day11/illustration.jpeg b/2023/Day11/illustration.jpeg new file mode 100644 index 000000000..542eb6e96 Binary files /dev/null and b/2023/Day11/illustration.jpeg differ diff --git a/2023/Day12/illustration.jpeg b/2023/Day12/illustration.jpeg new file mode 100644 index 000000000..21c6ccdb3 Binary files /dev/null and b/2023/Day12/illustration.jpeg differ diff --git a/2023/Day13/illustration.jpeg b/2023/Day13/illustration.jpeg new file mode 100644 index 000000000..034cf2d83 Binary files /dev/null and b/2023/Day13/illustration.jpeg differ diff --git a/2023/Day14/illustration.jpeg b/2023/Day14/illustration.jpeg new file mode 100644 index 000000000..3d5dbea0f Binary files /dev/null and b/2023/Day14/illustration.jpeg differ diff --git a/2023/Day15/illustration.jpeg b/2023/Day15/illustration.jpeg new file mode 100644 index 000000000..a338e9416 Binary files /dev/null and b/2023/Day15/illustration.jpeg differ diff --git a/2023/Day16/illustration.jpeg b/2023/Day16/illustration.jpeg new file mode 100644 index 000000000..bd921cad4 Binary files /dev/null and b/2023/Day16/illustration.jpeg differ diff --git a/2023/Day17/illustration.jpeg b/2023/Day17/illustration.jpeg new file mode 100644 index 000000000..8c04f08d7 Binary files /dev/null and b/2023/Day17/illustration.jpeg differ diff --git a/2023/Day18/illustration.jpeg b/2023/Day18/illustration.jpeg new file mode 100644 index 000000000..2d45b35ee Binary files /dev/null and b/2023/Day18/illustration.jpeg differ diff --git a/2023/Day19/illustration.jpeg b/2023/Day19/illustration.jpeg new file mode 100644 index 000000000..bc8956993 Binary files /dev/null and b/2023/Day19/illustration.jpeg differ diff --git a/2023/Day20/README.md b/2023/Day20/README.md index d486557da..607ee92ad 100644 --- a/2023/Day20/README.md +++ b/2023/Day20/README.md @@ -2,14 +2,13 @@ The task description is copyrighted, but it's available [here](https://adventofcode.com/2023/day/20). I modeled Part 1 following the description closely. I didn't want to introduce separate -classes for the gate types, instead I used a function parameter that maps signals to signals. -I tells what should be emitted when a signal is received by the gate. I know that this is -Elf logic, but it's 🎄, what did you expect? I have one constructor function for each -gate type (Nand, FlipFlop and Repeater) these declare the necessary state variables -and capture it in the returned lambda. Everything is self contained, I have a single Gate type, -yet different behavior. +classes for the gate types, instead created just one Gate type with a function parameter that defines the inner logic. It basically tells what should be emitted when a signal comes in the gate's input. -I made a function that triggers the button and executes all the logic until things settle down. +Building on this, I defined factory functions for each +gate type (Nand, FlipFlop and Repeater). I know that this is +Elf logic, but it's 🎄, what did you expect? + +I added a function that triggers the button and executes all the logic until things settle down. It returns all signals that were emitted, so that I can work with them in both parts. I think Part 1 doesn't need more explanation. Part 2 however, is a different beast. It's a _reverse diff --git a/2023/Day20/illustration.jpeg b/2023/Day20/illustration.jpeg new file mode 100644 index 000000000..772a67c58 Binary files /dev/null and b/2023/Day20/illustration.jpeg differ diff --git a/2023/Day21/illustration.jpeg b/2023/Day21/illustration.jpeg new file mode 100644 index 000000000..843c9e1ce Binary files /dev/null and b/2023/Day21/illustration.jpeg differ diff --git a/2023/Day22/illustration.jpeg b/2023/Day22/illustration.jpeg new file mode 100644 index 000000000..135992b9f Binary files /dev/null and b/2023/Day22/illustration.jpeg differ diff --git a/2023/Day23/illustration.jpeg b/2023/Day23/illustration.jpeg new file mode 100644 index 000000000..cdd403505 Binary files /dev/null and b/2023/Day23/illustration.jpeg differ diff --git a/2023/Day24/illustration.jpeg b/2023/Day24/illustration.jpeg new file mode 100644 index 000000000..77f5b727e Binary files /dev/null and b/2023/Day24/illustration.jpeg differ diff --git a/2023/Day25/illustration.jpeg b/2023/Day25/illustration.jpeg new file mode 100644 index 000000000..42399f317 Binary files /dev/null and b/2023/Day25/illustration.jpeg differ diff --git a/2023/SplashScreen.cs b/2023/SplashScreen.cs index 99553604a..d5f9a011a 100644 --- a/2023/SplashScreen.cs +++ b/2023/SplashScreen.cs @@ -8,8 +8,8 @@ public void Show() { var color = Console.ForegroundColor; Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); - Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /^2023$/\n \n "); - Write(0xcc00, false, " "); + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ $year = 2023\n "); + Write(0xcc00, false, "\n "); Write(0xa25151, false, "...'''''''''... \n .'' "); Write(0xdf2308, true, "~"); Write(0xa5a8af, false, "/\\"); diff --git a/2023/calendar.svg b/2023/calendar.svg index 7effa5b89..e515150c5 100644 --- a/2023/calendar.svg +++ b/2023/calendar.svg @@ -1,4 +1,4 @@ - + Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit. + +As each location is checked, they will mark it on their list with a star. They figure the Chief Historian must be in one of the first fifty places they'll look, so in order to save Christmas, you need to help them get fifty stars on their list before Santa takes off on December 25th. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/1) description._ diff --git a/2024/Day01/Solution.cs b/2024/Day01/Solution.cs new file mode 100644 index 000000000..3b440af39 --- /dev/null +++ b/2024/Day01/Solution.cs @@ -0,0 +1,29 @@ +namespace AdventOfCode.Y2024.Day01; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; + +[ProblemName("Historian Hysteria")] +class Solution : Solver { + + public object PartOne(string input) => + // go over the sorted columns pairwise and sum the difference of the pairs + Enumerable.Zip(Column(input, 0), Column(input, 1)) + .Select(p => Math.Abs(p.First - p.Second)) + .Sum(); + + public object PartTwo(string input) { + // sum the elements of the left column weighted by its occurrences in the right + // ⭐ .Net 9 comes with a new CountBy function + var weights = Column(input, 1).CountBy(x=>x).ToDictionary(); + return Column(input, 0).Select(num => weights.GetValueOrDefault(num) * num).Sum(); + } + + IEnumerable Column(string input, int column) => + from line in input.Split("\n") + let nums = line.Split(" ").Select(int.Parse).ToArray() + orderby nums[column] + select nums[column]; +} diff --git a/2024/Day01/illustration.jpeg b/2024/Day01/illustration.jpeg new file mode 100644 index 000000000..c5dbd40d7 Binary files /dev/null and b/2024/Day01/illustration.jpeg differ diff --git a/2024/Day01/input.in b/2024/Day01/input.in new file mode 100644 index 000000000..8eba02d04 Binary files /dev/null and b/2024/Day01/input.in differ diff --git a/2024/Day01/input.refout b/2024/Day01/input.refout new file mode 100644 index 000000000..85ba5a423 --- /dev/null +++ b/2024/Day01/input.refout @@ -0,0 +1,2 @@ +2904518 +18650129 \ No newline at end of file diff --git a/2024/Day02/README.md b/2024/Day02/README.md new file mode 100644 index 000000000..ba6e3516b --- /dev/null +++ b/2024/Day02/README.md @@ -0,0 +1,10 @@ +## --- Day 2: Red-Nosed Reports --- +Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. + +While the _Red-Nosed Reindeer nuclear fusion/fission plant_ appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/2) description._ + +I created a function to check the validity of a single input line. This is achieved using the usual method of _zipping_ the input with itself to generate a list of consecutive pairs. The next step involves checking the monotonicity condition (either increasing or decreasing) for each pair. + +The second part of the problem is addressed with another helper function. This function takes an input sequence and generates attenuated versions of it in all possible ways, by omitting _zero_ or _one_ elements from the sample. \ No newline at end of file diff --git a/2024/Day02/Solution.cs b/2024/Day02/Solution.cs new file mode 100644 index 000000000..8f07d7144 --- /dev/null +++ b/2024/Day02/Solution.cs @@ -0,0 +1,36 @@ +namespace AdventOfCode.Y2024.Day02; + +using System; +using System.Collections.Generic; +using System.Linq; + +[ProblemName("Red-Nosed Reports")] +class Solution : Solver { + + public object PartOne(string input) => + ParseSamples(input).Count(Valid); + + public object PartTwo(string input) => + ParseSamples(input).Count(samples => Attenuate(samples).Any(Valid)); + + IEnumerable ParseSamples(string input) => + from line in input.Split("\n") + let samples = line.Split(" ").Select(int.Parse) + select samples.ToArray(); + + // Generates all possible variations of the input sequence by omitting + // either zero or one element from it. + IEnumerable Attenuate(int[] samples) => + from i in Enumerable.Range(0, samples.Length+1) + let before = samples.Take(i - 1) + let after = samples.Skip(i) + select Enumerable.Concat(before, after).ToArray(); + + // Checks the monothinicity condition by examining consecutive elements + bool Valid(int[] samples) { + var pairs = Enumerable.Zip(samples, samples.Skip(1)); + return + pairs.All(p => 1 <= p.Second - p.First && p.Second - p.First <= 3) || + pairs.All(p => 1 <= p.First - p.Second && p.First - p.Second <= 3); + } +} diff --git a/2024/Day02/illustration.jpeg b/2024/Day02/illustration.jpeg new file mode 100644 index 000000000..cebc32454 Binary files /dev/null and b/2024/Day02/illustration.jpeg differ diff --git a/2024/Day02/input.in b/2024/Day02/input.in new file mode 100644 index 000000000..2ceeb0950 Binary files /dev/null and b/2024/Day02/input.in differ diff --git a/2024/Day02/input.refout b/2024/Day02/input.refout new file mode 100644 index 000000000..2e38115b0 --- /dev/null +++ b/2024/Day02/input.refout @@ -0,0 +1,2 @@ +202 +271 \ No newline at end of file diff --git a/2024/Day03/README.md b/2024/Day03/README.md new file mode 100644 index 000000000..c437cf887 --- /dev/null +++ b/2024/Day03/README.md @@ -0,0 +1,8 @@ +## --- Day 3: Mull It Over --- +"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the [North Pole Toboggan Rental Shop](/2020/day/2). The Historians head out to take a look. + +The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?" + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/3) description._ + +I took a functional approach today. Regular expressions are ugly beasts, I normally try avoid them. Fortunately, we're not writing production code here. Otherwise... everything is just a fold if you look at it from a distance. diff --git a/2024/Day03/Solution.cs b/2024/Day03/Solution.cs new file mode 100644 index 000000000..292cf926f --- /dev/null +++ b/2024/Day03/Solution.cs @@ -0,0 +1,29 @@ +namespace AdventOfCode.Y2024.Day03; + +using System.Linq; +using System.Text.RegularExpressions; + +[ProblemName("Mull It Over")] +class Solution : Solver { + + public object PartOne(string input) => Solve(input, @"mul\((\d{1,3}),(\d{1,3})\)"); + + public object PartTwo(string input) => Solve(input, @"mul\((\d{1,3}),(\d{1,3})\)|don't\(\)|do\(\)"); + + long Solve(string input, string rx) { + // overly functionaly approach... + var matches = Regex.Matches(input, rx, RegexOptions.Multiline); + return matches.Aggregate( + (enabled: true, res: 0L), + (acc, m) => + (m.Value, acc.res, acc.enabled) switch { + ("don't()", _, _) => (false, acc.res), + ("do()", _, _) => (true, acc.res), + (_, var res, true) => + (true, res + int.Parse(m.Groups[1].Value) * int.Parse(m.Groups[2].Value)), + _ => acc + }, + acc => acc.res + ); + } +} \ No newline at end of file diff --git a/2024/Day03/illustration.jpeg b/2024/Day03/illustration.jpeg new file mode 100644 index 000000000..e19c0a13b Binary files /dev/null and b/2024/Day03/illustration.jpeg differ diff --git a/2024/Day03/input.in b/2024/Day03/input.in new file mode 100644 index 000000000..46d2a13b9 Binary files /dev/null and b/2024/Day03/input.in differ diff --git a/2024/Day03/input.refout b/2024/Day03/input.refout new file mode 100644 index 000000000..b4d21cde1 --- /dev/null +++ b/2024/Day03/input.refout @@ -0,0 +1,2 @@ +165225049 +108830766 \ No newline at end of file diff --git a/2024/Day04/README.md b/2024/Day04/README.md new file mode 100644 index 000000000..830b6cf4e --- /dev/null +++ b/2024/Day04/README.md @@ -0,0 +1,11 @@ +## --- Day 4: Ceres Search --- +"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the __Ceres monitoring station__! +As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; she'd like to know if you could help her with her word search. She only has to find one word: XMAS. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/4) description._ + +I employed my proven tactic of converting the input into a dictionary, using coordinates as keys. This approach makes it straightforward to iterate over the keys and check whether they fall within the bounds of the map. + +Representing coordinates with complex numbers is another effective technique for handling steps in various directions. + +The algorithm itself is a straightforward brute-force check of all starting positions and reading orders. diff --git a/2024/Day04/Solution.cs b/2024/Day04/Solution.cs new file mode 100644 index 000000000..b5cfcc9fd --- /dev/null +++ b/2024/Day04/Solution.cs @@ -0,0 +1,61 @@ +namespace AdventOfCode.Y2024.Day04; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Numerics; +using System.Linq; + +using Map = System.Collections.Immutable.ImmutableDictionary; + +[ProblemName("Ceres Search")] +class Solution : Solver { + + Complex Up = -Complex.ImaginaryOne; + Complex Down = Complex.ImaginaryOne; + Complex Left = -1; + Complex Right = 1; + + public object PartOne(string input) { + var mat = GetMap(input); + return ( + from pt in mat.Keys + from dir in new[] { Right, Right + Down, Down + Left, Down} + where Matches(mat, pt, dir, "XMAS") + select 1 + ).Count(); + } + + public object PartTwo(string input) { + var mat = GetMap(input); + return ( + from pt in mat.Keys + where + Matches(mat, pt + Up + Left, Down + Right, "MAS") && + Matches(mat, pt + Down + Left, Up + Right, "MAS") + select 1 + ).Count(); + } + + // check if the pattern (or its reverse) can be read in the given direction + // starting from pt + bool Matches(Map map, Complex pt, Complex dir, string pattern) { + var chars = Enumerable.Range(0, pattern.Length) + .Select(i => map.GetValueOrDefault(pt + i * dir)) + .ToArray(); + return + Enumerable.SequenceEqual(chars, pattern) || + Enumerable.SequenceEqual(chars, pattern.Reverse()); + } + + // store the points in a dictionary so that we can iterate over them and + // to easily deal with points outside the area using GetValueOrDefault + Map GetMap(string input) { + var map = input.Split("\n"); + return ( + from y in Enumerable.Range(0, map.Length) + from x in Enumerable.Range(0, map[0].Length) + select new KeyValuePair(Complex.ImaginaryOne * y + x, map[y][x]) + ).ToImmutableDictionary(); + } +} \ No newline at end of file diff --git a/2024/Day04/illustration.jpeg b/2024/Day04/illustration.jpeg new file mode 100644 index 000000000..a5fdc0918 Binary files /dev/null and b/2024/Day04/illustration.jpeg differ diff --git a/2024/Day04/input.in b/2024/Day04/input.in new file mode 100644 index 000000000..9f76d332e Binary files /dev/null and b/2024/Day04/input.in differ diff --git a/2024/Day04/input.refout b/2024/Day04/input.refout new file mode 100644 index 000000000..947b78a71 --- /dev/null +++ b/2024/Day04/input.refout @@ -0,0 +1,2 @@ +2414 +1871 \ No newline at end of file diff --git a/2024/Day05/README.md b/2024/Day05/README.md new file mode 100644 index 000000000..6f40cba61 --- /dev/null +++ b/2024/Day05/README.md @@ -0,0 +1,12 @@ +## --- Day 5: Print Queue --- +Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. + +The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically significant facility, an Elf operating a **very familiar printer** beckons you over. + +The Elf must recognize you, because they waste no time explaining that the new sleigh launch safety manual updates won't print correctly. Failure to update the safety manuals would be dire indeed, so you offer your services. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/5) description._ + +The constraints in both my input and the provided sample input define a total ordering of the pages, which I leveraged in my solution. (*) I implemented a custom parser that returns the list of updates to be printed and a page comparison function. That's all we need. In `Part1`, we check which updates are in the correct order, while in `Part2`, we handle the remaining updates by applying .NET's built-in `OrderBy` function with our custom comparer. + +(*) others say that the ordering is not total, in fact there are loops in it. But it was not an issue for the update lines we need to sort. So the thing below works only because of the Elf magic of X-mas. diff --git a/2024/Day05/Solution.cs b/2024/Day05/Solution.cs new file mode 100644 index 000000000..e25ef7a09 --- /dev/null +++ b/2024/Day05/Solution.cs @@ -0,0 +1,40 @@ +namespace AdventOfCode.Y2024.Day05; + +using System.Collections.Generic; +using System.Linq; + +[ProblemName("Print Queue")] +class Solution : Solver { + + public object PartOne(string input) { + var (updates, comparer) = Parse(input); + return updates + .Where(pages => Sorted(pages, comparer)) + .Sum(GetMiddlePage); + } + + public object PartTwo(string input) { + var (updates, comparer) = Parse(input); + return updates + .Where(pages => !Sorted(pages, comparer)) + .Select(pages => pages.OrderBy(p => p, comparer).ToArray()) + .Sum(GetMiddlePage); + } + + (string[][] updates, Comparer) Parse(string input) { + var parts = input.Split("\n\n"); + + var ordering = new HashSet(parts[0].Split("\n")); + var comparer = + Comparer.Create((p1, p2) => ordering.Contains(p1 + "|" + p2) ? -1 : 1); + + var updates = parts[1].Split("\n").Select(line => line.Split(",")).ToArray(); + return (updates, comparer); + } + + int GetMiddlePage(string[] nums) => int.Parse(nums[nums.Length / 2]); + + bool Sorted(string[] pages, Comparer comparer) => + Enumerable.SequenceEqual(pages, pages.OrderBy(x=>x, comparer)); + +} diff --git a/2024/Day05/illustration.jpeg b/2024/Day05/illustration.jpeg new file mode 100644 index 000000000..d270b7fa4 Binary files /dev/null and b/2024/Day05/illustration.jpeg differ diff --git a/2024/Day05/input.in b/2024/Day05/input.in new file mode 100644 index 000000000..258e15c8b Binary files /dev/null and b/2024/Day05/input.in differ diff --git a/2024/Day05/input.refout b/2024/Day05/input.refout new file mode 100644 index 000000000..4d6180ed3 --- /dev/null +++ b/2024/Day05/input.refout @@ -0,0 +1,2 @@ +4790 +6319 \ No newline at end of file diff --git a/2024/Day06/README.md b/2024/Day06/README.md new file mode 100644 index 000000000..2a908234f --- /dev/null +++ b/2024/Day06/README.md @@ -0,0 +1,14 @@ +## --- Day 6: Guard Gallivant --- +The Historians use their fancy __device__ again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year __1518__! It turns out that having direct access to history is very convenient for a group of historians. + +You still have to be careful of time paradoxes, and so it will be important to avoid anyone from 1518 while The Historians search for the Chief. Unfortunately, a single guard is patrolling this part of the lab. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/6) description._ + +This has been a straightforward implementation challenge. I wrote a `Walk` function that tracks the guard's movement and returns the visited locations. It also determines whether the guard enters a loop or exits the grid. `Part1` utilizes only the location information, while `Part2` adds blockers along the guard's path and counts the instances where he starts walking in a cycle. + +To make a 90º turn in 2D you need swap the coordinates and multiply _one_ of them by -1. The turn can be clockwise or counterclockwise, it depends on which coordinate was multiplied. + +Here we use complex numbers to represent coordinates, and we get the same effect by simply multiplying with ImaginaryOne or `i`. `-i` turns right, and `i` to left (but this depends on how you draw your coordinate system of course, 'i' points upwards in mine). + +It's not complicated at all, but if sounds a bit magical to You, try it out on a few vectors by hand. diff --git a/2024/Day06/Solution.cs b/2024/Day06/Solution.cs new file mode 100644 index 000000000..9b493893e --- /dev/null +++ b/2024/Day06/Solution.cs @@ -0,0 +1,63 @@ +namespace AdventOfCode.Y2024.Day06; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; +using Map = System.Collections.Immutable.ImmutableDictionary; + +[ProblemName("Guard Gallivant")] +class Solution : Solver { + + Complex Up = Complex.ImaginaryOne; + Complex TurnRight = -Complex.ImaginaryOne; + + public object PartOne(string input) { + var (map, start) = Parse(input); + return Walk(map, start).positions.Count(); + } + + public object PartTwo(string input) { + var (map, start) = Parse(input); + // try a blocker in each locations visited by the guard counting the loops + return Walk(map, start).positions + .AsParallel() + .Count(pos => Walk(map.SetItem(pos, '#'), start).isLoop); + + } + + // returns the positions visited when starting from 'pos', isLoop is set if the + // guard enters a cycle. + (IEnumerable positions, bool isLoop) Walk(Map map, Complex pos) { + var seen = new HashSet<(Complex pos, Complex dir)>(); + var dir = Up; + while (map.ContainsKey(pos) && !seen.Contains((pos, dir))) { + seen.Add((pos, dir)); + if (map.GetValueOrDefault(pos + dir) == '#') { + dir *= TurnRight; + } else { + pos += dir; + } + } + return ( + positions: seen.Select(s => s.pos).Distinct(), + isLoop: seen.Contains((pos, dir)) + ); + } + + // store the grid in a dictionary, to make bounds checks and navigation simple + // start represents the starting postion of the guard + (Map map, Complex start) Parse(string input) { + var lines = input.Split("\n"); + var map = ( + from y in Enumerable.Range(0, lines.Length) + from x in Enumerable.Range(0, lines[0].Length) + select new KeyValuePair(-Up * y + x, lines[y][x]) + ).ToImmutableDictionary(); + + var start = map.First(x => x.Value == '^').Key; + + return (map, start); + } +} \ No newline at end of file diff --git a/2024/Day06/illustration.jpeg b/2024/Day06/illustration.jpeg new file mode 100644 index 000000000..62e5e4349 Binary files /dev/null and b/2024/Day06/illustration.jpeg differ diff --git a/2024/Day06/input.in b/2024/Day06/input.in new file mode 100644 index 000000000..6d740e90a Binary files /dev/null and b/2024/Day06/input.in differ diff --git a/2024/Day06/input.refout b/2024/Day06/input.refout new file mode 100644 index 000000000..cd63e0fc5 --- /dev/null +++ b/2024/Day06/input.refout @@ -0,0 +1,2 @@ +4789 +1304 \ No newline at end of file diff --git a/2024/Day07/README.md b/2024/Day07/README.md new file mode 100644 index 000000000..902b0774d --- /dev/null +++ b/2024/Day07/README.md @@ -0,0 +1,12 @@ +## --- Day 7: Bridge Repair --- +The Historians take you to a familiar _rope bridge_ over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? + +When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/7) description._ + +It's time to pull out the recursion guns. I introduced a checker logic that goes through the numbers in one line of input and tries all possible operators on the accumulated result to reach the target. + +The common logic that parses the input and executes the checker was extracted into a single `Solve` function, but I found it more readable to have distinct checkers for the two parts of the problem. + +Everything runs in about a second, but since it's just a single line, I couldn't stand and added an optimization in `Check2` to exit early when the accumulated result exceeds the target. diff --git a/2024/Day07/Solution.cs b/2024/Day07/Solution.cs new file mode 100644 index 000000000..2cb0af10a --- /dev/null +++ b/2024/Day07/Solution.cs @@ -0,0 +1,41 @@ +namespace AdventOfCode.Y2024.Day07; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +[ProblemName("Bridge Repair")] +class Solution : Solver { + + public object PartOne(string input) => Filter(input, Check1).Sum(); + public object PartTwo(string input) => Filter(input, Check2).Sum(); + + // returns those calibrations that are valid according to the checker + private IEnumerable Filter(string input, Func, bool> check) => + from line in input.Split("\n") + let parts = Regex.Matches(line, @"\d+").Select(m=>long.Parse(m.Value)) + let target = parts.First() + let nums = parts.Skip(1).ToList() + where check(target, nums[0], nums[1..]) + select target; + + // separate checkers provided for the two parts, these recursive functions go + // over the numbers and use all allowed operators to update the accumulated result. + // at the end of the recursion we simply check if we reached the target + private bool Check1(long target, long acc, List nums) => + nums switch { + [] => target == acc, + _ => Check1(target, acc * nums[0], nums[1..]) || + Check1(target, acc + nums[0], nums[1..]) + }; + + private bool Check2(long target, long acc, List nums) => + nums switch { + _ when acc > target => false, // optimization: early exit from deadend + [] => target == acc, + _ => Check2(target, long.Parse($"{acc}{nums[0]}"), nums[1..]) || + Check2(target, acc * nums[0], nums[1..]) || + Check2(target, acc + nums[0], nums[1..]) + }; +} diff --git a/2024/Day07/illustration.jpeg b/2024/Day07/illustration.jpeg new file mode 100644 index 000000000..f08fd6f20 Binary files /dev/null and b/2024/Day07/illustration.jpeg differ diff --git a/2024/Day07/input.in b/2024/Day07/input.in new file mode 100644 index 000000000..723bf50a4 Binary files /dev/null and b/2024/Day07/input.in differ diff --git a/2024/Day07/input.refout b/2024/Day07/input.refout new file mode 100644 index 000000000..7a69a12ba --- /dev/null +++ b/2024/Day07/input.refout @@ -0,0 +1,2 @@ +6231007345478 +333027885676693 \ No newline at end of file diff --git a/2024/Day08/README.md b/2024/Day08/README.md new file mode 100644 index 000000000..fcfa0971a --- /dev/null +++ b/2024/Day08/README.md @@ -0,0 +1,14 @@ +## --- Day 8: Resonant Collinearity --- +You find yourselves on the _roof_ of a top-secret Easter Bunny installation. + +While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable! + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/8) description._ + +Continuing the steps I started yesterday, I extracted a common function (`GetUniquePositions`) that takes a parameter to generate antinode positions, representing the difference between part one and part two. + +`getAntinodes` returns the antinode positions of srcAntenna on the dstAntenna side. It doesn’t need to be symmetric — i.e., it doesn’t have to return the antinodes on the srcAntenna side — because GetUniquePositions will call it with the parameters swapped as well. This allows us to handle only one direction at a time. + +The generators are fairly straightforward: I simply take steps in the direction determined by the antennas, starting from the destination. Since I represented coordinates using complex numbers again, there’s no need for any special handling on the algebra side, regular + and - operations work. + +The `GetAntinodes` delegate is introduced only for documentation purposes. It looks better to my eyes than an ugly `Func<>` with four type parameters would in `GetUniquePositions`-s signature. diff --git a/2024/Day08/Solution.cs b/2024/Day08/Solution.cs new file mode 100644 index 000000000..e3c4c4695 --- /dev/null +++ b/2024/Day08/Solution.cs @@ -0,0 +1,66 @@ +namespace AdventOfCode.Y2024.Day08; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; + +using Map = System.Collections.Immutable.ImmutableDictionary; + +[ProblemName("Resonant Collinearity")] +class Solution : Solver { + public object PartOne(string input) => GetUniquePositions(input, GetAntinodes1).Count(); + public object PartTwo(string input) => GetUniquePositions(input, GetAntinodes2).Count(); + + HashSet GetUniquePositions(string input, GetAntinodes getAntinodes) { + var map = GetMap(input); + + var antennaLocations = ( + from pos in map.Keys + where char.IsAsciiLetterOrDigit(map[pos]) + select pos + ).ToArray(); + + return ( + from srcAntenna in antennaLocations + from dstAntenna in antennaLocations + where srcAntenna != dstAntenna && map[srcAntenna] == map[dstAntenna] + from antinode in getAntinodes(srcAntenna, dstAntenna, map) + select antinode + ).ToHashSet(); + } + + // returns the antinode positions of srcAntenna on the dstAntenna side + delegate IEnumerable GetAntinodes(Complex srcAntenna, Complex dstAntenna, Map map); + + // in part 1 we just look at the immediate neighbour + IEnumerable GetAntinodes1(Complex srcAntenna, Complex dstAntenna, Map map) { + var dir = dstAntenna - srcAntenna; + var antinote = dstAntenna + dir; + if (map.Keys.Contains(antinote)) { + yield return antinote; + } + } + + // in part 2 this becomes a cycle, plus dstAntenna is also a valid position now + IEnumerable GetAntinodes2(Complex srcAntenna, Complex dstAntenna, Map map) { + var dir = dstAntenna - srcAntenna; + var antinote = dstAntenna; + while (map.Keys.Contains(antinote)) { + yield return antinote; + antinote += dir; + } + } + + // store the points in a dictionary so that we can iterate over them and + // to easily deal with points outside the area using GetValueOrDefault + Map GetMap(string input) { + var map = input.Split("\n"); + return ( + from y in Enumerable.Range(0, map.Length) + from x in Enumerable.Range(0, map[0].Length) + select new KeyValuePair(x - y * Complex.ImaginaryOne, map[y][x]) + ).ToImmutableDictionary(); + } +} \ No newline at end of file diff --git a/2024/Day08/illustration.jpeg b/2024/Day08/illustration.jpeg new file mode 100644 index 000000000..c15028cbf Binary files /dev/null and b/2024/Day08/illustration.jpeg differ diff --git a/2024/Day08/input.in b/2024/Day08/input.in new file mode 100644 index 000000000..8b2c34647 Binary files /dev/null and b/2024/Day08/input.in differ diff --git a/2024/Day08/input.refout b/2024/Day08/input.refout new file mode 100644 index 000000000..fb3dee4bd --- /dev/null +++ b/2024/Day08/input.refout @@ -0,0 +1,2 @@ +247 +861 \ No newline at end of file diff --git a/2024/Day09/README.md b/2024/Day09/README.md new file mode 100644 index 000000000..be72beecb --- /dev/null +++ b/2024/Day09/README.md @@ -0,0 +1,10 @@ +## --- Day 9: Disk Fragmenter --- +Another push of the button leaves you in the familiar hallways of some friendly _amphipods_! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. + +While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/9) description._ + +I'm taking a break from using LINQ today and turning my attention to the low-level world of linked lists instead. I discovered a way to express both paths using a single `CompactFs` function with a `fragmentsEnabled` parameter. `CompactFs` operates with two pointers, `i` and `j`, which define the scan range we’re working on. `i` starts at the beginning of the disk, while `j` starts at the end and moves backward. When `i` points to a free space and `j` points to a used space, we call `RelocateBlock`, which moves `j` (or parts of `j`, depending on whether fragmentation is enabled) to a free space found after `i`. + +The rest involves careful pointer arithmetic and linked list management, where I aim to avoid overwriting the data I’ll need in the next line. I find this surprisingly hard to get right when working with linked lists... diff --git a/2024/Day09/Solution.cs b/2024/Day09/Solution.cs new file mode 100644 index 000000000..0622a6368 --- /dev/null +++ b/2024/Day09/Solution.cs @@ -0,0 +1,78 @@ +namespace AdventOfCode.Y2024.Day09; + +using System.Linq; + +using Fs = System.Collections.Generic.LinkedList; +using Node = System.Collections.Generic.LinkedListNode; +record struct Block(int fileId, int length) { } + +[ProblemName("Disk Fragmenter")] +class Solution : Solver { + + public object PartOne(string input) => Checksum(CompactFs(Parse(input), fragmentsEnabled: true)); + + public object PartTwo(string input) => Checksum(CompactFs(Parse(input), fragmentsEnabled: false)); + + // moves used blocks of the filesystem towards the beginning of the disk using RelocateBlock + Fs CompactFs(Fs fs, bool fragmentsEnabled) { + var (i, j) = (fs.First, fs.Last); + while (i != j) { + if (i.Value.fileId != -1) { + i = i.Next; + } else if (j.Value.fileId == -1) { + j = j.Previous; + } else { + RelocateBlock(fs, i, j, fragmentsEnabled); + j = j.Previous; + } + } + return fs; + } + + // Relocates the contents of block `j` to a free space starting after the given node `start`. + // - Searches for the first suitable free block after `start`. + // - If a block of equal size is found, `j` is moved entirely to that block. + // - If a larger block is found, part of it is used for `j`, and the remainder is split into + // a new free block. + // - If a smaller block is found and fragmentation is enabled, a portion of `j` is moved to fit, + // leaving the remainder in place. + void RelocateBlock(Fs fs, Node start, Node j, bool fragmentsEnabled) { + for (var i = start; i != j; i = i.Next) { + if (i.Value.fileId != -1) { + // noop + } else if (i.Value.length == j.Value.length) { + (i.Value, j.Value) = (j.Value, i.Value); + return; + } else if (i.Value.length > j.Value.length) { + var d = i.Value.length - j.Value.length; + i.Value = j.Value; + j.Value = j.Value with { fileId = -1 }; + fs.AddAfter(i, new Block(-1, d)); + return; + } else if (i.Value.length < j.Value.length && fragmentsEnabled) { + var d = j.Value.length - i.Value.length; + i.Value = i.Value with { fileId = j.Value.fileId }; + j.Value = j.Value with { length = d }; + fs.AddAfter(j, new Block(-1, i.Value.length)); + } + } + } + + long Checksum(Fs fs) { + var res = 0L; + var l = 0; + for (var i = fs.First; i != null; i = i.Next) { + for (var k = 0; k < i.Value.length; k++) { + if (i.Value.fileId != -1) { + res += l * i.Value.fileId; + } + l++; + } + } + return res; + } + + Fs Parse(string input) { + return new Fs(input.Select((ch, i) => new Block(i % 2 == 1 ? -1 : i / 2, ch - '0'))); + } +} diff --git a/2024/Day09/illustration.jpeg b/2024/Day09/illustration.jpeg new file mode 100644 index 000000000..7e5c69dd3 Binary files /dev/null and b/2024/Day09/illustration.jpeg differ diff --git a/2024/Day09/input.in b/2024/Day09/input.in new file mode 100644 index 000000000..8e4220afb Binary files /dev/null and b/2024/Day09/input.in differ diff --git a/2024/Day09/input.refout b/2024/Day09/input.refout new file mode 100644 index 000000000..59f6af771 --- /dev/null +++ b/2024/Day09/input.refout @@ -0,0 +1,2 @@ +6448989155953 +6476642796832 \ No newline at end of file diff --git a/2024/Day10/README.md b/2024/Day10/README.md new file mode 100644 index 000000000..e0d8711b7 --- /dev/null +++ b/2024/Day10/README.md @@ -0,0 +1,14 @@ +## --- Day 10: Hoof It --- +You all arrive at a _Lava Production Facility_ on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. + +The reindeer is holding a book titled "Lava Island Hiking Guide". However, when you open the book, you discover that most of it seems to have been scorched by lava! As you're about to ask how you can help, the reindeer brings you a blank [topographic map](https://en.wikipedia.org/wiki/Topographic_map) of the surrounding area (your puzzle input) and looks up at you excitedly. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/10) description._ + +Today's problem is surprisingly straightforward compared to yesterday's pointer juggling. We finally get to use our favorite queue data structure to implement a flood fill. I saw this coming... + +As usual, we use a dictionary with complex numbers to parse the input. The meat of the solution is in `GetTrailsFrom`, which returns all trails starting at a specific trailhead. + +The difference between `Part 1` and `Part 2` lies in how distinct trails are defined. I decided to return all trails keyed by their trailheads in `GetAllTrails` and delegate the distinctness logic to `PartOne` and `PartTwo`. + +A nice and easy task for today! diff --git a/2024/Day10/Solution.cs b/2024/Day10/Solution.cs new file mode 100644 index 000000000..1b882279f --- /dev/null +++ b/2024/Day10/Solution.cs @@ -0,0 +1,59 @@ +namespace AdventOfCode.Y2024.Day10; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; + +using Map = System.Collections.Immutable.ImmutableDictionary; + +[ProblemName("Hoof It")] +class Solution : Solver { + + Complex Up = Complex.ImaginaryOne; + Complex Down = -Complex.ImaginaryOne; + Complex Left = -1; + Complex Right = 1; + + public object PartOne(string input) => GetAllTrails(input).Sum(t => t.Value.Distinct().Count()); + public object PartTwo(string input) => GetAllTrails(input).Sum(t => t.Value.Count()); + + Dictionary> GetAllTrails(string input) { + var map = GetMap(input); + return GetTrailHeads(map).ToDictionary(t => t, t => GetTrailsFrom(map, t)); + } + + IEnumerable GetTrailHeads(Map map) => map.Keys.Where(pos => map[pos] == '0'); + + List GetTrailsFrom(Map map, Complex trailHead) { + // standard floodfill algorithm using a queue + var positions = new Queue(); + positions.Enqueue(trailHead); + var trails = new List(); + while (positions.Any()) { + var point = positions.Dequeue(); + if (map[point] == '9') { + trails.Add(point); + } else { + foreach (var dir in new[] { Up, Down, Left, Right }) { + if (map.GetValueOrDefault(point + dir) == map[point] + 1) { + positions.Enqueue(point + dir); + } + } + } + } + return trails; + } + + // store the points in a dictionary so that we can iterate over them and + // to easily deal with points outside the area using GetValueOrDefault + Map GetMap(string input) { + var map = input.Split("\n"); + return ( + from y in Enumerable.Range(0, map.Length) + from x in Enumerable.Range(0, map[0].Length) + select new KeyValuePair(x + y * Down, map[y][x]) + ).ToImmutableDictionary(); + } +} diff --git a/2024/Day10/illustration.jpeg b/2024/Day10/illustration.jpeg new file mode 100644 index 000000000..4c66aecd0 Binary files /dev/null and b/2024/Day10/illustration.jpeg differ diff --git a/2024/Day10/input.in b/2024/Day10/input.in new file mode 100644 index 000000000..c5e8a9c7c Binary files /dev/null and b/2024/Day10/input.in differ diff --git a/2024/Day10/input.refout b/2024/Day10/input.refout new file mode 100644 index 000000000..2f0670b4a --- /dev/null +++ b/2024/Day10/input.refout @@ -0,0 +1,2 @@ +674 +1372 \ No newline at end of file diff --git a/2024/Day11/README.md b/2024/Day11/README.md new file mode 100644 index 000000000..4d9b8030a --- /dev/null +++ b/2024/Day11/README.md @@ -0,0 +1,14 @@ +## --- Day 11: Plutonian Pebbles --- +The ancient civilization on _Pluto_ was known for its ability to manipulate spacetime, and while The Historians explore their infinite corridors, you've noticed a strange set of physics-defying stones. + +At first glance, they seem like normal stones: they're arranged in a perfectly straight line, and each stone has a number engraved on it. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/11) description._ + +Today is all about dynamic programming and cached calculations. Our goal is to determine the number of stones based on specific rules derived from the numbers engraved on them. Without careful optimization, this process can quickly spiral out of control. + +To address this, I encoded the stone generation logic inside the `Eval` function and added a cache to prevent exponential growth. + +I discovered the `ConcurrentDictionary` class, which includes a convenient `GetOrAdd` method. While this functionality is missing in regular `Dictionary` variants, it allows the caching logic to be neatly encapsulated in a single place. I decided to "abuse" it a bit here, even though my solution doesn’t involve any concurrency at all. + +There is an iterative approach to solving this problem as well, which progresses one blink at a time while keeping track of how many times each number occurs at each step. Working through this approach is left as an exercise for the reader. \ No newline at end of file diff --git a/2024/Day11/Solution.cs b/2024/Day11/Solution.cs new file mode 100644 index 000000000..f5bb4786b --- /dev/null +++ b/2024/Day11/Solution.cs @@ -0,0 +1,38 @@ +namespace AdventOfCode.Y2024.Day11; + +using System.Linq; + +using Cache = System.Collections.Concurrent.ConcurrentDictionary<(string, int), long>; + +[ProblemName("Plutonian Pebbles")] +class Solution : Solver { + + public object PartOne(string input) => StoneCount(input, 25); + + public object PartTwo(string input) => StoneCount(input, 75); + + long StoneCount(string input, int blinks) { + var cache = new Cache(); + return input.Split(" ").Sum(n => Eval(long.Parse(n), blinks, cache)); + } + + // Recursively calculates the total number of stones generated by a single engravement (n) + // after a specified number of blinks. Uses caching to optimize and prevent exponential + // computation by storing intermediate results. + long Eval(long n, int blinks, Cache cache) => + cache.GetOrAdd((n.ToString(), blinks), key => + key switch { + (_, 0) => 1, + + ("0", _) => + Eval(1, blinks - 1, cache), + + (var st, _) when st.Length % 2 == 0 => + Eval(long.Parse(st[0..(st.Length / 2)]), blinks - 1, cache) + + Eval(long.Parse(st[(st.Length / 2)..]), blinks - 1, cache), + + _ => + Eval(2024 * n, blinks - 1, cache) + } + ); +} \ No newline at end of file diff --git a/2024/Day11/illustration.jpeg b/2024/Day11/illustration.jpeg new file mode 100644 index 000000000..04d52a2c8 Binary files /dev/null and b/2024/Day11/illustration.jpeg differ diff --git a/2024/Day11/input.in b/2024/Day11/input.in new file mode 100644 index 000000000..5a4dfc848 Binary files /dev/null and b/2024/Day11/input.in differ diff --git a/2024/Day11/input.refout b/2024/Day11/input.refout new file mode 100644 index 000000000..75b88057d --- /dev/null +++ b/2024/Day11/input.refout @@ -0,0 +1,2 @@ +189547 +224577979481346 \ No newline at end of file diff --git a/2024/Day12/README.md b/2024/Day12/README.md new file mode 100644 index 000000000..d8fdb2ff0 --- /dev/null +++ b/2024/Day12/README.md @@ -0,0 +1,31 @@ +## --- Day 12: Garden Groups --- +Why not search for the Chief Historian near the _gardener_ and his _massive farm_? There's plenty of food, so The Historians grab something to eat while they search. + +You're about to settle near a complex arrangement of garden plots when some Elves ask if you can lend a hand. They'd like to set up fences around each region of garden plots, but they can't figure out how much fence they need to order or how much it will cost. They hand you a map (your puzzle input) of the garden plots. + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/12) description._ + +One can sense that the difficulty has ramped up today with a more complex problem involving area and perimeter calculations. + +First we determine the connected components (regions) of plants of the same type. This is done by picking a position of the +garden and applying a standard flood-fill algorithm to it. The result is a _region_. As we process each region, we carefully +remove all affected positions and then pick an untouched position to repeat the process. In a few iterations, the entire +garden is associated with the correct regions. The size of the regions corresponds to the _area_ in question. This logic +is implemented in the `GetRegions` function below. + +The second part of the problem, however, is more intriguing: how do we calculate the lengths of the fences? In part 1, this is +relatively simple because we just iterate through each region and count the neighboring cells that belong to a different regions. +This tells how many fence is needed. Unfortunately, this logic doesn't work for part 2... + +I attempted to implement a "walk-around" approach, which involves finding a fence segment and tracing it like a line-following +robot while counting the turns. The challenge with this approach is that some regions have holes, that require fences as well +and I didnt want to implement hole finding. + +Later realized that it is probably more straightforward to collect the fence segments along straight lines scanning the garden +from top to bottom an right to left. This is how I solved the problem. + +Finally went to reddit and read the hint: the number of segments equal to the number of corners... In other words difference +between part 1 and 2 is very small. In part 1 we are building an edge detector which becomes a corner detector in part 2. I changed +my implementation to that. + +This concludes our day 12. I'll take an extra ⭐ for learning something new again. diff --git a/2024/Day12/Solution.cs b/2024/Day12/Solution.cs new file mode 100644 index 000000000..f169d9a40 --- /dev/null +++ b/2024/Day12/Solution.cs @@ -0,0 +1,113 @@ +namespace AdventOfCode.Y2024.Day12; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; + +using Region = System.Collections.Generic.HashSet; + +[ProblemName("Garden Groups")] +class Solution : Solver { + + Complex Up = Complex.ImaginaryOne; + Complex Down = -Complex.ImaginaryOne; + Complex Left = -1; + Complex Right = 1; + + public object PartOne(string input) => CalculateFencePrice(input, FindEdges); + + public object PartTwo(string input) => CalculateFencePrice(input, FindCorners); + + int CalculateFencePrice(string input, MeasurePerimeter measure){ + var regions = GetRegions(input); + var res = 0; + foreach (var region in regions.Values.Distinct()) { + var perimeter = 0; + foreach (var pt in region) { + perimeter += measure(regions, pt); + } + res += region.Count() * perimeter; + } + return res; + } + + delegate int MeasurePerimeter(Dictionary map, Complex pt); + + int FindEdges(Dictionary map, Complex pt) { + var res = 0; + var region = map[pt]; + foreach (var du in new[] { Right, Down, Left, Up}) { + // x. + if (map.GetValueOrDefault(pt + du) != region) { + res++; + } + } + return res; + } + + int FindCorners(Dictionary map, Complex pt) { + var res = 0; + var region = map[pt]; + + // check the 4 corner types + foreach (var (du, dv) in new[] { (Up, Right), (Right, Down), (Down, Left), (Left, Up) }) { + // .. + // x. convex corner + if (map.GetValueOrDefault(pt + du) != region && + map.GetValueOrDefault(pt + dv) != region + ) { + res++; + } + + // x. + // xx concave corner + if (map.GetValueOrDefault(pt + du) == region && + map.GetValueOrDefault(pt + dv) == region && + map.GetValueOrDefault(pt + du + dv) != region + ) { + res++; + } + } + return res; + } + + // Maps the positions of plants in a garden to their corresponding regions, grouping plants + // of the same type into contiguous regions. + Dictionary GetRegions(string input) { + var lines = input.Split("\n"); + var garden = ( + from y in Enumerable.Range(0, lines.Length) + from x in Enumerable.Range(0, lines[0].Length) + select new KeyValuePair(x + y * Down, lines[y][x]) + ).ToDictionary(); + + // go over the positions of the garden and use a floodfill to determine the region + var res = new Dictionary(); + var positions = garden.Keys.ToHashSet(); + while (positions.Any()) { + var pivot = positions.First(); + var region = new Region { pivot }; + + var q = new Queue(); + q.Enqueue(pivot); + + var plant = garden[pivot]; + + while (q.Any()) { + var point = q.Dequeue(); + res[point] = region; + positions.Remove(point); + foreach (var dir in new[] { Up, Down, Left, Right }) { + if (!region.Contains(point + dir) && garden.GetValueOrDefault(point + dir) == plant) { + region.Add(point + dir); + q.Enqueue(point + dir); + } + } + } + } + return res; + } + +} diff --git a/2024/Day12/illustration.jpeg b/2024/Day12/illustration.jpeg new file mode 100644 index 000000000..62c1d43f1 Binary files /dev/null and b/2024/Day12/illustration.jpeg differ diff --git a/2024/Day12/input.in b/2024/Day12/input.in new file mode 100644 index 000000000..87382f822 Binary files /dev/null and b/2024/Day12/input.in differ diff --git a/2024/Day12/input.refout b/2024/Day12/input.refout new file mode 100644 index 000000000..03255f67a --- /dev/null +++ b/2024/Day12/input.refout @@ -0,0 +1,2 @@ +1374934 +841078 \ No newline at end of file diff --git a/2024/Day13/README.md b/2024/Day13/README.md new file mode 100644 index 000000000..12fb1f33f --- /dev/null +++ b/2024/Day13/README.md @@ -0,0 +1,8 @@ +## --- Day 13: Claw Contraption --- +Next up: the [lobby](/2020/day/24) of a resort on a tropical island. The Historians take a moment to admire the hexagonal floor tiles before spreading out. + +Fortunately, it looks like the resort has a new [arcade](https://en.wikipedia.org/wiki/Amusement_arcade)! Maybe you can win some prizes from the [claw machines](https://en.wikipedia.org/wiki/Claw_machine)? + +_Visit the website for the full story and [puzzle](https://adventofcode.com/2024/day/13) description._ + +We got a math problem today. The movements triggered by buttons A, B and the target position P form a linear equation that we can solve for the two unknowns: the number of button presses. Using math terms, if _i_ and _j_ marks the number of button presses, we are to solve `A * i + B * j = P`. This is simple enough to do using [Cramer's rule](https://en.wikipedia.org/wiki/Cramer%27s_rule), especially with two dimensional vectors. In this case the determinats can be computed with a simple cross product. We should not forget about the special cases: A and B can be parallel (didn't occur in my input), and the solution needs to be non negative integer for _i_ and _j_. \ No newline at end of file diff --git a/2024/Day13/Solution.cs b/2024/Day13/Solution.cs new file mode 100644 index 000000000..a37e1f094 --- /dev/null +++ b/2024/Day13/Solution.cs @@ -0,0 +1,46 @@ +namespace AdventOfCode.Y2024.Day13; + +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using Machine = (Vec2 a, Vec2 b, Vec2 p); + +record struct Vec2(long x, long y); + +[ProblemName("Claw Contraption")] +class Solution : Solver { + + public object PartOne(string input) => Parse(input).Sum(GetPrize); + public object PartTwo(string input) => Parse(input, shift: 10000000000000).Sum(GetPrize); + + long GetPrize(Machine m) { + var (a, b, p) = m; + + // solve a * i + b * j = p for i and j using Cramer's rule + var i = Det(p, b) / Det(a, b); + var j = Det(a, p) / Det(a, b); + + // return the prize when a non negative _integer_ solution is found + if (i >= 0 && j >= 0 && a.x * i + b.x * j == p.x && a.y * i + b.y * j == p.y) { + return 3 * i + j; + } else { + return 0; + } + } + + long Det(Vec2 a, Vec2 b) => a.x * b.y - a.y * b.x; + + IEnumerable Parse(string input, long shift=0) { + var blocks = input.Split("\n\n"); + foreach (var block in blocks) { + var nums = + Regex.Matches(block, @"\d+", RegexOptions.Multiline) + .Select(m => int.Parse(m.Value)) + .Chunk(2).Select(p => new Vec2(p[0], p[1])) + .ToArray(); + + nums[2] = new Vec2(nums[2].x + shift, nums[2].y + shift); + yield return (nums[0], nums[1], nums[2]); + } + } +} \ No newline at end of file diff --git a/2024/Day13/illustration.jpeg b/2024/Day13/illustration.jpeg new file mode 100644 index 000000000..a62957630 Binary files /dev/null and b/2024/Day13/illustration.jpeg differ diff --git a/2024/Day13/input.in b/2024/Day13/input.in new file mode 100644 index 000000000..10f78d949 Binary files /dev/null and b/2024/Day13/input.in differ diff --git a/2024/Day13/input.refout b/2024/Day13/input.refout new file mode 100644 index 000000000..78a92a9e3 --- /dev/null +++ b/2024/Day13/input.refout @@ -0,0 +1,2 @@ +32041 +95843948914827 \ No newline at end of file diff --git a/2024/Day14/README.md b/2024/Day14/README.md new file mode 100644 index 000000000..9c226b17a --- /dev/null +++ b/2024/Day14/README.md @@ -0,0 +1,50 @@ +## --- Day 14: Restroom Redoubt --- +One of The Historians needs to use the bathroom; fortunately, you know there's a bathroom near an unvisited location on their list, and so you're all quickly teleported directly to the lobby of Easter Bunny Headquarters. + +Unfortunately, EBHQ seems to have "improved" bathroom security again after your last [visit](/2016/day/2). The area outside the bathroom is swarming with robots! + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/14) description._ + +A nice simulation challenge for today. `Part 1` was straightforward: iterate 100 times and count the robots in the different quadrants. + +I’d bet many of us anticipated some `least common multiple` or `Chinese Remainder Theorem` magic for `Part 2`, but Eric threw us a curveball by making us search for a Christmas tree pattern in the robot’s movement. + +The expected output wasn’t clearly specified — other than the fact that it should resemble a Christmas tree. I wrote a plot function to display the robot’s locations on the screen, dumped everything into a long file, and manually inspected it in my editor. + +Later, to automate this process, decided to search for a longer horizontal '####' pattern in the output: + +``` + ############################### + # # # # + # # # + # # # + # # # # + # # # + # ### # # + # ##### # + # # ####### # + # # ######### # # + # ##### # + # # ####### # + # ######### # + # ########### # + # ############# # # # + # ######### # + # # ########### # # + # # ############# # + # ############### # # # + # ################# # # + # ############# # + # ############### # + # ################# # + # ################### # + # # ##################### # + # ### # + # ### # # + # # ### # # + # # # + # # # + # # # + # # # # + # ############################### +``` \ No newline at end of file diff --git a/2024/Day14/Solution.cs b/2024/Day14/Solution.cs new file mode 100644 index 000000000..72850bf90 --- /dev/null +++ b/2024/Day14/Solution.cs @@ -0,0 +1,69 @@ +namespace AdventOfCode.Y2024.Day14; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +record struct Vec2(int x, int y); +record struct Robot(Vec2 pos, Vec2 vel); + +[ProblemName("Restroom Redoubt")] +class Solution : Solver { + const int width = 101; + const int height = 103; + + // run the simulation for 100 steps and count the robots in the different quadrants. + public object PartOne(string input) => + Simulate(input) + .ElementAt(100) + .CountBy(GetQuadrant) + .Where(group => group.Key.x != 0 && group.Key.y != 0) + .Aggregate(1, (acc, group) => acc * group.Value); + + // I figured that the xmas tree pattern has a long horizontal ### pattern in it + public object PartTwo(string input) => + Simulate(input) + .TakeWhile(robots => !Plot(robots).Contains("#################")) + .Count(); + + // an infinite simulation of robot movement + IEnumerable Simulate(string input) { + var robots = Parse(input).ToArray(); + while (true) { + yield return robots; + robots = robots.Select(Step).ToArray(); + } + } + + // advance a robot by its velocity taking care of the 'teleportation' + Robot Step(Robot robot) => robot with {pos = AddWithWrapAround(robot.pos, robot.vel) }; + + // returns the direction (-1/0/1) of the robot to the center of the room + Vec2 GetQuadrant(Robot robot) => + new Vec2(Math.Sign(robot.pos.x - width / 2), Math.Sign(robot.pos.y - height / 2)); + + Vec2 AddWithWrapAround(Vec2 a, Vec2 b) => + new Vec2((a.x + b.x + width) % width, (a.y + b.y + height) % height); + + // shows the robot locations in the room + string Plot(IEnumerable robots) { + var res = new char[height, width]; + foreach (var robot in robots) { + res[robot.pos.y, robot.pos.x] = '#'; + } + var sb = new StringBuilder(); + for (var y = 0; y < height; y++) { + for (var x = 0; x < width; x++) { + sb.Append(res[y, x] == '#' ? "#" : " "); + } + sb.AppendLine(); + } + return sb.ToString(); + } + + IEnumerable Parse(string input) => + from line in input.Split("\n") + let nums = Regex.Matches(line, @"-?\d+").Select(m => int.Parse(m.Value)).ToArray() + select new Robot(new Vec2(nums[0], nums[1]), new Vec2(nums[2], nums[3])); +} \ No newline at end of file diff --git a/2024/Day14/illustration.jpeg b/2024/Day14/illustration.jpeg new file mode 100644 index 000000000..1fdaa3615 Binary files /dev/null and b/2024/Day14/illustration.jpeg differ diff --git a/2024/Day14/input.in b/2024/Day14/input.in new file mode 100644 index 000000000..28019ec95 Binary files /dev/null and b/2024/Day14/input.in differ diff --git a/2024/Day14/input.refout b/2024/Day14/input.refout new file mode 100644 index 000000000..34259b6fe --- /dev/null +++ b/2024/Day14/input.refout @@ -0,0 +1,2 @@ +231019008 +8280 \ No newline at end of file diff --git a/2024/Day15/README.md b/2024/Day15/README.md new file mode 100644 index 000000000..0e8fd4eb6 --- /dev/null +++ b/2024/Day15/README.md @@ -0,0 +1,14 @@ +## --- Day 15: Warehouse Woes --- +You appear back inside your own mini submarine! Each Historian drives their mini submarine in a different direction; maybe the Chief has his own submarine down here somewhere as well? + +You look up to see a vast school of [lanternfish](/2021/day/6) swimming past you. On closer inspection, they seem quite anxious, so you drive your mini submarine over to see if you can help. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/15) description._ + +A nice Sokoban-style puzzle for the weekend! The main difference is that in the original Sokoban, the robot could push only a single box, not multiple boxes. This adds complexity to both parts of the puzzle. However, it’s not that difficult to handle... I moved the hard parts into the `TryToStep` function that takes the map, a position, and a direction, then attempts to make a move in that direction. + +If the position corresponds to the robot or a box, the function checks whether the neighboring cell is free or can be made free by pushing boxes in the given direction. The .NET API sometimes uses the `TryToDoX` pattern, where a function returns a boolean result and provides an `out` parameter. I reused this pattern here. On success, the updated map is returned via the `ref` parameter. If the move fails, the map remains unchanged. + +The real challenge lies in `part 2`, where recursion needs to branch whenever the robot pushes more than one box at a time. In such cases, we must invoke `TryToStep` for each box. Due to the recursive nature of the algorithm, it’s possible for one branch to succeed while the other fails. When this happens, the entire map must be reset to its original state before we pop from the recursion. This could be quite tricky to manage unless you make copies of the dictionary that holds the state — or, as I did, use an immutable dictionary instead. + +I’m not entirely satisfied with the "if-ladder" structure of the `TryToStep` function, but for now, I don’t have a better idea to handle all the cases in a more readable way. diff --git a/2024/Day15/Solution.cs b/2024/Day15/Solution.cs new file mode 100644 index 000000000..35261aa50 --- /dev/null +++ b/2024/Day15/Solution.cs @@ -0,0 +1,110 @@ +namespace AdventOfCode.Y2024.Day15; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; + +using Map = System.Collections.Immutable.IImmutableDictionary; + +[ProblemName("Warehouse Woes")] +class Solution : Solver { + + static Complex Up = -Complex.ImaginaryOne; + static Complex Down = Complex.ImaginaryOne; + static Complex Left = -1; + static Complex Right = 1; + + public object PartOne(string input) => Solve(input); + public object PartTwo(string input) => Solve(ScaleUp(input)); + + public double Solve(string input) { + var (map, steps) = Parse(input); + + var robot = map.Keys.Single(k => map[k] == '@'); + foreach (var dir in steps) { + if (TryToStep(ref map, robot, dir)) { + robot += dir; + } + } + + return map.Keys + .Where(k => map[k] == '[' || map[k] == 'O') + .Sum(box => box.Real + 100 * box.Imaginary); + } + + // Attempts to move the robot in the given direction on the map, pushing boxes as necessary. + // If the move is successful, the map is updated to reflect the new positions and the function returns true. + // Otherwise, the map remains unchanged and the function returns false. + bool TryToStep(ref Map map, Complex pos, Complex dir) { + var mapOrig = map; + + if (map[pos] == '.') { + return true; + } else if (map[pos] == 'O' || map[pos] == '@') { + if (TryToStep(ref map, pos + dir, dir)) { + map = map + .SetItem(pos + dir, map[pos]) + .SetItem(pos, '.'); + return true; + } + } else if (map[pos] == ']') { + return TryToStep(ref map, pos + Left, dir); + } else if (map[pos] == '[') { + if (dir == Left) { + if (TryToStep(ref map, pos + Left, dir)) { + map = map + .SetItem(pos + Left, '[') + .SetItem(pos, ']') + .SetItem(pos + Right, '.'); + return true; + } + } else if (dir == Right) { + if (TryToStep(ref map, pos + 2 * Right, dir)) { + map = map + .SetItem(pos, '.') + .SetItem(pos + Right, '[') + .SetItem(pos + 2 * Right, ']'); + return true; + } + } else { + if (TryToStep(ref map, pos + dir, dir) && TryToStep(ref map, pos + Right + dir, dir)) { + map = map + .SetItem(pos, '.') + .SetItem(pos + Right, '.') + .SetItem(pos + dir, '[') + .SetItem(pos + dir + Right, ']'); + return true; + } + } + } + + map = mapOrig; + return false; + } + + string ScaleUp(string input) => + input.Replace("#", "##").Replace(".", "..").Replace("O", "[]").Replace("@", "@."); + + (Map, Complex[]) Parse(string input) { + var blocks = input.Split("\n\n"); + var lines = blocks[0].Split("\n"); + var map = ( + from y in Enumerable.Range(0, lines.Length) + from x in Enumerable.Range(0, lines[0].Length) + select new KeyValuePair(x + y * Down, lines[y][x]) + ).ToImmutableDictionary(); + + var steps = blocks[1].ReplaceLineEndings("").Select(ch => + ch switch { + '^' => Up, + '<' => Left, + '>' => Right, + 'v' => Down, + _ => throw new Exception() + }); + + return (map, steps.ToArray()); + } +} diff --git a/2024/Day15/illustration.jpeg b/2024/Day15/illustration.jpeg new file mode 100644 index 000000000..75f133b4a Binary files /dev/null and b/2024/Day15/illustration.jpeg differ diff --git a/2024/Day15/input.in b/2024/Day15/input.in new file mode 100644 index 000000000..4641e0ca4 Binary files /dev/null and b/2024/Day15/input.in differ diff --git a/2024/Day15/input.refout b/2024/Day15/input.refout new file mode 100644 index 000000000..2c35fe07a --- /dev/null +++ b/2024/Day15/input.refout @@ -0,0 +1,2 @@ +1476771 +1468005 \ No newline at end of file diff --git a/2024/Day16/README.md b/2024/Day16/README.md new file mode 100644 index 000000000..160ab57ff --- /dev/null +++ b/2024/Day16/README.md @@ -0,0 +1,12 @@ +## --- Day 16: Reindeer Maze --- +It's time again for the _Reindeer Olympics_! This year, the big event is the Reindeer Maze, where the Reindeer compete for the lowest score. + +You and The Historians arrive to search for the Chief right as the event is about to start. It wouldn't hurt to watch a little, right? + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/16) description._ + +I spent hell a lot of time on this one. I’m not sure why, because I had a good understanding of what to do for both parts. `Part 1` went reasonably well: I quickly used a priority queue based approach to find the shortest path from the `start` state to the `goal`. + +For `Part 2`, I tried a few dead ends, because I overcomplicate things as usual. But I found the right direction after about half an hour. The idea is to split the problem into two halves. First, we compute the optimal distances from every tile and direction to the goal node. This can be found using _Dijskstra's algorithm_. + +Once I have the distances, I can start an other round, now working forward from the start position and using a flood-fill-like algorithm to discover the positions on the shortest path. This is easy to do with the distance map as a guide. I maintain the 'remaining score' along the path, and just need to check if the distance from a potential next state equals to the score I still have to use. This logic can be found in the `FindBestSpots` function. diff --git a/2024/Day16/Solution.cs b/2024/Day16/Solution.cs new file mode 100644 index 000000000..89f5bd78e --- /dev/null +++ b/2024/Day16/Solution.cs @@ -0,0 +1,98 @@ +namespace AdventOfCode.Y2024.Day16; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; +using AngleSharp.Common; +using Map = System.Collections.Generic.Dictionary; +using State = (System.Numerics.Complex pos, System.Numerics.Complex dir); + +[ProblemName("Reindeer Maze")] +class Solution : Solver { + + static readonly Complex North = -Complex.ImaginaryOne; + static readonly Complex South = Complex.ImaginaryOne; + static readonly Complex West = -1; + static readonly Complex East = 1; + + public object PartOne(string input) => FindBestScore(GetMap(input)); + public object PartTwo(string input) => FindBestSpots(GetMap(input)); + + int FindBestScore(Map map) => Dijkstra(map, Goal(map))[Start(map)]; + + int FindBestSpots(Map map) { + var dist = Dijkstra(map, Goal(map)); + var start = Start(map); + + // track the shortest paths using the distance map as guideline. + var q = new PriorityQueue(); + q.Enqueue(start, dist[start]); + + var bestSpots = new HashSet { start }; + while (q.TryDequeue(out var state, out var remainingScore)) { + foreach (var (next, score) in Steps(map, state, forward: true)) { + var nextRemainingScore = remainingScore - score; + if (!bestSpots.Contains(next) && dist[next] == nextRemainingScore) { + bestSpots.Add(next); + q.Enqueue(next, nextRemainingScore); + } + } + } + return bestSpots.DistinctBy(state => state.pos).Count(); + } + + Dictionary Dijkstra(Map map, Complex goal) { + // Dijkstra algorithm; works backwards from the goal, returns the + // distances to _all_ tiles and directions. + var dist = new Dictionary(); + + var q = new PriorityQueue(); + foreach (var dir in new[]{North, East, West, South}) { + q.Enqueue((goal, dir), 0); + dist[(goal, dir)] = 0; + } + + while (q.TryDequeue(out var cur, out var totalDistance)) { + foreach (var (next, score) in Steps(map, cur, forward: false)) { + var nextCost = totalDistance + score; + if (nextCost < dist.GetOrDefault(next, int.MaxValue)) { + q.Remove(next, out _, out _, null); + dist[next] = nextCost; + q.Enqueue(next, nextCost); + } + } + } + return dist; + } + + // returns the possible next or previous states and the associated costs for a given state. + // in forward mode we scan the possible states from the start state towards the goal. + // in backward mode we are working backwards from the goal to the start. + IEnumerable<(State, int cost)> Steps(Map map, State state, bool forward) { + foreach (var dir in new[]{North, East, West, South}) { + if (dir == state.dir) { + var pos = forward ? state.pos + dir : state.pos - dir; + if (map.GetValueOrDefault(pos) != '#') { + yield return ((pos, dir), 1); + } + } else if (dir != -state.dir) { + yield return ((state.pos, dir), 1000); + } + } + } + + // store the points in a dictionary so that we can iterate over them and + // to easily deal with points outside the area using GetValueOrDefault + Map GetMap(string input) { + var map = input.Split("\n"); + return ( + from y in Enumerable.Range(0, map.Length) + from x in Enumerable.Range(0, map[0].Length) + select new KeyValuePair(x + y * South, map[y][x]) + ).ToDictionary(); + } + Complex Goal(Map map) => map.Keys.Single(k => map[k] == 'E'); + State Start(Map map) => (map.Keys.Single(k => map[k] == 'S'), East); +} \ No newline at end of file diff --git a/2024/Day16/illustration.jpeg b/2024/Day16/illustration.jpeg new file mode 100644 index 000000000..2e27f1e4b Binary files /dev/null and b/2024/Day16/illustration.jpeg differ diff --git a/2024/Day16/input.in b/2024/Day16/input.in new file mode 100644 index 000000000..44464bc38 Binary files /dev/null and b/2024/Day16/input.in differ diff --git a/2024/Day16/input.refout b/2024/Day16/input.refout new file mode 100644 index 000000000..6d050d07f --- /dev/null +++ b/2024/Day16/input.refout @@ -0,0 +1,2 @@ +130536 +1024 \ No newline at end of file diff --git a/2024/Day17/README.md b/2024/Day17/README.md new file mode 100644 index 000000000..dcddf5cf2 --- /dev/null +++ b/2024/Day17/README.md @@ -0,0 +1,27 @@ +## --- Day 17: Chronospatial Computer --- +The Historians push the button on their strange device, but this time, you all just feel like you're _falling_. + +"Situation critical", the device announces in a familiar voice. "Bootstrapping process failed. Initializing debugger...." + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/17) description._ + +I'm not a big fan of _disassembly_ tasks, but they come up almost every year. The first part of the problem, which +I _actually_ liked, was to write an interpreter for an elvish computer (i.e. one with a weird instruction set). This +is really easy to do with a simple for loop and switching on the different opcodes. + +The second half was a bit harder, as I had to understand what's going on in the program. We had to generate inputs that +would force the program to print out its own source. Well, a _quine_ is a computer program that takes no input and +produces a copy of its own source code as its only output. Although our program was not a real quine, I couldn't help +but smile when I read the problem description in the morning. + +Fortunately, the algorithm was not that complicated once I realized that the _next output number_ depends only on the +_lowest few bits_ of the input. Then the input gets shifted by a small amount, and this continues until the end. + +There is _some interconnection_ between the consecutive numbers, so one cannot just calculate the result independently +for each. But I was able to come up with a _recursive solution_ that generates the input _backwards_. Once we know the +higher bits, we can try all combinations for the next 3 bits, and so on down to the first bit. + +As an added bonus I implemented (part of) the emulator in [VIC-20 BASIC](https://hu.wikipedia.org/wiki/Commodore_VIC-20). +This is how it runs the second sample that prints out its own source code. + +![vic20.gif](vic20.gif) \ No newline at end of file diff --git a/2024/Day17/Solution.cs b/2024/Day17/Solution.cs new file mode 100644 index 000000000..b5e44d86e --- /dev/null +++ b/2024/Day17/Solution.cs @@ -0,0 +1,70 @@ +namespace AdventOfCode.Y2024.Day17; + +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +[ProblemName("Chronospatial Computer")] +class Solution : Solver { + + enum Opcode { + Adv, Bxl, Bst, Jnz, Bxc, Out, Bdv, Cdv + } + + public object PartOne(string input) { + var (state, program) = Parse(input); + return string.Join(",", Run(state, program)); + } + public object PartTwo(string input) { + var (_, program) = Parse(input); + return GenerateA(program, program).Min(); + } + + List Run(List state, List program) { + var combo = (int op) => op < 4 ? op : state[op - 4]; + var res = new List(); + for (var ip = 0; ip < program.Count; ip += 2) { + switch ((Opcode)program[ip], (int)program[ip + 1]) { + case (Opcode.Adv, var op): state[0] = state[0] >> (int)combo(op); break; + case (Opcode.Bdv, var op): state[1] = state[0] >> (int)combo(op); break; + case (Opcode.Cdv, var op): state[2] = state[0] >> (int)combo(op); break; + case (Opcode.Bxl, var op): state[1] = state[1] ^ op; break; + case (Opcode.Bst, var op): state[1] = combo(op) % 8; break; + case (Opcode.Jnz, var op): ip = state[0] == 0 ? ip : op - 2; break; + case (Opcode.Bxc, var op): state[1] = state[1] ^ state[2]; break; + case (Opcode.Out, var op): res.Add(combo(op) % 8); break; + } + } + return res; + } + + /* + Determines register A for the given output. The search works recursively and in + reverse order, starting from the last number to be printed and ending with the first. + */ + IEnumerable GenerateA(List program, List output) { + if (!output.Any()) { + yield return 0; + yield break; + } + + foreach (var ah in GenerateA(program, output[1..])) { + for (var al = 0; al < 8; al++) { + var a = ah * 8 + al; + if (Run([a, 0, 0], program).SequenceEqual(output)) { + yield return a; + } + } + } + } + + (List state, List program) Parse(string input) { + var blocks = input.Split("\n\n").Select(ParseNums).ToArray(); + return (blocks[0], blocks[1]); + } + + List ParseNums(string st) => + Regex.Matches(st, @"\d+", RegexOptions.Multiline) + .Select(m => long.Parse(m.Value)) + .ToList(); +} \ No newline at end of file diff --git a/2024/Day17/illustration.jpeg b/2024/Day17/illustration.jpeg new file mode 100644 index 000000000..001875746 Binary files /dev/null and b/2024/Day17/illustration.jpeg differ diff --git a/2024/Day17/input.in b/2024/Day17/input.in new file mode 100644 index 000000000..593be0de4 Binary files /dev/null and b/2024/Day17/input.in differ diff --git a/2024/Day17/input.refout b/2024/Day17/input.refout new file mode 100644 index 000000000..fa0a5d5c9 --- /dev/null +++ b/2024/Day17/input.refout @@ -0,0 +1,2 @@ +1,5,0,5,2,0,1,3,5 +236581108670061 \ No newline at end of file diff --git a/2024/Day17/vic20.gif b/2024/Day17/vic20.gif new file mode 100644 index 000000000..ab0829883 Binary files /dev/null and b/2024/Day17/vic20.gif differ diff --git a/2024/Day18/README.md b/2024/Day18/README.md new file mode 100644 index 000000000..3f8903f0a --- /dev/null +++ b/2024/Day18/README.md @@ -0,0 +1,8 @@ +## --- Day 18: RAM Run --- +You and The Historians look a lot more pixelated than you remember. You're _inside a computer_ at the North Pole! + +Just as you're about to check out your surroundings, a program runs up to you. "This region of memory isn't safe! The User misunderstood what a [pushdown automaton](https://en.wikipedia.org/wiki/Pushdown_automaton) is and their algorithm is pushing whole bytes down on top of us! Run!" + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/18) description._ + +We got a simple path finding problem for today. I implemented a _binary search_ for the second part. \ No newline at end of file diff --git a/2024/Day18/Solution.cs b/2024/Day18/Solution.cs new file mode 100644 index 000000000..bc9747461 --- /dev/null +++ b/2024/Day18/Solution.cs @@ -0,0 +1,64 @@ +namespace AdventOfCode.Y2024.Day18; + +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Numerics; +using AngleSharp.Common; + +[ProblemName("RAM Run")] +class Solution : Solver { + + public object PartOne(string input) => Distance(GetBlocks(input).Take(1024)); + + public object PartTwo(string input) { + // find the first block position that will cut off the goal position + // we can use a binary search for this + + var blocks = GetBlocks(input); + var (lo, hi) = (0, blocks.Length); + while (hi - lo > 1) { + var m = (lo + hi) / 2; + if (Distance(blocks.Take(m)) == null) { + hi = m; + } else { + lo = m; + } + } + return $"{blocks[lo].Real},{blocks[lo].Imaginary}"; + } + + int? Distance(IEnumerable blocks) { + // our standard priority queue based path finding + + var size = 70; + var (start, goal) = (0, size + size * Complex.ImaginaryOne); + var blocked = blocks.Concat(start).ToHashSet(); + + var q = new PriorityQueue(); + q.Enqueue(start, 0); + while (q.TryDequeue(out var pos, out var dist)) { + if (pos == goal) { + return dist; + } + + foreach (var dir in new[] { 1, -1, Complex.ImaginaryOne, -Complex.ImaginaryOne }) { + var posT = pos + dir; + if (!blocked.Contains(posT) && + 0 <= posT.Imaginary && posT.Imaginary <= size && + 0 <= posT.Real && posT.Real <= size + ) { + q.Enqueue(posT, dist + 1); + blocked.Add(posT); + } + } + } + return null; + } + + Complex[] GetBlocks(string input) => ( + from line in input.Split("\n") + let nums = Regex.Matches(line, @"\d+").Select(m => int.Parse(m.Value)).ToArray() + select nums[0] + nums[1] * Complex.ImaginaryOne + ).ToArray(); +} \ No newline at end of file diff --git a/2024/Day18/illustration.jpeg b/2024/Day18/illustration.jpeg new file mode 100644 index 000000000..12a134ec2 Binary files /dev/null and b/2024/Day18/illustration.jpeg differ diff --git a/2024/Day18/input.in b/2024/Day18/input.in new file mode 100644 index 000000000..bc02b11cd Binary files /dev/null and b/2024/Day18/input.in differ diff --git a/2024/Day18/input.refout b/2024/Day18/input.refout new file mode 100644 index 000000000..db6793b1f --- /dev/null +++ b/2024/Day18/input.refout @@ -0,0 +1,2 @@ +338 +20,44 \ No newline at end of file diff --git a/2024/Day19/README.md b/2024/Day19/README.md new file mode 100644 index 000000000..91ef262a7 --- /dev/null +++ b/2024/Day19/README.md @@ -0,0 +1,15 @@ +## --- Day 19: Linen Layout --- +Today, The Historians take you up to the _hot springs_ on Gear Island! Very [suspiciously](https://www.youtube.com/watch?v=ekL881PJMjI), absolutely nothing goes wrong as they begin their careful search of the vast field of helixes. + +Could this finally be your chance to visit the [onsen](https://en.wikipedia.org/wiki/Onsen) next door? Only one way to find out. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/19) description._ + +I initially thought that I would be able to entirely solve today's problem using regular expressions. This worked for Part 1, but unfortunately, the regex library can only determine whether a pattern matches a string — it cannot return the number of ways the match can occur. Not that it’s its job anyway... + +I had to implement the search function myself. It’s a simple recursive function that iterates through all towels and tries to match them to the beginning of the pattern. If a match is found, it continues recursively with the remaining pattern until the entire pattern becomes an empty string, which signifies a complete match. + +Of course, this approach would never terminate as-is, it needs to be converted into a cached function. Thankfully, this is straightforward to do using a _ConcurrentDictionary_, which I discovered earlier this year. By utilizing the _GetOrAdd_ method of +the _ConcurrentDictionary_ class, one can simply wrap the uncached logic inside a lambda and call it a day. + +It’s very similar to Python’s cached function decorators, albeit with the caveat of having to pass an additional 'cache' argument at the end of the parameter list. But since we’re in the world of C#, we have to work with what it offers. diff --git a/2024/Day19/Solution.cs b/2024/Day19/Solution.cs new file mode 100644 index 000000000..952efada5 --- /dev/null +++ b/2024/Day19/Solution.cs @@ -0,0 +1,37 @@ +namespace AdventOfCode.Y2024.Day19; + +using System; +using System.Collections.Generic; +using System.Linq; + +using Cache = System.Collections.Concurrent.ConcurrentDictionary; + +[ProblemName("Linen Layout")] +class Solution : Solver { + + public object PartOne(string input) => MatchCounts(input).Count(c => c != 0); + + public object PartTwo(string input) => MatchCounts(input).Sum(); + + IEnumerable MatchCounts(string input) { + var blocks = input.Split("\n\n"); + var towels = blocks[0].Split(", "); + return + from pattern in blocks[1].Split("\n") + select MatchCount(towels, pattern, new Cache()); + } + + // computes the number of ways the pattern can be build up from the towels. + // works recursively by matching the prefix of the pattern with each towel. + // a full match is found when the pattern becomes empty. the cache is applied + // to _drammatically_ speed up execution + long MatchCount(string[] towels, string pattern, Cache cache) => + cache.GetOrAdd(pattern, (pattern) => + pattern switch { + "" => 1, + _ => towels + .Where(pattern.StartsWith) + .Sum(towel => MatchCount(towels, pattern[towel.Length ..], cache)) + } + ); +} \ No newline at end of file diff --git a/2024/Day19/illustration.jpeg b/2024/Day19/illustration.jpeg new file mode 100644 index 000000000..6a4aa3f54 Binary files /dev/null and b/2024/Day19/illustration.jpeg differ diff --git a/2024/Day19/input.in b/2024/Day19/input.in new file mode 100644 index 000000000..c718fe1b3 Binary files /dev/null and b/2024/Day19/input.in differ diff --git a/2024/Day19/input.refout b/2024/Day19/input.refout new file mode 100644 index 000000000..92770631d --- /dev/null +++ b/2024/Day19/input.refout @@ -0,0 +1,2 @@ +333 +678536865274732 \ No newline at end of file diff --git a/2024/Day20/README.md b/2024/Day20/README.md new file mode 100644 index 000000000..76d9ad9bb --- /dev/null +++ b/2024/Day20/README.md @@ -0,0 +1,22 @@ +## --- Day 20: Race Condition --- +The Historians are quite pixelated again. This time, a massive, black building looms over you - you're _right outside_ the CPU! + +While The Historians get to work, a nearby program sees that you're idle and challenges you to a race. Apparently, you've arrived just in time for the frequently-held race condition festival! + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/20) description._ + +The problem included a small but crucial hint: _there is only a single path from the start to the end_. Moreover, there are no dead ends in the input; it's just a single, continuous trace. + +The definition of _cheating_ was super hard to understand. I have to admit that instead, I used my intuition and used a more simple definition: in cheat mode you can step to any cell within the distance of 2 (or 20 for the second part). This really worked. + +I created a function that returns the points of the track in finish to start order. This way, the _index_ of an item in the array corresponds to its distance to the finish line. + +Then, I go over the path. For each position, the number of possible cheats is calculated by checking what happens if we are trying to make a shortcut to any other positions around. + +There are a number of cases to consider: +- the target position is too far away. This happens when its Manhattan distance is greater than the allowed _cheat_ limit +- the target is within range, but actually further away from the finish than we are (the saving is negative). +- the target is within range, closer to the finish, but the saving is still less than 100 +- the target is within range, and the saving is at least 100 + +We need to determine the number of good cheats for each position _add_ them up. I used Parallel LINQ here, as the regular sequential one took significantly more time. diff --git a/2024/Day20/Solution.cs b/2024/Day20/Solution.cs new file mode 100644 index 000000000..d56acd386 --- /dev/null +++ b/2024/Day20/Solution.cs @@ -0,0 +1,59 @@ +namespace AdventOfCode.Y2024.Day20; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +[ProblemName("Race Condition")] +class Solution : Solver { + + public object PartOne(string input) => Solve(input, 2); + public object PartTwo(string input) => Solve(input, 20); + + int Solve(string input, int cheat) { + var path = GetPath(input); + var indices = Enumerable.Range(0, path.Length).ToArray(); + + // sum up the worthy cheats for each index along the path + var cheatsFromI = (int i) => ( + from j in indices[0..i] + let dist = Manhattan(path[i], path[j]) + let saving = i - (j + dist) + where dist <= cheat && saving >= 100 + select 1 + ).Sum(); + + // parallel is gold today, it gives us an 3-4x boost + return indices.AsParallel().Select(cheatsFromI).Sum(); + } + + int Manhattan(Complex a, Complex b) => + (int)(Math.Abs(a.Imaginary - b.Imaginary) + Math.Abs(a.Real - b.Real)); + + // Follow the path from finish to start, supposed that there is a single track in the input. + // The index of a position in the returned array equals to its distance from the finish + Complex[] GetPath(string input) { + var lines = input.Split("\n"); + var map = ( + from y in Enumerable.Range(0, lines.Length) + from x in Enumerable.Range(0, lines[0].Length) + select new KeyValuePair(x + y * Complex.ImaginaryOne, lines[y][x]) + ).ToDictionary(); + + Complex[] dirs = [-1, 1, Complex.ImaginaryOne, -Complex.ImaginaryOne]; + + var start = map.Keys.Single(k => map[k] == 'S'); + var goal = map.Keys.Single(k => map[k] == 'E'); + + var (prev, cur) = ((Complex?)null, goal); + var res = new List { cur }; + + while (cur != start) { + var dir = dirs.Single(dir => map[cur + dir] != '#' && cur + dir != prev); + (prev, cur) = (cur, cur + dir); + res.Add(cur); + } + return res.ToArray(); + } +} \ No newline at end of file diff --git a/2024/Day20/illustration.jpeg b/2024/Day20/illustration.jpeg new file mode 100644 index 000000000..dc1389f34 Binary files /dev/null and b/2024/Day20/illustration.jpeg differ diff --git a/2024/Day20/input.in b/2024/Day20/input.in new file mode 100644 index 000000000..3a67ed17b Binary files /dev/null and b/2024/Day20/input.in differ diff --git a/2024/Day20/input.refout b/2024/Day20/input.refout new file mode 100644 index 000000000..a7c19236d --- /dev/null +++ b/2024/Day20/input.refout @@ -0,0 +1,2 @@ +1384 +1008542 \ No newline at end of file diff --git a/2024/Day21/README.md b/2024/Day21/README.md new file mode 100644 index 000000000..a10d58bb1 --- /dev/null +++ b/2024/Day21/README.md @@ -0,0 +1,23 @@ +## --- Day 21: Keypad Conundrum --- +As you teleport onto Santa's _Reindeer-class starship_, The Historians begin to panic: someone from their search party is missing. A quick life-form scan by the ship's computer reveals that when the missing Historian teleported, he arrived in another part of the ship. + +The door to that area is locked, but the computer can't open it; it can only be opened by physically typing the door codes (your puzzle input) on the numeric keypad on the door. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/21) description._ + +This is the problem that sets casual players apart competitors. I had a hard time solving it. I think I was on track, but +I just couldn't visualize the whole idea of robots controlling robots controlling robots. I love recursion, but just +cannot mentally follow multiple layers of indirection. Anyway. I could solve it in the evening hours, so I'm still on track with _Advent of Code 2024_. + +It was clear from the exponential growth demonstrated by _part 1_ that I wont be able to generate the final string to +be entered. Luckily the problem asked only for the length of it. (Which makes it really artifical: how would the elves enter +such a long key?) + +I created a function called `EncodeKeys` which takes a sequence of keys to be pressed and an array of keypads, and returns the length of the shortest sequence needed to enter the given keys. An empty keypad array means that the sequence is simply entered by a human and no further encoding is needed. Otherwise, the sequence is entered by a robot that needs to be programmed using its keypad. In this case the keys are encoded using the first keypad in the array (the robot's keypad), character by character using _EncodeKey_ which will recursively call back to `EncodeKeys` with the rest of the keypads. + +The `_EncodeKey_` helper function is used to move the robot from position _A_ to position _B_ on the keypad and press the button. Usually, _A_ and _B_ are not in the same row and column, so the movement has both a horizontal and a vertical part. We could go both ways: horizontal first then vertical, or the other way around, and we need to check which movement results in fewer key presses. Lastly, we should not forget that the robot's hand should never move over the empty space `' '`. + +Since every key sequence we need to enter ends with a button press `'A'`, we can always be sure that the robot will stay over the `'A'` button at the end. Since it initially starts over the `'A'` key as well, we have an invariant: at the beginning and the end of `EncodeKeys`, the robot is over the `'A'` key. It can move around while entering the keys, but the invariant holds when it finishes. + +This is great because we don't have to keep track of it! The `Cache` used by `EncodeKey` doesn't need to care about the robot's position recursively. All it depends on is the current robot's position, the position of the next key to be entered, and the number of keypads left in the recursion. This reduces the problem space quite a bit and gives us a well-performing algorithm. + diff --git a/2024/Day21/Solution.cs b/2024/Day21/Solution.cs new file mode 100644 index 000000000..99cf4d96f --- /dev/null +++ b/2024/Day21/Solution.cs @@ -0,0 +1,94 @@ +namespace AdventOfCode.Y2024.Day21; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +using Cache = System.Collections.Concurrent.ConcurrentDictionary<(char currentKey, char nextKey, int depth), long>; +using Keypad = System.Collections.Generic.Dictionary; +record struct Vec2(int x, int y); + +[ProblemName("Keypad Conundrum")] +class Solution : Solver { + + public object PartOne(string input) => Solve(input, 2); + + public object PartTwo(string input) => Solve(input, 25); + + long Solve(string input, int depth) { + var keypad1 = ParseKeypad("789\n456\n123\n 0A"); + var keypad2 = ParseKeypad(" ^A\n"); + var keypads = Enumerable.Repeat(keypad2, depth).Prepend(keypad1).ToArray(); + + var cache = new Cache(); + var res = 0L; + + foreach (var line in input.Split("\n")) { + var num = int.Parse(line[..^1]); + res += num * EncodeKeys(line, keypads, cache); + } + return res; + } + + // Determines the length of the shortest sequence that is needed to enter the given + // keys. An empty keypad array means that the sequence is simply entered by a human + // and no further encoding is needed. Otherwise the sequence is entered by a robot + // which needs to be programmed. In practice this means that the keys are encoded + // using the robots keypad (the first keypad), generating an other sequence of keys. + // This other sequence is then recursively encoded using the rest of the keypads. + long EncodeKeys(string keys, Keypad[] keypads, Cache cache) { + if (keypads.Length == 0) { + return keys.Length; + } else { + // invariant: the robot starts and finishes by pointing at the 'A' key + var currentKey = 'A'; + var length = 0L; + + foreach (var nextKey in keys) { + length += EncodeKey(currentKey, nextKey, keypads, cache); + // while the sequence is entered the current key changes accordingly + currentKey = nextKey; + } + + // at the end the current key should be reset to 'A' + Debug.Assert(currentKey == 'A', "The robot should point at the 'A' key"); + return length; + } + } + long EncodeKey(char currentKey, char nextKey, Keypad[] keypads, Cache cache) => + cache.GetOrAdd((currentKey, nextKey, keypads.Length), _ => { + var keypad = keypads[0]; + + var currentPos = keypad.Single(kvp => kvp.Value == currentKey).Key; + var nextPos = keypad.Single(kvp => kvp.Value == nextKey).Key; + + var dy = nextPos.y - currentPos.y; + var vert = new string(dy < 0 ? 'v' : '^', Math.Abs(dy)); + + var dx = nextPos.x - currentPos.x; + var horiz = new string(dx < 0 ? '<' : '>', Math.Abs(dx)); + + var cost = long.MaxValue; + // we can usually go vertical first then horizontal or vica versa, + // but we should check for the extra condition and don't position + // the robot over the ' ' key: + if (keypad[new Vec2(currentPos.x, nextPos.y)] != ' ') { + cost = Math.Min(cost, EncodeKeys($"{vert}{horiz}A", keypads[1..], cache)); + } + + if (keypad[new Vec2(nextPos.x, currentPos.y)] != ' ') { + cost = Math.Min(cost, EncodeKeys($"{horiz}{vert}A", keypads[1..], cache)); + } + return cost; + }); + + Keypad ParseKeypad(string keypad) { + var lines = keypad.Split("\n"); + return ( + from y in Enumerable.Range(0, lines.Length) + from x in Enumerable.Range(0, lines[0].Length) + select new KeyValuePair(new Vec2(x, -y), lines[y][x]) + ).ToDictionary(); + } +} \ No newline at end of file diff --git a/2024/Day21/illustration.jpeg b/2024/Day21/illustration.jpeg new file mode 100644 index 000000000..00430c919 Binary files /dev/null and b/2024/Day21/illustration.jpeg differ diff --git a/2024/Day21/input.in b/2024/Day21/input.in new file mode 100644 index 000000000..a7fdffcf2 Binary files /dev/null and b/2024/Day21/input.in differ diff --git a/2024/Day21/input.refout b/2024/Day21/input.refout new file mode 100644 index 000000000..5aa4febc5 --- /dev/null +++ b/2024/Day21/input.refout @@ -0,0 +1,2 @@ +176650 +217698355426872 \ No newline at end of file diff --git a/2024/Day22/README.md b/2024/Day22/README.md new file mode 100644 index 000000000..4358da5ea --- /dev/null +++ b/2024/Day22/README.md @@ -0,0 +1,11 @@ +## --- Day 22: Monkey Market --- +As you're all teleported deep into the jungle, a _monkey_ steals The Historians' device! You'll need get it back while The Historians are looking for the Chief. + +The monkey that stole the device seems willing to trade it, but only in exchange for an absurd number of bananas. Your only option is to buy bananas on the Monkey Exchange Market. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/22) description._ + +A refreshing challenge after yesterday's hard one. I created a secret number generator function that returns the 2001 numbers for each seller (the initial one and the 2000 additional). This is enough for _Part 1_. + +For _Part 2_ I maintain the dictionary of buying options for each potential sequence the monkey can recognize with the +combined amount of bananas this would generate from all sellers. \ No newline at end of file diff --git a/2024/Day22/Solution.cs b/2024/Day22/Solution.cs new file mode 100644 index 000000000..6a81e92de --- /dev/null +++ b/2024/Day22/Solution.cs @@ -0,0 +1,60 @@ +namespace AdventOfCode.Y2024.Day22; + +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; + +[ProblemName("Monkey Market")] +class Solution : Solver { + + public object PartOne(string input) { + return GetNums(input).Select(x => (long)SecretNumbers(x).Last()).Sum(); + } + + public object PartTwo(string input) { + // create a dictionary of all buying options then select the one with the most banana: + + var buyingOptions = new Dictionary<(int,int,int,int), int>(); + + foreach (var num in GetNums(input)) { + var optionsBySeller = BuyingOptions(num); + foreach (var seq in optionsBySeller.Keys) { + buyingOptions[seq] = buyingOptions.GetValueOrDefault(seq) + optionsBySeller[seq]; + } + } + return buyingOptions.Values.Max(); + } + + Dictionary<(int,int,int,int), int> BuyingOptions(int seed) { + var bananasSold = Bananas(seed).ToArray(); + var buyingOptions = new Dictionary<(int,int,int,int), int>(); + + // a sliding window of 5 elements over the sold bananas defines the sequence the monkey + // will recognize. add the first occurrence of each sequence to the buyingOptions dictionary + // with the corresponding banana count + var diff = Diff(bananasSold); + for (var i = 0; i < bananasSold.Length - 4; i++) { + var seq = (diff[i], diff[i+1], diff[i+2], diff[i+3]); + if (!buyingOptions.ContainsKey(seq)) { + buyingOptions[seq] = bananasSold[i+4]; + } + } + return buyingOptions; + } + int[] Bananas(int seed) => SecretNumbers(seed).Select(n => n % 10).ToArray(); + + int[] Diff(IEnumerable x) => x.Zip(x.Skip(1)).Select(p => p.Second - p.First).ToArray(); + + IEnumerable SecretNumbers(int seed) { + var mixAndPrune = (int a, int b) => (a ^ b) & 0xffffff; + + yield return seed; + for (var i = 0; i < 2000; i++) { + seed = mixAndPrune(seed, seed << 6); + seed = mixAndPrune(seed, seed >> 5); + seed = mixAndPrune(seed, seed << 11); + yield return seed; + } + } + IEnumerable GetNums(string input) => input.Split("\n").Select(int.Parse); +} \ No newline at end of file diff --git a/2024/Day22/illustration.jpeg b/2024/Day22/illustration.jpeg new file mode 100644 index 000000000..d0ba24944 Binary files /dev/null and b/2024/Day22/illustration.jpeg differ diff --git a/2024/Day22/input.in b/2024/Day22/input.in new file mode 100644 index 000000000..c00da3dae Binary files /dev/null and b/2024/Day22/input.in differ diff --git a/2024/Day22/input.refout b/2024/Day22/input.refout new file mode 100644 index 000000000..895648653 --- /dev/null +++ b/2024/Day22/input.refout @@ -0,0 +1,2 @@ +18525593556 +2089 \ No newline at end of file diff --git a/2024/Day23/README.md b/2024/Day23/README.md new file mode 100644 index 000000000..1bc05ba21 --- /dev/null +++ b/2024/Day23/README.md @@ -0,0 +1,10 @@ +## --- Day 23: LAN Party --- +As The Historians wander around a secure area at Easter Bunny HQ, you come across posters for a [LAN party](https://en.wikipedia.org/wiki/LAN_party) scheduled for today! Maybe you can find it; you connect to a nearby _datalink port_ and download a map of the local network (your puzzle input). + +The network map provides a list of every connection between two computers. For example: + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/23) description._ + +We tackled a graph algorithm problem today, where we had to find maximal cliques in an undirected graph. The literature provides [efficient algorithms](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm) for this problem, but our graph is not too large, so we can use a straightforward "poor man's" strategy as well. + +I started with the _seed_ components, that is single element components for each node. Then, I proceeded to _grow_ these components by adding a single node to them in all possible ways. I can put this in a loop, to get components with size 2, 3, 4, etc. _Part 1_ asks for the number of components that have 3 nodes and have at least one node starting with 't'. _Part 2_ asks for the biggest component that cannot be grown anymore. \ No newline at end of file diff --git a/2024/Day23/Solution.cs b/2024/Day23/Solution.cs new file mode 100644 index 000000000..e43da8f65 --- /dev/null +++ b/2024/Day23/Solution.cs @@ -0,0 +1,56 @@ +namespace AdventOfCode.Y2024.Day23; + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Graph = System.Collections.Generic.Dictionary>; +using Component = string; + +[ProblemName("LAN Party")] +class Solution : Solver { + public object PartOne(string input) { + var g = GetGraph(input); + var components = g.Keys.ToHashSet(); + components = Grow(g, components); + components = Grow(g, components); + return components.Count(c => Members(c).Any(m => m.StartsWith("t"))); + } + + public object PartTwo(string input) { + var g = GetGraph(input); + var components = g.Keys.ToHashSet(); + while (components.Count > 1) { + components = Grow(g, components); + } + return components.Single(); + } + + HashSet Grow(Graph g, HashSet components) => ( + from c in components.AsParallel() + let members = Members(c) + from neighbour in members.SelectMany(m => g[m]).Distinct() + where !members.Contains(neighbour) + where members.All(m => g[neighbour].Contains(m)) + select Extend(c, neighbour) + ).ToHashSet(); + + IEnumerable Members(Component c) => + c.Split(","); + Component Extend(Component c, string item) => + string.Join(",", Members(c).Append(item).OrderBy(x=>x)); + + Graph GetGraph(string input) { + var edges = + from line in input.Split("\n") + let nodes = line.Split("-") + from edge in new []{(nodes[0], nodes[1]), (nodes[1], nodes[0])} + select (From: edge.Item1, To: edge.Item2); + + return ( + from e in edges + group e by e.From into g + select (g.Key, g.Select(e => e.To).ToHashSet()) + ).ToDictionary(); + } +} \ No newline at end of file diff --git a/2024/Day23/illustration.jpeg b/2024/Day23/illustration.jpeg new file mode 100644 index 000000000..1a3da9908 Binary files /dev/null and b/2024/Day23/illustration.jpeg differ diff --git a/2024/Day23/input.in b/2024/Day23/input.in new file mode 100644 index 000000000..2233d6e98 Binary files /dev/null and b/2024/Day23/input.in differ diff --git a/2024/Day23/input.refout b/2024/Day23/input.refout new file mode 100644 index 000000000..18bc5052a --- /dev/null +++ b/2024/Day23/input.refout @@ -0,0 +1,2 @@ +1368 +dd,ig,il,im,kb,kr,pe,ti,tv,vr,we,xu,zi \ No newline at end of file diff --git a/2024/Day24/README.md b/2024/Day24/README.md new file mode 100644 index 000000000..5c708fc50 --- /dev/null +++ b/2024/Day24/README.md @@ -0,0 +1,21 @@ +## --- Day 24: Crossed Wires --- +You and The Historians arrive at the edge of a _large grove_ somewhere in the jungle. After the last incident, the Elves installed a small device that monitors the fruit. While The Historians search the grove, one of them asks if you can take a look at the monitoring device; apparently, it's been malfunctioning recently. + +The device seems to be trying to produce a number through some boolean logic gates. Each gate has two inputs and one output. The gates all operate on values that are either true (1) or false (0). + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/24) description._ + +The first half of the problem was a familiar logic circuit evaluator, we have done this before. I really liked the second part, although I don't have a super generic solution for it. I generated a graph from my input using Graphviz, then realized that the circuit tries to implement a Ripple-carry adder. + +A single full adder consists of two half adders: + +![half adder](halfadder.png) + +Which are chained one after the other like this to get a Ripple-carry adder: + +![full adder](adder.png) + +I took the images from [build-electronic-circuits.com](https://www.build-electronic-circuits.com/full-adder/). + +I implemented this logic in my 'fix' method. I start with the inputs x01 and y01 and try to identify the gates for the individual steps. Where I found an error, I manually checked my input to figure out what went wrong. I had just two different +kind of errors which can be corrected by the fixer. \ No newline at end of file diff --git a/2024/Day24/Solution.cs b/2024/Day24/Solution.cs new file mode 100644 index 000000000..0eed31740 --- /dev/null +++ b/2024/Day24/Solution.cs @@ -0,0 +1,101 @@ +namespace AdventOfCode.Y2024.Day24; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using Circuit = System.Collections.Generic.Dictionary; + +record struct Gate(string in1, string kind, string in2); + +[ProblemName("Crossed Wires")] +class Solution : Solver { + + public object PartOne(string input) { + var (inputs, circuit) = Parse(input); + + var outputs = from label in circuit.Keys where label.StartsWith("z") select label; + + var res = 0L; + foreach (var label in outputs.OrderByDescending(label=>label)) { + res = res * 2 + Eval(label, circuit, inputs); + } + return res; + } + + int Eval(string label, Circuit circuit, Dictionary inputs) { + if (inputs.TryGetValue(label, out var res)) { + return res; + } else { + return circuit[label] switch { + Gate(var in1, "AND", var in2) => Eval(in1, circuit, inputs) & Eval(in2, circuit, inputs), + Gate(var in1, "OR", var in2) => Eval(in1, circuit, inputs) | Eval(in2, circuit, inputs), + Gate(var in1, "XOR", var in2) => Eval(in1, circuit, inputs) ^ Eval(in2, circuit, inputs), + _ => throw new Exception(circuit[label].ToString()), + }; + } + } + + public object PartTwo(string input) { + var circuit = Parse(input).circuit; + return string.Join(",", Fix(circuit).OrderBy(label => label)); + } + + // the circuit should define a full adder for two 44 bit numbers + // this fixer is specific to my input. + IEnumerable Fix(Circuit circuit) { + var cin = Output(circuit, "x00", "AND", "y00"); + for (var i = 1; i < 45; i++) { + var x = $"x{i:D2}"; + var y = $"y{i:D2}"; + var z = $"z{i:D2}"; + + var xor1 = Output(circuit, x, "XOR", y); + var and1 = Output(circuit, x, "AND", y); + var xor2 = Output(circuit, cin, "XOR", xor1); + var and2 = Output(circuit, cin, "AND", xor1); + + if (xor2 == null && and2 == null) { + return SwapAndFix(circuit, xor1, and1); + } + + var carry = Output(circuit, and1, "OR", and2); + if (xor2 != z) { + return SwapAndFix(circuit, z, xor2); + } else { + cin = carry; + } + } + return []; + } + + IEnumerable SwapAndFix(Circuit circuit, string out1, string out2) { + (circuit[out1], circuit[out2]) = (circuit[out2], circuit[out1]); + return Fix(circuit).Concat([out1, out2]); + } + + string Output(Circuit circuit, string x, string kind, string y) => + circuit.SingleOrDefault(pair => + (pair.Value.in1 == x && pair.Value.kind == kind && pair.Value.in2 == y) || + (pair.Value.in1 == y && pair.Value.kind == kind && pair.Value.in2 == x) + ).Key; + + (Dictionary inputs, Circuit circuit) Parse(string input) { + var inputs = new Dictionary(); + var circuit = new Circuit(); + + var blocks = input.Split("\n\n"); + + foreach (var line in blocks[0].Split("\n")) { + var parts = line.Split(": "); + inputs.Add(parts[0], int.Parse(parts[1])); + } + + foreach (var line in blocks[1].Split("\n")) { + var parts = Regex.Matches(line, "[a-zA-z0-9]+").Select(m => m.Value).ToArray(); + circuit.Add(parts[3], new Gate(in1: parts[0], kind: parts[1], in2: parts[2])); + } + return (inputs, circuit); + } + +} \ No newline at end of file diff --git a/2024/Day24/adder.png b/2024/Day24/adder.png new file mode 100644 index 000000000..9b21c1063 Binary files /dev/null and b/2024/Day24/adder.png differ diff --git a/2024/Day24/halfadder.png b/2024/Day24/halfadder.png new file mode 100644 index 000000000..76cdb3d92 Binary files /dev/null and b/2024/Day24/halfadder.png differ diff --git a/2024/Day24/illustration.jpeg b/2024/Day24/illustration.jpeg new file mode 100644 index 000000000..322a5b212 Binary files /dev/null and b/2024/Day24/illustration.jpeg differ diff --git a/2024/Day24/input.in b/2024/Day24/input.in new file mode 100644 index 000000000..2df3714a9 Binary files /dev/null and b/2024/Day24/input.in differ diff --git a/2024/Day24/input.refout b/2024/Day24/input.refout new file mode 100644 index 000000000..bf2c0f14a --- /dev/null +++ b/2024/Day24/input.refout @@ -0,0 +1,2 @@ +61495910098126 +css,cwt,gdd,jmv,pqt,z05,z09,z37 \ No newline at end of file diff --git a/2024/Day25/README.md b/2024/Day25/README.md new file mode 100644 index 000000000..a4042b8c3 --- /dev/null +++ b/2024/Day25/README.md @@ -0,0 +1,6 @@ +## --- Day 25: Code Chronicle --- +Out of ideas and time, The Historians agree that they should go back to check the Chief Historian's office one last time, just in case he went back there without you noticing. + +When you get there, you are surprised to discover that the door to his office is locked! You can hear someone inside, but knocking yields no response. The locks on this floor are all fancy, expensive, virtual versions of [five-pin tumbler locks](https://en.wikipedia.org/wiki/Pin_tumbler_lock), so you contact North Pole security to see if they can help open the door. + +_Visit the website for the full story and [full puzzle](https://adventofcode.com/2024/day/25) description._ diff --git a/2024/Day25/Solution.cs b/2024/Day25/Solution.cs new file mode 100644 index 000000000..16046d22f --- /dev/null +++ b/2024/Day25/Solution.cs @@ -0,0 +1,24 @@ +namespace AdventOfCode.Y2024.Day25; + +using System; +using System.Linq; + +[ProblemName("Code Chronicle")] +class Solution : Solver { + + public object PartOne(string input) { + int[] parsePattern(string[] lines) => + Enumerable.Range(0, lines[0].Length).Select(x => + Enumerable.Range(0, lines.Length).Count(y => lines[y][x] == '#') + ).ToArray(); + + bool match(int[] k, int[] l) => + Enumerable.Range(0, k.Length).All(i => k[i] + l[i] <= 7); + + var patterns = input.Split("\n\n").Select(b => b.Split("\n")); + var keys = patterns.Where(p => p[0][0] == '.').Select(parsePattern).ToList(); + var locks = patterns.Where(p => p[0][0] == '#').Select(parsePattern).ToList(); + + return keys.Sum(k => locks.Count(l => match(l, k))); + } +} \ No newline at end of file diff --git a/2024/Day25/illustration.jpeg b/2024/Day25/illustration.jpeg new file mode 100644 index 000000000..a7665d28e Binary files /dev/null and b/2024/Day25/illustration.jpeg differ diff --git a/2024/Day25/input.in b/2024/Day25/input.in new file mode 100644 index 000000000..9c008e4e5 Binary files /dev/null and b/2024/Day25/input.in differ diff --git a/2024/Day25/input.refout b/2024/Day25/input.refout new file mode 100644 index 000000000..ddc2c2009 --- /dev/null +++ b/2024/Day25/input.refout @@ -0,0 +1 @@ +3242 \ No newline at end of file diff --git a/2024/README.md b/2024/README.md new file mode 100644 index 000000000..e4d82c85c --- /dev/null +++ b/2024/README.md @@ -0,0 +1,4 @@ +# Advent of Code (2024) +Check out https://adventofcode.com/2024. + + diff --git a/2024/SplashScreen.cs b/2024/SplashScreen.cs new file mode 100644 index 000000000..e29c3095b --- /dev/null +++ b/2024/SplashScreen.cs @@ -0,0 +1,370 @@ +using System; + +namespace AdventOfCode.Y2024; + +class SplashScreenImpl : SplashScreen { + + public void Show() { + + var color = Console.ForegroundColor; + Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ "); + Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /* 2024 */\n \n "); + Write(0xcc00, false, " "); + Write(0x888888, false, " .-----. .------------------. \n "); + Write(0xcccccc, false, ".--'"); + Write(0xe3b585, false, "~ ~ ~"); + Write(0xcccccc, false, "| .-' "); + Write(0xffff66, true, "* "); + Write(0x886655, false, "\\ / "); + Write(0xcccccc, false, "'-. 1 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ".--'"); + Write(0xe3b585, false, "~ "); + Write(0xcc00, false, ","); + Write(0xffff66, true, "* "); + Write(0xe3b585, false, "~ "); + Write(0xcccccc, false, "| | "); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "< "); + Write(0x886655, false, "\\_\\_\\|_/__/ "); + Write(0xcccccc, false, "| 2 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ".---'"); + Write(0xe3b585, false, ": ~ "); + Write(0xcc00, false, "'"); + Write(0x5555bb, false, "(~)"); + Write(0xcc00, false, ", "); + Write(0xe3b585, false, "~"); + Write(0xcccccc, false, "| | "); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, "< "); + Write(0xff0000, true, "o"); + Write(0x886655, false, "-_/"); + Write(0xcccccc, false, ".()"); + Write(0x886655, false, "__------"); + Write(0xcccccc, false, "| 3 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x4d8b03, false, "@"); + Write(0x5eabb4, false, ".."); + Write(0x4d8b03, false, "@"); + Write(0xe3b585, false, "'. ~ "); + Write(0xcc00, false, "\" ' "); + Write(0xe3b585, false, "~ "); + Write(0xcccccc, false, "| |"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "< "); + Write(0x886655, false, "\\____ "); + Write(0xcc00, false, ".'"); + Write(0xcccccc, false, "| 4 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x488813, false, "_"); + Write(0x5eabb4, false, ".~."); + Write(0x488813, false, "_"); + Write(0x7fbd39, false, "@"); + Write(0xe3b585, false, "'.. ~ ~ "); + Write(0xffff66, true, "*"); + Write(0xcccccc, false, "| | "); + Write(0xaaaaaa, false, "_| |_ "); + Write(0xcccccc, false, "..\\_"); + Write(0x886655, false, "\\_ "); + Write(0xcc00, false, "..'"); + Write(0xffff66, true, "* "); + Write(0xcccccc, false, "| 5 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xffffff, false, "||| "); + Write(0x427322, false, "@ "); + Write(0xe3b585, false, "'''..."); + Write(0xcccccc, false, "| |"); + Write(0xa25151, false, "... "); + Write(0xcccccc, false, ".' '."); + Write(0xcc00, false, "'''.."); + Write(0xd4dde4, false, "/"); + Write(0xcc00, false, ".."); + Write(0xcccccc, false, "| 6 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x1461f, false, "@"); + Write(0xffffff, false, "~~~"); + Write(0x488813, false, "@"); + Write(0x4d8b03, false, "@##"); + Write(0x7fbd39, false, "@"); + Write(0x4d8b03, false, "# "); + Write(0x427322, false, "@# "); + Write(0xcccccc, false, "| |"); + Write(0xa5a8af, false, "/\\ "); + Write(0xa25151, false, "''. "); + Write(0xcccccc, false, "| | "); + Write(0xccccff, false, "-"); + Write(0xd4dde4, false, "/ "); + Write(0xffffff, false, ":"); + Write(0xcccccc, false, "| 7 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x5eabb4, false, "~~."); + Write(0xcccccc, false, ".--."); + Write(0x666666, false, " _____ "); + Write(0xcccccc, false, "| |"); + Write(0xffff66, true, "* "); + Write(0xa5a8af, false, "/"); + Write(0xdf2308, true, "~"); + Write(0xa5a8af, false, "\\ "); + Write(0xa25151, false, "'."); + Write(0xcccccc, false, "| | "); + Write(0xccccff, false, "- "); + Write(0xd4dde4, false, "/ "); + Write(0xffffff, false, ".'"); + Write(0xcccccc, false, "| 8 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "'---' |"); + Write(0x666666, false, "|[][]_\\-"); + Write(0xcccccc, false, "| |"); + Write(0xdf2308, true, "~"); + Write(0xa5a8af, false, "/ "); + Write(0xffff66, true, "* "); + Write(0xa5a8af, false, "\\ "); + Write(0xa25151, false, ":"); + Write(0xcccccc, false, "| | "); + Write(0xffff66, true, "*"); + Write(0xffffff, false, "..' "); + Write(0xcccccc, false, "| 9 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x666666, false, "------- "); + Write(0xcccccc, false, "| | "); + Write(0xa5a8af, false, "/\\ "); + Write(0xa25151, false, ".'"); + Write(0xcccccc, false, "| |"); + Write(0xffffff, false, "'''"); + Write(0xc8ff, false, "~~~~~"); + Write(0xcccccc, false, "| 10 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xccccff, false, "......."); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "| |"); + Write(0xa5a8af, false, "/\\ "); + Write(0xa25151, false, "..' "); + Write(0xcccccc, false, "| | "); + Write(0xb5ed, false, ". "); + Write(0xffffff, false, ". "); + Write(0xb5ed, false, "."); + Write(0xcccccc, false, "| 11 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xffffff, false, "- - "); + Write(0xcccccc, false, "| |"); + Write(0xa25151, false, "'''"); + Write(0x333333, false, "::"); + Write(0xffff66, true, ":"); + Write(0x333333, false, "::"); + Write(0xcccccc, false, "| | "); + Write(0xffffff, false, ". "); + Write(0xa2db, false, ". ."); + Write(0xff0000, true, "."); + Write(0xcccccc, false, "| 12 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xffffff, false, "'. - -"); + Write(0xcccccc, false, "| | "); + Write(0x333333, false, "::"); + Write(0x9900, true, ":"); + Write(0x333333, false, "::"); + Write(0xcccccc, false, "| |"); + Write(0x66ff, true, ". "); + Write(0xffffff, false, ".' "); + Write(0x9933, true, ". "); + Write(0x91cc, false, "."); + Write(0xcccccc, false, "| 13 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xcc00, false, "..."); + Write(0xffffff, false, "'..''"); + Write(0xcccccc, false, "| |"); + Write(0xffffff, true, ". "); + Write(0x333333, false, ".:"); + Write(0x9900, true, ":::"); + Write(0x333333, false, ":"); + Write(0xcccccc, false, "| |"); + Write(0xc74c30, false, "."); + Write(0xff0000, false, "."); + Write(0xffffff, false, "|\\"); + Write(0xff0000, false, "."); + Write(0xc74c30, false, "."); + Write(0xa47a4d, false, "''"); + Write(0xcccccc, false, "| 14 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xcc00, false, ". ''. "); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, ". "); + Write(0x9900, true, ":::::"); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, "──┬┴┴┴┬─"); + Write(0xcccccc, false, "| 15 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xcc00, false, "'."); + Write(0x5555bb, false, "~ "); + Write(0xcc00, false, "'."); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, " : "); + Write(0x333333, false, "::"); + Write(0x553322, true, ":"); + Write(0x333333, false, "::"); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, "──┤AoC├o"); + Write(0xcccccc, false, "| 16 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xcc00, false, ". "); + Write(0xffff66, true, "*"); + Write(0xcc00, false, "'."); + Write(0x5555bb, false, "~ "); + Write(0xcc00, false, ":"); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, " '. "); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, "┬o┤ten├─"); + Write(0xcccccc, false, "| 17 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xcc00, false, "'..' .'"); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, " '"); + Write(0x456efe, true, "o "); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, "┘"); + Write(0xffff66, true, "*"); + Write(0x666666, false, "┤yrs├─"); + Write(0xcccccc, false, "| 18 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0x5555bb, false, "~ "); + Write(0xcc00, false, "..' "); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, ": '."); + Write(0x333333, false, ".."); + Write(0xcccccc, false, "| |"); + Write(0x666666, false, "─┘├┬┬┬┴─"); + Write(0xcccccc, false, "| 19 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xcc00, false, "'''"); + Write(0xcccccc, false, ")) | | "); + Write(0xbee4e7, true, "o "); + Write(0xffff66, true, "*"); + Write(0x666666, false, " : "); + Write(0xcccccc, false, "'. .'"); + Write(0x666666, false, "──┘"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<<"); + Write(0xcccccc, false, "| 20 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, ".------'"); + Write(0x66ff, false, ".-"); + Write(0xcccccc, false, "(("); + Write(0x66ff, false, "---."); + Write(0xcccccc, false, "'------. |"); + Write(0x666666, false, " :"); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "\\| "); + Write(0x333399, false, "~ "); + Write(0x9900ff, false, "_"); + Write(0xcccccc, false, "'' "); + Write(0x9900ff, false, "O> "); + Write(0x9900, false, ">>"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<"); + Write(0xff9900, true, "o"); + Write(0x9900, false, "<"); + Write(0xcccccc, false, "| 21 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "| "); + Write(0xff0000, false, ".---_ "); + Write(0x66ff, false, "'------'_ "); + Write(0xaaaaaa, false, ".~' "); + Write(0xcccccc, false, "| | |"); + Write(0xff0000, false, "\\|"); + Write(0x9900ff, false, "\\ / \\ /"); + Write(0x333399, false, "~ "); + Write(0x9900, false, ">"); + Write(0xff0000, true, "@"); + Write(0x9900, false, "<<"); + Write(0xffff66, true, "*"); + Write(0x9900, false, "<"); + Write(0x66ff, true, "O"); + Write(0xcccccc, false, "| 22 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0xff0000, false, "/ "); + Write(0x880000, false, "/ "); + Write(0xff0000, false, "/\\|"); + Write(0x66ff, false, "| | )"); + Write(0xaaaaaa, false, "/"); + Write(0xe6410b, false, "~"); + Write(0xaaaaaa, false, "\\ "); + Write(0xcccccc, false, "| |"); + Write(0x66ff, false, "___"); + Write(0xff0000, false, "|"); + Write(0xcccccc, false, "\\|"); + Write(0x66ff, false, "________"); + Write(0x9900, false, ">"); + Write(0x66ff, true, "O"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0x9900, false, ">>"); + Write(0xff9900, true, "o"); + Write(0xcccccc, false, "| 23 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x880000, false, "/ | "); + Write(0xff0000, false, "\\ "); + Write(0xffff66, true, "*"); + Write(0x66ff, false, "| |/"); + Write(0xaaaaaa, false, "/ "); + Write(0xe6410b, false, "/ "); + Write(0xaaaaaa, false, "\\ "); + Write(0xcccccc, false, "| | "); + Write(0x9b715b, false, "----@ "); + Write(0xaaaaaa, false, "_"); + Write(0xd0b376, false, "|%%%=%%|"); + Write(0xaaaaaa, false, "_ "); + Write(0xcccccc, false, "| 24 "); + Write(0xffff66, false, "**\n "); + Write(0xcccccc, false, "|"); + Write(0x880000, false, "/ \\ "); + Write(0xff0000, false, "\\ "); + Write(0x66ff, false, "'------'"); + Write(0xaaaaaa, false, "/ "); + Write(0xe6410b, false, "/ \\ "); + Write(0xaaaaaa, false, "\\"); + Write(0xcccccc, false, "| '-."); + Write(0x9b715b, false, "! /^\\ "); + Write(0xaaaaaa, false, "/ \\"); + Write(0x5eabb4, false, ".~~."); + Write(0xaaaaaa, false, "/ \\"); + Write(0xcccccc, false, ".-' 25 "); + Write(0xffff66, false, "**\n "); + Write(0x888888, false, "'----------------------' '------------------' \n \n"); + + Console.ForegroundColor = color; + Console.WriteLine(); + } + + private static void Write(int rgb, bool bold, string text){ + Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}"); + } +} \ No newline at end of file diff --git a/2024/calendar.svg b/2024/calendar.svg new file mode 100644 index 000000000..576f4919f --- /dev/null +++ b/2024/calendar.svg @@ -0,0 +1,48 @@ + + + + +▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄  ▄▄▄ ▄█  ▄▄ ▄▄▄ ▄▄█ ▄▄▄ +█▄█ █ █ █ █ █▄█ █ █ █   █ █ █▄  █  █ █ █ █ █▄█ +█ █ █▄█ ▀▄▀ █▄▄ █ █ █▄  █▄█ █   █▄ █▄█ █▄█ █▄▄  /* 2024 */ +  +          .-----.          .------------------.          +       .--'~ ~ ~|        .-' *       \  /     '-.   1 ** +    .--'~  ,* ~ |        |  >o<   \_\_\|_/__/   |   2 ** +.---': ~ '(~), ~|        | >@>O< o-_/.()__------|   3 ** +|@..@'. ~ " ' ~ |        |>O>o<@< \____       .'|   4 ** +|_.~._@'.. ~ ~ *|        | _| |_    ..\_\_ ..'* |   5 ** +| ||| @   '''...|        |...     .'  '.'''../..|   6 ** +|@~~~@@##@# @#  |        |/\ ''.  |    |   -/  :|   7 ** +|~~..--. _____  |        |* /~\ '.|    | - /  .'|   8 ** +'---'  ||[][]_\-|        |~/ * \ :|    |  *..'  |   9 ** +       |------- |        |   /\ .'|    |'''~~~~~|  10 ** +       |.......||        |/\ ..'  |    | . .   .|  11 ** +       |  -  -  |        |''':::::|    |  . . ..|  12 ** +       |'. -   -|        |   :::::|    |. .' . .|  13 ** +       |...'..''|        |. .:::::|    |..|\..''|  14 ** +       |.  ''.  |        |.  :::::|    ||  15 ** +       | '.~  '.|        | : :::::|    |AoCo|  16 ** +       |. *'.~ :|        |  '.    |    |oten|  17 ** +       | '..' .'|        |   'o   |    |*yrs|  18 ** +       | ~ ..'  |        |:   '...|    ||  19 ** +       |'''))   |        | o  * : '.  .'>>o<<|  20 ** +.------'.-((---.'------. |  :|\| ~ _'' O> >>@<o<|  21 ** +| .---_ '------'_  .~' | |   |\|\ / \ /~ >@<<*<O|  22 ** +|/ / /\||      | )/~\  | |___|\|________>O>>o>>o|  23 ** +|/ | \ *|      |// / \ | |  ----@  _|%%%=%%|_   |  24 ** +|/  \ \ '------'/ / \ \| '-.! /^\ /  \.~~./  \.-'  25 ** +'----------------------'   '------------------'          + + + + \ No newline at end of file diff --git a/App.cs b/App.cs index f34502567..75d69d14d 100644 --- a/App.cs +++ b/App.cs @@ -56,22 +56,22 @@ var tsolversSelected = tsolvers.First(tsolver => SolverExtensions.Year(tsolver) == year && SolverExtensions.Day(tsolver) == day); - return () => Runner.RunAll(GetSolvers(tsolversSelected)); + return () => Runner.RunAll(true, true, true, GetSolvers(tsolversSelected)); }) ?? Command(args, Args("[0-9]+"), m => { var year = int.Parse(m[0]); var tsolversSelected = tsolvers.Where(tsolver => SolverExtensions.Year(tsolver) == year); - return () => Runner.RunAll(GetSolvers(tsolversSelected.ToArray())); + return () => Runner.RunAll(true, true, true, GetSolvers(tsolversSelected.ToArray())); }) ?? Command(args, Args("([0-9]+)/all"), m => { var year = int.Parse(m[0]); var tsolversSelected = tsolvers.Where(tsolver => SolverExtensions.Year(tsolver) == year); - return () => Runner.RunAll(GetSolvers(tsolversSelected.ToArray())); + return () => Runner.RunAll(true, true, true, GetSolvers(tsolversSelected.ToArray())); }) ?? Command(args, Args("all"), m => { - return () => Runner.RunAll(GetSolvers(tsolvers)); + return () => Runner.RunAll(true, true, true, GetSolvers(tsolvers)); }) ?? Command(args, Args("today"), m => { var dt = DateTime.UtcNow.AddHours(-5); @@ -82,26 +82,17 @@ SolverExtensions.Day(tsolver) == dt.Day); return () => - Runner.RunAll(GetSolvers(tsolversSelected)); + Runner.RunAll(true, true, true, GetSolvers(tsolversSelected)); } else { throw new AocCommuncationError("Event is not active. This option works in Dec 1-25 only)"); } }) ?? Command(args, Args("calendars"), _ => { - return () => { - var tsolversSelected = ( - from tsolver in tsolvers - group tsolver by SolverExtensions.Year(tsolver) into g - orderby SolverExtensions.Year(g.First()) descending - select g.First() - ).ToArray(); - - var solvers = GetSolvers(tsolversSelected); - foreach (var solver in solvers) { - solver.SplashScreen().Show(); - } - }; + return () => Runner.RunAll(false, true, false, GetSolvers(tsolvers)); + }) ?? + Command(args, Args("loc"), _ => { + return () => Runner.RunAll(false, false, true, GetSolvers(tsolvers)); }) ?? new Action(() => { Console.WriteLine(Usage.Get()); @@ -156,6 +147,7 @@ [year] Solve the whole year all Solve everything calendars Show the calendars + loc Show the line of code charts 2) To start working on new problems: login to https://adventofcode.com, then copy your session cookie, and export diff --git a/Lib/Generator/ReadmeGenerator.cs b/Lib/Generator/ReadmeGenerator.cs index 9860a9fa4..5b88fe66a 100644 --- a/Lib/Generator/ReadmeGenerator.cs +++ b/Lib/Generator/ReadmeGenerator.cs @@ -1,83 +1,7 @@ -using System.Linq; using AdventOfCode.Model; namespace AdventOfCode.Generator; -class ProjectReadmeGenerator { - public string Generate(int firstYear, int lastYear) { - - return $""" - # Advent of Code ({firstYear}-{lastYear}) - C# solutions to the [Advent of Code](https://adventofcode.com) problems. - - - - This project is best used as a template for your own AoC repository and a guide in solving - the puzzles. I put a lot of effort into my solutions. I aim for clarity which means that - they are not super effective or super short, but hopefully more readable. - - Due to copyright requirements I'm not allowed to include my input files within this repository - so you cannot just clone it and run. However I wanted to have a self contained documentary - for myself that I can later refactor, so I decided to commit the encrypted version of the - input files. It doesn't violate the copyright since it's just random garbage for everyone else - but when I check it out, a plugin called `git-crypt` decrypts all my inputs transparently, - so I can work with them freely. On commit the whole process is reversed and the files get - encrypted again. - - If you find this useful, please [support](https://github.com/sponsors/encse) me. - - ## Dependencies - - - This project is based on `.NET 8` and `C# 12`. - - `AngleSharp` is used for problem download. - - ## Use it as a solution template: - - 1. Install .NET Core - 2. Clone the repo - 3. Remove all solution folders - - ``` - > cd repo-dir - > rm -fr 20* - ``` - - 4. Install and initialize git-crypt: - - ``` - > brew install git-crypt - > cd repo-dir - > git-crypt init - > git-crypt export-key ~/aoc-crypt.key - ``` - - 5. Don't commit `aoc-crypt.key` into a public repo, back it up in some protected place. - If you need to clone your repo later you will need to unlock it using this key such as: - - ``` - > git clone ... - > cd repo-dir - > git-crypt unlock ~/aoc-crypt.key - ``` - - 6. Get help with `dotnet run` and start coding. - ``` - {Usage.Get()} - ``` - - ## Working in Visual Studio Code - If you prefer, you can work directly in VSCode as well. - - Open the command Palette (⇧ ⌘ P), select `Tasks: Run Task` then e.g. `update today`. - - Work on part 1. Check the solution with the `upload today` task. Continue with part 2. - - **Note:** this feature relies on the "Memento Inputs" extension to store your session cookie, you need - to set it up in advance from the Command Palette with `Install Extensions`. - """; - } -} - class ReadmeGeneratorForYear { public string Generate(Calendar calendar) { return $""" diff --git a/Lib/Generator/SolutionTemplateGenerator.cs b/Lib/Generator/SolutionTemplateGenerator.cs index 331851f67..8b67a4ed3 100644 --- a/Lib/Generator/SolutionTemplateGenerator.cs +++ b/Lib/Generator/SolutionTemplateGenerator.cs @@ -13,6 +13,7 @@ namespace AdventOfCode.Y{{problem.Year}}.Day{{problem.Day:00}}; using System.Linq; using System.Text.RegularExpressions; using System.Text; + using System.Numerics; [ProblemName("{{problem.Title}}")] class Solution : Solver { diff --git a/Lib/Model/Calendar.cs b/Lib/Model/Calendar.cs index 119fd5d68..2d6fcc714 100644 --- a/Lib/Model/Calendar.cs +++ b/Lib/Model/Calendar.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using System.Text; using AngleSharp.Dom; +using System.Globalization; namespace AdventOfCode.Model; @@ -97,7 +98,7 @@ public static Calendar Parse(int year, IDocument document) { foreach (var textNode in GetText(calendar)) { var text = textNode.Text(); var style = textNode.ParentElement.ComputeCurrentStyle(); - var rgbaColor = style["color"]; + var rgbaColor = !string.IsNullOrEmpty(style["color"]) ? style["color"]: "rgba(204,204,204,1)"; var bold = !string.IsNullOrEmpty(style["text-shadow"]); if (style["position"] == "absolute" || @@ -111,7 +112,7 @@ public static Calendar Parse(int year, IDocument document) { var m = Regex.Match(widthSpec, "[.0-9]+"); if (m.Success) { - var width = double.Parse(m.Value) * 1.7; + var width = double.Parse(m.Value, CultureInfo.InvariantCulture) * 1.7; var c = (int)Math.Round(width - text.Length, MidpointRounding.AwayFromZero); if (c > 0) { text += new string(' ', c); diff --git a/Lib/Model/Problem.cs b/Lib/Model/Problem.cs index ffe5ce651..b1ae3a94f 100644 --- a/Lib/Model/Problem.cs +++ b/Lib/Model/Problem.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text.RegularExpressions; using AngleSharp.Dom; -using Microsoft.CodeAnalysis.CSharp.Syntax; namespace AdventOfCode.Model; class Problem { @@ -17,7 +16,7 @@ class Problem { public static Problem Parse(int year, int day, string url, IDocument document, string input) { - var md = ParseMdIntro(document, 3, url); + var md = ParseMdIntro(document, 2, url); var answers = ParseAnswers(document); var title = document.QuerySelector("h2").TextContent; @@ -32,7 +31,7 @@ public static Problem Parse(int year, int day, string url, IDocument document, s static string ParseMdIntro(IDocument document, int paragraphs, string url) { var article = ParseMd(document).Split("\n\n").ToList(); article = article.Take(Math.Min(paragraphs, article.Count)).ToList(); - article.Add($"Read the [full puzzle]({url}).\n"); + article.Add($"_Visit the website for the full story and [full puzzle]({url}) description._\n"); return string.Join("\n\n", article); } diff --git a/Lib/Runner.cs b/Lib/Runner.cs index ed65b8dd4..4ae3e3792 100644 --- a/Lib/Runner.cs +++ b/Lib/Runner.cs @@ -150,7 +150,7 @@ public static SolverResult RunSolver(Solver solver) { return new SolverResult(answers.ToArray(), errors.ToArray()); } - public static void RunAll(params Solver[] solvers) { + public static void RunAll(bool executeSolvers, bool showSplashScreen, bool showLocChart, params Solver[] solvers) { var errors = new List(); @@ -159,19 +159,27 @@ public static void RunAll(params Solver[] solvers) { foreach (var solver in solvers) { if (lastYear != solver.Year()) { - SlocChart.Show(slocs); + if (showLocChart){ + SlocChart.Show(lastYear, slocs); + } slocs.Clear(); - - solver.SplashScreen().Show(); + + if (showSplashScreen){ + solver.SplashScreen().Show(); + } lastYear = solver.Year(); } slocs.Add((solver.Day(), solver.Sloc())); - var result = RunSolver(solver); + if (executeSolvers){ + var result = RunSolver(solver); + WriteLine(); + errors.AddRange(result.errors); + } + } + if (showLocChart){ + SlocChart.Show(lastYear, slocs); WriteLine(); - errors.AddRange(result.errors); } - SlocChart.Show(slocs); - WriteLine(); if (errors.Any()) { WriteLine(ConsoleColor.Red, "Errors:\n" + string.Join("\n", errors)); @@ -182,12 +190,10 @@ public static void RunAll(params Solver[] solvers) { } private static void WriteLine(ConsoleColor color = ConsoleColor.Gray, string text = "") { - Write(color, text + "\n"); + Terminal.WriteLine(color, text); } private static void Write(ConsoleColor color = ConsoleColor.Gray, string text = "") { - var c = Console.ForegroundColor; - Console.ForegroundColor = color; - Console.Write(text); - Console.ForegroundColor = c; + Terminal.Write(color, text); } + } diff --git a/Lib/SlocChart.cs b/Lib/SlocChart.cs index 9a86c8569..f4a667a77 100644 --- a/Lib/SlocChart.cs +++ b/Lib/SlocChart.cs @@ -1,21 +1,26 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.VisualBasic; namespace AdventOfCode; class SlocChart { - public static void Show(List<(int day, int sloc)> slocs) { + public static void Show(int year, List<(int day, int sloc)> slocs) { if (slocs.Count < 2) { return; } - Console.WriteLine(" In code lines"); - Console.WriteLine(""); var chars = "█▁▂▃▄▅▆▇"; - var max = slocs.Select(sloc => sloc.sloc).Max(); + var max = slocs.Max(sloc => sloc.sloc); + var min = slocs.Min(sloc => sloc.sloc); + var total = slocs.Sum(sloc => sloc.sloc); + + Console.WriteLine($" {year } in code lines total: {total} max: {max} min: {min}"); + Console.WriteLine(""); + var columns = new List>(); @@ -67,15 +72,12 @@ public static void Show(List<(int day, int sloc)> slocs) { rows.Insert(0, row); } - var c = Console.ForegroundColor; foreach (var row in rows) { foreach (var item in row) { - Console.ForegroundColor = item.c; - Console.Write(item.st); + Terminal.Write(item.c, item.st); } Console.WriteLine(); } - Console.ForegroundColor = c; Console.WriteLine(""); } } \ No newline at end of file diff --git a/Lib/Terminal.cs b/Lib/Terminal.cs new file mode 100644 index 000000000..6f9a3d1d9 --- /dev/null +++ b/Lib/Terminal.cs @@ -0,0 +1,36 @@ + +using System; + +class Terminal { + public static void WriteLine(ConsoleColor color = ConsoleColor.Gray, string text = "") { + Write(color, text + "\n"); + } + public static void Write(ConsoleColor color = ConsoleColor.Gray, string text = "") { + + Console.Write($"\u001b[{ToAnsiColorCode(color)}"); + Console.Write(text); + Console.Write("\u001b[0m"); + } + + private static string ToAnsiColorCode(ConsoleColor color) { + switch(color) { + case ConsoleColor.Black: return "30m"; + case ConsoleColor.DarkRed: return "31m"; + case ConsoleColor.DarkGreen: return "32m"; + case ConsoleColor.DarkYellow: return "33m"; + case ConsoleColor.DarkBlue: return "34m"; + case ConsoleColor.DarkMagenta: return "35m"; + case ConsoleColor.DarkCyan: return "36m"; + case ConsoleColor.DarkGray: return "37m"; + case ConsoleColor.Gray: return "90m"; + case ConsoleColor.Red: return "91m"; + case ConsoleColor.Green: return "92m"; + case ConsoleColor.Yellow: return "93m"; + case ConsoleColor.Blue: return "94m"; + case ConsoleColor.Magenta: return "95m"; + case ConsoleColor.Cyan: return "96m"; + case ConsoleColor.White: return "97m"; + } + throw new Exception($"unhandled color code {color}"); + } +} \ No newline at end of file diff --git a/Lib/Updater.cs b/Lib/Updater.cs index 30c9e33f5..62d2dde2a 100644 --- a/Lib/Updater.cs +++ b/Lib/Updater.cs @@ -49,7 +49,6 @@ public async Task Update(int year, int day) { years = new int[] { year }; } - UpdateProjectReadme(years.Min(), years.Max()); UpdateReadmeForYear(calendar); UpdateSplashScreen(calendar); UpdateReadmeForDay(problem); @@ -205,11 +204,6 @@ void UpdateSolutionTemplate(Problem problem) { } } - void UpdateProjectReadme(int firstYear, int lastYear) { - var file = Path.Combine("README.md"); - WriteFile(file, new ProjectReadmeGenerator().Generate(firstYear, lastYear)); - } - void UpdateReadmeForYear(Calendar calendar) { var file = Path.Combine(SolverExtensions.WorkingDir(calendar.Year), "README.md"); WriteFile(file, new ReadmeGeneratorForYear().Generate(calendar)); diff --git a/README.md b/README.md index 5d2720cdc..8b616b4f6 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,18 @@ -# Advent of Code (2015-2023) -C# solutions to the [Advent of Code](https://adventofcode.com) problems. + # Advent of Code (2015-2024) + C# solutions to the [Advent of Code](https://adventofcode.com) problems. - + -This project is best used as a template for your own AoC repository and a guide in solving -the puzzles. I put a lot of effort into my solutions. I aim for clarity which means that -they are not super effective or super short, but hopefully more readable. + I'm making a [website](https://aoc.csokavar.hu) out of this. + + A lot of effort goes into my solutions to present things in an easy to understand and elegant way. Clarity first also means less emphasis on speed, but I try to balance it until each puzzle's runtime fits into a second. + + The framework I'm using is freely available and it's pretty streamlined by now. You can start with the + https://github.com/encse/adventofcode-template repository. -Due to copyright requirements I'm not allowed to include my input files within this repository -so you cannot just clone it and run. However I wanted to have a self contained documentary -for myself that I can later refactor, so I decided to commit the encrypted version of the -input files. It doesn't violate the copyright since it's just random garbage for everyone else -but when I check it out, a plugin called `git-crypt` decrypts all my inputs transparently, -so I can work with them freely. On commit the whole process is reversed and the files get -encrypted again. + Like what you see? Consider [sponsoring](https://github.com/sponsors/encse) me. -## Dependencies - -- This project is based on `.NET 8` and `C# 12`. -- `AngleSharp` is used for problem download. - -## Use it as a solution template: - -1. Install .NET Core -2. Clone the repo -3. Remove all solution folders - -``` -> cd repo-dir -> rm -fr 20* -``` - -4. Install and initialize git-crypt: - -``` -> brew install git-crypt -> cd repo-dir -> git-crypt init -> git-crypt export-key ~/aoc-crypt.key -``` - -5. Don't commit `aoc-crypt.key` into a public repo, back it up in some protected place. -If you need to clone your repo later you will need to unlock it using this key such as: - -``` -> git clone ... -> cd repo-dir -> git-crypt unlock ~/aoc-crypt.key -``` - -6. Get help with `dotnet run` and start coding. -``` -Usage: dotnet run [arguments] -1) To run the solutions and admire your advent calendar: - - [year]/[day|all] Solve the specified problems - today Shortcut to the above - [year] Solve the whole year - all Solve everything - - calendars Show the calendars - -2) To start working on new problems: -login to https://adventofcode.com, then copy your session cookie, and export -it in your console like this - - export SESSION=73a37e9a72a... - -then run the app with - - update [year]/[day] Prepares a folder for the given day, updates the input, - the readme and creates a solution template. - update today Shortcut to the above. - -3) To upload your answer: -set up your SESSION variable as above. - - upload [year]/[day] Upload the answer for the selected year and day. - upload today Shortcut to the above. - -4) Don't forget to tip the maintainer https://github.com/sponsors/encse. -``` - -## Working in Visual Studio Code -If you prefer, you can work directly in VSCode as well. - - Open the command Palette (⇧ ⌘ P), select `Tasks: Run Task` then e.g. `update today`. - - Work on part 1. Check the solution with the `upload today` task. Continue with part 2. - - **Note:** this feature relies on the "Memento Inputs" extension to store your session cookie, you need - to set it up in advance from the Command Palette with `Install Extensions`. - -## How can I help? - -If you find this useful, please [support](https://github.com/sponsors/encse) me. + ## Dependencies + - Based on `.NET 9` and `C# 13`. + - `AngleSharp` is used for problem download. + - git-crypt to store the input files in an encrypted form diff --git a/adventofcode.csproj b/adventofcode.csproj index b7d412597..426add6a1 100755 --- a/adventofcode.csproj +++ b/adventofcode.csproj @@ -1,14 +1,13 @@ Exe - net8.0 - 12 + net9.0 + 13 true false - \ No newline at end of file diff --git a/docs/build.js b/docs/build.js new file mode 100644 index 000000000..4a0efdc78 --- /dev/null +++ b/docs/build.js @@ -0,0 +1,185 @@ +const fs = require('fs'); +const path = require('path'); +const marked = require('marked'); + + +function media(dir){ + const files = fs.readdirSync(dir); + return files.filter(file => + path.extname(file).toLowerCase() === '.gif' || + path.extname(file).toLowerCase() === '.png' + ).map(file => path.join(dir, file)); +} + +function* findReadmes(dir) { + const entries = fs.readdirSync(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + + if (entry.isDirectory()) { + const match = fullPath.match(/(\d{4})\/Day(\d{1,2})/i); + if (match) { + const year = parseInt(match[1], 10); + const day = parseInt(match[2], 10); + + // Check the directory for a readme.md file + const readmePath = path.join(fullPath, 'README.md'); + const solutionPath = path.join(fullPath, 'Solution.cs'); + const illustrationPath = path.join(fullPath, 'illustration.jpeg'); + if (fs.existsSync(readmePath) && fs.existsSync(solutionPath)) { + + const rawContent = fs.readFileSync(readmePath, 'utf8'); + + let name = ''; + const match = rawContent.match(/^## --- Day \d+: (.+?) ---/); + if (match) { + name = match[1]; + } + + let lines = rawContent.split('\n'); + while (lines.length > 0) { + let line = lines.shift(); + if (line.match(/^## --- Day \d+: (.+?) ---/)) { + break; + } + } + + + yield { + year, + day, + path: readmePath, + name: name, + notes: marked.parse(lines.join('\n')), + code: fs.readFileSync(solutionPath, 'utf8'), + illustration: fs.existsSync(illustrationPath) ? illustrationPath : 'docs/elf.jpeg', + media: media(fullPath) + }; + } + } + + // Recursively search within this directory + yield* findReadmes(fullPath); + } + } +} + + +function copyDirectory(src, dest) { + if (!fs.existsSync(src)) { + throw new Error(`Source directory does not exist: ${src}`); + } + + if (!fs.existsSync(dest)) { + fs.mkdirSync(dest, { recursive: true }); + } + + const items = fs.readdirSync(src); + + items.forEach(item => { + const srcPath = path.join(src, item); + const destPath = path.join(dest, item); + + if (fs.statSync(srcPath).isDirectory()) { + copyDirectory(srcPath, destPath); + } else { + fs.copyFileSync(srcPath, destPath); + } + }); + }; + + +function loadTemplate(templatePath) { + return fs.readFileSync(templatePath, 'utf8'); +} + + +function fillTemplate(template, replacements) { + return template.replace(/{{\s*([\w-]+)\s*}}/g, (_, key) => replacements[key] || ''); +} + +function generateYearPicker(year, day, yearToDays) { + let options = ''; + for (let y of Object.keys(yearToDays).sort()){ + let lastDay = yearToDays[y][yearToDays[y].length-1]; + let target = `/${y}/${lastDay}/` + options += `${y}` + } + + return ` + `; +} + +function generateDayPicker(year, day, yearToDays) { + let res = ''; + for (i = 1; i <= yearToDays[year].length; i++) { + const link = `${i.toString().padStart(2, '0')}`; + res += i == day ? `${link}` : `${link}`; + } + return res; +} + +function escapeHtml(st) { + const map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + return st.replace(/[&<>"']/g, (char) => map[char]); +} + +const template = loadTemplate('docs/template.html'); +const redirectTemplate = loadTemplate('docs/redirect_template.html') + +const yearToDays = {}; +for (const { year, day } of findReadmes('.')) { + if (!yearToDays[year]) { + yearToDays[year] = []; + } + yearToDays[year].push(day); +} + +for(const year of Object.keys(yearToDays)){ + yearToDays[year] = yearToDays[year].sort((a,b) => a-b); +} + +const lastYear = Math.max(...Object.keys(yearToDays)) +const lastDay = Math.max(...yearToDays[lastYear]); + +copyDirectory('docs/static', 'build'); + +const filledRedirectTemplate = fillTemplate(redirectTemplate, { + 'default-page': `/${lastYear}/${lastDay}/`, +}); + +fs.writeFileSync(path.join('build', 'index.html'), filledRedirectTemplate); + +const currentYear = new Date().getFullYear(); +// Iterate over readme.md files and print filled templates +for (const { year, day, name, notes, code, illustration, media } of findReadmes('.')) { + const filledHtml = fillTemplate(template, { + url: `https://aoc.csokavar.hu/${year}/${day}/`, + 'problem-id': `${year}/${day}`, + 'problem-name': `${name}`, + 'year-picker': generateYearPicker(year,day, yearToDays), + 'day-picker': generateDayPicker(year, day, yearToDays), + 'current-year': `${currentYear}`, + notes, + code: escapeHtml(code), + }); + const dst = `build/${year}/${day}`; + fs.mkdirSync(dst, { recursive: true }); + fs.writeFileSync(path.join(dst, 'index.html'), filledHtml); + fs.copyFileSync(illustration, path.join(dst, 'illustration.jpeg')); + for(let file of media) { + fs.copyFileSync(file, path.join(dst, path.basename(file))); + } +} + diff --git a/docs/elf.jpeg b/docs/elf.jpeg new file mode 100644 index 000000000..d61c3abb0 Binary files /dev/null and b/docs/elf.jpeg differ diff --git a/docs/package-lock.json b/docs/package-lock.json new file mode 100644 index 000000000..a398ad371 --- /dev/null +++ b/docs/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "docs", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "docs", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "marked": "^15.0.3" + } + }, + "node_modules/marked": { + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/marked/-/marked-15.0.3.tgz", + "integrity": "sha512-Ai0cepvl2NHnTcO9jYDtcOEtVBNVYR31XnEA3BndO7f5As1wzpcOceSUM8FDkNLJNIODcLpDTWay/qQhqbuMvg==", + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + } + } +} diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 000000000..d90559306 --- /dev/null +++ b/docs/package.json @@ -0,0 +1,14 @@ +{ + "name": "docs", + "version": "1.0.0", + "main": "build.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "marked": "^15.0.3" + } +} diff --git a/docs/redirect_template.html b/docs/redirect_template.html new file mode 100644 index 000000000..cc99add5e --- /dev/null +++ b/docs/redirect_template.html @@ -0,0 +1,10 @@ + + + diff --git a/docs/static/404.html b/docs/static/404.html new file mode 100644 index 000000000..9c931b102 --- /dev/null +++ b/docs/static/404.html @@ -0,0 +1,2 @@ + + diff --git a/docs/static/CNAME b/docs/static/CNAME new file mode 100644 index 000000000..dfac70bb5 --- /dev/null +++ b/docs/static/CNAME @@ -0,0 +1 @@ +aoc.csokavar.hu \ No newline at end of file diff --git a/docs/static/android-chrome-192x192.png b/docs/static/android-chrome-192x192.png new file mode 100644 index 000000000..00444eee3 Binary files /dev/null and b/docs/static/android-chrome-192x192.png differ diff --git a/docs/static/android-chrome-512x512.png b/docs/static/android-chrome-512x512.png new file mode 100644 index 000000000..ac878c39a Binary files /dev/null and b/docs/static/android-chrome-512x512.png differ diff --git a/docs/static/apple-touch-icon.png b/docs/static/apple-touch-icon.png new file mode 100644 index 000000000..bf6729c6a Binary files /dev/null and b/docs/static/apple-touch-icon.png differ diff --git a/docs/static/browserconfig.xml b/docs/static/browserconfig.xml new file mode 100644 index 000000000..b3930d0f0 --- /dev/null +++ b/docs/static/browserconfig.xml @@ -0,0 +1,9 @@ + + + + + + #da532c + + + diff --git a/docs/static/favicon-16x16.png b/docs/static/favicon-16x16.png new file mode 100644 index 000000000..ca6fbddd6 Binary files /dev/null and b/docs/static/favicon-16x16.png differ diff --git a/docs/static/favicon-32x32.png b/docs/static/favicon-32x32.png new file mode 100644 index 000000000..d4fac82eb Binary files /dev/null and b/docs/static/favicon-32x32.png differ diff --git a/docs/static/favicon.ico b/docs/static/favicon.ico new file mode 100644 index 000000000..70d3d947b Binary files /dev/null and b/docs/static/favicon.ico differ diff --git a/docs/static/mstile-150x150.png b/docs/static/mstile-150x150.png new file mode 100644 index 000000000..f1d02c0d4 Binary files /dev/null and b/docs/static/mstile-150x150.png differ diff --git a/docs/static/safari-pinned-tab.svg b/docs/static/safari-pinned-tab.svg new file mode 100644 index 000000000..46cebff23 --- /dev/null +++ b/docs/static/safari-pinned-tab.svg @@ -0,0 +1,110 @@ + + + + +Created by potrace 1.14, written by Peter Selinger 2001-2017 + + + + + + + + + + diff --git a/docs/static/site.webmanifest b/docs/static/site.webmanifest new file mode 100644 index 000000000..b20abb7cb --- /dev/null +++ b/docs/static/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "", + "short_name": "", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/docs/template.html b/docs/template.html new file mode 100644 index 000000000..a512a3981 --- /dev/null +++ b/docs/template.html @@ -0,0 +1,314 @@ + + + + + + + + + + + + + + + + + + Advent of Code {{problem-id}} '{{problem-name}}'' in C# by encse + + + + + + + + + + + + + + +
+
{{year-picker}}
+
{{day-picker}}
+
+
+
+
+ +
+ +
+

Advent of Code

+

{{problem-id}}

+

{{problem-name}}

+

in C#

+

+

by encse

+
+ +
+ +
+
{{notes}}
+
{{code}}
+

Please ☆ my repo if you like it!

+
+ +
+
+ © {{current-year}} + Advent of Code is a registered trademark in the US + Images provided by Bing image creator +
+ + + + + + + + \ No newline at end of file