login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A321802 Delete all consecutive identical decimal digits of n; write -1 if all digits disappear. 6

%I #13 Nov 14 2023 11:47:11

%S 0,1,2,3,4,5,6,7,8,9,10,-1,12,13,14,15,16,17,18,19,20,21,-1,23,24,25,

%T 26,27,28,29,30,31,32,-1,34,35,36,37,38,39,40,41,42,43,-1,45,46,47,48,

%U 49,50,51,52,53,54,-1,56,57,58,59,60,61,62,63,64,65,-1,67,68,69,70,71,72,73,74,75,76,-1,78,79,80,81,82,83,84,85,86,87,-1,89,90,91,92,93,94,95,96,97,98,-1,1,101,102,103,104,105,106,107,108,109,0,-1,2,3,4,5,6,7,8,9,120,121,1

%N Delete all consecutive identical decimal digits of n; write -1 if all digits disappear.

%C Consecutive identical digits of n are erased. Leading zeros are erased unless the result is 0. If all digits are erased, we write -1 for the result (A321801 is another version, which uses 0 for the empty string).

%C More than the usual number of terms are shown in order to reach some interesting examples. Agrees with A320485 for n < 101.

%H Chai Wah Wu, <a href="/A321802/b321802.txt">Table of n, a(n) for n = 0..10000</a>

%e 12311 becomes 123, 1123 becomes 23, 11231 becomes 231, and 110232 becomes 232 (as we don't accept leading zeros). Note that 112233 disappears immediately and we get -1.

%e 1110 becomes 0 and 11000, 1100011 all become -1.

%t A321802[n_]:=With[{d=Flatten[Select[Split[IntegerDigits[n]],Length[#]==1&]]},If[d=={},-1,FromDigits[d]]];Array[A321802,100,0] (* _Paolo Xausa_, Nov 14 2023 *)

%o (Python)

%o from re import split

%o def A321802(n):

%o return (lambda x: int(x) if x != '' else -1)(''.join(d if len(d) == 1 else '' for d in split('(0+)|(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)',str(n)) if d != '' and d != None))

%o (PARI) apply( A321802(n)={if(n,forstep(i=#n=digits(n), 2, -1, n[i]!=n[i-1]&&next; if(i<3||n[i-2]!=n[i], n=n[^i]; i--); n=n[^i]); if(#n,fromdigits(n),-1))}, [0..122]) \\ _M. F. Hasler_, Nov 20 2018

%Y Cf. A320485, A321801.

%K sign,base

%O 0,3

%A _Chai Wah Wu_, Nov 19 2018

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 18 18:58 EDT 2024. Contains 371781 sequences. (Running on oeis4.)