Yellowstone sequence: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 35:
:* The OEIS entry: [https://oeis.org/A098550 A098550 The Yellowstone permutation].
:* Applegate et al, 2015: The Yellowstone Permutation [https://arxiv.org/abs/1501.01669].
=={{header|Factor}}==
Line 586 ⟶ 585:
1 2 3 4 9 8 15 14 5 6 25 12 35 16 7 10 21 20 27 22 39 11 13 33 26 45 28 51 32 17</pre>
See graph at [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/yellowstone-sequence.png off-site PNG image]
=={{header|Perl 6}}==▼
{{works with|Rakudo|2020.01}}▼
Not really clear whether a line graph or bar graph was desired, so generate both. Also, 100 points don't really give a good feel for the overall shape so do 500. ▼
<lang perl6>my @yellowstone = 1, 2, 3, -> $q, $p {▼
state @used = True xx 4;▼
state $min = 3;▼
my \index = ($min .. *).first: { not @used[$_] and $_ gcd $q != 1 and $_ gcd $p == 1 };▼
@used[index] = True;▼
$min = @used.first(!*, :k) // +@used - 1;▼
index▼
} … *;▼
put "The first 30 terms in the Yellowstone sequence:\n", @yellowstone[^30];▼
use SVG;▼
use SVG::Plot;▼
my @x = ^500;▼
my $chart = SVG::Plot.new(▼
background => 'white',▼
width => 1000,▼
height => 600,▼
plot-width => 950,▼
plot-height => 550,▼
x => @x,▼
x-tick-step => { 10 },▼
y-tick-step => { 50 },▼
min-y-axis => 0,▼
values => [@yellowstone[@x],],▼
title => "Yellowstone Sequence - First {+@x} values (zero indexed)",▼
);▼
my $line = './Yellowstone-sequence-line-perl6.svg'.IO;▼
my $bars = './Yellowstone-sequence-bars-perl6.svg'.IO;▼
$line.spurt: SVG.serialize: $chart.plot: :lines;▼
$bars.spurt: SVG.serialize: $chart.plot: :bars;</lang>▼
{{out}}▼
<pre>The first 30 terms in the Yellowstone sequence:▼
1 2 3 4 9 8 15 14 5 6 25 12 35 16 7 10 21 20 27 22 39 11 13 33 26 45 28 51 32 17</pre>▼
See (offsite SVG images) [https://github.com/thundergnat/rc/blob/master/img/Yellowstone-sequence-line-perl6.svg Line graph] or [https://github.com/thundergnat/rc/blob/master/img/Yellowstone-sequence-bars-perl6.svg Bar graph]▼
=={{header|Phix}}==
Line 845 ⟶ 798:
{{Out}}
<pre>1,2,3,4,9,8,15,14,5,6,25,12,35,16,7,10,21,20,27,22,39,11,13,33,26,45,28,51,32,17]</pre>
(formerly Perl 6)
▲{{works with|Rakudo|2020.01}}
▲Not really clear whether a line graph or bar graph was desired, so generate both. Also, 100 points don't really give a good feel for the overall shape so do 500.
▲<lang perl6>my @yellowstone = 1, 2, 3, -> $q, $p {
▲ state @used = True xx 4;
▲ state $min = 3;
▲ my \index = ($min .. *).first: { not @used[$_] and $_ gcd $q != 1 and $_ gcd $p == 1 };
▲ @used[index] = True;
▲ $min = @used.first(!*, :k) // +@used - 1;
▲ index
▲} … *;
▲put "The first 30 terms in the Yellowstone sequence:\n", @yellowstone[^30];
▲use SVG;
▲use SVG::Plot;
▲my @x = ^500;
▲my $chart = SVG::Plot.new(
▲ background => 'white',
▲ width => 1000,
▲ height => 600,
▲ plot-width => 950,
▲ plot-height => 550,
▲ x => @x,
▲ x-tick-step => { 10 },
▲ y-tick-step => { 50 },
▲ min-y-axis => 0,
▲ values => [@yellowstone[@x],],
▲ title => "Yellowstone Sequence - First {+@x} values (zero indexed)",
▲);
▲my $line = './Yellowstone-sequence-line-perl6.svg'.IO;
▲my $bars = './Yellowstone-sequence-bars-perl6.svg'.IO;
▲$line.spurt: SVG.serialize: $chart.plot: :lines;
▲$bars.spurt: SVG.serialize: $chart.plot: :bars;</lang>
▲{{out}}
▲<pre>The first 30 terms in the Yellowstone sequence:
▲1 2 3 4 9 8 15 14 5 6 25 12 35 16 7 10 21 20 27 22 39 11 13 33 26 45 28 51 32 17</pre>
▲See (offsite SVG images) [https://github.com/thundergnat/rc/blob/master/img/Yellowstone-sequence-line-perl6.svg Line graph] or [https://github.com/thundergnat/rc/blob/master/img/Yellowstone-sequence-bars-perl6.svg Bar graph]
=={{header|REXX}}==
|