Acme-Goedelize
view release on metacpan or search on metacpan
lib/Acme/Goedelize.pm view on Meta::CPAN
my %link = %a_to_n;
### Check the text
croak "The string must contain only alpha chars and spaces"
if ($text !~ /^[a-zA-Z\s]*$/);
### Append dot
if ($text !~ /\.$/) { $text .= "."; }
my @txt = split(//, $text);
my $current_prime = 2;
my $result = Math::BigInt->new(1);
foreach my $char ( @txt ) {
my $prime = get_next_prime($current_prime);
my $current = Math::BigInt->new($prime);
$result *= ($current ** $link{$char});
$current_prime = $prime + 1;
}
return $result;
}
sub to_text {
my ($self, $number) = @_;
my %link = reverse %a_to_n;
### Check the text
croak "The string must be number\n"
if $number !~ /^[0-9]*$/;
my $goedel = Math::BigInt->new($number);
my $current_prime = 2;
my $result;
PROCESS: while (1) {
my $prime = get_next_prime($current_prime);
my $times = 0;
my $tmp = $goedel;
DIVISION: while (1) {
my $num = ($tmp/$prime);
last DIVISION if ( ($tmp % $prime) > 0 );
$times++;
$tmp = $num;
}
last PROCESS if $link{$times} eq ".";
$result .= $link{$times};
$current_prime = $prime + 1;
}
return $result;
}
sub get_next_prime {
my $current = shift;
GUESS: for (my $guess = $current; ; $guess++)
{
for (my $divisor = 2; $divisor < $guess; $divisor++)
{
next GUESS unless $guess % $divisor;
}
return $guess;
}
}
1;
__END__
=head1 NAME
Acme::Goedelize - Goedelize text
=head1 SYNOPSIS
use Acme::Goedelize;
my $goedelize = new Acme::Goedelize;
my $number = $goedelize->to_number('text');
my $text = $goedelize->to_text($number);
=head1 DESCRIPTION
Transforms text into one big number and vice versa.
=head1 AUTHOR
Todor Todorov, E<lt>acidmax@jambolnet.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2004 by Todor Todorov
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 0.839 second using v1.01-cache-2.11-cpan-5a3173703d6 )