Last active
August 29, 2015 13:56
-
-
Save OzTamir/9168983 to your computer and use it in GitHub Desktop.
Find the number of options to paint m (or more) pixels in a pixel row with n pixels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def number_of_paint_options(n, m): | |
def find_num_options(n, m): | |
'''Find the number of options to paint m (or more) pixels in a pixel row with n pixels''' | |
return 1 + sum((k - m + 1) * find_num_options(n - k - 1, m) for k in range(m, n + 1)) | |
if m > n or m == 0: | |
return 0 | |
elif n == m: | |
return 1 | |
return find_num_options(n, m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if m == 0: return 0
Personal preference, different then question requirements.