Dynamic Value List, and Last Value Containment

Submitted by Mercutio on 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?


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))][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?