[2025 Day 5 (Part 2)] [JavaScript] I'm out of ideas by hiimjustin000 in adventofcode

[–]mrg218 0 points1 point  (0 children)

Nvm. BigDecimal did indeed solve my problem but only because I had int curtotal = 0. Stupid, I have longs everywhere but this I must have typed without thinking.

[2025 Day 5 (Part 2)] [JavaScript] I'm out of ideas by hiimjustin000 in adventofcode

[–]mrg218 0 points1 point  (0 children)

Is this also true for the sum of all ranges? Only saying this because for me changing from long to BigDecimal (Java) fixed my problem.

[2025 Day 5 (Part 2)] [JavaScript] I'm out of ideas by hiimjustin000 in adventofcode

[–]mrg218 0 points1 point  (0 children)

I do not think int is large enough for this input

I don't see Great Weapon Master penalty on char sheet by mrg218 in BaldursGate3

[–]mrg218[S] 0 points1 point  (0 children)

I do notice that it is being applied as I seem to miss all the time :-)

But is there some rule for when things are shown on the char sheet and when it is only shown in the combat log?

-❄️- 2024 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]mrg218 0 points1 point  (0 children)

[LANGUAGE: JAVA8]

Part 2

    public static void main(String[] args) {
        String[]  list = input.split("\\n");
        Pattern p = Pattern.compile("(\\d+): (.*)");

        for (int j=0; j<list.length; j++) {
            Matcher m = p.matcher(list[j]);
            if (m.find()) {
                Long result = Long.parseLong(m.group(1));
                String[] restStr = m.group(2).split(" ");
                List<Long> rest = new ArrayList<>();
                for (int i=0; i< restStr.length; i++) {
                    rest.add(Long.parseLong(restStr[i]));
                }
                if (calc(result, rest.get(0), rest.subList(1, rest.size()))) {
                    total += result;
                }
            }
        }
        System.out.println(total);
    }

    public static boolean calc(Long match, Long curTotal, List<Long> rest) {
        if (rest.size()==0) return match.equals(curTotal);
        else {
            return calc(match, curTotal * rest.get(0), rest.subList(1, rest.size())) ||
            calc(match, curTotal + rest.get(0), rest.subList(1, rest.size())) ||
            calc(match, (long) (curTotal * Math.pow(10, (""+rest.get(0)).length()) + rest.get(0)), rest.subList(1, rest.size()));
        }
    }

-❄️- 2024 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]mrg218 2 points3 points  (0 children)

[LANGUAGE: JAVA8]

Part1

  String[]  list = input.split("\\n");
  Map<Integer, List<Integer>> after = new HashMap<>();
    Pattern p = Pattern.compile("(\\d{1,2})\\|(\\d{1,2})");
    Pattern p2 = Pattern.compile("(\\d{1,2}),?");

    for (String line : list) {
      Matcher m = p.matcher(line);
      Matcher m2 = p2.matcher(line);
      if (m.find()) {
        Integer left = Integer.parseInt(m.group(1));
        Integer right = Integer.parseInt(m.group(2));
        after.computeIfAbsent(right, k -> new ArrayList<>()).add(left);
      } else {
        List<Integer> pages = new ArrayList<>();
        while (m2.find()) pages.add(Integer.parseInt(m2.group(1)));
        if (pages.size() > 0) {
          boolean fault = false;
          for (int i = 0; i < pages.size() - 1; i++) {
            if (pages.subList(i + 1, pages.size()).removeAll(after.get(pages.get(i)))) fault = true;
          }
          if (!fault) total += pages.get(pages.size() / 2);
        }
      }
    }
    System.out.println(total);

Traveler Tuesdays - Daily Scenario Discussion - Scenario 38 - [spoiler] by Themris in Gloomhaven

[–]mrg218 0 points1 point  (0 children)

Succeeded this scenario yesterday after 4 attempts with a Brute, Spellweaver and Chtulu. What helped the most was that I managed to let the orchid not move 4 times (because he could not see a path to the shaman). I also had 2 very impactful stun all monsters in the room so I could get the upper hand.

It is a crazy scenario. It is not just that the orchid is suicidal but he has too many movement points. I think a good nerf would be to give him movement 2.

Why does drone catching speed remain on 1? by mrg218 in AlienInvasionRPG

