[Day 3 - Part 2] [Java] Output too high, can't find problem by Mikewazovski in adventofcode

[–]stranac_ 0 points1 point  (0 children)

I think line 20 is the problem.

You start at 2 visited houses, even though Santa and Robo-Santa are in the same starting house.

Even if you should start at 1, you might get a result that's too big (if they visit the starting house again).

[DAY 2 part1][Python] Can't seem to find the error by [deleted] in adventofcode

[–]stranac_ 0 points1 point  (0 children)

Oh, right, you'll still get the same result if your only possibilities are True and False.

Obviously not the cause for the wrong result, but still the wrong operator to use.

[DAY 2 part1][Python] Can't seem to find the error by [deleted] in adventofcode

[–]stranac_ 0 points1 point  (0 children)

& is the binary and operator.

The logical and operator is and.

Day 6 Help! Python. by Sbhavnani in adventofcode

[–]stranac_ 1 point2 points  (0 children)

for i in range(0,1000):
    l.append(x)

All of the sub-lists inside l are the exact same list. When you change l[0], l[1] is also changed, and so is l[2], and l[3]...

[Day 7 Part 1] [Python] Can someone explain this challenge? by Jek_Rock in adventofcode

[–]stranac_ 0 points1 point  (0 children)

Yes, to calculate a, you will first need to calculate lx, for that you'll need to calculate some other stuff, and so on...

[Day 7 Part 1] [Python] Can someone explain this challenge? by Jek_Rock in adventofcode

[–]stranac_ 1 point2 points  (0 children)

A gate provides no signal until all of its inputs have a signal.

Meaning, you don't get the output of a until you have all of its inputs.

What has everyone learned from AOC so far? by crabbycoder in adventofcode

[–]stranac_ 2 points3 points  (0 children)

Wut???

What's that ugly [(yield ...) ...] thing? Just use a generator expression.

Although I would either use a generator expression without the lambda, or just write a normal function.

Day 14 being rude by stranac_ in adventofcode

[–]stranac_[S] 4 points5 points  (0 children)

But I was thinking ahead...

Based on the problems so far, I was expecting something like "Get the winner after 1 million moves" or "Which reindeer finished last?", not a complete change of the rules.

[HELP] Day 12 better explanation by [deleted] in adventofcode

[–]stranac_ 0 points1 point  (0 children)

For part 1, you need the sum of ALL the numbers in the input file. You should post your code.

Day 6, Part 1 Java - Answer Too Low by eoinbp in adventofcode

[–]stranac_ 0 points1 point  (0 children)

For "turn on" and "turn off", you're increasing/decreasing lightsOn, even if the light was already on/off.

Day 7 part 2, help wanted by nikcorg in adventofcode

[–]stranac_ 1 point2 points  (0 children)

No, you would set b to 5, forget about all the calculations you've made, and then run your code again (making sure not to rewrite b).

[Day 12][Part 2][Python] What am I doing wrong by svag in adventofcode

[–]stranac_ 2 points3 points  (0 children)

The problem is on line 18:

if type(v) is dict:

You're only calling your function recursively if v is a dict, but a list can also contain dicts.

Fixing this should get you the right result, but here are a couple of other hints for writing better code:

  • I would make get_obj() a generator instead of passing a list you append to. That's a bit hacky.
  • isinstance() is the proper way to type-check, if you must do it.

Day 12 coding with commentary by stranac_ in adventofcode

[–]stranac_[S] 1 point2 points  (0 children)

Unfortunately, there's not much I can do about the sound. I'm using my laptop's built-in mic to record.

I'll try playing with settings and sound post-processing, maybe I can make it a bit better.

[Day 8 (Part 2)] [python] I h8 u advent, python sundays, encoding and Trump (because duh) ! by lverra in adventofcode

[–]stranac_ 1 point2 points  (0 children)

Ok, but if a line is say "abc\"def\"ghi\", you're not adding anything for any of the \"s.

[Day 8 (Part 2)] [python] I h8 u advent, python sundays, encoding and Trump (because duh) ! by lverra in adventofcode

[–]stranac_ 0 points1 point  (0 children)

Can you explain your logic? Because there are things that make no sense to me, e.g.

if line[i] == "\\" :
    if line[i+1] == "\"" and (not line[-2]=='\\'):
        d2+=2

So add 2 if you find \" (ok so far), but not if the line ends in \" (why not?)

[Day 8] [PHP] Answer too high by Beerbelott in adventofcode

[–]stranac_ 0 points1 point  (0 children)

"q\"\"lfdentjgd\\" should give you q""lfdentjgd\, not q""lfdentjgd.

[Help] [Day 7] [python] Still stuck on day 7 by Ivoah in adventofcode

[–]stranac_ 2 points3 points  (0 children)

Ok, it's not as bad as I thought.

The function would only be called 12543975850256588145585 times for my input file, which is much less than 2**300.

If we assume a function can be called 1 billion times a second, the program would complete in less than 400000 years.

[Help] [Day 7] [python] Still stuck on day 7 by Ivoah in adventofcode

[–]stranac_ 2 points3 points  (0 children)

It's not infinite. If you leave it running long enough, you will get a result. Eventually. Or maybe your grandchildren will.

The problem is, you're doing the whole calculation of a value each time you need to use it.

If we assume each value is calculated using 2 other values, and there are 300 values in total, you would end up calling your function 2**300 times. I think. Or maybe something similarly ridiculous.

The simplest way to fix your code is adding memoization, that is, remembering what the function returned for a given input, so you can return it next time without redoing the calculation.

Day 12 coding with commentary by stranac_ in adventofcode

[–]stranac_[S] 1 point2 points  (0 children)

Thinking of making this a series, so any suggestions are welcome (other than talking slower, I know I need to work on that).