Last active
November 8, 2019 07:54
-
-
Save default-writer/f5aec429e24e7ea347d103c0574f5e07 to your computer and use it in GitHub Desktop.
Snail Python challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Implement snail algorithm in python to draw snail path on console window. | |
| Snail can't go up, allows right, left, or down. Snali move to the right can't go besides the screen boundaries, so she will not. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def _prn(i): | |
| q = [c for c in i] | |
| c = q.pop(0) | |
| ch = c | |
| right = [ch] | |
| head = 0 | |
| while True: | |
| if len(q) > 0: | |
| c = q.pop(0) | |
| if c == 'V': | |
| right[head] = ch | |
| print(convert(right)) | |
| right = [' ' if i < head else ch for i, x in enumerate(right[:head+1])] | |
| continue | |
| if c == '<': | |
| right.insert(head, ch) | |
| right = right[1:] | |
| head -= 1 | |
| continue | |
| if c == '>': | |
| right.insert(head, ch) | |
| head += 1 | |
| continue | |
| break | |
| print(convert(right)) | |
| print("\n") | |
| def convert(s): | |
| new = "" | |
| for x in s: | |
| new += x | |
| return new | |
| # import functools | |
| # import operator | |
| # return functools.reduce(operator.add, s) | |
| _prn(".>>>>VV<<V") | |
| _prn("@VVV>>>>>>>>V<<VVVV<<<VV>>>") | |
| _prn("@") | |
| _prn("@V") | |
| _prn("@VV") | |
| _prn("@>") | |
| _prn("@>V") | |
| _prn("@>V<") | |
| _prn("@") | |
| _prn("@>") | |
| _prn("@>>") | |
| _prn("@>>") | |
| _prn("@>>>") | |
| _prn("@>>>V") | |
| _prn("@>>>V<") | |
| _prn("@>>>V<<") | |
| _prn("@>>>V<<V") | |
| _prn("@") | |
| _prn("@>") | |
| _prn("@>V") | |
| _prn("@>V<") | |
| _prn("@>V<V") | |
| _prn("@>V<V>") | |
| _prn("@>V<V>V") | |
| _prn("@>V<V>V<") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment