Suppose your alarm wakes you up one morning, but you hit snooze so you can sleep for 8 more minutes. When it rings again you grudgingly get up and take a shower, which you estimate takes 15 to 17 minutes. You then brush your teeth for exactly 2 minutes, and get dressed, which takes about 3 to 5 minutes. Finally, you eat a hurried breakfast in 6 to 8 minutes and run out the door.
We can denote this timing sequence as 8 15-17 2 3-5 6-8
.
Given the uncertainty of your morning's routine, what is the probability you were doing each task at some particular number of minutes since you first woke up?
Assuming every task takes a whole number of minutes, we can chart every possible combination of uncertain time spans (e.g. 3, 4, and 5 minutes for brushing teeth). This chart shows all 27 possibilities, with time increasing to the right, and each task of N minutes represented by (N - 1) dashes and one vertical bar, just to mark its ending. The minute boundaries occur between characters, so the space between the 8
and 9
column is 8 min 59 sec
turning into 9 min
.
1111111111222222222233333333334
1234567890123456789012345678901234567890 <-- Minute
-------|--------------|-|--|-----|
-------|--------------|-|--|------|
-------|--------------|-|--|-------|
-------|--------------|-|---|-----|
-------|--------------|-|---|------|
-------|--------------|-|---|-------|
-------|--------------|-|----|-----|
-------|--------------|-|----|------|
-------|--------------|-|----|-------|
-------|---------------|-|--|-----|
-------|---------------|-|--|------|
-------|---------------|-|--|-------|
-------|---------------|-|---|-----|
-------|---------------|-|---|------|
-------|---------------|-|---|-------|
-------|---------------|-|----|-----|
-------|---------------|-|----|------|
-------|---------------|-|----|-------|
-------|----------------|-|--|-----|
-------|----------------|-|--|------|
-------|----------------|-|--|-------|
-------|----------------|-|---|-----|
-------|----------------|-|---|------|
-------|----------------|-|---|-------|
-------|----------------|-|----|-----|
-------|----------------|-|----|------|
-------|----------------|-|----|-------|
1234567891111111111222222222233333333334 <-- Minute
0123456789012345678901234567890
It is clear that the routine could have taken 40 minutes at most and 34 minutes at least.
The question is, at a particular minute, say minute 29, what is the chance you were doing each of the 5 tasks? Assume each uncertain time frame is uniformly distributed over the exact whole minutes. So a 4-7 task has 25% chance of taking 4, 5, 6, or 7 minutes.
From the chart it can be seen that at minute 29 there was a...
0/27 chance you were snoozing (task 1)
0/27 chance you were showering (task 2)
0/27 chance you were brushing (task 3)
24/27 chance you were dressing (task 4)
3/27 chance you were eating (task 5)
Similarly at minute 1 there was a 27/27
chance you were snoozing with 0/27
everywhere else.
At minute 38 for example, 17 of the potential routines have already ended. So in 10 out of 10 cases you will be eating. This means the probabilities look like
0/10 task 1, 0/10 task 2, 0/10 task 3, 0/10 task 4, 10/10 task 5
Challenge
Write a function that takes an integer for the minute value, and a string consisting of a sequence of single integers, or pairs of integers a-b
with b
> a
, all separated by spaces (just like 8 15-17 2 3-5 6-8
). All the integers are positive. The input minute will be less than or equal to the maximum time possible (40 in example).
The function should return another string denoting the unreduced fractional chance of being in each task at the given minute.
Examples
myfunc(29, "8 15-17 2 3-5 6-8")
returns the string0/27 0/27 0/27 24/27 3/27
myfunc(1, "8 15-17 2 3-5 6-8")
returns the string27/27 0/27 0/27 0/27 0/27
myfunc(38, "8 15-17 2 3-5 6-8")
returns the string0/10 0/10 0/10 0/10 10/10
myfunc(40, "8 15-17 2 3-5 6-8")
returns the string0/1 0/1 0/1 0/1 1/1
If your language does not have strings or functions you may use named variables, stdin/stdout, the command line, or whatever seems most appropriate.
Scoring
This is code golf. The shortest solution in bytes wins.
|
, the right|
, or half of each? \$\endgroup\$