Skip to content

Instantly share code, notes, and snippets.

@ZeikJT
Created February 5, 2022 10:07
Show Gist options
  • Save ZeikJT/6f73917442b84cca4247e0ac56ea0ab9 to your computer and use it in GitHub Desktop.
Save ZeikJT/6f73917442b84cca4247e0ac56ea0ab9 to your computer and use it in GitHub Desktop.
Fun experiment based on idea from https://www.twitch.tv/lunatic_mag
function vectorMove(vector) {
for (let i = vector.length - 2; i >= 0; i--) {
if (vector[i] === 0) continue
for (let j = i + 1; j < vector.length; j++) {
if (vector[i] !== vector[j] && vector[j] !== 0) break
if (vector[j] === 0) {
vector[j] = vector[i]
} else {
vector[j] *= 2
}
vector[i] = 0
i = j
}
}
}
function testVector(vector) {
console.log('Before:', vector)
vectorMove(vector)
console.log('After:', vector)
}
testVector([2,2,4,4])
testVector([2,2,4,2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment