<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	>
<channel>
	<title>Comments on: Cedric&#8217;s Problem in OCaml</title>
	<atom:link href="http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/</link>
	<description>programming, politics, &#38; other religious issues</description>
	<lastBuildDate>Mon, 15 Mar 2010 00:31:40 +0000</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mauricio Fernandez</title>
		<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/#comment-33529</link>
		<dc:creator>Mauricio Fernandez</dc:creator>
		<pubDate>Tue, 08 Jul 2008 15:37:34 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/?p=671#comment-33529</guid>
		<description>Wheelwright: have you noticed that everybody else is using maxRange =
10000000000 (or 4611686018427387903) as opposed to your maxRange = 32768?

My fastest OCaml implementation uses functional sets represented with two lists
(reminiscent of the classic functional queue).

Here are the times I get on a 3GHz Athlon:

Robert Fischer&#039;s version:             2420ms
pango&#039;s version (no I/O):             569ms
functional sets enc. as two lists:    273ms                    
functional sets with manual inlining: 217ms

(all versions capped to 10_000_000_000)

You can find the code at http://eigenclass.org/misc/beust.ml and
http://eigenclass.org/misc/beust2.ml.</description>
		<content:encoded><![CDATA[<p>Wheelwright: have you noticed that everybody else is using maxRange =<br />
10000000000 (or 4611686018427387903) as opposed to your maxRange = 32768?</p>
<p>My fastest OCaml implementation uses functional sets represented with two lists<br />
(reminiscent of the classic functional queue).</p>
<p>Here are the times I get on a 3GHz Athlon:</p>
<p>Robert Fischer&#8217;s version:             2420ms<br />
pango&#8217;s version (no I/O):             569ms<br />
functional sets enc. as two lists:    273ms<br />
functional sets with manual inlining: 217ms</p>
<p>(all versions capped to 10_000_000_000)</p>
<p>You can find the code at <a href="http://eigenclass.org/misc/beust.ml" rel="nofollow">http://eigenclass.org/misc/beust.ml</a> and<br />
<a href="http://eigenclass.org/misc/beust2.ml" rel="nofollow">http://eigenclass.org/misc/beust2.ml</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wheelwright</title>
		<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/#comment-33522</link>
		<dc:creator>Wheelwright</dc:creator>
		<pubDate>Mon, 07 Jul 2008 21:32:05 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/?p=671#comment-33522</guid>
		<description>Last time I swear, damn it is addictive:

foreach (var n in Enumerable.Range(1, maxRange).Cast())
Response.Write(n.Select(c =&gt; c).Distinct().Count() == n.Length ?  n : &quot;&quot;);</description>
		<content:encoded><![CDATA[<p>Last time I swear, damn it is addictive:</p>
<p>foreach (var n in Enumerable.Range(1, maxRange).Cast())<br />
Response.Write(n.Select(c =&gt; c).Distinct().Count() == n.Length ?  n : &#8220;&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wheelwright</title>
		<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/#comment-33521</link>
		<dc:creator>Wheelwright</dc:creator>
		<pubDate>Mon, 07 Jul 2008 21:17:24 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/?p=671#comment-33521</guid>
		<description>Oh forget it, it got mangled because I included html break character</description>
		<content:encoded><![CDATA[<p>Oh forget it, it got mangled because I included html break character</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wheelwright</title>
		<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/#comment-33520</link>
		<dc:creator>Wheelwright</dc:creator>
		<pubDate>Mon, 07 Jul 2008 21:15:44 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/?p=671#comment-33520</guid>
		<description>Sorry, if you want printing this will do the job:

for (int n = 0; n  c).Distinct().Count() == n.ToString().Length) 
    Response.Write(&quot;&quot; + n);

Execution time increased to 00.093 secs</description>
		<content:encoded><![CDATA[<p>Sorry, if you want printing this will do the job:</p>
<p>for (int n = 0; n  c).Distinct().Count() == n.ToString().Length)<br />
    Response.Write(&#8220;&#8221; + n);</p>
<p>Execution time increased to 00.093 secs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wheelwright</title>
		<link>http://enfranchisedmind.com/blog/posts/cedrics-problem-in-ocaml/#comment-33518</link>
		<dc:creator>Wheelwright</dc:creator>
		<pubDate>Mon, 07 Jul 2008 20:11:40 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/?p=671#comment-33518</guid>
		<description>Enumerable.Range(1, maxRange).Aggregate((total, n) =&gt; 
{
    var chars = from c in n.ToString() select c;
    return total += (chars.Distinct().Count() == chars.Count()) ? n : 0;
}));

With no optimization it calculates all the values from 1 to max-int (maxRange = 32767) in 00.078 seconds on my crusty 512MB 3GHz Pentium 4.


Another (albeit slightly slower) way to do it:

Enumerable.Range(1, maxRange).Select(n =&gt;
{
  var chars = from c in n.ToString() select c; 
  var count = chars.Count();
  return chars.Distinct().Count() == count ? n : 0;
}
).Sum())


And if anyone wonders I am using LINQ. Both queries are one-liners, line breaks added for clarity.</description>
		<content:encoded><![CDATA[<p>Enumerable.Range(1, maxRange).Aggregate((total, n) =&gt;<br />
{<br />
    var chars = from c in n.ToString() select c;<br />
    return total += (chars.Distinct().Count() == chars.Count()) ? n : 0;<br />
}));</p>
<p>With no optimization it calculates all the values from 1 to max-int (maxRange = 32767) in 00.078 seconds on my crusty 512MB 3GHz Pentium 4.</p>
<p>Another (albeit slightly slower) way to do it:</p>
<p>Enumerable.Range(1, maxRange).Select(n =&gt;<br />
{<br />
  var chars = from c in n.ToString() select c;<br />
  var count = chars.Count();<br />
  return chars.Distinct().Count() == count ? n : 0;<br />
}<br />
).Sum())</p>
<p>And if anyone wonders I am using LINQ. Both queries are one-liners, line breaks added for clarity.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
