Skip to main content
added 652 characters in body
Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

Charcoal, 60/62 bytes

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηIΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Try it online! Link is to verbose version of code. Explanation:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυ

Input n and generate the spiral using the method from my answer to Print a NxN integer involute except 1-indexed.

Nθ≔⊟Φυ№ιθη

Input m and find the row containing m in the spiral.

IΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Extract the neighbours of m and output the sum.

Note that the 5, 17 test case includes the 17 itself in the total; if this is not wanted then it can be subtracted at a cost of 2 bytes:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηI⁻ΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²θ

Try it online! Link is to verbose version of code.

Charcoal, 60 bytes

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηIΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Try it online! Link is to verbose version of code. Explanation:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυ

Input n and generate the spiral using the method from my answer to Print a NxN integer involute except 1-indexed.

Nθ≔⊟Φυ№ιθη

Input m and find the row containing m in the spiral.

IΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Extract the neighbours of m and output the sum.

Charcoal, 60/62 bytes

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηIΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Try it online! Link is to verbose version of code. Explanation:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυ

Input n and generate the spiral using the method from my answer to Print a NxN integer involute except 1-indexed.

Nθ≔⊟Φυ№ιθη

Input m and find the row containing m in the spiral.

IΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Extract the neighbours of m and output the sum.

Note that the 5, 17 test case includes the 17 itself in the total; if this is not wanted then it can be subtracted at a cost of 2 bytes:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηI⁻ΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²θ

Try it online! Link is to verbose version of code.

Source Link
Neil
  • 177.3k
  • 12
  • 74
  • 281

Charcoal, 60 bytes

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυNθ≔⊟Φυ№ιθηIΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Try it online! Link is to verbose version of code. Explanation:

F⊗N≔⁺⟦Eυ⊕λ⟧E∧υ⌊υ⁺LυE⮌υ§μλυ

Input n and generate the spiral using the method from my answer to Print a NxN integer involute except 1-indexed.

Nθ≔⊟Φυ№ιθη

Input m and find the row containing m in the spiral.

IΣEΦυ‹↔⁻κ⌕υη²ΣΦι‹↔⁻μ⌕ηθ²

Extract the neighbours of m and output the sum.