❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

2022 Day 9: Rope Bridge

9 December 2022 at 06:32

I think the problem statement was intentionally difficult to parse this time. Those conditionals are a lot simpler than it makes them sound.

I kept the visited positions in a Hashed_Set and coming up with a good Hash function for a pair of Integers was new for me. I ended up making a lot of assumptions (Integer'Size = 32 and Hash_Type'Size = 64) and just shifted one of the integers left 32 bits. A cursory Google search turned up the Cantor Pairing function, but I wasn’t able to make this work with negative integers in a short amount of time. Clearly I need to do more reading.

Part 2 caught me off guard, I hadn’t anticipated I’d need to deal with more elements.

Note: I’m going to stop using the spoiler blur on the daily posts. If you’ve gotten this far, I assume you know that these posts contain spoilers.

13 posts - 8 participants

Read full topic

2022 Day 13: Distress Signal

By: cantanima
13 December 2022 at 09:01

We’re past halfway! :grin: :dark_sunglasses: :grinning: :sunglasses: :fireworks: :sparkler: :partying_face:

(The downside is that the problems have suddenly stepped up in difficulty!)

For the second day in a row, writing a program that solves the example wasn’t enough. Twice I ran it and got solutions that were rejected as too large. I had to comb through some of the pairs that my program claimed were legitimate. In both cases, it was the case where I had to compare a number and a list. The instructions are to create a new list that includes the number, then compare the lists, but it seemed equivalent to me simply to compare the number with the first element of the list. This produced false positives. I haven’t quite figured out why, though.

Curiously, in part 2 I was able to make it work simply by spoiler

5 posts - 5 participants

Read full topic

2022 Day 15: Beacon Exclusion Zone

By: cantanima
15 December 2022 at 07:42

Only 10 days left!

My solution to Part 1 was quite slow, perhaps because I used an OrderedSet. It might be worth retrying with a HashedSet at some point.

So I was really worried that Part 2 would be one of those problems whose obvious solution is to apply Part 1, but whoses complexity explodes on you, and as I first began to read it, my heart filled with dread. But then I realized that spoiler It still takes a few moments, but it worked! So I will be interested in seeing if anyone manages to solve it in a fraction of a second, and if so, then how.

I’m also amazed that Part 2 can even be a problem; the fact that he pulled off such a puzzle impresses me. Maybe it won’t impress me if I think about it enough, but even after a couple of glances, I’m still impressed. Maybe I just need some :sleeping_bed:

8 posts - 4 participants

Read full topic

2022 Day 17: Pyroclastic Flow

By: cantanima
17 December 2022 at 12:16

Part 1 is pretty straightforward, I think.

Part 2 requires some mathematics, or at least that’s what got me to solve it quite quickly I did one other thing, too.

The solution I uploaded for part 2 will probably not work on the example program, because the example’s sequences aren’t quite as well-behaved as the actual puzzle, which made the problem a little harder. But the same technique really does work!

2 posts - 2 participants

Read full topic

2022 Day 18: Boiling Boulders

By: wutka
18 December 2022 at 16:52

It was nice to get an easy one after the past two days. The only hard thing was that gnatprove was either hanging or crashing, and I guessed that it didn’t like all the nested-nested-nested loops. I rewrote it so I generated an array of all coordinates and looped through that instead of the nested loops and I was able to get gnatprove to finish.

In case anyone needs help with part B:

8 posts - 4 participants

Read full topic

2022 Day 19: Not Enough Minerals

By: cantanima
19 December 2022 at 13:43

Nope. I’ve been at this for hours.

  • I wasted hours just trying to get my code to run the example in a reasonable time, and when I gave up I discovered that the input takes not much longer to run than the example.

    So there’s a hint that doesn’t require a spoiler: don’t bother trying to get your program to work on the example in seconds; the input isn’t that much harder! Just try to get the program to work on the example, period!

  • Unfortunately, that’s not enough. The example doesn’t really illuminate the problem. Your code can run correctly on the example and run incorrectly on the problem input. This happens from time to time, but on a problem like today it’s ruinous.

  • To help me debug my program, I downloaded and ran several people’s solutions posted online (in other languages). I haven’t tried any of the solutions, but there’s a morbid satisfaction in the fact that different “solutions” produce different results on my input.

  • Some authors admit that they guessed at optimizations and got lucky; the optimizations probably don’t work in general. I’ve tried a few, and nope, they don’t work on my input (unless I’m implementing them wrong).

  • Some authors used parallelism. I may yet try that, since the problem is parallelizable, and otherwise I have to wait 5-10 minutes per attempt.

In short, I haven’t finished it yet. IMHO the puzzle is terribly flawed, for the reasons given above. And, yeah, sour grapes, too. :grin:

8 posts - 3 participants

Read full topic

2022 Day 20: Grove Positioning System

By: cantanima
20 December 2022 at 14:52

(edited after remembering another bad idea, whoops)

I had one very good idea, one good idea, and quite a few bad ideas, including one very bad idea that held me up a long time.

  • The very good idea was spoiler As a result, the solution to both parts takes only less than two seconds (using full optimization and inlining).
  • The good idea I don’t quite remember, sorry, but I had it in mind at one point. :grin:
  • One bad idea was spoiler. Fortunately, I caught that one quickly.
  • Another bad idea was spoiler Rather naughty of the example not to have a value that would illustrate that.
  • The very bad idea came while testing my code on the example. spoiler I wasted over an hour on that stupid mistake…

8 posts - 4 participants

Read full topic

2022 Day 21: Monkey Math

By: cantanima
21 December 2022 at 07:38

I really enjoyed today’s puzzle! Observations / hints / spoilers:

  • The example does not cover all the cases you need to check in Part 2. Interestingly, the input is relatively small if you look at it right, so even though I got Part 2 wrong the first time, it didn’t take me long to work through the example and find my mistake.
  • In part 1, spoiler
  • In part 2, spoiler

4 days left!!!

7 posts - 4 participants

Read full topic

Day 22: Monkey Map

By: cantanima
22 December 2022 at 09:37

This was fun. Even the debugging was fun. Even though the example was once again naughty, at least for Part 2, this was fun. (If anyone’s input creates a cube in the same way as the example, I’d like to know!)

Only one hint / comment from me: in part 2, spoiler.

I thought about drawing the paths onto the map, but it’s pretty late where I am, so maybe tomorrow. In lieu of that, here’s an aid I made to help with Part 2.
Day_22_cube

3 days left!

10 posts - 3 participants

Read full topic

❌
❌