Project Euler #213: Flea Circus

  • + 0 comments

    This can be solved by calculating the probability of given square P(i, j) being occupied after m ring bells for given single flea starting at position (k, l). We can then compute the complement of the union of this events that is for all P(∑(i,j)') = ∏(1 - P(i.j)) - De Morgan Law Of Unions. The probability of square (i,j) being unocuppied afetr m ring bells is just equal to this value: P'(i,j) = ∏(1 - P(i.j)) when multiplication is calculated over flea starting from every square (k,l) in the grid. The expected value is the sum of all P'(i,j). To speed things up we can use symmetry and use just upper left quarter of the square as the starting positions of the fleas.