[Perl] p6 problème dépilatoire

Dominique d.minix at gmail.com
Sam 28 Oct 12:37:10 CEST 2017


quand on arrive un peu a reflechir c'est mieux, mais si vous avez mieux je
prend.


#! /usr/bin/env perl6
my @names = <zero un deux trois quatre cinq six sept huit neuf dix onze
douze treize quatorze quinze seize dix-sept dix-huit dix-neuf vingt trente
quarante cinquante>;

multi sub spell-number(Int $n where {$n < 20}) {
return @names[$n];
}
multi sub spell-number(Int $n where {$n < 60}) {
        my $r = @names[$n / 10 + 18];
        $r ~= '-' ~ @names[$n % 10] if $n % 10;
        return $r;
}
multi sub spell-number(Int $n where {$n < 80}) {
my $r ~= 'soixante ' ~ @names[$n-60];
return $r;
}
multi sub spell-number(Int $n where {$n < 100}) {
my $r ~= 'quatre-vingt ' ~ @names[$n-80];
return $r;
}
multi sub spell-number(Int $n where {$n < 1000}) {
return spell-part($n, 100, 'cent');
}

multi sub spell-number(Int $n where {$n < 1000000}) { return
spell-part($n,1000,"mille")};
multi sub spell-number(Int $n where {$n < 1000000000}) { return
spell-part($n,1000000,"million")};
multi sub spell-number(Int $n where {$n < 1000000000000}) { return
spell-part($n,1000000000,"milliard")};
multi sub spell-number(Int $n where {$n < 1000000000000000}) { return
spell-part($n,1000000000000,"billion")};
multi sub spell-number(Int $n where {$n < 1000000000000000000}) { return
spell-part($n,1000000000000000,"billiard")};
multi sub spell-number(Int $n where {$n < 1000000000000000000000}) { return
spell-part($n,1000000000000000000,"trillion")};
multi sub spell-number(Int $n where {$n < 1000000000000000000000000}) {
return spell-part($n,1000000000000000000000,"trilliard")};
multi sub spell-number(Int $n where {$n < 1000000000000000000000000000}) {
return spell-part($n,1000000000000000000000000,"quadrillion")};
multi sub spell-number(Int $n where {$n < 1000000000000000000000000000000})
{ return spell-part($n,1000000000000000000000000000,"quadrilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000,"quintillion")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000,"quintilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000,"sextillion")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000,"sextilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000,"septillion")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000,"septilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000000,"octillion")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000000000,"octilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000000000000,"nonillion")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000000000000000,"nonilliard")};
multi sub spell-number(Int $n where {$n <
1000000000000000000000000000000000000000000000000000000000000000}) { return
spell-part($n,1000000000000000000000000000000000000000000000000000000000000,"decillion")};

sub spell-part(Int $n, Int $base, Str $name) {
my $r = spell-number(($n / $base).Int) ~ ' ' ~ $name;
$r ~~ s/un" "cent/cent/;
$r ~~ s/^un" "mille/mille/;
$r ~= ' ' ~ spell-number($n % $base) if $n % $base;
return $r;
}

say spell-number(147);
say spell-number(1397);
say spell-number(51397);
say spell-number(123001197);
-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: <http://listes.mongueurs.net/mailman/private/perl/attachments/20171028/46b0123c/attachment.html>


Plus d'informations sur la liste de diffusion Perl