tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
16
Task/Pythagorean-triples/MATLAB/pythagorean-triples.m
Normal file
16
Task/Pythagorean-triples/MATLAB/pythagorean-triples.m
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
N= 100;
|
||||
a = 1:N;
|
||||
b = a(ones(N,1),:).^2;
|
||||
b = b+b';
|
||||
b = sqrt(b); [y,x]=find(b==fix(b)); % test
|
||||
% here some alternative tests
|
||||
% b = b.^(1/k); [y,x]=find(b==fix(b)); % test 2
|
||||
% [y,x]=find(b==(fix(b.^(1/k)).^k)); % test 3
|
||||
% b=b.^(1/k); [y,x]=find(abs(b - round(b)) <= 4*eps*b);
|
||||
|
||||
z = sqrt(x.^2+y.^2);
|
||||
ix = (z+x+y<100) & (x < y) & (y < z);
|
||||
p = find(gcd(x(ix),y(ix))==1); % find primitive triples
|
||||
|
||||
printf('There are %i Pythagorean Triples and %i primitive triples with a perimeter smaller than %i.\n',...
|
||||
sum(ix), length(p), N);
|
||||
Loading…
Add table
Add a link
Reference in a new issue