perl -E'@x=split//,"4335443554366887798866555766";$_=<>;chop;print;while($_-4){split//,"99aabb87780";$x=0;$x+=hex(pop)*!!$&+($1&&$x[$1]+7)+($2>1?$x[$2+18]+$x[$3]:$x[$2.$3])while s/(.??)(.?)(.)$//;say" is $x.";print$_=$x}say" is magic."'
__END__
999999999999999999999999999999999
999999999999999999999999999999999 is 231.
231 is 19.
19 is 8.
8 is 5.
5 is 4.
4 is magic.