X-Git-Url: https://jasonwoof.com/gitweb/?p=hexbog.git;a=blobdiff_plain;f=freq.coffee;fp=freq.coffee;h=bf4e497f0d0b49881276e9f58f83777ea65cc5c3;hp=0000000000000000000000000000000000000000;hb=c0823d94d3ddcfd3006b931ebf2e9c1116553b1b;hpb=c5ea138fb8cfce9977ce486c9fbceedebe8af2c4 diff --git a/freq.coffee b/freq.coffee new file mode 100644 index 0000000..bf4e497 --- /dev/null +++ b/freq.coffee @@ -0,0 +1,65 @@ +#!/usr/bin/coffee + +# this script tries to calculate an optimal letter distrobution. + +fs = require 'fs' + + +fs.readFile 'wordlist.txt', 'utf8', (err, data) -> + if err? + console.log "Error reading #{orig_file}: #{err}" + process.exit(1) + else + weights = { + a: 0 + b: 0 + c: 0 + d: 0 + e: 0 + f: 0 + g: 0 + h: 0 + i: 0 + j: 0 + k: 0 + l: 0 + m: 0 + n: 0 + o: 0 + p: 0 + q: 0 + r: 0 + s: 0 + t: 0 + u: 0 + v: 0 + w: 0 + x: 0 + y: 0 + z: 0 + qu: 0 + } + words = data.split '\n' + for word in words + weight = 1.0 * Math.pow .6, (Math.abs(word.length - 4)) + i = 0 + while i < word.length + if word[i] is 'q' and i < word.length and word[i+1] is 'u' + weights['qu'] += weight + i += 2 + else + #if word[i] is 'u' and i > 0 and word[i-1] is 'q' + # console.log "skipping the u of a qu didn't work" + weights[word[i]] += weight + i += 1 + + total = 0 + for letter, weight of weights + total += Math.round(weight) + + for letter, weight of weights + weight = Math.round(weight) + #console.log "#{letter}: #{Math.round(weight / total * 1000)} (1 in #{Math.round(total / weight)})" + console.log "#{weight} # #{letter}" + + console.log "total: #{total}"