Jumping on the Clouds: Revisited

Sort by

recency

|

1173 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/retgbr5jSsg

    int jumpingOnClouds(vector<int> c, int k) {
        int position = 0, energie = 100;
        do{
            position = (position + k) % c.size();
            energie -= 1 + c[position] * 2;
        }while(position != 0);
        return energie;
    }
    
  • + 0 comments
    def jumpingOnClouds(n, c, k):
        e = 100
        i = 0
        while True:
            i = (i + k) % n
            e -= 1 + 2 * c[i]
            if i == 0:
                break
        return e
    
  • + 0 comments
    function jumpingOnClouds(c, k) {
        let n = c.length, energy = 100; 
        let index = 0; 
        
        do {
            energy -= c[index] === 1 ? 3 : 1;
            index = (index + k ) % n; 
        }while(index !== 0);
        
        return energy;  
    }
    
  • + 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;
    }
    
  • + 0 comments
    total,i,e=0,0,100
        for _ in range(17):
          e-=3 if c[(i+k)%n] else 1
          if (i+k)%n==0:
            break
          i+=k
        return e