From dbeda825d396deff88ac6754b20c084bd77510b7 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Mon, 14 Aug 2017 20:55:39 +0700 Subject: Add others/other/{chonso1.pas,khaosat.py} --- others/other/khaosat.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 others/other/khaosat.py (limited to 'others/other/khaosat.py') 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) -- cgit 1.4.1