More javascript. Still can't see a regex solution. Part 2 contains part 1, so I'll just post that:
function findWeaknessp2() { let input = document.querySelector('pre') .innerHTML .split('\n') .map(n => parseInt(n, 10)); let win = 25; let fail = -1; let failIndex = -1; for(let i = win; i < input.length; i++) { let target = input[i]; let options = input.slice(i-win, i); let found = options.reduce((val, opt) => { if(val == -1) { val = options.indexOf(target-opt); } return val; },-1); if(found == -1) { fail = target; failIndex = i; break; } } let weakness = -1; for(let curWin = 2; curWin < failIndex/2; curWin++) { for(let i = 0; i < failIndex; i++) { let options = input.slice(i, i+curWin); let testVal = options.reduce((sum, val) => sum+val, 0); if(testVal == fail) { weakness = Math.min(...options) + Math.max(...options); break; } } if(weakness > -1) { break; } } return weakness; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
More javascript. Still can't see a regex solution. Part 2 contains part 1, so I'll just post that: