Skip to main content
Post Undeleted by Erik the Outgolfer
deleted 632 characters in body
Source Link
Erik the Outgolfer
  • 40.6k
  • 5
  • 45
  • 122

Jelly, 915 bytes

ŒRṗAS$Þ⁸ịµ<1ạḤðŒRṗAS$Þ⁸ị

Try it online!Try it online!

1-indexed.

Explanation:

ŒRṗAS$Þ⁸ị Arguments: n, k
ŒR        Return sorted range from -n to n, inclusive
  ṗ       Cartesian power of the range above and k
   AS$Þ   Sort by sum of absolute values
       ⁸ị Get the nth item

Inverse:

AṀ×LŒRṗLAS$ÞiAṀ×LŒRṗLAS$Þiµ:2NḂ}¡

Try it online!

Explanation:Try it online!

AṀ×LŒRṗLAS$Þi Arguments: z
A             Get absolute values of z's items
 Ṁ            Max
  ×L          Multiply with z's length (let's call it x)
    ŒR        Get sorted range from -x to x, inclusive
      ṗL      Cartesian power of the range above with z's length
        AS$Þ  Sort by sum of absolute values
            i Return the index of z in the list we made above

Jelly, 9 bytes

ŒRṗAS$Þ⁸ị

Try it online!

1-indexed.

Explanation:

ŒRṗAS$Þ⁸ị Arguments: n, k
ŒR        Return sorted range from -n to n, inclusive
  ṗ       Cartesian power of the range above and k
   AS$Þ   Sort by sum of absolute values
       ⁸ị Get the nth item

Inverse:

AṀ×LŒRṗLAS$Þi

Try it online!

Explanation:

AṀ×LŒRṗLAS$Þi Arguments: z
A             Get absolute values of z's items
 Ṁ            Max
  ×L          Multiply with z's length (let's call it x)
    ŒR        Get sorted range from -x to x, inclusive
      ṗL      Cartesian power of the range above with z's length
        AS$Þ  Sort by sum of absolute values
            i Return the index of z in the list we made above

Jelly, 15 bytes

µ<1ạḤðŒRṗAS$Þ⁸ị

Try it online!

1-indexed.

Inverse:

AṀ×LŒRṗLAS$Þiµ:2NḂ}¡

Try it online!

Post Deleted by Erik the Outgolfer
added 690 characters in body
Source Link
Erik the Outgolfer
  • 40.6k
  • 5
  • 45
  • 122

Jelly, 9 bytes

ŒRṗAS$Þ⁸ị

Try it online!

1-indexed.

Explanation:

ŒRṗAS$Þ⁸ị Arguments: n, k
ŒR        Return sorted range from -n to n, inclusive
  ṗ       Cartesian power of the range above and k
   AS$Þ   Sort by sum of absolute values
       ⁸ị Get the nth item

Inverse:

AṀ×LŒRṗLAS$Þi

Try it online!

Explanation:

AṀ×LŒRṗLAS$Þi Arguments: z
A             Get absolute values of z's items
 Ṁ            Max
  ×L          Multiply with z's length (let's call it x)
    ŒR        Get sorted range from -x to x, inclusive
      ṗL      Cartesian power of the range above with z's length
        AS$Þ  Sort by sum of absolute values
            i Return the index of z in the list we made above

Jelly, 9 bytes

ŒRṗAS$Þ⁸ị

Try it online!

Inverse:

AṀ×LŒRṗLAS$Þi

Try it online!

Jelly, 9 bytes

ŒRṗAS$Þ⁸ị

Try it online!

1-indexed.

Explanation:

ŒRṗAS$Þ⁸ị Arguments: n, k
ŒR        Return sorted range from -n to n, inclusive
  ṗ       Cartesian power of the range above and k
   AS$Þ   Sort by sum of absolute values
       ⁸ị Get the nth item

Inverse:

AṀ×LŒRṗLAS$Þi

Try it online!

Explanation:

AṀ×LŒRṗLAS$Þi Arguments: z
A             Get absolute values of z's items
 Ṁ            Max
  ×L          Multiply with z's length (let's call it x)
    ŒR        Get sorted range from -x to x, inclusive
      ṗL      Cartesian power of the range above with z's length
        AS$Þ  Sort by sum of absolute values
            i Return the index of z in the list we made above
Source Link
Erik the Outgolfer
  • 40.6k
  • 5
  • 45
  • 122

Jelly, 9 bytes

ŒRṗAS$Þ⁸ị

Try it online!

Inverse:

AṀ×LŒRṗLAS$Þi

Try it online!