All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
ABCDEABCDEABCDE is one (Posted on 2023-11-14) Difficulty: 3 of 5
How many arrangements of the letters AAABBBCCCDDDEEE are there such that there are no triple letters in the sequence?

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer Solution | Comment 2 of 3 |
The total number of ways, including triplets, is 15!/(3!)^5 = 168,168,000

The Python itertools.permutations does not account for duplicate elements, but a different library does have that function:    more-itertools.distinct_permutations.
A test run counted the expected number.

But when all triplets are excluded, the count is 145,895,280

The first 10 and the last 10 permutations are shown:
['AABABBCCDCDEDEE',
 'AABABBCCDCDEEDE',
 'AABABBCCDCEDDEE',
 'AABABBCCDCEDEDE',
 'AABABBCCDCEDEED',
 'AABABBCCDCEEDDE',
 'AABABBCCDCEEDED',
 'AABABBCCDDCEDEE',
 'AABABBCCDDCEEDE',
 'AABABBCCDDECDEE',
 ... ... ... ...  ,
 ... ... ... ...  ,
 ... ... ... ...  ,
 'EEDEDDCCBBACBAA',
  'EEDEDDCCBBCAABA',
  'EEDEDDCCBBCABAA',
  'EEDEDDCCBCAABAB',
  'EEDEDDCCBCAABBA',
  'EEDEDDCCBCABAAB',
  'EEDEDDCCBCABABA',
  'EEDEDDCCBCABBAA',
  'EEDEDDCCBCBAABA',
  'EEDEDDCCBCBABAA']]

------------------------

count = 0
results = []
from more_itertools import distinct_permutations
for p in  (distinct_permutations('AAABBBCCCDDDEEE')):
    skip = False
    inarow = 0
    for i,v in enumerate(p):
        if i == 0:
            last = v
            inarow = 1
            continue
        if v == last:
            inarow += 1
            if inarow >= 3:
                skip = True
                break
        elif v != last:
            inarow = 1
            last = v
    if not skip:
        results.append(''.join(p))
        count += 1

print(count)

  Posted by Larry on 2023-11-14 15:05:56
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (10)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information