Skip to content

Instantly share code, notes, and snippets.

@dkaraush
Last active December 4, 2026 01:54
Show Gist options
  • Select an option

  • Save dkaraush/4e5abbefb348dc3b10124ba281cd4478 to your computer and use it in GitHub Desktop.

Select an option

Save dkaraush/4e5abbefb348dc3b10124ba281cd4478 to your computer and use it in GitHub Desktop.
M=document.querySelector('pre').innerText.trim().split('\n').map(l=>l.split('')),h=M.length
sqr=(x,y,r)=>[...Array(r?h-y:1)].reduce((s,_,Y)=>M[y+Y].slice(x+1,h-y-Y+x).reduce((s,c,d)=>s+(c+M[y+1+d][x-Y]+M[y+Y+1+d][x+1+d-Y]=='###'),s),0)
M.reduce((s,l,y)=>l.reduce((s,c,x)=>c=='#'?s.map((a,i)=>a+sqr(x,y,i)):s,s),[0,0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment