-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
99 lines (78 loc) · 1.96 KB
/
Copy pathcode.py
File metadata and controls
99 lines (78 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# --------------
#Code starts here
import sys
def palindrome(num):
for i in range(num+1,sys.maxsize):
if str(i) == str(i)[::-1]:
return i
palindrome(2345)
# --------------
#Code starts here
def a_scramble(str_1,str_2):
str_1 = list(str_1.lower())
str_2 = list(str_2.lower())
for i in range(0, len(str_2)):
if str_2[i] in str_1:
str_1.remove(str_2[i])
if i == len(str_2) - 1:
return True
else:
return False
print(a_scramble("Tom Marvolo Riddle","Voldemort"))
print(a_scramble("ticket","chat"))
print(a_scramble("labratory","Bat"))
# --------------
#Code starts here
def check_fib(num):
num1 = 0
num2 = 1
num3 = 0
while num>num3:
num3 = num1 + num2
if num==num3:
return True
elif num<num3:
return False
num1=num2
num2=num3
print(check_fib(145))
print(check_fib(377))
print(check_fib(456))
# --------------
#Code starts here
def compress(word):
word=word.lower()
result = ""
count = 1
#Add in first character
result += word[0]
#Iterate through loop, skipping last one
for i in range(len(word)-1):
if(word[i] == word[i+1]):
count+=1
else:
result += str(count)
result += word[i+1]
count = 1
result += str(count)
return result
print(compress("abbs"))
print(compress("xxcccdex"))
print(compress('Ss'))
print(compress('banana'))
print(compress('ssggtts'))
# --------------
#Code starts here
def k_distinct(string,k):
string = string.lower()
unique = []
for char in string[::]:
if char not in unique:
unique.append(char)
count = len(unique)
if count==k:
return True
else:
return False
print(k_distinct('Messoptamia',8))
print(k_distinct('banana',4))