Last active
January 9, 2020 14:02
-
-
Save Lycea/074df04e4472695a78e46115b88c37eb to your computer and use it in GitHub Desktop.
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
--code advent first day_sample fuel from mass | |
--part1 function | |
function calc_fuel(mass) | |
return math.floor(mass/3)-2 | |
end | |
function calc_additional(fuel) | |
additional_ = 0 | |
next_ = fuel | |
while next_ >0 do | |
next_= math.floor(next_ /3) -2 | |
if next_> 0 then | |
additional_=additional_+next_ | |
end | |
end | |
return additional_ | |
end | |
local sample_data ={ | |
12, | |
14, | |
1969, | |
100756 | |
} | |
local real_data ={ | |
71343, | |
60747, | |
122054, | |
67364, | |
53017, | |
81716, | |
55910, | |
120565, | |
59809, | |
148941, | |
124539, | |
108258, | |
77377, | |
97572, | |
56164, | |
57858, | |
97899, | |
53786, | |
129974, | |
88645, | |
89330, | |
136628, | |
139228, | |
128560, | |
88358, | |
85431, | |
68350, | |
61458, | |
61833, | |
104279, | |
127850, | |
111139, | |
94752, | |
95037, | |
141723, | |
96355, | |
89433, | |
78355, | |
108635, | |
59567, | |
55589, | |
141992, | |
104238, | |
68291, | |
147546, | |
73476, | |
70991, | |
62313, | |
58672, | |
121783, | |
63158, | |
112817, | |
117776, | |
134302, | |
107446, | |
124540, | |
84279, | |
51193, | |
78829, | |
142544, | |
102528, | |
131341, | |
121502, | |
78165, | |
127783, | |
81012, | |
106876, | |
90403, | |
62091, | |
58090, | |
74824, | |
109657, | |
55042, | |
108119, | |
56850, | |
69635, | |
107792, | |
131462, | |
106842, | |
83864, | |
127170, | |
88563, | |
138150, | |
117904, | |
75996, | |
78850, | |
76719, | |
133639, | |
55213, | |
111209, | |
126243, | |
123495, | |
89420, | |
54618, | |
110194, | |
79674, | |
109834, | |
77521, | |
110024, | |
115217 | |
} | |
local sum = 0 | |
for idx,data in pairs(real_data) do | |
local calc_data = calc_fuel(data) | |
--print(data,calc_data) | |
sum = sum +calc_data | |
end | |
local sum_2 = 0 | |
for idx,data in pairs(real_data) do | |
local fuel_base =calc_fuel(data) | |
local fuel_additional = calc_additional(fuel_base) | |
print(data,fuel_base+fuel_additional) | |
sum_2=sum_2+ fuel_base+fuel_additional | |
end | |
print(sum_2) | |
--print(sum) |
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
local function computer_part1(input_) | |
local input = input_ | |
local idx = 1 | |
local code = input[1] | |
while code ~= 99 do | |
local first_pos = input[idx+1]+1 | |
local second_pos = input[idx+2]+1 | |
local save_pos = input[idx+3]+1 | |
--print(code,first_pos,second_pos,save_pos) | |
if code == 1 then | |
input[save_pos] = input[first_pos]+input[second_pos] | |
elseif code == 2 then | |
input[save_pos] = input[first_pos]*input[second_pos] | |
else | |
print("???") | |
break | |
end | |
--print( table.concat(input,",")) | |
idx=idx+4 | |
code = input[idx] | |
end | |
return input[1] | |
end | |
local test_input = { | |
--1,9,10,3,2,3,11,0,99,30,40,50 | |
1,1,1,4,99,5,6,0,99 | |
} | |
local function mysplit (inputstr, sep) | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} | |
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
table.insert(t, str*1) | |
end | |
return t | |
end | |
local function test () | |
local real_input ={ | |
1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,19,10,23,2,13,23,27,1,5,27,31,2,6,31,35,1,6,35,39,2,39,9,43,1,5,43,47,1,13,47,51,1,10,51,55,2,55,10,59,2,10,59,63,1,9,63,67,2,67,13,71,1,71,6,75,2,6,75,79,1,5,79,83,2,83,9,87,1,6,87,91,2,91,6,95,1,95,6,99,2,99,13,103,1,6,103,107,1,2,107,111,1,111,9,0,99,2,14,0,0 | |
} | |
for i=0,99 do | |
for j=0,99 do | |
print(i,j) | |
local input_ = mysplit(table.concat(real_input,","),",") | |
input_[2] = i | |
input_[3] = j | |
if computer_part1(input_)== 19690720 then | |
print("Found it!!!",i,j) | |
print(100*i+j) | |
os.exit() | |
end | |
end | |
end | |
end | |
test() |
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
local min = 372037 | |
local max = 905157 | |
function check_num(num_to_check) | |
local txt = tostring(num_to_check) | |
--has six digits | |
if #txt > 6 then | |
return false | |
end | |
--is in range ... | |
local function cut_string (str) | |
local tmp ={} | |
for i=0, #str do | |
tmp[i+1] =tonumber(string.sub(str,i+1,i+1)) | |
end | |
return tmp | |
end | |
local cut_txt = cut_string(txt) | |
local found_same = false | |
local decreases = false | |
local prev =9 | |
local num_wait = 0 | |
for idx=1,#cut_txt do --in ipairs(cut_txt) do | |
local num = cut_txt[idx] | |
--two neighbours are the same | |
if idx ~=1 and num_wait == 0 then | |
if prev == num and found_same == false then | |
--for part two find as many repeats as possible... | |
local mat = string.match(txt,num.."*",idx-1) | |
--print(mat,txt,idx-1) | |
if #mat >2 then | |
--idx = idx+ #mat-1 | |
--uncomment for solution part 2 | |
--num_wait= #mat -1 | |
else | |
found_same = true | |
end | |
end | |
if prev > num then | |
decreases = true | |
end | |
end | |
if num_wait >0 then num_wait = num_wait-1 end | |
prev = tonumber( num) | |
end | |
if found_same == true and decreases == false then | |
--never decreases | |
print("true",num_to_check) | |
return true | |
end | |
--print("false",num_to_check) | |
return false | |
end | |
count = 0 | |
for i=min,max do | |
if check_num(i) == true then | |
count = count+1 | |
end | |
end | |
print(count) |
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
local function parse_raw_code(code) | |
local code_id = 0 | |
local parameters = {} | |
local txt_code = tostring(code) | |
code_id = tonumber(string.sub(txt_code,#txt_code-1,#txt_code-1)..string.sub(txt_code,#txt_code,#txt_code)) | |
--print("Found code",code_id) | |
--print("Raw code",code) | |
local parameter_txt = string.reverse(string.sub(txt_code,1,#txt_code-2)) | |
if #txt_code < 3 then | |
return code_id , parameters | |
end | |
--print("Parameters,reversed",parameter_txt) | |
for param_idx=1,#parameter_txt do | |
parameters[param_idx] =string.sub(parameter_txt,param_idx,param_idx)+0 | |
end | |
return code_id , parameters | |
end | |
local function get_value(input,idx,mode) | |
if mode == 0 then | |
--print("Value",input[input[idx]+1]) | |
return input[input[idx]+1] | |
elseif mode == 1 then | |
--print("Value",input[idx]) | |
return input[idx] | |
else | |
print("Mode is not supported",mode) | |
end | |
end | |
local function computer_part1(input_) | |
local input = input_ | |
local idx = 1 | |
local raw_code = input[1] | |
local code,params = parse_raw_code(raw_code) | |
while code ~= 99 do | |
--local first_pos = input[idx+1]+1 | |
--local second_pos = input[idx+2]+1 | |
--print("-------------------") | |
--print("Actual index",idx) | |
local save_pos = input[idx+3]+1 | |
--print(code,first_pos,second_pos,save_pos) | |
--addition of two parameters | |
if code == 1 then | |
input[save_pos] = get_value(input, idx+1,params[1]or 0)+get_value(input, idx+2,params[2]or 0) | |
idx=idx+4 | |
--multiplication of two parameters | |
elseif code == 2 then | |
input[save_pos] = get_value(input, idx+1,params[1]or 0)*get_value(input, idx+2,params[2]or 0) | |
idx=idx+4 | |
--3 and 4 where added in part 5 of the challenges | |
--input of a parameter | |
elseif code == 3 then | |
save_pos = input[idx+1]+1 | |
print("Input needed:") | |
input[save_pos] = tonumber( io.read()) | |
idx=idx+2 | |
--output of a parameter | |
elseif code == 4 then | |
print(" Output",get_value(input,idx+1,params[1]or 0)) | |
idx=idx+2 | |
--jump if true : check if non zero and then move else not | |
elseif code == 5 then | |
if get_value(input,idx+1,params[1]or 0)~= 0 then | |
idx = get_value(input,idx+2,params[2]or 0) +1 --increase by one cause not 0 indexed *sights* | |
else | |
idx = idx+3 | |
end | |
--jump if false... do the oposite of above | |
elseif code == 6 then | |
if get_value(input,idx+1,params[1]or 0) == 0 then | |
idx = get_value(input,idx+2,params[2]or 0) +1 --increase by one cause not 0 indexed *sights* | |
else | |
idx = idx+3 | |
end | |
--if smaler set to 1 else to 0 | |
elseif code == 7 then | |
local value_to_set = 0 | |
if get_value(input,idx+1,params[1] or 0)<get_value(input,idx+2,params[2] or 0) then | |
value_to_set = 1 | |
else | |
value_to_set = 0 | |
end | |
input[save_pos] = value_to_set | |
idx = idx+4 | |
elseif code == 8 then | |
local value_to_set = 0 | |
if get_value(input,idx+1,params[1] or 0) == get_value(input,idx+2,params[2] or 0) then | |
value_to_set = 1 | |
else | |
value_to_set = 0 | |
end | |
input[save_pos] = value_to_set | |
idx = idx+4 | |
else | |
print("???") | |
idx=idx+1 | |
break | |
end | |
--print( table.concat(input,",")) | |
--idx=idx+4 | |
raw_code = input[idx] | |
code, params = parse_raw_code(raw_code) | |
end | |
return input[1] | |
end | |
local test_input = { | |
--1,9,10,3,2,3,11,0,99,30,40,50 | |
--1,1,1,4,99,5,6,0,99, | |
3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, | |
1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, | |
999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99 | |
} | |
local function mysplit (inputstr, sep) | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} | |
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
table.insert(t, str*1) | |
end | |
return t | |
end | |
local function test () | |
local real_input ={ | |
3,225,1,225,6,6,1100,1,238,225,104,0,1101,86,8,225,1101,82,69,225,101,36,65,224,1001,224,-106,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,102,52,148,224,101,-1144,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1102,70,45,225,1002,143,48,224,1001,224,-1344,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,69,75,225,1001,18,85,224,1001,224,-154,224,4,224,102,8,223,223,101,2,224,224,1,224,223,223,1101,15,59,225,1102,67,42,224,101,-2814,224,224,4,224,1002,223,8,223,101,3,224,224,1,223,224,223,1101,28,63,225,1101,45,22,225,1101,90,16,225,2,152,92,224,1001,224,-1200,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,45,28,224,1001,224,-73,224,4,224,1002,223,8,223,101,7,224,224,1,224,223,223,1,14,118,224,101,-67,224,224,4,224,1002,223,8,223,1001,224,2,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,7,677,677,224,102,2,223,223,1005,224,329,1001,223,1,223,1008,226,226,224,1002,223,2,223,1005,224,344,1001,223,1,223,1107,677,226,224,1002,223,2,223,1006,224,359,1001,223,1,223,107,677,677,224,102,2,223,223,1005,224,374,101,1,223,223,1108,677,226,224,102,2,223,223,1005,224,389,1001,223,1,223,1007,677,677,224,1002,223,2,223,1005,224,404,101,1,223,223,1008,677,226,224,102,2,223,223,1005,224,419,101,1,223,223,1108,226,677,224,102,2,223,223,1006,224,434,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,449,101,1,223,223,1008,677,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1108,226,226,224,1002,223,2,223,1005,224,479,1001,223,1,223,1007,226,677,224,102,2,223,223,1005,224,494,1001,223,1,223,1007,226,226,224,102,2,223,223,1005,224,509,101,1,223,223,107,677,226,224,1002,223,2,223,1006,224,524,1001,223,1,223,108,677,677,224,102,2,223,223,1006,224,539,101,1,223,223,7,677,226,224,102,2,223,223,1006,224,554,1001,223,1,223,1107,226,677,224,102,2,223,223,1005,224,569,101,1,223,223,108,677,226,224,1002,223,2,223,1006,224,584,101,1,223,223,108,226,226,224,102,2,223,223,1006,224,599,1001,223,1,223,1107,226,226,224,102,2,223,223,1006,224,614,1001,223,1,223,8,226,677,224,102,2,223,223,1006,224,629,1001,223,1,223,107,226,226,224,102,2,223,223,1005,224,644,101,1,223,223,8,226,226,224,102,2,223,223,1006,224,659,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,674,101,1,223,223,4,223,99,226 | |
} | |
local input_ = mysplit(table.concat(real_input,","),",") | |
computer_part1(input_) | |
end | |
test() |
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
--orbit stuff | |
local function split_input(input) | |
local start_idx = 0 | |
local txt = input | |
local split_result ={} | |
while #txt>0 do | |
local match_ =string.match(txt,"(.-)\n",start_idx) | |
if match_ == "" then | |
elseif match_ == nil then | |
break | |
else | |
--print("Match:",match_) | |
table.insert(split_result,match_) | |
end | |
start_idx = start_idx+#match_+1 | |
end | |
return split_result | |
end | |
local function split_connection(input) | |
local part1 = "" | |
local part2 = "" | |
local idx = input:find(")") | |
part1 = input:sub(0,idx-1) | |
part2 = input:sub(idx+1) | |
print(part1,part2) | |
return part1,part2 | |
end | |
local test_input = [[ | |
COM)B | |
B)C | |
C)D | |
D)E | |
E)F | |
B)G | |
G)H | |
D)I | |
E)J | |
J)K | |
K)L | |
K)YOU | |
I)SAN | |
]] | |
local real_input = [[ | |
HL2)HP5 | |
PD5)SVL | |
GGS)YTS | |
59G)C67 | |
V3R)BTY | |
B9B)4QH | |
P42)PNP | |
3MR)YPD | |
HPL)T7M | |
9T9)BV2 | |
QTG)LZM | |
LYL)2K1 | |
ZM2)CCK | |
983)QLL | |
WYK)SKS | |
G2H)5QT | |
GW2)39Q | |
K68)HBF | |
FLF)GYC | |
Y8H)B69 | |
H61)TSN | |
J6L)PZH | |
BD3)WSD | |
321)HZ7 | |
FC4)X58 | |
7M7)SR7 | |
KXX)S7P | |
JBT)HFR | |
DPQ)96V | |
47S)36P | |
JQ8)FJL | |
1PX)J2L | |
DR8)HJ5 | |
1P6)GS4 | |
LXJ)WDK | |
8BB)LYL | |
TPD)9XH | |
5ZB)TML | |
ZYQ)DLC | |
1D2)L82 | |
SZX)TLH | |
3HG)2Z4 | |
T16)DT9 | |
TDS)8PD | |
Y9F)VNZ | |
7NW)LQD | |
F5W)88Z | |
YQH)N7L | |
TRH)V7C | |
FHB)WDL | |
DT3)BHQ | |
4Q8)MXM | |
J1X)5DP | |
172)6NG | |
SR7)FLL | |
DT9)PZP | |
M8V)FY6 | |
RXG)Y4B | |
H5F)9G9 | |
B53)F72 | |
9JQ)2WM | |
422)BQD | |
96B)6XD | |
F89)LCS | |
F59)9H9 | |
J73)JQ9 | |
PNV)BC3 | |
B84)N4Y | |
9FC)7L8 | |
2ZK)79Z | |
7CM)6R3 | |
2LL)N46 | |
DXF)2RH | |
C6Q)JVW | |
96V)4FT | |
G86)3CT | |
Y4D)33X | |
MXM)BCN | |
KRR)S7L | |
BKX)8FF | |
RQ7)RLG | |
6Q5)93D | |
YCZ)J41 | |
ZSM)QGQ | |
R72)2QY | |
848)SZX | |
93D)Z9Q | |
X5S)T2M | |
1H4)6Q5 | |
3F1)M8L | |
Y4W)FLF | |
K7D)1DD | |
CGL)8VF | |
N46)LCX | |
WDL)XHZ | |
YZ4)SC1 | |
6K8)D4Z | |
Z2B)F5J | |
SQF)1BV | |
NK2)BXT | |
SF7)H5Y | |
HBF)2GM | |
7RN)5N6 | |
9XH)YGR | |
P7L)HWR | |
CRR)5JF | |
GGG)L41 | |
3JH)HVX | |
BCH)LNN | |
4BG)XGX | |
JCZ)Q5T | |
SYH)H2H | |
CLB)TTD | |
1QW)MX8 | |
F58)9C6 | |
DZY)B84 | |
D76)LX2 | |
JDC)RKC | |
55J)B9B | |
DQY)1RB | |
41Q)VN9 | |
TQW)CY7 | |
G1F)SYH | |
9MQ)G1F | |
H1W)3LQ | |
Y5C)QBJ | |
CCK)PYL | |
C6D)P9Y | |
837)N5C | |
ZKQ)SPV | |
DT9)37T | |
FSQ)GQG | |
3GY)6BC | |
TP6)JWB | |
X42)9Y6 | |
Z9Q)3G2 | |
FF9)CFX | |
WJ8)873 | |
TPP)VK6 | |
5ZY)DT3 | |
1LM)63J | |
21Z)SQF | |
RQT)VQT | |
CSP)H3T | |
3PC)S6B | |
337)D7H | |
HZ7)XRK | |
36P)8VL | |
R2C)LTF | |
NXN)5DQ | |
S24)5PL | |
X8H)7D5 | |
LW1)GYR | |
H14)9SQ | |
P15)76B | |
31W)NX3 | |
QTH)97M | |
35S)7XM | |
DK7)VGQ | |
VNZ)BGT | |
T6V)1MB | |
JK4)H92 | |
BV1)ZPR | |
3YG)7WM | |
YNL)JQ8 | |
H92)C6G | |
5GH)R7B | |
4SK)X7R | |
KYK)VTJ | |
DWX)13Z | |
2QN)XC3 | |
MPF)CFJ | |
2DW)G9R | |
KGF)V15 | |
BQD)W9L | |
CX6)LRG | |
TGZ)KC3 | |
1S6)YCZ | |
S7L)3JH | |
K83)C6Q | |
H1X)K9L | |
ZPV)QYC | |
Z7D)CMZ | |
PVY)SNN | |
RVP)5B4 | |
4SX)5J5 | |
WK5)C4P | |
XZ3)8XF | |
T3J)337 | |
X5D)DR8 | |
S6B)9FC | |
4Z9)1F3 | |
HF3)VCN | |
C37)2H4 | |
71S)NYD | |
1MB)7CH | |
TXD)LYX | |
SF3)P7L | |
X4Z)VX8 | |
XRL)RTX | |
F7V)QMZ | |
VR9)MHV | |
F6P)4FB | |
SC1)N9V | |
QSH)SG5 | |
GVP)5DL | |
C4G)T1T | |
VH1)RH4 | |
MZW)4W5 | |
R7B)MRX | |
P4F)PY4 | |
7YW)577 | |
Y1Y)NGJ | |
642)M1Z | |
BLQ)Y4H | |
3DT)PRB | |
DPQ)K8G | |
JKL)N97 | |
7KZ)ZY4 | |
CX6)8RN | |
WM5)W5L | |
QBM)NK2 | |
2Z4)X8H | |
T1T)5BV | |
2GM)5WD | |
LZM)V3R | |
S61)RN6 | |
744)BD2 | |
VQT)WBH | |
QVF)YGJ | |
P4B)XCQ | |
J41)3FX | |
NCP)BL5 | |
1NK)VPM | |
9H9)47S | |
T92)5X8 | |
W9W)439 | |
ST9)HTJ | |
SMD)1NK | |
DGW)2QN | |
T7N)LDH | |
Y9B)3HG | |
BBW)3DP | |
QQS)1H3 | |
YNM)P4F | |
J4X)KK5 | |
XHS)FJP | |
L82)HVP | |
K9L)2RT | |
1VG)35S | |
7GK)RD6 | |
1QV)BL4 | |
5NM)Z91 | |
FK8)DWX | |
JQ9)7TN | |
5J5)X7L | |
5X8)837 | |
1DD)VYM | |
PKR)1QV | |
V32)Y5C | |
QMZ)XSF | |
CPY)8KQ | |
Y23)DQH | |
P9Y)YBY | |
DQH)QQS | |
S98)VB3 | |
DGF)MS9 | |
MTR)T5J | |
PZP)6CK | |
G6T)3G9 | |
JYX)ZSM | |
9G9)J2Q | |
F2F)NF1 | |
8X9)JGY | |
7N3)91G | |
CJX)PCK | |
3BR)FP2 | |
HTQ)JF1 | |
XW6)XXN | |
Y47)LZQ | |
ZZZ)Y23 | |
VYM)TXW | |
9G6)27H | |
Q5T)YLK | |
BV2)C1N | |
GZ4)K83 | |
QXJ)JYX | |
M8P)YSL | |
741)VSZ | |
QXP)BFG | |
X2H)TJ1 | |
H2H)G1T | |
L41)NH6 | |
QBJ)8BB | |
XN5)LTC | |
26R)W2M | |
2N6)YJD | |
3LN)XHS | |
LRG)V65 | |
4W5)B8Y | |
HG6)QC9 | |
Z3L)GFD | |
MLK)Y1Y | |
13Z)LCC | |
4QH)G2H | |
XSF)M8R | |
VH7)K7D | |
V8N)YBV | |
751)7CM | |
NW1)P5H | |
7FK)SHV | |
R6J)V32 | |
TK7)H61 | |
2WM)26R | |
8RN)5VS | |
BSF)5ZB | |
WW5)QXV | |
N42)2JB | |
FKG)V4R | |
Q5T)7GK | |
XBL)546 | |
1TC)Z4Y | |
4F9)ZKZ | |
XRK)J4X | |
JZK)XN5 | |
W23)GZB | |
V65)TQW | |
BF7)DXT | |
726)3F1 | |
L84)M8P | |
PDX)9QY | |
7D4)QSN | |
439)SCX | |
WBL)X42 | |
9NG)P36 | |
R51)R17 | |
Z9F)321 | |
SSS)NSV | |
DQ4)P15 | |
R2D)2J4 | |
LDH)V8N | |
96V)8J9 | |
J9C)JDC | |
YBD)RQ3 | |
7FK)RSW | |
YJD)1X7 | |
LYX)VSR | |
HWZ)1T5 | |
W32)B53 | |
CT7)FPL | |
YLH)HS7 | |
C67)2F6 | |
TGL)1D2 | |
XH1)751 | |
B95)TP6 | |
918)97J | |
LC7)52P | |
4W5)Y9F | |
5DP)XRP | |
JF1)KXX | |
95P)8NP | |
SR8)HG8 | |
5ZB)D9Q | |
NRG)F2Z | |
FMT)J6S | |
2RC)DGF | |
4GZ)BXH | |
4FB)LWM | |
2YN)69M | |
PCK)9VS | |
9W8)L84 | |
SMH)JHR | |
B2X)WM5 | |
96B)BL2 | |
F7V)R3L | |
DR3)JBY | |
ZF8)WRJ | |
1RB)KTP | |
TWN)5QY | |
N7L)WLK | |
XM8)NRG | |
T84)6K8 | |
FY6)XDY | |
6GC)B9W | |
HFR)JRG | |
6BC)SYX | |
MM1)53N | |
TDS)KPB | |
CSD)VJN | |
XDC)DK7 | |
6GV)KRR | |
5JW)15B | |
VTJ)SMD | |
MMS)4Z9 | |
7WM)L7Q | |
7XM)3PC | |
QGQ)2GB | |
WXR)G6T | |
MTP)65C | |
5RP)C4G | |
PP3)Y2M | |
9SV)27Y | |
1ZD)2ZK | |
D2B)7TC | |
5BV)9MQ | |
V15)844 | |
CMZ)1VG | |
6SH)BKX | |
C41)366 | |
3V4)DPQ | |
8BB)MZW | |
HXL)X88 | |
2YN)JKL | |
YPD)9PN | |
SPV)YOU | |
64L)S24 | |
VGK)ZF1 | |
ZJN)3WG | |
CSP)T7N | |
7CH)MWB | |
3DP)YNN | |
37T)3V4 | |
Z5N)J1Z | |
578)FPJ | |
QYC)YNL | |
52P)FXJ | |
844)3GY | |
PWJ)S98 | |
RB9)M14 | |
T84)F89 | |
C58)TCC | |
YVT)XW6 | |
P49)STW | |
ZPR)TPD | |
Y4W)QFY | |
BNJ)VGT | |
3FX)1TC | |
SP3)FNK | |
B4Y)PKR | |
WHY)TDS | |
VVL)Z5D | |
C99)GS9 | |
3WQ)MST | |
33X)7D4 | |
BLD)9JQ | |
MQN)QRP | |
M8R)ST9 | |
5DL)1P6 | |
5QY)D2V | |
X7R)LSR | |
BXT)MG4 | |
6TQ)LVD | |
XZQ)2KZ | |
PKW)V3X | |
QXP)95S | |
RRY)WLQ | |
KK5)VH7 | |
PCG)1RS | |
SYX)SKW | |
GS9)ZPV | |
JBT)62J | |
N42)PJF | |
5QT)JYF | |
QMQ)QRD | |
W1P)WJY | |
YD2)51R | |
XPL)4L3 | |
RXS)ZF8 | |
B8B)3ZN | |
JGY)R51 | |
9QY)WXJ | |
SHY)Y9B | |
HG8)TKR | |
L7Q)SZG | |
NYM)9T9 | |
ZY4)6SF | |
879)41Q | |
YBY)LBZ | |
RNN)J9C | |
LB6)XQG | |
48W)XPL | |
W5K)TYT | |
JHR)94L | |
2P8)QBM | |
ZW3)BF7 | |
JBD)1GF | |
X4Z)9NG | |
HC7)PD5 | |
7JK)GNY | |
HQB)31W | |
M8L)JK4 | |
LBZ)7NP | |
FC4)932 | |
KGF)WW6 | |
6R3)Z2B | |
1MM)3F3 | |
WXR)8BP | |
SM6)JSD | |
8WV)6C1 | |
Z9M)S99 | |
GZB)MTR | |
39Q)1VY | |
VR9)PBP | |
B6D)MLC | |
DJW)YTY | |
X7L)R6J | |
YNN)G86 | |
ZPV)NYM | |
8KQ)5N5 | |
K1Y)D8G | |
SVK)M3R | |
ZZD)XBJ | |
5VS)M8V | |
5N5)JZK | |
D2V)Y8H | |
SZG)FMS | |
CG2)2S3 | |
2H4)9P8 | |
9XY)SMV | |
1YJ)3DT | |
932)NDV | |
3PK)PKW | |
8PD)T4Z | |
6C1)578 | |
6NK)2LL | |
NF1)H4Z | |
KC3)YQ2 | |
1F3)B9V | |
XLH)H1W | |
1RS)YQH | |
R3L)92R | |
COM)K9X | |
TTD)BNJ | |
4SV)5HZ | |
549)J2W | |
S96)4JG | |
88Z)TK7 | |
7D4)JPH | |
PYG)F76 | |
TSC)W23 | |
9Y6)48W | |
S7P)QMQ | |
15Y)NGF | |
82B)NL3 | |
2RH)BW5 | |
B8Y)MM1 | |
L6M)JRV | |
53V)S61 | |
K8G)7YW | |
N5S)VQ8 | |
W2H)WK7 | |
GS7)3ZK | |
WSD)965 | |
J2W)7FK | |
PNS)S6T | |
XHS)9LF | |
1Z3)WJ4 | |
7F3)8X9 | |
XRP)1KP | |
QGR)QNM | |
5CB)N5N | |
T21)F2F | |
FP2)XZ9 | |
7L8)BCH | |
B9W)KCL | |
XNB)JFV | |
H4Z)2V1 | |
C1N)DXF | |
LTF)918 | |
KMJ)WSW | |
CYN)Y7D | |
KG3)XNB | |
SGC)TXD | |
KPB)Q9J | |
Y4B)KNW | |
MBC)XY7 | |
XY1)717 | |
VTH)RXS | |
VK6)S96 | |
HP5)T6H | |
BMC)15Y | |
X6L)D2B | |
S99)P6L | |
642)HWZ | |
Q9J)V3G | |
QM5)457 | |
72F)TWN | |
YTS)K9N | |
VQ8)QXP | |
XN5)WMB | |
Z6B)1Z3 | |
JFV)HZB | |
NH6)4BY | |
8VF)RQT | |
1F3)BP7 | |
1LQ)WF3 | |
RTX)SVK | |
RV4)572 | |
61D)64D | |
SQY)XHJ | |
TFB)KMX | |
GD7)RRY | |
TJ1)FC4 | |
J5K)PYG | |
WLK)DGW | |
PYL)F58 | |
PY4)X61 | |
K5P)W32 | |
SMD)GSG | |
SY2)XLH | |
43L)XX5 | |
4DJ)NVS | |
GF5)T8J | |
R6J)T16 | |
6NG)W1R | |
LCS)6WZ | |
N9V)JBN | |
H9N)86Z | |
NS9)3MR | |
C2R)DLH | |
NM3)9H4 | |
YSL)CQC | |
N8X)GZ4 | |
XVG)Z9F | |
FPL)LXJ | |
PZH)ZJN | |
B9V)W2H | |
XDC)PNS | |
873)V82 | |
Q6L)S21 | |
P4R)642 | |
YQ2)QMR | |
C66)JJ2 | |
CFJ)FFQ | |
NDV)MDT | |
D44)5ZY | |
HND)B8B | |
P67)PCG | |
QC9)C58 | |
6Z5)3PK | |
N5N)CPY | |
6NG)N8P | |
6ND)LC7 | |
2RT)GBM | |
GWW)WJB | |
5DQ)3WS | |
5WD)1MM | |
SQY)1LM | |
STW)2HX | |
R2T)1S1 | |
8BP)XMG | |
VPM)PVP | |
HWR)858 | |
N8P)ZDH | |
3G2)4KC | |
T8J)5HL | |
VLG)WBL | |
ZKZ)QM5 | |
4L3)5PN | |
G9R)WYK | |
SH1)K2B | |
JRG)9MN | |
WBH)B7R | |
4FT)Y72 | |
LCX)VL5 | |
1H4)1XQ | |
DLH)848 | |
V3X)7F3 | |
CT7)SF7 | |
M6J)Q7R | |
5B4)YLH | |
SNN)XZQ | |
5GH)DV3 | |
GS7)JCZ | |
D9Q)CJX | |
MX8)172 | |
MG4)J73 | |
RQ3)9G6 | |
FJP)SC6 | |
SKW)NDP | |
1YN)T21 | |
1H3)GW2 | |
YBD)6PV | |
62J)MLK | |
BFG)GGS | |
GYR)P49 | |
6TQ)8Z3 | |
JSD)87S | |
V82)53V | |
HTQ)YNM | |
CJM)FHB | |
JBD)SQY | |
XY7)MPF | |
RN6)Q4W | |
VN9)2MT | |
3VM)61H | |
RN2)QGR | |
BV6)BLQ | |
3WG)XPY | |
B69)TGL | |
3VT)HG6 | |
BL2)M1P | |
1BV)2DW | |
75P)3WQ | |
9PN)CG2 | |
DGF)J78 | |
LQD)5GH | |
L2H)96B | |
XX5)82W | |
GYC)SGC | |
LYL)S9Z | |
HZB)D8R | |
K9N)6SH | |
6R3)S3N | |
NGJ)VB5 | |
QLL)SH1 | |
366)6Z5 | |
QRP)9XY | |
NL3)21Z | |
2G7)MJZ | |
P6L)RN2 | |
DSH)GBJ | |
VGQ)95P | |
N97)94D | |
BD2)X47 | |
T6H)VMN | |
G1R)B6D | |
B7R)R72 | |
K9X)1PX | |
NJ8)2RC | |
S9Z)ZM2 | |
HW5)FMT | |
FPJ)M5C | |
MST)1P9 | |
965)X32 | |
NX3)CGK | |
717)DR3 | |
1D2)TSC | |
RXH)H9N | |
8G2)HPL | |
D8G)XXT | |
5QT)4SX | |
1XS)NHG | |
M9V)PF2 | |
4FB)744 | |
8NP)5JW | |
LZM)H14 | |
J9C)484 | |
7TC)Z4B | |
Z27)1LQ | |
RKC)GVP | |
RQC)JBD | |
LVD)FKJ | |
GFD)HQB | |
8J9)1ZD | |
6SF)SAN | |
SC8)BK9 | |
VGT)JX7 | |
KCZ)4HT | |
K9L)MQN | |
9MY)LZ5 | |
JLP)WVP | |
HFV)Z7D | |
J1Z)LB6 | |
X61)T92 | |
WW6)VTH | |
KNC)NL4 | |
C4P)RSJ | |
QNM)TFB | |
N12)983 | |
3JJ)QR5 | |
LZ5)H84 | |
KTP)7JK | |
3WB)Q6L | |
MS9)YW7 | |
DXT)Y4W | |
3G9)LVC | |
2K1)1YJ | |
577)ZQT | |
7NP)Y47 | |
PVP)ZW3 | |
V3H)SSS | |
ZVM)ZZZ | |
1GF)ZYQ | |
HVX)R2D | |
J9G)4GZ | |
3FX)CX6 | |
97J)X4Z | |
WMB)M2K | |
9LF)B95 | |
QBJ)HF3 | |
JWB)292 | |
QRD)P42 | |
Q4W)RV4 | |
XPY)M5Y | |
5DQ)JGR | |
95S)GYM | |
T7M)SY2 | |
6GV)PNV | |
P5H)7YV | |
6XD)FVC | |
ZRP)LWH | |
BP7)W78 | |
6G4)741 | |
G2B)HTQ | |
F2Z)D6P | |
XZ9)XVG | |
T7M)1H4 | |
1X7)55J | |
94D)9ZH | |
HJ5)R2C | |
WSW)3VT | |
2JB)CLB | |
91G)GGG | |
S21)NJ8 | |
1Z3)5RP | |
15B)WXR | |
Q63)PMD | |
18C)C2R | |
97M)DQ4 | |
MRX)Y4D | |
82W)BBW | |
QR5)2P8 | |
CYN)H5F | |
WRJ)PWK | |
XCQ)3V1 | |
BFM)8LX | |
69M)HGF | |
LCC)9W8 | |
15Y)71S | |
WLF)CRR | |
MDT)549 | |
918)19W | |
J9B)82B | |
H6R)HL2 | |
2S3)1XS | |
5JW)6ND | |
WF3)NCP | |
XGX)5CH | |
6WZ)SHY | |
J67)P4B | |
VSR)J6N | |
9ZH)35Y | |
MRJ)DSH | |
86Z)X2H | |
TXW)WJ8 | |
3LQ)N8X | |
9H4)3LN | |
KK5)4SK | |
NHG)K4C | |
GYM)43L | |
XQ4)KDX | |
Z5D)DZY | |
H4Z)JBT | |
BK9)KYK | |
1KP)BV6 | |
44Y)T6V | |
T1T)TRH | |
95Q)XZ3 | |
47X)375 | |
PRB)MJX | |
VL5)FR1 | |
CGK)7RN | |
5CH)9BB | |
5WN)NVY | |
SKS)YVT | |
DV3)SM6 | |
63J)ZRP | |
7YV)GY7 | |
PKW)T3J | |
JRV)XQ4 | |
2WM)XWK | |
F5J)GF5 | |
5PL)5WN | |
LWH)J67 | |
WJY)N39 | |
N12)3WB | |
FLL)RB9 | |
T5J)J9B | |
FFQ)YD2 | |
R2D)SC8 | |
VX8)6G4 | |
VMN)PP3 | |
NDP)V3H | |
V8N)2XQ | |
8VL)GD7 | |
1S1)4F9 | |
GHT)8G2 | |
T8V)4T3 | |
DLC)MBC | |
1RS)VH1 | |
VN9)SMH | |
N39)RNN | |
W78)SCY | |
3F3)Z17 | |
8LX)ZQY | |
3VT)B11 | |
9BB)SP3 | |
D8R)NW1 | |
NGF)ZL8 | |
NVS)G2B | |
ZQY)4FY | |
BHQ)C99 | |
2KZ)HFV | |
D6P)NM3 | |
YTY)4DJ | |
6PV)61D | |
TK7)1WL | |
1VG)F7V | |
5JF)75P | |
XWK)LZZ | |
V7C)NXN | |
RSJ)XY1 | |
BCN)K5P | |
TCC)3YG | |
V4R)RHF | |
1P9)NHK | |
JJ2)CW6 | |
SCY)CYN | |
Z17)ZZD | |
VMQ)BV1 | |
XMG)44Y | |
H84)726 | |
R72)KMJ | |
546)WK5 | |
T4Z)QSH | |
CFX)WLF | |
JGR)TGZ | |
V7C)HXL | |
PBP)RB5 | |
KMX)7M7 | |
N65)MMS | |
XXN)9SV | |
VLN)422 | |
RTX)8MY | |
J6S)TTH | |
YGJ)4SV | |
FN9)59G | |
NYD)H5N | |
YW7)8WV | |
GNY)7NW | |
TYT)YZ4 | |
BL2)64L | |
HS7)P4R | |
XHJ)XDC | |
N5C)HND | |
CW6)W9W | |
8FF)3YH | |
HD3)Z6B | |
2J4)J9G | |
7G7)KM7 | |
S6T)BLD | |
WDK)Q63 | |
PJF)PH3 | |
ZGX)DJW | |
JBY)HCG | |
SMV)M9V | |
3ZN)B2X | |
RB5)VMQ | |
XXT)YBD | |
35Y)5BH | |
ZF1)LW1 | |
LTC)D44 | |
SHV)C41 | |
WJB)HD3 | |
MHV)VLG | |
W5L)FSQ | |
FVC)QTH | |
QR5)FLP | |
8MY)C6D | |
KDX)J6L | |
ZQT)95Q | |
SH1)WHY | |
BL4)JLP | |
VB3)RQ7 | |
GY7)ZGX | |
RH4)XNZ | |
D4Z)VFR | |
ZZZ)PDX | |
NM3)QTG | |
6CK)XRL | |
92R)XH1 | |
LBZ)SR8 | |
JNM)BTB | |
Q7R)FK8 | |
M2K)JV2 | |
457)1S6 | |
Q6L)B4Y | |
BC3)2G7 | |
VJN)6NK | |
B9W)CGL | |
WVP)BSF | |
HVP)VGK | |
9MN)879 | |
YLK)QVF | |
J2Q)QXJ | |
MLC)47X | |
NHK)DQY | |
9G9)18C | |
2X2)Z9M | |
375)QGC | |
572)F59 | |
YJD)RQC | |
X47)BFM | |
M14)N5S | |
S3N)6GC | |
4T3)C66 | |
4DJ)X5D | |
P36)W5K | |
H5Y)SF3 | |
WXJ)CT7 | |
BL5)ZVM | |
JTW)6GV | |
M1Z)17T | |
27Y)ZKQ | |
1XQ)TTF | |
LZQ)DPY | |
Z9F)J1X | |
NL4)X6L | |
LCC)HMV | |
RD6)KCZ | |
M1P)H6R | |
TKR)3VM | |
1WL)CSD | |
KCL)RVP | |
QGC)HC9 | |
V3G)Z5N | |
NSV)9MY | |
VFR)G1R | |
M5Y)VR9 | |
S9Z)KNC | |
YQH)N12 | |
K4C)T84 | |
4JG)T8V | |
SG5)JNM | |
79Z)V5L | |
PWK)MRJ | |
95Q)J5K | |
FXJ)FN9 | |
7D5)KGF | |
K2B)VD1 | |
QSN)4Q8 | |
PD7)SLF | |
BKX)WW5 | |
YGR)PWJ | |
LWM)XBL | |
XDY)3JJ | |
9VS)D76 | |
3WS)4BG | |
B11)F6P | |
94L)N42 | |
VTH)PD7 | |
9H9)N65 | |
YNL)2N6 | |
JV2)CJM | |
M5C)7G7 | |
RH4)W1P | |
64D)BD3 | |
FKJ)R2T | |
Z91)RXH | |
FJL)RXG | |
Y2M)DM4 | |
2F6)L6M | |
27Q)KG3 | |
9SQ)M6J | |
KMJ)Z27 | |
3ZK)CDV | |
3YH)1YN | |
SCX)NS9 | |
C6G)27Q | |
GQG)5CB | |
C6L)5C1 | |
MJZ)NP1 | |
BGT)C37 | |
NXN)P67 | |
ZL8)FKG | |
36P)JTW | |
LSR)X5S | |
2XQ)H1X | |
X58)L2H | |
G1T)HC7 | |
FLF)Z3L | |
XX5)7KZ | |
SLF)VVL | |
ZDH)TTQ | |
WK7)F5W | |
8XF)K1Y | |
87S)3BR | |
W2M)GHT | |
PF2)2YN | |
17T)HW5 | |
TSN)2X2 | |
Z4Y)BWY | |
J2L)PVY | |
76B)K68 | |
H5F)XM8 | |
TTQ)GWW | |
61H)MTP | |
JYF)C6L | |
MBC)BMC | |
PMD)TPP | |
MJX)CSP | |
LZ5)1QW | |
XBJ)FF9 | |
T2M)6TQ | |
53N)GS7 | |
2QY)VLN | |
RLG)72F | |
HC9)5NM | |
YBV)7N3 | |
]] | |
local planet_list = {} | |
local planets={} | |
function planets.add(planet_name) | |
if planet_list[planet_name] == nil then | |
planet_list[planet_name] ={name=planet_name,childs = {},parent=nil} | |
end | |
end | |
local function get_parents_of_planet(planet) | |
local parent_list ={} | |
local distance = 0 | |
while planet.parent ~= nil do | |
--print(planet.name) | |
parent_list[planet.name]=distance | |
planet = planet_list[planet.parent] | |
distance=distance+1 | |
end | |
--print("-----") | |
return distance,parent_list | |
end | |
function find_common_planets(planet_a,planet_b) | |
local nearest_dist = 2000000 | |
local nearest_plan = "na" | |
for name,dist in pairs(planet_a) do | |
if planet_b[name] ~= nil then | |
if dist+planet_b[name] < nearest_dist then | |
nearest_dist = dist+planet_b[name] | |
nearest_plan = name | |
end | |
end | |
end | |
print("\n\nResults") | |
print(nearest_plan, nearest_dist -2) | |
end | |
local connections =split_input(real_input) | |
for idx,connection in ipairs(connections) do | |
local base,orbiter =split_connection(connection) | |
planets.add(base) | |
planets.add(orbiter) | |
table.insert(planet_list[base].childs,orbiter) | |
planet_list[orbiter].parent = base | |
end | |
--part2 | |
_,list_you =get_parents_of_planet(planet_list["YOU"]) | |
_,list_san =get_parents_of_planet(planet_list["SAN"]) | |
find_common_planets(list_you,list_san) | |
--part1 | |
local orbits = 0 | |
for name,planet in pairs(planet_list) do | |
--print(name,planet) | |
distance,list =get_parents_of_planet(planet) | |
orbits = orbits+distance | |
end | |
print("\nOrbits",orbits) | |
--print(string.match(test_input,".-\n")) |
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 process_layer(layer) | |
local found_0 = 0 | |
local found_1 = 0 | |
local found_2 = 0 | |
for idx=1,#layer do | |
local num = tonumber( layer:sub(idx,idx)) | |
if num == 0 then found_0= found_0+1 | |
elseif num == 1 then found_1 = found_1+1 | |
elseif num == 2 then found_2 = found_2+1 end | |
end | |
return found_0 ,found_1,found_2 | |
end | |
function split_to_layers(img_string,width,height) | |
local start_idx = 1 | |
local layer_size = width*height | |
local layers = {} | |
while start_idx <#img_string do | |
local layer =img_string:sub(start_idx,start_idx+layer_size -1) | |
print(#layer,layer_size,layer) | |
table.insert(layers,layer) | |
start_idx = start_idx+layer_size | |
end | |
return layers | |
end | |
local real_input = [[222221022222222122022202122222221022222222222222022221222220222222222022022222222022210222212202220222222222221222022222221022222222222102222222022222222220122222222222022212022222222022222222222222222221222222222222222022222222222022220222202202221222222222220222222222201222222222222102222222122222222220122222222022222202122222222222222222222222222222222222222222222222022222222122202222202222221222222222220222022222202122222222022022222222222222222221022222222122122202020222221122222222222222122220222221222222222022222222222122220222202212220222222222200222122222220222222222222222222222022222222222022222222022122212122222221222222222222222222221222222222222222122022222222122220222212202221222222222220222122222201022222222122122222222022222222221122222222222122222120222221222222222222222222221222220222222222222222222222022200222202222220222222222201222222222210222222222022012222222222222222222122222222222222222120222220022222222222222022220222222222222222122222222222212212222212202220222222222212222222222221122222022122002222222122222222220122222222022122222020222220122222222222222212222222222222222222122022222222102211222222212222222222222200222222222202122222122122222222222222222222220022222222222022212222222220122222222222222022222222220222222222022022222222112211222202202221222222222200222222222202222222222222102222222022222222221222222222022022212121222221122222222222222212222222222222222222122022222222112210222212202220222222222201222222222200022222222222102222222122222222222122222222022222202122222221022222222222222122222222222222222222122022212222102200222212212221222222222200222222222200122222222122022222222222222222220122222222222222212021222221222222222222222012222222220222222222122022202222002221222222212220222222222200222122222212022222122222210222222120222222221222222222222222222120222220122222222222222212221222220222222222122222212222002222222222202222222222222202222122222222022222022122011222222021222222221022222222222022202120222220122222222222222112220222200222222222022122212222122201222202222220222222222010222022222212122222122122200222222121222222221022222222222022222020222220122222222212222222221222202222222222222122222222012211222212202210222222222200222022222202022222022022010222222121222222221122222222222222212011222220022222222222222002222222222222222222222022212222222221222222212202222222222111222022222220022222022022022222222120222222220122222222122222202010222221222222222212222102221222210222222222222222212222202220222202202200222222222001222022222221222222222222222222222121222222221022222222222122222211222221022222220222222002220222220222222222222022222222102212222212202220222222222021222122222222022222122022200222222222222222221122222222222122202202222221222222222212222212221222211222222222122222212222122212222202212212222222222212222022222210222222222022112222222222222222222022222222222022212220222221022221020222222122200222220222222222122122202222022201222212202222222222222021222222222212022222122022112222222020222222220122222222022122212020222220222221220202222122212222200222222222022022222222222221222202222221222222222120222222222211222222122122120222222021222222222222222222222222212012222222222221220202222222221212200222222222122222212222002221222202212201222222222210222112222222222222222022210222222220222222221022222222022122222112222222122221020202222012202222211222222222022222222222012222222222202211222222222101222022222200122222022122101222222021222222221022222222022222222011222222122222120222222212212222200222222022022222222222112210222222222012222222222022222112222201122222022122211222222221222222221022222222222122222212222222022222022212222102211222202222222222222022222222022211222222202102222222222011222222222211222222222022011222222121222222221122222222221022212022222222222220221212222022202202201222222022222022212222022211222212222010222222222211222002222201222222022022100222222122222222220222222222021122212202222221022220020212222022202212200222222122022222202222102201222202202021222222222201222002222221122222222122221222222222222122221222222222120222222220222221122222122212222012210222200222222222222122222222002200222212202020222222222220222122222211122222222122020222222022222122221022222222020022222221222221122220122212222022220212202222222022222222202222002221222212202112222222221000222112222222122222022222120222222002222222222122222222022022212210222220022222121222222212210212221222222022022222202222002221222222212212222222222122222112222200022222122222212222222001222222221122222222022022222002222221022220021202222102211212221222222222022122212222122210222212212222222222222122222212222211122222022222222222222201222122221022222222120122212011222222022222021202222222222222200222222222022022202222012200222212222201222222220000222122222211222222122222000222222110222122220122212222022022212211222220222222020202222202210202201222222222022122222222122210222202202120222222222101222102222201222222212122211222222022222022222222222222022002222210222222222220120202222202201222220222222122022222222222002201222202202001222222221222222012222212122222012222210222222012222122222122202222120022202122222220222220221222222102220202222222222222222122201222022221222202222121222222220011222112222201122222022222200222222111222122221022212222220002212002222221122220020222222012200222202222222222122022211222102212222212202022222222221122222202222211022222202222121222222102222022220022202222020012202111222222222221021202222222222222221222222022022122201222122211222212222000222222222012222102222202022222122122021222222120222222221222200222122122202220222221022221120202222002222212222222222122122022210222012222222202212211222222220011222102222211222222202122221222222200222122220121220222220112222000222220222220212212222202221222212222202022122122202222202212222222212220222222220001222122222210022222122022112222222221222222222022210222021012212021222221222202010222222222222212200222202222222122222222202202222222202212222222220000222122222200222222022122022222222112222122222021220222121222222001222220222210002222222022200222200222202122022122222222022220222202012012222222222202222022222211222222212222202222222200222122222120211222220012212122222222122222002212222102221212210122222122222122221222102212222212002022222222222010222212222211022222002122101222222212222222222021222222221122222212222221122210101002222222210222220122212222222222211222202201222222222020222222221010222022222212122222202022011222222101222222220022202222020112202002222222022200012202222202210212212222212022122022201222022200222222222211222222221111222222222220122222022122220222222012222222220221200222221222202210222221122212210112222212202212212022202222222222201222122221222222022011222222220120222202222221122222102022212222222001222222222221221220222112012210222220222222020002222112210212202122212222022222202222002201222222122212222222221101222012222221222222212022111222222100222022020020212221022122022202222220122200111112222212211222211022202022122022211222222210222222222021222222220202222022222220022222012222212222222222222122021122201220021222022121222222122210222102222112212212212122222122122122222222222010222222212100222222221222222122222210222222002022001222222221222222021221201222021122222020222122222200011222222002210202202222222122122222210222202122222202012122222222221000222202222222122222102222100222222210222022222221200222020022002202222222122210111122222012212222200222212222022222202222012102222202222201222222221020222112222222122222022122011222222021222122021221202222021202012202222120022221100222222112201212221022212022022022222222022110222222102021222222222022222012222211022222212020220222222002222122221020202220020022102220222220122222100002222222200212202122202122022022200222202012222222102220222122220112222202222220222222202220102222222002222122120021222222121002012122222121122222211012222212221212202222212122022122201222222022222202122110222122221201222022222210122222002021122222222112222222001022220220220012202200222121122222020202220112212202202122222222222022200222002211222212112221222022222122222002222210122222122220100222222002222222201021221220120212112122022122122211010122222112202222211122212122222122221222202220222202102210222122222000222202222221022222112120202222222220202022212120202221022012212222122221022210100102222022221202202022212022222212211221022022222212002020222022221010222002222220022222212021021222222000212222111020200221220212022101022122022201010022221122210222201022212222222012200200102101222202212100222122222101222212222212222222002222000222222210202122212121211220121002222020122021122202211202222212201212201122202222222102200200222111222222112011222222220122222122222220222222112022120222222020212121002021201221021102212021222220222211002102220222201222222022222122022122201211222121222222222021222122221120222002222210022222122120111222222201202222210021222220020122102122222122222211000222221202221202222122202222022112212222022001012212222222222122220101222202222211222222122121201222222001212222101021200221121122022111222222022210111202222222200212221022202122122002222220012012112202012200222022222022222212222222022222112122012222222020222222200122222222110122220020222020222211111222221012210202200122222022122022221200202100002102022212222022220120222212202200222222012020201222222212112220211020220221222122201222022022022211110202220112212222201122222022222212200220112122122002002111222122222202222002212221222222202121222222222001022222102122222221001112111122222220022201021002222012201222202222222022202202211221202112012012112022222222222202222212212212022222120121112222222000222022222122202220022022011212022222122220112202220202220202220221222222202222210220222001112012002210222022221102222212202210222222112221210222222112122222002021221222020002210212222220122210212222222222222202210222202122102112202000212212200022122211222222221200222222212221222222210121002222222121112122220121211222220122022221222220022210010122222202221202222022222122222122210021012010202012002011222222220211222212202200122222202021202222222122022122112200211221210022100101222221122212221012222122202202210221212022002012211012202020201122202112222222221221222112222211222222201021021202222001002220222220202220110112210020022221222202100022221222221212210121202022202022200110222212111102212001222222221122222022212201222222110022212202222210002120020220210222200012101021222020022202112122222202222202212122212122102112210020022120102112002101222222221100222202202211122222122222022202222020222222210202202221002102101012022021222201122002221012222222220022212122011012210002122222102202122101222122222101222102202210122222000120201222222011222121122120210221101012111021122020022221001112222222221212202121222222200212201012222212021222012110222122221111222212202212122222211220110202222112012020221100020222211202010101222122022220221212220122221212221120222122210212211002012001020202202222222122220102222212212002122222010020011212222021222220201002001222102122211102122122222221020222222112200202201221211202222122220211122112011122122221222222221012222012222010222222210121012202222001112121112112220222022002212010222021222212111122220212220212200020210002101112202011212102100212002211222222222020222002202011222222211120221222222001022022210212212221202022020121222121122212102222222202200222210221222202100022210110222021220022102222222222122110222102222211222022010220112202222200022021211002122221210202121120022120222212022122221022202202220220212022101002220112022100221122202112222222021212222112202110022122212122111222222020002220021202022222010101020021022122022201222202201212210212210022222012012202222001222112112122202100222022121022222102222212222022200222210212222012002221100000210222212122002120122220122222202212200012212212221220222022201102202211122111112212002111222022222201222122212120222022110220010202222100222110112112121220120011111111122021222222111020221212000202210022212222022112220012002020101012222002222222020000222012202200122022012222012212222122222202221212022221211100000211222022122201110201201222020202200022220112121012210021212001100202102122222022020010222022222021022222222122010222222101012011222211102212220201012122022122022201210122121102122202222021210112121112222012122011022001122001222122220021202002212100122022221120221212222112122210002020121221022122021100022221122211002112222212222222220022220202011122222002012002202021222020222022221222202012222021122222222120212222222211202021111111011211120102002010222222022200210222102202000222211020202222110112211212022010010100202112222022121110202012112120122122012121000122222121012012100020201202122021110202222120222200022201121212100202210021222212012222200220212021010210202122222122121210202222022020122222210022221022222202002011121020022221012221201021122021222210021010100102120212200222222002021122201000002101121100022101222222022222212212122000202222221122010102222002122200122220212212100102112112022022022221001122202222211222212222200002002102211020012010120002012202212022222002202122012101022102200220220002222012002022220120211221201112012021022020122200012111220122000002211120220012120212220001002011222110122221212222022120222012202001122122212120122222222000122212120001002212022112200022222121222222010100010122212222202022202222011112201222212012202020022102222222021122202102212210112122202120200222222221102111222110211202201122120221122120022221120021111212222022202022202002002022221120112222010002012102202222120212222212112211012022002121011222222122200120201121120200000000202022022020022201221222000222102122222220222022212122101221002010000001022102222122221022202022222121202222200020212002222120121221201011221201220012102210122120022220202110012202001202200220212122001222102201002110120021202121202122022222212002222112002212220212011022222102120120012201022212200102002010122020122202100020100122101112211221201022220202121120110200120222112102222122122121222112212022012022101112022002222120101210222000121222220122110020122121222201002020022012001002212022210102012012121001210220122012102021202022222200212122002020022102020111110022222021000202002220010220111002221210122021122021010110202112011022201020221212220222011120120111111101112011202122021101202212022100002212211111011121221112001212200211222212112202201120122220122100200112011012002222212222202102212212122100222122212222002212222222222222222122022220102002001002211112220121020001200111121221021021102011222022022110201220212222201222210221200022212212100220110201101010202212222222022002222212222220012122210221121101222202121100210220222212100212102000022022022111121211121002110202211221202022100122220102011110011022012022222022020210202002202100102122111012121121220212000111211100011202202001002212022021222020202222001002010002220122200022000212221202212222010121012101212022021100202122202010011122122122210021020121120222112102200020112212222112110200001202012001211021122221001212102001222100220000202102210202100021000000100112021200210110221211122021212110202200211]] | |
function calc_image(layers_,width,height) | |
local pixel_map ={} | |
for y=1,height do | |
pixel_map[y]={} | |
end | |
pix_id = 1 | |
for y=1,height do | |
for x=1,width do | |
for id,lay in pairs(layers_) do | |
pix = lay:sub(pix_id,pix_id) | |
if pix ~= "2" then | |
--print("Calc id",pix,type(pix)) | |
pixel_map[y][x] = pix | |
break | |
end | |
end | |
pix_id=pix_id+1 | |
end | |
end | |
return pixel_map | |
end | |
local txt = real_input | |
local layers = split_to_layers(txt,25,6) | |
local min_0 =200000 | |
local min_idx = 9999999 | |
local sum_1_2 = 0 | |
for idx,layer in pairs(layers) do | |
local f0,f1,f2 = process_layer(layer) | |
if min_0 >= f0 then | |
min_0 =f0 | |
min_idx = idx | |
sum_1_2 = f1*f2 | |
--print(idx,min_0,f1,f2,sum_1_2) | |
end | |
end | |
-- part 2 calculate and draw the message ... | |
local img =calc_image(layers,25,6) | |
local cols ={ | |
{0,0,0}, | |
{1,1,1} | |
} | |
function love.draw() | |
--print(cols[1],cols[0]) | |
for y=1,6 do | |
for x =1,25 do | |
--print("test",tonumber(img[y][x])) | |
love.graphics.setColor(cols[ tonumber(img[y][x])+1]) | |
love.graphics.rectangle("fill",x*3,y*3,3,3) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment