Skip to content

Commit 0b4cbb2

Browse files
authored
Merge pull request #49 from imtiazpy/update-version
Upated python code version and modified solutions under BuiltIns subd…
2 parents 3a3f572 + b2964e7 commit 0b4cbb2

File tree

5 files changed

+58
-75
lines changed

5 files changed

+58
-75
lines changed

BuiltIns/AnyorAll.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,11 @@
33
Subdomain : Built-Ins
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6+
Updater : Imtiaz Ahmed
67
Created : 15 July 2016
8+
Updated : 29 August 2022
79
Problem : https://www.hackerrank.com/challenges/any-or-all/problem
810
'''
9-
n = int(input())
10-
ar = list(map(int,input().split()))
11-
ar = sorted(ar)
12-
if(ar[0]<=0):
13-
print(False)
14-
else:
15-
chk = False
16-
for i in ar:
17-
s = str(i)
18-
if (s==s[::-1]):
19-
chk = True
20-
break
21-
print(chk)
11+
n = input()
12+
ar = input().split()
13+
print(all([int(i)>0 for i in ar]) and any([i==i[::-1] for i in ar]))

BuiltIns/AthleteSort.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
Subdomain : Built-Ins
44
Domain : Python
55
Author : Atharva Shah
6+
Updater : Imtiaz Ahmed
67
Created : 3 April 2021
8+
Updated : 30 August 2022
79
Problem : https://www.hackerrank.com/challenges/python-sort-sort/problem
810
'''
911

10-
import sys
12+
if __name__ == '__main__':
13+
n, m = map(int, input().split())
1114

12-
if __name__ == "__main__":
13-
n, m = input().strip().split(' ')
14-
n, m = [int(n), int(m)]
1515
arr = []
16-
for arr_i in range(n):
17-
arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
18-
arr.append(arr_t)
19-
k = int(input().strip())
16+
17+
for _ in range(n):
18+
arr.append(list(map(int, input().rstrip().split())))
19+
20+
k = int(input())
2021

21-
sorted_arr = sorted(arr, key = lambda x : x[k])
22-
for row in sorted_arr:
23-
print(' '.join(str(y) for y in row))
22+
for i in sorted(arr, key= lambda x: x[k]):
23+
print(*i)

BuiltIns/Zipped.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
Subdomain : Built-Ins
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6+
Updater : Imtiaz Ahmed
67
Created : 15 July 2016
8+
Updated : 30 August 2022
79
Problem : https://www.hackerrank.com/challenges/zipped/problem
810
'''
9-
n, x = map(int,input().split())
10-
ar = [0 for i in range(n)]
11-
for i in range(x):
12-
temp_ar=list(map(float,input().split()))
13-
for j in range(n):
14-
ar[j] += temp_ar[j]
15-
for i in range(n):
16-
print(ar[i]/x)
11+
12+
N, X = map(int, input().split())
13+
scores = []
14+
for _ in range(X):
15+
scores.append(list(map(float, input().split())))
16+
for i in zip(*scores):
17+
print(sum(i)/len(i))

BuiltIns/ginortS.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
Subdomain : Built-Ins
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6+
Updater : Imtiaz Ahmed
67
Created : 15 July 2016
8+
Updated : 29 August 2022
79
Problem : https://www.hackerrank.com/challenges/ginorts/problem
810
'''
11+
912
s = input()
10-
s = sorted(s,key = lambda x:(x.isdigit() and int(x)%2==0, x.isdigit(),x.isupper(),x.islower(),x))
11-
print(*(s),sep = '')
13+
print(''.join(sorted(s, key=lambda x: (x.isdigit() and int(x)%2==0, x.isdigit(), x.isupper(), x.islower(), x))))
Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import math
2+
3+
14
'''
25
Title : Class 2 - Find the Torsional Angle
36
Subdomain : Classes
@@ -6,52 +9,37 @@
69
Created : 15 July 2016
710
Problem : https://www.hackerrank.com/challenges/class-2-find-the-torsional-angle/problem
811
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
11-
import math
12-
def custom_diff(a,b):
13-
res0 = a[0] - b[0]
14-
res1 = a[1] - b[1]
15-
res2 = a[2] - b[2]
16-
return [res0,res1,res2]
17-
18-
def dot_product(a,b):
19-
return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]
20-
21-
def abs_val(a):
22-
tmp_val=a[0]*a[0]+a[1]*a[1]+a[2]*a[2]
23-
return math.sqrt(tmp_val)
24-
25-
2612

27-
def cross(a, b):
28-
c = [a[1]*b[2] - a[2]*b[1],
29-
a[2]*b[0] - a[0]*b[2],
30-
a[0]*b[1] - a[1]*b[0]]
13+
class Points:
14+
def __init__(self, x, y, z):
15+
self.x = x
16+
self.y = y
17+
self.z = z
3118

32-
return c
19+
def __sub__(self, other):
20+
return Points(self.x - other.x, self.y - other.y, self.z - other.z)
3321

34-
a_str_ar=raw_input().strip().split()
35-
b_str_ar=raw_input().strip().split()
36-
c_str_ar=raw_input().strip().split()
37-
d_str_ar=raw_input().strip().split()
22+
def dot(self, other):
23+
return self.x * other.x + self.y * other.y + self.z * other.z
24+
25+
def absolute(self):
26+
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
3827

39-
a=list(map(float,a_str_ar))
40-
b=list(map(float,b_str_ar))
41-
c=list(map(float,c_str_ar))
42-
d=list(map(float,d_str_ar))
28+
def cross(self, other):
29+
return Points(self.y * other.z - self.z * other.y,
30+
self.z * other.x - self.x * other.z,
31+
self.x * other.y - self.y * other.x)
4332

44-
ab=custom_diff(b,a)
45-
bc=custom_diff(c,b)
46-
cd=custom_diff(d,c)
4733

48-
x=cross(ab,bc)
49-
y=cross(bc,cd)
50-
51-
cosphi_top=dot_product(x,y)
52-
cosphi_bottom=abs_val(x)*abs_val(y)
53-
cosphi=cosphi_top/cosphi_bottom
34+
if __name__ == '__main__':
35+
points = list()
36+
for i in range(4):
37+
a = list(map(float, input().split()))
38+
points.append(a)
5439

55-
res=math.degrees(math.acos(cosphi))
40+
a, b, c, d = Points(*points[0]), Points(*points[1]), Points(*points[2]), Points(*points[3])
41+
x = (b - a).cross(c - b)
42+
y = (c - b).cross(d - c)
43+
angle = math.acos(x.dot(y) / (x.absolute() * y.absolute()))
5644

57-
print "%.2f" %res
45+
print("%.2f" % math.degrees(angle))

0 commit comments

Comments
 (0)