Created
August 5, 2018 21:19
-
-
Save oprypin/e2050d6c4c5f61840e43bb32eadaf873 to your computer and use it in GitHub Desktop.
My SHENZHEN I/O puzzles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_name() | |
return "THE 99-HOLE" | |
end | |
function get_description() | |
return { | |
"*alice* is an XBus input connected to an electronic transmitter.", | |
"*bob* is an XBus output connected to an electronic receiver.", | |
"Receive packets of data from *alice* and send them to *bob*.", | |
"Numbers are between 1 and 26.", | |
} | |
end | |
function get_board() | |
return [[ | |
.................. | |
..#####...#####... | |
..####.....###2... | |
..######1######... | |
..0###.....####... | |
..#####...#####... | |
.................. | |
]] | |
end | |
MESSAGES = { | |
{"decentralized","autonomous","corporation","has"}, -- 4 5 | |
{"thorium","mining","operations","can","be","optimized"}, -- 20 8 | |
{"creating","a","device","with","certain","specifications"}, -- 3 18 | |
{"a","quick","brown","fox","jumps","over","the","lazy","dog"},-- 1 | |
{"maintain","the","system","and","expect","instructions"}, -- 13 1 | |
{"a","quick","brown","fox","jumps","over","the","lazy","dog"},-- 1 | |
{"lorem","ipsum","dolor","sit","amet","consectetur","elit"}, -- 12 15 | |
} | |
function get_data() | |
input = {} | |
noise = {} | |
output = {} | |
time = 1 | |
function send(packet) | |
input[time] = packet | |
output[time] = packet | |
time = time + #packet | |
end | |
message = MESSAGES[math.random(#MESSAGES + 1)] | |
if message then | |
for _, word in ipairs(message) do | |
packet = {} | |
for i = 1, #word do | |
packet[i] = string.byte(word, i) - 96 | |
end | |
send(packet) | |
end | |
else | |
repeat | |
packet = {} | |
repeat | |
packet[#packet + 1] = math.random(1, 26) | |
until math.random(0, 9 - #packet) == 0 | |
send(packet) | |
until time > 33 | |
end | |
for time = 1, 60 do | |
noise[time] = 99 | |
end | |
create_terminal("alice", "0", TYPE_XBUS, DIR_INPUT, input) | |
create_terminal("bob", "2", TYPE_XBUS, DIR_OUTPUT, output) | |
create_terminal("99", "1", TYPE_SIMPLE, DIR_INPUT, noise) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment