r/adventofcode • • Dec 06 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 6 Solutions -❄️-

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's theme ingredient is… *whips off cloth covering and gestures grandly*

Obsolete Technology

Sometimes a chef must return to their culinary roots in order to appreciate how far they have come!

  • Solve today's puzzles using an abacus, paper + pen, or other such non-digital methods and show us a picture or video of the results
  • Use the oldest computer/electronic device you have in the house to solve the puzzle
  • Use an OG programming language such as FORTRAN, COBOL, APL, or even punchcards

    • We recommend only the oldest vintages of codebases such as those developed before 1970
  • Use a very old version of your programming language/standard library/etc.

    • Upping the Ante challenge: use deprecated features whenever possible

Endeavor to wow us with a blast from the past!

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 6: Wait For It ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:05:02, megathread unlocked!

46 Upvotes

1.2k comments sorted by

View all comments

2

u/dhruvasagar Dec 06 '23 edited Dec 07 '23

2

u/reddit_Twit Dec 06 '23

Just advice, it's unnecessary to use any allocations for AoC 2023 at this moment, if you need dynamic array you can use std.BoundedArray, it holds comptime known maximum capacity and current length.

basic usage

// type, 1000 is capacity, so this is array with sizeof(u64) * 1000

const NumsArray = std.BoundedArray(u64, 1000);

//Array with initial length 0

var arr = NumsArray.init(0) catch unreachable;

// some pushes

arr.append(1) catch unrechable;

arr.append(2) catch unrechable;

arr.append(3) catch unrechable;

// iteration example

while (arr.popOrNull()) |value|{

// value is 1 2 3

...

}

1

u/dhruvasagar Dec 06 '23

Thanks! I am new to zig, just started exploring a week back. Will use this going forward!

Do you have any suggestions for strings / parsing ? I often struggle with those too, but I suppose, I could use BoundedArray for them too ?

1

u/reddit_Twit Dec 06 '23

At first this article is useful. You use right way for parsing data using std.mem.* functions and std.fmt.parseInt, zig have not any like regular expressions(ofc. there are external libraries and included in libc, but imo it not necessary).

I've posted day5 solution, there are comptime parsing input data, but it may be hard to understand, and working with BoundedArray for part2 ranges solution.

1

u/dhruvasagar Dec 06 '23

Thanks a lot! Lot of nice stuff in the article. I tried to find a way to do var buf: [1000]u8 = .{} but nothing worked, it's great to know this trick! I've been just learning more by reading the std lib code. Really impressed by the performance of most solutions. So far every day solutions have been significantly faster with zig compared to go, rust, haskell, etc.

2

u/daggerdragon Dec 06 '23

Your code block is too long for the megathreads. Please edit your post to replace your oversized code with an external link to your code.