I have always wanted to do Advent of Code, but this year is when I actually understood the prompt being given. So, hence, I decided to give it a go.
EDIT: Deleted github repository for now until I fix up a few things.
I have always wanted to do Advent of Code, but this year is when I actually understood the prompt being given. So, hence, I decided to give it a go.
EDIT: Deleted github repository for now until I fix up a few things.
Day 5 looking really difficult to understand and do. Probably might not even be easily feasible in G’MIC with the input.
Day 6 Answer released - Deleted (See first post)
I love how cursed it looks.
I finally have solved Day 5 Part 2. What a PITA. But, I’m proud regardless.
Seems like a lot of hard work. Not of all of them are as bad a fit for g’mic as I imagined (some would work in a grid quite well), but probably not many people could check your code!
I finished on Day 8. Finding the Part 2 answer with LCM leads to breaking. How come G’MIC doesn’t have lcm yet? Or multiple variable GCD or LCM?
p2_ans = 922657
p2_ans = 67353961
p2_ans = 3973883699
p2_ans = -91983485980753
p2_ans = 1.9135324588576046e+18
So, I resorted to Python to calculate lcm of my values within G’MIC.
I think I’ll stop with the AoC here.
Here’s my result:
EDIT:
Looked up an alternative to the standard LCM formula. This code works in G’MIC:
#@cli advent_of_code_day_8_answer:
#@cli : Code to Day 8 Advent of Code.
advent_of_code_day_8:
it nodes
# 1. Parse string as parsable images
split -,{_'\n'}
last_var_index={$!-2}
fill[0] i==_'R'?1
name[0] directions
A,Z={'AZ'}
1 store. Aimg
1 store. Zimg
foreach[^directions] {
discard {_'\ '}
split -,{_'='}
{0,t}=$>
char:=i[#0,h#0-1]
if $char==$A
$Aimg
eval da_push(#-1,$>)
store. Aimg
fi
if $char==$Z
$Zimg
eval da_push(#-1,$>)
store. Zimg
fi
rm[0]
crop 0,1,0,{h-2}
}
foreach[^directions] {
split -,{_','}
(${{0,t}}^${{1,t}})
keep[-1]
}
append[^directions] x => nodes
# 2. Find answers
eval "
const directions=$directions;
const nodes=$nodes;
const starting_node=$AAA;
const node_to_reach=$ZZZ;
const length_of_LR_seq=h#directions;
p1_ans=pos=0;
current_node=starting_node;
while(current_node!=node_to_reach,
current_node=(I[#nodes,current_node])[i[#0,pos++]];
if(pos==length_of_LR_seq,pos=0;);
++p1_ans;
);
set('p1_ans',p1_ans);
"
$Aimg $Zimg da_freeze[-2--1]
append[-2--1] c
1,100%,1,1,:"begin(
const directions=$directions;
const nodes=$nodes;
const length_of_LR_seq=whd#directions;
);
current_node=i0#-1;
ending_nodes=crop(#-1,0,0,0,1,1,h#-1,1,1);
steps=pos=0;
while(find(ending_nodes,current_node,0,1)==-1,
test_node=I[#nodes,current_node];
current_node=test_node[i[#0,pos++]];
if(pos==length_of_LR_seq,pos=0;);
++steps;
);
"
eval "
const num_of_values=h#-1;
lcm(a,b)=(
if(a>b
,A=a;B=b;
,A=b;B=a;
);
lcm=A;
while(lcm%B,lcm+=A;);
lcm;
);
p2_ans=i[#-1,0];
for(p=1,p<num_of_values,++p,
p2_ans=lcm(p2_ans,i[#-1,p]);
);
set('p2_ans',p2_ans);
"
e[^-1] "Number of steps from AAA to ZZZ: "$p1_ans
e[^-1] "Number of steps for ghosts: "$p2_ans
rm
Someone needs to make a request, code or talk about it, which is what I do all the time: giving nudges and prods. Yeah, giving an example usually helps. Then, hopefully, David swoops in with a better implementation.