Jumping on the Clouds: Revisited

  • + 0 comments

    PHP

    function jumpingOnClouds($c, $k) {
        $energy = 100;
        $n = sizeof($c);
        $cloud = 0;
        
        do {
            $cloud = ($cloud + $k) % $n;
            if ($c[$cloud] == 1) {
                $energy = $energy - 3;
            } else {
                $energy--;
            }
        } while($cloud != 0);
        
        return $energy;
    }