Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- def sum_of_digits(number):
- """
- Calculate the sum of the digits of the specified parameter.
- """
- return sum(map(int, str(number)))
- def is_accessible_point(x, y):
- """
- Verify if the given point is accessible to the monkey or not.
- """
- return (sum_of_digits(abs(x)) + sum_of_digits(abs(y))) <= 19
- def append_neighbors(points, x, y):
- """
- Append accessible neighbors to the accessible points `points`
- if does not exists.
- """
- for (i, j) in ((x+1, y), (x, y+1), (x-1, y), (x, y-1)):
- # print "%d, %d" % (i, j)
- if is_accessible_point(i, j) and ((i, j) not in points):
- points.append((i, j))
- if __name__ == '__main__':
- points = [(0, 0)]
- i = 0
- while i < len(points):
- append_neighbors(points, points[i][0], points[i][1])
- i += 1
- print "Number of accessible points is: %d" % len(points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement