A simple implementation to solve subset sum problems.
See the related Reddit post.
To compile the code, run the following command in a command prompt:
cargo build
You need to have the Rust toolchain installed.
To run the program, open a command prompt and type:
numbercrunching.exe <path_to_file_with_the_numbers> [the_sum_to_find, default=0]
Required parameters are surrounded by <>
and optional parameters are surrounded by []
.
- The file containing the numbers should have one number per line.
- The numbers should all be decimal (as in "not integers").
- The numbers must have two (and only two) digits after the decimal point.
- Empty lines are supported (e.g. between the numbers, and at the end of the file).
File with the numbers (numbers.txt
):
-2.00
-1.00
1.00
2.00
3.00
numbercrunching.exe numbers.txt
Result:
[-1.00, 1.00]
[-2.00, 2.00]
[-1.00, -2.00, 3.00]
Note: the result doesn't include "duplicates", as per OP's request.
E.g.
[-2.00, -1.00, 1.00, 2.00]
shouldn't be included, since both[-2.00, 2.00]
and[-1.00, 1.00]
are already included in the results.
File with the numbers (numbers.txt
):
-2.00
-1.00
1.00
2.00
3.00
numbercrunching.exe numbers.txt 1.0
Result:
[1.00]
[-1.00, 2.00]
[-2.00, 3.00]