0

Problem Statement

In a university, your attendance determines whether you'll be allowed to attend your graduation ceremony. You are not allowed to miss classes for four or more consecutive days. You graduation ceremony is on the last day of the of the academic year, which is the Nth day.

Your task is to determine the following:

  1. The number of ways of attending classes over N days.
  2. The probability that you will miss your graduation ceremony.

Information I tried to decode from the problem statement:

  1. There would be two choices everyday for N number of days i.e. attend the class or not.

  2. But, because of the constraint, the allowed consecutive gaps are 0 days, 1 days, 2 days and 3 days.

  3. Let's try to find the invalid ways and subtract it from total number of possibilities.

  4. So, Total number of ways - Invalid possibilities i.e. 4. $$ 2^{n - 1} - ( 2^{n - 4} * (n - 3)) $$

  5. I also visited this answer but was not able to map it to my problem.

MY DOUBT

Actually, I am not able to figure out whether my solution is correct. My approach seems right to me but actually it is right or wrong I'm not able to figure out. Or is there any other way of solving this problem?

Any assistance will be helpful. Sorry If I missed something. Please do let me know what else I can add.

Thanks

mandy8055
  • 101
  • 1
    I don't think that there is a simple answer. If you look at this question you'll see it's hard even if you are allowed to miss $s=2$ days in a row, but not $3$. You can do it with a recurrence, but it will be fourth-degree, and an exact solution will be complicated. As for the second part, unless the probability of attending class on any given day is $\frac12$, that's even more complicated. – saulspatz Jun 11 '21 at 18:53
  • Okay @saulspatz. So if I proceed via recursion, then are there chances of reaching to the solution? How hard can it be actually? – mandy8055 Jun 11 '21 at 18:58
  • You can solve the problem easily with a recursive formula. Look at the the answers to the question I linked. What I'm trying to say is that I doubt there is a simple explicit formula. This problem is simpler than the linked problem in that we don't care how many absences there have been, so long as there have not been four consecutive ones. – saulspatz Jun 11 '21 at 19:04
  • this solution is for 2 days but how to make it for four days ?? any idea ~~~ N = int(input()) a = 1 p = 1 N = N-1 while(N): tempP = a+p tempA = p a = tempA p = tempP N = N-1 print(a+p) print(str(a) + "/" + str(a+p)) – Anshul bisen Oct 21 '21 at 18:46
  • This question is easy to answer with Fibonacci series instead of plain Permutation and Combination – Mrinal Kamboj May 04 '23 at 08:52

2 Answers2

1

Following shall be the solution:

We start with n=1 till n=4 and find the series as base data, after that fibonacci or similar series takes over since for next set of records result is the sum of seed data and it moves on (I am not aware of specific name of the series):

  1. For n days, data is n=1 - 2, n=2 - 4, n=3 - 8, n=4 - 15, since AAAA is invalid, series become [2,4,8,15,29,56,108,208,401,773], for n = 10

  2. Now when it is absence on graduation day, then n=n-1, since graduation day is fixed as A (Absent) otherwise condition of 4 or more consecutive absent remains as is, therefore the series is: [1,2,4,7,14,27,52,100,193,372]

  3. Now the solution for of n <= 10 can be calculated here and for higher number like n = 365 a program can calculate by creating a series:

like n=5, Solution - 14/29 n = 10, Solution - 372/773

Important aspect that many solutions omit is that graduation day absence cannot lead to consider invalid data, 4 or more absents aren't allowed

0

code implimentaion of @darren

def solve(n):
    if n<4:
        return str(2**(n-1))+'/'+str(2**n)
    A=2
    AA=1
    AAA=1
    P = 4
    count = 8
    for i in range(4,n+1):
        temp= AAA
        AAA=AA
        AA=A
        A=P
        P= count
        count = (count-temp)*2+temp
    return str(AAA+AA+A)+'/'+str(count)