langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
13
Task/Generator-Exponential/Perl-6/generator-exponential.pl6
Normal file
13
Task/Generator-Exponential/Perl-6/generator-exponential.pl6
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
sub powers($m) { 0..* X** $m }
|
||||
|
||||
my @squares := powers(2);
|
||||
my @cubes := powers(3);
|
||||
|
||||
sub infix:<without> (@orig,@veto) {
|
||||
gather for @veto -> $veto {
|
||||
take @orig.shift while @orig[0] before $veto;
|
||||
@orig.shift if @orig[0] eqv $veto;
|
||||
}
|
||||
}
|
||||
|
||||
say (@squares without @cubes)[20 ..^ 20+10].join(', ');
|
||||
25
Task/Generator-Exponential/XPL0/generator-exponential.xpl0
Normal file
25
Task/Generator-Exponential/XPL0/generator-exponential.xpl0
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
code ChOut=8, IntOut=11;
|
||||
|
||||
func Gen(M); \Generate Mth powers of positive integers
|
||||
int M;
|
||||
int N, R, I;
|
||||
[N:= [0, 0, 0, 0]; \provides own/static variables
|
||||
R:= 1;
|
||||
for I:= 1 to M do R:= R*N(M);
|
||||
N(M):= N(M)+1;
|
||||
return R;
|
||||
];
|
||||
|
||||
func Filter; \Generate squares of positive integers that aren't cubes
|
||||
int S, C;
|
||||
[C:= [0]; \static variable = smallest cube > current square
|
||||
repeat S:= Gen(2);
|
||||
while S > C(0) do C(0):= Gen(3);
|
||||
until S # C(0);
|
||||
return S;
|
||||
];
|
||||
|
||||
int I;
|
||||
[for I:= 1 to 20 do Filter; \drop first 20 values
|
||||
for I:= 1 to 10 do [IntOut(0, Filter); ChOut(0, ^ )]; \show next 10 values
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue