On Fri, Oct 30, 2020 at 2:19 PM Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> > On 30 Oct 2020, at 22:11, Sean McAfee <eef...@gmail.com> wrote: > > With polymod, I can get the values of digits even in large bases like > 101: > > > > > 1234567890.polymod(101 xx *) > > (46 20 26 87 11) > > > > Given a list of digit values like that, and the base, I want to > reconstruct the original number. So you'd basically need a sub that takes a List, and a base factor, and > does the necessary arithmetic for you. I don't think that's in core. I'd > be glad if someone proved me wrong :-) > Found it! The "trick" is to use square braces after the colon and base. For example, :101[11,87,26,20,46] evaluates to 1234567890. The digit values have to be supplied most-significant to least-significant, the opposite of the order returned by polymod, and the base must be known at compile time, but this is definitely the construction I was trying to recall originally. Even nicer for my golfing purposes, the list elements are coerced to numbers automatically, so for example :2[True, False, True, False] evaluates to 10. I can't locate any documentation on this feature, but then I couldn't find documentation on the dynamic string-parsing version (eg. :2($str)) when I looked either, only the literal form, like :2<10101>.