-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCronym
71 lines (62 loc) · 2.15 KB
/
Cronym
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
# === Transformation Matrices ===
T_flip = np.array([[-1, 0, 0], [0, 1, 0], [0, 0, 1]])
T_rotate_90 = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]])
T_rotate_45 = np.array([
[np.cos(np.pi/4), -np.sin(np.pi/4), 0],
[np.sin(np.pi/4), np.cos(np.pi/4), 0],
[0, 0, 1]
])
T_rotate_180 = np.array([[-1, 0, 0], [0, -1, 0], [0, 0, 1]])
# === Simplified Letter Positions ===
letter_positions = {
'A': np.array([1, 1, 2]),
'B': np.array([1, 1, 3]),
'C': np.array([1, 1, 1]),
'D': np.array([1, 1, 4]),
'E': np.array([0, 1, 2]),
'F': np.array([1, 1, 3]),
'H': np.array([1, 0, 1]),
'I': np.array([0, 0, 2]),
'M': np.array([1, 0, 3]),
'N': np.array([1, 0, 4]),
'O': np.array([0, 0, 1]),
'R': np.array([0, 1, 3]),
'L': np.array([0, 1, 4]),
'W': np.array([1, 0, 5])
}
# === Helpers ===
def get_scaling_matrix(word):
vowel_count = sum(1 for letter in word.upper() if letter in "AEIOU")
scale = 1.5 if vowel_count > 2 else 1.0
return np.diag([scale, scale, scale])
def extract_acronym(word):
return ''.join([c.upper() for c in word if c.isalpha()])
def transform_word(word, matrix):
result = ""
for letter in word:
if letter.upper() in letter_positions:
pos = matrix @ letter_positions[letter.upper()]
closest = min(letter_positions, key=lambda k: np.linalg.norm(letter_positions[k] - pos))
result += closest
else:
result += letter
return result
def transform_and_report(word, label, matrix):
transformed = transform_word(word, matrix)
acronym = extract_acronym(transformed)
print(f"[{label}] {word} → {transformed} → {acronym}")
return (word, transformed, acronym)
# === Main Execution ===
words_to_test = ["CAB", "LIME", "HEAR", "WORLD", "EXAMPLE", "COMPUTER"]
transformations = {
"Rotate180": T_rotate_180,
"Rotate90": T_rotate_90,
"Flip": T_flip,
"Rotate45": T_rotate_45
}
for word in words_to_test:
scaling_matrix = get_scaling_matrix(word)
for name, matrix in transformations.items():
full_matrix = matrix @ scaling_matrix
transform_and_report(word, name, full_matrix)