JOIN 2004 - Day 2

cog on 2004-04-20T16:14:53

I'm a little tired today, as I haven't slept much lately...

Marty, Kiko and Simon gave great talks. I'm glad we decided to do this... and I hope we'll do more and better as the years go by :-)

Meanwhile, I left Marty at the airport with the challenge of writing a program in the least amount of characters. If you care to give it a try,

Input: root:admins administrator:admins me:users

Output: admins: root, administrator users: me

I'll let you figure it out by yourselves :-)


Will this do?

claes on 2004-04-20T20:40:46

$"=", ",print"$_: @$_\n"for grep{!$d{$_}&&do{$d{$_}=1}}map{/(\w+):(\w+)/&&push@$2=>$1;$2; };

just pipe the input to the program.... I assume someone has a shorter way.

Re:Will this do? ( got lost in HTML hell)

claes on 2004-04-20T20:43:21

$"=", ",print"$_: @$_\n"for grep{!$d{$_}&&do{$d{$_}=1}}map{/(\w+):(\w+)/&&push@$2=>$1;$2; }<>;

An even shorter one (84 chars)

claes on 2004-04-21T09:55:22

$"=", ",print"$_: @$_\n"for grep{!$$_&($$_=1)}map{/(\w+):(\w+)/&&push@$2,$1;$2;}<>;

Re:An even shorter one (84 chars)

cog on 2004-04-21T11:21:05

You haven't beaten me yet ;-)

I'm thinking about proposing a talk for YAPC::Europe on this subject :-)

Re:An even shorter one (84 chars)

claes on 2004-04-21T13:30:32

print "admins: root, administrator\nusers: me\n";



That is shorter and still a valid solution. However, if it should handle any number of <user>:<group> lines it wouldn't count.. right?



Care to post your solution?

65 chars

cog on 2004-04-21T16:09:52

#!/usr/bin/perl -l0n
/:/;$_{$'.$&}.=" $`,"}{map{s/,$/
/;print}%_

Maybe I could propose a talk about this for YAPC::Europe (a talk on the several stuff I use here, that is)... I think I will...

Oh, but I'm sure some of the guys can work out a way of saving some more characters ;-)

Re:65 chars (I'm now at 72)

claes on 2004-04-21T17:03:35

That's a nice one. To make it trickier, make it preserve the order of the group it finds.
$"=", ";print"$_: @$_\n"for grep{$$_++<1}map{/:(.+)/&push@$1,$`;$1;}<>;

Re:65 chars (I'm now at 67)

claes on 2004-04-21T17:26:56

$"=", ";!$$_++&&print"$_: @$_\n"for map{/:(.+)/&push@$1,$`;$1;}<>;