@@ -34,13 +34,13 @@ <h2>Editor</h2>
3434 </ div >
3535 < textarea id ="code " spellcheck ="false ">
3636primes = primes(200000);
37- plot(x = > pix(x, primes));
37+ plot(count( primes));
3838plot(x => ceil(x / ln(x)));
3939plot(x => ceil(x / ln(x) + x / pow(ln(x), 2)));
4040plot(x => floor(li(x)));
4141plot(x => Math.ceil(x / (ln(x) - 1)));
4242maybeprimes = maybePrimes(200000, []);
43- plot(x = > pix(x, maybeprimes));
43+ plot(count( maybeprimes));
4444
4545//plot(x => cgamma(complex(0, x)).y);
4646
@@ -425,18 +425,18 @@ <h2>Editor</h2>
425425 return arr ;
426426}
427427
428- function pix ( x , primes ) {
429- let left = 0 ;
430- let right = primes . length - 1 ;
431- let result = 0 ;
432- while ( left <= right ) {
433- const mid = Math . floor ( ( left + right ) / 2 ) ;
434- if ( primes [ mid ] <= x ) {
435- result = mid + 1 ;
436- left = mid + 1 ;
437- } else {
438- right = mid - 1 ;
428+ function count ( arr ) {
429+ const max = Math . max ( ...arr ) ;
430+ const sorted = [ ...arr ] . sort ( ( a , b ) => a - b ) ;
431+ const result = [ ] ;
432+ let countv = 0 ;
433+ let idx = 0 ;
434+ for ( let i = 0 ; i <= max ; i ++ ) {
435+ while ( idx < sorted . length && sorted [ idx ] <= i ) {
436+ countv ++ ;
437+ idx ++ ;
439438 }
439+ result . push ( countv ) ;
440440 }
441441 return result ;
442442}
@@ -738,11 +738,11 @@ <h2>Editor</h2>
738738 try {
739739 const fn = new Function ( 'randomColor' , 'sin' , 'cos' , 'tan' , 'log' , 'ln' , 'log2' , 'log10' ,
740740 'sqrt' , 'abs' , 'exp' , 'pow' , 'PI' , 'E' , 'asin' , 'acos' , 'atan' , 'atan2' ,
741- 'sinh' , 'cosh' , 'tanh' , 'floor' , 'ceil' , 'round' , 'sign' , 'min' , 'max' , 'random' , 'primes' , 'pix ' , 'li' , 'complex' ,
741+ 'sinh' , 'cosh' , 'tanh' , 'floor' , 'ceil' , 'round' , 'sign' , 'min' , 'max' , 'random' , 'primes' , 'count ' , 'li' , 'complex' ,
742742 'cgamma' , 'csin' , 'cexp' , 'clog' , 'cinv' , 'cpow' ,
743743 code ) ;
744744 fn ( randomColor , sin , cos , tan , log , log , log2 , log10 , sqrt , abs , exp , pow , PI , E ,
745- asin , acos , atan , atan2 , sinh , cosh , tanh , floor , ceil , round , sign , min , max , random , primes , pix , li , complex , cgamma , csin , cexp , clog , cinv , cpow ) ;
745+ asin , acos , atan , atan2 , sinh , cosh , tanh , floor , ceil , round , sign , min , max , random , primes , count , li , complex , cgamma , csin , cexp , clog , cinv , cpow ) ;
746746 document . getElementById ( 'cnt' ) . textContent = graphs . length ;
747747 render ( ) ;
748748 showMsg ( `✓ Build: ${ graphs . length } ` , 'ok' ) ;
0 commit comments