1. Too complex!!!!!!!!!
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> Jun 09, 1997
- 812 views
I created this code. It works great. BUT I can't figure out how to undo it. I have designed some code that will convert any sequence Multi-Dimensional or not into a single dimension sequence. This sequence will be easier to save to a file. Compressing these sequences should be easier. My problem is that I have figured out how to design a function to Recreate the original sequences from these Single dimension sequences. DON'T LAUGH at the size of it. It took me 6 hours to come up with this perfect design. I threw away several failed attempts at this. I would also appreciate a good name for this function. I presently call it Flatten. This doesn't exactly sound right though. The function does recursive calls. So if you rename it you must rename where it calls itself for it to work. HERE is the Function. ------------------------------------- -- Created by Lucius L. Hilley III -- -- Co-Creator of Hollow Horse Soft -- -- 06-09-1997 -- ------------------------------------- function Flatten(sequence s) sequence temp sequence sh sh = {length(s)} for a = 1 to sh[1] do if sequence(s[a]) then temp = Flatten(s[a]) sh = sh & temp else sh = sh & {-1, s[a]} end if end for return sh end function --This one of my Vain attempts --function DeFlatten(sequence s) -- atom a, p -- sequence temp -- -- a = 2 -- p = 1 -- temp = repeat({}, s[1]) -- while a <= length(s) do -- if s[a] = -1 then -- a = a + 1 -- temp[p] = s[a] -- p = p + 1 -- else -- temp[p] = repeat({}, s[a]) -- end if -- a = a + 1 -- end while -- return temp --end function -- This should give a pretty good demonstration. -- The first value is length of main sequence. -- If first value is 0 then it is an empty sequence. -- If not then if second value is 0 you have an -- empty sequence for your first value inside the -- sequence. -- A -1 value indicates that an atom follows. -- All values are lengths or -1 for atom -- and an atom follows all -1's. sequence x x = {} ? x ? Flatten(x) x = {{}} ? x ? Flatten(x) x = {5} ? x ? Flatten(x) x = {{5}} ? x ? Flatten(x) x = {1,2} ? x ? Flatten(x) x = {{},{}} ? x ? Flatten(x) x = {9,{8},7,{},6} ? x ? Flatten(x) x = {{{9}},8,7,{6}} ? x ? Flatten(x) ------------------------------------- --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 60K. -- I can Decode both UU and Base64 format.
2. Re: Too complex!!!!!!!!!
- Posted by Marcel Kollenaar <M.Kollenaar at SLO.NL> Jun 09, 1997
- 790 views
Hello Lucius, > BUT I can't figure out how to undo it. What do you mean with 'undo'. > I would also appreciate a good name > for this function. I presently call > it Flatten. This doesn't exactly sound What do you think of "Stretcher". MK
3. Re: Too complex!!!!!!!!!
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> Jun 09, 1997
- 801 views
On Mon, 9 Jun 1997 15:59:16 +0100 Marcel Kollenaar <M.Kollenaar at SLO.NL> writes: >---------------------- Information from the mail header > >Hello Lucius, > >> BUT I can't figure out how to undo it. > >What do you mean with 'undo'. I wrote the function so that sequences would be eaiser to write to a file. Then I could retrieve them from the file. BUT I need to be able to reconstruct the original sequences. This function creates a sequence that contains all the required information for recreating the Original sequence. I just haven't figured out how to the use the information to recreate it. >> I would also appreciate a good name >> for this function. I presently call >> it Flatten. > >What do you think of "Stretcher". Sounds good. >MK >
4. Re: Too complex!!!!!!!!!
- Posted by Jacques Deschenes <desja at QUEBECTEL.COM> Jun 09, 1997
- 803 views
hi Lucius, I found a solution to your deflatten problem. It work on every sample I tested. function DeFlatten(sequence s) integer i, l sequence d, stack if length(s) < 2 then return {} end if d = {} stack = {} i = 1 l = 0 while i <= length(s) do if s[i] > 0 then if l > 0 then stack = append(stack,{l,d}) end if l = s[i] d = {} i = i + 1 elsif s[i] = 0 then if l > 0 then d = append(d,{}) end if i = i + 1 else d = d & s[i+1] i = i + 2 end if while length(d) = l and length(stack) do d = append(stack[length(stack)][2],d) l = stack[length(stack)][1] stack = stack[1..length(stack)-1] end while end while if length(stack) then for j = length(stack) to 1 by -1 do d = append(stack[j][2],d) end for end if return d end function -- DeFlatten() Jacques Deschenes Baie-Comeau, Quebec Canada desja at quebectel.com
5. Re: Too complex!!!!!!!!!
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> Jun 09, 1997
- 814 views
- Last edited Jun 10, 1997
I found a solution to your deflatten problem. It work on every sample I tested. My sincerest thanks. --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 60K. -- I can Decode both UU and Base64 format.
6. Re: Too complex!!!!!!!!!
- Posted by Marcel Kollenaar <M.Kollenaar at SLO.NL> Jun 10, 1997
- 788 views
Lucius wrote: > I wrote the function so that sequences would be > eaiser to write to a file. > > Then I could retrieve them from the file. > BUT I need to be able to reconstruct the > original sequences. You lose the structure after converting and need meta information (=information about Information). > This function creates a sequence that contains > all the required information for recreating {{structure info},{structure data}} > the Original sequence. I just haven't figured > out how to the use the information to recreate > it. I think you have to keep track of the type you are converting, the structure size and the nesting depth of the structure. Maybe is recursive behavour not the solution. Use a stack (sequence) where you keep your information of how deep, how much and type. If I'm wrong correct me, it's for me a test if I understand your problem. I imagine it as a database. You can store the data but you need information were to start and end and what kind information you are reading. This is always put in the header of a database file. MK
7. Re: Too complex!!!!!!!!!
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> Jun 10, 1997
- 813 views
Marcel Kollenaar, Check out Jacques DeFlatten(). If you missed it I will repost both routines Flatten() created by me, Lucius AND DeFlatten() created by Jacques I created Flatten and as I and Jacques can tell you. It contains ALL the needed information for reconstruction of the sequence. I even provided details as how the information was being stored. Many Thanks to Jacques for figuring out how to create DeFlatten. I had such a headache with Flatten that I had NO Idea how to go about making it's counterpart. Kind of like creating Encrytion without knowing how to create its Decryptor. I knew how to do it mentally but hadn't a clue computer logically. Thanks again Jacques. --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 60K. -- I can Decode both UU and Base64 format.
8. Re: Too complex!!!!!!!!!
- Posted by Joseph Martin <jam at MAILHUB.EXIS.NET> Jun 10, 1997
- 811 views
> Check out Jacques DeFlatten(). > If you missed it I will repost both routines > > Flatten() created by me, Lucius AND > DeFlatten() created by Jacques Please put both on the FTP site. I seem to have lost the messages... ~~>Joseph Martin ~~>E-mail: joe at cyber-wizard.com ~~>URL: http://users.exis.net/~jam/
9. Re: Too complex!!!!!!!!!
- Posted by "Carl R. White" Jun 11, 1997
- 799 views
On Mon, 9 Jun 1997, Lucius L Hilley III wrote: > I created this code. > It works great. > BUT I can't figure out how to undo it. [Space save snip] > HERE is the Function. [Space save snip] > function Flatten(sequence s) > sequence temp > sequence sh > > sh = {length(s)} > for a = 1 to sh[1] do > if sequence(s[a]) then > temp = Flatten(s[a]) > sh = sh & temp > else > sh = sh & {-1, s[a]} > end if > end for > return sh > end function > > --This one of my Vain attempts > --function DeFlatten(sequence s) > -- atom a, p > -- sequence temp > -- > -- a = 2 > -- p = 1 > -- temp = repeat({}, s[1]) > -- while a <= length(s) do > -- if s[a] = -1 then > -- a = a + 1 > -- temp[p] = s[a] > -- p = p + 1 > -- else > -- temp[p] = repeat({}, s[a]) > -- end if > -- a = a + 1 > -- end while > -- return temp > --end function I don't think it *can* be undone, because both {{4}, 5 , {6, 7} ,8} and {4, {5, 6, 7}, 8} compact to {4, 5, 6, 7, 8} . How do you know which one was the original, when it's blatantly obvious they both were (and several other possible combinations too)? It's like saying sqrt(9) = 3 (which is what the function returns) but (-3) * (-3) = 9, so how do you know what created the 9 in the first place? Was it 3 or -3? Sorry to burst the bubble... -- Carl R White | e-mail...: crwhite- at -comp.brad.ac.uk | finger...: crwhite- at -dcsun1.comp.brad.ac.uk | web......: http://www.student.comp.brad.ac.uk/~crwhite/ Anti-Spam and Uncle-Pek measures in place & .sig fixed too...