Advertisement
Davitkova

01_worms_and_holes

Sep 23rd, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. from collections import deque
  2.  
  3. worms = [int(worm) for worm in input().split()]
  4. holes = deque(int(hole) for hole in input().split())
  5. matches = 0
  6. total_worms_count = len(worms)
  7.  
  8. while worms and holes:
  9.  
  10.     worm = worms.pop()
  11.     hole = holes.popleft()
  12.  
  13.     if worm <= 0:
  14.         holes.appendleft(hole)
  15.         continue
  16.  
  17.     if worm == hole:
  18.         matches += 1
  19.  
  20.     else:
  21.         worm -= 3
  22.         worms.append(worm)
  23.  
  24. matched_result = f"Matches: {matches}" if matches > 0 else "There are no matches."
  25. print(matched_result)
  26.  
  27. if total_worms_count == matches:
  28.     print("Every worm found a suitable hole!")
  29. elif worms:
  30.     print(f"Worms left: {', '.join(str(w) for w in worms)}")
  31. else:
  32.     print("Worms left: none")
  33.  
  34. if not holes:
  35.     print("Holes left: none")
  36. else:
  37.     print(f"Holes left: {', '.join(str(h) for h in holes)}")
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement