From 79f48cd7ef6387ec600e9830fb8d86d625827da4 Mon Sep 17 00:00:00 2001 From: Chance Date: Wed, 1 May 2024 04:17:36 -0400 Subject: [PATCH] Update to 12 --- .../006-staircase/staircase.py | 28 +++++++++++ .../007-miniMaxSum/miniMaxSum.py | 24 ++++++++++ .../007-miniMaxSum/miniMaxSum2.py | 29 +++++++++++ .../birthdayCakeCandles.py | 32 +++++++++++++ .../birthdayCakeCandles2.py | 38 +++++++++++++++ .../009-timeConversion/timeConversion.py | 42 ++++++++++++++++ .../010- gradingStudents/gradingStudents.py | 40 ++++++++++++++++ .../011-kangaroo/kangaroo.py | 48 +++++++++++++++++++ .../012-breakingRecords/breakingRecords.py | 43 +++++++++++++++++ 9 files changed, 324 insertions(+) create mode 100644 python/practice-together/006-staircase/staircase.py create mode 100644 python/practice-together/007-miniMaxSum/miniMaxSum.py create mode 100644 python/practice-together/007-miniMaxSum/miniMaxSum2.py create mode 100644 python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles.py create mode 100644 python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles2.py create mode 100644 python/practice-together/009-timeConversion/timeConversion.py create mode 100644 python/practice-together/010- gradingStudents/gradingStudents.py create mode 100644 python/practice-together/011-kangaroo/kangaroo.py create mode 100644 python/practice-together/012-breakingRecords/breakingRecords.py diff --git a/python/practice-together/006-staircase/staircase.py b/python/practice-together/006-staircase/staircase.py new file mode 100644 index 0000000..a911041 --- /dev/null +++ b/python/practice-together/006-staircase/staircase.py @@ -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) diff --git a/python/practice-together/007-miniMaxSum/miniMaxSum.py b/python/practice-together/007-miniMaxSum/miniMaxSum.py new file mode 100644 index 0000000..2548214 --- /dev/null +++ b/python/practice-together/007-miniMaxSum/miniMaxSum.py @@ -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) diff --git a/python/practice-together/007-miniMaxSum/miniMaxSum2.py b/python/practice-together/007-miniMaxSum/miniMaxSum2.py new file mode 100644 index 0000000..4706df1 --- /dev/null +++ b/python/practice-together/007-miniMaxSum/miniMaxSum2.py @@ -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) diff --git a/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles.py b/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles.py new file mode 100644 index 0000000..56ecb48 --- /dev/null +++ b/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles.py @@ -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() diff --git a/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles2.py b/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles2.py new file mode 100644 index 0000000..30eb7ed --- /dev/null +++ b/python/practice-together/008-birthdayCakeCandles/birthdayCakeCandles2.py @@ -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() diff --git a/python/practice-together/009-timeConversion/timeConversion.py b/python/practice-together/009-timeConversion/timeConversion.py new file mode 100644 index 0000000..6a025fe --- /dev/null +++ b/python/practice-together/009-timeConversion/timeConversion.py @@ -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() diff --git a/python/practice-together/010- gradingStudents/gradingStudents.py b/python/practice-together/010- gradingStudents/gradingStudents.py new file mode 100644 index 0000000..5614758 --- /dev/null +++ b/python/practice-together/010- gradingStudents/gradingStudents.py @@ -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() diff --git a/python/practice-together/011-kangaroo/kangaroo.py b/python/practice-together/011-kangaroo/kangaroo.py new file mode 100644 index 0000000..e2c10aa --- /dev/null +++ b/python/practice-together/011-kangaroo/kangaroo.py @@ -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() diff --git a/python/practice-together/012-breakingRecords/breakingRecords.py b/python/practice-together/012-breakingRecords/breakingRecords.py new file mode 100644 index 0000000..853a9c7 --- /dev/null +++ b/python/practice-together/012-breakingRecords/breakingRecords.py @@ -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()