this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

part 1

+159 -10
+37
2023/day05/deno.lock
··· 1 + { 2 + "version": "3", 3 + "remote": { 4 + "https://deno.land/std@0.208.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", 5 + "https://deno.land/std@0.208.0/assert/_diff.ts": "58e1461cc61d8eb1eacbf2a010932bf6a05b79344b02ca38095f9b805795dc48", 6 + "https://deno.land/std@0.208.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", 7 + "https://deno.land/std@0.208.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", 8 + "https://deno.land/std@0.208.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", 9 + "https://deno.land/std@0.208.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", 10 + "https://deno.land/std@0.208.0/assert/assert_equals.ts": "d8ec8a22447fbaf2fc9d7c3ed2e66790fdb74beae3e482855d75782218d68227", 11 + "https://deno.land/std@0.208.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", 12 + "https://deno.land/std@0.208.0/assert/assert_false.ts": "0ccbcaae910f52c857192ff16ea08bda40fdc79de80846c206bfc061e8c851c6", 13 + "https://deno.land/std@0.208.0/assert/assert_greater.ts": "ae2158a2d19313bf675bf7251d31c6dc52973edb12ac64ac8fc7064152af3e63", 14 + "https://deno.land/std@0.208.0/assert/assert_greater_or_equal.ts": "1439da5ebbe20855446cac50097ac78b9742abe8e9a43e7de1ce1426d556e89c", 15 + "https://deno.land/std@0.208.0/assert/assert_instance_of.ts": "3aedb3d8186e120812d2b3a5dea66a6e42bf8c57a8bd927645770bd21eea554c", 16 + "https://deno.land/std@0.208.0/assert/assert_is_error.ts": "c21113094a51a296ffaf036767d616a78a2ae5f9f7bbd464cd0197476498b94b", 17 + "https://deno.land/std@0.208.0/assert/assert_less.ts": "aec695db57db42ec3e2b62e97e1e93db0063f5a6ec133326cc290ff4b71b47e4", 18 + "https://deno.land/std@0.208.0/assert/assert_less_or_equal.ts": "5fa8b6a3ffa20fd0a05032fe7257bf985d207b85685fdbcd23651b70f928c848", 19 + "https://deno.land/std@0.208.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", 20 + "https://deno.land/std@0.208.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", 21 + "https://deno.land/std@0.208.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", 22 + "https://deno.land/std@0.208.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", 23 + "https://deno.land/std@0.208.0/assert/assert_not_strict_equals.ts": "4cdef83df17488df555c8aac1f7f5ec2b84ad161b6d0645ccdbcc17654e80c99", 24 + "https://deno.land/std@0.208.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", 25 + "https://deno.land/std@0.208.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", 26 + "https://deno.land/std@0.208.0/assert/assert_strict_equals.ts": "b1f538a7ea5f8348aeca261d4f9ca603127c665e0f2bbfeb91fa272787c87265", 27 + "https://deno.land/std@0.208.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", 28 + "https://deno.land/std@0.208.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", 29 + "https://deno.land/std@0.208.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", 30 + "https://deno.land/std@0.208.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", 31 + "https://deno.land/std@0.208.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", 32 + "https://deno.land/std@0.208.0/assert/mod.ts": "37c49a26aae2b254bbe25723434dc28cd7532e444cf0b481a97c045d110ec085", 33 + "https://deno.land/std@0.208.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", 34 + "https://deno.land/std@0.208.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", 35 + "https://deno.land/std@0.208.0/fmt/colors.ts": "34b3f77432925eb72cf0bfb351616949746768620b8e5ead66da532f93d10ba2" 36 + } 37 + }
+57 -2
2023/day05/part1.ts
··· 1 + import { assert } from "https://deno.land/std@0.208.0/assert/mod.ts"; 2 + 1 3 if (import.meta.main) { 2 4 const input = ( 3 5 await Deno.readFile("input").then((bytes) => ··· 7 9 console.log(answer(input)); 8 10 } 9 11 12 + type Range = { 13 + fromStart: number; 14 + toStart: number; 15 + range: number; 16 + }; 17 + 18 + type MapRanges = { 19 + from: string; 20 + to: string; 21 + ranges: Range[]; 22 + }; 23 + 10 24 export function answer(input: string): number { 11 - console.log(input); 12 - return 42; 25 + const [seedLine, _, ...mapLines] = input.split("\n"); 26 + const seeds = seedLine 27 + .replace("seeds: ", "") 28 + .split(" ") 29 + .map((x) => parseInt(x)); 30 + 31 + const mapRanges: MapRanges[] = mapLines 32 + .join("\n") 33 + .split("\n\n") 34 + .map((mapLine) => { 35 + const [fromToLine, ...rangeLines] = mapLine.split("\n"); 36 + const [_, from, to] = fromToLine.match(/([a-z]+)-to-([a-z]+) map/)!; 37 + const ranges = rangeLines.map((rangeLine) => { 38 + const [toStart, fromStart, range] = rangeLine 39 + .split(" ") 40 + .map((n) => parseInt(n)); 41 + return { fromStart, toStart, range }; 42 + }); 43 + 44 + return { from, to, ranges }; 45 + }); 46 + 47 + // start at `from: seed` to `to: location` 48 + const locationNumbers = seeds.map((s) => getLocationNumber(s, mapRanges)); 49 + 50 + return Math.min(...locationNumbers); 51 + } 52 + 53 + function getLocationNumber(seed: number, mapRanges: MapRanges[]): number { 54 + let current = "seed"; 55 + let currentNum = seed; 56 + while (current !== "location") { 57 + const mapRange = mapRanges.find(({ from }) => from === current); 58 + assert(mapRange, `mapRange not found for: ${current}`); 59 + 60 + const range = mapRange.ranges.find( 61 + (r) => currentNum >= r.fromStart && currentNum <= r.fromStart + r.range, 62 + ); 63 + if (range) currentNum = currentNum + (range.toStart - range.fromStart); 64 + 65 + current = mapRange.to; 66 + } 67 + return currentNum; 13 68 }
+25 -2
2023/day05/puzzle.md
··· 109 109 110 110 *What is the lowest location number that corresponds to any of the initial seed numbers?* 111 111 112 - To begin, [get your puzzle input](5/input). 112 + Your puzzle answer was `322500873`. 113 + 114 + The first half of this puzzle is complete! It provides one gold star: \* 115 + 116 + \--- Part Two --- 117 + ---------- 118 + 119 + Everyone will starve if you only plant such a small number of seeds. Re-reading the almanac, it looks like the `seeds:` line actually describes *ranges of seed numbers*. 120 + 121 + The values on the initial `seeds:` line come in pairs. Within each pair, the first value is the *start* of the range and the second value is the *length* of the range. So, in the first line of the example above: 122 + 123 + ``` 124 + seeds: 79 14 55 13 125 + ``` 126 + 127 + This line describes two ranges of seed numbers to be planted in the garden. The first range starts with seed number `79` and contains `14` values: `79`, `80`, ..., `91`, `92`. The second range starts with seed number `55` and contains `13` values: `55`, `56`, ..., `66`, `67`. 128 + 129 + Now, rather than considering four seed numbers, you need to consider a total of *27* seed numbers. 130 + 131 + In the above example, the lowest location number can be obtained from seed number `82`, which corresponds to soil `84`, fertilizer `84`, water `84`, light `77`, temperature `45`, humidity `46`, and *location `46`*. So, the lowest location number is `*46*`. 132 + 133 + Consider all of the initial seed numbers listed in the ranges on the first line of the almanac. *What is the lowest location number that corresponds to any of the initial seed numbers?* 113 134 114 135 Answer: 115 136 116 - You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22If+You+Give+A+Seed+A+Fertilizer%22+%2D+Day+5+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F5&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle. 137 + Although it hasn't changed, you can still [get your puzzle input](5/input). 138 + 139 + You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22If+You+Give+A+Seed+A+Fertilizer%22+%2D+Day+5+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F5&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle.
+40 -6
2023/day05/test.ts
··· 3 3 import * as p2 from "./part2.ts"; 4 4 5 5 Deno.test("part1", () => { 6 - const examples = ["abc", "def"].join("\n"); 7 - assertEquals(p1.answer(examples), 42); 6 + const examples = [ 7 + "seeds: 79 14 55 13", 8 + "", 9 + "seed-to-soil map:", 10 + "50 98 2", 11 + "52 50 48", 12 + "", 13 + "soil-to-fertilizer map:", 14 + "0 15 37", 15 + "37 52 2", 16 + "39 0 15", 17 + "", 18 + "fertilizer-to-water map:", 19 + "49 53 8", 20 + "0 11 42", 21 + "42 0 7", 22 + "57 7 4", 23 + "", 24 + "water-to-light map:", 25 + "88 18 7", 26 + "18 25 70", 27 + "", 28 + "light-to-temperature map:", 29 + "45 77 23", 30 + "81 45 19", 31 + "68 64 13", 32 + "", 33 + "temperature-to-humidity map:", 34 + "0 69 1", 35 + "1 0 69", 36 + "", 37 + "humidity-to-location map:", 38 + "60 56 37", 39 + "56 93 4", 40 + ].join("\n"); 41 + assertEquals(p1.answer(examples), 35); 8 42 }); 9 43 10 - Deno.test("part2", () => { 11 - const examples = ["abc", "def"].join("\n"); 12 - assertEquals(p2.answer(examples), 42); 13 - }); 44 + // Deno.test("part2", () => { 45 + // const examples = ["abc", "def"].join("\n"); 46 + // assertEquals(p2.answer(examples), 42); 47 + // });