From 064504ab2b80d0f5658aa8bc4b50cfe3c2627d5e Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 1 Dec 2025 14:38:16 +0000 Subject: [PATCH] m --- 2015_day_2/README | 34 +--------------------------------- 2015_day_3/README.md | 34 +--------------------------------- 2015_day_4/README.md | 13 +------------ 3 files changed, 3 insertions(+), 78 deletions(-) diff --git a/2015_day_2/README b/2015_day_2/README index 2ef6b8e..01cadc6 100644 --- a/2015_day_2/README +++ b/2015_day_2/README @@ -1,35 +1,3 @@ +Calculating the amount of wrapping paper and ribbon needed to wrap all the presents Note: My goal here is to learn C better, not just complete the challenge, so in this case I'm learning structs a little better, and trying a 2d array. Completed 22/3/2024 - - -Prompt: ---- Day 2: I Was Told There Would Be No Math --- -The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length l, width w, and height h) of each present, and only want to order exactly as much as they need. - -Fortunately, every present is a box (a perfect right rectangular prism), which makes calculating the required wrapping paper for each gift a little easier: find the surface area of the box, which is 2*l*w + 2*w*h + 2*h*l. The elves also need a little extra paper for each present: the area of the smallest side. - -For example: - -A present with dimensions 2x3x4 requires 2*6 + 2*12 + 2*8 = 52 square feet of wrapping paper plus 6 square feet of slack, for a total of 58 square feet. -A present with dimensions 1x1x10 requires 2*1 + 2*10 + 2*10 = 42 square feet of wrapping paper plus 1 square foot of slack, for a total of 43 square feet. -All numbers in the elves' list are in feet. How many total square feet of wrapping paper should they order? - - - - -Your puzzle answer was 1588178. - -The first half of this puzzle is complete! It provides one gold star: * ---- Part Two --- - -The elves are also running low on ribbon. Ribbon is all the same width, so they only have to worry about the length they need to order, which they would again like to be exact. - -The ribbon required to wrap a present is the shortest distance around its sides, or the smallest perimeter of any one face. Each present also requires a bow made out of ribbon as well; the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of the present. Don't ask how they tie the bow, though; they'll never tell. - -For example: - - A present with dimensions 2x3x4 requires 2+2+3+3 = 10 feet of ribbon to wrap the present plus 2*3*4 = 24 feet of ribbon for the bow, for a total of 34 feet. - A present with dimensions 1x1x10 requires 1+1+1+1 = 4 feet of ribbon to wrap the present plus 1*1*10 = 10 feet of ribbon for the bow, for a total of 14 feet. - -How many total feet of ribbon should they order? - Total ribbon needed: 3783758 \ No newline at end of file diff --git a/2015_day_3/README.md b/2015_day_3/README.md index a540288..8e7d554 100644 --- a/2015_day_3/README.md +++ b/2015_day_3/README.md @@ -1,4 +1,4 @@ - +Part 1: Santa delivering over a grid of houses Use realloc/malloc? To me, this is kinda a memory management problem. Basically, we must create a 2D array of infinite size. Which we can't, as I don't have infinite memory (640K ought to be enough for anyone? Maybe I should see if I can compile this and run it on a virtual 8088). Fortunately, the file can be dealt with using fgetc, so I don't need to allocate that. So now I need to learn the allocation functions in C. @@ -26,38 +26,6 @@ So, it seems that really what I'll be doing is managing arrays of pointers for r I really like passing the pointer to the struct to the function in C, it makes things quite elegant (and easier for memory management!) as you're updating fields in a struct rather than creating a new copy each time. There's probably performance benefits, but this is so tiny that I'm unlikely to have to think about that. The new_grid pointers being inserted into the ->houses slot is handy. Did I say I really like only having one struct in play? https://adventofcode.com/2015/day/3 ---- Day 3: Perfectly Spherical Houses in a Vacuum --- - -Santa is delivering presents to an infinite two-dimensional grid of houses. - -He begins by delivering a present to the house at his starting location, and then an elf at the North Pole calls him via radio and tells him where to move next. Moves are always exactly one house to the north (^), south (v), east (>), or west (<). After each move, he delivers another present to the house at his new location. - -However, the elf back at the north pole has had a little too much eggnog, and so his directions are a little off, and Santa ends up visiting some houses more than once. How many houses receive at least one present? - -For example: - - > delivers presents to 2 houses: one at the starting location, and one to the east. - ^>v< delivers presents to 4 houses in a square, including twice to the house at his starting/ending location. - ^v^v^v^v^v delivers a bunch of presents to some very lucky children at only 2 houses. - - - -Your puzzle answer was 2565. - -The first half of this puzzle is complete! It provides one gold star: * ---- Part Two --- - -The next year, to speed up the process, Santa creates a robot version of himself, Robo-Santa, to deliver presents with him. - -Santa and Robo-Santa start at the same location (delivering two presents to the same starting house), then take turns moving based on instructions from the elf, who is eggnoggedly reading from the same script as the previous year. - -This year, how many houses receive at least one present? - -For example: - - ^v delivers presents to 3 houses, because Santa goes north, and then Robo-Santa goes south. - ^>v< now delivers presents to 3 houses, and Santa and Robo-Santa end up back where they started. - ^v^v^v^v^v now delivers presents to 11 houses, with Santa going one direction and Robo-Santa going the other. PART 2 COMMENTS diff --git a/2015_day_4/README.md b/2015_day_4/README.md index edd886e..57b46b6 100644 --- a/2015_day_4/README.md +++ b/2015_day_4/README.md @@ -1,17 +1,6 @@ ---- Day 4: The Ideal Stocking Stuffer --- - -Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the economically forward-thinking little girls and boys. - -To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least five zeroes. The input to the MD5 hash is some secret key (your puzzle input, given below) followed by a number in decimal. To mine AdventCoins, you must find Santa the lowest positive number (no leading zeroes: 1, 2, 3, ...) that produces such a hash. - -For example: - - If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043 starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so. - If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like 000006136ef.... - Your puzzle input is yzbqklnj. - +The puzzle is to find MD5 hashes where the output has 5 leading zeroes by appending an integer to an input string I'm going to use the RFC 1321 library here, as designing an md5 implementation is a bit too much for right now