Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Interleaving strings -How?

 [1/5] from: webdev:accglobal at: 21-Sep-2000 23:30


This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C02423.F20764C0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Dear "Fellow Rebol Rousers", After having read the docs I have not quite figured out how to accomplish the interleaving of strings. The short and the long of what I want to do is take latitude and longitude coordinate pairs and interleave them with each other. The rational behind this is to place objects that are physically close to each other in the real world close together in computer memory, which we all know is linear and not spherical like the earth. The coordinates are in decimal degrees for the sake of easy manipulation. The max longitude is 180 degrees while the max latitude is 90. Ignore the issue of positive/negative values as indications of north/south east/west locations. The first segment of the numbers would be interleaved on the basis of the non decimal portion of their values (1st three positions assuming required zero padding). The balance of the values would be interleaved on each subsequent pair. As an example: latitude value : 043.6732452849 longitude value: 142.8321724625 interleaved value: 043142 6783 3221 4572 2846 4925 (spaces are only for readability/illustration) The non decimal portion must be padded with a zero for all latitude values (they never exceed 90). For longitude the non decimal portion must be padded with zero if the value is <100. I understand that I must convert the numbers to rebol strings to access the necessary functionality required to step through the "number" and pluck out the required portion. My problem: At bare minimum I need to understand the command syntax for stepping and clipping the string at specific points as well as the method for specifying the length of the clipped portion. Any inspiration would be most appreciated. Thanks in advance, [webdev--accglobal--net] ------=_NextPart_000_0009_01C02423.F20764C0 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content="text/html; charset=windows-1252" http-equiv=Content-Type> <META content="MSHTML 5.00.2314.1000" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Dear "Fellow Rebol Rousers",</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>After having read the docs I have not quite figured out how to accomplish the interleaving of strings.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>The short and the long of what I want to do is take latitude and longitude coordinate pairs and interleave them with each other.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>The rational behind this is to place objects that are physically close to each other in the real world close together in computer memory, which we all know is linear and not spherical like the earth. </FONT><FONT face=Arial size=2>The coordinates are in decimal degrees for the sake of easy manipulation.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>The max longitude is 180 degrees while the max latitude is 90.<BR>Ignore the issue of positive/negative values as indications of north/south east/west locations.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>The first segment of the numbers would be interleaved on the basis of the non decimal portion of their values (1st three positions assuming required zero padding).<BR>The balance of the values would be interleaved on each subsequent pair.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>As an example:</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>latitude value :&nbsp;&nbsp; 043.6732452849<BR>longitude value:&nbsp;&nbsp; 142.8321724625</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>interleaved value: 043142 6783 3221 4572 2846 4925<BR>(spaces are only for readability/illustration)</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>The non decimal portion must be padded with a zero for all latitude values (they never exceed 90).<BR>For longitude the non decimal portion must be padded with zero if the value is <100.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>I understand that I must convert the numbers to rebol strings to access the necessary functionality required to step through the number and pluck out the required portion.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>My problem:</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>At bare minimum I need to understand the command syntax for stepping and clipping the string at specific points as well as the method for specifying the length of the clipped portion.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2><BR>Any inspiration would be most appreciated.</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2>Thanks in advance,</FONT></DIV> <DIV>&nbsp;</DIV> <DIV><FONT face=Arial size=2><A href="mailto:[webdev--accglobal--net]">[webdev--accglobal--net]</A></FONT></DIV
></BODY></HTML>
------=_NextPart_000_0009_01C02423.F20764C0--

 [2/5] from: rebol:techscribe at: 21-Sep-2000 21:45


Hi Webdev,
>At bare minimum I need to understand the command >syntax for stepping and clipping >the string at specific points as well as the >method for specifying the length of >the clipped portion.
This should get you started skip
>> string: "0123456789"
== "0123456789"
>> string: skip string 3
== "3456789"
>> string
== "3456789"
>> head string
== "0123456789"
>> string: head string
== "0123456789"
>> string
== "0123456789"
>> string skip tail string -3
== "789" at
>> string: at string 3
== "23456789"
>> string
== "23456789"
>> string: head string
== "0123456789" back
>> string back tail string
== "9" next
>> string: next string
== "123456789"
>> string: head string
== "0123456789" copy/part
>> partial-string: copy/part string 3
== "012"
>> partial-string
== "012"
>> partial-string: copy/part skip string 3 2
== "34"
>> partial-string
== "34" Creating a string from an integer
>> string: form 1234
== "1234"
>> string
== "1234" Another way to do it
>> string: ""
== ""
>> insert string 1
== ""
>> append string 2
== "12" picking and poking
>> string
== "12"
>> pick string 1
== #"1"
>> pick string 2
== #"2"
>> poke string 2 #"X"
== "1X" Hope this helps At 11:30 PM 9/21/00 -0400, you wrote:
> Dear "Fellow Rebol Rousers", After having read the docs I have not >quite figured out how to accomplish the interleaving of strings. The
<<quoted lines omitted: 22>>
>Any inspiration would be most appreciated. Thanks in advance, >[webdev--accglobal--net]
;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com

 [3/5] from: al:bri:xtra at: 22-Sep-2000 19:39


