# Divide into 2 isosceles triangles

Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with 180 - x - y), draw a line segment that cuts this triangle into two isosceles triangles. You need to output the angle measures of both of your triangles.

However, because the base angles are the same, you only need to output the list [apex angle, base angle] of the divided triangles for both of the isosceles triangles. You can output the divided triangles in any order.

## An example

Say your input is 100, 60.

Let's take a look at the complete triangle first. The triangle looks approximately like this.

100

60            20

Now we try to divide one of the angles such that two divided triangles are both isosceles triangles.

100

(40,20)           20

Now our bottom triangle is an isosceles triangle, since both of the base angles
of the bottom triangle are 20. The angle measures of the bottom triangle
looks approximately like this.

140
20             20

Now, is the top triangle an isosceles triangle?

100
40
40

It is an isosceles triangle, because two of the angle measures are 40.

Therefore, for [100, 60], you need to output [[100, 40], [140, 20]].



## Example cases

[20, 40] -> [[140, 20], [100, 40]]
[45, 45] -> [[90, 45], [90, 45]]
[36, 72] -> [[108, 36], [36, 72]]
[108, 36] -> [[108, 36], [36, 72]]
[44, 132] -> [[92, 44], [4, 88]]


## Specifications

• You can always assume that the triangle is dividable into two isosceles triangles.
• You can output one of the many solutions of the cases; for example, you can also output [20, 40] -> [[100, 40], [20, 80]] for the first test case.
• Nice challenge, but I think it could benefit a lot from some (rough) pictures to illustrate the example better. It took me a while to figure out what was being asked tbh. Jul 1 '20 at 14:59
• Is it guaranteed that the input triangle can be divided that way? (For instance, it's impossible to divide an equilateral triangle into 2 isosceles triangles.) Jul 1 '20 at 16:00
• Did you mean [20, 40] -> [[140, 20], [100, 40]] for the first test case? Jul 1 '20 at 16:29
• The 3rd test case should be [36, 72] -> [108, 36], [36, 72] Jul 1 '20 at 17:07
• FYI I found a PDF linked from a Math Overflow question. A triangle can be divided into 2 isosceles triangles either if the smallest angle is < 45° and is exactly one half or one third of one of the other angles, or if one of the angles is 90°.
– Neil
Jul 1 '20 at 19:10

# 05AB1E, 39 38 bytes

OƵΔαª©90KD®Qiʒ45‹®y23S*åà*}ßx‚}ε90α·y‚


Input as a pair of integers; output as a pair of pairs of integers.

Explanation:

O                 # Take the sum of the (implicit) input-pair of angles
ƵΔα              # Get the absolute difference with (compressed) 180
ª             # Append that third angle to the (implicit) input-pair
©            # Store it in variable ® (without popping)
90K               # Remove 90 from the triplet of angles
D              # Duplicate it
®Qi               # If it's still equal to ® (thus none were 90):
ʒ              #  Filter the triplet by:
45‹           #   Check that the angle is smaller than 45
*  #   AND
y2 S*     #   Check if the angle multiplied by 2
3S* à   #   or multiplied by 3
®     å    #   is in the triplet of angles ®
}ß             #  After the filter: pop and push the minimum of the remaining angles
x            #  Double it (without popping)
‚           #  Pair the non-doubled and doubled values together
}ε              # After the if statement: map the angles in the pair to:
90α           #  Get the absolute difference with 90
·          #  Double it
y‚        #  And pair it with the non-mapped angle
# (after which the resulting pair of pairs is output implicitly)


See this 05AB1E tip of mine (section How to compress large integers?) to understand why ƵΔ is 180.

# Python 3.8 (pre-release), 123 129 bytes

g=lambda*p:[[180-2*x,x]for x in p]
f=lambda a,b:((c:=180-a-b)==90or c>45>2in{a/b,b/a})*g(a,b)or(c/3in{a,b})*g(c/3,c/3*2)or f(b,c)


Try it online!

A function that takes in 2 angles, and returns the 2 isosceles triangles. If the given triangle cannot be divided, the function loops forever.

# APL (Dyalog Unicode), 47 bytes

(⊢,⍨¨2×90-⊢)∘{90∊⍵:⍵~90⋄1 2×⌊/⍵∩∊⍵÷⊂2 3},,180-+


Try it online!

A tacit function that takes two angles as left and right arguments.

Uses the information found by Neil, modified to take care of xnor's test case:

