Too complex!!!!!!!!!
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> Jun 09, 1997
- 708 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.