Lets take a set of integers greater than 1 and call it X. We will define S(i) to be the set of all members of X divisible by i where i > 1. Would like to choose from these subsets a group of sets such that
Their union is the set X
No element of X is in two of the sets.
For example we can regroup {3..11}
as
{3,4,5,6,7,8,9,10,11}
S(3): {3, 6, 9, }
S(4): { 4, 8, }
S(5): { 5, 10, }
S(7): { 7, }
S(11):{ 11}
Some sets cannot be expressed in this way. For example if we take {3..12}
, 12
is a multiple of both 3 and 4 preventing our sets from being mutually exclusive.
Some sets can be expressed in multiple ways, for example {4..8}
can be represented as
{4,5,6,7,8}
S(4): {4, 8}
S(5): { 5, }
S(6): { 6, }
S(7): { 7, }
but it can also be represented as
{4,5,6,7,8}
S(2): {4, 6, 8}
S(5): { 5, }
S(7): { 7, }
Task
Our goal is to write a program that will take a set as input and output the smallest number of subsets that cover it in this fashion. If there are none you should output some value other than a positive integer (for example 0
).
This is a code-golf question so answers will be scored in bytes, with less bytes being better.
Tests
{3..11} -> 5
{4..8} -> 3
{22,24,26,30} -> 1
{5} -> 1
[5..5]
? Can we receive things like[8..4]
? \$\endgroup\$12
is a multiple of both3
and4
preventing our sets from being mutually exclusive": why? I don't see anything else in the problem statement which requires12
to go into both subsets. \$\endgroup\$[22,24,26,30]
are all multiples of2
. Are you sure it wouldn't be better to delete this and sandbox it? \$\endgroup\$