Public
Edited
Dec 11, 2022
Insert cell
Insert cell
register=input_day10.split("\n").map(r => r=="noop"?0:+r.split(" ")[1])
Insert cell
register_cumsum=register.map((sum => value => sum += value)(1))
Insert cell
register_time=register.map(r=> r==0?1:2).map((sum => value => sum += value)(0))
Insert cell
[20, 60, 100, 140, 180,220].map(
cycle =>
cycle*register_cumsum[register_time.findIndex(r=>r>=cycle)-1]
).reduce((a,b)=>a+b)
Insert cell
CRT={
let crt=[]
let creg_cum = [1,...register_cumsum]
let creg_time = [1,...register_time]
for(let r=1;r<=6;r++){
let cr =[]
for(let p=0;p<=40;p++){
let s=(r-1)*40+p
let cpos = creg_cum[creg_time.findIndex(r=>r>s)-1]
if((p-1)==cpos||p==cpos||(p+1)==cpos){
cr.push("#")
}else{
cr.push(".")
}
}
crt.push(cr)
}
return crt
}
Insert cell
CRT.map(r=>r.join("")).join("\n")
Insert cell
input_day10 = FileAttachment("input_day10.txt").text()
Insert cell
input_day10_test = FileAttachment("input_day10_test.txt").text()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more