Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Recamans-sequence/Raku/recamans-sequence.raku
Normal file
21
Task/Recamans-sequence/Raku/recamans-sequence.raku
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
my @recamans = 0, {
|
||||
state %seen;
|
||||
state $term;
|
||||
$term++;
|
||||
my $this = $^previous - $term;
|
||||
$this = $previous + $term unless ($this > 0) && !%seen{$this};
|
||||
%seen{$this} = True;
|
||||
$this
|
||||
} … *;
|
||||
|
||||
put "First fifteen terms of Recaman's sequence: ", @recamans[^15];
|
||||
|
||||
say "First duplicate at term: a[{ @recamans.first({@recamans[^$_].Bag.values.max == 2})-1 }]";
|
||||
|
||||
my @seen;
|
||||
my int $i = 0;
|
||||
loop {
|
||||
next if (my int $this = @recamans[$i++]) > 1000 or @seen[$this];
|
||||
@seen[$this] = 1;
|
||||
say "Range 0..1000 covered by terms up to a[{$i - 1}]" and last if ++$ == 1001;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue