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

→‎{{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 primeunique+positive numbersintegers drawn from two sequences.
<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 @primesbase = ((21..*N/2).grep:{.is-prime})[^N] ; and my @roof = ((N/2+1).Int..N) ; # for randomness.pick(*)
my ($bTotal,$rTotal) <<[+] =<< [ @base, @roof ]>>.sum ;
my @base = @primes[0..N/2-1] and my @roof = @primes[N/2..*]; # add .pick(*)
 
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) (145181.833333818182 500))
((0 0) (145181.833333818182 500) (200166.666667 0))
((145181.833333818182 500) (200166.666667 0) (375409.090909 500))
((200166.666667 0) (375409.090909 500) (500 0))
((375409.090909 500) (500 0) (645681.833333818182 500))
((500 0) (645681.833333818182 500) (1000 0))
((645681.833333818182 500) (1000 0) (1000 500))
</pre>
 
351

edits