Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
deleted 21 characters in body
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216

Pyth, 49 3232 31 bytes

AxLJsua_MCG+LheeGUGysQ]]1Q@J@Jsua_MCG+LheeGUGysQ]]1s-yHGMPBxLJ

Try it online!Try it online!

Takes input as [x[y, y]x].

  • Jsua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size, then collapse it to a flat list and save it in J.

  • AxLJ ... QxLJ: Find the index in J of the two inputs. Save the indices in G and H respectively.

  • @Js-yHGMPB: GenerateConvert to the target index, .

  • 2*H - G@, and index: Index into J to get the target number.

Pyth, 49 32 bytes

AxLJsua_MCG+LheeGUGysQ]]1Q@J-yHG

Try it online!

Takes input as [x, y].

  • Jsua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size, then collapse it to a flat list and save it in J.

  • AxLJ ... Q: Find the index in J of the two inputs. Save the indices in G and H respectively.

  • @J-yHG: Generate the target index, 2*H - G, and index into J.

Pyth, 49 32 31 bytes

@Jsua_MCG+LheeGUGysQ]]1s-MPBxLJ

Try it online!

Takes input as [y, x].

  • Jsua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size, then collapse it to a flat list and save it in J.

  • xLJ: Find the index in J of the two inputs.

  • s-MPB: Convert to the target index.

  • @: Index into J to get the target number.

deleted 6 characters in body
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216

Pyth, 4949 32 bytes

Jua_MCG+LheeGUGysQ]]1AmAxLJsua_MCG+LheeGUGysQ]]1Q@J-yedhdCm.e@bkPr8xRdJQ@@JGHyHG

Try it online!Try it online!

Takes input as [x, y].

  • Jua_MCG+LheeGUGysQ]]1Jsua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size, then collapse it to a flat list and save it in J.

  • mAxLJ .e@bkPr8xRdJQ.. Q: Find the row and column indicesindex in J of the two inputs in. Save the generated spiralindices in G and H respectively.

  • Am@J-yedhdyHG: Convert to the row and column indices ofGenerate the output

  • target index, @@JGH2*H - G: Index, and index into the spiralJ.

Pyth, 49 bytes

Jua_MCG+LheeGUGysQ]]1Am-yedhdCm.e@bkPr8xRdJQ@@JGH

Try it online!

Takes input as [x, y].

  • Jua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size

  • m.e@bkPr8xRdJQ: Find the row and column indices of the two inputs in the generated spiral.

  • Am-yedhd: Convert to the row and column indices of the output

  • @@JGH: Index into the spiral.

Pyth, 49 32 bytes

AxLJsua_MCG+LheeGUGysQ]]1Q@J-yHG

Try it online!

Takes input as [x, y].

  • Jsua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size, then collapse it to a flat list and save it in J.

  • AxLJ ... Q: Find the index in J of the two inputs. Save the indices in G and H respectively.

  • @J-yHG: Generate the target index, 2*H - G, and index into J.

Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216

Pyth, 49 bytes

Jua_MCG+LheeGUGysQ]]1Am-yedhdCm.e@bkPr8xRdJQ@@JGH

Try it online!

Takes input as [x, y].

  • Jua_MCG+LheeGUGysQ]]1: Generate the spiral to a sufficient size

  • m.e@bkPr8xRdJQ: Find the row and column indices of the two inputs in the generated spiral.

  • Am-yedhd: Convert to the row and column indices of the output

  • @@JGH: Index into the spiral.