Previous thread adventofcode.com/ >Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme. You need to register with an account but you can appear as anonymous.
Private leaderboard join code (currently full):
368748-e33dcae3
People who are inactive for 5 days will be kicked, but other leaderboards can be made if desired.
Alternative leaderboard for those waiting for inactives to be kicked from the first:
>What do you want to use goto/label for? I use it everywhere in OCaml, and I often use it when I code in C. And please don't talk about continue/break, those two keywords are an abomination.
Ryan Martinez
won't let me post it in code tags here pastebin.com/JBreb9Np highlights number of stars
You shouldn't read such thing. You should go ahead and thunk about the problem.
Evan Cox
What do you mean, "real problems"?
Brayden Wright
87, one more. Oh yeah!!!!!!!!!!!!!
Since now, we only have jokes.
Camden Howard
Unlike C++, math is not a costless abstraction. Don't waste precious brain nodules trying to understand the problem from a higher perspective when it is perfectly soluble at the immediate level.
Jonathan Robinson
Oh, you're bragging.
Nathaniel Richardson
You don't know, who I am, what I did, and the kind of problems I solve at work.
Caleb Russell
i'm a brainlet that got filtered day 7p2. still here to root for our user. i want to ask him what resources helped him the most? and how do i begin to be as good as him.
Isaiah Torres
>i'm a brainlet that got filtered day 7p2. What blocked you. Do you need help?
Anthony Reed
If you refuse to water your brain seeds and put healthy animal poop on them they will not grow. For day 7 part 1 you just need to keep track of a few things. First populate a dict with every letter in the alphabet as keys, then read through the dependency data line by line. Each time you find a step that depends on another step, populate your dict so that all letters have their dependencies in their values. In your loop, you should start by populating a list of candidates for the next instruction step. Then simply check which instructions in that dict that have not been completed (track that however you want) And which are not already in the candidates list are added to the candidates list. Sort the candidates alphabetically so that the first element in the candidates list is the one that is completed this loop. You add it sequentially to the end of your final answer, but the important thing is that, since this dependency-less step is being completed, you need to remove any instance of it in your main dict's values for every key that depended on it. That way, when the loop starts again, it will populate some new candidates to the candidates list because their dependencies are all complete.
You almost certainly don't need all of this instruction and there are different methods, just pick and choose the parts you want.
Joshua Rivera
for 7p2 i felt like i had to manage a lot of spaghetti and the bugs probably somewhere among my spaghetti. i'm still gonna continue, i still also got messed up on part 2 from last night.
Isaiah Anderson
You shouldn't get so dramatic, user. People brag.
Dominic Ross
>for 7p2 i felt like i had to manage a lot of spaghetti It's not a big problem, so get rid of your old code and restart from scratch with a good alg in mind, could be a good start. Just code your alg until the end.
Josiah Hall
wikipedia pages on math and science are not written to be understood. The information is too dense and the writing is far to complicated. >a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. What the fuck does that even mean?
Here's my part1 solution in psudocode: >generate a dictionary (associative array) where the keys are the instructions and the values are their dependencies >>{ 'A': ['C'], 'B': ['A'], 'C': [ ], 'D': ['A'], 'E': ['B', 'D', 'F'], 'F': ['C'] } >find all the steps with no dependencies >put the list into alphabetical order >>the first step in that list is the next one you have to do >modify the dictionary so that the step you did is removed completely >>remove its key and remove it from any dependency array >restart the process with finding all the steps without dependencies
Asher Robinson
sorry senpai
Michael Jenkins
You don't a clever algorithm for topological sort. The input is small enough you can just brute force it. Basic idea is to loop through all the tasks A-Z, and for each one, if (1) it isn't done yet, and (2) all the tasks that have to happen before it (according to the input) are already done, then this is the task you're supposed to do in the current iteration. Do multiple iterations of this whole thing until all of the tasks are done.
For part 2 it's more complicated, but you can reuse the "find the task you're supposed to do next" part as a helper function.
Colton Russell
I'm a little bit drunk.
>What the fuck does that even mean? It's obvious, it means, that it's a morphism (fuck anglo-saxon and the stupid word homomorphism) from an ordered set to a totally ordered set. Something that preserve order.
Jace Evans
fuck it, im going to slap a GDPR complaint on this shit site. brainlet uprising!!
Aiden Jenkins
Finally got around to day 7, was not that bad aside from using the wrong variable name in part 2 (was too tired to notice). Tried today's with a recursive solution, it nearly but didn't work I think because variables were being clobbered. Going to use a stack for it when I do it. I'm about to pass out from tiredness so someone else will have to FUCKpost the second the puzzle unlocks instead of me. Best of luck for the anons who are awake on time.
Jackson Perez
I joined the leaderboard. And I'm reminded of what's there to dislike about the scoring. I don't have time for this until the European evening. At least I can display my 16 stars there.
David Carter
>First populate a dict with every letter in the alphabet as keys Even better, populate the dict with all of the letters found in the input.
Carson Young
>I'm a little bit drunk. Eh, don't worry about it. The post was substantive. I was being a jerk attacking your possible intent instead of discussing the content.
Connor Bailey
Careful with that, if you end up only populating the dict with keys that have dependencies as you would normally append, you'll end up missing your whole initial candidates list.
Isaac Lee
Fell for that one myself.
Ethan Bailey
you can reuse 90% of your code of task1 for task2 just a worker int[5] needed and a for loop
Hudson Bailey
That's why I said all the letters. As in parents and dependencies. That way you won't have extra keys and even if more keys than the A-Z are added, you will have them in your candidates list.
Evan Davis
1.3 with the big one. You have a big margin user.
Tyler Rodriguez
>you'll end up missing your whole initial candidates list Happened to me first but then I did and made sure I got all letters mentioned, not just the one with dependencies
Juan Walker
probably a common concept, but day7 made me realize that you can represent a sparse matrix with two hash tables. i feel like that's something that'll come in handy knowing.
Elijah Torres
day 2 ex 2 don't bully me for my slowness please, i'm learning perl6 with this for fun : - ) my @lines = "input".IO.lines>>.comb;
(@lines X @lines).hyper.map: -> @p { my @out = (); my @l1 = @p[0].cache; my @l2 = @p[1].cache; for ^@l1.elems { @out.push( @l1[$_] eq @l2[$_] ?? @l2[$_] !! "#" ); } if @out.Bag == 1 {say "found"; say [~] @out; exit} }
Juan Russell
When you often ask a question, a hash table can be very useful. In the case of a graph, what are the ancestors fo such node? What are the successor of such node? Try to spot such questions, and use a hash table when needed.
Daniel Ross
Eh, nvm. You can only need one hash table to represent a sparse matrix, of course. But you can use two to represent a sparse connection matrix.
My brainlet self is about to start trying question 7 again. I should be looking into priority queues, right?
Ian Bennett
Do you know how to schedule events?
Blake Harris
I use facebook, mostly.
John Butler
I don't know what to say.
At each steps, you have running tasks and a end time for those task. So the min of those end time is your next event, wheen you must update the state.
Josiah Martin
>I should be looking into priority queues, right? I pajeeted out of this by sorting my queue's entries after each iteration of the main loop
I used an adjacency list for the graph itself, and implemented it as a dict of letters to sets of other letters. Also, my worker elves were represented by tuples in a list, with each tuple containing the letter being worked on and the current progress.
based
Luis Johnson
Is it true that State is a useless abstraction unless you're using the lens library?
Gabriel Cooper
i really feel proud of myself for getting this far
Austin Evans
>Is it true that State is a useless abstraction No.
Tyler Baker
are you RSSG?
Jacob Morris
no, i'm one of the anonymous users
Mason Robinson
tried to make my rust solution a little more rusty.
use std::str::FromStr;
struct Node { metadata: Vec, children: Vec, }
impl Node { fn from_iter(iter: &mut Iterator) -> Option { let child_count = iter.next()?; let meta_count = iter.next()?;
let children = (0..child_count) .map(|_| Node::from_iter(iter)) .collect::()?;
let metadata: Vec = iter.take(meta_count).collect();
Runs in ~5 ms on my shitty laptop. At first I tried to implement FromIterator for Option, but that's not possible because of the orphan rule :(
Hunter Richardson
> The input is small enough you can just brute force it.
This is what makes these kind of lame sometimes. Some of these problems might actually require interesting algorithms with good enough inputs, but I'm not gonna waste time doing big brain coding when I can just do something easy
Jose Gray
That's why we have bigboy.
Carson Cooper
>can't even print text without resorting to macros
the absolute state of Rust
Luis Thomas
>And please don't talk about continue/break, those two keywords are an abomination. Oh I see, you're retarded.
Me too. It's probably mostly just the picture, but it feels like leaving somebody behind.
Ian Lewis
Only jumped on board today Bashed them all out over the course of a few hours, was a lotta fun What languages are people going for? Python seems like the obvious one cause you can just jump in and try things with no boilerplate needed but no doubt some of you enjoy making things as hard as possible for yourselves
Aaron Ramirez
time to catch a bit of sleep before the next puzzle hits at fucking 6AM
Anthony Lewis
>What languages are people going for? OCaml of course. That's what I used for prototyping. And when speed matters (ie. bigboys) C.
Samuel Cox
Using haskell which also requires basically no boilerplate
Haskell because I want to play around with it and because its abstractions are really well suited for algorithm puzzles. I'll switch to python or sepples if I can't get a Haskell solution to run within a minute.
Luis Russell
Out of interest, for day 5, the one with the polymers, how did you guys approach that? My implementation was slow as fuck, I basically had a method which removed the first pair of 'reactive units' and I would call it repeatedly until the method didn't change the input anymore. For part 2 I just looped over the letters, removed 'xX' from the input and then called part 1 It took like 5 mins to run :(
Samuel Martin
Runs original in ~7ms, small boy in ~3.5s, big boy in ~30s. Could be faster but it's good enough for aoc import Data.Tree import Data.Attoparsec.Text import qualified Data.Text.IO as T import System.Environment
main :: IO () main = do contents
John Williams
use a stack
Parker Morgan
Create a stack. Iterate through each character in the polymer string: if the current character and the character at the top of the stack form a "reactive pair", pop the stack; otherwise, push the current character to it.
Nolan Rivera
Learning Go. If you already know python then I think doing the whole thing in that would be a bit of a cop-out
Kayden Torres
>scan character >is it the anti of the stack top? >if yes, pop stack >if no, push to stack I implemented it with parsec so instead of a stack it's a recursive function, but recursion is a push/eval stack, so the idea is the same
Evan Morgan
That's fair enough, I want to focus on my approach to the problem rather than the actual language Need to improve my algorithms knowledge desu
Carson Ross
>can only figure out part 1 of each day looks like I'm not saving christmas
>but recursion is a push/eval stack I've never considered this, neat
Robert Reyes
This year has had a smoother difficulty curve than last, so it's been nice for learning a new language - one or two new features a day and I'm now pretty comfortable with it as the problems get tricky
Grayson Sanchez
>use a stack or the non-electron bloat way, 2 pointers into the string simulating a stack
Jason Phillips
you must be joking
most part 2s are easier than the distance puzzle
Hunter Gonzalez
>2468 people with 1 star on day 7 Really? Did you guys find part 2 to be that hard?