Vibgyor

Let us call an arrangement of the letters of the word VIBGYOR good if it doesn't contain any string of letters (length \geq 2 letters) present in the original word ( VIBGYOR ). How many good arrangements are there?

Details and Assumptions

  • For example, OYVIBRG is not acceptable as it contains the string VIB .

  • But, IVGBROY is acceptable.


The answer is 2119.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Patryk Lipski
Dec 11, 2014

Since the characters are all distinct, let's use the string 1234567 1234567 instead. Let G n G_{n} denote the set of good arrangements for a string of distinct characters of length n n . For every string in G n G_{n} , we can form a string in G n + 1 G_{n+1} by adding in a new character n + 1 n+1 anywhere that isn't directly after the character denoted by n n , giving n n good arrangements in G n + 1 G_{n+1} for every arrangement in G n G_{n} (for example, in 214365 214365 we can add a 7 7 anywhere except after 6 6 ).

However, consider an arrangement of n n characters in which there exist only two characters in order. We could place the n + 1 t h n+1th character in between these two to create a good arrangement out of a non-good one. For 1 k n 1 1 \leq k \leq n-1 , we can model the triplet k , n + 1 , k + 1 k, n+1, k+1 as one character, so we reduce n + 1 n+1 characters to n 1 n-1 characters (for example, 651243 651243 can be made into 6517243 6517243 , and 172 172 can go anywhere except before 3 3 ). This allows us to only consider arrangements in G n 1 G_{n-1} , and create n 1 n-1 good arrangements from each one.

Then, G n + 1 |G_{n+1}| = ( n ) G n + ( n 1 ) G n 1 (n)|G_{n}| + (n-1)|G_{n-1}| . G 2 |G_{2}| and G 3 |G_{3}| are easily calculable as 1 1 and 3 3 , so:

G 4 = ( 3 ) ( 3 ) + ( 2 ) ( 1 ) = 11 |G_{4}| = (3)(3) + (2)(1) = 11

G 5 = ( 4 ) ( 11 ) + ( 3 ) ( 3 ) = 53 |G_{5}| = (4)(11) + (3)(3) = 53

G 6 = ( 5 ) ( 53 ) + ( 4 ) ( 11 ) = 309 |G_{6}| = (5)(53) + (4)(11) = 309

G 7 = ( 6 ) ( 309 ) + ( 5 ) ( 53 ) = 2119 |G_{7}| = (6)(309) + (5)(53) = \boxed{2119}

Brock Brown
Dec 23, 2014

An approach using breadth first search to generate the search space, counting the number of strings with length 7.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def bfs(beginning, children, goal, iterlimit):
    cause = {beginning:None}
    frontier = [beginning]
    next_frontier = []
    goal_count = 0
    while frontier:
        next_frontier = []
        for member in frontier:
            for child in children(member):
                if child not in cause:
                    cause[child] = member
                    next_frontier.append(child)
                    if goal(child):
                        goal_count += 1
        frontier = next_frontier[:]
        iterlimit -= 1
        if iterlimit == 0:
            print "Iteration limit reached."
            break
    print "Operation completed."
    print "Number of nodes found: {0}".format(len(cause))
    print "Number of goals: {0}".format(goal_count)
    return cause
def substrings(s):
    # returns all substrings of s that
    # have a length of two or more
    answers = set()
    answers.add(s)
    for length in xrange(2,len(s)):
        for sub in xrange(0,len(s)-length+1):
            answers.add(s[sub:sub+length])
    return answers

vibgyor_subs = substrings("vibgyor")
start = ""

def neighbor(x):
    children = []
    for char in "vibgyor":
        if x.count(char) == 0:
            subs = substrings(x+char)
            if len(subs & vibgyor_subs) == 0:
                children.append(x+char)
    return children
def goal(x):
    return len(x) == 7

bfs(start,neighbor,goal,100)

Rohit Shah
Dec 18, 2014

Any letter in the combination must not be followed by its next letter in VIBGYOR. After that just apply inclusion and exclusion principle

Yash Shroff
Dec 6, 2014

D7 + other cases..

Why D7 (Seventh derangement number)? Could you elaborate? For example, OYVIBRG is counted in D7, but it is not acceptable.

Pratik Shastri - 6 years, 6 months ago

Log in to reply

I don't get it. SO there are six possible strings of length 2 right? If I have VI,IB,BG,GY,YO and OR and I have 6 possible ways to place them such that they are consecutive and 5! ways to move the remaining letters then I have 4320 possible 'Bad' arrangements out of 5040. WHy isn't that right?

johnson adeleke - 6 years, 6 months ago

Log in to reply

If I understand correctly, you have arranged the six strings. That itself is wrong as every letter is occurring twice except V and R.

Pratik Shastri - 6 years, 6 months ago

One may use inclusion-exclusion to prove a generalization-

The number of permutations π \pi of 1 , 2 , . . , n {1,2,..,n} such that π ( j + 1 ) π ( j ) + 1 π(j+1)≠π(j)+1 for j = 1 , 2.. , n 1 j=1,2..,n-1 is D n + D n 1 D_{n}+D_{n-1} where D n D_{n} is the n n -th Derangement number.

So, here the answer is D 6 + D 5 D_{6}+D_{5} which equals 2119 2119

Souryajit Roy - 6 years, 6 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...