Skip to content

Small program that finds a subset of numbers whose sum is divisible by the size of the superset

License

Notifications You must be signed in to change notification settings

g-peery/finddiv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

finddiv

This is a small program that finds a subset of numbers whose sum is divisible by the size of the superset.

I was given a mathematical puzzle: prove that for any set of 100 integers, there exists a subset whose sum is divisible by 100. The proof suggested an elegant way to find such a subset, so I implemented it in this program. As a bonus, it is made to work with an arbitrary number n of integers and find a subset with a sum divisible by n.

Give it whitespace-separated integers on stdin, and it will print the subset on stdout. Example:

$ make
$ seq 1 100 | ./finddiv
9
10
11
12
13
14
15
16

Note: only guaranteed to work with integers in the range of your machine's unsigned int data type.

About

Small program that finds a subset of numbers whose sum is divisible by the size of the superset

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published