Skip to content

Instantly share code, notes, and snippets.

@LyricLy
Created November 24, 2018 07:44
Show Gist options
  • Save LyricLy/f9d1a63c64c8b6e75a987690553145a5 to your computer and use it in GitHub Desktop.
Save LyricLy/f9d1a63c64c8b6e75a987690553145a5 to your computer and use it in GitHub Desktop.
import time
from collections import defaultdict
class Entity:
def __init__(self, value):
self.value = value
self.pos = 0
self.vel = value
def move(self):
self.pos += self.vel
if self.pos <= 0:
return self.value
self.vel -= 1
def print_entities(edct):
print("\n" * 100)
for i in range(max(edct.keys()))[::-1]:
try:
print(edct[i][0].value)
except IndexError:
print("-")
time.sleep(1)
def arrowsort(lst, output=None):
rlst = []
edct = defaultdict(list, {0: list(map(Entity, lst))})
while True:
if output:
output(edct)
new_edct = defaultdict(list)
for n in edct:
for x in edct[n]:
r = x.move()
if r is not None:
rlst.append(r)
else:
new_edct[x.pos].append(x)
if not new_edct:
return rlst
edct = new_edct
if __name__ == "__main__":
print(arrowsort(eval(input()), print_entities))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment