advent-of-code | Advent of Code | Learning library
kandi X-RAY | advent-of-code Summary
kandi X-RAY | advent-of-code Summary
Advent of Code 2019 and 2020 in Panda.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of advent-of-code
advent-of-code Key Features
advent-of-code Examples and Code Snippets
Community Discussions
Trending Discussions on advent-of-code
QUESTION
I'm trying to get use a BTreeMap (or HashMap) from within a struct but I can't because it keeps complaining an ownership problem.
cannot move out of
self.vertices
which is behind a shared reference move occurs becauseself.vertices
has typestd::collections::BTreeMap>
, which does not implement theCopy
trait help: consider borrowing here:&self.vertices
rustc(E0507) digraph.rs(13, 17): move occurs becauseself.vertices
has typestd::collections::BTreeMap>
, which does not implement theCopy
I'm totally confused at this stage.
...ANSWER
Answered 2020-Dec-05 at 22:56The problem seems to be that you're trying to mutate something that you have not marked as mutable. The add_edge
method clearly has to mutate the struct but you have an &self
receiver instead of an &mut self
. Upon making that change the code compiles:
QUESTION
I'm trying to solve the whole Advent of Code series in Haskell.
I'm encountering a memory issue while solving the 2015/06 exercise where there is a bunch of instructions to turn on, off and toggle lights on a grid. The goal is to count the number of lit lights at the end.
Given instructions are parsed and stored in a Instruction
type, this is the type definition:
ANSWER
Answered 2019-Jun-08 at 16:38I would strongly suggest not using a typeclass. Typeclasses are supposed to have laws, and they should be "rare", in the sense that each type has only a few valid implementations. I would suggest taking initialState
and toggle
as arguments, but even that is overkill, because the given instructions simply do not make sense with any type that isn't Bool
. Just operate on a Matrix Bool
directly and you can cut out a good chunk of the code you've written. However, I won't change anything for my answer.
In any case, I think the issue may be laziness. 1000 * 1000 = 1000000, so each Matrix
will be several megabytes in size. On a 64-bit machine, a pointer is 8 bytes, so each Matrix is at least 8 MB, plus a few more for the data behind it. You are mconcat
ing 300 of them (that's what I get from the site) together, but, because you are doing it lazily, all 300 matrices are resident simultaneously, so it's at least 2.4 GB, just for the structures themselves. The cost of filling each of those 300 million pointers with thunks also makes itself known—a thunk is at least one pointer (8 bytes, pointing to code in static memory, making another 2.4 GB), plus its payload, which, here, means more pointers, each one bestowing your computer with another 2.4 GB of memory pressure. I suggest deepseq
:
QUESTION
Problem Description: I am trying to do the task mentioned here - https://codereview.stackexchange.com/questions/182483/advent-of-code-2017-day-1-sum-of-digits-matching-the-next-digit-circular-list
But in Windows Power Shell using simple loop logic (as I am new to Power Shell)
The task requires to review a sequence of digits and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list. For example:
1122 produces a sum of 3 (1 + 2) because the first digit 1 matches the second digit and the third digit 2 matches the fourth digit; 1111 produces 4 because each digit (all 1) matches the next; 1234 produces 0 because no digit matches the next; 91212129 produces 9 because the only digit that matches the next one is the last digit, 9
I have coded this:
...ANSWER
Answered 2018-May-17 at 19:22The var $i iterates through the Length,
Edit streamlined version thank to a hint from BenH
QUESTION
I'm learning Haskell and I'm using Advent of Code 2015 to practice. I tried to solve Day06 with a bitlist rather than a list of coordinates and status, but it does not compute the right value and I can't understand if there's a fault in the logic or in the implementation.
Here's the code:
...ANSWER
Answered 2018-Feb-01 at 14:05Make sure that you don't use
Int
due to overflow. UseInteger
instead, which can grow arbitrarily large.As I understand it, the problem asks you to turn on/turn off a rectangular area between opposite corners (a,b), (A,B). I think you interpret the two tuples as rectangle [a..b]x[A..B] but it should be [a..A]x[b..B] (assuming a<=A, b<=B)
QUESTION
I've started leaning Haskell not long ago by solving this year's Advent of Code tasks.
While solving Part 2 of Day 17 I've ran into a nasty memory leak (space leak) -- I think.
(Here's the full README including Part 2, one can only access it after solving Part 1.)
My solution works and it runs fine, but only with a dirty little hack, which forces Haskell to evaluate an intermediate computation every now and then.
I'm using traceShow
to print the intermediate state to the console after every 5000 iterations (please see here the actual code). This way the program finishes in a reasonable time and doesn't use too much memory.
The problem: if I remove this (not printing the intermediate state at all, only the last state) the program eats up all available memory. :(
I've started out with using iterate
and then I've read that using that can cause stuff like what I'm noticing. I've replaced it. Nothing. Tried different folds (foldl
, foldl'
, etc.). Nothing. I'm not sure at this point what can cause this although my guess is that at some point there's some not so evident lazy evaluation going on.
My question: how can I avoid this? What causes this in my case?
Thank you for your time and insight. Oh, and I'm pretty sure that there are shorter, sweeter solutions to this problem, but currently I'm only interested in what causes the memory leak in my case.
TestingI've isolated the part of the code where I notice this error.
...ANSWER
Answered 2017-Dec-30 at 14:59The following works:
QUESTION
New to Perl6, trying to figure out what I'm doing wrong here. The problem is a simple checksum that takes the difference of the max and min values for each row in the csv
The max and min values it returns are completely wrong. For the first row in the csv, it returns the max as 71, and the min as 104, which is incorrect.
Here's the link to the repo for reference, and the link to the corresponding problem.
...ANSWER
Answered 2017-Dec-05 at 04:26I assume your input contains numbers, but since CSV is a text format, the input is being read in as strings. min
and max
are operating based on string sorting, so max("4", "10")
is 4
but max("04", "10")
is 10
. To solve this, you can either cast each element to Numeric
(int, floating point, etc.) before you get the min/max:
QUESTION
When working on an AoC puzzle, I found I wanted to subtract lists (preserving ordering):
...ANSWER
Answered 2017-Jan-06 at 22:00- Removing an item from a list of length N is O(N) if the list is unordered, because you have to find it.
- Removing k items from a list of length N, therefore, is O(kN) if we focus on "reasonable" cases where k << N.
So I don't see how you could get it down to O(N).
A concise way to write this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install advent-of-code
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page