Solved cloud_jump and hiking
+72 · 2 files changed
-
Pyton_stuff/hackerRank/cloud_jump.py+35 −0 -
Pyton_stuff/hackerRank/hiking.py+37 −0
@@ -0,0 +1,35 @@ +#!/bin/python3 +#8/8 tests + +import math +import os +import random +import re +import sys + +# Complete the jumpingOnClouds function below. +def jumpingOnClouds(c): + min_jumps = 0 + all_clouds = len(c) + current_pos = 0 + while(current_pos != all_clouds): + print(all_clouds, current_pos) + if current_pos + 2 == all_clouds-1: + min_jumps += 1 + break + elif current_pos + 1 == all_clouds - 1: + min_jumps += 1 + break + elif c[current_pos + 2] == 0: + current_pos = current_pos + 2 + min_jumps += 1 + elif c[current_pos + 1] == 0: + current_pos = current_pos + 1 + min_jumps += 1 + + + return min_jumps + + +print("4=",jumpingOnClouds(list(map(int, "0 0 1 0 0 1 0".rstrip().split())))) +print("3=",jumpingOnClouds(list(map(int, "0 0 0 1 0 0".rstrip().split())))) @@ -0,0 +1,37 @@ +#21/21 test passed + +import math +import os +import random +import re +import sys + +# Complete the countingValleys function below. +def countingValleys(n, s): + valley_num = 0 + level = 0 + print(n, s) + for elem in range(n): + if s[elem] == "D": + level -= 1 + elif s[elem] == "U": + level += 1 + print(level) + if level == 0 and s[elem] == "U": + print(n,elem, s[elem]) + valley_num += 1 + return valley_num + +if __name__ == '__main__': + os.environ['OUTPUT_PATH'] = os.getcwd() + "\\outfile.log" + #fptr = open(os.environ['OUTPUT_PATH'], 'w') + + #n = int(input()) + n = 12 + #s = input() + s = "DDUUDDUDUUUD" + result = countingValleys(n, s) + + #fptr.write(str(result) + '\n') + print(str(result)) + #fptr.close()