<?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: Luhn algorithm in F#</title>
	<atom:link href="http://www.fsharp.it/2009/04/15/luhn-algorithm-in-f/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fsharp.it/2009/04/15/luhn-algorithm-in-f/</link>
	<description>Functional programming on .Net</description>
	<lastBuildDate>Wed, 18 Aug 2010 12:04:06 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Pramod</title>
		<link>http://www.fsharp.it/2009/04/15/luhn-algorithm-in-f/comment-page-1/#comment-3812</link>
		<dc:creator>Pramod</dc:creator>
		<pubDate>Sun, 10 May 2009 17:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/?p=122#comment-3812</guid>
		<description>I wrote a similar function in Haskell. However, I used map, zip etc. instead of tail recursion.

dblDigit d = if 2*d &gt; 9 then 2*d - 9 else 2*d
luhn num =
&#160;&#160;  let digits         = map digitToInt (show num) 
&#160;&#160;&#160;&#160;      nDigits        = length digits
&#160;&#160;&#160;&#160;      indices        = (map (\d -&gt; (nDigits-1) - d) [0..])
&#160;&#160;&#160;&#160;      values         = zip digits indices
&#160;&#160;&#160;&#160;      modifiedDigits = map (\(d,i) -&gt; if i `mod` 2 == 1 then dblDigit d else d) values
&#160;&#160;&#160;&#160; digitSum       = sum modifiedDigits
&#160;&#160; in digitSum `mod` 10 == 0

Might be a personal prefernece, but isn&#039;t this method a little bit cleaner?</description>
		<content:encoded><![CDATA[<p>I wrote a similar function in Haskell. However, I used map, zip etc. instead of tail recursion.</p>
<p>dblDigit d = if 2*d &gt; 9 then 2*d &#8211; 9 else 2*d<br />
luhn num =<br />
&nbsp;&nbsp;  let digits         = map digitToInt (show num)<br />
&nbsp;&nbsp;&nbsp;&nbsp;      nDigits        = length digits<br />
&nbsp;&nbsp;&nbsp;&nbsp;      indices        = (map (\d -&gt; (nDigits-1) &#8211; d) [0..])<br />
&nbsp;&nbsp;&nbsp;&nbsp;      values         = zip digits indices<br />
&nbsp;&nbsp;&nbsp;&nbsp;      modifiedDigits = map (\(d,i) -&gt; if i `mod` 2 == 1 then dblDigit d else d) values<br />
&nbsp;&nbsp;&nbsp;&nbsp; digitSum       = sum modifiedDigits<br />
&nbsp;&nbsp; in digitSum `mod` 10 == 0</p>
<p>Might be a personal prefernece, but isn&#8217;t this method a little bit cleaner?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
