Platform
Resources
Pricing
Sign in
Get started
Chuncheng
Workspace
Fork
Public
By
Chuncheng
Edited
Feb 22, 2023
5
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mainTableLvl0
=
{
const
table
=
[
]
;
for
(
let
i
=
2
;
i
<
100
;
++
i
)
{
for
(
let
j
=
i
+
1
;
j
<
100
;
++
j
)
{
table
.
push
(
{
i
,
j
,
sum
:
i
+
j
,
mul
:
i
*
j
}
)
;
}
}
return
table
;
}
Insert cell
mainTableLvl0
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
countUniqueSumMul
=
(
table
)
=>
{
const
mulUnique
=
{
}
,
sumUnique
=
{
}
;
table
.
map
(
(
d
)
=>
{
if
(
!
mulUnique
[
d
.
mul
]
)
mulUnique
[
d
.
mul
]
=
0
;
if
(
!
sumUnique
[
d
.
sum
]
)
sumUnique
[
d
.
sum
]
=
0
;
mulUnique
[
d
.
mul
]
+=
1
;
sumUnique
[
d
.
sum
]
+=
1
;
}
)
;
return
table
.
map
(
(
{
i
,
j
,
sum
,
mul
}
)
=>
{
const
nMul
=
mulUnique
[
mul
]
,
nSum
=
sumUnique
[
sum
]
;
return
{
i
,
j
,
sum
,
mul
,
nSum
,
nMul
}
;
}
)
;
}
Insert cell
Insert cell
mainTableLvl1
=
{
return
countUniqueSumMul
(
mainTableLvl0
)
;
}
Insert cell
mainTableLvl1
Filter
1
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
mainTableLvl2
=
{
const
singleDecomPossible
=
mainTableLvl1
.
filter
(
(
e
)
=>
e
.
nMul
===
1
)
.
map
(
(
{
mul
,
sum
}
)
=>
{
return
{
mul
,
sum
}
;
}
)
;
const
muls
=
singleDecomPossible
.
map
(
(
d
)
=>
d
.
mul
)
,
sums
=
singleDecomPossible
.
map
(
(
d
)
=>
d
.
sum
)
;
const
avaible
=
mainTableLvl1
.
filter
(
(
d
)
=>
!
(
muls
.
indexOf
(
d
.
mul
)
>
-
1
||
sums
.
indexOf
(
d
.
sum
)
>
-
1
)
)
;
return
countUniqueSumMul
(
avaible
)
;
}
Insert cell
mainTableLvl2
Filter
1
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Plot
.
plot
(
{
x
:
{
grid
:
true
}
,
y
:
{
grid
:
true
}
,
color
:
{
legend
:
true
}
,
marks
:
[
Plot
.
dot
(
mainTableLvl2
,
{
x
:
"i"
,
y
:
"j"
,
stroke
:
"nSum"
}
)
,
Plot
.
text
(
mainTableLvl2
,
{
x
:
"i"
,
y
:
"j"
,
text
:
(
d
)
=>
`${
d
.
i
}, ${
d
.
j
}, ${
d
.
nSum
}`
,
fill
:
"gray"
,
dy
:
-
8
}
)
]
}
)
Insert cell
Insert cell
mainTableLvl3
=
{
const
mulsUnique
=
{
}
;
mainTableLvl2
.
map
(
(
d
)
=>
{
if
(
!
mulsUnique
[
d
.
mul
]
)
mulsUnique
[
d
.
mul
]
=
0
;
mulsUnique
[
d
.
mul
]
+=
1
;
}
)
;
const
muls
=
[
]
;
for
(
const
k
in
mulsUnique
)
{
if
(
mulsUnique
[
k
]
===
1
)
muls
.
push
(
parseInt
(
k
)
)
;
}
const
select
=
mainTableLvl2
.
filter
(
(
d
)
=>
muls
.
indexOf
(
d
.
mul
)
>
-
1
)
;
return
{
mulsUnique
,
muls
,
select
}
;
}
Insert cell
select3
=
countUniqueSumMul
(
mainTableLvl3
.
select
)
Insert cell
select3
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Plot
.
plot
(
{
x
:
{
grid
:
true
}
,
y
:
{
grid
:
true
}
,
color
:
{
legend
:
true
}
,
marks
:
[
Plot
.
dot
(
select3
,
{
x
:
"i"
,
y
:
"j"
,
stroke
:
"nSum"
}
)
,
Plot
.
text
(
select3
,
{
x
:
"i"
,
y
:
"j"
,
text
:
(
d
)
=>
`${
d
.
i
}, ${
d
.
j
}, ${
d
.
nSum
}`
,
fill
:
"gray"
,
dy
:
-
8
}
)
]
}
)
Insert cell
Insert cell
snipaste_20230221_201141
=
FileAttachment
(
"Snipaste_2023-02-21_20-11-41.png"
)
.
image
(
)
Insert cell
snipaste_20230221_201154
=
FileAttachment
(
"Snipaste_2023-02-21_20-11-54.png"
)
.
image
(
)
Insert cell
snipaste_20230221_201209
=
FileAttachment
(
"Snipaste_2023-02-21_20-12-09.png"
)
.
image
(
)
Insert cell
snipaste_20230221_201219
=
FileAttachment
(
"Snipaste_2023-02-21_20-12-19.png"
)
.
image
(
)
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
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
snipaste_20230221_201114
Edit
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mainTableLvl0
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
mainTableLvl0
File attachments
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
countUniqueSumMul
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
mainTableLvl1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
mainTableLvl1
File attachments
Databases
Filter
mul
Operator
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mainTableLvl2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
mainTableLvl2
File attachments
Databases
Filter
nMul
Operator
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mainTableLvl3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
select3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
select3
File attachments
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
snipaste_20230221_201141
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
snipaste_20230221_201154
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
snipaste_20230221_201209
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
snipaste_20230221_201219
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML