Skip to content

Commit

Permalink
Merge pull request #51 from HighnessAtharva/master
Browse files Browse the repository at this point in the history
imports sorted and code formatted
  • Loading branch information
arsho committed Feb 7, 2023
2 parents c462100 + c30fda0 commit 18467c8
Show file tree
Hide file tree
Showing 95 changed files with 605 additions and 475 deletions.
3 changes: 1 addition & 2 deletions BasicDataTypes/Findingthepercentage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Updated : 06 February 2023
Problem : https://www.hackerrank.com/challenges/finding-the-percentage/problem
"""
if __name__ == '__main__':
if __name__ == "__main__":
n = int(input())
student_marks = {}
for _ in range(n):
Expand All @@ -17,4 +17,3 @@
query_name = input()
avg_score = sum(student_marks[query_name]) / len(student_marks[query_name])
print(f"{avg_score:.2f}")

2 changes: 1 addition & 1 deletion BasicDataTypes/FindtheSecondLargestNumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem
"""
if __name__ == '__main__':
if __name__ == "__main__":
n = int(input())
arr = map(int, input().split())
print(sorted(set(arr), reverse=True)[1])
11 changes: 8 additions & 3 deletions BasicDataTypes/ListComprehensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
Created : 06 July 2020
Problem : https://www.hackerrank.com/challenges/list-comprehensions/problem
"""
if __name__ == '__main__':
if __name__ == "__main__":
x = int(input())
y = int(input())
z = int(input())
n = int(input())
ar = [[i, j, k] for i in range(x + 1) for j in range(y + 1)
for k in range(z + 1) if i + j + k != n]
ar = [
[i, j, k]
for i in range(x + 1)
for j in range(y + 1)
for k in range(z + 1)
if i + j + k != n
]
print(ar)
2 changes: 1 addition & 1 deletion BasicDataTypes/Lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Problem : https://www.hackerrank.com/challenges/python-lists/problem
"""

if __name__ == '__main__':
if __name__ == "__main__":
N = int(input())
ar = []
for i in range(N):
Expand Down
7 changes: 4 additions & 3 deletions BasicDataTypes/NestedLists.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Created : 06 July 2020
Problem : https://www.hackerrank.com/challenges/nested-list/problem
"""
if __name__ == '__main__':
if __name__ == "__main__":
students = []
scores = []
for _ in range(int(input())):
Expand All @@ -16,6 +16,7 @@
students.append(student)
scores.append(score)
second_min_score = sorted(set(scores))[1]
student_names = sorted([student[0] for student in students
if student[1] == second_min_score])
student_names = sorted(
[student[0] for student in students if student[1] == second_min_score]
)
print("\n".join(student_names))
2 changes: 1 addition & 1 deletion BasicDataTypes/Tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Created : 06 July 2020
Problem : https://www.hackerrank.com/challenges/python-tuples/problem
"""
if __name__ == '__main__':
if __name__ == "__main__":
n = int(input())
integer_list = map(int, input().split())
t = tuple(integer_list)
Expand Down
6 changes: 3 additions & 3 deletions BuiltIns/AnyorAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Title : Any or All
Subdomain : Built-Ins
Domain : Python
Expand All @@ -7,7 +7,7 @@
Created : 15 July 2016
Updated : 29 August 2022
Problem : https://www.hackerrank.com/challenges/any-or-all/problem
'''
"""
n = input()
ar = input().split()
print(all([int(i)>0 for i in ar]) and any([i==i[::-1] for i in ar]))
print(all([int(i) > 0 for i in ar]) and any([i == i[::-1] for i in ar]))
12 changes: 6 additions & 6 deletions BuiltIns/AthleteSort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Title : Athlete Sort
Subdomain : Built-Ins
Domain : Python
Expand All @@ -7,17 +7,17 @@
Created : 3 April 2021
Updated : 30 August 2022
Problem : https://www.hackerrank.com/challenges/python-sort-sort/problem
'''
"""

if __name__ == '__main__':
if __name__ == "__main__":
n, m = map(int, input().split())

arr = []

for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))

k = int(input())
for i in sorted(arr, key= lambda x: x[k]):

for i in sorted(arr, key=lambda x: x[k]):
print(*i)
4 changes: 2 additions & 2 deletions BuiltIns/Input.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'''
"""
Title : Input()
Subdomain : Built-Ins
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Updated : 3 April 2021
Problem : https://www.hackerrank.com/challenges/input/problem
'''
"""

if __name__ == "__main__":
x, k = map(int, input().strip().split())
Expand Down
4 changes: 2 additions & 2 deletions BuiltIns/PythonEvaluation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'''
"""
Title : Python Evaluation
Subdomain : Built-Ins
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/python-eval/problem
'''
"""
eval(input())
6 changes: 3 additions & 3 deletions BuiltIns/Zipped.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Title : Zipped!
Subdomain : Built-Ins
Domain : Python
Expand All @@ -7,11 +7,11 @@
Created : 15 July 2016
Updated : 30 August 2022
Problem : https://www.hackerrank.com/challenges/zipped/problem
'''
"""

N, X = map(int, input().split())
scores = []
for _ in range(X):
scores.append(list(map(float, input().split())))
for i in zip(*scores):
print(sum(i)/len(i))
print(sum(i) / len(i))
19 changes: 16 additions & 3 deletions BuiltIns/ginortS.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Title : ginortS
Subdomain : Built-Ins
Domain : Python
Expand All @@ -7,7 +7,20 @@
Created : 15 July 2016
Updated : 29 August 2022
Problem : https://www.hackerrank.com/challenges/ginorts/problem
'''
"""

s = input()
print(''.join(sorted(s, key=lambda x: (x.isdigit() and int(x)%2==0, x.isdigit(), x.isupper(), x.islower(), x))))
print(
"".join(
sorted(
s,
key=lambda x: (
x.isdigit() and int(x) % 2 == 0,
x.isdigit(),
x.isupper(),
x.islower(),
x,
),
)
)
)
25 changes: 16 additions & 9 deletions Classes/Class2FindtheTorsionalAngle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math


'''
"""
Title : Class 2 - Find the Torsional Angle
Subdomain : Classes
Domain : Python
Expand All @@ -10,7 +9,8 @@
Created : 15 July 2016
Updated : 30 August 2022
Problem : https://www.hackerrank.com/challenges/class-2-find-the-torsional-angle/problem
'''
"""


class Points:
def __init__(self, x, y, z):
Expand All @@ -22,24 +22,31 @@ def __sub__(self, other):
return Points(self.x - other.x, self.y - other.y, self.z - other.z)

def dot(self, other):
return self.x * other.x + self.y * other.y + self.z * other.z
return self.x * other.x + self.y * other.y + self.z * other.z

def absolute(self):
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)

def cross(self, other):
return Points(self.y * other.z - self.z * other.y,
return Points(
self.y * other.z - self.z * other.y,
self.z * other.x - self.x * other.z,
self.x * other.y - self.y * other.x)
self.x * other.y - self.y * other.x,
)


if __name__ == '__main__':
if __name__ == "__main__":
points = list()
for i in range(4):
a = list(map(float, input().split()))
points.append(a)

a, b, c, d = Points(*points[0]), Points(*points[1]), Points(*points[2]), Points(*points[3])
a, b, c, d = (
Points(*points[0]),
Points(*points[1]),
Points(*points[2]),
Points(*points[3]),
)
x = (b - a).cross(c - b)
y = (c - b).cross(d - c)
angle = math.acos(x.dot(y) / (x.absolute() * y.absolute()))
Expand Down
36 changes: 21 additions & 15 deletions Classes/ClassesDealingwithComplexNumbers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Title : Classes: Dealing with Complex Numbers
Subdomain : Classes
Domain : Python
Expand All @@ -7,31 +7,36 @@
Created : 15 July 2016
Updated : 30 August 2022
Problem : https://www.hackerrank.com/challenges/class-1-dealing-with-complex-numbers/problem
'''
"""
import math



class Complex():
class Complex:
def __init__(self, real, imaginary):
self.real = real
self.imaginary = imaginary

def __add__(self, no):
return Complex(self.real + no.real, self.imaginary + no.imaginary)

def __sub__(self, no):
return Complex(self.real - no.real, self.imaginary - no.imaginary)

def __mul__(self, no):
return Complex(self.real * no.real - self.imaginary * no.imaginary, self.real * no.imaginary + self.imaginary * no.real)
return Complex(
self.real * no.real - self.imaginary * no.imaginary,
self.real * no.imaginary + self.imaginary * no.real,
)

def __truediv__(self, no):
divider = no.real ** 2 + no.imaginary ** 2
return Complex((self.real * no.real + self.imaginary * no.imaginary)/divider, (self.imaginary * no.real - self.real * no.imaginary)/divider)

divider = no.real**2 + no.imaginary**2
return Complex(
(self.real * no.real + self.imaginary * no.imaginary) / divider,
(self.imaginary * no.real - self.real * no.imaginary) / divider,
)

def mod(self):
return Complex(math.sqrt(self.real ** 2 + self.imaginary ** 2), 0.00)
return Complex(math.sqrt(self.real**2 + self.imaginary**2), 0.00)

def __str__(self):
if self.imaginary == 0:
Expand All @@ -46,10 +51,11 @@ def __str__(self):
else:
result = "%.2f-%.2fi" % (self.real, abs(self.imaginary))
return result

if __name__ == '__main__':


if __name__ == "__main__":
c = map(float, input().split())
d = map(float, input().split())
x = Complex(*c)
y = Complex(*d)
print(*map(str, [x+y, x-y, x*y, x/y, x.mod(), y.mod()]), sep='\n')
print(*map(str, [x + y, x - y, x * y, x / y, x.mod(), y.mod()]), sep="\n")
15 changes: 10 additions & 5 deletions ClosuresandDecorators/Decorators2NameDirectory.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
'''
"""
Title : Decorators 2 - Name Directory
Subdomain : Closures and Decorators
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Updated : 3 April 2021
Problem : https://www.hackerrank.com/challenges/decorators-2-name-directory/problem
'''
"""

import operator


def person_lister(func):
def inner(people):
return [func(p) for p in sorted(people, key = lambda x: (int(x[2])))]
return [func(p) for p in sorted(people, key=lambda x: (int(x[2])))]

return inner


@person_lister
def name_format(person):
return ("Mr. " if person[3] == "M" else "Ms. ") + person[0] + " " + person[1]

if __name__ == '__main__':

if __name__ == "__main__":
people = [input().split() for i in range(int(input()))]
print(*name_format(people), sep='\n')
print(*name_format(people), sep="\n")
18 changes: 10 additions & 8 deletions Collections/CollectionsOrderedDict.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
'''
"""
Title : Collections.OrderedDict()
Subdomain : Collections
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/py-collections-ordereddict/problem
'''
import collections, re
"""
import collections
import re

n = int(input())
item_od = collections.OrderedDict()
for i in range(n):
record_list = re.split(r'(\d+)$',input().strip())
record_list = re.split(r"(\d+)$", input().strip())
item_name = record_list[0]
item_price = int(record_list[1])
if item_name not in item_od:
item_od[item_name]=item_price
item_od[item_name] = item_price
else:
item_od[item_name]=item_od[item_name]+item_price
item_od[item_name] = item_od[item_name] + item_price

for i in item_od:
print(i+str(item_od[i]))
print(i + str(item_od[i]))
Loading

0 comments on commit 18467c8

Please sign in to comment.