Divide a rectangle into a number of unequal triangles: Difference between revisions
Divide a rectangle into a number of unequal triangles (view source)
Revision as of 17:10, 25 January 2022
, 2 years ago→{{header|Raku}}: revised as using primes is an overkill
m (→{{header|Raku}}: fix a mistake) |
(→{{header|Raku}}: revised as using primes is an overkill) |
||
Line 418:
=={{header|Raku}}==
All triangle vertices lie over the lengths and corners of the rectangle and their locations are defined by ratios among
<lang perl6># 20220123 Raku programming solution
Line 425:
if N == 3 { return (0,H), (0,0), ((2/5)*L,H), (L,0), (L,H) }
my @
▲ my ($bTotal,$rTotal) <<[+]=<< [ @base, @roof ] ;
my ($bPartial,$rPartial) = [ @base, @roof ]>>.shift ;
my @vertices = (0,H), (0,0), (($rPartial/$rTotal)*L,H), ;
for ^+@base {
Line 446 ⟶ 444:
{{out}}
<pre>
((0 500) (0 0) (
((0 0) (
((
((
((
((500 0) (
((
</pre>
|