Demo entry 6720765

combinatorics

   

Submitted by SelfStudyApp on Mar 18, 2018 at 09:34
Language: Python 3. Code size: 1.7 kB.

#--------*---------*---------*---------*---------*---------*---------*---------*
# Desc: Sum 4 addendums up to 68, using nums 1 = 4 but excluding 3, 12
#--------*---------*---------*---------*---------*---------*---------*---------*
import itertools

if True:
#                                  # create U = [1, 2, ..., 40] 
    U = list(range(1, 41))
#                                  # remove 12 from U
    U.pop(11)
#                                  # remove 3  from U    
    U.pop(2)
    countEmUp = 0
    countRejects = 0
    for i in itertools.product(U, U, U, U):
        if max(i) < 19:
            countRejects = countRejects + 1
            continue                    
        if min(i) > 15:
            countRejects = countRejects + 1
            continue            
#                                  # to screen for uniqueness,
#                                  # consider standard form  
        if i[0] < i[1] and i[1] < i[2] and i[2] < i[3]:
            pass
        else:
            countRejects = countRejects + 1
            continue
        if i[0] + i[1] + i[2] + i[3] == 68:
            countEmUp = countEmUp + 1
#                                  # print first 10 4-tuples
#                                  # that add up to 68
            if countEmUp <= 10:
                print(i)
        else:
            countRejects = countRejects + 1    
    print('Combinations Adding to Sixty-Eight =     ', countEmUp)
    print('Rejected tuples                    = ', countRejects)
    print('                                     ', '-------')
    print('38 raised to the fourth power      = ', 38*38*38*38)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).