<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Partitioning Sets in Ruby</title>
	<atom:link href="http://www.rubyrailways.com/partitioning-sets-in-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/</link>
	<description>Experiences with Ruby and Rails, Web2.0 and other development technologies</description>
	<pubDate>Sat, 31 Jul 2010 08:01:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: grnch</title>
		<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/comment-page-1/#comment-40300</link>
		<dc:creator>grnch</dc:creator>
		<pubDate>Sun, 11 May 2008 14:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyrailways.com/partitioning-sets-in-ruby/#comment-40300</guid>
		<description>&lt;p&gt;Come on, you can do better than that :)&lt;/p&gt;

&lt;p&gt;There is a method Set.classify, related to Set.divide, which gets you closer to your goal:&lt;/p&gt;

&lt;p&gt;require 'set'
input = Set.new open('input.txt').readlines.map{&#124;line&#124; line.chomp.split}
groups = input.classify {&#124;e&#124; e.shift}
result = groups.map {&#124;k,v&#124; {k =&#62; v.to&lt;em&gt;a.flatten.inject(0) {&#124;sum, x&#124; sum+x.to&lt;/em&gt;i}}}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Come on, you can do better than that <img src='http://www.rubyrailways.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There is a method Set.classify, related to Set.divide, which gets you closer to your goal:</p>
<p>require &#8217;set&#8217;<br />
input = Set.new open(&#8217;input.txt&#8217;).readlines.map{|line| line.chomp.split}<br />
groups = input.classify {|e| e.shift}<br />
result = groups.map {|k,v| {k =&gt; v.to<em>a.flatten.inject(0) {|sum, x| sum+x.to</em>i}}}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/comment-page-1/#comment-8572</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 29 Apr 2007 13:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyrailways.com/partitioning-sets-in-ruby/#comment-8572</guid>
		<description>&lt;p&gt;Well, the original idea was to show how Set.divide works... Admiring my just found shiny new hammer, I guess this problem pretty much looked like a big nail :-)&lt;/p&gt;

&lt;p&gt;Thanks for the solution, Aur.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Well, the original idea was to show how Set.divide works&#8230; Admiring my just found shiny new hammer, I guess this problem pretty much looked like a big nail <img src='http://www.rubyrailways.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Thanks for the solution, Aur.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SonOfLilit</title>
		<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/comment-page-1/#comment-8567</link>
		<dc:creator>SonOfLilit</dc:creator>
		<pubDate>Sun, 29 Apr 2007 13:16:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyrailways.com/partitioning-sets-in-ruby/#comment-8567</guid>
		<description>&lt;p&gt;So why complicate it with divide?&lt;/p&gt;

&lt;p&gt;Why not:&lt;/p&gt;

&lt;p&gt;#&lt;/p&gt;

&lt;p&gt;h = {}
open('input.txt').each&lt;em&gt;line{&#124;l&#124;
  h[l[0..0]] +=
    l[2..-1].split(‘ ‘).inject(0) {&#124;c,x&#124; c+=x.to&lt;/em&gt;i; c}}
}
p h.to_a.map{&#124;k,v&#124; {k =&#62; v}&lt;/p&gt;

&lt;p&gt;#&lt;/p&gt;

&lt;p&gt;?&lt;/p&gt;

&lt;p&gt;It would also remove the same-line weakness.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>So why complicate it with divide?</p>
<p>Why not:</p>
<p>#</p>
<p>h = {}<br />
open(&#8217;input.txt&#8217;).each<em>line{|l|<br />
  h[l[0..0]] +=<br />
    l[2..-1].split(‘ ‘).inject(0) {|c,x| c+=x.to</em>i; c}}<br />
}<br />
p h.to_a.map{|k,v| {k =&gt; v}</p>
<p>#</p>
<p>?</p>
<p>It would also remove the same-line weakness.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/comment-page-1/#comment-8548</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 29 Apr 2007 11:50:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyrailways.com/partitioning-sets-in-ruby/#comment-8548</guid>
		<description>&lt;p&gt;Ben,&lt;/p&gt;

&lt;p&gt;theoretically that could happen -  there is absolutely no guarantee that two rows will be different. 
Well... it seems even &lt;i&gt;divide&lt;/i&gt; is not perfect (it could do the partitioning into a Hash, where the value set would be the number of occurrences of the sets or something) - or maybe this is possible somehow? 
Going to check it...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ben,</p>
<p>theoretically that could happen -  there is absolutely no guarantee that two rows will be different.<br />
Well&#8230; it seems even <i>divide</i> is not perfect (it could do the partitioning into a Hash, where the value set would be the number of occurrences of the sets or something) - or maybe this is possible somehow?<br />
Going to check it&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.rubyrailways.com/partitioning-sets-in-ruby/comment-page-1/#comment-8160</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 27 Apr 2007 18:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyrailways.com/partitioning-sets-in-ruby/#comment-8160</guid>
		<description>&lt;p&gt;What happens if you have 2 lines with the same numbers - or does that never happen?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>What happens if you have 2 lines with the same numbers - or does that never happen?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
