From f5181cdcb000384d02cc826714d18ee634482a42 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:45:01 +0530 Subject: [PATCH 01/20] problem_038 solution solution for Euler problem_038 (pandigital multiples) --- project_euler/problem_038/__init__.py | 0 project_euler/problem_038/pandigital.py | 50 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 project_euler/problem_038/__init__.py create mode 100644 project_euler/problem_038/pandigital.py diff --git a/project_euler/problem_038/__init__.py b/project_euler/problem_038/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py new file mode 100644 index 000000000000..06a656ba238b --- /dev/null +++ b/project_euler/problem_038/pandigital.py @@ -0,0 +1,50 @@ +""" +Project Euler Problem [problem_038]: https://projecteuler.net/problem=38 + +...[Problem statement: Take the number 192 and multiply it by each of 1, 2, and 3: + + 192 × 1 = 192 + 192 × 2 = 384 + 192 × 3 = 576 +By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3) + +The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5). + +What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] ... + +""" +def solution(): + # largest pandigital number + largest = 0 + + # for loop to loop till 4 digits + for i in range(1,10000): + + # value for concatenated product + multiplication = '' + + # (1,2,3,4,.....n) + integer = 1 + + # if the multiplication < 9 digits + while len(multiplication) < 9: + + # concatenating the product at each stage + multiplication += str(i*integer) + + # incrementing (1,2,3,4,....n) + integer += 1 + + # check for digits less than 9 + # check for all 1-9 numbers + # check if '0' not in concatenated sting + if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) + and ('0' not in multiplication)): + + # check if multiplication is greater than largest + if int(multiplication) > largest: + largest = int(multiplication) + + # return the largest + return(largest) +solution() From cd8a015d2c313c508b2599592e4c021b6831dcfc Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:59:21 +0530 Subject: [PATCH 02/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 06a656ba238b..83536f987253 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -15,15 +15,13 @@ """ def solution(): # largest pandigital number - largest = 0 - + largest = 0 # for loop to loop till 4 digits for i in range(1,10000): - # value for concatenated product + # value for concatenated string multiplication = '' - # (1,2,3,4,.....n) integer = 1 # if the multiplication < 9 digits @@ -31,13 +29,12 @@ def solution(): # concatenating the product at each stage multiplication += str(i*integer) - - # incrementing (1,2,3,4,....n) + integer += 1 # check for digits less than 9 # check for all 1-9 numbers - # check if '0' not in concatenated sting + # check if '0' not in concatenated string if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): From 437305f090af38be098a130f775e59d2f9e4433d Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:00:44 +0530 Subject: [PATCH 03/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 83536f987253..b9a593b3c014 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -20,16 +20,14 @@ def solution(): for i in range(1,10000): # value for concatenated string - multiplication = '' - + multiplication = '' integer = 1 # if the multiplication < 9 digits while len(multiplication) < 9: # concatenating the product at each stage - multiplication += str(i*integer) - + multiplication += str(i*integer) integer += 1 # check for digits less than 9 From 3437c604cc683dfef1b2dea3d1a2edb9f87f3f4f Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:30:55 +0530 Subject: [PATCH 04/20] Update pandigital.py removed spaces --- project_euler/problem_038/pandigital.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index b9a593b3c014..ec343351cfec 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -17,29 +17,22 @@ def solution(): # largest pandigital number largest = 0 # for loop to loop till 4 digits - for i in range(1,10000): - + for i in range(1,10000): # value for concatenated string multiplication = '' integer = 1 - # if the multiplication < 9 digits - while len(multiplication) < 9: - + while len(multiplication) < 9: # concatenating the product at each stage multiplication += str(i*integer) - integer += 1 - + integer += 1 # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) - and ('0' not in multiplication)): - + if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): # check if multiplication is greater than largest if int(multiplication) > largest: - largest = int(multiplication) - + largest = int(multiplication) # return the largest return(largest) solution() From a75747d51456933021a7dbdf558129bb109d0af6 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:02:37 +0530 Subject: [PATCH 05/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 29 ++++++++++--------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 83536f987253..9efd779b93de 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -13,35 +13,30 @@ What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] ... """ -def solution(): +def main(): # largest pandigital number largest = 0 # for loop to loop till 4 digits - for i in range(1,10000): - + for i in range(1,10000): # value for concatenated string - multiplication = '' - - integer = 1 - + multiplication = '' + integer = 1 # if the multiplication < 9 digits - while len(multiplication) < 9: - + while len(multiplication) < 9: # concatenating the product at each stage - multiplication += str(i*integer) - + multiplication += str(i*integer) integer += 1 - # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) - and ('0' not in multiplication)): - + and ('0' not in multiplication)): # check if multiplication is greater than largest if int(multiplication) > largest: - largest = int(multiplication) - + largest = int(multiplication) # return the largest return(largest) -solution() +if __name__=="__main__": + import doctest + doctest.testmod() + main() From f5f756236ac5e4ff3fa8ec8b01ec9c78fa03a06a Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:05:52 +0530 Subject: [PATCH 06/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index bdd0915103d7..a54c341d8bb9 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -17,7 +17,6 @@ def main(): # largest pandigital number largest = 0 # for loop to loop till 4 digits -<<<<<<< HEAD for i in range(1,10000): # value for concatenated string multiplication = '' @@ -35,7 +34,6 @@ def main(): # check if multiplication is greater than largest if int(multiplication) > largest: largest = int(multiplication) -======= for i in range(1,10000): # value for concatenated string multiplication = '' @@ -52,7 +50,6 @@ def main(): # check if multiplication is greater than largest if int(multiplication) > largest: largest = int(multiplication) ->>>>>>> 3437c604cc683dfef1b2dea3d1a2edb9f87f3f4f # return the largest return(largest) if __name__=="__main__": From 24f5d2267354e8bf33f1a695fa15e29fecf39b95 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:18:03 +0530 Subject: [PATCH 07/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index a54c341d8bb9..5853df4670b1 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -13,7 +13,7 @@ What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] ... """ -def main(): +def solution(): # largest pandigital number largest = 0 # for loop to loop till 4 digits @@ -53,6 +53,4 @@ def main(): # return the largest return(largest) if __name__=="__main__": - import doctest - doctest.testmod() - main() + print(solution()) From faa4504838c22f0a2f781cf8dee2e343a90cb30c Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:24:41 +0530 Subject: [PATCH 08/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 5853df4670b1..154d111c49fb 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -1,17 +1,14 @@ """ Project Euler Problem [problem_038]: https://projecteuler.net/problem=38 -...[Problem statement: Take the number 192 and multiply it by each of 1, 2, and 3: +Problem statement: Take the number 192 and multiply it by each of 1, 2, and 3: 192 × 1 = 192 192 × 2 = 384 192 × 3 = 576 By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3) - The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5). - -What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] ... - +What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] """ def solution(): # largest pandigital number @@ -33,23 +30,7 @@ def solution(): and ('0' not in multiplication)): # check if multiplication is greater than largest if int(multiplication) > largest: - largest = int(multiplication) - for i in range(1,10000): - # value for concatenated string - multiplication = '' - integer = 1 - # if the multiplication < 9 digits - while len(multiplication) < 9: - # concatenating the product at each stage - multiplication += str(i*integer) - integer += 1 - # check for digits less than 9 - # check for all 1-9 numbers - # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): - # check if multiplication is greater than largest - if int(multiplication) > largest: - largest = int(multiplication) + largest = int(multiplication) # return the largest return(largest) if __name__=="__main__": From 44c11a4d1c568d303634853e10949e4f5c4b0c69 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:30:56 +0530 Subject: [PATCH 09/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 154d111c49fb..0a04224b3457 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -1,20 +1,12 @@ """ -Project Euler Problem [problem_038]: https://projecteuler.net/problem=38 - -Problem statement: Take the number 192 and multiply it by each of 1, 2, and 3: - - 192 × 1 = 192 - 192 × 2 = 384 - 192 × 3 = 576 -By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3) -The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5). -What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?] +problem_038: https://projecteuler.net/problem=38 +Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 """ -def solution(): +def solution(n): # largest pandigital number largest = 0 # for loop to loop till 4 digits - for i in range(1,10000): + for i in range(1,n): # value for concatenated string multiplication = '' integer = 1 @@ -34,4 +26,4 @@ def solution(): # return the largest return(largest) if __name__=="__main__": - print(solution()) + print(solution(10000)) From 5bb6b250876f4bb73e37a92acdd816ccf29f2ba3 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:46:45 +0530 Subject: [PATCH 10/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 0a04224b3457..9f8dde6c003f 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -2,19 +2,19 @@ problem_038: https://projecteuler.net/problem=38 Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 """ -def solution(n): +def solution(): # largest pandigital number largest = 0 # for loop to loop till 4 digits - for i in range(1,n): + for i in range(1,10000): # value for concatenated string multiplication = '' - integer = 1 + int_eger = 1 # if the multiplication < 9 digits while len(multiplication) < 9: # concatenating the product at each stage - multiplication += str(i*integer) - integer += 1 + multiplication += str(i*int_eger) + int_eger += 1 # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string @@ -22,8 +22,9 @@ def solution(n): and ('0' not in multiplication)): # check if multiplication is greater than largest if int(multiplication) > largest: - largest = int(multiplication) + largest = int(multiplication) # return the largest return(largest) if __name__=="__main__": - print(solution(10000)) + print(solution()) + From 211482f37b9f7a7096f3f79779e6f53c383d949d Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:23:00 +0530 Subject: [PATCH 11/20] Update pandigital.py --- project_euler/problem_038/pandigital.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py index 9f8dde6c003f..fda5a15c3170 100644 --- a/project_euler/problem_038/pandigital.py +++ b/project_euler/problem_038/pandigital.py @@ -4,25 +4,25 @@ """ def solution(): # largest pandigital number - largest = 0 + largest = 0 # for loop to loop till 4 digits - for i in range(1,10000): + for i in range(1,10000): # value for concatenated string - multiplication = '' - int_eger = 1 + multiplication = '' + int_eger = 1 # if the multiplication < 9 digits - while len(multiplication) < 9: + while len(multiplication) < 9: # concatenating the product at each stage - multiplication += str(i*int_eger) + multiplication += str(i*int_eger) int_eger += 1 # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) - and ('0' not in multiplication)): + if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) + and ('0' not in multiplication)): # check if multiplication is greater than largest if int(multiplication) > largest: - largest = int(multiplication) + largest = int(multiplication) # return the largest return(largest) if __name__=="__main__": From 990b523f55f9f1a84401ec0d7843b90ef61d2aad Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:31:56 +0530 Subject: [PATCH 12/20] a update --- project_euler/problem_038/pandigital.py | 30 ------------------------ project_euler/problem_038/pandigital1.py | 28 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 project_euler/problem_038/pandigital.py create mode 100644 project_euler/problem_038/pandigital1.py diff --git a/project_euler/problem_038/pandigital.py b/project_euler/problem_038/pandigital.py deleted file mode 100644 index fda5a15c3170..000000000000 --- a/project_euler/problem_038/pandigital.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -problem_038: https://projecteuler.net/problem=38 -Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 -""" -def solution(): - # largest pandigital number - largest = 0 - # for loop to loop till 4 digits - for i in range(1,10000): - # value for concatenated string - multiplication = '' - int_eger = 1 - # if the multiplication < 9 digits - while len(multiplication) < 9: - # concatenating the product at each stage - multiplication += str(i*int_eger) - int_eger += 1 - # check for digits less than 9 - # check for all 1-9 numbers - # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) - and ('0' not in multiplication)): - # check if multiplication is greater than largest - if int(multiplication) > largest: - largest = int(multiplication) - # return the largest - return(largest) -if __name__=="__main__": - print(solution()) - diff --git a/project_euler/problem_038/pandigital1.py b/project_euler/problem_038/pandigital1.py new file mode 100644 index 000000000000..66f36a357289 --- /dev/null +++ b/project_euler/problem_038/pandigital1.py @@ -0,0 +1,28 @@ +""" +problem_038: https://projecteuler.net/problem=38 +Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 +""" +def solution(): + # largest pandigital number + largest = 0 + # for loop to loop till 4 digits + for i in range(1,10000): + # value for concatenated string + multiplication = '' + int_eger = 1 + # if the multiplication < 9 digits + while len(multiplication) < 9: + # concatenating the product at each stage + multiplication += str(i*int_eger) + int_eger += 1 + # check for digits less than 9 + # check for all 1-9 numbers + # check if '0' not in concatenated string + if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): + # check if multiplication is greater than largest + if int(multiplication) > largest: + largest =int(multiplication) + # return the largest + return(largest) +if __name__=="__main__": + print(solution()) \ No newline at end of file From e48b0848bd40f79beeaf7648bb361a23ca713b34 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:44:46 +0530 Subject: [PATCH 13/20] updated solution --- project_euler/problem_038/pandigital1.py | 2 ++ project_euler/problem_038/sol1.py | 28 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 project_euler/problem_038/sol1.py diff --git a/project_euler/problem_038/pandigital1.py b/project_euler/problem_038/pandigital1.py index 66f36a357289..422c0d20fbf3 100644 --- a/project_euler/problem_038/pandigital1.py +++ b/project_euler/problem_038/pandigital1.py @@ -2,6 +2,8 @@ problem_038: https://projecteuler.net/problem=38 Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 """ + + def solution(): # largest pandigital number largest = 0 diff --git a/project_euler/problem_038/sol1.py b/project_euler/problem_038/sol1.py new file mode 100644 index 000000000000..66f36a357289 --- /dev/null +++ b/project_euler/problem_038/sol1.py @@ -0,0 +1,28 @@ +""" +problem_038: https://projecteuler.net/problem=38 +Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 +""" +def solution(): + # largest pandigital number + largest = 0 + # for loop to loop till 4 digits + for i in range(1,10000): + # value for concatenated string + multiplication = '' + int_eger = 1 + # if the multiplication < 9 digits + while len(multiplication) < 9: + # concatenating the product at each stage + multiplication += str(i*int_eger) + int_eger += 1 + # check for digits less than 9 + # check for all 1-9 numbers + # check if '0' not in concatenated string + if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): + # check if multiplication is greater than largest + if int(multiplication) > largest: + largest =int(multiplication) + # return the largest + return(largest) +if __name__=="__main__": + print(solution()) \ No newline at end of file From 873578694b1ea5848712cf1b3d71387145fdeb19 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:48:25 +0530 Subject: [PATCH 14/20] Delete pandigital1.py --- project_euler/problem_038/pandigital1.py | 30 ------------------------ 1 file changed, 30 deletions(-) delete mode 100644 project_euler/problem_038/pandigital1.py diff --git a/project_euler/problem_038/pandigital1.py b/project_euler/problem_038/pandigital1.py deleted file mode 100644 index 422c0d20fbf3..000000000000 --- a/project_euler/problem_038/pandigital1.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -problem_038: https://projecteuler.net/problem=38 -Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 -""" - - -def solution(): - # largest pandigital number - largest = 0 - # for loop to loop till 4 digits - for i in range(1,10000): - # value for concatenated string - multiplication = '' - int_eger = 1 - # if the multiplication < 9 digits - while len(multiplication) < 9: - # concatenating the product at each stage - multiplication += str(i*int_eger) - int_eger += 1 - # check for digits less than 9 - # check for all 1-9 numbers - # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): - # check if multiplication is greater than largest - if int(multiplication) > largest: - largest =int(multiplication) - # return the largest - return(largest) -if __name__=="__main__": - print(solution()) \ No newline at end of file From bf64ce47aa683a51a94fa739a748a6652d19389c Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:13:31 +0530 Subject: [PATCH 15/20] Update sol1.py --- project_euler/problem_038/sol1.py | 38 +++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/project_euler/problem_038/sol1.py b/project_euler/problem_038/sol1.py index 66f36a357289..35a70628619d 100644 --- a/project_euler/problem_038/sol1.py +++ b/project_euler/problem_038/sol1.py @@ -1,28 +1,52 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + """ problem_038: https://projecteuler.net/problem=38 Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 """ + + def solution(): + # largest pandigital number + largest = 0 + # for loop to loop till 4 digits - for i in range(1,10000): + + for i in range(1, 10000): + # value for concatenated string + multiplication = '' int_eger = 1 + # if the multiplication < 9 digits + while len(multiplication) < 9: + # concatenating the product at each stage - multiplication += str(i*int_eger) + + multiplication += str(i * int_eger) int_eger += 1 + # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string - if ((len(multiplication) == 9) and (len(set(multiplication)) == 9) and ('0' not in multiplication)): + + if len(multiplication) == 9 and len(set(multiplication)) == 9 \ + and '0' not in multiplication: + # check if multiplication is greater than largest + if int(multiplication) > largest: - largest =int(multiplication) + largest = int(multiplication) + # return the largest - return(largest) -if __name__=="__main__": - print(solution()) \ No newline at end of file + + return largest + + +if __name__ == '__main__': + print solution() From e7f50083bdbe986e27737ce59dfc747021363f6a Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:34:53 +0530 Subject: [PATCH 16/20] Update sol1.py --- project_euler/problem_038/sol1.py | 46 +++++++++---------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/project_euler/problem_038/sol1.py b/project_euler/problem_038/sol1.py index 35a70628619d..36cac368dfa6 100644 --- a/project_euler/problem_038/sol1.py +++ b/project_euler/problem_038/sol1.py @@ -1,52 +1,32 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -""" +""" problem_038: https://projecteuler.net/problem=38 -Problem statement: What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1 +Problem statement: What is the largest 1 to 9 pandigital 9-digit +number that can be formed as the concatenated +product of an integer with (1,2, ... , n) where n > 1 """ def solution(): - # largest pandigital number - largest = 0 - # for loop to loop till 4 digits - for i in range(1, 10000): - # value for concatenated string - - multiplication = '' + mul = '' int_eger = 1 - # if the multiplication < 9 digits - - while len(multiplication) < 9: - + while len(mul) < 9: # concatenating the product at each stage - - multiplication += str(i * int_eger) + mul += str(i*int_eger) int_eger += 1 - # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string - - if len(multiplication) == 9 and len(set(multiplication)) == 9 \ - and '0' not in multiplication: - + if ((len(mul) == 9) and (len(set(mul)) == 9) and ('0' not in mul)): # check if multiplication is greater than largest - - if int(multiplication) > largest: - largest = int(multiplication) - + if int(mul) > largest: + largest = int(mul) # return the largest - - return largest - - -if __name__ == '__main__': - print solution() + return(largest) +if __name__ == "__main__": + print(solution()) From f61fa7998cd7399ff4036b0da231943d48a6f959 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:53:31 +0530 Subject: [PATCH 17/20] pep8 update --- project_euler/problem_038/{sol1.py => sol2.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename project_euler/problem_038/{sol1.py => sol2.py} (100%) diff --git a/project_euler/problem_038/sol1.py b/project_euler/problem_038/sol2.py similarity index 100% rename from project_euler/problem_038/sol1.py rename to project_euler/problem_038/sol2.py From 66c8839218741b5656fd23901f7b869ea6665fe4 Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:59:23 +0530 Subject: [PATCH 18/20] Update sol2.py --- project_euler/problem_038/sol2.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_038/sol2.py b/project_euler/problem_038/sol2.py index 36cac368dfa6..987ed1cb1bd2 100644 --- a/project_euler/problem_038/sol2.py +++ b/project_euler/problem_038/sol2.py @@ -12,21 +12,23 @@ def solution(): # for loop to loop till 4 digits for i in range(1, 10000): # value for concatenated string - mul = '' + mul = "" int_eger = 1 # if the multiplication < 9 digits while len(mul) < 9: # concatenating the product at each stage - mul += str(i*int_eger) + mul += str(i * int_eger) int_eger += 1 # check for digits less than 9 # check for all 1-9 numbers # check if '0' not in concatenated string - if ((len(mul) == 9) and (len(set(mul)) == 9) and ('0' not in mul)): + if (len(mul) == 9) and (len(set(mul)) == 9) and ("0" not in mul): # check if multiplication is greater than largest if int(mul) > largest: largest = int(mul) # return the largest - return(largest) + return largest + + if __name__ == "__main__": print(solution()) From f7b3fc3833a67ef06bb7e1dc78d2d5a06c25dc3d Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:52:03 +0530 Subject: [PATCH 19/20] solution for Euler problem_050 --- project_euler/problem_050/__init__.py | 0 project_euler/problem_050/problem_050.py | 52 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 project_euler/problem_050/__init__.py create mode 100644 project_euler/problem_050/problem_050.py diff --git a/project_euler/problem_050/__init__.py b/project_euler/problem_050/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/project_euler/problem_050/problem_050.py b/project_euler/problem_050/problem_050.py new file mode 100644 index 000000000000..b88eaab70037 --- /dev/null +++ b/project_euler/problem_050/problem_050.py @@ -0,0 +1,52 @@ +"""problem_050 statement:The longest sum of consecutive primes below +one-thousand that adds to a prime, contains 21 terms, and is equal to 953. +Which prime, below one-million, can be written as the sum of the most +consecutive primes""" +# Sieve of Erotosthenes +# One of the best algorithm to generate prime numbers +# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes + + +def sieve(n): + is_prime = [True] * n + is_prime[0] = False + is_prime[1] = False + is_prime[2] = True + # even numbers except 2 have been eliminated + for i in range(3, int(n ** 0.5 + 1), 2): + index = i * 2 + while index < n: + is_prime[index] = False + index = index + i + prime = [2] + for i in range(3, n, 2): + if is_prime[i]: + prime.append(i) + return prime + + +# prime numbers upto 1 million +primes = sieve(1000000) + +# length of the consecutive prime sum +length = 0 + +# value of the consecutive prime sum +largest = 0 + +# max value of the j variable(second for loop) +lastj = len(primes) + +# two for loops +for i in range(len(primes)): + for j in range(i + length, lastj): + sol = sum(primes[i:j]) + if sol < 1000000: + if sol in primes: + length = j - i + largest = sol + else: + lastj = j + 1 + break +# printing the requried solution +print(largest) From df7f64f610834d4c2f82435f3eeb078ec028b6ed Mon Sep 17 00:00:00 2001 From: Dark00infinity <47387653+dark00infinity@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:56:27 +0530 Subject: [PATCH 20/20] . --- project_euler/problem_050/__init__.py | 0 project_euler/problem_050/problem_050.py | 52 ------------------------ 2 files changed, 52 deletions(-) delete mode 100644 project_euler/problem_050/__init__.py delete mode 100644 project_euler/problem_050/problem_050.py diff --git a/project_euler/problem_050/__init__.py b/project_euler/problem_050/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/project_euler/problem_050/problem_050.py b/project_euler/problem_050/problem_050.py deleted file mode 100644 index b88eaab70037..000000000000 --- a/project_euler/problem_050/problem_050.py +++ /dev/null @@ -1,52 +0,0 @@ -"""problem_050 statement:The longest sum of consecutive primes below -one-thousand that adds to a prime, contains 21 terms, and is equal to 953. -Which prime, below one-million, can be written as the sum of the most -consecutive primes""" -# Sieve of Erotosthenes -# One of the best algorithm to generate prime numbers -# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes - - -def sieve(n): - is_prime = [True] * n - is_prime[0] = False - is_prime[1] = False - is_prime[2] = True - # even numbers except 2 have been eliminated - for i in range(3, int(n ** 0.5 + 1), 2): - index = i * 2 - while index < n: - is_prime[index] = False - index = index + i - prime = [2] - for i in range(3, n, 2): - if is_prime[i]: - prime.append(i) - return prime - - -# prime numbers upto 1 million -primes = sieve(1000000) - -# length of the consecutive prime sum -length = 0 - -# value of the consecutive prime sum -largest = 0 - -# max value of the j variable(second for loop) -lastj = len(primes) - -# two for loops -for i in range(len(primes)): - for j in range(i + length, lastj): - sol = sum(primes[i:j]) - if sol < 1000000: - if sol in primes: - length = j - i - largest = sol - else: - lastj = j + 1 - break -# printing the requried solution -print(largest)