Babylonian spiral: Difference between revisions
→{{header|Raku}}: Reduce unnecessary calculations, use more efficient abstractions, reduce execution time about another 50%, other minor style twiddles
Thundergnat (talk | contribs) m (→Independent implementation: slices rather than explicit enumerations) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Reduce unnecessary calculations, use more efficient abstractions, reduce execution time about another 50%, other minor style twiddles) |
||
Line 473:
:width<100%>, :height<100%>,
:rect[:width<100%>, :height<100%>, :style<fill:white;>],
:polyline[ :points
:style("stroke:red; stroke-width:6; fill:white;"),
:transform("scale (.05, -.05) translate (1000,-10000)")
Line 491:
===Independent implementation===
Exact same output;
<lang perl6>my @next = { :x(1), :y(1), :
sub next-interval (Int $int) {
@next.append: (0..$int).map: { %( :x($int), :y($_), :
@next = |@next.sort:
}
my @spiral = [\»+«] lazy gather {
my $
take [0,0];
take my @tail = 0,1;
Line 507:
my \Θ = atan2 |@tail[1,0];
my @this = @next.shift;
@this.push: @next.shift while @next and @next[0]<
my @candidates =
|((i,j),(-i,j),(i,-j),(-i,-j),(j,i),(-j,i),(j,-i),(-j,-i))
}
take @tail = |@candidates.min: { ( Θ - atan2 |.[1,0] ) % τ };
Line 518 ⟶ 519:
# The task
say "The first $_ Babylonian spiral points are:\n",
# Stretch
Line 527 ⟶ 528:
:width<100%>, :height<100%>,
:rect[:width<100%>, :height<100%>, :style<fill:white;>],
:polyline[ :points
:style("stroke:red; stroke-width:6; fill:white;"),
:transform("scale (.05, -.05) translate (1000,-10000)")
|