Skip to content

Instantly share code, notes, and snippets.

@JesterXL
Created December 8, 2020 00:12
Show Gist options
  • Save JesterXL/7b85e96d4ada7c65b0bd4a274a9d1928 to your computer and use it in GitHub Desktop.
Save JesterXL/7b85e96d4ada7c65b0bd4a274a9d1928 to your computer and use it in GitHub Desktop.
local module = {}
function module.puzzleInput()
return [[light red bags contain 1 bright white bag, 2 muted yellow bags.
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
bright white bags contain 1 shiny gold bag.
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
faded blue bags contain no other bags.
dotted black bags contain no other bags.]]
end
return module
local function split(string, match)
local list = {}
for i in string.gmatch(string, match) do
table.insert(list, i)
end
return list
end
local function splitOnNewLines(string)
return split(string, "([^\n]*)\n?")
end
local function splitOnContains(string)
return split(string, '[^ contain ]*')
end
local input = require('./input')
local string = input.puzzleInput()
local bags = splitOnNewLines(string)
print(splitOnContains(bags[1])[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment