diff options
Diffstat (limited to 'challenge-220/robert-dicicco/python')
| -rw-r--r-- | challenge-220/robert-dicicco/python/ch-1.py | 38 | ||||
| -rw-r--r-- | challenge-220/robert-dicicco/python/ch-2.py | 49 |
2 files changed, 87 insertions, 0 deletions
diff --git a/challenge-220/robert-dicicco/python/ch-1.py b/challenge-220/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..632e169c46 --- /dev/null +++ b/challenge-220/robert-dicicco/python/ch-1.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# ------------------------------------------------ +# AUTHOR: Robert DiCicco +# DATE : 2023-06-05 +# Challenge 220 Task 1 common Characters ( Python ) +# ------------------------------------------------ + +words = [["Perl", "Rust", "Raku"], ["love", "live", "leave"]] + +alphabet_hash = {} + +for wds in words: + for char in range(ord('a'), ord('z')+1): + alphabet_hash[chr(char)] = 0 + + print("Input: @words = ",wds) + for wd in wds: + wd = wd.lower() + for ch in wd: + alphabet_hash[ch] += 1 + + print("Output: ",end= " ") + for i in alphabet_hash: + if alphabet_hash[i] >= 3: + print(i,end=" ") + print("\n") + +# ------------------------------------------------ +# SAMPLE OUTPUT +# python .\CommonChars.py + +# Input: @words = ['Perl', 'Rust', 'Raku'] +# Output: r + +# Input: @words = ['love', 'live', 'leave'] +# Output: e l v + +# ------------------------------------------------ diff --git a/challenge-220/robert-dicicco/python/ch-2.py b/challenge-220/robert-dicicco/python/ch-2.py new file mode 100644 index 0000000000..550194cb55 --- /dev/null +++ b/challenge-220/robert-dicicco/python/ch-2.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# ------------------------------------------ +# AUTHOR: Robert DiCicco +# DATE : 2023-06-00 +# Challenge 220 Task 2 Squareful ( Python ) +# ------------------------------------------ +import math +from itertools import permutations + + +myints = [[1,8,17],[1,8,17,19]] + +def IsPerfectSquare(number_to_test) : + root = math.floor(math.sqrt(number_to_test)) + if ((root ** 2 ) == number_to_test) : + return True; + return False; + +for intsub in myints: + print("Input: @ints = ",intsub) + print("OutPut: ",end="") + perm = permutations(intsub) + for i in list(perm): + ln = len(i) - 1 + tv = 0 + flag = 0 + while tv < ln : + if IsPerfectSquare(i[tv] + i[tv + 1]) : + flag += 1 + else : + flag = 0 + tv += 1 + if flag == ln - 1 : + print(i,end=" ") + print("\n") + +#------------------------------------------ +# SAMPLE OUTPUT +# python .\Squareful.py + +# Input: @ints = [1, 8, 17] +# OutPut: (1, 17, 8) (17, 1, 8) + +# Input: @ints = [1, 8, 17, 19] +# OutPut: (1, 19, 17, 8) (19, 1, 8, 17) +#------------------------------------------ + + + |
