First very naive attempt at brute forcing all possible

This commit is contained in:
Matt McWilliams 2021-07-25 23:17:55 -04:00
parent a6f57c5972
commit 7f6488cad6
1 changed files with 88 additions and 0 deletions

88
dvd_bounce_brute_force.js Normal file
View File

@ -0,0 +1,88 @@
const { writeFileSync } = require('fs');
const xMax = 1080.0;
const yMax = 1920.0;
const framesMin = 30 * 7;
const framesMax = 30 * 60;
const distanceMax = 30.0;
const buffer = 50;
let xStart = 0;
let yStart = 0;
let frames = framesMin;
let distance = 15.0;
let angle = 45;
let angles = [ 45, 45 + 90, 45 + 180, 45 + 270];
let searchHit = 1;
function simulate (x, y, frames, angle, distance) {
for (let i = 0; i < frames; i++) {
x = x + distance * Math.cos(angle * Math.PI / 180.0);
y = y + distance * Math.sin(angle * Math.PI / 180.0);
if (x >= 1080.0 || x <= 0.0) {
angle = 180 - angle;
}
if (x >= 1080.0) x = 1080.0;
if (x <= 0.0) x = 0.0;
if (y >= 1920.0 || y <= 0.0) {
angle = 360 - angle;
}
if (y >= 1920.0) y = 1920.0;
if (y <= 0.0) y = 0.0;
}
return { x, y, angle }
}
function simulateAll () {
let res;
let attempts = 0;
let startTime;
let duration;
let secondsLeft;
for (let x = buffer; x < xMax-buffer; x++ ) {
for (let y = buffer; y < yMax-buffer; y++) {
startTime = +new Date();
console.time(`${x},${y}`)
for (let a = 0; a < 4; a++) {
for (let d = 0; d < 10; d++) {
for (let frames = framesMin; frames < framesMax + 1; frames++) {
angle = angles[a];
res = simulate(x, y, frames, angle, distance + d);
attempts++;
if (Math.abs(res.x - x) < searchHit && Math.abs(res.y - y) < searchHit && res.angle == angle) {
console.log(`#${attempts}`);
console.log(`startx = ${x} endx = ${res.x}`);
console.log(`starty = ${y} endy = ${res.y}`);
console.log(`startangle = ${angle}`);
console.log(`frames = ${frames}`);
console.log(`distance = ${distance + d}`);
console.log(`searchHit = ${searchHit}`);
console.log("++++++++++++++++++++++++++++++++++++++++");
return res;
}
}
}
}
console.timeEnd(`${x},${y}`)
duration = ((+new Date()) - startTime);
secondsLeft = (duration / 1000) * (x - (xMax - buffer)) * (y - (yMax - buffer));
console.log(`Minutes Left: ${Math.round(secondsLeft / 60)}`);
}
}
}
function main () {
let res;
for (let i = 0; i < 7; i++) {
res = simulateAll();
searchHit = Math.floor(searchHit / 2.0);
if (searchHit === 0) process.exit()
}
}
main();