DEV Community

Simon Green
Simon Green

Posted on

1 2

Weekly Challenge 086

This weeks challenge

With last week's task one, while I submitted a solution that works, I wasn't happy with the logic I used. The solution like Roger Bell West's one is much better.

TASK #1 › Pair Difference

After submitting a subpar solution last week, hopefully this one is better :)

First I check we have at least three values, and all values appear to be integers. Then I work through combinations of first number and second number. If first number minus the second number meets the target (excluding the situation where we use the same positioned number twice), then I output the solution. If no solution is found, then I output zero.

Originally I exited the outer loop if that number was less than the target. I removed that line when I figured that negative integers could mean a lower value could provide a solution.

I should also point out that the output of the first solution differs from the given example. There is more than one valid pair combination to reach $A.

Examples

» ./ch-1.pl 10 8 12 15 5 7
Output: 1 as 12 - 5 = 7

» ./ch-1.pl 1 5 2 9 7 6
Output: 1 as 7 - 1 = 6

» ./ch-1.pl 10 30 20 50 40 15
Output: 0
Enter fullscreen mode Exit fullscreen mode

TASK #2 › Sudoku Puzzle

At this stage, I don't plan to submit a solution to this task. A solution that I would be happy with would take many hours to write. This is the first time I have done this.

Take this row / column / sub-box for example: [123] [124] 5 [12] 6 7 [12] 8 9

There is a lot of work required to figure out that the solution can be reduced to 3 4 5 [12] 5 7 [12] 8 9.

The alternative is to use a CPAN module that probably already exists to solve Sudoku puzzles. But that's no fun at all, and (IMO) against the spirit of these challenges.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay