Skip to content

Instantly share code, notes, and snippets.

@hastern
Created December 2, 2016 21:24
Show Gist options
  • Save hastern/1d6dc31c6dab7214d743282021b8c8c9 to your computer and use it in GitHub Desktop.
Save hastern/1d6dc31c6dab7214d743282021b8c8c9 to your computer and use it in GitHub Desktop.
Advent of Code - Day 2 - Design to be used with Shenzhen IO
-- This is a custom design based on the Advent of Code Day 2
--
-- You can put your own input into the design by changing parts of
-- the code below.
-- Currently it is not possible to solve both parts at once.
function get_name()
return "AoC-Day 2-Bathroom Security"
end
function get_description()
return {
"You are tasked with the construction of a keypad breaking device.",
"The device will be used to bybass security locks in the Easterbunny HQ. The device receives the mnenonics for the code via radio and should transmit the resulting key back.",
"| Keypad",
"--------",
"| 1 2 3",
"| 4 5 6",
"| 7 8 9",
"<PAGE>",
"Movement will always start on key 5.",
"Moving outside the pad will do nothing.",
"Movement Table:",
"| # | Direction ",
"----------------",
"| 1 | Up ",
"| 2 | Right ",
"| 3 | Down ",
"| 4 | Left ",
"<PAGE>",
"Based on Advent of Code 2016 - Day 2",
"http://adventofcode.com/2016/day/2"
}
end
function get_board()
return [[
##################
R#################
##################
##################
##################
##################
##################
]]
end
function get_data()
inputs = {
--
-- Put your own input here
--
--
-- +--- The input lines
-- | +---- The resulting key for part 1
-- | | +---- The resulting key for part 2
-- | | |
-- v v v
{"ULL", 1, 5},
{"RRDDD", 9, 13},
{"LURDL", 8, 11},
{"UUUUD", 5, 3},
}
translation = {U=1, R=2, D=3, L=4} -- If you want other movement encoding, change this
direction = {}
key = {}
next_i = 1
for i = 1, 60 do
direction[i] = {}
key[i] = {}
end
for j = 1,#inputs do
local input = inputs[j][1]
local p = j * 5
key[p+1] = {inputs[j][2]} -- Use this line for solving part 1
-- key[p+1] = {inputs[j][3]} -- Use this line for solving part 2
for n = 1,#input do
local c = input:sub(n, n)
direction[p][n] = translation[c]
end
end
create_radio(direction, key)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment