-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1b5c35
commit 79f48cd
Showing
9 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Staircase | ||
# https://www.hackerrank.com/challenges/staircase/problem?isFullScreen=true | ||
|
||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'staircase' function below. | ||
# | ||
# The function accepts INTEGER n as parameter. | ||
# | ||
|
||
def staircase(n): | ||
space = ' ' | ||
hashtag = '#' | ||
|
||
for i in range(1,n+1): | ||
print(f'{space * (n-i)}{hashtag * i}') | ||
|
||
if __name__ == '__main__': | ||
n = int(input().strip()) | ||
|
||
staircase(n) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'miniMaxSum' function below. | ||
# | ||
# The function accepts INTEGER_ARRAY arr as parameter. | ||
# | ||
|
||
def miniMaxSum(arr): | ||
min_sum = sum(arr) - max(arr) | ||
max_sum = sum(arr) - min(arr) | ||
print(f'{min_sum} {max_sum}') | ||
|
||
if __name__ == '__main__': | ||
|
||
arr = list(map(int, input().rstrip().split())) | ||
|
||
miniMaxSum(arr) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'miniMaxSum' function below. | ||
# | ||
# The function accepts INTEGER_ARRAY arr as parameter. | ||
# | ||
|
||
def miniMaxSum(arr): | ||
sum = min = max = arr[0] | ||
for n in arr[1:]: | ||
if n < min: | ||
min = n | ||
elif n > max: | ||
max = n | ||
sum += n | ||
print(f"{sum-max} {sum-min}") | ||
|
||
if __name__ == '__main__': | ||
|
||
arr = list(map(int, input().rstrip().split())) | ||
|
||
miniMaxSum(arr) |
32 changes: 32 additions & 0 deletions
32
python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'birthdayCakeCandles' function below. | ||
# | ||
# The function is expected to return an INTEGER. | ||
# The function accepts INTEGER_ARRAY candles as parameter. | ||
# | ||
|
||
def birthdayCakeCandles(candles): | ||
candles.sort() | ||
tallest = candles[-1] | ||
return candles.count(tallest) | ||
|
||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
candles_count = int(input().strip()) | ||
|
||
candles = list(map(int, input().rstrip().split())) | ||
|
||
result = birthdayCakeCandles(candles) | ||
|
||
fptr.write(str(result) + '\n') | ||
|
||
fptr.close() |
38 changes: 38 additions & 0 deletions
38
python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles2.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'birthdayCakeCandles' function below. | ||
# | ||
# The function is expected to return an INTEGER. | ||
# The function accepts INTEGER_ARRAY candles as parameter. | ||
# | ||
|
||
def birthdayCakeCandles(candles): | ||
count = 1 | ||
tallest = candles[0] | ||
for i in candles[1:]: | ||
if i == tallest: | ||
count += 1 | ||
elif i > tallest: | ||
tallest = i | ||
count = 1 | ||
return count | ||
|
||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
candles_count = int(input().strip()) | ||
|
||
candles = list(map(int, input().rstrip().split())) | ||
|
||
result = birthdayCakeCandles(candles) | ||
|
||
fptr.write(str(result) + '\n') | ||
|
||
fptr.close() |
42 changes: 42 additions & 0 deletions
42
python/practice-together/009-timeConversion/timeConversion.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'gradingStudents' function below. | ||
# | ||
# The function is expected to return an INTEGER_ARRAY. | ||
# The function accepts INTEGER_ARRAY grades as parameter. | ||
# | ||
|
||
def gradingStudents(grades): | ||
grades_after_round = [] | ||
for i in grades: | ||
if i < 38: | ||
grades_after_round.append(i) | ||
elif 5 - i % 5 < 3: | ||
grades_after_round.append(i + 5 - i % 5) | ||
else: | ||
grades_after_round.append(i) | ||
return grades_after_round | ||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
grades_count = int(input().strip()) | ||
|
||
grades = [] | ||
|
||
for _ in range(grades_count): | ||
grades_item = int(input().strip()) | ||
grades.append(grades_item) | ||
|
||
result = gradingStudents(grades) | ||
|
||
fptr.write('\n'.join(map(str, result))) | ||
fptr.write('\n') | ||
|
||
fptr.close() |
40 changes: 40 additions & 0 deletions
40
python/practice-together/010- gradingStudents/gradingStudents.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'timeConversion' function below. | ||
# | ||
# The function is expected to return a STRING. | ||
# The function accepts STRING s as parameter. | ||
# | ||
|
||
def timeConversion(s): | ||
AM_or_PM = s[-2:] | ||
hour = s[:2] | ||
if AM_or_PM == "AM": | ||
if hour == "12": | ||
s = "00" + s[2:-2] | ||
else: | ||
s = s[:-2] | ||
elif AM_or_PM == "PM": | ||
if hour == "12": | ||
s = "12" + s[2:-2] | ||
else: | ||
s = str(int(hour) + 12) + s[2:-2] | ||
return s | ||
|
||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
s = input() | ||
|
||
result = timeConversion(s) | ||
|
||
fptr.write(result + '\n') | ||
|
||
fptr.close() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'kangaroo' function below. | ||
# | ||
# The function is expected to return a STRING. | ||
# The function accepts following parameters: | ||
# 1. INTEGER x1 | ||
# 2. INTEGER v1 | ||
# 3. INTEGER x2 | ||
# 4. INTEGER v2 | ||
# | ||
|
||
def kangaroo(x1, v1, x2, v2): | ||
if x1 < x2 and v1 <= v2: | ||
return 'NO' | ||
elif x1 > x2 and v1 >= v2: | ||
return 'NO' | ||
elif (x1 - x2) % (v2 - v1) != 0: | ||
return 'NO' | ||
else: | ||
return 'YES' | ||
|
||
|
||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
first_multiple_input = input().rstrip().split() | ||
|
||
x1 = int(first_multiple_input[0]) | ||
|
||
v1 = int(first_multiple_input[1]) | ||
|
||
x2 = int(first_multiple_input[2]) | ||
|
||
v2 = int(first_multiple_input[3]) | ||
|
||
result = kangaroo(x1, v1, x2, v2) | ||
|
||
fptr.write(result + '\n') | ||
|
||
fptr.close() |
43 changes: 43 additions & 0 deletions
43
python/practice-together/012-breakingRecords/breakingRecords.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/python3 | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# | ||
# Complete the 'breakingRecords' function below. | ||
# | ||
# The function is expected to return an INTEGER_ARRAY. | ||
# The function accepts INTEGER_ARRAY scores as parameter. | ||
# | ||
|
||
def breakingRecords(scores): | ||
highest_record = scores[0] | ||
lowest_record = scores[0] | ||
count_break_highest = 0 | ||
count_break_lowest = 0 | ||
for i in range(1, len(scores)): | ||
if scores[i] > highest_record: | ||
highest_record = scores[i] | ||
count_break_highest += 1 | ||
elif scores[i] < lowest_record: | ||
lowest_record = scores[i] | ||
count_break_lowest += 1 | ||
return count_break_highest, count_break_lowest | ||
|
||
|
||
if __name__ == '__main__': | ||
fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
|
||
n = int(input().strip()) | ||
|
||
scores = list(map(int, input().rstrip().split())) | ||
|
||
result = breakingRecords(scores) | ||
|
||
fptr.write(' '.join(map(str, result))) | ||
fptr.write('\n') | ||
|
||
fptr.close() |