# random trigger, with decreasing threshold, "relaxed" to be sparse in time and space

## Recommended Posts

Posted (edited)

Let's say, there is a class with 10 children and teacher asks 10 questions with decreasing difficulty. Kids are in a row.

Please, is there any common attitude to make the raised hands sparse in time and space? The total count of raised hands is not crucial. The purpose is just to make it visually appealing.

- first question is the hardest, 1 kid raises hand
- second question, 2 or 3 kids, not the kid from first question, hands are "far away" from each other
- third question, 3 kids who did not answer before, and again gaps between kids
...
- tenth question, everybody raises hand
- at the end, each kid raised hand circa 5 times

Edited by ikoon

##### Share on other sites

The best (and simplest) method I could think of is a brute force:

- generate a number of solutions, with different seed
- for each solution, calculate the "sparsity" with weights (the gap between the answers is more important then the gap between kids)
- choose the solution with the highest sparsity

There are not many kids and questions. I think it is going to be fast. Still, I am curious, if it is a common scripting problem.

##### Share on other sites

Hi. Here is the crappy function I could think of. It returns list of lists with questions answered by each kid. First question is answered by one kid, last question is answered by everyone.

Kids will get some kind of brain penalty for answers, so they won't know the answer next time. I found if I force this strictly, I get visible switching between two "teams" in the middle.

So, randomized sampling is taking precedence after a few questions:

```from random import seed, shuffle, randint
from numpy import median

seed(hou.ch('seed'))

# Empty lists accumulating answered questions per kid.
kids = [[] for _ in range(num_kids)]

i = 0
while True:
# Randomize pending kids to avoid halves switching pattern.
slice = int(len(kids) * randomness)
a = kids[:slice]
b = kids[slice:]
shuffle(a)
kids = a + b  # Comment this to see problem.

pick = randint(max(1, i), min(i + 1, num_kids))
clever = kids[:pick]
dumb = kids[pick:]
clever = [scores + [i] for scores in clever]

# Extra shuffle for cases where randomness is near 0.
shuffle(clever)

kids = dumb + clever

# Finish if kids answered enough questions.
if median([len(s) for s in kids]) >= median_answers:
# Complete last row.
kids = [s + [i] if i not in s else s for s in kids]
return kids, i

i += 1```

Close neighbors can still answer simultaneously, though.

random_kids.hipnc

• 1

##### Share on other sites

Hi F1! This is great! Thank you very much!

It will take me a while to understand it all, but I really like the solution (add until median per kid is met). This is great idea. Also the shuffle ... I never used that, also the array output is great for me. I can build on that, thank you very very much again!

## Create an account

Register a new account