sasaharayuugo.net

三角形定理ループだとかの自動化

できた。
テストツールを導入するほどでも無いと思ったんで、テストは手元でごく簡単に済ませた。
明日1日休んで、明後日から2ステップの作図の問題を解こう。
まあ細かい修正は必要だろうが。

プログラムの上の方で実行したかったのだけど、関数が定義されてないだとかでエラーが出てできないんだね。できると思ってた。

当たり前だけどプログラムは読まない方が良い。結果を先に上の方に貼っておく。
 

angle_equ[4] == angle_equ[0]
    angle_equ[7] == DCG
    AC == CE
    angle_equ[6] == angle_equ[7]
    angle_equ[8] == angle_equ[9]
    AH == DH
    side_equ[0] == DI
    BE == EI
    side_equ[2] == DE
    CH == EH
    angle_equ[1] == angle_equ[5]
    DCF == angle_equ[1]
    side_equ[4] == DG

    角
    0 : ['DAI', 'BCD', 'FEI', 'FCG', 'EBI', 'CGD', 'AIH', 'BIE', 'CDG']
    1 : ['ADC', 'CBI', 'CFE', 'CGH', 'AIE', 'BIH', 'DCF']
    2 : ['AHG', 'CHI']
    3 : ['AHI', 'CHG', 'FCH']
    6 : ['DAH', 'BCH', 'ADG', 'BEI', 'BCF', 'DCG']
    8 : ['HAI', 'DCH', 'BEF', 'BCG']

    角の和
    [2] + [3] == 180
    [0] + [1] == 180
    [3] + GCH == [0]
    [6] + [8] == [0]
    [0] + [6] == [1]
    [3] + [8] == [1]
    [1] + GCH == [2]
    [0] + [8] == [2]
    [6] + [6] == [3]
    [6] + GCH == [8]

    辺
    0 : ['AD', 'BC', 'EG', 'CF', 'DI']
    1 : ['AB', 'CD', 'EF', 'CG']
    2 : ['AC', 'CE', 'DE']
    3 : ['AH', 'DH']
    4 : ['BE', 'EI', 'DG']
    5 : ['CH', 'EH']

    辺の和
    GH + HI == GI
    [5] + GH == [0]
    [3] + HI == [0]
    [4] + GI == [0]
    AI + BI == [1]
    [3] + [5] == [2]
    [0] + [4] == [2]
    [4] + GH == [3]
    [4] + HI == [5]

    三角形
    ABC : [HAI[8], AB[1], CBI[1], BC[0], BCH[6], AC[2]]
    ACD : [DAH[6], AC[2], DCH[8], CD[1], ADC[1], AD[0]]
    ADH : [DAH[6], AD[0], ADG[6], DH[3], AHG[2], AH[3]]
    ADI : [DAI[0], AD[0], ADG[6], DI[0], AIH[0], AI]
    AHI : [HAI[8], AH[3], AHI[3], HI, AIH[0], AI]
    BEI : [EBI[0], BE[4], BEI[6], EI[4], BIE[0], BI]
    CDE : [BCD[0], CD[1], CDG[0], DE[2], BEI[6], CE[2]]
    CDG : [DCG[6], CD[1], CDG[0], DG[4], CGD[0], CG[1]]
    CDH : [DCH[8], CD[1], CDG[0], DH[3], CHG[3], CH[5]]
    CEF : [BCF[6], CE[2], BEF[8], EF[1], CFE[1], CF[0]]
    CEG : [BCG[8], CE[2], BEI[6], EG[0], CGH[1], CG[1]]
    CEH : [BCH[6], CE[2], BEI[6], EH[5], CHI[2], CH[5]]
    CGH : [GCH, CG[1], CGH[1], GH, CHG[3], CH[5]]

 

