Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - david_uwi

Pages: [1]
1
QB64 Discussion / Possible error in INTEGER64 calculations
« on: September 25, 2021, 04:19:42 am »
Sorry I've not got the latest version, so if this has been sorted you can delete this.

DIM z AS _INTEGER64
z = 7 ^ 19
PRINT z

The answer should end in ..373143, but the above gives ...373144


2
Programs / multiplication of large numbers - fast method
« on: June 19, 2021, 01:59:27 pm »
Dealing with larger numbers without using strings. This time multiplication using a FFT (fast Fourier transform).
No idea how it works, but it does. Essentially it reduces multiplication to addition (which is much faster).
Here's the program - it squares a number. The key number is the N it specifies number size. Each number in the array is 2 digits ( 0-99 ) and is generated using  "randomize timer". N MUST BE a factor of 2 (that's the way FFTs work). Currently N=256 so it will generate a 512 digit number and square it.
It does not have to be squaring the two numbers can be different and it works just the same (but they have to both be multiples of 2 -you could zero fill to get round this).
Almost forgot to mention - it also uses imaginary numbers (the array AI contain the imaginary part).
Code: QB64: [Select]
  1.  
  2. 'The fourier transform I have translated from Fortran and I got it from IEEE transactions (March 1965).
  3.  
  4. TT = TIMER
  5. DEFSNG A-F, P-Z
  6. DEFINT G-O
  7. REM N is the number of two digit numbers to be loaded
  8. REM so the total number of digits is 2*N
  9. N = 256
  10. DIM AR(N * 4), AI(N * 4)
  11. DIM BR(N * 2 + 1) AS LONG, IC AS LONG
  12. M = INT(LOG(N) / LOG(2) + .5)
  13. PI = 3.141593
  14. FOR I = 1 TO N
  15.     AR(N - I + 1) = INT(RND * 100)
  16. PRINT: PRINT "Number to be squared"
  17. FOR I = N TO 1 STEP -1
  18.     Q$ = "0" + LTRIM$(STR$(AR(I)))
  19.     Q$ = RIGHT$(Q$, 2)
  20.     PRINT Q$;
  21. N = N * 4
  22. M = M + 2
  23. GOSUB CooleyTukey
  24. FOR I = 1 TO N
  25.     AR(I) = AR(I) / N
  26.     AI(I) = AI(I) / N
  27.     AR(I) = AR(I) * AR(I) - AI(I) * AI(I)
  28.     AI(I) = 2 * AR(I) * AI(I)
  29. GOSUB CooleyTukey
  30. FOR J = 1 TO N
  31.     AR(J) = AR(J) * N
  32. BR(1) = AR(1): BR(N / 2 + 1) = AR(N / 2 + 1)
  33. FOR I = 2 TO N / 2
  34.     K = N - I + 2
  35.     BR(I) = AR(I) + AR(K)
  36. IC = 0
  37. FOR I = 1 TO N / 2 + 1
  38.     BR(I) = BR(I) + IC
  39.     IC = BR(I) \ 100
  40.     BR(I) = BR(I) MOD 100
  41. PRINT "OUTPUT...."
  42. FOR I = N / 2 + 1 TO 1 STEP -1
  43.     Q$ = "0" + LTRIM$(STR$(BR(I)))
  44.     Q$ = RIGHT$(Q$, 2)
  45.     PRINT Q$;
  46. PRINT: PRINT "TIME TAKEN = "; TIMER - TT
  47. CooleyTukey:
  48. J = 1
  49. FOR I = 1 TO N - 1
  50.     IF I < J THEN
  51.         SWAP AR(I), AR(J)
  52.         SWAP AI(I), AI(J)
  53.     END IF
  54.     K = N / 2
  55.     WHILE K < J
  56.         J = J - K
  57.         K = K / 2
  58.     WEND
  59.     J = J + K
  60. FOR L = 1 TO M
  61.     LE = 2 ^ L
  62.     LE1 = LE / 2
  63.     UR = 1!: UI = 0!
  64.     ANG = PI / LE1
  65.     WR = COS(ANG): WI = SIN(ANG)
  66.     FOR J = 1 TO LE1
  67.         FOR I = J TO N STEP LE
  68.             IP = I + LE1
  69.             TR = AR(IP) * UR - AI(IP) * UI
  70.             ti = AR(IP) * UI + AI(IP) * UR
  71.             AR(IP) = AR(I) - TR
  72.             AI(IP) = AI(I) - ti
  73.             AR(I) = AR(I) + TR
  74.             AI(I) = AI(I) + ti
  75.         NEXT I
  76.         URT = UR * WR - UI * WI
  77.         UI = UR * WI + UI * WR
  78.         UR = URT
  79.     NEXT J
  80.  

