Divide a rectangle into a number of unequal triangles: Difference between revisions

→‎{{header|Raku}}: moving the goalposts: now use a descending sequence to tell the triangles apart
(→‎{{header|Raku}}: after all the blunders, init 6)
(→‎{{header|Raku}}: moving the goalposts: now use a descending sequence to tell the triangles apart)
Line 462:
 
=={{header|Raku}}==
The first triangle bisects the rectangle via the diagonal. The rest of them all got one vertex at the origin and a side defined by ratios of numbers from ana ascendingdescending positive integer sequence.
<lang perl6># 20220123 Raku programming solution
 
# Proof :
#
# H---A-----B---A----C-----B----D---C-----D---E
# | |
# | |
Line 475:
# ▲OEL is unique as its area is the sum of the rest.
#
# Theand sumalso ofin lengthterms on sidesof forarea ▲OED▲OHA > ▲ODC▲OAB > ... > ▲OAH▲ODE
# so no pairs of any will meet the SSS congruence requirement.
 
sub UnequalDivider (\L,\H,\N where N > 2) {
 
my \sum = ( my @sequence = (1N^..^N.1) ).sum;
my \part = $ = 0;
 
( [ (0,0), (L,H), (L,0) ], ).Array.append: gather @sequence.map: -> \chunk {
take [ (0,0), (L*part/sum,H), (L*(part+=chunk)/sum,H) ] ;
}
}
Line 492:
<pre>
[(0 0) (1000 500) (1000 0)]
[(0 0) (0 500) (100400 500)]
[(0 0) (100400 500) (300700 500)]
[(0 0) (300700 500) (600900 500)]
[(0 0) (600900 500) (1000 500)]
</pre>
 
351

edits