Ruud H.G. van Tol on Tue, 17 Oct 2023 17:58:23 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: digits(n,-4)



On 2023-10-15 12:46, Ruud H.G. van Tol wrote:
[...]

Still playing:

baseneg( n, b= -10 ) = if( n, baseneg(n\b, b) * -b + n%b, 0 )

? baseneg(12, -4)
% 20

? digits(20, 4)
% [1, 1, 0]

? fromdigits(digits(20, 4), -4)
% 12


-- Ruud



Example usage:

? a005352(n) = baseneg(-n, -2);

? [ a005352(n) |n<-[1..40] ]
% [3, 2, 13, 12, 15, 14, 9, 8, 11, 10, 53, 52, 55, 54, 49, 48, 51, 50, 61, 60, 63, 62, 57, 56, 59, 58, 37, 36, 39, 38, 33, 32, 35, 34, 45, 44, 47, 46, 41, 40]