Skip to content

Commit 5ea1184

Browse files
committed
finish one 5kyu,one 6kyu and one beta
1 parent b9d61f9 commit 5ea1184

7 files changed

+71
-10
lines changed

[5 kyu]RGB To Hex Conversion.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def rgb(r, g, b):
2+
r,g,b = [element if element <= 255 else 255 for element in (r,g,b)]
3+
r,g,b = [element if element >= 0 else 0 for element in (r,g,b)]
4+
return ''.join([hex(element)[2:].upper().zfill(2) for element in (r,g,b)])
5+
6+
print(rgb(255,255,300))
7+
print(rgb(1,2,3))
8+
print(rgb(0,0,0))

[6 kyu]Linear Regression of Y on X.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def regressionLine(x, y):
2+
sumSquareX = sum([n**2 for n in x])
3+
sumSquareY = sum([n**2 for n in y])
4+
sumX = sum(x)
5+
sumY = sum(y)
6+
sumXY = sum([X*Y for X,Y in zip(x,y)])
7+
a = ((sumSquareX*sumY) - (sumX*sumXY)) / float(((len(x) * sumSquareX) - sumX**2))
8+
b = ((len(x)*sumXY) - (sumX*sumY)) / float(((len(x)*sumSquareX) - sumX**2))
9+
a = round(a,4)
10+
b = round(b,4)
11+
return a,b
12+
13+
14+
15+
print(regressionLine([25,30,35,40,45,50], [78,70,65,58,48,42]))
16+
#(114.381, -1.4457)
17+
#a = [(Σx²)(Σy) - (Σx)(Σxy)] / [n(Σx²) - (Σx)²]
18+
#b = [n(Σxy) - (Σx)(Σy)] / [n(Σx²) - (Σx)²]

[beta]Mysterious function.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def get_num(n):
2+
return sum([2 if c == '8' else 1 for c in str(n) if c in ('0','6','8','9')])
3+
4+
print(get_num(300))

[leetcode]Add Binary

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
# @param {string} a
3+
# @param {string} b
4+
# @return {string}
5+
def addBinary(self, a, b):
6+

[leetcode]Add Binary.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
# @param {string} a
3+
# @param {string} b
4+
# @return {string}
5+
def addBinary(self, a, b):
6+
def binToDecimal(string):
7+
return sum([int(n) * (2**i) for i,n in enumerate(reversed(string),0)])
8+
return bin(binToDecimal(a) + binToDecimal(b))[2:]
9+
10+
test = Solution()
11+
print(test.addBinary('1','11'))

[leetcode]Excel Sheet Column Title.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
# @param {integer} n
3+
# @return {string}
4+
def convertToTitle(self, n):
5+
times = 0
6+
res = []
7+
while n >= 27:
8+
res.append(n % 27)
9+
n %= 27
10+
times += 1
11+
if times == 10000:
12+
break
13+
res.append(n)
14+
return res
15+
16+
test = Solution()
17+
for i in range(24,30):
18+
print(test.convertToTitle(i))

test.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
def substract7(n):
2-
res = [n]
3-
while n > 0:
4-
x = input('press cotinues')
5-
n -= 7
6-
print(n)
7-
8-
print(substract7(200))
9-
10-
b = 3
1+
if True:
2+
print('a')
3+
print('a')
4+
print('a')
5+
print('a')
6+

0 commit comments

Comments
 (0)