Jelly, 15 bytes
RØ.ṗŒpFS=ɗƇUƑƇḢ
-1 byte thanks to caird coinheringaahing
RØ.ṗŒpFS=ɗƇUƑƇḢ Main Link; accepts w as the left argument and n as the right argument
R Range; [1, 2, ..., w]
Ø.ṗ [0, 1] ~ cartesian power ~ ^
Œp Cartesian Product of ^'s items - this gets all valid triangles of the right size
---ɗƇ Keep elements where
S the sum of
F the triangle flattened
= equals (right argument)
Ƈ Keep elements where
Ƒ the element is the same when
U each sub-list is reversed
Ḣ Get the first such triangle
Jelly, 15 bytes
RØ.ṗŒpFS=ɗƇUƑƇḢ
-1 byte thanks to caird coinheringaahing
RØ.ṗŒpFS=ɗƇUƑƇḢ Main Link; accepts w as the left argument and n as the right argument
R Range; [1, 2, ..., w]
Ø.ṗ [0, 1] ~ cartesian power ~ ^
Œp Cartesian Product of ^'s items - this gets all valid triangles of the right size
---ɗƇ Keep elements where
S the sum of
F the triangle flattened
= equals (right argument)
Ƈ Keep elements where
Ƒ the element is the same when
U each sub-list is reversed
Ḣ Get the first such triangle
Jelly, 1916 bytes
RSr_\ṖṬŒ!ṁ8ドルRR¤UƑƇḢRØ.ṗŒpFS=9ƲƇUƑƇḢ
Finds a valid solution by brute force. Waiting for caird to outgolf me by 50%.
Loading