Pythagorean quadruples: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (Added R.) |
|||
Line 1,699: | Line 1,699: | ||
{{Out}} |
{{Out}} |
||
<pre>[1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 128, 160, 256, 320, 512, 640, 1024, 1280, 2048]</pre> |
<pre>[1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 128, 160, 256, 320, 512, 640, 1024, 1280, 2048]</pre> |
||
=={{header|R}}== |
|||
The best solution to this problem - using lots of for loops - is practically language agnostic. The R way of doing this is far less efficient, taking about 10 minutes on my machine, but it's the obvious way to do this in R. |
|||
<lang R>squares <- d <- seq_len(2200)^2 |
|||
aAndb <- outer(squares, squares, '+') |
|||
aAndb <- aAndb[upper.tri(aAndb, diag = TRUE)] |
|||
sapply(squares, function(c) d <<- setdiff(d, aAndb + c)) |
|||
print(sqrt(d))</lang> |
|||
{{out}} |
|||
<pre>[1] 1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |