722 karma · joined June 8, 2012
I wrote a small script that evolves them based on a scoring function, paste in your console and run evolve(1000, score)
function evolve(numGenerations, scoringFn, stepInterval) {
var children = document.querySelectorAll('[id*=child]'), generation = 0
if (stepInterval == null) stepInterval = 10
function run() {
var i, child, ctx, data, score, winner, winningScore = -Infinity
for (i = children.length - 1; i >= 0; i--) {
child = children[i]
ctx = child.getContext('2d')
data = ctx.getImageData(0, 0, 318, 148)
score = scoringFn(data)
if (score > winningScore) {
winningScore = score
winner = i
}
}
children[winner].click()
if (++generation < numGenerations) setTimeout(run, stepInterval)
// console.log(winner, winningScore)
}
run()
}
function score(imageData) {
var i, r, g, b, rv = 0,
data = imageData.data, l = data.length
for (i = 0; i < l; i += 4) {
r = 255 - data[i]
g = 255 - data[i+1]
b = 255 - data[i+2]
a = data[i+3] / 255
rv += (r + g + b) * a
}
return rv
}> it is likely to have repercussions especially on the cryptographic applications of smart cards, RFID chips (2), etc.
It will be easier to bruteforce RSA/DSA?
http://johan-nordberg.com/2048/
(or if you're in the future the js1k crew might have updated my submission already, in that case, forget you read this, it was perfect from the start, whoa i need a break, my brain is trying to find ways to write this comment using fewer characters, commas are nice, sleep)
Crappy algo, I would think that lots of comments indicates that people find it interesting... Next time I won't reply to peoples comments :/
(Math.random()*2+1)<<1
Math.random()>.25?2:4
But still too much, I only have 2 bytes to spare :)Got nuked for some reason by HN's algorithm dropping it from nr 4 to the second page :(
That's a bug, it should pop up a dialog with your score. Rest is intentional.
newtile = 2 vs. newtile = Math.random() > 0.25 ? 2 : 4I think it is some hisenbug related to that js1k loads all entries by injecting the script in a iframes src attribute.
EDIT: clicking anywhere to focus the iframe makes it stop