# Fuzzy Eidetic

Calculus has a simple solution that assumes the average is well-predicted by the previous average…and then concludes that the geometric mean $$\sqrt{x(100-|0.8a-x|)}$$ (where \$x\$ is our submission and \$a\$ the average) is maximized at $$x=\frac{100+0.8a}{2}$$  It's hard to do better than that!

So, the only thing remaining is to figure out the next average.  Ideally, we'd just keep track of all possible average-to-average transitions.  But I don't think we're going to see enough data for that to converge.  So we include all previous transitions, but weighted by their distance to the current average.  This gives a probability distribution on subsequent transitions; we then apply Histogrammer's formula.  

```js
{
  name: "Fuzzy Eid",
  fallback: 250/3,
  prev: NaN,
  zeros: new Array(100).fill(0),
  transitions: new Array(100).map(()=>new Array(100).fill(0)),
  scale: (scalar, vec) => vec.map(x=>scalar*x),
  vec_plus(lhs, rhs) {
    let result = lhs.slice();
    for(var index=0; index<result.length; ++index) result[index]+=rhs[index];
    return result
  },
  wts: (function()
  { 
    let range = (n) => new Array(n).map((_,index) => index);
    return range(100).map(avg => 
      sum(
        range(100).map(index => 
          Math.exp(-Math.pow(avg - index,2))
        )
      )
    )
  }),
  run(scores) {
    if(scores.length)
    {
      const avg = Math.round(average(scores)) - 1, old_prev = this.prev;
      this.prev = avg;
      if(!isNaN(old_prev))
      {
        ++this.transitions[old_prev][avg];
        //prob dist=sum_recordings{e^-(recording - avg)^2*(prob dist inferred from record)}/(sum of e^-(recording - avg)^2)
        //infer prob dist, scale by e^-(recording - avg)^2
        function get_summand(outpts, index)
        {
          return this.scale(Math.exp(-Math.pow(avg - index,2)) / sum(outpts), outpts)
        }
        const 
          total=this.transitions.map(get_summand).reduce(this.vec_plus,this.zeros),
          //wts[avg]=sum of e^-(recording - avg)^2
          dist = this.scale(1/this.wts[avg], total);
        return 100 + 0.4*sum(dist.map((p,n)=>p*n))
      }
    }
    return fallback
  }
}