diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-14 20:55:39 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-14 20:55:39 +0700 |
commit | dbeda825d396deff88ac6754b20c084bd77510b7 (patch) | |
tree | b19034a50cfcec1e3675d57c4da1ee6314177fb8 /others/other/khaosat.py | |
parent | df20bbbebb8d5951607560d358c1a19388743113 (diff) | |
download | cp-dbeda825d396deff88ac6754b20c084bd77510b7.tar.gz |
Add others/other/{chonso1.pas,khaosat.py}
Diffstat (limited to 'others/other/khaosat.py')
-rwxr-xr-x | others/other/khaosat.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/others/other/khaosat.py b/others/other/khaosat.py new file mode 100755 index 0000000..861d6f5 --- /dev/null +++ b/others/other/khaosat.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +DIRECTIONS = {'E': (1, 0), 'W': (-1, 0), 'S': (0, -1), 'N': (0, 1)} + +current, memory = (0, 0), {(0, 0): 0} +with open('KHAOSAT.INP') as fi, open('KHAOSAT.OUT', 'w') as fo: + for c in fi.read().rstrip(): + prev, current = current, tuple(map(sum, zip(current, DIRECTIONS[c]))) + memory.setdefault(current, memory[prev] + 1) + print(memory[current], file=fo) |