Raspberry BASIC

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 - AIR

Pages: [1]
1
Programming Challenges / SALC Ubuntu 64
« on: December 15, 2019, 08:16:57 am »
I reworked the FreeBasic submission, and ran it on my Ubuntu PI4:

Code: FreeBasic
  1. ' FreeBasic - 1mil3.bas
  2.  
  3. DIM SHARED a(1000001) AS INTEGER
  4.  
  5. function Reverse( byref source as string ) as string
  6.     dim as integer first = 0, last = Len(source)-1
  7.  
  8.     while( first < last )
  9.         Swap source[first], source[last]
  10.         first += 1 : last -= 1
  11.     wend
  12.  
  13.     return source
  14. end function
  15.  
  16. sub mil()
  17.     dim as string s,t,r
  18.     dim as integer x,c
  19.  
  20.     FOR x = 1 TO 1000000
  21.         c = (x - 1) MOD 26
  22.         s &= CHR(c + 65)
  23.         a(x) = x
  24.         IF c = 25 THEN
  25.             t &= s
  26.             s = ""
  27.             c = 0
  28.         ENDIF
  29.     NEXT
  30.  
  31.     r = Reverse(t)
  32.  
  33.     PRINT "r LEN: " & LEN(r)
  34.     PRINT "Front: " & LEFT(r, 26)
  35.     PRINT "Back:  " & RIGHT(r, 26)
  36.     PRINT "UBVal: " & a(1000000)
  37. end sub
  38.  
  39.  
  40. mil()
  41.  

riveraa@dpi:~/tmp$ timex ./1mil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.16user 0.02system 0:00.18elapsed 98%CPU (0avgtext+0avgdata 11596maxresident)k
0inputs+0outputs (0major+2623minor)pagefaults 0swaps


AIR.

EDIT:  Cleaned up code.

Pages: [1]