Public
Edited
Dec 2, 2023
Insert cell
Insert cell
games
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
games = input
.trim()
.split("\n")
.flatMap((line, i) =>
line
.split(/[:;]/)
.slice(1)
.map((s) =>
Object.fromEntries([
["id", i + 1],
["red", null],
["green", null],
["blue", null],
...s.split(",").map((c) => {
const [color, n] = c.trim().split(" ").reverse();
return [color, +n];
})
])
)
)
Insert cell
games
with
impossible as (
select *
from games
where red > 12 or green > 13 or blue > 14
),
possible as (
select distinct id
from games
where id not in (select id from impossible)
)
select sum(id) from possible
Insert cell
games
with powers as (
select max(red) * max(green) * max(blue) as power
from games
group by id
)
select sum(power) from powers
Insert cell
Insert cell
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.
Learn more