Skip to content

Instantly share code, notes, and snippets.

@chandu-io
Created December 11, 2012 19:21
Show Gist options
  • Save chandu-io/4261220 to your computer and use it in GitHub Desktop.
Save chandu-io/4261220 to your computer and use it in GitHub Desktop.
js :: numbers of wirth
/*
* Numbers of Wirth
* Solution to http://programmingpraxis.com/2012/12/07/wirth-problem-15-12/2/
*
* Author: Chandrasekhar Thotakura
*/
(function (N) {
'use strict';
var wirth = {
queue: [1],
series: [],
insert: function (x) {
var len = this.queue.length, i = 0;
if (len) {
while (i < len && this.queue[i] < x) {
i += 1;
}
}
if (this.queue[i] !== x) {
this.queue.splice(i, 0, x);
}
},
generate: function () {
var head;
while (this.queue.length) {
head = this.queue.shift();
if (this.series.length < N) {
this.series.push(head);
this.insert(2 * head + 1);
this.insert(3 * head + 1);
}
}
}
};
wirth.generate();
return wirth.series;
}(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment