Skip to content

Commit 7c0fd36

Browse files
committed
Complex utils: added manhattan distance sorting
1 parent 3c83d1f commit 7c0fd36

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

2019/complex_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def complex_sort(complexes, mode=""):
116116
elif mode == "reading":
117117
complexes.sort(key=lambda a: (-a.imag, a.real))
118118
# Sorts by distance from 0,0 (kind of polar coordinates)
119+
elif mode == "manhattan":
120+
complexes.sort(key=lambda a: manhattan_distance(0, a))
119121
else:
120122
complexes.sort(key=lambda a: sqrt(a.imag ** 2 + a.real ** 2))
121123
return complexes

0 commit comments

Comments
 (0)