Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #41 Dec 14 2019 08:08:04
%S 112,123,134,145,156,167,178,189,213,224,235,246,257,268,279,314,325,
%T 336,347,358,369,415,426,437,448,459,516,527,538,549,617,628,639,718,
%U 729,819,1123,1235,1347,1459,1910,2134,2246,2358,2810,2911,3145,3257,3369
%N Numbers whose digits can be partitioned into at least 3 segments (not beginning with 0) where each segment is the sum of the previous two segments.
%H Bi Cheng Wu, <a href="/A329719/b329719.txt">Table of n, a(n) for n = 1..4958 (a(n) < 1000000)</a>
%e 112 -> 1+1=2;
%e 1235 -> 1+2=3 and 2+3=5;
%e 224610 -> 2+2=4 and 2+4=6 and 4+6=10.
%t part[n_] := part[n] = Select[Flatten[ Permutations /@ Reverse /@ IntegerPartitions[n, {3,n}], 1], 0 <= #[[3]] - Max[#[[1]], #[[2]]] <= 1 && AllTrue[Rest@ Rest@ Differences@ #, 0 <= # <= 1 &] &]; spl[x_, L_] := Map[ FromDigits@ Take[x, #] &, Transpose[{Most@ #, Rest[#]-1}& [ FoldList[ Plus, 1, L]]]]; sumQ[w_] := AllTrue[Range[3, Length@w], w[[#]] == w[[#-1]] + w[[#-2]] &]; ok[n_] := Block[{m = IntegerLength@ n}, AnyTrue[ spl[ IntegerDigits[n], #] & /@ part[m], sumQ[#] && Total[ IntegerLength /@ #] == m &]]; Select[ Range[100, 6000], ok] (* _Giovanni Resta_, Dec 03 2019 *)
%o (Python)
%o def isSegmentSum(digits,segment1=None,segment2=None):
%o digits = str(digits)
%o N = len(digits)
%o if N == 0:
%o return True
%o else:
%o if (segment1 is None) and (segment2 is None):
%o for i in range(N):
%o try:
%o slice1 = digits[:i+1]
%o for j in range(N-(i+1)):
%o slice2 = digits[i+1:i+1+j+1]
%o slice3 = digits[i+1+j+1:]
%o if (isSegmentSum(slice3,slice1,slice2) and
%o len(slice3)>0 and not (slice1.startswith("0") or
%o slice2.startswith("0") or
%o (slice3.startswith("0")))):
%o return True
%o except:
%o return False
%o else:
%o sumOfDigits = str(int(segment1)+int(segment2))
%o nS = len(sumOfDigits)
%o try:
%o if digits[:nS] == sumOfDigits:
%o return isSegmentSum(digits[nS:],segment2,digits[:nS])
%o else:
%o return False
%o except:
%o return False
%o return False
%o def findSegmentSum(lower,upper):
%o for i in range(lower,upper+1):
%o if isSegmentSum(i):
%o print(str(i))
%o findSegmentSum(1, 5200)
%Y Shares subsequences with A108203, A308104, A214527.
%Y Cf. A019523.
%K nonn,base
%O 1,1
%A _Bi Cheng Wu_, Nov 19 2019