Skip to content

Instantly share code, notes, and snippets.

@e0en
Created November 23, 2017 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0en/a08a3997c76f07ee3fbd9bac98c8f28e to your computer and use it in GitHub Desktop.
Save e0en/a08a3997c76f07ee3fbd9bac98c8f28e to your computer and use it in GitHub Desktop.
The secret algorithm for user taste score
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
alphabet_to_num = {
'A': 3,
'B': 3,
'C': 1,
'D': 2,
'E': 4,
'F': 3,
'G': 3,
'H': 3,
'I': 1, # open to discussion
'J': 2,
'K': 3,
'L': 2,
'M': 4,
'N': 3,
'O': 1,
'P': 2,
'Q': 2,
'R': 3,
'S': 1,
'T': 2,
'U': 1,
'V': 2,
'W': 4,
'X': 2,
'Y': 3,
'Z': 3
}
def reduce_numbers(numbers):
return [(x + y) % 10 for x, y in zip(numbers[1:], numbers)]
def print_numbers(numbers, size):
pad = " " * (size - len(numbers))
return pad + " ".join([str(x) for x in numbers])
if len(sys.argv) != 3:
print("usage: match_score.py <name1> <name2>")
name1 = sys.argv[1]
name2 = sys.argv[2]
if not (name1.isalpha() and name2.isalpha()):
print("All names must be written in alphabets")
else:
name1 = name1.upper()
name2 = name2.upper()
merged = [z for x, y in zip(name1, name2) for z in [x, y]]
print(" ".join(merged))
numbers = [alphabet_to_num[x] for x in merged]
size = len(numbers)
for i in range(size, 2, -1):
print(print_numbers(numbers, size))
numbers = reduce_numbers(numbers)
print(print_numbers(numbers, size) + " % match!")
@e0en
Copy link
Author

e0en commented Nov 23, 2017

$ python match-score.py gray matthew
G M R A A T Y T
3 4 3 3 3 2 3 2
 7 7 6 6 5 5 5
  4 3 2 1 0 0
   7 5 3 1 0
    2 8 4 1
     0 2 5
      2 7 % match!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment