view release on metacpan or search on metacpan
devel/haferman-carpet.pl view on Meta::CPAN
$Seq_1s_init1,
$Seq_1s_init1_by_formula,
$Seq_1s_init1 == $Seq_1s_init1_by_formula ? '' : '******',
Array_1s_init0($n),
Array_1s_init1($n),
);
}
exit 0;
# num black cells after n iterations (9^(k+1) - (-5)^(k+1))/14 = 1,4,61,424
# Array1s(k+1) = 9^(k+1) - 5*Array1s(k)
# Array1s(0) = 1
# Array1s(1) = 9^1 - 5*1 = 4
# Array1s(2) = 9^2 - 5*(9^1 - 5*1)
# = 5^0*9^2 - 5^1*9^1 + 5^2*9^0
# Array1s(3) = 5^0*9^3 - 5^1*9^2 + 5^2*9^1 - 5^3*9^0
# 5^0*9^0 = 1
# 5^1*9^0 - 5^2*9^1 = 20
sub Array_1s_init1 {
my ($n) = @_;
devel/lib/Math/NumSeq/LeastPrimitiveRoot-oeis.t view on Meta::CPAN
# A066696 Euler phi(n) / Carmichael lambda(n) = 14.
# A066697 Euler phi(n) / Carmichael lambda(n) = 18.
# A066698 Euler phi(n) / Carmichael lambda(n) = 34.
# A104196 Sum of CarmichaelLambda[n] between successive powers of 2.
# A104194 a(n) = EulerPhi[n]-CarmichaelLambda[n] (cf. A000010, A002322).
# A123101 lambda(phi(n))=phi(lambda(n)) for the sequential application of Euler totient and Carmichael lambda functions.
# A124240 Numbers n such that lambda(n) divides n, where lambda is Carmichael's function, A002322.
# A131492 Numbers n such that the sum of the Carmichael lambda functions of the divisors is a proper divisor of n.
# A162578 Partial sums of the Carmichael lambda function A002322.
# A173694 Arguments n for which the Carmichael lambda function A002322(n) is a perfect square.
# A173927 Smallest integer k such that the number of iterations of Carmichael lambda function (A002322) needed to reach 1 starting at k (k is counted) is n.
# A181776 a(n) = lambda(lambda(n)), where lambda(n) is the Carmichael lambda function (A002322).
# A187730 Greatest common divisor of Carmichael lambda(n) and n - 1.
# A207193 Auxiliary function for computing the Carmichael lambda function (A002322).
# A214428 Carmichael numbers n such that lambda(n) = 2^k * p, where lambda is the Carmichael lambda function, k is an integer, and p is a prime.
use 5.004;
use strict;
use List::Util 'min','max';
devel/lucky-numbers.pl view on Meta::CPAN
# uncomment this to run the ### lines
# use Smart::Comments;
{
# speed
require Devel::TimeThis;
my $iterations = 5000;
# {
# my $self = { values => [ 7 ],
# value => 7,
# i => 1,
# remaining => [ 4 ],
# inc => 4,
# };
# my $t = Devel::TimeThis->new('subs');
# foreach (1 .. $iterations) {
# &next($self);
# }
# }
# {
# require Math::NumSeq::LuckyNumbersSlow;
# my $seq = Math::NumSeq::LuckyNumbersSlow->new;
# my $t = Devel::TimeThis->new('slow');
# foreach (1 .. $iterations) {
# $seq->next;
# }
# }
{
require Math::NumSeq::LuckyNumbers;
my $seq = Math::NumSeq::LuckyNumbers->new;
if ($seq->can('ith')) {
my $t = Devel::TimeThis->new('ith');
foreach (1 .. $iterations) {
$seq->ith($_);
}
### $seq
}
}
{
require Math::NumSeq::LuckyNumbers;
my $seq = Math::NumSeq::LuckyNumbers->new;
my $t = Devel::TimeThis->new('seq');
foreach (1 .. $iterations) {
$seq->next;
}
### $seq
}
{
require Math::NumSeq::LuckyNumbersByStep;
my $seq = Math::NumSeq::LuckyNumbersByStep->new;
my $t = Devel::TimeThis->new('step');
foreach (1 .. $iterations) {
$seq->next;
}
### $seq
}
{
require '../backup/DanaLuckyNumbers.pm';
my $seq = Math::NumSeq::DanaLuckyNumbers->new;
my $t = Devel::TimeThis->new('array');
foreach (1 .. $iterations) {
$seq->next;
}
### $seq
}
exit 0;
}
{
require Math::NumSeq::LuckyNumbers;
require Math::NumSeq::OEIS::File;
lib/Math/NumSeq/DigitProductSteps.pm view on Meta::CPAN
# A031350 -
# A031351
# A031352
# A031353
# A031354
# A031355 -
# A031356 - 10th powers of digits
#
# A087471 - iterate product of alternate digits, final digit
# A087472 - num steps
# A087473 - first of n iterations
# A087474 - triangle of values of those first taking n iterations
#
# A031286 - additive persistence to single digit
# A010888 - additive root single digit
my %oeis_anum;
$oeis_anum{'count'}->[10] = 'A031346';
$oeis_anum{'root'}->[10] = 'A031347';
# OEIS-Catalogue: A031346
# OEIS-Catalogue: A031347 values_type=root
lib/Math/NumSeq/DigitProductSteps.pm view on Meta::CPAN
=head1 DESCRIPTION
This is an iteration taking the product of the digits of a number until
reaching a single digit value. The sequence values are the count of steps,
also called the multiplicative persistence.
0,0,..0,0,1,1,..1,1,2,2,2,2,2,1,1,1,1,2,2,2,2,2,3,1,1,1,2,...
starting i=0
For example i=39 goes 3*9=27 -E<gt> 2*7=14 -E<gt> 1*4=4 to reach a single
digit, so value=3 iterations.
The C<values_type =E<gt> 'root'> gives the final digit reached by the steps,
which is called the multiplicative digital root.
values_type => 'root'
0,1,2,...,9,0,1,...,9,0,2,4,6,8,0,2,4,6,8,0,3,6,9,2,5,8,...
i=0 through i=9 are already single digits so their count is 0 and root is
the value itself. Then i=10 to i=19 all take just a single iteration to
reach a single digit. i=25 is the first to require 2 iterations.
Any i with a 0 digit takes just one iteration to get to root 0. Any i like
119111 which is all 1s except for at most a single non-1 takes just one
iteration. This includes the repunits 111..11.
=head2 Radix
An optional C<radix> parameter selects a base other than decimal.
Binary C<radix=E<gt>2> is not very interesting since the digit product is
lib/Math/NumSeq/ErdosSelfridgeClass.pm view on Meta::CPAN
starting i=1,
A prime p is classified by factorizing p+1 into primes, then on each of
those primes q factorizing q+1, and so on, repeating until reaching entirely
2s and 3s. p=2 or p=3 interchange on factorizing p+1 (2+1=3 and 3+1=2*2).
A prime p where p+1 factorizes to all 2s or 3s is class 1. For example i=11
has 11+1=12=2*2*3 which is all 2s and 3s so class 1. 2 and 3 themselves are
class 1 too, since their p+1 factorizing gives 2s and 3s.
Further primes are classified by how many iterations of the p+1 factorizing
is necessary to reach 2s and 3s. For example prime p=3847 is iterated as
3847+1 = 2*13*37
then 13+1 = 2*7
37+1 = 2*19
then 7+1 = 2*2*2
19+1 = 2*2*5
lib/Math/NumSeq/Factorials.pm view on Meta::CPAN
Newton's method is applied to solve for i,
target=log(value)
f(x) = x*log(x) - x - target wanting f(x)=0
f'(x) = log(x)
iterate next_x = x - f(x)/f'(x)
= (x+target)/log(x)
Just two iterations is quite close
target = log(value)
i0 = target
i1 = (i0+target)/log(target)
= 2*target/log(target)
i2 = (i1+target)/log(i1)
i ~= int(i2)
=head1 SEE ALSO
lib/Math/NumSeq/HappySteps.pm view on Meta::CPAN
return ($value >= 0 && $value == int($value));
}
1;
__END__
=for stopwords Ryde HappyNumbers HappySteps Math-NumSeq Radix
=head1 NAME
Math::NumSeq::HappySteps -- number of sum of squares of digits iterations to reach a repeat
=head1 SYNOPSIS
use Math::NumSeq::HappySteps;
my $seq = Math::NumSeq::HappySteps->new (radix => 10);
my ($i, $value) = $seq->next;
=head1 DESCRIPTION
This is the number of iterations of the C<HappyNumbers> style "sum of
squares of digits" is required to reach a repeat of a value seen before, and
therefore to establish whether a number is a happy number or not.
1, 9, 13, 8, 12, 17, 6, 13, 12, 2,
starting i=1
For example i=10 is value 2 because 10-E<gt>1-E<gt>1 is 2 iterations to get
to a repeat (a repeat of 1). At i=1 itself the value is 1 since 1 iteration
reaches 1 again which is itself the repeat. That count 1 at i=1 is the
minimum.
=head2 Radix
An optional C<radix> parameter selects a base other than decimal. In binary
C<radix=E<gt>2> the digits are all either 0 or 1 so "sum of squares of
digits" is the same as a plain "sum of digits".
lib/Math/NumSeq/HappySteps.pm view on Meta::CPAN
Create and return a new sequence object.
=back
=head2 Random Access
=over
=item C<$value = $seq-E<gt>ith($i)>
Return the number of iterations starting from C<$i> required to reach a
repeat.
=back
=head1 SEE ALSO
L<Math::NumSeq>,
L<Math::NumSeq::HappyNumbers>,
L<Math::NumSeq::DigitSum>
lib/Math/NumSeq/JugglerSteps.pm view on Meta::CPAN
# ],
# description => Math::NumSeq::__('Rounding type.'),
# },
];
#------------------------------------------------------------------------------
# eg. 78901 peaks at about 370,000 digits ...
#
# cf
# A094683 - iteration, ie. n^(1/2) or n^(3/2)
# A094670 - smallest requiring n iterations
# A094679 - start requiring n iterations
# A094684 - records in plain seq
# A094698 - num steps where new record
# A143745 - next largest
# A094716 - largest value in trajectory starting from n
# A094778 - dropping time from odd
# A094804 - num primes in trajectory
# A094819 - steps starting 10^n
# A143742 - producing larger value
# A143743 - num digits
# A143744 - steps next largest
lib/Math/NumSeq/PrimeIndexOrder.pm view on Meta::CPAN
=head1 SYNOPSIS
use Math::NumSeq::PrimeIndexOrder;
my $seq = Math::NumSeq::PrimeIndexOrder->new;
my ($i, $value) = $seq->next;
=head1 DESCRIPTION
This is the order of primeness by Neil Fernandez, counting levels of prime
at prime index iterations,
=over
L<http://www.borve.org/primeness/FOP.html>
=back
i = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
value = 0, 1, 2, 0, 3, 0, 1, 0, 0, 0, 4, 0, 1, 0, 0, 0, 2, ...
Any composite has order 0. The order for a prime is based on whether its
index in the list of all primes 2,3,5,7,11,etc is a prime and how many times
that prime index descent can be repeated.
For example i=17 is a prime and is at index 7 in the list of all primes.
That index 7 is a prime too and is at index 4. Then stop there since 4 is
not a prime. Two iterations to reach a non-prime means i=17 has value 2 as
its order of primeness.
=head2 Primes Only
Option C<on_values =E<gt> 'primes'> selects the orders of just the primes
2,3,5,7,etc. The effect is to eliminate the 0s from the sequence.
1, 2, 3, 1, 4, 1, 2, 1, 1, 1, 5, 1, 2, 1, 1, 1, ...
=head1 FUNCTIONS
lib/Math/NumSeq/PrimeIndexPrimes.pm view on Meta::CPAN
Successive levels filter further and the remaining values soon become quite
large. For example level=11 starts at 9737333 (and is quite slow to
generate).
=head2 Level Exact
Optional C<level_type=E<gt>'exact'> asks for values which have exactly
C<level> as their order of primeness.
With the default level 2 this means primes whose index is a prime, but then
the index of that index is not a prime, ie. the iterations of prime index
stops there,
level_type => 'exact', level => 2
3, 17, 41, 67, 83, 109, 157, 191, 211, 241, 283, 353, ...
Here 11 is not in the sequence because its order of primeness is 3, since 11
is at index 5, 5 is at index 3, 3 is at index 2.
level_type=exact,level=1 means those primes which are at composite indexes.
This is all the primes which are not prime index primes, ie. primes not in
lib/Math/NumSeq/ReverseAddSteps.pm view on Meta::CPAN
use Math::NumSeq::Base::Digits
'parameter_info_array'; # radix parameter
#------------------------------------------------------------------------------
# http://oeis.org/index/Res#RAA reverse-adds
#
# cf A015976 - numbers needing 1 iteration to reach palindrome
# A065206 - 1 iteration to reach palindrome, excluding palindromes
# A015977 - 2 iterations to reach palindrome
# A015979 - 3 iterations to reach palindrome
# A033865 - the palindrome at which each n stops
#
# A023109 - first number requiring n iterations to palindrome
# suggesting where to make the hard limit ...
#
# A030547 - num steps, minimum 0, so palindromes value 1
#
# ~/OEIS/a058042.txt on reaching binary palindromes
my @oeis_anum;
$oeis_anum[10] = 'A016016'; # steps to palindrome, or -1 if infinite
# OEIS-Catalogue: A016016
t/MyTestHelpers.pm view on Meta::CPAN
# Don't want to load Exporter here since that could hide a problem of a
# module missing a "use Exporter". Though Test.pm and Test::More (via
# Test::Builder::Module) both use it anyway.
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
sub DEBUG { 0 }
#-----------------------------------------------------------------------------
t/MyTestHelpers.pm view on Meta::CPAN
MyTestHelpers::diag ("search ", $proberef);
MyTestHelpers::findrefs($proberef);
}
}
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
# {
# local $SIG{'__WARN__'} = \&MyTestHelpers::warn_suppress_gtk_icon;
# $something = SomeThing->new;
# }
#
t/MyTestHelpers.pm view on Meta::CPAN
# in Gtk 2.0 gdk_flush() is a sync actually
Gtk2::Gdk->flush;
}
my $count = 0;
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
#-----------------------------------------------------------------------------
# X11::Protocol helpers
sub X11_chosen_screen_number {
xt/oeis/HafermanCarpet-oeis.t view on Meta::CPAN
use lib 't','xt';
use MyTestHelpers;
MyTestHelpers::nowarnings();
use MyOEIS;
use Math::NumSeq::HafermanCarpet;
#------------------------------------------------------------------------------
# A118005 num black cells after n iterations
# = ((-1)^n*5^(n+1) + 9^(n+1)) / 14
# = (9^(n+1) - (-5)^(n+1)) / 14
# n 0 1 2 3 4 5 6
# A118005 1,4,61,424,4441,36844,347221
# start0 0,4,36,424,3816,36844,331596
# start1 1,9,61,549,4441,39969,347221 start1 = start0 + 5^n
# diff 1 5 25 124 625
#
# if start from single 0 cell then 1s count is