diff options
Diffstat (limited to 'challenge-102/paulo-custodio/python')
| -rw-r--r-- | challenge-102/paulo-custodio/python/ch-1.py | 36 | ||||
| -rw-r--r-- | challenge-102/paulo-custodio/python/ch-2.py | 44 |
2 files changed, 80 insertions, 0 deletions
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..d513c19117 --- /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])) diff --git a/challenge-102/paulo-custodio/python/ch-2.py b/challenge-102/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..558367a422 --- /dev/null +++ b/challenge-102/paulo-custodio/python/ch-2.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +# Challenge 102 +# +# TASK #2 > Hash-counting String +# Submitted by: Stuart Little +# +# You are given a positive integer $N. +# +# Write a script to produce Hash-counting string of that length. +# +# The definition of a hash-counting string is as follows: +# - the string consists only of digits 0-9 and hashes, '#' +# - there are no two consecutive hashes: '##' does not appear in your string +# - the last character is a hash +# - the number immediately preceding each hash (if it exists) is the position +# of that hash in the string, with the position being counted up from 1 +# +# It can be shown that for every positive integer N there is exactly one such +# length-N string. +# Examples: +# +# (a) "#" is the counting string of length 1 +# (b) "2#" is the counting string of length 2 +# (c) "#3#" is the string of length 3 +# (d) "#3#5#7#10#" is the string of length 10 +# (e) "2#4#6#8#11#14#" is the string of length 14 + +import sys + +def hash_counting(n): + out = '' + i = n + while i>0: + p = i + out = '#'+out + i -= 1 + while i>0 and p!=0: + out = str(p % 10)+out + i -= 1 + p = int(p/10) + return out + +print(hash_counting(int(sys.argv[1]))) |
