def main():

    acceptable_groups = list()

    # since n = 6:
    # 11 (middle from n = 5), 18 (11 + 6 + 1),
    # 19 (11 + 9 - 1), 20 (11 + 11 - 2), 22 (11 + 12 - 1),
    # 25 (11 + 13 + 1)

    # I make the guess that n = 7 is in the form of:
    # 20 (middle from n = 6), 31 (20 + 11) +/- 1, 38 (20 + 18) +/- 2,
    # 39 (20 + 19) +/- 3, 40 (20 + 20) +/- 3, 42 (20 + 22) +/- 2,
    # 45 (20 + 25) +/- 1

    # Brute force through all the possibilities to find the optimal set.
    for a in (30, 31, 32):
        for b in (36, 37, 38, 39, 40):
            for c in (36, 37, 38, 39, 40, 41, 42):
                for d in (37, 38, 39, 40, 41, 42, 43):
                    for e in (40, 41, 42, 43, 44):
                        for f in (44, 45, 46):
                            numbers = {20, a, b, c, d, e, f}

                            # no duplicates.
                            if len(numbers) != 7:
                                continue

                            if Problem105.is_group_acceptable(numbers):
                                # both properties have been verified. save this set for later.
                                acceptable_groups.append(numbers)

    # find the set with the smallest sum.
    minimum = None
    for acceptable in acceptable_groups:
        if minimum is None:
            minimum = acceptable
        elif sum(acceptable) < sum(minimum):
            minimum = acceptable

    # print out the set in set string notation as defined by the problem description.
    print "Optimal Set String: %s" % ''.join(
        str(number) for number in sorted(minimum))
def main(n_value):

    numbers = [number for number in xrange(1, n_value + 1)]

    groups_to_check_for_equality = 0

    for subset in Problem105.all_subsets(numbers):

        first_subset, second_subset = subset

        # because we assume that the second rule has been met,
        # we can assume that two differently-sized subsets
        # cannot possibly be equal
        if len(first_subset) != len(second_subset):
            continue

        # since the sequence is strictly increasing, no two
        # sets of cardinality 1 can be equal.
        if len(first_subset) == 1:
            continue

        # to see whether we need to test for equality,
        # we compare the values at the same indicies in both subsets.
        # if subset A's values are all less than subset B's counterparts,
        # then clearly there is no need to test for equality.
        smaller = 0
        greater = 0
        for pair in zip(first_subset, second_subset):
            first, second = pair
            if first < second:
                smaller += 1
            else:
                greater += 1

        if smaller == len(first_subset) or greater == len(first_subset):
            continue

        # these are the ones that have survived and need further processing.
        groups_to_check_for_equality += 1

    print "Groups to check for equality: %d" % groups_to_check_for_equality
def main():

    acceptable_groups = list()

    # since n = 6:
    # 11 (middle from n = 5), 18 (11 + 6 + 1),
    # 19 (11 + 9 - 1), 20 (11 + 11 - 2), 22 (11 + 12 - 1),
    # 25 (11 + 13 + 1)

    # I make the guess that n = 7 is in the form of:
    # 20 (middle from n = 6), 31 (20 + 11) +/- 1, 38 (20 + 18) +/- 2,
    # 39 (20 + 19) +/- 3, 40 (20 + 20) +/- 3, 42 (20 + 22) +/- 2,
    # 45 (20 + 25) +/- 1

    # Brute force through all the possibilities to find the optimal set.
    for a in (30, 31, 32):
        for b in (36, 37, 38, 39, 40):
            for c in (36, 37, 38, 39, 40, 41, 42):
                for d in (37, 38, 39, 40, 41, 42, 43):
                    for e in (40, 41, 42, 43, 44):
                        for f in (44, 45, 46):
                            numbers = {20, a, b, c, d, e, f}

                            # no duplicates.
                            if len(numbers) != 7:
                                continue

                            if Problem105.is_group_acceptable(numbers):
                                # both properties have been verified. save this set for later.
                                acceptable_groups.append(numbers)

    # find the set with the smallest sum.
    minimum = None
    for acceptable in acceptable_groups:
        if minimum is None:
            minimum = acceptable
        elif sum(acceptable) < sum(minimum):
            minimum = acceptable

    # print out the set in set string notation as defined by the problem description.
    print "Optimal Set String: %s" % ''.join(str(number) for number in sorted(minimum))