Skip to content

As simple bruteforce solver for the subset sum problem

License

Notifications You must be signed in to change notification settings

Ascor8522/number_crunching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numbercrunching

Release License

A simple implementation to solve subset sum problems.

See the related Reddit post.

Compile the code

To compile the code, run the following command in a command prompt:

cargo build

You need to have the Rust toolchain installed.

Run the program

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).

Examples

Default use case (sum = 0)

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.

Custom sum

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]