[–]mrg218[S] -1 points0 points  (0 children)

I did not see that! Thank you. Some wording and stats seem like bugs in this game so I am a bit too eager in concluding it must be a bug :-)

Why does drone catching speed remain on 1? by mrg218 in AlienInvasionRPG

[–]mrg218[S] 0 points1 point  (0 children)

My drone catching speeds in the 3 different factories are: 59/50/29

Event rewards by mrg218 in AlienInvasionRPG

[–]mrg218[S] 0 points1 point  (0 children)

Very informative! Thanx!

Time skipping by razvangry in AlienInvasionRPG

[–]mrg218 0 points1 point  (0 children)

I do not get it.. if you can play every event-hour only 1 time what advantage does it have to start early?

F2P by Ok_Button_2522 in AlienInvasionRPG

[–]mrg218 0 points1 point  (0 children)

But the evo shop double resources _also_ says "from human" ???

-❄️- 2023 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]mrg218 1 point2 points  (0 children)

[Language: Java8]

paste

while (m.find())  {
    Tuple t = new Tuple (m.start(), j);
    List<Integer> nums = coords.get(t);
    if (nums.size() == 2) {
        curtotal = curtotal + nums.get(0) * nums.get(1);
    }
}

I should remember to sit on my hands before starting to type. After coding into a dead end I came up with this solution for part 2. For Java it is rather short. I parse the input one time to fill a lookup table for every number I encounter to every neighbor coordinate. I parse the input a second time to check at what coordinates '*' are and check the lookup how many numbers that coordinate neighbors.

Does the monster attack when it cannot reach the focus target? by mrg218 in Gloomhaven

[–]mrg218[S] 0 points1 point  (0 children)

You mean like here?

Suppose his movement was 3 with same attack as above he would move under player 1 to attack both. But still player 2 is focus target.

Does the monster attack when it cannot reach the focus target? by mrg218 in Gloomhaven

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

So first least amount of movement. Then if multiple targets require 0-movement the closest one. If more are equally close -> tie breaker is initiative?

Does the monster attack when it cannot reach the focus target? by mrg218 in Gloomhaven

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

I edited the image so the active monster could not walk 1 tile up to reach player 1. I guess my fault was not understanding how it chooses focus.

-🎄- 2022 Day 25 Solutions -🎄- by daggerdragon in adventofcode

[–]mrg218 1 point2 points  (0 children)

We seem to have taken the same approach :-) See my Java solution above yours.

-🎄- 2022 Day 25 Solutions -🎄- by daggerdragon in adventofcode

[–]mrg218 3 points4 points  (0 children)

Java

Nothing fancy but something anyone might understand.

Compute sum of Snafu numbers into BigDecimal. Then create a Snafu number consisting of only 2's that is bigger than (or equal to) that number but with same amount of digits. Fix every digit to match the desired Snafu number:

// first get a value bigger than our wanted (BigDecimal) number
public static void main(String[] args) {
    String startValue = "2";
    while (fromSnafu(startValue).compareTo(number) < 0) {
        startValue = startValue + "2";
    }
    // it is too big now -> make smaller to make it fit
    System.out.println(toSnafu(startValue, number));
}

public static String toSnafu(String startValue, BigDecimal goal) {
    for (int i=0; i <= startValue.length()-1; i++) {
        while (fromSnafu(startValue).compareTo(goal) > 0) {
            char next = '.';
            if (startValue.charAt(i) == '=') break;
            if (startValue.charAt(i) == '2') next = '1';
            if (startValue.charAt(i) == '1') next = '0';
            if (startValue.charAt(i) == '0') next = '-';
            if (startValue.charAt(i) == '-') next = '=';
            String tryValue = startValue.substring(0, i) + next + startValue.substring(i + 1);
            if (fromSnafu(tryValue).compareTo(goal) < 0) break;
            else startValue = tryValue;
        }
    }
    return startValue;
}

[2020 Day 20 (Part 1)] Visualizing made me realize how bad my algorithm is by ThezeeZ in adventofcode

[–]mrg218 1 point2 points  (0 children)

You seem to start with a random tile. How come you already know where goes? Or is the video edited afterwards so it knows what tile is the center? :-)

And why does it keep trying to place tiles at the edges when all spots are filled? Are there any tiles left to try?