3
Programs / More matrix fun
« on: May 19, 2021, 02:35:56 pm »
As we seem to be looking at matrix manipulation...
Here's a program I wrote nearly 30 years ago. It diagonalizes a real symmetric matrix. This gives (in maths-speak) the eigenvalues and eigenvectors. It''s only set up for a 3x3 (which is read from a data file in the order 1,1 2,2 3,3 1,2 1,3 2,3),
but it will do any size (but note the time taken is approx N cubed where N is the size of the matrix). Enjoy...
Code: QB64: [Select]
  1. 5 DEFINT I-N
  2. n2 = 3
  3. DIM e(n2, n2), X(n2, n2)
  4. OPEN "c:\cw1\mymatrix.txt" FOR INPUT AS #1
  5. INPUT #1, e(1, 1), e(2, 2), e(3, 3), e(1, 2), e(1, 3), e(2, 3)
  6. e(2, 1) = e(1, 2): e(3, 2) = e(2, 3): e(3, 1) = e(1, 3)
  7. PRINT "input matrix"
  8. FOR i = 1 TO n2
  9.     FOR J = 1 TO n2
  10.         PRINT USING "####.#####"; e(i, J);
  11.     NEXT J
  12.     PRINT
  13.  
  14. GOSUB 4000
  15. PRINT "EIGENVALUES"
  16. FOR i = 1 TO n2
  17.     FOR J = 1 TO n2
  18.         PRINT USING "####.#####"; e(i, J);
  19.     NEXT J
  20.     PRINT
  21. PRINT "EIGENVECTORS"
  22. FOR i = 1 TO n2
  23.     FOR J = 1 TO n2
  24.         PRINT USING "####.#####"; X(i, J);
  25.     NEXT J
  26.     PRINT
  27.  
  28. GOTO 130
  29. 100 PRINT "*********************"
  30. 110 PRINT "INCORRECT INPUT!!!!!"
  31. 120 PRINT "*********************"
  32. 130 END
  33. 4000 REM DIAGONALISATION USING JACOBI'S METHOD (D.S. 1993)
  34. 4005 M = (n2 * n2 - n2) / 2
  35. 4010 TRA = M * .00001
  36. FOR i = 1 TO n2
  37.     FOR J = 1 TO n2
  38.         X(i, J) = 0!
  39.     NEXT J
  40.     X(i, i) = 1!
  41. 4090 FOR L = 1 TO M * 10
  42.    4100 Q = 0: AM = -1
  43.    4110 FOR J = 1 TO n2 - 1
  44.        4120 FOR i = J + 1 TO n2
  45.            4130 Z = ABS(e(i, J))
  46.            4140 Q = Q + Z
  47.            4150 IF Z < AM GOTO 4170
  48.            4160 AM = Z: IX = i: JX = J
  49.        4170 NEXT i
  50.    4180 NEXT J
  51.    4190 IF Q < TRA THEN RETURN
  52.    4200 A1 = e(IX, IX) - e(JX, JX)
  53.    4210 A5 = e(IX, JX)
  54.    4220 IF ABS(A5) * 50 > ABS(A1) GOTO 4270
  55.    4230 A6 = 2 * A1 * A1 + 3 * A5 * A5
  56.    4240 C = -2 * A1 * A5 / A6
  57.    4250 s = 1 - A5 * A5 / A6
  58.    4260 GOTO 4320
  59.    4270 A2 = SQR(A1 * A1 + 4 * A5 * A5)
  60.    4280 IF A1 > 0 THEN A2 = -A2
  61.    4290 A3 = (A1 + A2) / (2 * A5)
  62.    4300 s = 1 / SQR(A3 * A3 + 1)
  63.    4310 C = A3 * s
  64.    4320 FOR J = 1 TO n2
  65.        4330 TM = e(JX, J) * s + e(IX, J) * C
  66.        4340 e(IX, J) = e(IX, J) * s - e(JX, J) * C
  67.        4350 e(JX, J) = TM
  68.        4360 TM = X(JX, J) * s + X(IX, J) * C
  69.        4370 X(IX, J) = X(IX, J) * s - X(JX, J) * C
  70.        4380 X(JX, J) = TM
  71.    4390 NEXT J
  72.    4400 FOR J = 1 TO n2
  73.        4410 TM = e(J, JX) * s + e(J, IX) * C
  74.        4420 e(J, IX) = e(J, IX) * s - e(J, JX) * C
  75.        4430 e(J, JX) = TM
  76.    4440 NEXT J
  77. 4450 NEXT L
  78. 4460 PRINT "CONVERGENCE FAILURE": CLOSE #1
  79. 4490 END

4
Programs / Codeword solver
« on: July 06, 2020, 07:18:43 am »
Code word is a type of puzzle that has appeared recently (maybe?).
It is like a crossword but there are no clues, instead the grid has numbers which correspond to letters of the alphabet (1 to 26 - not in order obviously).
You have to try to fit in words that will work in the grid and have one letter per number.
It is often difficult to get a start so I have written this program that will search a word list.
There are comment line at the beginning that explain the input.
As a hint longer words are often best as there are much fewer words with 10 letters than there are with 5 also the pattern of repeated and unique letters is larger. There is also a function to eliminate known letters, but this has not been tested.

Code: QB64: [Select]
  1. OPEN "c:\cw1\dictionary_english.dic" FOR INPUT AS #1
  2. DIM word$(320000)
  3. DIM q1 AS STRING * 1, q2 AS STRING * 1 'there are problems if these are not dimensioned
  4. DIM wdot(25) AS STRING * 1, wndot(25) AS STRING * 1, wndot1(25) AS STRING * 1
  5. DIM w2(7) AS STRING * 1, w3(7) AS STRING * 1, w4(7) AS STRING * 1, w5(7) AS STRING * 1
  6. DIM ex1 AS STRING * 1
  7. DIM r1$(20)
  8. SCREEN _NEWIMAGE(1000, 500, 2)
  9.  
  10. 'font1& = _LOADFONT("c:\windows\fonts\courbd.ttf", 20, "bold")  'courier bold
  11. 'font1& = _LOADFONT("c:\windows\fonts\times.ttf", 20, "bold") 'times bold
  12. font1& = _LOADFONT("c:\windows\fonts\cour.ttf", 20, "bold") 'courier regular
  13. _FONT font1& 'lets have a monospaced font - lines up better
  14.  
  15. 'either put in the numbers in the puzzle separated by "," OR
  16. 'put in "." for unknowns and the numbers 2,3,4,5 for duplicates
  17. '.2334.4N52.54 will work as will 13,8,21,21,4,16,4,N,3,8,10,3,4 [the N was a given letter]
  18. 'both will give differentiate
  19.  
  20. 'when letters are given (or known) they can be excluded by loading an exclusion list
  21. 'input ! followed by the letters, this can be added to by ! [more letters] and reset by just putting in !
  22.  
  23. ' **************************all duplicates MUST be put in**********************
  24. 'for crosswords this will not work!!!
  25. PRINT "loading word list....please wait"
  26. FOR i = 1 TO 319378
  27.     INPUT #1, word$(i) 'load list into RAM it is much faster
  28.    200 PRINT "input word  ";
  29.     LINE INPUT a$
  30.     f$ = a$
  31.     IF INSTR(a$, ",") <> 0 THEN GOSUB longform
  32.     IF LEFT$(a$, 1) = "!" THEN
  33.         IF LEN(a$) = 1 THEN ex$ = ""
  34.         IF LEN(a$) > 1 THEN ex$ = RIGHT$(a$, LEN(a$) - 1) + ex$
  35.         lex1 = LEN(ex$)
  36.         IF lex1 > 0 THEN PRINT "exclusion list  "; ex$
  37.         IF lex1 = 0 THEN PRINT "exclusion list reset"
  38.         GOTO 200
  39.     END IF
  40.     x1 = LEN(a$)
  41.     z$ = a$
  42.     'z$ original input string
  43.     'a$ input string with 2,3,..replaced by dots
  44.     'b$ test string from word list
  45.     FOR i = 1 TO x1
  46.         IF ASC(MID$(a$, i, 1)) < 56 THEN MID$(a$, i, 1) = "."
  47.     NEXT i
  48.     exq$ = ""
  49.     FOR i = 1 TO x1
  50.         IF MID$(a$, i, 1) <> "." THEN exq$ = exq$ + MID$(a$, i, 1)
  51.     NEXT i
  52.     IF a$ = "end" THEN EXIT DO
  53.     FOR ii = 1 TO 319378
  54.         b$ = word$(ii)
  55.         IF LEN(b$) = x1 THEN
  56.             FOR i = 1 TO x1
  57.                 q1 = MID$(a$, i, 1)
  58.                 IF q1 <> "." THEN
  59.                     q2 = MID$(b$, i, 1)
  60.                     IF q1 <> q2 THEN 20
  61.                 END IF
  62.             NEXT i
  63.             k2 = 0
  64.             FOR i = 1 TO x1
  65.                 q1 = MID$(z$, i, 1)
  66.                 IF q1 = "2" THEN
  67.                     k2 = k2 + 1
  68.                     w2(k2) = MID$(b$, i, 1)
  69.                 END IF
  70.             NEXT i
  71.             k3 = 0
  72.             FOR i = 1 TO x1
  73.                 q1 = MID$(z$, i, 1)
  74.                 IF q1 = "3" THEN
  75.                     k3 = k3 + 1
  76.                     w3(k3) = MID$(b$, i, 1)
  77.                 END IF
  78.             NEXT i
  79.             k4 = 0
  80.             FOR i = 1 TO x1
  81.                 q1 = MID$(z$, i, 1)
  82.                 IF q1 = "4" THEN
  83.                     k4 = k4 + 1
  84.                     w4(k4) = MID$(b$, i, 1)
  85.                 END IF
  86.             NEXT i
  87.             k5 = 0
  88.             FOR i = 1 TO x1
  89.                 q1 = MID$(z$, i, 1)
  90.                 IF q1 = "5" THEN
  91.                     k5 = k5 + 1
  92.                     w5(k5) = MID$(b$, i, 1)
  93.                 END IF
  94.             NEXT i
  95.  
  96.             kdot = 0
  97.             FOR i = 1 TO x1
  98.                 q1 = MID$(z$, i, 1)
  99.                 IF q1 = "." THEN
  100.                     kdot = kdot + 1
  101.                     wdot(kdot) = MID$(b$, i, 1)
  102.                 END IF
  103.             NEXT i
  104.             kndot = 0
  105.             FOR i = 1 TO x1
  106.                 q1 = MID$(z$, i, 1)
  107.                 IF q1 <> "." THEN
  108.                     kndot = kndot + 1
  109.                     wndot(kndot) = MID$(b$, i, 1)
  110.                 END IF
  111.             NEXT i
  112.             kndot1 = 0
  113.             FOR i = 1 TO x1
  114.                 q1 = MID$(a$, i, 1)
  115.                 IF q1 <> "." THEN
  116.                     kndot1 = kndot1 + 1
  117.                     wndot1(kndot1) = MID$(a$, i, 1)
  118.                 END IF
  119.             NEXT i
  120.  
  121.             'PRINT k2; k3; w2$(1): INPUT sa$
  122.             'make sure all dots are different
  123.             IF k2 <> 0 THEN
  124.                 FOR i = 1 TO k2 - 1
  125.                     IF w2(i) <> w2(i + 1) THEN 20
  126.                 NEXT i
  127.             END IF
  128.  
  129.             IF k3 <> 0 THEN
  130.                 FOR i = 1 TO k3 - 1
  131.                     IF w3(i) <> w3(i + 1) THEN 20
  132.                 NEXT i
  133.             END IF
  134.             IF k4 <> 0 THEN
  135.                 FOR i = 1 TO k4 - 1
  136.                     IF w4(i) <> w4(i + 1) THEN 20
  137.                 NEXT i
  138.             END IF
  139.             IF k5 <> 0 THEN
  140.                 FOR i = 1 TO k5 - 1
  141.                     IF w5(i) <> w5(i + 1) THEN 20
  142.                 NEXT i
  143.             END IF
  144.  
  145.             'now checking if any of the dots are the same as inputted letters
  146.             IF kdot <> 0 THEN
  147.                 FOR i = 1 TO kdot - 1
  148.                     FOR j = i + 1 TO kdot
  149.  
  150.                         IF wdot(i) = wdot(j) THEN 20
  151.                     NEXT j
  152.                 NEXT i
  153.             END IF
  154.             FOR i = 1 TO kdot
  155.                 FOR j = 1 TO kndot
  156.  
  157.                     IF wdot(i) = wndot(j) THEN 20
  158.                 NEXT j
  159.             NEXT i
  160.             'now checking for duplicates in repeated letters
  161.             x2 = INSTR(z$, "2")
  162.             x3 = INSTR(z$, "3")
  163.             x4 = INSTR(z$, "4")
  164.             x5 = INSTR(z$, "5")
  165.             IF x3 <> 0 THEN
  166.                 IF MID$(b$, x2, 1) = MID$(b$, x3, 1) THEN 20
  167.             END IF
  168.             IF x4 <> 0 THEN
  169.                 IF MID$(b$, x2, 1) = MID$(b$, x4, 1) THEN 20
  170.                 IF MID$(b$, x3, 1) = MID$(b$, x4, 1) THEN 20
  171.             END IF
  172.             IF k5 <> 0 THEN
  173.                 IF MID$(b$, x2, 1) = MID$(b$, x5, 1) THEN 20
  174.                 IF MID$(b$, x3, 1) = MID$(b$, x5, 1) THEN 20
  175.                 IF MID$(b$, x4, 1) = MID$(b$, x5, 1) THEN 20
  176.  
  177.             END IF
  178.             'now check if any of the given letters are the same as multiples
  179.             IF x2 <> 0 THEN
  180.                 FOR j = 1 TO kndot1
  181.                     IF MID$(b$, x2, 1) = wndot1(j) THEN 20
  182.                 NEXT j
  183.             END IF
  184.             IF x3 <> 0 THEN
  185.                 FOR j = 1 TO kndot1
  186.                     IF MID$(b$, x3, 1) = wndot1(j) THEN 20
  187.                 NEXT j
  188.             END IF
  189.             IF x4 <> 0 THEN
  190.                 FOR j = 1 TO kndot1
  191.                     IF MID$(b$, x4, 1) = wndot1(j) THEN 20
  192.                 NEXT j
  193.             END IF
  194.             IF x5 <> 0 THEN
  195.                 FOR j = 1 TO kndot1
  196.                     IF MID$(b$, x5, 1) = wndot1(j) THEN 20
  197.                 NEXT j
  198.             END IF
  199.  
  200.  
  201.  
  202.             'use exclusion list if loaded
  203.             IF lex1 > 0 THEN
  204.                 FOR ie = 1 TO lex1
  205.                     ex1 = MID$(ex$, ie, 1)
  206.                     IF INSTR(exq$, ex1) = 0 THEN 'lets not remove known letters
  207.                         IF INSTR(b$, ex1) > 0 THEN 20
  208.                     END IF
  209.                 NEXT ie
  210.             END IF
  211.             PRINT b$,
  212.         END IF
  213.    20 NEXT ii
  214.  
  215.     PRINT ""
  216. longform:
  217. p0 = 1: kk = 0
  218. r1$ = ""
  219. r2$ = ""
  220.     kk = kk + 1
  221.     p1 = INSTR(p0, a$, ",")
  222.     IF p1 = 0 THEN
  223.         r1$(kk) = MID$(f$, p0, LEN(f$) - p0 + 1)
  224.         EXIT DO
  225.     END IF
  226.     r1$(kk) = MID$(f$, p0, p1 - p0)
  227.     p0 = p1 + 1
  228. FOR nn = 1 TO kk
  229.     'PRINT r1$(nn); ASC(r1$(nn))
  230. NEXT nn
  231. u1 = 0
  232. FOR ii = 1 TO kk
  233.     IF r1$(ii) = "." THEN 100
  234.     IF LEN(r1$(ii)) = 3 THEN 100
  235.     IF ASC(r1$(ii)) < 58 THEN
  236.         FOR jj = ii + 1 TO kk
  237.             IF r1$(jj) = "." THEN 120
  238.             IF LEN(r1$(jj)) = 3 THEN 120
  239.             IF ASC(r1$(jj)) < 58 THEN
  240.                 'PRINT r1$(ii); r1$(jj), ii; jj; LEN(r1$(jj)): INPUT sa$
  241.                 IF r1$(ii) = r1$(jj) THEN r1$(jj) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1): u2 = 99
  242.             END IF
  243.  
  244.         120 NEXT jj
  245.         IF u2 = 0 THEN r1$(ii) = "."
  246.         IF u2 = 99 THEN
  247.             u2 = 0
  248.             r1$(ii) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1)
  249.             u1 = u1 + 1
  250.         END IF
  251.     END IF
  252. 100 NEXT ii
  253. f$ = ""
  254. FOR ii = 1 TO kk
  255.     IF LEN(r1$(ii)) = 3 THEN r1$(ii) = LEFT$(r1$(ii), 1)
  256.  
  257.     f$ = f$ + r1$(ii)
  258. NEXT ii
  259. a$ = f$
  260. 'PRINT a$, LEN(a$)
  261.  
  262.  
  263. 'why does this get slower after several searches???
  264. 'changing q1$ to string*1 seems to solve it!

5
Programs / Joining the points of regular polygons
« on: February 04, 2020, 07:01:11 pm »
What is the minimum length of lines required to join the points of a regular polygon?
3 (triangle) is fairly easy, but what about a square (or a pentagon)?
As I was going through my old programs I found this (below) to do a triangle (iteratively).
The puzzle is normally phrased as a road building exercise - what is the minimum length of road needed to join four towns which happen to be at the vertices of a square.
So as a challenge can you do the same for 4 towns as I have done for 3. If that is too easy try 5.

Code: QB64: [Select]
  1. nn = 3
  2. rsummin = 10000: m = 1: n = 200
  3. WHILE m < 1000
  4.     x1 = (RND * 360)
  5.     y1 = (RND * 300)
  6.     IF m > 2 THEN
  7.         x1 = xa - n / m + RND * 2 * n / m
  8.         y1 = ya - n / m + RND * 2 * n / m
  9.     END IF
  10.     m = m + .1
  11.     x(1) = 60: y(1) = 300
  12.     x(2) = 360: y(2) = 300
  13.     x(3) = 210: y(3) = 40
  14.     FOR i = 1 TO nn
  15.         r(i) = SQR((x1 - x(i)) ^ 2 + (y1 - y(i)) ^ 2)
  16.     NEXT i
  17.     rsum = r(1) + r(2) + r(3)
  18.     IF rsum < rsummin THEN
  19.         rsummin = rsum
  20.         xa = x1: xb = x2: ya = y1: yb = y2
  21.         m = m + 1
  22.         CLS
  23.         FOR i = 1 TO nn
  24.             CIRCLE (x(i), y(i)), 10
  25.             LINE (x1, y1)-(x(i), y(i))
  26.         NEXT i
  27.         CIRCLE (x1, y1), 5
  28.         LOCATE 1, 1
  29.         q1 = SQR((x(1) - x(3)) ^ 2 + (y(1) - y(3)) ^ 2)
  30.         q2 = SQR((x(2) - x(3)) ^ 2 + (y(2) - y(3)) ^ 2)
  31.         PRINT rsummin * 20 / (q1 + q2)
  32.         tt = TIMER
  33.         WHILE TIMER - tt < .2: WEND
  34.     END IF
  35. LOCATE 3, 1
  36. PRINT "Finished"
  37. xx$ = INPUT$(1)
  38.  

