| using the haversine formula as a subroutine with parameters and return value
| when subroutine precedes first executable instruction, start LABEL must be used

lat1 : 0.0
lon1 : 0.0
lat2 : 0.0
lon2 : 0.0

dx : 0.
dy : 0.
dz : 0.

kms : 0.
k : 0.

haversine param lat1 lon1 lat2 lon2

  {degtorad(lon2 - lon1)} lon1
  {degtorad lat1} lat1
  {degtorad lat2} lat2

  {sin lat1 - sin lat2} dz
  {cos lon1 * cos lat1 - cos lat2} dx
  {sin lon1 * cos lat1} dy

  {arcsin(sqrt(dx^2 + dy^2 + dz^2)/2) * 12745.6} kms

  return kms

start

  call haversine 36.12 -86.67 33.94 -118.4
  result k

  "'Haversine distance: ' k ' kilometers'" []




| Find all Munchausen numbers between 1 and 5000

x : 10 1
 
 (2^2) x.2
 (3^3) x.3
 (4^4) x.4
 (5^5) x.5
 (6^6) x.6
 (7^7) x.7
 (8^8) x.8
 (9^9) x.9

 1 i
 if i <= 5000
    ~ i $i          | convert binary to string
    #$i j           | length to j
    y               | set y to 0
    if j > 0
       $i.j $j 1    | move digit j to string j
       ~ $j n       | convert j string to binary
       + x.n y      | add value x at n to y
       - j          | dec j
       goif
    endif
    if i = y
       i []         | output to console
    endif
    + i
    goif
 endif
 




|  the prog (T1) will cause 99 progs to run in SSX
           
    symsyn 'R T1'        | command to Symsyn to run T1
loop
    delay 100            | sleep for 100 milliseconds
    go loop 



| the square root of the sum of the squares


x : 2 0                   | array (vector) x ( 2 members each a value of 0 )
 3 x.0                    | first member = 3
 4 x.1                    | second member = 4
 vmul x x x               | multiply each member of array x by same in x, store in x
 vsum x y                 | add all the members of array x place total in word y
 sqrt y z                 | square root of y in z (rounded) = 5




| DES encryption

key :  x'0e329232ea6d0d73'
data : x'8787878787878787'

 edes key data             | encrypt data with key 
 data $s                   | move data to string
 unpackhex $s $s           | unpack
 $s []                     | output result - 0000000000000000



| quick sort

x : 23 : 15 : 99 : 146 : 3 : 66 : 71 : 5 : 23 : 73 : 19

quicksort param l r

   l i
   r j
   ((l+r) shr 1) k
   x.k pivot

repeat
   if pivot > x.i
      + i
      goif
   endif

   if pivot < x.j
      - j
      goif
   endif

   if i <= j
      swap x.i x.j
      - j
      + i
   endif

   if i <= j
      go repeat
   endif

   if l < j
      save l r i j
      call quicksort l j
      restore l r i j
   endif
 
   if i < r
      save l r i j
      call quicksort i r
      restore l r i j
   endif

   return

start

 ' original values : ' $r

 call showvalues

 call quicksort 0 10

 ' sorted values : ' $r

 call showvalues

 stop

showvalues
 $s
 i
 if i <= 10
    "$s ' ' x.i ' '" $s
    + i
    goif
 endif
 " $r $s " []
 return