The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Project::Euler::Lib::Utils - Collection of helper utilities for project euler problems

VERSION

version 0.20

SYNOPSIS

    use Project::Euler::Lib::Utils qw/ :all /;

EXPORTS

:fibs

  • fib_generator

  • n_fibs

:list

  • filter_ranges

:all

  • :fibs

  • :list

FUNCTIONS

fib_generator

This returns a clojure that returns the next successive fib number with each call

Example

    my $fib = fib_generator;

    #  Manually create the first 4 fibs
    my @fibs;
    push @fibs, $fib->()  for  1..4;

n_fibs

The returns either the first 'n' fibs or the nth fib if called in scalar context. If only the nth fib is used, then no memory is used to store the previous fibs and it should run very fast. For now this does some very primitive caching but will have to be improved in the future.

This also does not currently use Math::BigInt so if a large # is requested it may not be 100% accurate. This will be fixed once I decide upon a caching solution.

Parameters

  1. Fib number (or list up to a number) that you would like returned.

Example

    #  Get the first 4 fib numbers
    my @fibs = n_fibs( 4 );

    #  Just get the last one
    my $fourth_fib = n_fibs( 4 );

    $fibs[-1] == $fourth_fib;

multiple_check

Check to see if a number is evenly divisible by one or all of a range of numbers.

Parameters

  1. Number to check divisibility on (must be greater than 0)

  2. Range of numbers to check for divisibility (all must be grater than 0)

  3. Boolean to check all range numbers (optional)

Example

    my $is_divisible     = multiple_check(15, [2, 3, 5], 0);
    my $is_divisible2    = multiple_check(15, [2, 3, 5]);
    my $is_not_divisible = multiple_check(10, [3, 6, 7]);

    my $is_all_divisible     = multiple_check(30, [2, 3, 5], 1);
    my $is_not_all_divisible = multiple_check(15, [2, 3, 5], 1);

    my @div_by = multiple_check(15, [2, 3, 5]);
    @div_by ~~ (3, 5) == 1;


    my $num = 3;
    my $is_prime = !multiple_check($num, [2..sqrt($num)]);

AUTHOR

Adam Lesperance <lespea@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Adam Lesperance.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.