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
| Queens = function(num) { | |
| function range(n) { | |
| return Array.apply(null, new Array(n)).map(function(_, i) { return i; }); | |
| }; | |
| function is_safe(q, qs) { | |
| if(qs.length == 0) return true; | |
| return qs.filter(function(x, i) { | |
| return Math.abs(q - x) != Math.abs(qs.length - (qs.length - (i + 1))); |
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
| prime_factorization = function(n) { | |
| var i = 2; | |
| var factors = []; | |
| while (n > 0 && i <= n) { | |
| while (n % i == 0) { | |
| factors.push(i); | |
| n = n / i; | |
| } | |
| i++; | |
| } |
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
| function diff(a, b) { | |
| return _operation(a, b, [], diff, true) | |
| } | |
| function union(a, b) { | |
| return _operation(a, b, b, union, true) | |
| } | |
| function intersect(a, b) { | |
| return _operation(a, b, [], intersect) |
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
| var Iterator = function(m, n) { | |
| this.start = m; | |
| this.end = n || Infinity; | |
| this.step = 1; | |
| this.current = this.start; | |
| this.queue = new IteratorQueue(); | |
| this.next = function() { | |
| var c = this.current; | |
| this.current += this.step; |
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
| module Generators | |
| module Utils | |
| def self.included(other) | |
| other.extend(ModuleMethods) | |
| end | |
| module ModuleMethods | |
| def arbitrary | |
| @arbitrary ||= {}.tap do |o| | |
| o[Integer] = ->{Random.rand(-1e+10..1e+10).to_i} |
OlderNewer