From c39ebd369255bd04aaa8c11fcadbc482a4d0d9fa Mon Sep 17 00:00:00 2001 From: Parnabrita Mondal <72441280+hitblunders@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:53:19 -0400 Subject: [PATCH 1/2] Adding pythagorean triplet problem --- GeeksforGeeks/pythagorean_triplet.py | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 GeeksforGeeks/pythagorean_triplet.py diff --git a/GeeksforGeeks/pythagorean_triplet.py b/GeeksforGeeks/pythagorean_triplet.py new file mode 100644 index 0000000..0e20698 --- /dev/null +++ b/GeeksforGeeks/pythagorean_triplet.py @@ -0,0 +1,51 @@ +'''Given an array arr of N integers +write a function that +returns true if there is a triplet (a, b, c) +that satisfies a2 + b2 = c2 +otherwise false''' + +import math + +def checkTriplet(arr, n): + mxm = 0 + + # finding maximum element + for element in arr: + mxm = max(mxm, element) + + # hashing array + hash = [0]*(mxm+1) + + for element in arr: + hash[element] += 1 + + for i in range(1, mxm+1): + if hash[i] == 0: + continue + + for j in range(1, mxm+1): + if (i==j and hash[i]==1) or hash[j]==0: + continue + + val = int(math.sqrt(i*i+j*j)) + if val*val != (i*i+j*j): + continue + if val>mxm: + continue + if hash[val]: + return True + return False + +'''n = int(input()) +a = list(map(int,input().split()))''' + +N = 5 +Arr = [3, 2, 4, 6, 5] + +# N = 3 +# Arr = [3, 8, 5] + +if checkTriplet(Arr, N): + print("Yes") +else: + print("No") \ No newline at end of file From 7f7ec3edbe372f4cd114c1889df0533b5c66abed Mon Sep 17 00:00:00 2001 From: Parnabrita Mondal <72441280+hitblunders@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:04:26 -0400 Subject: [PATCH 2/2] Adding roman to integer conversion problem --- GeeksforGeeks/roman_to_integer.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 GeeksforGeeks/roman_to_integer.py diff --git a/GeeksforGeeks/roman_to_integer.py b/GeeksforGeeks/roman_to_integer.py new file mode 100644 index 0000000..8c76e99 --- /dev/null +++ b/GeeksforGeeks/roman_to_integer.py @@ -0,0 +1,41 @@ +''' +Input: +The first line of each test case contains the no of test cases T +Then T test cases follow. Each test case contains a string s denoting the roman no + +Output: +For each test case in a new line print the integer representation of roman number s +''' + +def roman_to_int(roman): + value = { + 'I': 1, + 'V': 5, + 'X': 10, + 'L': 50, + 'C': 100, + 'D': 500, + 'M': 1000 + } + + prev = 0 + ans = 0 + n = len(roman) + for i in range(n-1, -1, -1): + if value[roman[i]] >= prev: + ans += value[roman[i]] + else: + ans -= value[roman[i]] + + prev = value[roman[i]] + + print(ans) +'''for _ in range(int(input())): + s = input() + roman_to_int(s) +''' +# s = 'V' +# s = 'III' +s = 'XIV' + +roman_to_int(s)