Re: Code War: Quick Structure Check
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> May 16, 2000
- 555 views
> It's possible that the 'if not length(...' line is missing from your > code, You are correct. I intentionally removed it for my more flexible purposes. I was unaware the not length line was preventing negative dimensions. > > On a lighter note, a fun question: What's the dimension of this sequence: > > {{1,2,3},{{4,4},5,6}} ^------^ ^---^ ^--^ 2D 3D 2D It doesn't fit any one dimension setting. With your definition of equal_dimension(). equal_dimension(3,{}) is 0. When I altered your equal_dimension() I renamed it as well. REASON: your code correctly defines equal dimension. Your code answers the question. Is the dimension of {} equal to 3 The answer is no. The dimension of {} is 1. I wanted to ask the question. Is the data given suitable? suitable(3, {})-- the answer is yes. If I want 3 dimensions out of {} I can easily bloat it to. {{{}}} No data is lost in the bloating so the data is Suitable. Of course suitable(3, {1}) is false. You can't expand that data into 3 dimensions and not Corrupt the data. The data simply doesn't properly fit the dimensional design set forth. Let me elaborate even more. sequence format object exact_dim format = {5, 10} exact_dim = 0 for A = length(format) to 1 by -1 do exact_dim = repeat(exact_dim,format[A]) end for --exact_dim now looks like this. --{{0,0,0,0,0,0,0,0,0,0}, -- {0,0,0,0,0,0,0,0,0,0}, -- {0,0,0,0,0,0,0,0,0,0}, -- {0,0,0,0,0,0,0,0,0,0}, -- {0,0,0,0,0,0,0,0,0,0} --} exact_dim is a perfect 2D sequence. {"Lucius", "Lamar", "Hilley", "III", "123456789abc"} -- is suitable data to this format. However, it doesn't perfectly fit. It can be expanded to {{'L','u','c','i','u','s',0,0,0,0}, {'L','a','m','a','r',0,0,0,0,0}, {'I','I','I',0,0,0,0,0,0,0}, {'1','2','3','4','5','6','7','8','9','a'}, --some of this was truncated to fit. {0,0,0,0,0,0,0,0,0,0} } equal_dimension would have handled this without any problems. But it wouldn't take care of this. {} -- Your code realizes this is only 1 dimension. My code realizes that it is suitable. Then more of my code is able to fix it to look like the exact_dim defined above. > > For extra credit, use your answer to tell me why equal_dimension() is > implemented in the way that it is. I guess I don't get extra credit. Lucius L. Hilley III lhilley at cdc.net +----------+--------------+--------------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | | Horse +--------------+--------------+ | Software | http://www.cdc.net/~lhilley | +----------+-----------------------------+ ----- Original Message ----- From: "Carl R. White" <cyrek at BIGFOOT.COM> To: "Removing Subscription" <EUPHORIA at LISTSERV.MUOHIO.EDU> <--- very interesting. Cc: "Carl R. White" <cyrek at BIGFOOT.COM> Sent: Tuesday, May 16, 2000 6:57 AM Subject: Re: Code War: Quick Structure Check <SNIP> > > Lucius said (more or less): > > equal_dimension() fails on {{{}}}. It accepts it as 1 dimensional rather > > than 3. Changing the 'return 1' line to 'return (dimension > 0)' should > > fix it. > > I tried this on my computer here at work and equal_dimension(3, {{{}}}) > returns '1', and '0' when dimension is not 3. It's possible that the 'if > not length(...' line is missing from your code, as this would cause > the 'for' loop to fall straight through to the 'return 1' when the sequence > is empty, causing the problem. > > > ...(dimension > 0)... > <SNIP> > > Carl > > -- > I think my .sig ran away. >