# 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",
  prev: NaN,
  map: 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
  },
  range: (n) => new Array(n).map((_,index) => index),
  wts:
    range(100).map(avg => 
      sum(
        range(100).map(index => 
          Math.exp(-Math.pow(avg - index,2))
        )
      )
    ),
  run(scores) {
    if(isNaN(this.prev)) return 250/3;
    const avg = Math.round(average(scores)) - 1;
    ++this.map[prev][avg];
    this.prev = avg;
    //prob dist=sum_recordings{e^-(recording - avg)^2*(prob dist inferred from record)}/(sum of e^-(recording - avg)^2)
    //wts[avg]=sum of e^-(recording - avg)^2
    const dist = this.scale(1/this.wts[avg], this.map.map((outpts, index) => 
      this.scale(Math.exp(-Math.pow(avg - index,2)) / sum(outpts), outpts)).reduce(this.vec_plus));
    return 100 + 0.4*sum(dist.map((p,n)=>p*n))
  }
}