Browse Source

Add near palindrome output, and fix palindrome pairs to exclude palindromes

master
Charles Reid 2 years ago
parent
commit
d2ad99bfb6
4 changed files with 219 additions and 26 deletions
  1. +7
    -5
      near_palindromes.py
  2. +207
    -0
      output/near_palindromes
  3. +1
    -19
      output/palindromes
  4. +4
    -2
      palindromes.py

+ 7
- 5
near_palindromes.py View File

@@ -11,9 +11,9 @@ from get_words import get_words
from euclidean_distance import euclidean_distance
from pprint import pprint

def is_near_palindrome(word):
test1 = euclidean_distance(word[0],word[4])<=1.0
test2 = euclidean_distance(word[1],word[3])<=1.0
def is_near_palindrome(word,tol):
test1 = euclidean_distance(word[0],word[4])<=tol
test2 = euclidean_distance(word[1],word[3])<=tol
if(test1 and test2):
return True
return False
@@ -24,9 +24,11 @@ if __name__=="__main__":
knp = 0
near_palindromes = []

# Check for palindromes
# Euclidean distance tolerance
tol = 2.0

for i in range(len(words)):
if(is_near_palindrome(words[i])):
if(is_near_palindrome(words[i],tol)):
knp += 1
near_palindromes.append(words[i])



+ 207
- 0
output/near_palindromes View File

@@ -0,0 +1,207 @@
----------------------------------------
Near Palindromes:

['their',
'right',
'found',
'going',
'often',
'start',
'ocean',
'level',
'stars',
'sight',
'dance',
'fresh',
'spent',
'seeds',
'visit',
'towns',
'graph',
'fence',
'climb',
'bound',
'rooms',
'refer',
'curve',
'tight',
'blind',
'trust',
'blend',
'rings',
'flame',
'trips',
'reads',
'sport',
'sings',
'suits',
'hatch',
'shift',
'slant',
'comma',
'sends',
'tends',
'flung',
'shaft',
'radar',
'fetch',
'naval',
'robot',
'reeds',
'cocoa',
'traps',
'react',
'stout',
'spins',
'onion',
'curse',
'plump',
'users',
'madam',
'risks',
'sinks',
'blond',
'rotor',
'slums',
'edged',
'civic',
'spurs',
'jewel',
'snaps',
'silks',
'nasal',
'crate',
'sighs',
'erase',
'theft',
'fling',
'grape',
'ticks',
'pagan',
'sexes',
'reefs',
'stirs',
'serfs',
'spurt',
'soaps',
'snips',
'tufts',
'truss',
'sewer',
'strut',
'bland',
'soups',
'solos',
'spans',
'smelt',
'farce',
'spars',
'grate',
'flake',
'grope',
'sever',
'slams',
'trots',
'guise',
'weedy',
'froth',
'rusts',
'sagas',
'coupe',
'skims',
'quits',
'scabs',
'sways',
'moron',
'kayak',
'drape',
'runts',
'tsars',
'gnome',
'tress',
'roams',
'knell',
'talcs',
'dirge',
'wormy',
'ceded',
'gripe',
'rinks',
'feted',
'chafe',
'rends',
'scads',
'romps',
'suets',
'cilia',
'geode',
'fugue',
'knoll',
'ephod',
'veldt',
'fluke',
'crepe',
'reset',
'farad',
'peter',
'natal',
'thugs',
'egged',
'newel',
'seder',
'minim',
'paean',
'tenet',
'cruse',
'emend',
'snoot',
'clime',
'fiche',
'porno',
'tryst',
'flume',
'toons',
'narco',
'educe',
'roans',
'twixt',
'shahs',
'tutus',
'shags',
'clone',
'zingy',
'frosh',
'pinko',
'mambo',
'deuce',
'stats',
'slims',
'deice',
'offen',
'abaca',
'klunk',
'feued',
'anima',
'wedgy',
'celeb',
'tings',
'unapt',
'selfs',
'nihil',
'pavan',
'stets',
'scuds',
'tikis',
'relet',
'heigh',
'revet',
'sicks',
'pengo',
'kaiak',
'finif',
'dulse',
'topos',
'spoor',
'rajas',
'dewed',
'eland']

+ 1
- 19
output/palindromes View File

@@ -26,8 +26,6 @@ Palindrome Pairs:
('lived', 'devil'),
('speed', 'deeps'),
('sleep', 'peels'),
('level', 'level'),
('refer', 'refer'),
('straw', 'warts'),
('faced', 'decaf'),
('spots', 'stops'),
@@ -35,7 +33,6 @@ Palindrome Pairs:
('lever', 'revel'),
('smart', 'trams'),
('ports', 'strop'),
('radar', 'radar'),
('pools', 'sloop'),
('stool', 'loots'),
('draws', 'sward'),
@@ -44,33 +41,18 @@ Palindrome Pairs:
('alley', 'yella'),
('loops', 'spool'),
('sleek', 'keels'),
('madam', 'madam'),
('rotor', 'rotor'),
('civic', 'civic'),
('repel', 'leper'),
('snaps', 'spans'),
('depot', 'toped'),
('timed', 'demit'),
('sexes', 'sexes'),
('debut', 'tubed'),
('laced', 'decal'),
('solos', 'solos'),
('stink', 'knits'),
('regal', 'lager'),
('sagas', 'sagas'),
('tuber', 'rebut'),
('kayak', 'kayak'),
('remit', 'timer'),
('pacer', 'recap'),
('minim', 'minim'),
('tenet', 'tenet'),
('snoot', 'toons'),
('namer', 'reman'),
('shahs', 'shahs'),
('hales', 'selah'),
('tarps', 'sprat'),
('stats', 'stats'),
('stets', 'stets'),
('kaiak', 'kaiak'),
('finif', 'finif'),
('dewed', 'dewed')]
('tarps', 'sprat')]

+ 4
- 2
palindromes.py View File

@@ -50,8 +50,10 @@ if __name__=="__main__":
for i in range(len(words)):
for j in range(i,len(words)):
if(is_palindrome_pair(words[i],words[j])):
kpp += 1
palindrome_pairs.append((words[i],words[j]))
# Palindromes shouldn't count as palindrome pairs
if(words[i] is not words[j]):
kpp += 1
palindrome_pairs.append((words[i],words[j]))

print("-"*40)
print("Palindrome Pairs: \n")


Loading…
Cancel
Save