; Author: Andres M. Torres ; Date: August 25,2013 ; Title: Sequence A227643 ; ; Description: Generating sequence A227643 ; " Each a(n) is one more than the count of all descendant nodes in a tree, ; where values, n, are connected by relation p=c+bitcount(c). p=parent, c=child. ; Function bitcount(c) is the count of binary 1's in c. " ; ; Draft link: https://oeis.org/draft/A227643 ; This is Blitz3D code, (a free Blitz3D demo is available from the following links:) ; http://www.blitzbasic.com/Products/_index_.php ; http://shareit1.element5.com/product.html?productid=147747 ; { This code is in the Public Domain. } Global nmax = 1572 ;10020; 20000 Dim R(nmax) ;; an array of R values, R(i) = i+bitcount(i) Dim W(nmax) ;; tree weights (also known as node counts) Graphics 900,600,32,2 Print " sequence A227643 sampler: " Print ;; Initialize the array with R(i) = i+bitcount(i) values, (0..9999) init_R() s$ = " " : linecount=0 ;; calculate the node counts, and store in W(n) (an array of node counts) For z=0 To nmax n=z Repeat W(n) = W(n)+1 n=R(n) Until n=0 Or n>nmax Next z=0 Repeat s = s + Str(W(z))+" " If Len(s)>100 Print S S = " " : linecount = linecount +1 End If z = z +1 Until linecount=39 maxx = FindMax(0,z-1) Print Print" There were "+z+" terms listed for sequence A227643 " Print" The index displayed that has the highest value = a("+maxx+") = "+W(maxx) ratio# = 580.0/FindMax(0,779) Print" Touch a key to see a scatter plot. " WaitKey():Cls ;ratio# = 580.0/FindMax(0,779) For x=0 To 779 y = 590- W(x)*ratio WritePixel x+10,y, $33FFDD Next Color 140, 140, 140 ;66, 45, 34 Rect 10,10, 880,580, 0 Color 240,220,220 Locate 3,1 Print Print" Shown here is a scatter plot for Sequence A227643 Sequence A227643 : " Print" " Print" within the rectangle, (not proportional) : " Print" " Print" x values are : 0 to 880, " Print" y values are : 0 to 860, a(0) to a(860) " Print" " we() ;; initialize the "R" array Function init_R() Local z Local nmax1 =nmax-1 For z=0 To nmax1 R(z) = z+bitcount(z) Next End Function ;; counts the number of set binary bits in value n. Function bitcount(n) ;; A bitcount computation ... Local c= 0 ; count While(n) c = c + 1 n = n And (n-1) Wend Return c End Function Function we() WaitKey():End End Function ;; returns the index that has the max value of W(n) within range (r1,r2) Function FindMax(r1,r2) Local x, max, maxx For x=r1 To r2 If max