[webdev--accglobal--net] wrote:
> The short and the long of what I want to do is take latitude and longitude
coordinate pairs and interleave them with each other.
> The rational behind this is to place objects that are physically close to
each other in the real world close together in computer memory, which we all know is linear and not spherical like the earth. The coordinates are in decimal degrees for the sake of easy manipulation.
> As an example: > latitude value : 043.6732452849 > longitude value: 142.8321724625 > interleaved value: 043142 6783 3221 4572 2846 4925 > (spaces are only for readability/illustration)
Purely out of curiosity, could you describe the software around this scheme? How does it manipulate these shuffled coordinates to work out how things are close together? Andrew Martin ICQ: 26227169 http://members.ncbi.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/

 [4/5] from: webdev:accglobal at: 22-Sep-2000 12:10


Dear Andrew, At present there is no software (at least not in my possession). It is currently "dreamware". The question is whether Rebol can do it in a scalable distributed fashion.Terra Server uses this method to store locations in their database. It is called a "Z" transform. There is no loss of information during the transform. The transform actually introduces an ordering pattern that mimics physical proximity when values are sorted sequentially. Depending upon the resolution of the numbers you will see a pattern of sequential blocks that start at 1deg. x 1deg and nest themselves at .1, .01, .001, 0001, .00001, etc. resolutions depending upon how many pairs are in the interleaved value. If all the values in the database were to have five interleaved pairs to the right of the decimal they would have an effective resolution of 5 decimal places or .00001 of 1deg which is approx. 1/10000 of 110.57km or 11.057 meters. If you have one less pair in the resolution then the interleaved value will appear at the beginning of the next higher block and so on up. Think of them as basins of attraction. Anything at that resolution and a specific value will be drawn to that position in the linear series of all values. More resolution means smaller basins of attraction within larger ones. It is basically a compression method that takes multiple dimensions and compresses them into fewer dimensions (many multiple strings become single strings within a larger string). The first transformation was from 3 to 2 dimensions. We went from a position on a sphere (3 dimensional object) to a two dimensional description in the form of lat long coordinates. The next transformation went from 2 to 1 when we performed the "Z" transform and descended to one dimension in the form of a value in a line (computer memory is linear). Tell me if this starting to look a lot like a strand of DNA. Enzymes are to DNA the same way various parsing routines are to various strings. They serve to extract information based on position and content. In summary have a three dimensional (there might be more) "organism" defined in one dimension (a string). You can in essence have any level of resolution from 110.57 km down to 1 meter or less. Objects that are large need less precision and can be stored with a shorter string. Although they have less precision they will still be located in the data file with points that are close by in the "real" world. (Numbers are short for clarity) Notice the ordering 33, 33.5689, 33.57, 33.58, 33.583, 33.584 34, 34.5, 34.56, 34.562, 35, 36, The marks illustrate the lowest resolution boundries. The ordering of points follows a regular pattern. Where there is no data (spelled no data or less granularity) the pattern just turns into a void and requires no effort to maintain. The traversal of the locations actually follows a nesting zig zag pattern somewhat like the scan lines of wall of individual monitors depicting a larger scene except if there is no data then the scan jumps to the next block which can be at any resolution. Navigation can easily be accomplished by jumping to the next level (lower resolution) by trimming the last pair of numbers from our "Z" transform value and then walking the line by specific increments. Arrays within arrays in the easiest way to visualize it. Only when we find the point of interest do we need to reverse the transformation or do a lookup to find its' actual location coordinates in traditional lat long format. That's it in a nutshell. I hope I have made this somewhat clear despite its' ad hoc nature. Gotta fly... Jim

 [5/5] from: al:bri:xtra at: 24-Sep-2000 11:47


> After having read the docs I have not quite figured out how to accomplish
the interleaving of strings.
> The short and the long of what I want to do is take latitude and longitude
coordinate pairs and interleave them with each other. Try this QaD: [ Rebol [] Pad: function [Degree [decimal!]] [String] [ Degree: abs Degree String: to string! Degree if Degree < 10 [String: join "0" String] if Degree < 100 [String: join "0" String] if not found? find String "." [append String "."] String ] Interleave: function [Latitude [decimal!] Longitude [decimal!]] [String] [ Latitude: Pad Latitude Longitude: Pad Longitude while [< length? Latitude length? Longitude] [ Latitude: join Latitude "0" ] while [> length? Latitude length? Longitude] [ Longitude: join Longitude "0" ] String: rejoin [ copy/part Latitude 3 copy/part Longitude 3 ] for Index 5 length? Latitude 2 [ append String copy/part at Latitude Index 2 append String copy/part at Longitude Index 2 ] String ] Latitude: 043.6732452849 Longitude: 142.8321724625 print Interleave Latitude Longitude ]
>> do %LatLong.r
04314267833221457228464925 Such a nice explanation deserved a nice reward. Andrew Martin ICQ: 26227169 http://members.ncbi.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted