Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N_ELVES = 3018458
- class Elf():
- n = 0
- def __init__(self, right=None):
- self.left = None
- self.right = right
- Elf.n += 1
- self.n = Elf.n
- def remove_self(self):
- self.left.right = self.right
- self.right.left = self.left
- return self.left # return elf to left for easy iterating
- def do_stuff(*args, part_two=False):
- # Create all of the elves and link them together
- Elf.n = 0
- first_elf = Elf()
- last_elf = first_elf
- for i in range(N_ELVES - 1):
- new_elf = Elf(right=last_elf)
- last_elf.left = new_elf
- last_elf = new_elf
- last_elf.left = first_elf
- total_elves = N_ELVES
- # Find first elf that is removed from the game
- current_elf = first_elf
- if part_two:
- for _ in range(N_ELVES // 2):
- current_elf = current_elf.left
- else:
- current_elf = current_elf.left
- # Take one elf out of the game at a time
- while total_elves > 1:
- if part_two:
- current_elf = current_elf.remove_self()
- if total_elves % 2 == 1:
- current_elf = current_elf.left
- else:
- current_elf = current_elf.remove_self().left
- total_elves -= 1
- # Show the remaining elf
- print("Part {}:".format(2 if part_two else 1), current_elf.n)
- do_stuff()
- do_stuff(part_two=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement