1 #project gem
2
3 #import general
4
5 //Gematria batch search program
6 // takes line separated list of words or phrases as input & checks each one for matches
7
8
9 //letters
10 //abcdefghijklmnopqrstuvwxyz
11 //ABCDEFGHIJKLMNOPQRSTUVWXYZ
12
13 pyth : [26]int : { :int:
14 1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8
15 };
16 chal : [26]int : { :int:
17 1,2,3,4,5,8,3,5,1,1,2,3,4,5,7,8,1,2,3,4,6,6,6,5,1,7
18 };
19 //pyth unreduced is just the letter # of the alphabet, can just use ascii character encoding offset to get this
20
21
22 //gematria calculation storage
23 Gem :: struct
24 {
25 input : string;
26 pyth : int = 0;
27 pyth_unreduced : int = 0;
28 chal : int = 0;
29
30 //has a result 'x' in one of the gematrias
31 has_result :: (x : int) -> bool
32 {
33 if pyth == x || pyth_unreduced == x || chal == x
34 return true;
35 return false;
36 }
37
38 sprint :: (out : *ostring)
39 {
40 out.sprint_pad(input, 16);
41 out.sprint(" [pyth ");
42 out.sprint_lpad(pyth, 3);
43 out.sprint(", pyth-unreduced ");
44 out.sprint_lpad(pyth_unreduced, 3);
45 out.sprint(", chal ");
46 out.sprint_lpad(chal, 3);
47 out.sprint("]\r\n");
48 }
49 };
50
51
52 //calculate gematria for 'input' word/phrase
53 gem_calc :: (input : string) -> Gem
54 {
55 g : Gem;
56 g.input = input;
57 g.pyth = 0;
58 g.pyth_unreduced = 0;
59 g.chal = 0;
60
61 for i : input.size
62 {
63 c : char; c = input[i];
64
65 if (c >= 65 && c <= 90) //uppercase letter ('A' is ascii #65)
66 {
67 g.pyth += pyth[c-65];
68 g.pyth_unreduced += c-65+1;
69 g.chal += chal[c-65];
70 }
71 else if (c >= 97 && c <= 122) //lowercase letter ('a' is ascii #97)
72 {
73 g.pyth += pyth[c-97];
74 g.pyth_unreduced += c-97+1;
75 g.chal += chal[c-97];
76 }
77 }
78
79 return g;
80 }
81
82
83 //inputs
84 filedata : ostring;
85 input_strings : [..]string;
86
87 //output sections
88 gem_pyth_chal : [..]Gem;
89 gem_pyth_upyth : [..]Gem;
90 gem_upyth_chal : [..]Gem;
91 gem_only_pyth : [..]Gem;
92 gem_only_upyth : [..]Gem;
93 gem_only_chal : [..]Gem;
94 count_match : uint;
95 count_pyth : uint;
96 count_upyth : uint;
97 count_chal : uint;
98 out : ostring; //output file data
99 outfilename : ostring; //output file name
100
101
102 //batch search list of words to find specific gematria number
103 gem_batch_search_number :: (filename : string, result_find : int)
104 {
105 //load data from input file
106 static.read_file(filedata, filename);
107
108 //split data into input_strings array (newline separated strings)
109 string_split_newline(filedata.get_string(), input_strings);
110
111 //print status
112 print(cc_reset); //reset existing terminal formatting
113 print("Gematria batch search for number ", result_find, "\n");
114 print(" Checking ", input_strings.size, " words from file ", filename, " of size ", filedata.size, "\n");
115
116
117 //get result from each input string
118 for s : input_strings
119 {
120 g : Gem;
121 g = gem_calc(s);
122
123 if g.has_result(result_find)
124 {
125 //sorted list
126 if g.pyth == result_find && g.chal == result_find
127 {
128 gem_pyth_chal.add(g);
129 }
130 else if g.pyth == result_find && g.pyth_unreduced == result_find
131 {
132 gem_pyth_upyth.add(g);
133 }
134 else if g.pyth_unreduced == result_find && g.chal == result_find
135 {
136 gem_upyth_chal.add(g);
137 }
138 else if g.pyth == result_find
139 {
140 gem_only_pyth.add(g);
141 }
142 else if g.pyth_unreduced == result_find
143 {
144 gem_only_upyth.add(g);
145 }
146 else if g.chal == result_find
147 {
148 gem_only_chal.add(g);
149 }
150
151 //count
152 count_match++;
153 if g.pyth == result_find
154 {
155 count_pyth++;
156 }
157 if g.pyth_unreduced == result_find
158 {
159 count_upyth++;
160 }
161 if g.chal == result_find
162 {
163 count_chal++;
164 }
165 }
166
167 }
168
169 print("\nFinished - found ", count_match, " matches\n");
170
171
172 //--- Generate file output ---
173 out.sprint("Gematria batch search for number ");
174 out.sprint(result_find);
175
176 out.sprint("\r\n");
177 out.sprint(" Found ");
178 out.sprint(count_match);
179 out.sprint(" matches from ");
180 out.sprint(input_strings.size);
181 out.sprint(" words.");
182
183 out.sprint("\r\n");
184 out.sprint(" Totals: pythagorean ");
185 out.sprint(count_pyth);
186 out.sprint(", unreduced pythagorean ");
187 out.sprint(count_upyth);
188 out.sprint(", chaldean ");
189 out.sprint(count_chal);
190
191 //multiple matches
192 section_header_sprint(out, "pythagorean and chaldean", gem_pyth_chal.size);
193 for g : gem_pyth_chal
194 {
195 g.sprint(out);
196 }
197
198 section_header_sprint(out, "pythagorean and unreduced pythagorean", gem_pyth_upyth.size);
199 for g : gem_pyth_upyth
200 {
201 g.sprint(out);
202 }
203
204 //doesn't seem to happen so added conditional
205 if gem_upyth_chal.size > 0
206 {
207 section_header_sprint(out, "unreduced pythagorean and chaldean", gem_upyth_chal.size);
208 for g : gem_upyth_chal
209 {
210 g.sprint(out);
211 }
212 }
213
214 //only 1 match
215 section_header_sprint(out, "only pythagorean", gem_only_pyth.size);
216 for g : gem_only_pyth
217 {
218 g.sprint(out);
219 }
220
221 section_header_sprint(out, "only unreduced pythagorean", gem_only_upyth.size);
222 for g : gem_only_upyth
223 {
224 g.sprint(out);
225 }
226
227 section_header_sprint(out, "only chaldean: ", gem_only_chal.size);
228 for g : gem_only_chal
229 {
230 g.sprint(out);
231 }
232
233
234
235 //--- save file to disk ---
236 outfilename.set("gematria batch search for ");
237 outfilename.sprint(result_find);
238 outfilename.sprint(".txt");
239 print("\nSaving output to ", outfilename, " (", out.size, "b)\n");
240
241 //write file to disk
242 write_file(out.get_string(), outfilename.get_string());
243 }
244
245 //output section header text for given title & # of matches
246 section_header_sprint :: (out : *ostring, title : string, size : uint)
247 {
248 //4 newlines
249 out.sprint("\r\n\r\n\r\n\r\n--- ");
250 out.sprint(title);
251 out.sprint(": ");
252 out.sprint(size);
253 out.sprint(" ---\r\n");
254 }
255
256 //standalone exe entry point
257 main :: () -> int
258 {
259 //initial memory allocations
260 out.alloc(1024*64);
261 outfilename.alloc(1024);
262
263 gem_batch_search_number("words_alpha.txt", 33);
264 return 0;
265 }
266