Skip to content

Instantly share code, notes, and snippets.

@likev
Last active August 7, 2023 09:51
Show Gist options
  • Save likev/bcdd6a2ac759efd67782ef006cb7fa4d to your computer and use it in GitHub Desktop.
Save likev/bcdd6a2ac759efd67782ef006cb7fa4d to your computer and use it in GitHub Desktop.
Start with six integers. At each step, replace any two of them a, b each with their sum a +b, a +b. Can you always make all six equal? https://twitter.com/JDHamkins/status/1688190004508459009
function r(a, b) {
return Math.floor(Math.random() * (b - a)) + a;
}
function all_equal(arr){
for (let i = 1; i < 6; i++) {
if(arr[i] !== arr[0]) return false;
}
return true;
}
function e(totalSteps) {
let arr = [];
for (let i = 0; i < 6; i++) {
arr.push( BigInt(r(0, 10) ) )
}
console.log(arr)
let step = 1;
for ( ; step <= totalSteps; step++) {
let p1 = r(0, 6),
p2 = r(0, 6);
while (p2 === p1) {
p2 = r(0, 6)
}
let m = arr[p1] + arr[p2];
arr[p1] = m;
arr[p2] = m;
if(all_equal(arr)) break;
}
if(step > totalSteps) step = 'Not Found';
console.log({step, arr})
}
e(1E6)
Array(6) [ 3n, 1n, 3n, 2n, 8n, 8n ]
Array(6) [
57205089522553295527513445124735205614376429449684953927917961216403227112132744932012432149966139427565592251133943761338368n,
48833226998788624021099248246385899028899648929248577951307683760897644027139127244572969319346197705591791272546655744819200n,
5136919586423053910801861692080021397490537486636374088521906430030481806429223226543684392525401192221825904695037053108224n,
57205089522553295527513445124735205614376429449684953927917961216403227112132744932012432149966139427565592251133943761338368n,
48833226998788624021099248246385899028899648929248577951307683760897644027139127244572969319346197705591791272546655744819200n,
48833226998788624021099248246385899028899648929248577951307683760897644027139127244572969319346197705591791272546655744819200n ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment