Please post your solutions to this étude, by commenting or forking. (I don't want to add comments directly on my blog, partly to skip coding up the feature but mainly because that's what your own blog is for, normally. Let's see if the gist form works for this particular case of commenting.)
This file contains 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
""" | |
Would this make a better random.sample() function for the Python | |
standard library? Robert Floyd's algorithm as presented in Jon | |
Bentley, "A Sample of Brilliance". | |
Answer: no, it's slower; somewhat slower even if you tune it. | |
I tried a few different test cases -- both small and large | |
result lists. I'd expect it to use much less memory in some cases, | |
but my flailings turned up no case where that seemed to matter. |
This file contains 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
""" | |
*** OBSOLETE | |
*** SEE FIXED FORK: http://gist.github.com/375850 | |
Test out 20 binary-search functions harvested from | |
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
See results at the bottom. | |
""" | |
import random |
This file contains 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
""" | |
Test out 20 binary-search functions harvested from | |
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
See results at the bottom. | |
""" | |
import random | |
failures = {} |
This file contains 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
## b = InitialChessBoard() | |
## print str(b) | |
#. rnbqkbnr | |
#. pppppppp | |
#. | |
#. | |
#. | |
#. | |
#. PPPPPPPP | |
#. RNBQKBNR |
This file contains 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
The point of sore or milk in hot cream. Any | |
Such matters. Boil for twenty minutes then | |
Whip made it properly and crumb of many | |
Cooks. Bake the public. Make the point. For men | |
To english cooks to swell them stew the skin | |
At once in every week we doubt the soles | |
Among the custard cut into a tin | |
Which sprinkle over each half pints of holes | |
And ham into a delicate digestion | |
And finish cooking. See page. Lemonade |
This file contains 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
# A list is either () or (head, list). | |
# list = () | (head, list) | |
def make_list(xs): return (xs[0], make_list(xs[1:])) if xs else () | |
L = make_list('abcd') | |
## L | |
#. ('a', ('b', ('c', ('d', ())))) | |
This file contains 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
;; (mcase subject-expr (pattern action) ...) | |
(defmacro mcase (subject &rest clauses) | |
`(funcall (mlambda ,@clauses) ,subject)) | |
;; (mlambda (pattern action) ...) | |
(defmacro mlambda (&rest clauses) | |
(if (null clauses) | |
'(lambda (x) (match-error x)) | |
(let ((subject (gensym)) (fail (gensym))) | |
`(lambda (,subject) |
This file contains 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
// Context: https://news.ycombinator.com/item?id=5474833 | |
(function() { | |
if (typeof module === "undefined") self.queue = queue; | |
else module.exports = queue; | |
queue.version = "1.0.3dev"; | |
var slice = [].slice; | |
function queue(parallelism) { | |
var queue = {}, |
OlderNewer