Ruud H.G. van Tol on Mon, 19 Dec 2022 05:40:07 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Binary Complement Sequences |
On seqfan, there is a thread about Binary Complement Sequences. > on any number: > -multiply by 3 > -find the binary complement (if it is 1001010 in binary, > the complement is 0110101). I created this code: { bc3(n)= bitneg(n*=3,logint(n,2)); } { bc3_seqX(n)= my(x=n,i=0);while(x>0,x=bc3(x);i++); print(n," -> ",x," (",i,")"); } { bc3_dropX(n)= my(x=n,i=0);until(x<=n,x=bc3(x);i++); print(n," -> ",x," (",i,")"); } Related code on https://oeis.org/wiki/User:Ruud_H.G._van_Tol ? bc3_dropX(22246); 22246 -> 9838 (120796648) cpu time = 4min, 16,771 ms, real time = 4min, 17,641 ms. ? bc3_seqX(22246); 22246 -> 0 (120796790) cpu time = 4min, 17,644 ms, real time = 4min, 18,250 ms. Are there ways to do this faster? If I inline the bitneg, it becomes: ? bc3_seqX(22246); 22246 -> 0 (120796790) cpu time = 3min, 39,774 ms, real time = 3min, 40,153 ms. but I'm of course after a decimation. :) -- Ruud