From 1a2c8b663ed89b4d4a75463e28260a7c4955ecb1 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Nov 2024 03:27:03 +0100 Subject: Cleaned up and added common reading scripts --- ascii+32.lua | 9 +++++++++ decimal.lua | 11 +++++++++++ eyes/init.lua | 22 ++++++++++++++++++++++ reading.lua | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100755 ascii+32.lua create mode 100755 decimal.lua create mode 100644 eyes/init.lua create mode 100644 reading.lua diff --git a/ascii+32.lua b/ascii+32.lua new file mode 100755 index 0000000..c16eb6f --- /dev/null +++ b/ascii+32.lua @@ -0,0 +1,9 @@ +#!/usr/bin/env lua +local eyes = require "eyes" +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() +end diff --git a/decimal.lua b/decimal.lua new file mode 100755 index 0000000..6f32e5d --- /dev/null +++ b/decimal.lua @@ -0,0 +1,11 @@ +#!/usr/bin/env lua +local eyes = require "eyes" +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() +end diff --git a/eyes/init.lua b/eyes/init.lua new file mode 100644 index 0000000..de63d08 --- /dev/null +++ b/eyes/init.lua @@ -0,0 +1,22 @@ +return { + require "eyes.east1", + require "eyes.east2", + require "eyes.east3", + require "eyes.east4", + require "eyes.east5", + require "eyes.west1", + require "eyes.west2", + require "eyes.west3", + require "eyes.west4", + east1 = require "eyes.east1", + east2 = require "eyes.east2", + east3 = require "eyes.east3", + east4 = require "eyes.east4", + east5 = require "eyes.east5", + west1 = require "eyes.west1", + west2 = require "eyes.west2", + west3 = require "eyes.west3", + west4 = require "eyes.west4", + permutations = require "eyes.permutations", + random = require "eyes.random", +} diff --git a/reading.lua b/reading.lua new file mode 100644 index 0000000..2b74446 --- /dev/null +++ b/reading.lua @@ -0,0 +1,38 @@ +local function next_trigram (message, index) + index = (index or 0) + 1 + local offset = (index - 1) * 3 + local a = message[offset + 1] + if not a then + return nil + end + return index, a, message[offset + 2], message[offset + 3] +end + + +local function next_value (message, index) + local a, b, c + index, a, b, c = next_trigram(message, index) + if not index then + return nil + end + return index, a * 25 + b * 5 + c +end + + +local reading = { + next_trigram = next_trigram, + next_value = next_value, +} + + +function reading.trigrams (message, start) + return next_trigram, message, start +end + + +function reading.values (message, start) + return next_value, message, start +end + + +return reading -- cgit v1.1