JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
tweak tile: shadows, corners and hp0 color
[hexbog.git] / freq.coffee
1 #!/usr/bin/coffee
2
3 # this script tries to calculate an optimal letter distrobution.
4
5 fs = require 'fs'
6
7
8 fs.readFile 'wordlist.txt', 'utf8', (err, data) ->
9         if err?
10                 console.log "Error reading #{orig_file}: #{err}"
11                 process.exit(1)
12         else
13                 weights = {
14                         a: 0
15                         b: 0
16                         c: 0
17                         d: 0
18                         e: 0
19                         f: 0
20                         g: 0
21                         h: 0
22                         i: 0
23                         j: 0
24                         k: 0
25                         l: 0
26                         m: 0
27                         n: 0
28                         o: 0
29                         p: 0
30                         q: 0
31                         r: 0
32                         s: 0
33                         t: 0
34                         u: 0
35                         v: 0
36                         w: 0
37                         x: 0
38                         y: 0
39                         z: 0
40                         qu: 0
41                 }
42                 words = data.split '\n'
43                 for word in words
44                         weight = 1.0 * Math.pow .6, (Math.abs(word.length - 4))
45                         i = 0
46                         while i < word.length
47                                 if word[i] is 'q' and i < word.length and word[i+1] is 'u'
48                                         weights['qu'] += weight
49                                         i += 2
50                                 else
51                                         #if word[i] is 'u' and i > 0 and word[i-1] is 'q'
52                                         #       console.log "skipping the u of a qu didn't work"
53                                         weights[word[i]] += weight
54                                         i += 1
55
56                 total = 0
57                 for letter, weight of weights
58                         total += Math.round(weight)
59
60                 for letter, weight of weights
61                         weight = Math.round(weight)
62                         #console.log "#{letter}: #{Math.round(weight / total * 1000)} (1 in #{Math.round(total / weight)})"
63                         console.log "#{weight} # #{letter}"
64
65                 console.log "total: #{total}"