Last active
May 21, 2019 13:31
-
-
Save svmihar/3b000d72a02a0ed07d9d41164bf9df95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" def f(arr1, arr2): | |
k = arr2[3] | |
ct = 0 | |
while k > arr2[2]-1: | |
if (arr1[k] <= arr2[1] and not arr1[k] <= arr2[0]): | |
ct = ct + 1 | |
k = k - 1 | |
return ct | |
if __name__ == "__main__": | |
x = [11,10,10,5,10,15,20,10,7,11] | |
soal1 = [8,18,3,6] | |
soal2 = [10,20,0,9] | |
soal3 = [8,18,6,3] | |
soal4 = [20,10,0,9] | |
soal5 = [6,7,8,8] | |
kumpulan = [soal1, soal2, soal3, soal4, soal5] | |
for soal in kumpulan: | |
print(f(x, soal)) | |
""" | |
################################################## | |
def g(str): | |
i = 0 | |
new_str = "" | |
while i < len(str) -1: | |
new_str = new_str + str[i+1] | |
i = i+1 | |
return new_str | |
def f(str): | |
if len(str) == 0: | |
return "" | |
elif len(str) == 1: | |
return str | |
else: | |
return (f(g(str)) + str[0]) | |
def h(n, str): | |
i= 0 | |
while n != 1: | |
i+=1 | |
# print(f'{n}') | |
if n%2 == 0: | |
n = n/2 | |
else: | |
n = 3*n + 1 | |
str = f(str) | |
print(f'diulang {i} kali') | |
return str | |
def pow(x,y): | |
if y == 0: | |
return 1 | |
else: | |
return x**y | |
def fast_power(base, power): | |
""" | |
Returns the result of a^b i.e. a**b | |
We assume that a >= 1 and b >= 0 | |
Remember two things! | |
- Divide power by 2 and multiply base to itself (if the power is even) | |
- Decrement power by 1 to make it even and then follow the first step | |
""" | |
result = 1 | |
while power > 0: | |
# If power is even | |
if power % 2 == 0: | |
# Divide the power by 2 | |
power = power // 2 | |
# Multiply base to itself | |
base = base * base | |
else: | |
# Decrement the power by 1 and make it even | |
power = power - 1 | |
# Take care of the extra value that we took out | |
# We will store it directly in result | |
result = result * base | |
# Now power is even, so we can follow our previous procedure | |
power = power // 2 | |
base = base * base | |
return result | |
print(g('fruits')) | |
print(f('asyu')) | |
hasil = [] | |
for i in [1,2,5,fast_power(2,1000000000000000), fast_power(2, 9831050005000007)]: | |
print(f"sekarang {i}. {h(i,'fruits')} ") | |
print('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment