Skip to content

Instantly share code, notes, and snippets.

View danaj's full-sized avatar

Dana Jacobsen danaj

View GitHub Profile
@danaj
danaj / lehmer.c
Last active November 29, 2021 17:09
Prime counting utility using primesieve (http://code.google.com/p/primesieve/). Includes counting via sieve, Legendre, Meissel, and Lehmer methods. Part of the Math::Prime::Util Perl module (https://github.com/danaj/Math-Prime-Util). All code is in C, but primesieve makes a C++ library, hence the C++ compilation.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* Below this size, just sieve. */
#define SIEVE_LIMIT 1000000
/*****************************************************************************
*
@danaj
danaj / prime_sieves.pl
Created November 28, 2012 17:25
Prime Sieves in Perl
#!/usr/bin/env perl
package Acme::Math::ExampleSieves;
use warnings;
use strict;
# A simple example, showing some new prime sieves in Perl (all SoE).
# Copyright 2012 by Dana Jacobsen (dana@acm.org)
# This program is free software using the Perl 5 artistic license v2.
# Note, the string sieve will be 2x faster using Perl 5.16.0 or later.
@danaj
danaj / taks.pl
Created October 28, 2012 01:21
Simple AKS in Perl
#!/usr/bin/env perl
package Acme::Math::AKS;
use warnings;
use strict;
use Math::BigInt try => 'GMP';
use Math::BigFloat try => 'GMP';
# Technically we can get by without any of these functions
use Math::Prime::Util qw/primes next_prime euler_phi is_prob_prime/;
# A simple standalone Perl implementation of the AKS primality algorithm:
@danaj
danaj / fasta5c.pl
Created October 11, 2011 04:50
A faster fasta
# The Computer Language Benchmarks game
# http://shootout.alioth.debian.org/
#
# contributed by David Pyke
# tweaked by Danny Sauer
# optimized by Steffen Mueller
# tweaked by Kuang-che Wu
# optimized by Rodrigo de Oliveira
# modified by Dana Jacobsen
@danaj
danaj / Moo_Mouse_Moose_Bitstream_compare.txt
Created October 3, 2011 18:32
Testing Moo vs. Mouse vs. Moose with the Data::BitStream package
For package Data::BitStream. Perl 5.14.1, Moose 2.0202, Mouse 0.93, Moo 0.009011.
Steps to convert package from Mouse to Moose:
1. find . -type f|egrep '\.(t|pl|pm)$' | xargs perl -i -pe 's/Mouse/Moose/g'
Steps to convert from Mouse to Moo:
1. find . -type f|egrep '\.(t|pl|pm)$' | xargs perl -i -pe 's/Mouse/Moo/g'
@danaj
danaj / integercoding.pl
Created September 26, 2011 05:21
Simple Integer Variable Length Coding in Perl
#!/usr/bin/perl
use strict;
use warnings;
sub die_usage { die "Usage: -encode|-decode unary|gamma|delta|omega|fib\n"; }
use Getopt::Long;
my $emethod;
my $dmethod;
GetOptions('help|usage|?' => sub { die_usage() },