xxxxxxxxxx
51
let odds = [];
let sliders = [];
let punt;
const N = 3;
const A_template = [
[-1, -1, -1],
[-1, -1, -1],
[-1, -1, -1]
];
let profit = [];
let layout;
let bet = [];
function setup() {
//createCanvas(400, 400);
for (let ni = 0; ni < N; ni++) {
odds.push(document.getElementById("in" + (ni + 1).toString()));
sliders.push(document.getElementById("slide" + (ni + 1).toString()));
profit.push(document.getElementById("profit" + (ni + 1).toString()));
bet.push(document.getElementById("bet" + (ni + 1).toString()));
}
punt = document.getElementById("punt");
layout = document.getElementById("layout");
}
function draw() {
//background(220);
let A = JSON.parse(JSON.stringify(A_template));
let p = [];
for (let ni = 0; ni < N; ni++) {
A[ni][ni] = A[ni][ni] + float(odds[ni].value);
p.push(float(sliders[ni].value));
}
x = math.lusolve(A,p);
console.log(A);
let scl = x[0];
for (let ni=0;ni<N;ni++){
x[ni] = x[ni]*float(punt.value)/scl;
}
let totspent = 0;
for (let ni=0;ni<N;ni++){
totspent = totspent + x[ni];
}
for (let ni=0;ni<N;ni++){
profit[ni].innerHTML = (x[ni]*odds[ni].value-totspent).toFixed(2);
bet[ni].innerHTML = (x[ni]).toFixed(2);
}
layout.innerHTML = totspent.toFixed(2);
console.log(x);
}