Day 4 visualization

This commit is contained in:
Simon Cambier 2023-12-04 20:14:28 +01:00
parent f889ccffc0
commit e8f4923de1

32
day4.p8
View File

@ -2,7 +2,8 @@ pico-8 cartridge // http://www.pico-8.com
version 41 version 41
__lua__ __lua__
local input = split([[Card 1: 47 10 77 75 94 50 93 43 27 18|73 75 32 65 98 76 71 13 50 78 54 94 18 83 77 6 79 93 45 27 87 57 51 55 43 local input = split(
[[Card 1: 47 10 77 75 94 50 93 43 27 18|73 75 32 65 98 76 71 13 50 78 54 94 18 83 77 6 79 93 45 27 87 57 51 55 43
Card 2: 17 9 7 91 32 97 76 39 83 88|88 25 46 50 91 18 39 76 17 22 28 82 44 66 52 7 11 56 77 9 40 83 97 32 47 Card 2: 17 9 7 91 32 97 76 39 83 88|88 25 46 50 91 18 39 76 17 22 28 82 44 66 52 7 11 56 77 9 40 83 97 32 47
Card 3: 32 2 10 96 30 37 60 86 88 50|64 96 58 41 24 37 86 84 80 49 30 53 83 50 42 33 2 52 88 46 19 89 32 51 5 Card 3: 32 2 10 96 30 37 60 86 88 50|64 96 58 41 24 37 86 84 80 49 30 53 83 50 42 33 2 52 88 46 19 89 32 51 5
Card 4: 62 21 85 90 64 44 29 2 86 84|98 21 82 55 62 14 3 33 7 90 85 57 94 44 64 5 43 91 96 67 84 78 69 81 29 Card 4: 62 21 85 90 64 44 29 2 86 84|98 21 82 55 62 14 3 33 7 90 85 57 94 44 64 5 43 91 96 67 84 78 69 81 29
@ -199,7 +200,8 @@ Card 194: 86 2 31 64 69 39 24 61 59 37|46 85 40 90 73 92 8 71 24 97 35 70 19 57
Card 195: 82 32 90 59 51 6 27 24 36 98|74 79 95 91 14 87 39 57 1 20 37 93 68 4 54 66 86 35 36 28 38 49 65 98 67 Card 195: 82 32 90 59 51 6 27 24 36 98|74 79 95 91 14 87 39 57 1 20 37 93 68 4 54 66 86 35 36 28 38 49 65 98 67
Card 196: 54 71 23 38 79 55 78 67 44 10|71 17 85 93 55 72 68 14 8 11 75 86 52 41 47 61 29 53 3 59 30 21 76 92 32 Card 196: 54 71 23 38 79 55 78 67 44 10|71 17 85 93 55 72 68 14 8 11 75 86 52 41 47 61 29 53 3 59 30 21 76 92 32
Card 197: 7 65 66 60 52 23 15 27 32 3|59 4 79 97 91 41 83 36 22 89 19 38 96 81 8 29 49 86 46 12 25 6 24 16 78 Card 197: 7 65 66 60 52 23 15 27 32 3|59 4 79 97 91 41 83 36 22 89 19 38 96 81 8 29 49 86 46 12 25 6 24 16 78
Card 198: 89 99 29 80 68 39 38 10 2 63|88 8 92 81 23 54 1 12 45 96 67 86 37 98 47 34 71 4 58 3 27 41 75 93 66]], "\n") Card 198: 89 99 29 80 68 39 38 10 2 63|88 8 92 81 23 54 1 12 45 96 67 86 37 98 47 34 71 4 58 3 27 41 75 93 66]], "\n"
)
printh("") printh("")
printh("Advent of Code 2013 - Day 4") printh("Advent of Code 2013 - Day 4")
@ -233,9 +235,10 @@ for i = 1, #input do
copies[i] = "1" copies[i] = "1"
end end
for i, line in ipairs(input) do local iter = cocreate(function()
for i, lne in ipairs(input) do
printh("Card " .. i .. " - " .. copies[i] .. " copies") printh("Card " .. i .. " - " .. copies[i] .. " copies")
local numbers = split(line, ":")[2] local numbers = split(lne, ":")[2]
local winning = split(split(numbers, "|")[1], " ") local winning = split(split(numbers, "|")[1], " ")
local mine = split(split(numbers, "|")[2], " ") local mine = split(split(numbers, "|")[2], " ")
@ -243,7 +246,14 @@ for i, line in ipairs(input) do
for j, v in ipairs(mine) do for j, v in ipairs(mine) do
if contains(winning, v) then if contains(winning, v) then
count = count + 1 count = count + 1
-- yay exponential growth
copies[i + count] = strdsum(copies[i + count], tostr(copies[i])) copies[i + count] = strdsum(copies[i + count], tostr(copies[i]))
-- lne(1, 0, 1, 10, 7)
-- pset(i, count, 7)
-- print(count)
-- circ(i%128, count*10, 1, 7)
line(i % 128, 0, i % 128, count * 10 + 10, 11)
yield()
end end
end end
printh(" " .. count .. " winning cards") printh(" " .. count .. " winning cards")
@ -264,6 +274,20 @@ for i = 1, #copies do
part2 = strdsum(part2, tostr(copies[i])) part2 = strdsum(part2, tostr(copies[i]))
end end
printh("Part 2 " .. part2) printh("Part 2 " .. part2)
end)
cls()
function _update()
coresume(iter)
for i = 1, 100 do
local x, y = rnd(128), rnd(128)
if pget(x, y) == 11 then
pset(x, y, 8)
elseif pget(x, y) == 8 then
pset(x, y, 0)
end
end
end
__gfx__ __gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000