Weekend challenge

Geoff Canyon gcanyon at gmail.com
Tue Jul 2 04:42:27 EDT 2013


I'd be very curious to know what the rails code looked like. I've said many times, and I hope the new language features enable this soon, that there are *many* extensions to the LC language that would be equal parts intuitive and useful.

The unique requirement on the  type might be (assuming the data has been processed to 6-item comma-delimited lines):

put the indexes of lines of myList where the count of item 4 of each > 1 into myDupedTypes


For the requirement across the ID, section, and subsection, and type, not counting the type when it dupes its parent subsection, maybe:

put the indexes of lines of myList where item 1 of each is among the items of item 2 to 4 of any into myDupedIDs

Just a thought. 


As one example of what we're missing, consider this implementation of Conway's game of Life in J:

life=: (_3 _3 (+/ e. 3+0,4&{)@,;._3 ])@(0,0,~0,.0,.~])

Granted, that looks like greek, but J is incredibly expressive. Consider what it does in just one line:

1. Pad the array representing the current state of the grid with zeroes all the way around, so 

1,0
1,1

becomes

0,0,0,0
0,1,0,0
0,1,1,0
0,0,0,0

2. Slice that array up into 3x3 sub-arrays, allowing overlaps, so now we have:

0,0,0   0,0,0
0,1,0   1,0,0
0,1,1   1,1,0

0,1,0   1,0,0
0,1,1   1,1,0
0,0,0   0,0,0

3. Sum those arrays to an element in a new array -- 1 if the sum is 3 (dead cell with 3 live neighbors, or live cell with 2 live neighbors) or 4 if the center cell is 1 (live cell with 3 live neighbors). The result is:

1,1
1,1



On Mon, Jul 1, 2013 at 12:46 PM, J. Landman Gay <jacque at hyperactivesw.com> wrote:
> On 7/1/13 12:53 AM, Geoff Canyon wrote:
>> Okay, this is a beast, and in no way good or generalized. It doesn't use
>> the previous function, instead just going through line by line and flagging
>> all the issues it sees in one pass.
> 
> <snip>
> 
> Thanks Geoff, I'll definitely look it over. I actually won't have to use it though because I was excused from the exercise, the server is doing it instead. But it bugged me that I couldn't write a nice, neat handler to do it.
> 
> The backstory: The client wanted a data verification check performed on both the server and in the LiveCode stacks. I spent a weekend toiling over this, I probably wrote six or eight different versions using different methods. I never did produce anything neat and compact, so the next Monday I asked the server person how they did it. They replied with a four or five line algorithm which was very close to one of my initial attempts, but they didn't have to do any duplicate checking. Apparently there's a way in Rails to do that easily. They were bouncing arrays around. A couple of my attempts used arrays but looping through all the sub-keys wasn't any easier than just looping through the list.
> 
> I was feeling kind of miffed that they were able to produce a workable script in a couple of hours and I'd been messing with it for days. Fortunately the client said never mind, they would just use the one on the server, and that I should move on to other things.
> 
> I was not disappointed, but it did leave me feeling kind of stupid (and a little defensive about LiveCode.) I was relieved that no one here jumped in to say "oh, just do this". But I still wonder if I was missing some cool trick.
> 
> 
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list