-
Notifications
You must be signed in to change notification settings - Fork 0
/
num2words.html
318 lines (299 loc) · 8.38 KB
/
num2words.html
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html>
<head>
<title>RememberEasier -- Convert number to words for easier recalling</title>
<style type="text/css">
* {margin:0; padding:0}
h1 {font-size:large;color:#000f1a;font-weight:normal;margin-bottom:0.5em}
#icontainer {margin:0.5em 0.5em 0.5em 0.5em; text-align:center}
a:link {color:#339933}
a:visited {color:#339933}
a:hover {color:#00ff00}
a:active {color:#faeedd;background-color:#281700}
span.digit {font-weight:bold;color:#281700}
#partnersclosed, #partnersopen, #privacyclosed, #privacyopen, #helpclosed, #helpopen {margin-right:4px;margin-left:4px}
/*--------------------------------------------------------------
1.0 - BASE SITE STYLES
--------------------------------------------------------------*/
*,*:after,*:before {
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
.cf:before,
.cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
body {
background: #3aaae8;
color: #fff;
font:12px/18px 'HelveticaNeue', Helvetica, Arial, sans-serif;
}
a,a:visited {
color:#fff
}
/*--------------------------------------------------------------
2.0 - SEARCH FORM
--------------------------------------------------------------*/
.searchform {
background:#f4f4f4;
background:rgba(244,244,244,.79);
border: 1px solid #d3d3d3;
left: 40%;
padding: 2px 5px;
position: absolute;
margin: -22px 0 0 -170px;
top: 50%;
width:600px;
box-shadow:0 4px 9px rgba(0,0,0,.37);
-moz-box-shadow:0 4px 9px rgba(0,0,0,.37);
-webkit-box-shadow:0 4px 9px rgba(0,0,0,.37);
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px
}
.searchform input, .searchform button {
float: left
}
.searchform input {
background:#fefefe;
border: none;
font:12px/12px 'HelveticaNeue', Helvetica, Arial, sans-serif;
margin-right: 5px;
padding: 10px;
width: 216px;
box-shadow: 0 0 4px rgba(0,0,0,.4) inset, 1px 1px 1px rgba(255,255,255,.75);
-moz-box-shadow: 0 0 4px rgba(0,0,0,.4) inset, 1px 1px 1px rgba(255,255,255,.75);
-webkit-box-shadow: 0 0 4px rgba(0,0,0,.4) inset, 1px 1px 1px rgba(255,255,255,.75);
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px
}
.searchform input:focus {
outline: none;
box-shadow:0 0 4px #0d76be inset;
-moz-box-shadow:0 0 4px #0d76be inset;
-webkit-box-shadow:0 0 4px #0d76be inset;
}
.searchform input::-webkit-input-placeholder {
font-style: italic;
line-height: 15px
}
.searchform input:-moz-placeholder {
font-style: italic;
line-height: 15px
}
.searchform button {
background: rgb(52,173,236);
background: -moz-linear-gradient(top, rgba(52,173,236,1) 0%, rgba(38,145,220,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(52,173,236,1)), color-stop(100%,rgba(38,145,220,1)));
background: -webkit-linear-gradient(top, rgba(52,173,236,1) 0%,rgba(38,145,220,1) 100%);
background: -o-linear-gradient(top, rgba(52,173,236,1) 0%,rgba(38,145,220,1) 100%);
background: -ms-linear-gradient(top, rgba(52,173,236,1) 0%,rgba(38,145,220,1) 100%);
background: linear-gradient(to bottom, rgba(52,173,236,1) 0%,rgba(38,145,220,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#34adec', endColorstr='#2691dc',GradientType=0 );
border: none;
color:#fff;
cursor: pointer;
font: 13px/13px 'HelveticaNeue', Helvetica, Arial, sans-serif;
padding: 10px;
width:106px;
box-shadow: 0 0 2px #2692dd inset;
-moz-box-shadow: 0 0 2px #2692dd inset;
-webkit-box-shadow: 0 0 2px #2692dd inset;
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
}
.searchform button:hover {
opacity:.9;
}
</style>
</head>
<body>
<div id="icontainer">
<!-- content goes here -->
<h1 style="margin-top: 100px">Remember a number easier!</h1>
<form class="searchform cf" >
<input type="text" id = "frml" placeholder="What's your number?">
<button type="submit" onclick="myFunction()">Convert</button>
<input type="text" id = "output" placeholder="This is output">
</form>
</div>
<div style="left: 10%;position: absolute">
<p style="font-size: 14px">In this program we intepret numbers as follows:
<ul>
<li>0-z</li>
<li>1-l</li>
<li>2-n</li>
<li>3-m</li>
<li>4-r</li>
<li>5-s</li>
<li>6-g</li>
<li>7-t</li>
<li>8-f</li>
<li>9-q</li>
</ul>
</p>
</div>
<p style="margin-top: 480px">RememberEasier -- a project that helps remember numbers by <a href="https://github.com/AlanFermat">Zhe</a> </p>
<script type="text/javascript">
function setCharAt(str,index,chr) {
if(index > str.length-1) return str;
return str.substr(0,index) + chr + str.substr(index+1);
}
function test() {
var str = "a";
str = setCharAt(str, 0, "l");
alert(str);
}
function num_to_char(t){
// ENCODE
// 0-z
// 1-l
// 2-n
// 3-w
// 4-r
// 5-s
// 6-g
// 7-t
// 8-f
// 9-q
if (t == "0") {
var result = "z";
}if (t == "1") {
var result = "l";
}if (t == "2") {
var result = "n";
}if (t == "3") {
var result = "m";
}if (t == "4") {
var result = "r";
}if (t == "5") {
var result = "s";
}if (t == "6") {
var result = "b";
}if (t == "7") {
var result = "t";
}if (t == "8") {
var result = "f";
}if (t == "9") {
var result = "q";
}
return result;
}
function getIndicesOf(searchStr, str) {
var searchStrLen = searchStr.length;
if (searchStrLen == 0) {
return [];
}
var startIndex = 0, index, indices = [];
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
indices.push(index);
startIndex = index + searchStrLen;
}
return indices;
}
function convert(text){
// For the sake of convenience,
// here, we only consider 11 possible and most frequently
// used words which have three consonants, as follows,
// bll --- bill
// mmm --- mummy
// mrs --- Mrs.
// lmt --- limit
// smt --- Smith
// lsr --- loser
// fml --- family
// nll --- null
// bss --- boss
// mst --- most
// fst --- fast
var searchStr = ["bll","mmm","mrs","lmt","smt","lsr","fml","nll","bss","mst","fst"];
var size = 3;
var indices_dict = {};
for (var i = 0; i < searchStr.length; i++) {
var indices = getIndicesOf(searchStr[i],text);
if (indices.length > 0) {
indices_dict[searchStr[i]] = indices;
for (var k = 0; k < indices.length; k++) {
for (var j = 0; j < size ; j++) {
var t = indices[k] + j;
text = setCharAt(text, t, "o");
}
}
}
}
return [indices_dict, text];
}
function mappingWord(index, word_dict){
var store_word = {
"bll": " bill ",
"mmm": " mummy ",
"mrs": " Mrs ",
"lmt": " limit ",
"smt": " Smith ",
"lsr": " loser ",
"fml": " family ",
"nll": " null ",
"bss": " boss ",
"mst": " most ",
"fst": " fast "
};
var word_map = [];
for (var i = 0; i < index.length; i++) {
for(p in word_dict){
if (word_dict[p].indexOf(index[i]) > -1) {
word_map.push(store_word[p]);
}
}
}
return word_map;
}
function myFunction(){
var x = document.getElementById("frml").value;
var arr= [];
var seq = [];
var size = 3;
for (var j = 0;j < x.length;j++){
arr.push(x[j]);
}
var word = "";
for(var i = 0;i<arr.length;i++){
var result = num_to_char(arr[i]);
word += result;
}
var [word_dict, word] = convert(word);
// For the sake of checking everything is correct so far
// alert(word);
// for (i in word_dict){
// alert(i + " " + word_dict[i]);
// }
var index = [];
for (i in word_dict) {
for (var j = 0;j < word_dict[i].length; j ++) {
index.push(word_dict[i][j]);
}
}
index.sort();
var word_map = mappingWord(index, word_dict);
var start = 0;
for (var i =0;i<index.length; i++) {
var pos = start + index[i];
word = setCharAt(word, pos, word_map[i]);
start += word_map[i].length;
}
while(word.indexOf("o") != -1){
word = word.replace("o", "");
}
alert(word);
// Want to show my output in the following box
document.getElementById("output").innerHTML = x;
}
</script>
</body>
</html>