A triangle can be divided into 2 isosceles triangles either if one of the angles is < 45° and is exactly one half or one third of one of the other angles, or if one of the angles is 90°.

Now, the base angles of the result can be found as follows:

• If one of the angles is 90°, the bases are the other two angles.
• Otherwise, one of the angles is < 45° and is exactly one half or one third of one of the other angles should hold, because the input is guaranteed to have a solution. In this case, the angle satisfying the condition becomes the base for one triangle, and the other triangle's base angle is twice the angle.

### How it works: the code

(⊢,⍨¨2×90-⊢)∘{90∊⍵:⍵~90⋄1 2×⌊/⍵∩∊⍵÷⊂2 3},,180-+  ⍝ Left, Right: two angles
,,180-+  ⍝ Length-3 vector of three angles
{                         }  ⍝ Find two base angles:
90∊⍵:⍵~90⋄                  ⍝ If an angle is 90, the bases are the other two
⍵∩∊⍵÷⊂2 3   ⍝ Otherwise, find the angles that are 1÷2 or 1÷3 of another
1 2×⌊/            ⍝ Take the minimum angle of that and attach its double
(          )∘  ⍝ Attach apex angles to two base angles
2×90-⊢    ⍝ apex=180-2×base
⊢,⍨¨          ⍝ Attach each apex to the left of the base


# Charcoal, 66 bytes

Ｆ²⊞υＮ⊞υ⁻¹⁸⁰Συ≔Φυ∧‹ι⁴⁵∨№υ⊗ι№υ×³ιθ¿θ≔⟦⌊θ⊗⌊θ⟧θＦ№υ⁹⁰≔Φυ⁻⁹⁰κθＩＥθ⟦⊗⁻⁹⁰ιι


Try it online! Link is to verbose version of code. Explanation:

Ｆ²⊞υＮ


Input the two provided angles.

⊞υ⁻¹⁸⁰Συ


Calculate the third angle.

≔Φυ∧‹ι⁴⁵∨№υ⊗ι№υ×³ιθ


See if any angle under 45° appears doubled or tripled.

¿θ≔⟦⌊θ⊗⌊θ⟧θ


If so then the base angles of the result are that angle and the doubled angle.

Ｆ№υ⁹⁰


Otherwise if this is a right-angled triangle, ...

≔Φυ⁻⁹⁰κθ


... then the base angles of the result are the other two angles.

ＩＥθ⟦⊗⁻⁹⁰ιι


If we got any base angles then compute the apex angles and output all of the angles.

# R, 146132 128 bytes

or 158 150 146 bytes to output the 4 angles as 2 lists of 2 angles each.

function(i,j,t=c(i,j,180-i-j),s=min(t))if((45-s/4)%in%t,c(45-s/4,90+s/2,s,90-s/2),c(s,180-2*s,2*s,if(90%in%t,90-s,180-4*s)))


Try it online!

An approach that does not use the 'one-half or one-third' trick:

Consider initial triangle with angles a,b,s, where s is the smallest angle (so s is never divided). a will be the angle that gets divided.

case 1: right-angle triangle (uses both bases of smaller triangles as sides) => divide right angle

case 2: starting triangle uses base and base+wall of smaller triangles as sides

=> t1=b,b,d (where d is formed from divided angle: d=a-s)

=> t2=s,s,180-b

=> so (from t2) we get b=2*s and we can specify both t1 and t2 from s

case 3: starting triangle uses only 1 base as side (other is created internally)

=> t1=b,b,180-d (where d is formed from divided angle: d=a-b)

=> t2=s,d,d

=> so (from t2): d=90-s/2, and we can specify both t1 and t2 from s

and (from t1): b=45-s/4 to check when this case is satisfied (but we won't bother to do this...)

Readable code:

cuttri=function(i,j,t=c(i,j,180-i-j)){      # we don't know which angle is a or b
s=min(t)                                # but we know s is the smallest
if(90 %in% t){                          # case 1: right-angle triangle
list(c(90-s,2*s),c(s,180-2*s))}
else if((2*s) %in% t){                  # case 2:
list(c(2*s,180-4*s),c(s,180-2*s))}
else if((45-s/4) %in% t){               # case 3 (but we don't actually need to check if
list(c(45-s/4,90+s/2),c(s,90-s/2))}    # we're assured that triangle can be divided)
}


Note that because the golfed code skips the final check for case 3, the output will be incorrect if it is 'fed' non-valid angles corresponding to a triangle that can't be divided into two isosceles triangles.