search.cpan.org is shutting down
Adam Lesperance > Project-Euler-0.20 > Project::Euler::Lib::Utils

Project-Euler-0.20.tar.gz

Dependencies

Annotate this POD

# CPAN RT

 Open 0
View/Report Bugs
Module Version: 0.20

# NAME

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

version 0.20

# SYNOPSIS

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

# EXPORTS

## :fibs

• fib_generator
• n_fibs

## :list

• filter_ranges

• :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)]);```