Platform
Resources
Pricing
Sign in
Get started
Jeff Baumes
Producing open source analytics and vis @Kitware.
Workspace
Fork
Published
By
Jeff Baumes
Edited
Sep 1, 2020
Fork of
Pythagorean Triples
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
min
=
-
5000
;
Insert cell
max
=
5000
;
Insert cell
triples
=
{
const
out
=
[
]
;
for
(
let
a
=
min
;
a
<=
max
;
a
++
)
{
for
(
let
b
=
min
;
b
<=
max
;
b
++
)
{
const
c
=
Math
.
sqrt
(
a
**
2
+
b
**
2
)
;
if
(
a
&&
b
&&
Number
.
isInteger
(
c
)
&&
Math
.
abs
(
gcd
(
a
,
b
)
)
===
1
)
out
.
push
(
{
a
,
b
,
c
}
)
;
}
}
return
out
;
}
Insert cell
frequency
=
arr
.
unique
(
triples
,
d
=>
d
.
a
)
.
map
(
a
=>
{
return
{
a
,
count
:
triples
.
filter
(
d
=>
d
.
a
===
a
)
.
length
}
}
)
Insert cell
fy
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
d3
.
max
(
frequency
,
d
=>
d
.
count
)
]
)
.
range
(
[
chartHeight
,
0
]
)
;
Insert cell
function
gcd
(
a
,
b
)
{
if
(
!
b
)
{
return
a
;
}
return
gcd
(
b
,
a
%
b
)
;
}
Insert cell
Insert cell
style
=
`
circle.triple {
fill: tomato;
}
.axis .domain {
display: none;
}
.grid .domain {
display: none;
}
.grid text {
display: none;
}
.grid line {
stroke: #ddd;
shape-rendering: crispEdges;
}
`
Insert cell
Insert cell
x
=
d3
.
scaleLinear
(
)
.
domain
(
[
min
,
max
]
)
.
range
(
[
0
,
chartWidth
]
)
;
Insert cell
y
=
d3
.
scaleLinear
(
)
.
domain
(
[
min
,
max
]
)
.
range
(
[
chartHeight
,
0
]
)
;
Insert cell
Insert cell
margin
=
(
{
left
:
40
,
right
:
10
,
top
:
10
,
bottom
:
40
}
)
;
Insert cell
size
=
Math
.
min
(
width
,
800
)
;
Insert cell
chartWidth
=
size
-
margin
.
left
-
margin
.
right
;
Insert cell
chartHeight
=
size
-
margin
.
top
-
margin
.
bottom
;
Insert cell
Insert cell
arr
=
require
(
"arraygeous"
)
;
Insert cell
d3
=
require
(
"d3@6"
)
;
Insert cell
import
{
toc
}
from
"@harrystevens/toc"
;
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
min
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
max
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
triples
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
frequency
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fy
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
gcd
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
style
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
y
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
margin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
size
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chartWidth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chartHeight
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
arr
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML