Dynamic Value List, and Last Value Containment

Dynamic Value List, and Last Value Containment Mercutio Fri, 2010-10-01 14:41

I pose you a problem:

Input:  foo:1 bar:2 zen:2 foo:44 meow:cat bar:meow
Output: foo:44 zen:2 meow:cat bar:meow (in any order)

Basically, unique and last-value matches for key:value.
Then I made it a tad harder, and demanded that the delimiter was chr(160) (Non-breaking space)

So... what ways can this be solved?

Mike:

setq(0,revwords(%0,chr(160)),1,regeditall(sort(%0,chr(160)),(\\w+):\\w+( \\1:\\w+)*,$1))[squish(iter(%q1,grab(%q0,%i0:*,chr(160)),chr(160),%r),%r)]

setq(X,chr(160))[iter(squish(fold(#lambda/if(match(\%0,first(\%1,:):*,%qX),,\%1)%qX\%0,revwords(%0,%qX),,%qX),%qX),%i0,%qX,%r)]

Mercutio:

iter(setunion(iter(setr(1,%0),first(%i0,:),chr(160)),),grab(revwords(%q1,chr(160)),%i0:*,chr(160)),,%r)

Javelin:

[setq(x,chr(160))][squish([iter(reverse(%0,%qx),if(member(%q1,after(%i0,:)),,setq(1,%q1 [after(%i0,:)],0,%q0 %i0)),%qx,%qx)][reverse(%q0)])] 

Trinsec: (doesn't handle [chr(160)] )

[If( Words(%0),   SetQ(A, MatchAll(%0,[First(First(%0),:)]:*) )   [SetQ(L,%qL [Elements(%0,Last(%qA))])]   [U(%#/LIST`TRINSEC, LDelete(%0,%qA) )]   ,   %qL)] 

As you can tell, many solutions to one problem. I think it'd be interesting to have some kind of weekly problem - that people can comment on with solutions to the problem.

How would you do this?