From b2ea4c9dc861d0caf722bf8c58274714242efde7 Mon Sep 17 00:00:00 2001 From: Abhijeeth S <35632653+abhikmp@users.noreply.github.com> Date: Fri, 17 May 2019 23:11:24 +0530 Subject: [PATCH 1/4] LargestOfVeryLargeNumbers Finds the largest among two very large numbers of the form x^y. Numbers like 512^513 etc --- maths/LargestOfVeryLargeNumbers | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 maths/LargestOfVeryLargeNumbers diff --git a/maths/LargestOfVeryLargeNumbers b/maths/LargestOfVeryLargeNumbers new file mode 100644 index 000000000000..c367ede9c118 --- /dev/null +++ b/maths/LargestOfVeryLargeNumbers @@ -0,0 +1,29 @@ +#Author: Abhijeeth S + +import math + +def res(x,y): + if x and y !=0: + return y*math.log10(x) # We use the relation x^y = y*log10(x), where 10 is the base. + else: + if(x==0): # 0 raised to any number is 0 + return 0 + elif(y==0): + return 1 # any number raised to 0 is 1 + +# Reads two numbers from input and typecasts them to int using map function. +# Here x is the base and y is the power. +x1,y1 = map(int, input().split(',')) +x2,y2 = map(int, input().split(',')) + +# We find the log of each number, using the function res(), which takes two arguments. +res1=res(x1,y1) +res2=res(x2,y2) + +# We check for the largest number +if(res1>res2): + print("Largest number is",x1,'^',y1) +elif(res2>res1): + print("Largest number is", x2, '^', y2) +else: + print("Both are equal") From e4d4fd5c07beecc5e231535a4ec2cfb9d6901166 Mon Sep 17 00:00:00 2001 From: John Law Date: Mon, 29 Jul 2019 17:00:53 +0800 Subject: [PATCH 2/4] Rename LargestOfVeryLargeNumbers to LargestOfVeryLargeNumbers.py --- maths/{LargestOfVeryLargeNumbers => LargestOfVeryLargeNumbers.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename maths/{LargestOfVeryLargeNumbers => LargestOfVeryLargeNumbers.py} (100%) diff --git a/maths/LargestOfVeryLargeNumbers b/maths/LargestOfVeryLargeNumbers.py similarity index 100% rename from maths/LargestOfVeryLargeNumbers rename to maths/LargestOfVeryLargeNumbers.py From 0d7f2b304bce2c104244a346fc47f188caf3fdd3 Mon Sep 17 00:00:00 2001 From: Abhijeeth S Date: Mon, 29 Jul 2019 19:33:20 +0530 Subject: [PATCH 3/4] Input() statements have been indented. input() statements are indented under if __name__ == "__main__": --- maths/LargestOfVeryLargeNumbers.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/maths/LargestOfVeryLargeNumbers.py b/maths/LargestOfVeryLargeNumbers.py index c367ede9c118..000b1ed88113 100644 --- a/maths/LargestOfVeryLargeNumbers.py +++ b/maths/LargestOfVeryLargeNumbers.py @@ -11,19 +11,21 @@ def res(x,y): elif(y==0): return 1 # any number raised to 0 is 1 -# Reads two numbers from input and typecasts them to int using map function. -# Here x is the base and y is the power. -x1,y1 = map(int, input().split(',')) -x2,y2 = map(int, input().split(',')) + +if __name__ == "__main__": # Main function + # Reads two numbers from input and typecasts them to int using map function. + # Here x is the base and y is the power. + x1,y1 = map(int, input().split(',')) + x2,y2 = map(int, input().split(',')) -# We find the log of each number, using the function res(), which takes two arguments. -res1=res(x1,y1) -res2=res(x2,y2) + # We find the log of each number, using the function res(), which takes two arguments. + res1=res(x1,y1) + res2=res(x2,y2) -# We check for the largest number -if(res1>res2): - print("Largest number is",x1,'^',y1) -elif(res2>res1): - print("Largest number is", x2, '^', y2) -else: - print("Both are equal") + # We check for the largest number + if(res1>res2): + print("Largest number is",x1,'^',y1) + elif(res2>res1): + print("Largest number is", x2, '^', y2) + else: + print("Both are equal") From 9d3c1c1f17028cd2653e2a28ed897094a6099527 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 30 Jul 2019 08:47:32 +0200 Subject: [PATCH 4/4] largest_of_very_large_numbers.py --- maths/LargestOfVeryLargeNumbers.py | 31 ----------------------- maths/largest_of_very_large_numbers.py | 35 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 31 deletions(-) delete mode 100644 maths/LargestOfVeryLargeNumbers.py create mode 100644 maths/largest_of_very_large_numbers.py diff --git a/maths/LargestOfVeryLargeNumbers.py b/maths/LargestOfVeryLargeNumbers.py deleted file mode 100644 index 000b1ed88113..000000000000 --- a/maths/LargestOfVeryLargeNumbers.py +++ /dev/null @@ -1,31 +0,0 @@ -#Author: Abhijeeth S - -import math - -def res(x,y): - if x and y !=0: - return y*math.log10(x) # We use the relation x^y = y*log10(x), where 10 is the base. - else: - if(x==0): # 0 raised to any number is 0 - return 0 - elif(y==0): - return 1 # any number raised to 0 is 1 - - -if __name__ == "__main__": # Main function - # Reads two numbers from input and typecasts them to int using map function. - # Here x is the base and y is the power. - x1,y1 = map(int, input().split(',')) - x2,y2 = map(int, input().split(',')) - - # We find the log of each number, using the function res(), which takes two arguments. - res1=res(x1,y1) - res2=res(x2,y2) - - # We check for the largest number - if(res1>res2): - print("Largest number is",x1,'^',y1) - elif(res2>res1): - print("Largest number is", x2, '^', y2) - else: - print("Both are equal") diff --git a/maths/largest_of_very_large_numbers.py b/maths/largest_of_very_large_numbers.py new file mode 100644 index 000000000000..d2dc0af18126 --- /dev/null +++ b/maths/largest_of_very_large_numbers.py @@ -0,0 +1,35 @@ +# Author: Abhijeeth S + +import math + + +def res(x, y): + if 0 not in (x, y): + # We use the relation x^y = y*log10(x), where 10 is the base. + return y * math.log10(x) + else: + if x == 0: # 0 raised to any number is 0 + return 0 + elif y == 0: + return 1 # any number raised to 0 is 1 + + +if __name__ == "__main__": # Main function + # Read two numbers from input and typecast them to int using map function. + # Here x is the base and y is the power. + prompt = "Enter the base and the power separated by a comma: " + x1, y1 = map(int, input(prompt).split(",")) + x2, y2 = map(int, input(prompt).split(",")) + + # We find the log of each number, using the function res(), which takes two + # arguments. + res1 = res(x1, y1) + res2 = res(x2, y2) + + # We check for the largest number + if res1 > res2: + print("Largest number is", x1, "^", y1) + elif res2 > res1: + print("Largest number is", x2, "^", y2) + else: + print("Both are equal")