From e64734f9b42c5838a7d3ade2d6c2e8ba14625cf0 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 19:39:28 +0000 Subject: Add Lua and Python solutions to challenge 102 --- challenge-102/paulo-custodio/python/ch-1.py | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 challenge-102/paulo-custodio/python/ch-1.py (limited to 'challenge-102/paulo-custodio/python/ch-1.py') diff --git a/challenge-102/paulo-custodio/python/ch-1.py b/challenge-102/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..f9ffb4c5c1 --- /dev/null +++ b/challenge-102/paulo-custodio/python/ch-1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# Challenge 102 +# +# TASK #1 > Rare Numbers +# Submitted by: Mohammad S Anwar +# +# You are given a positive integer $N. +# +# Write a script to generate all Rare numbers of size $N if exists. Please +# checkout the page for more information about it. +# Examples +# +# (a) 2 digits: 65 +# (b) 6 digits: 621770 +# (c) 9 digits: 281089082 + +import sys +import math + +def perfect_square(n): + sq = math.sqrt(float(n)) + if math.floor(sq) == sq: + return True + else: + return False + +def print_rare(n): + for r in range(10**(n-1), 10**n): + r1 = int(str(r)[::-1]) + if perfect_square(r+r1): + if r>=r1: + if perfect_square(r-r1): + print(r) + +print_rare(int(sys.argv[1])) -- cgit From c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Tue, 9 Mar 2021 20:01:18 +0000 Subject: Remove tabs --- challenge-102/paulo-custodio/python/ch-1.py | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'challenge-102/paulo-custodio/python/ch-1.py') diff --git a/challenge-102/paulo-custodio/python/ch-1.py b/challenge-102/paulo-custodio/python/ch-1.py index f9ffb4c5c1..d513c19117 100644 --- a/challenge-102/paulo-custodio/python/ch-1.py +++ b/challenge-102/paulo-custodio/python/ch-1.py @@ -1,16 +1,16 @@ #!/usr/bin/env python # Challenge 102 -# +# # TASK #1 > Rare Numbers # Submitted by: Mohammad S Anwar -# +# # You are given a positive integer $N. -# -# Write a script to generate all Rare numbers of size $N if exists. Please +# +# Write a script to generate all Rare numbers of size $N if exists. Please # checkout the page for more information about it. # Examples -# +# # (a) 2 digits: 65 # (b) 6 digits: 621770 # (c) 9 digits: 281089082 @@ -19,18 +19,18 @@ import sys import math def perfect_square(n): - sq = math.sqrt(float(n)) - if math.floor(sq) == sq: - return True - else: - return False + sq = math.sqrt(float(n)) + if math.floor(sq) == sq: + return True + else: + return False def print_rare(n): - for r in range(10**(n-1), 10**n): - r1 = int(str(r)[::-1]) - if perfect_square(r+r1): - if r>=r1: - if perfect_square(r-r1): - print(r) - + for r in range(10**(n-1), 10**n): + r1 = int(str(r)[::-1]) + if perfect_square(r+r1): + if r>=r1: + if perfect_square(r-r1): + print(r) + print_rare(int(sys.argv[1])) -- cgit