summary refs log tree commit diff
path: root/mapScore.py
diff options
context:
space:
mode:
Diffstat (limited to 'mapScore.py')
-rwxr-xr-xmapScore.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/mapScore.py b/mapScore.py
index 61a5259..430feb8 100755
--- a/mapScore.py
+++ b/mapScore.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 import sys
+import math
 
 def makeMap(filename):
   l= [(0,0) for x in range(0,127)]
@@ -10,24 +11,34 @@ def makeMap(filename):
       if c == '\t':
         x=x+1
       elif c == '\n':
-        x=0;y=y+1
+        y=y+1
+        x = (y%2)/2
       elif c:
         l[ord(c)] =(x,y)
       else:
         break
   return l
 
-def scoreWord(word,mm):
+def scoreWord(word,mm,fun):
   pc=word[0] or ' '
   s=0
   for c in word:
-    #manhattan dist
-    s+=abs(mm[ord(pc)][0]-mm[ord(c)][0])
-    s+=abs(mm[ord(pc)][1]-mm[ord(c)][1])
+    s += fun(mm[ord(pc)],mm[ord(c)])
     pc=c
   return s
 
+def manhattan_dist(p1, p2):
+   return abs(int(p1[0])-int(p2[0])) + abs(p1[1]-p2[1])
+
+def bee_dist(p1, p2):
+   yd = abs(p1[1] - p2[1])
+   xd = max(0, math.floor(abs(p1[0]-p2[0])) - yd//2)
+   return xd+yd
+
 def main(argv):
+  fun = manhattan_dist
+  if len(argv) >= 3 and argv[2] == 'bee':
+    fun = bee_dist
   mm=makeMap(argv[1])
   while 1:
    line = sys.stdin.readline()
@@ -35,7 +46,7 @@ def main(argv):
      break
    w=line.strip()
    if w:
-    print(scoreWord(w,mm),w,sep='\t')
+    print(scoreWord(w,mm,fun),w,sep='\t')
 
 if __name__ == '__main__':
   main(sys.argv)