diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-24 22:11:46 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-24 22:11:46 +0100 |
| commit | ac43b36f9732005921ef7f303ffa669fe2c6ae03 (patch) | |
| tree | 34b34026a75b49f05fbbfca79e9a177e463e1715 | |
| parent | 7471e4d859724f217eecd4fe691e588b6f7e209e (diff) | |
| download | perlweeklychallenge-club-ac43b36f9732005921ef7f303ffa669fe2c6ae03.tar.gz perlweeklychallenge-club-ac43b36f9732005921ef7f303ffa669fe2c6ae03.tar.bz2 perlweeklychallenge-club-ac43b36f9732005921ef7f303ffa669fe2c6ae03.zip | |
Add Python solution to challenge 146
| -rw-r--r-- | challenge-146/paulo-custodio/perl/ch-1.pl | 2 | ||||
| -rw-r--r-- | challenge-146/paulo-custodio/python/ch-1.py | 11 | ||||
| -rw-r--r-- | challenge-146/paulo-custodio/python/ch-2.py | 42 |
3 files changed, 54 insertions, 1 deletions
diff --git a/challenge-146/paulo-custodio/perl/ch-1.pl b/challenge-146/paulo-custodio/perl/ch-1.pl index 756810be2c..db556137e3 100644 --- a/challenge-146/paulo-custodio/perl/ch-1.pl +++ b/challenge-146/paulo-custodio/perl/ch-1.pl @@ -2,7 +2,7 @@ # Challenge 146 # -# TASK #1 › 10001st Prime Number +# TASK #1 > 10001st Prime Number # Submitted by: Mohammad S Anwar # Write a script to generate the 10001st prime number. diff --git a/challenge-146/paulo-custodio/python/ch-1.py b/challenge-146/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..0cee726b6c --- /dev/null +++ b/challenge-146/paulo-custodio/python/ch-1.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +# Challenge 146 +# +# TASK #1 > 10001st Prime Number +# Submitted by: Mohammad S Anwar +# Write a script to generate the 10001st prime number. + +from sympy import prime + +print(prime(10001)) diff --git a/challenge-146/paulo-custodio/python/ch-2.py b/challenge-146/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..a355bd9517 --- /dev/null +++ b/challenge-146/paulo-custodio/python/ch-2.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# Challenge 146 +# +# Consider the following Curious Fraction Tree: +# +# +# Curious Fraction Tree +# +# +# You are given a fraction, member of the tree created similar to the above sample. +# +# Write a script to find out the parent and grandparent of the given member. +# +# Example 1: +# Input: $member = '3/5'; +# Output: parent = '3/2' and grandparent = '1/2' +# Example 2: +# Input: $member = '4/3'; +# Output: parent = '1/3' and grandparent = '1/2' +# +# Solution: +# for node a/b, the children are a/(a+b) and (a+b)/b + +import sys + +def parent(a, b): + if a / b < 1: # a/(a+b) + parent_a = a + parent_b = abs(b - a) + else: # (a+b)/b + parent_a = abs(b - a) + parent_b = b + return parent_a, parent_b + +input_value = sys.argv[1] +a, b = map(int, input_value.split('/')) +print(f"{a}/{b} -> ", end="") +a, b = parent(a, b) +print(f"{a}/{b} -> ", end="") +a, b = parent(a, b) +print(f"{a}/{b}") |
