I wish to solve the following problem by using only the concurrency features of Swift.
Problem
Given N + 1 integer numbers, where N >= 1, determine if the first number (the target number) can be expressed as a combination of the remaining N numbers (the input numbers) by following some simple rules (given below).
Rules
The combination process must follow these two rules to combine the input numbers:
- Each number may be used at most once;
- Multiple numbers may be combined using the arithmetic operations of addition, subtraction, multiplication, and exact integer-division (integer division without remainder.)
For example, here are a few simple instances of the problem:
numbers: 7, 7 (N = 1)
answer: yes
numbers: 21, 32 (N = 1)
answer: no
numbers: 32, 20, 12 (N = 2)
answer: yes (32 = 12 + 20 or 32 = 20 + 12)
numbers: 1, 20, 12, 20, 100 (N = 4)
answer: yes (1 = 20 / 20)
numbers: 155, 0, 5, 75, 2, 25 (N = 5)
answer: yes (155 = 2 * 75 + 5 or 155 = 25 / 5 + 2 * 75)
Solving this problem obviously involves taking the k-permutations of the N input numbers, applying all possible arithmetic operations to each such permutation, and checking the result to see if it equals the target number.
I have already solved this problem (even created a free App for it a decade ago) by using Objective C++ and The Grand Central Dispatch.
But, now I am slightly lost in the sea of Swift concurrency.
Thank you in advance for any expert advice you provide.