Mars Exploration

  • + 0 comments

    Perl solution:

    sub marsExploration {
        my $s = shift;
        
        my @arr = split("", $s);
        my $cnt = 0;
        for (my $i = 0; $i <= scalar(@arr) - 1; $i += 3) {
            $cnt++ if ($arr[$i] ne "S");
            $cnt++ if ($arr[$i+1] ne "O");
            $cnt++ if ($arr[$i+2] ne "S");
        }
        
        return $cnt
    }