-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetters.html
More file actions
223 lines (205 loc) · 7.59 KB
/
Letters.html
File metadata and controls
223 lines (205 loc) · 7.59 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE HTML>
<!--
Massively by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Joseph Ruff - Countdown Letters</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous">
</script>
<script>
$(document).ready(function(){
$("#img1").click(function(){
$("#img1").parent().toggleClass("col-6");
});
$("#img2").click(function(){
$("#img2").parent().toggleClass("col-6");
});
});
</script>
<style>
.code1 {
color:#ffa500;
}
.code2 {
color:#9900cc;
}
.code3 {
color:#008000;
}
.code4 {
color:#ff0000;
}
</style>
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<a href="https://josephruff.github.io" class="logo">Joseph Ruff</a>
</header>
<!-- Nav -->
<nav id="nav">
<ul class="links">
<li><a href="https://josephruff.github.io">Portfolio</a></li>
<li><a href="CurriculumVitae.html">Curriculum Vitae</a></li>
<li class="active"><a href="Letters.html">Countdown Letters Solver</a></li>
</ul>
<ul class="icons">
<li><a href="Curriculum Vitae Joseph David Ruff.pdf" class="icon solid fa-download"><span class="label">Download CV</span></a></li>
<li><a href="https://www.linkedin.com/in/joseph-ruff-a99062393" class="icon brands fa-linkedin"><span class="label">Instagram</span></a></li>
<li><a href="https://github.com/JosephRuff" class="icon brands fa-github"><span class="label">GitHub</span></a></li>
</ul>
</nav>
<!-- Main -->
<div id="main">
<!-- Post -->
<section class="post">
<header class="major">
<h1>Countdown Letters Solver</h1>
<p>Python 3 program written to solve the countdown letters game. </p>
</header>
<div class="image main"><img src="images/lukas-blazek-UAvYasdkzq8-unsplash.jpg" alt="" /></div>
<hr>
<h2>
Contents
</h2>
<ul class="alt">
<li>
<a href="#problem">The Problem</a>
</li>
<li>
<a href="#solution">The Solution</a>
</li>
<li>
<a href="#example">Examples</a>
</li>
<li>
<a href="#code">Source Code</a>
<ul class="alt nested">
<li><a href="#code">In Page</a></li>
<li><a href="#links">GitHub</a></li>
</ul>
</li>
</ul>
<hr>
<a id="problem"></a>
<h2>
The Problem
</h2>
<p>
The countdown letters game involves rearranging a selection of 9 letters into
the longest possible word. Each letter in the selection can only be used once,
however the selection can contain duplicate letters.
</p>
<p>
The selection must contain a minimum of 3 consonants and 4 vowels.
</p>
<hr>
<a id="solution"></a>
<h2>
The Solution
</h2>
<p>
My solution takes any string input, and will find any words from a given word
list that can be made from the characters in that string.
</p>
<p>
It achieves this by looking through the entire word list, line by line, and
for every word that is a valid anagram it appends it to a list.
</p>
<p>
The results are then sorted by length (descending), and printed.
</p>
<hr>
<a id="example"></a>
<h2>
Examples
</h2>
<div class="box alt">
<div class="row gtr-50 gtr-uniform">
<div class="col-6">
<a id="img1" class="image fit">
<img src="images/Letters1.png" alt="" />
</a>
</div>
<div class="col-6">
<a id="img2" class="image fit">
<img src="images/Letters2.png" alt="" />
</a>
</div>
</div>
</div>
<hr>
<a id="code"></a>
<h2>
Source Code
</h2>
<pre><code>
<span class="code1">from</span> collections <span class="code1">import</span> Counter
<span class="code1">while</span> (<span class="code1">True</span>):
<span class="code2">print</span>(<span class="code3">"Please enter a string: "</span>)
letters = Counter(<span class="code2">input</span>())
wordList = []
<span class="code1">with</span> <span class="code2">open</span>(<span class="code3">"ukenglish.txt"</span>, encoding=<span class="code3">"Latin-1"</span>) <span class="code1">as</span> f:
<span class="code4">#Content_list is the list that contains the read lines.</span>
<span class="code1">for</span> line <span class="code1">in</span> f:
line = line.rstrip(<span class="code3">"\n"</span>)
valid = <span class="code1">True</span>
lineCount = Counter(line)
<span class="code1">for</span> x <span class="code1">in</span> lineCount:
<span class="code1">if</span> (x <span class="code1">in</span> letters):
<span class="code1">if</span> (letters[x] >= lineCount[x]):
<span class="code1">pass</span>
<span class="code1">else</span>:
valid = <span class="code1">False</span>
<span class="code1">else</span>:
valid = <span class="code1">False</span>
<span class="code1">if</span> (valid):
wordList.append(line)
<span class="code4">#print(lineCount)</span>
<span class="code4">#print(letters)</span>
<span class="code4">#print(wordList)</span>
<span class="code1">for</span> i <span class="code1">in</span> <span class="code2">range</span> (0, <span class="code2">len</span>(wordList) - 1):
<span class="code1">for</span> j <span class="code1">in</span> <span class="code2">range</span> (0, <span class="code2">len</span>(wordList) - i - 1):
#print (wordList[j] + " " + wordList[j + 1])
if (len(wordList[j]) < len(wordList[j + 1])):
temp = wordList[j]
wordList[j] = wordList[j + 1]
wordList[j + 1] = temp
<span class="code4">#print(wordList)</span>
<span class="code1">for</span> word <span class="code1">in</span> wordList:
<span class="code2">print</span> (<span class="code2">str</span>(<span class="code2">len</span>(word)) + <span class="code3">": "</span> + word)
</code></pre>
<hr>
<a id="links"></a>
<p style="text-align:center">
<a href="https://github.com/JosephRuff/Countdown-Letters" class="button icon brands fa-github">Source Code</a>
</p>
</section>
</div>
<!-- Copyright -->
<div id="copyright">
<ul><li>© Joseph Ruff</li><li>Design: <a href="https://html5up.net">HTML5 UP</a></li></ul>
</div>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>