From:

Date:

October 30, 2020 20:25Subject:

Constructing a number from digits in an arbitrary baseMessage ID:

CANan03Z+vrkbAeN4Jo=4KgPmZq0GZWZZY7+hOyXHTHWb6kq2oA@mail.gmail.comI want to construct a number from its digits in some arbitrary base. That is, to essentially do the inverse of this kind of polymod call: my @digits = $number.polymod($base xx *); I have a nagging feeling that I've seen a very concise way to do this in Raku before, but now it escapes me, and all my searching has found only pages describing basic, ordinary base conversion. Obviously for bases from 2-10 one can just concatenate the digits and pass them to a conversion construct like :2(...) or :5(...) or whatever, if the base is fixed at compile time. For the more general case the best I can come up with is my $number = sum @digits Z* (1, * * $base ... *); Is there a shorter and/or better way?Thread Next

**Constructing a number from digits in an arbitrary base**by Sean McAfee- Re: Constructing a number from digits in an arbitrary base by Bruce Gray
- Re: Constructing a number from digits in an arbitrary base by Sean McAfee
- Re: Constructing a number from digits in an arbitrary base by Elizabeth Mattijsen
- Re: Constructing a number from digits in an arbitrary base by Elizabeth Mattijsen

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About