ivantanchev

santa-100/100

Sep 24th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. def eat_cookies(presents_left, nice_kids):
  2. for cordinates in directions.values():
  3. r = santa_pos[0] + cordinates[0]
  4. c = santa_pos[1] + cordinates[1]
  5.  
  6. if neighborhood[r][c].isalpha():
  7. if neighborhood[r][c] == "V":
  8. nice_kids += 1
  9.  
  10. neighborhood[r][c] = "-"
  11. presents_left -= 1
  12. if not presents_left:
  13. break
  14. return presents_left, nice_kids
  15.  
  16.  
  17. presents = int(input())
  18. size = int(input())
  19.  
  20. neighborhood = []
  21. santa_pos = []
  22.  
  23. total_nice_kids = 0
  24. nice_kid_visited = 0
  25.  
  26. directions = {
  27. "up": (-1, 0),
  28. "down": (1, 0),
  29. "left": (0, -1),
  30. "right": (0, 1),
  31. }
  32. for row in range(size):
  33. line = input().split()
  34. neighborhood.append(line)
  35.  
  36. if "S" in line:
  37. santa_pos = [row, line.index("S")]
  38. neighborhood[row][santa_pos[1]] = "-"
  39.  
  40. total_nice_kids += line.count("V")
  41.  
  42. command = input()
  43. while True:
  44. if command == "Christmas morning":
  45. break
  46. santa_pos = [
  47. santa_pos[0] + directions[command][0],
  48. santa_pos[1] + directions[command][1],
  49. ]
  50. house = neighborhood[santa_pos[0]][santa_pos[1]]
  51. if house == "V":
  52. nice_kid_visited += 1
  53. presents -= 1
  54. elif house == "C":
  55. presents, nice_kid_visited = eat_cookies(presents, nice_kid_visited)
  56.  
  57. neighborhood[santa_pos[0]][santa_pos[1]] = "-"
  58. if not presents or nice_kid_visited == total_nice_kids:
  59. break
  60.  
  61. command = input()
  62.  
  63. neighborhood[santa_pos[0]][santa_pos[1]] = "S"
  64.  
  65. if not presents and nice_kid_visited < total_nice_kids:
  66. print("Santa ran out of presents!")
  67. print(*[" ".join(row) for row in neighborhood], sep="\n")
  68.  
  69.  
  70. if nice_kid_visited == total_nice_kids:
  71. print(f"Good job, Santa! {nice_kid_visited} happy nice kid/s.")
  72. else:
  73. print(f"No presents for {total_nice_kids-nice_kid_visited} nice kid/s.")
  74.  
Advertisement
Add Comment
Please, Sign In to add comment