IQ Sort

In a remedial math class, the teacher decides to seat the students in an IQ order. The seats are setup in a way that they appear in a horizontal line.

The order is such that when a hypothetical person X is to the left of a hypothetical person Y, and X is not more than 8 IQ points higher than Y .

For Example, Say that in the math class, there are five students that have IQs of 60 , 65 , 70 , 75 , 80 60, 65, 70, 75, 80 . The students could be put in an order of 60 , 70 , 65 , 80 , 75 60, 70, 65, 80, 75 .

If the class had 20 students with IQ scores: 20, 25, 30, 35, 40, 45, 50, 55, 60, 64, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110 , in how many ways could the students be seated in the order defined above?

Note:

  • There is someone of IQ 64 .
  • This problem can also be solved using a computer.
Thank You, axas bit for sharing this. Shame on you for never replying to my email though.


The answer is 23322.

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.

1 solution

  • Dynamic Programming Approach:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def iqsort(arr):
    if len(arr) == 1:
            yield arr
    else:
            for i in xrange(len(arr)):
                    for j in arr:
                            if arr[i] - j > 8:
                                    break
                    else:
                            s = iqsort(arr[:i]+arr[i+1:])
                            for k in s:
                                    yield [arr[i]] + k

a = [] 
for i in iqsort([20,25,30,35,40,45,50,55,60,64,65,70,75,80,85,90,95,100,105,110]):
    if not i in a:
        a.append(i)
print len(a)


  • Mathematical Approach:

See Page 23 of this document

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...