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

→‎{{header|Raku}}: after all the blunders, init 6
m (→‎{{header|Perl}}: use another 3)
(→‎{{header|Raku}}: after all the blunders, init 6)
Line 462:
 
=={{header|Raku}}==
AllThe first triangle verticesbisects liethe overrectangle via the lengthsdiagonal. and cornersThe rest of them all got one vertex at the rectangleorigin and theira locations areside defined by ratios among primeof numbers drawn from twoan ascending positive integer sequencessequence.
<lang perl6># 20220123 Raku programming solution
 
# Proof :
#
# H---A-----B-------C---------D-----------E
# | |
# | |
# | |
# O---------------------------------------L
#
# ▲OEL is unique as its area is the sum of the rest.
#
# The sum of length on sides for ▲OED > ▲ODC > ... > ▲OAH
# so no pairs of any will meet the SSS congruence requirement.
sub UnequalDivider (\L,\H,\N where N > 2) {
 
ifmy \sum N == 3( {my return@sequence (0,H),= (0,01..^N), ((2/5)*L,H), (L,0), (L,H) }.sum;
my \part = $ = 0;
 
( [ (0,0), (L,H), (L,0) ], ).Array.append: gather @sequence.map: -> \chunk {
my @primes = ((2..*).grep:{.is-prime})[^N] ; # for randomness
take [ (0,0), (L*part/sum,H), (L*(part+=chunk)/sum,H) ]
my @base = @primes[0..N/2-1] and my @roof = @primes[N/2..*]; # add .pick(*)
}
 
my ($bTotal,$rTotal) = [ @base, @roof ]>>.sum ;
my ($bPartial,$rPartial) = [ @base, @roof ]>>.shift ;
my @vertices = (0,H), (0,0), (($rPartial/$rTotal)*L,H), ;
 
for ^+@base {
@vertices.push: ( ($bPartial/$bTotal)*L , 0 );
if +@base == 1 { # last segment, the rest just by hand
return N %% 2 ?? @vertices.append: (L,H) , (L,0)
!! @vertices.append: (L*(1-@roof[*-1]/$rTotal),H), (L,0), (L,H)
}
($bPartial,$rPartial) <<+=<< [ @base, @roof ]>>.shift ;
@vertices.push: ( ($rPartial/$rTotal)*L , H );
}
}
 
.say for UnequalDivider(1000,500,7).rotor( 3 => -2 5);</lang>
{{out}}
<pre>
([(0 5000) (01000 0500) (145.8333331000 500)0)]
([(0 0) (145.8333330 500) (200100 0)500)]
[((145.8333330 5000) (200100 0500) (375300 500))]
[((2000 0) (375300 500) (600 500 0))]
[((3750 5000) (600 500 0) (645.8333331000 500))]
((500 0) (645.833333 500) (1000 0))
((645.833333 500) (1000 0) (1000 500))
</pre>
 
350

edits