6
QB64 Discussion / Slow string handling
« on: July 15, 2019, 03:29:30 pm »
I've just had a problem with the following program- here is the relevent subroutine.
Code: QB64: [Select]
  1. addr = 32768
  2.     k = k + 1
  3.     IF k > addr THEN EXIT DO
  4.     FOR i = 1 TO 32 STEP 2
  5.         xi = ASC(MID$(x(k), i, 1)) + ASC(MID$(x(k), i + 1, 1)) * 256
  6.         PRINT xi;
  7.     NEXT i
  8.     PRINT k
  9.  

The problem is it takes just over 10 minutes to run on version 1.2 of QB64
On version 0.954 it takes 23 seconds.
That is it is 26x slower on the newer version!
I would have put this in "bugs" but it does not seem I can post there.

7
Programs / Which planet is closest to earth?
« on: March 25, 2019, 10:41:24 am »
https://physicstoday.scitation.org/do/10.1063/PT.6.3.20190312a/full/

I came across this article which claims that on average mercury is actually closest to the earth.
If you analyse the geometry it is actually fairly obvious.
Anyway they made quite a big deal about their calculation so I thought why not try it in QBasic.

Code: QB64: [Select]
  1. pi = 3.141593
  2. rmer = 57
  3. rven = 108 'average distance
  4. re = 150 'from the sun 1000 km
  5. rmar = 228
  6. FOR th = 1 TO 360000 'angle in degrees (1000 years)
  7.     thr = th * (pi / 180)
  8.     a1 = (re - rven * COS(thr)) ^ 2
  9.     a2 = (-rven * SIN(thr)) ^ 2
  10.     d = SQR(a1 + a2)
  11.     dcum = dcum + d
  12.     j = j + 1
  13.     thr1 = thr * 5.044 'synodic period adjustment
  14.     a1 = (re - rmer * COS(thr1)) ^ 2
  15.     a2 = (-rmer * SIN(thr1)) ^ 2
  16.     d1 = SQR(a1 + a2)
  17.     dcum1 = dcum1 + d1
  18.     thr2 = thr * .749 'synodic period adjustment
  19.     a1 = (re - rmar * COS(thr2)) ^ 2
  20.     a2 = (-rmar * SIN(thr2)) ^ 2
  21.     d2 = SQR(a1 + a2)
  22.     dcum2 = dcum2 + d2
  23.     IF d < d1 AND d < d2 THEN v = v + 1
  24.     IF d1 < d AND d1 < d2 THEN m = m + 1
  25.     IF d2 < d1 AND d2 < d THEN mar = mar + 1
  26.  
  27. NEXT th
  28. PRINT "average distances (au)  mercury    venus    mars"
  29. PRINT SPACE$(22); dcum1 / j / re; dcum / j / re; dcum2 / j / re
  30. tot = (m + v + mar) / 100
  31. PRINT "percent of time closest  mercury    venus    mars"
  32. PRINT SPACE$(25); m / tot; v / tot; mar / tot

8
QB64 Discussion / QB64 is getting slower?
« on: August 30, 2018, 12:56:22 pm »
I am transfering data using a serial COM port and the newer versions of qb64 are slow (and cause the data to get corrupted). The new version was downloaded 12 FEB 2018.
My older version QB64 ver0.954 from 2012 is much faster and the data transfer is good (I am working at 9600 baud, but changing this seems to make no difference).

Pages: [1]