# HackerRank ‘Jumping on the Clouds: Revisited’ Solution

##### Short Problem Definition:

Aerith is playing a cloud game! In this game, there are clouds numbered sequentially from 1 to n. Each cloud is either an ordinary cloud or a thundercloud. Given the values of n and k the configuration of the clouds, can you determine the final value of e after the game ends?

Jumping on the Clouds: Revisited

##### Complexity:

time complexity is O(N)

space complexity is O(1)

##### Execution:

Simulate the game in a loop.

##### Solution:
```#!/bin/python

def solveCloudRevisited(c, n, k):
pos = 0
cnt = 0

while cnt == 0 or pos != 0:
pos += k
pos %= n
if c[pos] == 0:
cnt += 1
else:
cnt += 3

return 100 - cnt

if __name__ == '__main__':
n,k = map(int,raw_input().strip().split(' '))
c = map(int,raw_input().strip().split(' '))
print solveCloudRevisited(c, n, k)
```

[rust]
use std::io;

fn get_numbers() -&gt; Vec&lt;u32&gt; {
let mut line = String::new();
line.split_whitespace().map(|s| s.parse::&lt;u32&gt;().unwrap()).collect()
}

fn calculate_jumping(a: Vec&lt;u32&gt;, n: usize, k: usize) -&gt; u32 {
let mut e = 0;
let mut pos = 0;

while e == 0 || pos != 0 {
e += match a[pos] {
0 =&gt; 1,
1 =&gt; 3,
_ =&gt; panic!("invalid input"),
};

pos += k;
pos %= n;
}

100 – e
}

fn main() {
let line = get_numbers();
let (n, k) = (line, line);
let a = get_numbers();
println!("{}", calculate_jumping(a, n as usize, k as usize) );
}
[/rust]

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.