user-pic

Chad A. Davis

  • Commented on Being nice to colleagues with git pre-commit hooks
    And if you work with multiple git repos and want to always be using the same pre-commit safety hook, you can just do something like: DIR=~/.git-template/ mkdir $DIR cp .git/hooks/pre-commit $DIR # Then in your ~/.bashrc export GIT_TEMPLATE_DIR=$DIR # Then...
  • Commented on Beating memoization
    If I new that the domain of my function was natural numbers, I'd use @cache rather than %cache. It's an order of magnitude faster than even the iterative algorithm on my machine and it's just as much of a quick...
  • Commented on Binary search versus hash lookup
    I would also run this multiple times for those reasons. And I would run it for different values of $target, including missing values. The conclusions still stand, but this might be more convincing : use Benchmark qw/cmpthese :hireswallclock/; cmpthese -5,...
Subscribe to feed Recent Actions from Chad A. Davis

  • Aristotle commented on Beating memoization

    Chad:

    Better yet, with knowledge of algorithm you can conclude that it’s not possible for fib(n-1) to be cached without fib(n-2) also being cached (because the latter must be calculated in order to calculate the former), and for the same reason it’s not possible for fib(n-2) to be uncached without fib(n-1) also being uncached. So you can run the calculation out of the cache, and you only ever need to check whether fib(n-1) is cached,

    my @fib = (undef, 1, 1);
    sub fib4 {
        my $n = shift;
        croak "fib($n) undefined" if $n <= 0;
        $fib[$n] //= ( $fib[$n-1] //…
Subscribe to feed Responses to Comments from Chad A. Davis

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.