@nickfernandez/

DishonestMidnightbluePlot

Python

No description

fork
loading
Files
  • main.py
  • nltk_data
  • bak
main.py
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
72
73
74
75
76
77
78
import nltk
# nltk.download('words')
from nltk.corpus import words

strings = ["ar", "as", "ch", "er", "hy", "op", "pe", "re", "st", "to", "un", "us"];

def getWords(start, parts):
  out = [];
  for s in parts:
      if(start != s):
        cur = start+s;
        if(cur in words.words()):
          out.append(cur);
  return out;

def possibleWords():
  for str in strings:
    out = getWords(str, strings);
    print(str, ": ", out);

def recur(word, list, level):  
  loop = [];
  start = word[2:];
  newList = list.copy();
  newList.remove(start);

  if(len(newList) <= 1):
    print("--- base case 2 ---");
    print("--- base case 2 ---");
    return [start, newList[0]];

  for nl in newList:
    w = start + nl;
    if(w in words.words()):
      for i in range(level):
        print(end="\t");
      print(w)
      recur(w, newList, level+1)
  
  return loop;

def seriesOut():
  output = [];
  strings.sort();
  curPart = strings[0];
  strings.remove(curPart);
  output.append(curPart);

  firstWords = getWords(curPart, strings);

  l = len(firstWords);
  if(l == 0):
    print("FAILED");
  elif(l == 1):
    print("Single original output");
    print(firstWords[0]);
    output += (recur(firstWords[0], strings, 1));
    print(output);
  else:
    print("multiple original output");
    print(firstWords);
    order = [];
    for first in firstWords:
      print(first + " produced order:");
      back = recur(first, strings, 1);  
      print(back);
      if(len(back) > len(order)):
        order = back;
    print("Best order: ");
    print(order);
    print(getWords(order[len(order)-1], [curPart]));


possibleWords();
print("---------------------------------");
seriesOut();