summaryrefslogtreecommitdiff
path: root/ioc.lua
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-11-02 15:19:02 +0100
committerAki <please@ignore.pl>2024-11-02 15:19:02 +0100
commit1abde5fcd3fde372cdefdc6c967d680a2cc82410 (patch)
tree475c2cb83272e1b22eb2b04edf9b5b59d3e6c181 /ioc.lua
parent690f62d324531d2a81789dc98784ce7bdb7a02b3 (diff)
downloadnoita-eyes-1abde5fcd3fde372cdefdc6c967d680a2cc82410.zip
noita-eyes-1abde5fcd3fde372cdefdc6c967d680a2cc82410.tar.gz
noita-eyes-1abde5fcd3fde372cdefdc6c967d680a2cc82410.tar.bz2
Cleaned up and added Index of Coincidence calculator script
Diffstat (limited to 'ioc.lua')
-rwxr-xr-xioc.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/ioc.lua b/ioc.lua
new file mode 100755
index 0000000..51c99e2
--- /dev/null
+++ b/ioc.lua
@@ -0,0 +1,62 @@
+#!/usr/bin/env lua
+local eyes = require "eyes"
+local reading = require "reading"
+
+
+local function fmt (float)
+ return string.format("%.5f", float)
+end
+
+
+local function stats (name, parent)
+ return {
+ name=name,
+ parent=parent,
+ letters=0,
+ length=0,
+ counts={},
+
+ add = function (self, value)
+ local current = self.counts[value] or 0
+ if current == 0 then
+ self.letters = self.letters + 1
+ end
+ self.length = self.length + 1
+ self.counts[value] = current + 1
+ end,
+
+ ioc = function (self, letters)
+ letters = letters or self.letters
+ local subtotal = 0
+ for _, count in pairs(self.counts) do
+ subtotal = subtotal + count * (count - 1)
+ end
+ return subtotal / (self.length * (self.length - 1) / letters)
+ end,
+
+ dump = function (self)
+ local letters = (self.parent or {}).letters
+ io.write(name, "\t", self.length, "\t", self.letters, "\t", fmt(self:ioc(letters)))
+ if letters then
+ io.write("\t", fmt(self:ioc()))
+ end
+ print()
+ end
+ }
+end
+
+
+local global = stats"global"
+local lokals = {}
+for index, message in ipairs(eyes) do
+ local lokal = stats("#"..index, global)
+ for _, value in reading.values(message) do
+ global:add(value)
+ lokal:add(value)
+ end
+ table.insert(lokals, lokal) -- Global is incomplete, can't dump yet.
+end
+global:dump()
+for _, lokal in ipairs(lokals) do
+ lokal:dump()
+end