Posts

Showing posts from December, 2022

Robbie Hatley's Perl Solutions to The Weekly Challenge #197

This is my first post to my first blog on a brand new blogger acct; this seems as good a place to start as any. For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2022-12-25 through 2022-12-31) is weekly challenge #197. Part 1 is a simple task of moving all zeros in an array to the end without disturbing the order of the non-zero elements. Of course this could be done by simply copying all non-zero elements to a second array, then padding the end of the output array with sufficient zeros. But that felt like cheating, so I took a completely different approach and spliced-out the zeros (using "splice") and tacked them on the end (also using "splice") so that I could edit the array in-situ with no need for multiple arrays, like so: for (@lists){ my @list = @{$_}; # Input. my $z;