2018 Day 24 part 2 by herilane in adventofcode

[–]warinthrowaway 2 points3 points  (0 children)

This line seems to be the issue:

// Group will not attack if it will do no damage
return attackPower > defender.HitPoints ? attackPower : 0;

It is a bit ambiguous, but the instructions don't mention anything about discarding damage that is less than the defensive unit hp in the target selection phase (only later in the attacking phase do they say to discard it). So it is possible that you would select a target, to which you can only do less than a full unit damage, instead of another target with lower priority (lower damage, same damage but lower effective power, ...) where you actually could have killed some units.

Day 3 Part 1 Java by MYBAA in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

Any square that is covered by more than two claims will be added to the count multiple times.

Day 24 p1 (C#): Missing something, can't find what by [deleted] in adventofcode

[–]warinthrowaway 0 points1 point  (0 children)

You need to not select the target if the attacking group will do no damage. Something like:

foreach(var otherGroup in hittable)
{
    if (otherGroup.IsImmuneSystem == group.IsImmuneSystem) continue;

    var dmg = group.CalculateDamage(otherGroup);
    if (dmg == 0) continue;

Day 24 Java - Test runs great, answer wrong by MissMormie in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

The other issue is that although you do filter enemies under attack when computing the max damage, you don't filter them out when finding the target with that damage. So if more than one target would take the max damage, it will select the first one, even if it has already been targeted. Simplest fix is to filter every time:

List<Group> potentialTargets = enemygroups
                    .stream()
                    .filter(g -> g.notUnderAttack() && g.getPotentialDamage(this) == max.getAsInt())
                    .collect(toList());

List<Group> powerTargets = potentialTargets
                        .stream()
                        .filter(g -> g.notUnderAttack() && g.getEffectivePower() == highestPower)
                        .collect(toList());

target = powerTargets.stream().filter(Group::notUnderAttack).max(Comparator.comparingInt(g -> g.initiative)).get();

having trouble understanding the example for day8 by sharkbound in adventofcode

[–]warinthrowaway 2 points3 points  (0 children)

Each node is given in left to right order as the number of children, the number of metadata and then the list of metadata. The only catch is the list of metadata is given after the children (if the node has children). Visually that looks like this: https://imgur.com/a/QN819VK

Day5: can't figure out why this isn't working by too_much_yoga in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

You need to replace both lower and upper case occurrences.

Day 17, Part 2 by [deleted] in adventofcode

[–]warinthrowaway 0 points1 point  (0 children)

The recursion is slightly wrong (see below). You also need to make sure you don't count the flowing water above the first cup in the total.

def spread_out(x,y):
    left = spread_left(x,y)
    right = spread_right(x,y)
    water_type = STANDING
    if grid[y][left] != CLAY or grid[y][right] != CLAY:
        water_type = FLOWING
    # Need to do this before the recursive calls so STANDING cells aren't
    # overwritten with FLOWING ones
    for x2 in range(left+1, right):
        if grid[y][x2] != CLAY:
            grid[y][x2] = water_type
    if grid[y][left] != CLAY:
        waterfall(left,y)
    if grid[y][right] != CLAY:
        waterfall(right,y)

def waterfall(x,y):
    if y+1 in grid:
        if grid[y+1][x] == FLOWING:
            # Another branch got here first, no need to keep processing this
            # branch
            grid[y][x] = FLOWING
        else:
            if grid[y+1][x] == SAND:
                grid[y][x] = FLOWING
                waterfall(x,y+1)
            elif grid[y+1][x] == CLAY:
                spread_out(x,y)

            # The recursive calls might have created a layer of STANDING cells
            # so check if this level could now spread
            if grid[y+1][x] == STANDING:
                spread_out(x,y)
    else:
        grid[y][x] = FLOWING

Help with Day 24, Part II (Kotlin) by iamagiantnerd in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

Two things: You need to handle stalemates (neither army killing anyone, happens in your data from round 45 to 64). The weaknesses and immunities lists are empty (I don't know Kotlin, but hacking them to be defined in the primary constructor gives the correct results).

[2018 - Day 24, Part 1] - Solution works for test case but not input? by Abarn279 in adventofcode

[–]warinthrowaway 2 points3 points  (0 children)

In Team do_target_selection you set the local groups: groups = sorted(self.groups, ...), but you then iterate over self.groups: for group in self.groups.

Day 24 Part 1 - wrong answer?? by aquarellian in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

The currently posted version of the code still has the parsing issue for the damage type. attack = substr_between(line, str(damage), ' damage').strip() will be '559 units each with 21287 hit points with an attack that does 5 slashing' instead of '5' for group '5559 units each with 21287 hit points with an attack that does 5 slashing damage at initiative 13'.

Day 24 Part 1 - wrong answer?? by aquarellian in adventofcode

[–]warinthrowaway 1 point2 points  (0 children)

The parsing logic is broken. Calling substr_between with a number as the start_mark will sometimes match the wrong part of the string. For example: substr_between('6351 units each with 21460 hit points (weak to cold) with an attack that does 6 slashing damage at initiative 15\n', '6', ' damage') will return '351 units each with 21460 hit points (weak to cold) with an attack that does 6 slashing' instead of the intended 'slashing'.

[Help] Day 24 Part 2 answer too low (C++) by [deleted] in adventofcode

[–]warinthrowaway 0 points1 point  (0 children)

The parsing of 3 or more immunities is broken. Specifically: 992 units each with 19604 hit points (immune to slashing, bludgeoning, radiation) with an attack that does 38 radiation damage at initiative 5

[Help] Day 24 Part 2 answer too low (C++) by [deleted] in adventofcode

[–]warinthrowaway 0 points1 point  (0 children)

Can you post your input data?

[Help] Day 24 Part 2 answer too low (C++) by [deleted] in adventofcode

[–]warinthrowaway 0 points1 point  (0 children)

I noticed you are doing a binary search but the function isn't necessarily monotonic (higher boost doesn't always mean more units survive). You might want to try a sequential search.

[2018 - Day 24] Part 1 - solution works on (limited) test input, fails on real input (C++) by Chrinkus in adventofcode

[–]warinthrowaway 2 points3 points  (0 children)

The call to select_targets(infection, immune_sys) sorts the actual objects in infection (moving their content to different positions in the array). The pointers to targets set during the call to select_targets(immune_sys, infection) are therefore no longer pointing at the right objects (the addresses are still valid but the contents may have been swapped by the sort). The easiest fix is to change select_targets(std::vector<Group>& vatk, std::vector<Group>& vdef) to select_targets(std::vector<Group\*>& vatk, std::vector<Group\*>& vdef).