diff options
author | Aki <please@ignore.pl> | 2024-11-02 13:41:36 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-11-02 13:41:36 +0100 |
commit | 0b0e02875dbc4d7d795cafe6e5720aa66b32e1ac (patch) | |
tree | e42c905d5d1ddde4c1bb1cf58fbf7d697c17616e | |
parent | 1a2c8b663ed89b4d4a75463e28260a7c4955ecb1 (diff) | |
download | noita-eyes-0b0e02875dbc4d7d795cafe6e5720aa66b32e1ac.zip noita-eyes-0b0e02875dbc4d7d795cafe6e5720aa66b32e1ac.tar.gz noita-eyes-0b0e02875dbc4d7d795cafe6e5720aa66b32e1ac.tar.bz2 |
Naive approach to disk-based masking directly on the trigrams
-rwxr-xr-x | ascii+32.lua | 6 | ||||
-rwxr-xr-x | decimal.lua | 8 | ||||
-rwxr-xr-x | disk-simple-mask.lua | 27 | ||||
-rw-r--r-- | disk/init.lua | 12 | ||||
-rw-r--r-- | format.lua | 22 | ||||
-rw-r--r-- | reading.lua | 21 |
6 files changed, 83 insertions, 13 deletions
diff --git a/ascii+32.lua b/ascii+32.lua index c16eb6f..cc4ce97 100755 --- a/ascii+32.lua +++ b/ascii+32.lua @@ -1,9 +1,7 @@ #!/usr/bin/env lua local eyes = require "eyes" +local format = require "format" local reading = require "reading" for _, message in ipairs(eyes) do - for _, value in reading.values(message) do - io.write(string.char(value + 32)) - end - print() + print(format.ascii32(reading.tvalues(message))) end diff --git a/decimal.lua b/decimal.lua index 6f32e5d..df6975e 100755 --- a/decimal.lua +++ b/decimal.lua @@ -1,11 +1,7 @@ #!/usr/bin/env lua local eyes = require "eyes" +local format = require "format" local reading = require "reading" for _, message in ipairs(eyes) do - local start, value = reading.next_value(message) - io.write(value) - for _, value in reading.values(message, start) do - io.write(",", value) - end - print() + print(format.csv(reading.tvalues(message))) end diff --git a/disk-simple-mask.lua b/disk-simple-mask.lua new file mode 100755 index 0000000..ba41f7b --- /dev/null +++ b/disk-simple-mask.lua @@ -0,0 +1,27 @@ +#!/usr/bin/env lua +local disk = require "disk" +local eyes = require "eyes" +local format = require "format" +local reading = require "reading" + + +local function mask (ring, index, value) + local offset = (index - 1) % #ring + if ring[offset + 1] == 0 then + return value + else + return 0 + end +end + + +for _, message in ipairs(eyes) do + local values = {} + for index, a, b, c in reading.trigrams(message) do + a = mask(disk.eyes1, index, a) + b = mask(disk.eyes2, index, b) + c = mask(disk.eyes3, index, c) + table.insert(values, reading.trigram_to_value(a, b, c)) + end + print(format.ascii32(values)) +end diff --git a/disk/init.lua b/disk/init.lua new file mode 100644 index 0000000..056e6df --- /dev/null +++ b/disk/init.lua @@ -0,0 +1,12 @@ +return { + require "disk.runes1", + require "disk.eyes1", + require "disk.eyes2", + require "disk.eyes3", + require "disk.runes2", + runes1 = require "disk.runes1", + eyes1 = require "disk.eyes1", + eyes2 = require "disk.eyes2", + eyes3 = require "disk.eyes3", + runes2 = require "disk.runes2", +} diff --git a/format.lua b/format.lua new file mode 100644 index 0000000..3a126a9 --- /dev/null +++ b/format.lua @@ -0,0 +1,22 @@ +local format = {} + + +function format.csv (tvalues) + local str = string.format("%d", tvalues[1]) + for i=2, #tvalues do + str = str .. string.format(",%d", tvalues[i]) + end + return str +end + + +function format.ascii32 (tvalues) + local str = "" + for _, value in ipairs(tvalues) do + str = str .. string.char(32 + value) + end + return str +end + + +return format diff --git a/reading.lua b/reading.lua index 2b74446..6c910e2 100644 --- a/reading.lua +++ b/reading.lua @@ -1,3 +1,8 @@ +local function trigram_to_value (a, b, c) + return a * 25 + b * 5 + c +end + + local function next_trigram (message, index) index = (index or 0) + 1 local offset = (index - 1) * 3 @@ -15,23 +20,33 @@ local function next_value (message, index) if not index then return nil end - return index, a * 25 + b * 5 + c + return index, trigram_to_value(a, b, c) end local reading = { + trigram_to_value = trigram_to_value, next_trigram = next_trigram, next_value = next_value, } function reading.trigrams (message, start) - return next_trigram, message, start + return next_trigram, message, start or 0 end function reading.values (message, start) - return next_value, message, start + return next_value, message, start or 0 +end + + +function reading.tvalues (message) + local values = {} + for _, value in reading.values(message) do + table.insert(values, value) + end + return values end |