attempting day 12, part 2 XD
This commit is contained in:
parent
6e571734f2
commit
029b023901
|
@ -32,7 +32,6 @@ function count_arrangements(s_damaged, groups)
|
|||
local groups_copy = {}
|
||||
table.move(groups, 1, #groups, 1, groups_copy)
|
||||
local g = table.remove(groups_copy,1)
|
||||
--print("group",g,#groups_copy)
|
||||
local count = 0
|
||||
local len = #s_damaged
|
||||
if #groups_copy==0 then --last element
|
||||
|
@ -40,8 +39,6 @@ function count_arrangements(s_damaged, groups)
|
|||
local prop = gen_proposed(len, g, i)
|
||||
local is_valid = is_valid_arrangement(s_damaged, prop)
|
||||
if is_valid then count = count + 1 end
|
||||
--print("VALID! internal count", count)
|
||||
--print(i,s_damaged, prop,is_valid)
|
||||
end
|
||||
else -- uy uy uy
|
||||
local n_remaining = #groups_copy
|
||||
|
@ -64,33 +61,34 @@ function count_arrangements(s_damaged, groups)
|
|||
return count
|
||||
end
|
||||
|
||||
x = is_valid_arrangement(".??..??...?##.","#....#....###." )
|
||||
print(x)
|
||||
|
||||
--[[
|
||||
print(gen_proposed(4,2,1))
|
||||
print(gen_proposed(4,2,2))
|
||||
print(gen_proposed(4,2,3))
|
||||
--]]
|
||||
|
||||
|
||||
--print( count_arrangements(".??..??...?##.", {1,1,3}))
|
||||
--print( count_arrangements("?#?#?#?#?#?#?#?", {1,3,1,6}))
|
||||
print( count_arrangements("?###????????", {3,2,1}))
|
||||
|
||||
|
||||
n = 1
|
||||
sum1 = 0
|
||||
sum2 = 0
|
||||
for line in io.lines() do
|
||||
--print(line)
|
||||
print("line",n)
|
||||
n = n + 1
|
||||
map, records_list = line:match("([%#%.%?]+) ([%d%,]+)$")
|
||||
records = {}
|
||||
for r in records_list:gmatch("(%d+)") do
|
||||
table.insert(records, tonumber(r))
|
||||
end
|
||||
local count = count_arrangements(map, records)
|
||||
print(count)
|
||||
|
||||
sum1 = sum1 + count
|
||||
|
||||
-- part 2
|
||||
local newmap = map
|
||||
local newrecords = {}
|
||||
table.move(records,1,#records,1,newrecords)
|
||||
for i=1,4 do
|
||||
newmap = newmap .."?"..map
|
||||
table.move(records,1,#records,1 + #records*i,newrecords)
|
||||
end
|
||||
print(newmap)
|
||||
local count2 = count_arrangements(newmap, newrecords)
|
||||
sum2 = sum2 + count2
|
||||
print(count2)
|
||||
end
|
||||
|
||||
print("part 1", sum1)
|
||||
print("part 2", sum2)
|
||||
|
|
Loading…
Reference in New Issue