#!/usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };useList::Utilqw{ sum };my@n=split' ',<>;sub process{my($pos,$sum)=@_;my$child_tally=$n[$pos++];my$data_size=$n[$pos++];for(1..$child_tally){my$ch=process($pos,$sum);$sum=$ch->[1];$pos=$ch->[0];}$sum+=sum(0,@n[$pos..$pos+$data_size-1]);$pos+=$data_size;return[$pos,$sum];}sayprocess(0,0)->[1];
Part 2
#!/usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };useList::Utilqw{ sum };my@n=split' ',<>;sub process{my($pos,$sum)=@_;my$child_tally=$n[$pos++];my$data_size=$n[$pos++];my@ch;for(1..$child_tally){my$ch=process($pos,$sum);push@ch,$ch->[1];$pos=$ch->[0];}if($child_tally){$sum+=sum(map{$ch[$_-1]//0}@n[$pos..$pos+$data_size-1]);}else{my$v=sum(@n[$pos..$pos+$data_size-1]);$sum+=$v;}$pos+=$data_size;return[$pos,$sum];}sayprocess(0,0)->[1];
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
And here are my Perl solutions:
Part 1
Part 2