4 ms·
The provided perl is a little dated: $x = &z(1, 100, 3); sub z{ $a = $_[0]; $b = $_[1]; $c = $_[2]; $d = 0.0; $e = 0.0; for (
by m0shen 15y ago
The provided perl is a little dated:
$x = &z(1, 100, 3);
sub z{
$a = $_[0];
$b = $_[1];
$c = $_[2];
$d = 0.0;
$e = 0.0;
for ($i = $a; $i <= $b; $i++){
if($i % $c == 0) {
$d = $d + 1;
}
else {
$e = $e + 1;
}
}
if($d > $e) {
$d;
}
else {
$e;
}
}
Fixed?
$x = z(1, 100, 3);
sub z{
my( $a, $b, $c ) = @_;
my $d = 0;
my $e = 0;
for ($a..$b){
if($_ % $c == 0) {
$d++;
}
else {
$e++;
}
}
if($d > $e) {
return $d;
}
else {
return $e;
}
}
- kokey 15y agoThis also clearly reminds me of one of the uses of perl. It's nice to use for prototyping something that can be implemented in ANSI C when necessary.