We're now 40% of the way done. Almost halfway! You can make it! You can do it! I believe in you! Even if you fell off the sleigh, as they say, you can still get back in and go back for the ones you missed later. You got this!
The Puzzle
In today’s puzzle, the device that we so cleverly hooked into yesterday has run out of battery. We want to plug it in, but, because we're on vacation and we want to spice things up a bit, we want to use every single one of the adapters in our bag to get there. Complicated prompt, but sounds like a fun challenge!
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 03:09PM 12/12/2020 PST.
| Language | Count |
|---|---|
| JavaScript | 4 |
| Rust | 3 |
| C# | 1 |
| Ruby | 1 |
| Haskell | 1 |
| C | 1 |
Merry Coding!
Latest comments (22)
Too late but for the sake of explanation: the DFS algorithms and the Dynamic Programming tehcniques are useful to know but the problem of counting (not enumerating) different paths in an oriented graph can be simply solved in O(n^3) time by these cycles:
for(i = 0 to N)
for(j =0 to N)
for(k = 0 to N)
path[i][j] += path[i][k] * path [k][j]
where path[][] is the matrix mapping any vertex to each other setting "0" if there is no edge between them and "1" if they are connected. The result will come in few seconds. Thanks to this post:
stackoverflow.com/questions/164213...
heres the solution in python for both part1 and 2 :
Sorry it's so late, but I'm pretty proud of figuring this out :D Obviously I'm continuing my javascript odyssey. It's pretty long, so I'll just link to the gist.
My Elixir solution:
C# solution part 1.
Execution time: 0ms, 235 ticks, the quickest so far :)
`
Another day where I solved Part1 and had to go back to rewrite it when Part2 came around!
My insight was that you could count the length of the sequences of 1 joltage deltas, and use that to derive the number of possible combinations. Unfortunately, I wasn't able to figure out the general formula for sequenceLength->permutations, and had to hardcode the table 😣
Part 1
Part 2
Did a bit of tricky business after looking over the test cases and my input. Linear time with no recursion.
Because the numbers in my input were either 3 or 1 apart, never 2, and there were never more than 4 1's in a row before a 3, I pre-calculated the # of possibilities each of the possible patterns generated and then multiplied together to find all possible combinations.
Then I rolled through the list producting up all the values for each "cell" of ones. The only thing I had an issue with is that I didn't think about the fact that the result was going to be a
long long int, so I chased my tail printing out regular ints for a while even though my algorithm was right.Also, TIL that C has a build-in sorting function called
qsort!COBOL, only part 1 again, gotta catch up during the week-end.
Part 2 javscript solution 🎨:
Took me a while to figure out. I was initially going down some path finding algorithm. But after looking at it a while It started to look like some dynamic programming/combinatorics.
Took me a while to get the actual equation down but finally did it.
inputis with0andmax + 3already added.