import itertools

    triangle_lst = {
        "ABC" : ["HAI", "AB", "CBI", "BC", "BCH", "AC"],
        "ACD" : ["DAH", "AC", "DCH", "CD", "ADC", "AD"],
        "ADH" : ["DAH", "AD", "ADG", "DH", "AHG", "AH"],
        "ADI" : ["DAI", "AD", "ADG", "DI", "AIH", "AI"],
        "AHI" : ["HAI", "AH", "AHI", "HI", "AIH", "AI"],
        "BEI" : ["EBI", "BE", "BEI", "EI", "BIE", "BI"],
        "CDE" : ["BCD", "CD", "CDG", "DE", "BEI", "CE"],
        "CDG" : ["DCG", "CD", "CDG", "DG", "CGD", "CG"],
        "CDH" : ["DCH", "CD", "CDG", "DH", "CHG", "CH"],
        "CEF" : ["BCF", "CE", "BEF", "EF", "CFE", "CF"],
        "CEG" : ["BCG", "CE", "BEI", "EG", "CGH", "CG"],
        "CEH" : ["BCH", "CE", "BEI", "EH", "CHI", "CH"],
        "CGH" : ["GCH", "CG", "CGH", "GH", "CHG", "CH"],
    }

    side_equ = {
        "AD" : 0,
        "BC" : 0,
        "EG" : 0,
        "CF" : 0,
        "AB" : 1,
        "CD" : 1,
        "EF" : 1,
        "CG" : 1
    }

    angle_equ = {
        "DAI" : 0,
        "BCD" : 0,
        "FEI" : 0,
        "FCG" : 0,
        "EBI" : 0,
        "CGD" : 0,
        "ADC" : 1,
        "CBI" : 1,
        "CFE" : 1,
        "CGH" : 1,
        "AHG" : 2,
        "CHI" : 2,
        "AHI" : 3,
        "CHG" : 3,
        "FCH" : 3,
        "AIH" : 4,
        "BIE" : 4,
        "CDG" : 4,
        "AIE" : 5,
        "BIH" : 5,
        "DAH" : 6,
        "BCH" : 6,
        "ADG" : 7,
        "BEI" : 7,
        "BCF" : 7,
        "HAI" : 8,
        "DCH" : 8,
        "BEF" : 9,
        "BCG" : 9,
    }


    sum_angle_lst = [   #[0] + [1] = [2]
        ["DAH", "HAI", "DAI"],
        ["EBI", "CBI", 180],
        ["DCG", "GCH", "DCH"],
        ["GCH", "BCH", "BCG"],
        ["BCH", "BCF", "FCH"],
        ["DCH", "BCH", "BCD"],
        ["BCG", "DCG", "BCD"],
        ["BCG", "BCF", "FCG"],
        ["FCH", "GCH", "FCG"],
        ["BCD", "BCF", "DCF"],
        ["FCG", "DCG", "DCF"],
        ["ADG", "CDG", "ADC"],
        ["BEI", "BEF", "FEI"],
        ["CGD", "CGH", 180],
        ["AHG", "CHG", 180],
        ["AIH", "AIE", 180],
        ["HAI", "BCH", "EBI"],
        ["BCG", "BEI", "CGD"],
        ["DAH", "ADG", "AHI"],
        ["DAI", "ADG", "AIE"],
        ["DCG", "CDG", "CGH"],
        ["EBI", "BEI", "BIH"],
        ["BEI", "BIE", "CBI"],
        ["HAI", "AHI", "BIH"],
        ["HAI", "AIH", "AHG"],
        ["DCH", "CDG", "AHG"],
        ["GCH", "CGH", "CHI"],
        ["GCH", "CHG", "CGD"]
    ]

    sum_side_lst = [    #[0] + [1] = [2]
        ["AI", "BI", "AB"],
        ["AH", "CH", "AC"],
        ["BC", "BE", "CE"],
        ["DG", "EG", "DE"],
        ["DH", "EH", "DE"],
        ["DI", "EI", "DE"],
        ["DG", "GH", "DH"],
        ["DG", "GI", "DI"],
        ["DH", "HI", "DI"],
        ["EI", "GI", "EG"],
        ["EH", "GH", "EG"],
        ["EI", "HI", "EH"],
        ["GH", "HI", "GI"]
    ]


    def angle1_equal_angle2(angle_equ, angle1, angle2):
        if angle1 not in angle_equ and angle2 not in angle_equ:
            angle_equ_values = list(angle_equ.values())

            if angle_equ_values != []:
                max_value = max(angle_equ_values)
                new_value = max_value + 1
            else:
                new_value = 0

            angle_equ[angle1] = new_value
            angle_equ[angle2] = new_value
        elif angle1 in angle_equ and angle2 not in angle_equ:
            angle_equ[angle2] = angle_equ[angle1]
        elif angle1 not in angle_equ and angle2 in angle_equ:
            angle_equ[angle1] = angle_equ[angle2]
        elif angle_equ[angle1] > angle_equ[angle2]:
            big_value = angle_equ[angle1]    #束縛は大丈夫?
            small_value = angle_equ[angle2]  

            for k, v in angle_equ.items():
                if v == big_value:
                    angle_equ[k] = small_value
        elif angle_equ[angle1] < angle_equ[angle2]:
            big_value = angle_equ[angle2]
            small_value = angle_equ[angle1]

            for k, v in angle_equ.items():
                if v == big_value:
                    angle_equ[k] = small_value
        
        return angle_equ

    """
    #angle_equ = angle1_equal_angle2(angle_equ, "CDG", "CGD") #angle_equの中に、有る 有る
    #angle_equ = angle1_equal_angle2(angle_equ, "CDG", "GCH") #有る 無い
    #angle_equ = angle1_equal_angle2(angle_equ, "GCH", "CGD") #無い 有る
    #angle_equ = angle1_equal_angle2(angle_equ, "GCH", "DCG") #無い 無い

    print(angle_equ)
    """


    def side1_equal_side2(side_equ, side1, side2):
        if side1 not in side_equ and side2 not in side_equ:
            side_equ_values = list(side_equ.values())

            if side_equ_values != []:
                max_value = max(side_equ_values)
                new_value = max_value + 1
            else:
                new_value = 0
            
            side_equ[side1] = new_value
            side_equ[side2] = new_value
        elif side1 in side_equ and side2 not in side_equ:
            side_equ[side2] = side_equ[side1]
        elif side1 not in side_equ and side2 in side_equ:
            side_equ[side1] = side_equ[side2]
        elif side_equ[side1] > side_equ[side2]:
            big_value = side_equ[side1]    #束縛は大丈夫?
            small_value = side_equ[side2]  

            for k, v in side_equ.items():
                if v == big_value:
                    side_equ[k] = small_value
        elif side_equ[side1] < side_equ[side2]:
            big_value = side_equ[side2]
            small_value = side_equ[side1]

            for k, v in side_equ.items():
                if v == big_value:
                    side_equ[k] = small_value
        
        return side_equ

    """
    #side_equ = side1_equal_side2(side_equ, "AD", "AB") #side_equの中に、有る 有る
    #side_equ = side1_equal_side2(side_equ, "AD", "AH") #有る 無い
    #side_equ = side1_equal_side2(side_equ, "AH", "AD") #無い 有る
    #side_equ = side1_equal_side2(side_equ, "AH", "BE") #無い 無い

    print(side_equ)
    """


    #いろいろやる関数。既にイコールかを確認して、そうでなければ新しいイコールとしてprint関数で出力して、新しいイコールとして登録して、内側のwhile文用のloop_flgと実行したことを伝えるexe_flgをTrueにして返す。
    def equ_angle_sub(angle_equ, angle1, angle2, loop_flg, exe_flg):
        if not (angle1 == angle2 or (angle1 in angle_equ and angle2 in angle_equ and angle_equ[angle1] == angle_equ[angle2])):
            angle1_val = "angle_equ[" + str(angle_equ[angle1]) + "]" if angle1 in angle_equ else angle1
            angle2_val = "angle_equ[" + str(angle_equ[angle2]) + "]" if angle2 in angle_equ else angle2

            print(str(angle1_val) + " == " + str(angle2_val))
            
            angle_equ = angle1_equal_angle2(angle_equ, angle1, angle2)

            loop_flg = True
            exe_flg = True
        
        return angle_equ, loop_flg, exe_flg


    #一つ上の辺バージョン
    def equ_side_sub(side_equ, side1, side2, loop_flg, exe_flg):
        if not (side1 == side2 or (side1 in side_equ and side2 in side_equ and side_equ[side1] == side_equ[side2])):
            side1_val = "side_equ[" + str(side_equ[side1]) + "]" if side1 in side_equ else side1
            side2_val = "side_equ[" + str(side_equ[side2]) + "]" if side2 in side_equ else side2

            print(str(side1_val) + " == " + str(side2_val))
            
            side_equ = side1_equal_side2(side_equ, side1, side2)

            loop_flg = True
            exe_flg = True
        
        return side_equ, loop_flg, exe_flg


    def isosceles_angle_check(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for angle1, angle2, side1, side2 in [(tri1[0], tri1[2], tri1[5], tri1[3]), (tri1[2], tri1[4], tri1[1], tri1[5]), (tri1[0], tri1[4], tri1[1], tri1[3])]:
                    if (angle1 in angle_equ and angle2 in angle_equ and angle_equ[angle1] == angle_equ[angle2]) or (angle1 not in angle_equ and angle2 not in angle_equ and angle1 == angle2):
                        side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side1, side2, loop_flg, exe_flg)

        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {"TST" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"]}
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE2"] = 0
    ###テスト2
    #triangle_lst["TST"][2] = "ANGLE1"
    ###テスト3
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE2"] = 0
    #side_equ["SIDE2"] = 0
    #side_equ["SIDE3"] = 0

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = isosceles_angle_check(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(side_equ)
    """


    def isosceles_side_check(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for side1, side2, angle1, angle2 in [(tri1[1], tri1[3], tri1[0], tri1[4]), (tri1[3], tri1[5], tri1[2], tri1[0]), (tri1[1], tri1[5], tri1[2], tri1[4])]:
                    if (side1 in side_equ and side2 in side_equ and side_equ[side1] == side_equ[side2]) or (side1 not in side_equ and side2 not in side_equ and side1 == side2):
                        angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle1, angle2, loop_flg, exe_flg)

        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {"TST" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"]}
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE2"] = 0
    ###テスト2
    #triangle_lst["TST"][3] = "SIDE1"
    ###テスト3
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE2"] = 0
    #angle_equ["ANGLE3"] = 0
    #angle_equ["ANGLE1"] = 0

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = isosceles_side_check(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(angle_equ)
    """


    def two_angle_check(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for tri2 in triangle_lst.values():
                    if tri1 == tri2:
                        continue

                    for angle_1_A, angle_1_B in itertools.combinations([tri1[0], tri1[2], tri1[4]], 2):
                        for angle_2_A, angle_2_B in itertools.combinations([tri2[0], tri2[2], tri2[4]], 2):
                            angle_1_A_val = angle_equ[angle_1_A] if angle_1_A in angle_equ else angle_1_A
                            angle_1_B_val = angle_equ[angle_1_B] if angle_1_B in angle_equ else angle_1_B
                            angle_2_A_val = angle_equ[angle_2_A] if angle_2_A in angle_equ else angle_2_A
                            angle_2_B_val = angle_equ[angle_2_B] if angle_2_B in angle_equ else angle_2_B

                            if {angle_1_A_val, angle_1_B_val} == {angle_2_A_val, angle_2_B_val}:
                                angle_1_C = [A for A in [tri1[0], tri1[2], tri1[4]] if A not in [angle_1_A, angle_1_B]][0]
                                angle_2_C = [A for A in [tri2[0], tri2[2], tri2[4]] if A not in [angle_2_A, angle_2_B]][0]

                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_C, loop_flg, exe_flg)
        
        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {
        "TST1" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"],
        "TST2" : ["ANGLE4", "SIDE4", "ANGLE5", "SIDE5", "ANGLE6", "SIDE6"]
    }
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE4"] = 0
    #angle_equ["ANGLE2"] = 1
    #angle_equ["ANGLE5"] = 1
    ###テスト2
    #triangle_lst["TST2"][0] = "ANGLE1"
    #triangle_lst["TST2"][2] = "ANGLE2"
    ###テスト3
    #triangle_lst["TST2"][0] = "ANGLE1"
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    ###テスト4
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE4"] = 0
    #angle_equ["ANGLE2"] = 1
    #angle_equ["ANGLE5"] = 1
    #angle_equ["ANGLE3"] = 2
    #angle_equ["ANGLE6"] = 2

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = two_angle_check(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(angle_equ)
    """


    def angle_side_angle(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for tri2 in triangle_lst.values():
                    if tri1 == tri2:
                        continue

                    for angle_1_A, side_1, angle_1_B, side_1_X, angle_1_C, side_1_Y in [(tri1[0], tri1[1], tri1[2], tri1[3], tri1[4], tri1[5]), \
                                                                                        (tri1[2], tri1[3], tri1[4], tri1[5], tri1[0], tri1[1]), \
                                                                                        (tri1[4], tri1[5], tri1[0], tri1[1], tri1[2], tri1[3])]:
                        for angle_2_A, side_2, angle_2_B, side_2_X, angle_2_C, side_2_Y in [(tri2[0], tri2[1], tri2[2], tri2[3], tri2[4], tri2[5]), \
                                                                                            (tri2[2], tri2[3], tri2[4], tri2[5], tri2[0], tri2[1]), \
                                                                                            (tri2[4], tri2[5], tri2[0], tri2[1], tri2[2], tri2[3])]:
                            angle_1_A_val = angle_equ[angle_1_A] if angle_1_A in angle_equ else angle_1_A
                            side_1_val = side_equ[side_1] if side_1 in side_equ else side_1
                            angle_1_B_val = angle_equ[angle_1_B] if angle_1_B in angle_equ else angle_1_B
                            angle_2_A_val = angle_equ[angle_2_A] if angle_2_A in angle_equ else angle_2_A
                            side_2_val = side_equ[side_2] if side_2 in side_equ else side_2
                            angle_2_B_val = angle_equ[angle_2_B] if angle_2_B in angle_equ else angle_2_B

                            if side_1_val == side_2_val and {angle_1_A_val, angle_1_B_val} == {angle_2_A_val, angle_2_B_val}:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_C, loop_flg, exe_flg)
                                
                                if angle_1_A_val == angle_2_A_val:
                                    side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side_1_X, side_2_X, loop_flg, exe_flg)
                                    side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side_1_Y, side_2_Y, loop_flg, exe_flg)
                                else:
                                    side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side_1_X, side_2_Y, loop_flg, exe_flg)
                                    side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side_1_Y, side_2_X, loop_flg, exe_flg)
        
        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {
        "TST1" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"],
        "TST2" : ["ANGLE4", "SIDE4", "ANGLE5", "SIDE5", "ANGLE6", "SIDE6"]
    }
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE4"] = 0
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 1
    #angle_equ["ANGLE5"] = 1
    ###テスト2
    #triangle_lst["TST2"][0] = "ANGLE1"
    #triangle_lst["TST2"][1] = "SIDE1"
    #triangle_lst["TST2"][2] = "ANGLE2"
    ###テスト3
    #triangle_lst["TST2"][0] = "ANGLE1"
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    ###テスト4
    #angle_equ["ANGLE1"] = 0
    #angle_equ["ANGLE4"] = 0
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 1
    #angle_equ["ANGLE5"] = 1
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    #angle_equ["ANGLE3"] = 2
    #angle_equ["ANGLE6"] = 2
    #side_equ["SIDE3"] = 2
    #side_equ["SIDE6"] = 2

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = angle_side_angle(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(angle_equ)
    print(side_equ)
    """


    def side_angle_side(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for tri2 in triangle_lst.values():
                    if tri1 == tri2:
                        continue

                    for side_1_A, angle_1, side_1_B, angle_1_X, side_1_C, angle_1_Y in [(tri1[1], tri1[2], tri1[3], tri1[4], tri1[5], tri1[0]), \
                                                                                        (tri1[3], tri1[4], tri1[5], tri1[0], tri1[1], tri1[2]), \
                                                                                        (tri1[5], tri1[0], tri1[1], tri1[2], tri1[3], tri1[4])]:
                        for side_2_A, angle_2, side_2_B, angle_2_X, side_2_C, angle_2_Y in [(tri2[1], tri2[2], tri2[3], tri2[4], tri2[5], tri2[0]), \
                                                                                            (tri2[3], tri2[4], tri2[5], tri2[0], tri2[1], tri2[2]), \
                                                                                            (tri2[5], tri2[0], tri2[1], tri2[2], tri2[3], tri2[4])]:
                            side_1_A_val = side_equ[side_1_A] if side_1_A in side_equ else side_1_A
                            angle_1_val = angle_equ[angle_1] if angle_1 in angle_equ else angle_1
                            side_1_B_val = side_equ[side_1_B] if side_1_B in side_equ else side_1_B
                            side_2_A_val = side_equ[side_2_A] if side_2_A in side_equ else side_2_A
                            angle_2_val = angle_equ[angle_2] if angle_2 in angle_equ else angle_2
                            side_2_B_val = side_equ[side_2_B] if side_2_B in side_equ else side_2_B

                            if angle_1_val == angle_2_val and {side_1_A_val, side_1_B_val} == {side_2_A_val, side_2_B_val}:
                                side_equ, loop_flg, exe_flg = equ_side_sub(side_equ, side_1_C, side_2_C, loop_flg, exe_flg)

                                if side_1_A_val == side_2_A_val:
                                    angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_X, angle_2_X, loop_flg, exe_flg)
                                    angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_Y, angle_2_Y, loop_flg, exe_flg)
                                else:
                                    angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_X, angle_2_Y, loop_flg, exe_flg)
                                    angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_Y, angle_2_X, loop_flg, exe_flg)
        
        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {
        "TST1" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"],
        "TST2" : ["ANGLE4", "SIDE4", "ANGLE5", "SIDE5", "ANGLE6", "SIDE6"]
    }
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    ###テスト2
    #triangle_lst["TST2"][1] = "SIDE1"
    #triangle_lst["TST2"][2] = "ANGLE2"
    #triangle_lst["TST2"][3] = "SIDE2"
    ###テスト3
    #triangle_lst["TST2"][1] = "SIDE1"
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    #side_equ["SIDE2"] = 0
    #side_equ["SIDE5"] = 0
    ###テスト4
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    #angle_equ["ANGLE3"] = 1
    #angle_equ["ANGLE6"] = 1
    #side_equ["SIDE3"] = 2
    #side_equ["SIDE6"] = 2
    #angle_equ["ANGLE1"] = 2
    #angle_equ["ANGLE4"] = 2

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = side_angle_side(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(angle_equ)
    print(side_equ)
    """


    def side_side_side(triangle_lst, angle_equ, side_equ, exe_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for tri1 in triangle_lst.values():
                for tri2 in triangle_lst.values():
                    if tri1 == tri2:
                        continue

                    angle_1_A, side_1_A, angle_1_B, side_1_B, angle_1_C, side_1_C = tri1
                    angle_2_A, side_2_A, angle_2_B, side_2_B, angle_2_C, side_2_C = tri2

                    side_1_A_val = side_equ[side_1_A] if side_1_A in side_equ else side_1_A
                    side_1_B_val = side_equ[side_1_B] if side_1_B in side_equ else side_1_B
                    side_1_C_val = side_equ[side_1_C] if side_1_C in side_equ else side_1_C
                    side_2_A_val = side_equ[side_2_A] if side_2_A in side_equ else side_2_A
                    side_2_B_val = side_equ[side_2_B] if side_2_B in side_equ else side_2_B
                    side_2_C_val = side_equ[side_2_C] if side_2_C in side_equ else side_2_C

                    if {side_1_A_val, side_1_B_val, side_1_C_val} == {side_2_A_val, side_2_B_val, side_2_C_val}:
                        if side_1_A_val == side_2_A_val:
                            if side_1_B_val == side_2_B_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_A, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_B, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_C, loop_flg, exe_flg)
                            elif side_1_B_val == side_2_C_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_B, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_A, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_C, loop_flg, exe_flg)
                        elif side_1_A_val == side_2_B_val:
                            if side_1_B_val == side_2_A_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_C, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_B, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_A, loop_flg, exe_flg)
                            elif side_1_B_val == side_2_C_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_B, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_C, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_A, loop_flg, exe_flg)
                        elif side_1_A_val == side_2_C_val:
                            if side_1_B_val == side_2_A_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_C, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_A, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_B, loop_flg, exe_flg)
                            elif side_1_B_val == side_2_B_val:
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_A, angle_2_A, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_B, angle_2_C, loop_flg, exe_flg)
                                angle_equ, loop_flg, exe_flg = equ_angle_sub(angle_equ, angle_1_C, angle_2_B, loop_flg, exe_flg)

        return triangle_lst, angle_equ, side_equ, exe_flg

    """
    triangle_lst = {
        "TST1" : ["ANGLE1", "SIDE1", "ANGLE2", "SIDE2", "ANGLE3", "SIDE3"],
        "TST2" : ["ANGLE4", "SIDE4", "ANGLE5", "SIDE5", "ANGLE6", "SIDE6"]
    }
    angle_equ = {}
    side_equ = {}

    ###テスト1
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    #side_equ["SIDE3"] = 2
    #side_equ["SIDE6"] = 2
    ###テスト2
    #triangle_lst["TST2"][1] = "SIDE1"
    #triangle_lst["TST2"][3] = "SIDE2"
    #triangle_lst["TST2"][5] = "SIDE3"
    ###テスト3
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    #triangle_lst["TST2"][5] = "SIDE3"
    ###テスト4
    #side_equ["SIDE1"] = 0
    #side_equ["SIDE4"] = 0
    #angle_equ["ANGLE2"] = 0
    #angle_equ["ANGLE5"] = 0
    #side_equ["SIDE2"] = 1
    #side_equ["SIDE5"] = 1
    #angle_equ["ANGLE3"] = 1
    #angle_equ["ANGLE6"] = 1
    #side_equ["SIDE3"] = 2
    #side_equ["SIDE6"] = 2
    #angle_equ["ANGLE1"] = 2
    #angle_equ["ANGLE4"] = 2

    exe_flg = False
    triangle_lst, angle_equ, side_equ, exe_flg = side_side_side(triangle_lst, angle_equ, side_equ, exe_flg)
    print(exe_flg)
    print(angle_equ)
    print(side_equ)
    """


    def sum_angle_check(sum_angle_lst, angle_equ, tri_theorem_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for sum_angle_1 in sum_angle_lst:
                for sum_angle_2 in sum_angle_lst:
                    if sum_angle_1 == sum_angle_2:
                        continue

                    angle_1_X, angle_1_Y, angle_1_sum = sum_angle_1
                    angle_2_X, angle_2_Y, angle_2_sum = sum_angle_2

                    angle_1_X_val = angle_equ[angle_1_X] if angle_1_X in angle_equ else angle_1_X
                    angle_1_Y_val = angle_equ[angle_1_Y] if angle_1_Y in angle_equ else angle_1_Y
                    angle_1_sum_val = angle_equ[angle_1_sum] if angle_1_sum in angle_equ else angle_1_sum
                    angle_2_X_val = angle_equ[angle_2_X] if angle_2_X in angle_equ else angle_2_X
                    angle_2_Y_val = angle_equ[angle_2_Y] if angle_2_Y in angle_equ else angle_2_Y
                    angle_2_sum_val = angle_equ[angle_2_sum] if angle_2_sum in angle_equ else angle_2_sum

                    for either_angle_1 in [angle_1_X, angle_1_Y]:
                        for either_angle_2 in [angle_2_X, angle_2_Y]:
                            either_angle_1_val = angle_equ[either_angle_1] if either_angle_1 in angle_equ else either_angle_1
                            either_angle_2_val = angle_equ[either_angle_2] if either_angle_2 in angle_equ else either_angle_2

                            if angle_1_sum_val == angle_2_sum_val and either_angle_1_val == either_angle_2_val:
                                another_angle_1 = [A for A in [angle_1_X, angle_1_Y] if A != either_angle_1][0]
                                another_angle_2 = [A for A in [angle_2_X, angle_2_Y] if A != either_angle_2][0]

                                angle_equ, loop_flg, tri_theorem_flg = equ_angle_sub(angle_equ, another_angle_1, another_angle_2, loop_flg, tri_theorem_flg)

                    if {angle_1_X_val, angle_1_Y_val} == {angle_2_X_val, angle_2_Y_val}:
                        angle_equ, loop_flg, tri_theorem_flg = equ_angle_sub(angle_equ, angle_1_sum, angle_2_sum, loop_flg, tri_theorem_flg)
        
        return sum_angle_lst, angle_equ, tri_theorem_flg

    """
    sum_angle_lst = [
        ["TST1", "TST2", "TST3"],
        ["TST4", "TST5", "TST6"]
    ]
    angle_equ = {}

    ###テスト1
    #angle_equ["TST1"] = 0
    #angle_equ["TST4"] = 0
    #angle_equ["TST2"] = 1
    #angle_equ["TST5"] = 1
    ###テスト2
    #angle_equ["TST1"] = 0
    #angle_equ["TST5"] = 0
    #angle_equ["TST3"] = 1
    #angle_equ["TST6"] = 1
    ###テスト3
    #angle_equ["TST1"] = 0
    #angle_equ["TST4"] = 0
    #sum_angle_lst[1][1] = "TST2"
    ###テスト4
    #angle_equ["TST1"] = 0
    #angle_equ["TST5"] = 0
    #sum_angle_lst[1][2] = "TST3"
    ###テスト5
    #angle_equ["TST1"] = 0
    #angle_equ["TST4"] = 0
    #angle_equ["TST2"] = 1
    #angle_equ["TST5"] = 1
    #angle_equ["TST3"] = 2
    #angle_equ["TST6"] = 2

    tri_theorem_flg = False
    sum_angle_lst, angle_equ, tri_theorem_flg = sum_angle_check(sum_angle_lst, angle_equ, tri_theorem_flg)
    print(tri_theorem_flg)
    print(angle_equ)
    """


    def sum_side_check(sum_side_lst, side_equ, tri_theorem_flg):
        loop_flg = True

        while loop_flg:
            loop_flg = False

            for sum_side_1 in sum_side_lst:
                for sum_side_2 in sum_side_lst:
                    if sum_side_1 == sum_side_2:
                        continue

                    side_1_X, side_1_Y, side_1_sum = sum_side_1
                    side_2_X, side_2_Y, side_2_sum = sum_side_2

                    side_1_X_val = side_equ[side_1_X] if side_1_X in side_equ else side_1_X
                    side_1_Y_val = side_equ[side_1_Y] if side_1_Y in side_equ else side_1_Y
                    side_1_sum_val = side_equ[side_1_sum] if side_1_sum in side_equ else side_1_sum
                    side_2_X_val = side_equ[side_2_X] if side_2_X in side_equ else side_2_X
                    side_2_Y_val = side_equ[side_2_Y] if side_2_Y in side_equ else side_2_Y
                    side_2_sum_val = side_equ[side_2_sum] if side_2_sum in side_equ else side_2_sum

                    for either_side_1 in [side_1_X, side_1_Y]:
                        for either_side_2 in [side_2_X, side_2_Y]:
                            either_side_1_val = side_equ[either_side_1] if either_side_1 in side_equ else either_side_1
                            either_side_2_val = side_equ[either_side_2] if either_side_2 in side_equ else either_side_2

                            if side_1_sum_val == side_2_sum_val and either_side_1_val == either_side_2_val:
                                another_side_1 = [A for A in [side_1_X, side_1_Y] if A != either_side_1][0]
                                another_side_2 = [A for A in [side_2_X, side_2_Y] if A != either_side_2][0]

                                side_equ, loop_flg, tri_theorem_flg = equ_side_sub(side_equ, another_side_1, another_side_2, loop_flg, tri_theorem_flg)

                    if {side_1_X_val, side_1_Y_val} == {side_2_X_val, side_2_Y_val}:
                        side_equ, loop_flg, tri_theorem_flg = equ_side_sub(side_equ, side_1_sum, side_2_sum, loop_flg, tri_theorem_flg)
        
        return sum_side_lst, side_equ, tri_theorem_flg

    """
    sum_side_lst = [
        ["TST1", "TST2", "TST3"],
        ["TST4", "TST5", "TST6"]
    ]
    side_equ = {}

    ###テスト1
    #side_equ["TST1"] = 0
    #side_equ["TST4"] = 0
    #side_equ["TST2"] = 1
    #side_equ["TST5"] = 1
    ###テスト2
    #side_equ["TST1"] = 0
    #side_equ["TST5"] = 0
    #side_equ["TST3"] = 1
    #side_equ["TST6"] = 1
    ###テスト3
    #side_equ["TST1"] = 0
    #side_equ["TST4"] = 0
    #sum_side_lst[1][1] = "TST2"
    ###テスト4
    #side_equ["TST1"] = 0
    #side_equ["TST5"] = 0
    #sum_side_lst[1][2] = "TST3"
    ###テスト5
    #side_equ["TST1"] = 0
    #side_equ["TST4"] = 0
    #side_equ["TST2"] = 1
    #side_equ["TST5"] = 1
    #side_equ["TST3"] = 2
    #side_equ["TST6"] = 2

    tri_theorem_flg = False
    sum_side_lst, side_equ, tri_theorem_flg = sum_side_check(sum_side_lst, side_equ, tri_theorem_flg)
    print(tri_theorem_flg)
    print(side_equ)
    """


    def triangle_theorem_loop(triangle_lst, angle_equ, side_equ):
        exe_flg = True

        while exe_flg:
            exe_flg = False

            triangle_lst, angle_equ, side_equ, exe_flg = isosceles_angle_check(triangle_lst, angle_equ, side_equ, exe_flg)
            triangle_lst, angle_equ, side_equ, exe_flg = isosceles_side_check(triangle_lst, angle_equ, side_equ, exe_flg)
            triangle_lst, angle_equ, side_equ, exe_flg = two_angle_check(triangle_lst, angle_equ, side_equ, exe_flg)
            triangle_lst, angle_equ, side_equ, exe_flg = angle_side_angle(triangle_lst, angle_equ, side_equ, exe_flg)
            triangle_lst, angle_equ, side_equ, exe_flg = side_angle_side(triangle_lst, angle_equ, side_equ, exe_flg)
            triangle_lst, angle_equ, side_equ, exe_flg = side_side_side(triangle_lst, angle_equ, side_equ, exe_flg)

        return triangle_lst, angle_equ, side_equ


    tri_theorem_flg = True

    while tri_theorem_flg:
        triangle_lst, angle_equ, side_equ = triangle_theorem_loop(triangle_lst, angle_equ, side_equ)
        tri_theorem_flg = False

        sum_angle_lst, angle_equ, tri_theorem_flg = sum_angle_check(sum_angle_lst, angle_equ, tri_theorem_flg)
        sum_side_lst, side_equ, tri_theorem_flg = sum_side_check(sum_side_lst, side_equ, tri_theorem_flg)


    print()
    print("角")
    angle_result_lst = {}
    for k, v in angle_equ.items():
        if v not in angle_result_lst:
            angle_result_lst[v] = []
        
        angle_result_lst[v].append(k)

    for k, v in sorted(angle_result_lst.items()):
        print(str(k) + " : " + str(v))


    print()
    print("角の和")
    sum_angle_result_lst = []
    for angles in sum_angle_lst:
        angle1, angle2, angle3 = angles
        angle_formula = ["","",""]

        if angle1 not in angle_equ and angle2 not in angle_equ:
            angle_formula[0] = str(angle1)
            angle_formula[1] = str(angle2)
        elif angle1 not in angle_equ and angle2 in angle_equ:
            angle_formula[0] = "[" + str(angle_equ[angle2]) + "]"
            angle_formula[1] = str(angle1)
        elif angle1 in angle_equ and angle2 not in angle_equ:
            angle_formula[0] = "[" + str(angle_equ[angle1]) + "]"
            angle_formula[1] = str(angle2)
        elif angle1 in angle_equ and angle2 in angle_equ:
            if angle_equ[angle1] > angle_equ[angle2]:
                angle_formula[0] = "[" + str(angle_equ[angle2]) + "]"
                angle_formula[1] = "[" + str(angle_equ[angle1]) + "]"
            elif angle_equ[angle1] <= angle_equ[angle2]:
                angle_formula[0] = "[" + str(angle_equ[angle1]) + "]"
                angle_formula[1] = "[" + str(angle_equ[angle2]) + "]"

        if angle3 in angle_equ:
            angle_formula[2] = "[" + str(angle_equ[angle3]) + "]"
        else:
            angle_formula[2] = str(angle3)

        sum_angle_result_lst.append(angle_formula)

    sum_angle_result_lst = list(map(list, set(map(tuple, sum_angle_result_lst))))    #二次元配列の重複削除、調べたらこんな方法が出てきた

    for angle1, angle2, angle3 in sorted(sum_angle_result_lst, key=lambda x: x[2]):
        print(angle1 + " + " + angle2 + " == " + angle3)


    print()
    print("辺")
    side_result_lst = {}
    for k, v in side_equ.items():
        if v not in side_result_lst:
            side_result_lst[v] = []

        side_result_lst[v].append(k)

    for k, v in sorted(side_result_lst.items()):
        print(str(k) + " : " + str(v))


    print()
    print("辺の和")
    sum_side_result_lst = []
    for sides in sum_side_lst:
        side1, side2, side3 = sides
        side_formula = ["","",""]

        if side1 not in side_equ and side2 not in side_equ:
            side_formula[0] = str(side1)
            side_formula[1] = str(side2)
        elif side1 not in side_equ and side2 in side_equ:
            side_formula[0] = "[" + str(side_equ[side2]) + "]"
            side_formula[1] = str(side1)
        elif side1 in side_equ and side2 not in side_equ:
            side_formula[0] = "[" + str(side_equ[side1]) + "]"
            side_formula[1] = str(side2)
        elif side1 in side_equ and side2 in side_equ:
            if side_equ[side1] > side_equ[side2]:
                side_formula[0] = "[" + str(side_equ[side2]) + "]"
                side_formula[1] = "[" + str(side_equ[side1]) + "]"
            elif side_equ[side1] <= side_equ[side2]:
                side_formula[0] = "[" + str(side_equ[side1]) + "]"
                side_formula[1] = "[" + str(side_equ[side2]) + "]"

        if side3 in side_equ:
            side_formula[2] = "[" + str(side_equ[side3]) + "]"
        else:
            side_formula[2] = str(side3)

        sum_side_result_lst.append(side_formula)

    sum_side_result_lst = list(map(list, set(map(tuple, sum_side_result_lst))))    #二次元配列の重複削除、調べたらこんな方法が出てきた

    for side1, side2, side3 in sorted(sum_side_result_lst, key=lambda x: x[2]):
        print(side1 + " + " + side2 + " == " + side3)


    print()
    print("三角形")
    for k, tri1 in triangle_lst.items():
        angle1_val = tri1[0] + "[" + str(angle_equ[tri1[0]]) + "]" if tri1[0] in angle_equ else str(tri1[0])
        side1_val = tri1[1] + "[" + str(side_equ[tri1[1]]) + "]" if tri1[1] in side_equ else str(tri1[1])
        angle2_val = tri1[2] + "[" + str(angle_equ[tri1[2]]) + "]" if tri1[2] in angle_equ else str(tri1[2])
        side2_val = tri1[3] + "[" + str(side_equ[tri1[3]]) + "]" if tri1[3] in side_equ else str(tri1[3])
        angle3_val = tri1[4] + "[" + str(angle_equ[tri1[4]]) + "]" if tri1[4] in angle_equ else str(tri1[4])
        side3_val = tri1[5] + "[" + str(side_equ[tri1[5]]) + "]" if tri1[5] in side_equ else str(tri1[5])

        print("" + k + " : [" + angle1_val + ", " + side1_val + ", " + angle2_val + ", " + side2_val + ", " + angle3_val + ", " + side3_val + "]")