Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created December 26, 2011 20:55
Show Gist options
  • Save michaelsbradleyjr/1522107 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/1522107 to your computer and use it in GitHub Desktop.
Faster algorithm
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