Weekly Challenge 086
Simon Green
Posted on November 9, 2020
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
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.
Posted on November 9, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.