1 #!/usr/bin/perl
2
3
4
5
6
7
8 use strict;
9 use warnings;
10
11
12 my $inputs = [
13 [1, 0, 3, 0, 0, 5],
14 [1, 6, 4],
15 [0, 1, 0, 2, 0]
16 ];
17
18
19 foreach my $input (@$inputs) {
20 print "(" . join(", ", @$input) . ") returns (" . join(", ", move_zero(@$input)) . ")\n";
21 }
22
23
24 sub move_zero {
25 my @values = @_;
26 my @return = ();
27 my @tmp = ();
28
29 foreach my $elem (@values) {
30 if($elem == 0) {
31 push @tmp, $elem;
32 } else {
33 push @return, $elem;
34 }
35 }
36
37 push @return, @tmp;
38 return @return;
39 }