Author Topic: Clustering prime numbers -- how do I position a console window ???  (Read 2502 times)

0 Members and 1 Guest are viewing this topic.

RobbeK

  • Guest
Hi all,

An interesting method of determing non prime numbers (based on Dirichlet's theorem ).
It is based on coprimes and I read on a website the modulo 30 group is the one with the highest number that can do this.
I think this is not correct , the 210 modulo , 2310 etc ... will also do
(someone can predict the next "wheel" ???  -- it's not so difficult  8)   (previous wheel is 30 , you c the trick ???? )
As you can see the primes are located on rays , and more important the grey rays can NOT contain primes -- this algorithm is extreme fast determing a  non prime (and in this case predicting an around 40% chance for a prime -- the red dots are the primes )  -- this of course lowers the bigger the numbers are (you can use the Li(x) function to find out how much )

it's written in NewLISP (a scripting language)

----------------------

 (define dll "screen.dll")
 
 

(dolist (i '("setscreen" "scr" "pixel")) (import dll i))

(silent
 

(define mx (array 200000 '(0)))
(define ray-freq (array 210 2 '(0 0)))
(define pi (mul 2 (acos 0)))

(define (make-primes)
    (dotimes (i 200000)
      (when (= 1 (length (factor i))) (setf (mx i) 1))))

 
(define (polar x)
  (let ((pos (mod x 210))
        (ring (int (div x 209))))
    (list (mul pos 12 (div 7)) (+ 90 ring) pos )))

 

(define (main n)
  (make-primes)
  (setscreen 800 800 200 20)
  (dotimes (i n)
  (letn ((L (polar i))
         (hk (div (mul pi (L 0)) 180))
         (x (int (mul (L 1) (cos hk))))
         (y (int (mul (L 1) (sin hk)))))
     (if (zero? (mx i))
            (begin (pixel (+ 400 x) (+ 400 y) 88 88 88)
                   (++ ((ray-freq (L 2)) 0)))
            (begin
                  (pixel (+ 400 x) (+ 400 y) 222 0 0)
                   (++ ((ray-freq (L 2)) 1)))))))

(define (report)
  (dotimes (i 210)
     (let ((result (ray-freq i)))
       (print "Ray #" i " : ")
       (print "Total hits : " (+ (result 0) (result 1)) "  Prime hits : " (result 1))
       (print " ->  ="(int (mul 100 (div (result 1) (+ (result 0) (result 1))))) "%")
       (println ""))))


)

(main 80000)
(report)
(println "")
(println "Enter to exit")
(read-char)
(scr 0)
(exit)

-----

and a dll doing the 2D output (from Freebasic)

question : is there an easy way (via dll ) to position the consolewindow -- newLISP lacks any control doing it -- been looking but only found something in C (using the studio.h   ...

thanks in advance

rob

 


.
« Last Edit: July 21, 2015, 02:32:04 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Clustering prime numbers -- how do I position a console window ???
« Reply #1 on: July 21, 2015, 02:28:46 AM »
Hi Rob,

It's nice to see you around again. :)

There are a lot of APIs whose direct or secondary effect will be the resizing/repositioning of windows, including (with some restrictions) Windows consoles, for example:

SetConsoleWindowInfo (kernel32.dll)
ShowWindow (user32.dll)
SetWindowPos (user32.dll)
MoveWindow (user32.dll)

and a few others. You can read up more on them in the Win32 Programmer's Reference manual (7MB) downloadable from this site.

Use GetConsoleWindow (kernel32.dll) or FindWindow[Ex] (user32.dll) functions to obtain the calling process' console hWnd for use in general-purpose API calls.

Charles Pegge

  • Guest
Re: Clustering prime numbers -- how do I position a console window ???
« Reply #2 on: July 21, 2015, 04:03:37 AM »
Thanks Mike

Simple console placement and sizing:

Code: OxygenBasic
  1. 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms683175(v=vs.85).aspx
  2. 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx
  3.  
  4. includepath "$\inc\"
  5. include "minwin.inc"
  6. include "console.inc"
  7.  
  8. extern lib "kernel32.dll"
  9. ! GetConsoleWindow() as sys
  10. end extern
  11.  
  12.  
  13. h=GetConsoleWindow
  14. SetWindowPos h,0,  200,200,600,800,  0
  15. waitkey
  16.  

RobbeK

  • Guest
Re: Clustering prime numbers -- how do I position a console window ???
« Reply #3 on: July 22, 2015, 11:04:58 AM »
Thanks Charles, Mike    ;)

It works without any problems !

,------------------------------------

(import "kernel32.dll" "GetConsoleWindow" )
(import "user32.dll" "SetWindowPos")
 

(SetWindowPos  (GetConsoleWindow) 0 20 20 600 600 0)

;;;

perfect,   many thanks !!

Rob