Offering 10k mana to whoever first sends in the solution.

For more info on the CPMM binary mechanism, see Maniswap.

We have the closed form for calculating shares given a bet amount:

function calculateCpmmShares(
  pool: {
    YES: number
    NO: number
  },
  p: number,
  bet: number,
  betChoice: string
) {
  const { YES: y, NO: n } = pool
  const k = y ** p * n ** (1 - p)

  return betChoice === 'YES'
    ? // <https://www.wolframalpha.com/input?i=%28y%2Bb-s%29%5E%28p%29*%28n%2Bb%29%5E%281-p%29+%3D+k%2C+solve+s>
      y + bet - (k * (bet + n) ** (p - 1)) ** (1 / p)
    : n + bet - (k * (bet + y) ** -p) ** (1 / (1 - p))
}

We also have the closed form to bet to a specific probability:

export function calculateCpmmAmountToProb(
  pool: {
    YES: number
    NO: number
  },
  p: number,
  prob: number,
  outcome: 'YES' | 'NO'
) {
  if (prob <= 0 || prob >= 1 || isNaN(prob)) return Infinity
  if (outcome === 'NO') prob = 1 - prob

  const { YES: y, NO: n } = pool
  const k = y ** p * n ** (1 - p)
  return outcome === 'YES'
    ? // <https://www.wolframalpha.com/input?i=-1+%2B+t+-+((-1+%2B+p)+t+(k%2F(n+%2B+b)>)^(1%2Fp))%2Fp+solve+b
      ((p * (prob - 1)) / ((p - 1) * prob)) ** -p *
        (k - n * ((p * (prob - 1)) / ((p - 1) * prob)) ** p)
    : (((1 - p) * (prob - 1)) / (-p * prob)) ** (p - 1) *
        (k - y * (((1 - p) * (prob - 1)) / (-p * prob)) ** (1 - p))
}

But what is the closed form for calculating the bet amount given an amount of shares you want to gain?

export function calculateAmountToBuyShares(
  pool: {
    YES: number
    NO: number
  },
  p: number,
  shares: number,
  outcome: 'YES' | 'NO'
) {
  // What is the bet amount to buy the given number of shares?

  // From @dreev:
	if (state.p === 0.5) {
    const { YES: y, NO: n } = state.pool
    if (outcome === 'YES')
      return (
        (1 / 2) *
        (shares - y - n + Math.sqrt(4 * n * shares + (y + n - shares) ** 2))
      )
    if (outcome === 'NO')
      return (
        (1 / 2) *
        (shares - y - n + Math.sqrt(4 * y * shares + (y + n - shares) ** 2))
      )
  }
}