diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -5,7 +5,7 @@
 d = dict(zip(A, s))
 
 next = d[-1]
-while next != N:
+for _ in range(N - 1):
     print(next, end=" ")
     next = d[next]
 print(next)
