aboutsummaryrefslogtreecommitdiff
path: root/challenge-220/robert-dicicco/python/ch-2.py
blob: 550194cb5583a888efb03d69407a831c7c1ab280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)
#------------------------------------------