Type Table, then Shift-Enter. Ctrl-space for more options.
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];
})
])
)
)
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
games
with powers as (
select max(red) * max(green) * max(blue) as power
from games
group by id
)
select sum(power) from powers
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.