Created
December 26, 2011 20:55
-
-
Save michaelsbradleyjr/1522107 to your computer and use it in GitHub Desktop.
Faster algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
util = require 'util' | |
width = 100 | |
height = 100 | |
population = width * height | |
charged = (c for c in [1..population]) | |
chargedCopy = charged.slice 0 | |
clen = charged.length | |
len = clen - 1 | |
counter = 0 | |
t1 = Date.now() | |
while len | |
chargedCopy.push chargedCopy.shift() | |
for c, i in charged | |
if i < len | |
counter += 1 | |
#console.log util.inspect [ charged[i], chargedCopy[i] ] | |
len-- | |
t2 = Date.now() - t1 | |
console.log 'num tuples: ' + counter | |
console.log 'took: ' + t2/1000 + ' sec' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment