<?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: Project Euler in F# &#8211; Problem 22</title>
	<atom:link href="http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/</link>
	<description>Functional programming on .Net</description>
	<lastBuildDate>Wed, 23 Mar 2011 17:29:06 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vikesh</title>
		<link>http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/comment-page-1/#comment-16408</link>
		<dc:creator>Vikesh</dc:creator>
		<pubDate>Sun, 12 Dec 2010 19:49:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/#comment-16408</guid>
		<description>Here is my solution.... not pretty efficient but it completes in 29-32ms on my System. (Java)



import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Vikesh
 */
public class Problem22 {

    static List names = new ArrayList();

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        File file = new File(System.getProperty(&quot;user.home&quot;), &quot;names.txt&quot;);
        String firstName = null;
        try {
            BufferedReader bf = new BufferedReader(new FileReader(file));
            firstName = bf.readLine();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Problem22.class.getName()).log(Level.SEVERE, null, ex);
        }
        Collections.sort(names);
        String[] tokens = firstName.split(&quot;,&quot;);
        for (String s : tokens) {
            names.add(s.substring(1, s.length() - 1));
        }
        Collections.sort(names);
        int count = 0;
        long nameRank = 0;
        long score = 0;
        for (String name : names) {
            ++count;
            int nameSum  = 0;
            for(int i = 0 ; i&lt; name.length();++i){
                nameSum+= (int)name.charAt(i) - 64;
                 nameRank = nameSum*(count);
            }
            score+= nameRank;
        }

        System.out.println(&quot;Total Count: &quot;+ score);
        long end = System.currentTimeMillis();
        System.out.println(&quot;Time: &quot;+(end-start));
    }
}</description>
		<content:encoded><![CDATA[<p>Here is my solution&#8230;. not pretty efficient but it completes in 29-32ms on my System. (Java)</p>
<p>import java.io.BufferedReader;<br />
import java.io.File;<br />
import java.io.FileNotFoundException;<br />
import java.io.FileReader;<br />
import java.io.IOException;<br />
import java.util.ArrayList;<br />
import java.util.Collections;<br />
import java.util.List;<br />
import java.util.logging.Level;<br />
import java.util.logging.Logger;</p>
<p>/**<br />
 *<br />
 * @author Vikesh<br />
 */<br />
public class Problem22 {</p>
<p>    static List names = new ArrayList();</p>
<p>    public static void main(String[] args) throws IOException {<br />
        long start = System.currentTimeMillis();<br />
        File file = new File(System.getProperty(&#8221;user.home&#8221;), &#8220;names.txt&#8221;);<br />
        String firstName = null;<br />
        try {<br />
            BufferedReader bf = new BufferedReader(new FileReader(file));<br />
            firstName = bf.readLine();<br />
        } catch (FileNotFoundException ex) {<br />
            Logger.getLogger(Problem22.class.getName()).log(Level.SEVERE, null, ex);<br />
        }<br />
        Collections.sort(names);<br />
        String[] tokens = firstName.split(&#8221;,&#8221;);<br />
        for (String s : tokens) {<br />
            names.add(s.substring(1, s.length() &#8211; 1));<br />
        }<br />
        Collections.sort(names);<br />
        int count = 0;<br />
        long nameRank = 0;<br />
        long score = 0;<br />
        for (String name : names) {<br />
            ++count;<br />
            int nameSum  = 0;<br />
            for(int i = 0 ; i&lt; name.length();++i){<br />
                nameSum+= (int)name.charAt(i) &#8211; 64;<br />
                 nameRank = nameSum*(count);<br />
            }<br />
            score+= nameRank;<br />
        }</p>
<p>        System.out.println(&quot;Total Count: &quot;+ score);<br />
        long end = System.currentTimeMillis();<br />
        System.out.println(&quot;Time: &quot;+(end-start));<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Roberts</title>
		<link>http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/comment-page-1/#comment-1010</link>
		<dc:creator>Bob Roberts</dc:creator>
		<pubDate>Thu, 13 Nov 2008 15:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/#comment-1010</guid>
		<description>You don&#039;t need to remove the quotes to sort the list.  The list will sort correctly with the quote.  When you add the value of the names, you can just ignore quotes when adding values.</description>
		<content:encoded><![CDATA[<p>You don&#8217;t need to remove the quotes to sort the list.  The list will sort correctly with the quote.  When you add the value of the names, you can just ignore quotes when adding values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michiel Borkent</title>
		<link>http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/comment-page-1/#comment-92</link>
		<dc:creator>Michiel Borkent</dc:creator>
		<pubDate>Mon, 03 Mar 2008 02:40:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/12/project-euler-in-f-problem-22/#comment-92</guid>
		<description>Here is another solution using List.mapi:

#light
open System.IO
let answer2 = 
    let names = File.ReadAllText(@&quot;C:\dev\Chapter4\names.txt&quot;).Split([&#124;&#039;,&#039;&#124;]) &#124;&gt; Seq.map (fun x -&gt; x.Replace(&quot;\&quot;&quot;, &quot;&quot;))
    let sortednames = names &#124;&gt; Seq.to_list &#124;&gt; List.sort compare
    let CharVal x = 1 + Char.code x - Char.code &#039;A&#039;
    let Score i x =
        (i+1) * (Seq.map CharVal x &#124;&gt; Seq.fold1 (+))
    List.mapi Score sortednames &#124;&gt; Seq.fold1 (+)</description>
		<content:encoded><![CDATA[<p>Here is another solution using List.mapi:</p>
<p>#light<br />
open System.IO<br />
let answer2 =<br />
    let names = File.ReadAllText(@&#8221;C:\dev\Chapter4\names.txt&#8221;).Split([|','|]) |&gt; Seq.map (fun x -&gt; x.Replace(&#8221;\&#8221;", &#8220;&#8221;))<br />
    let sortednames = names |&gt; Seq.to_list |&gt; List.sort compare<br />
    let CharVal x = 1 + Char.code x &#8211; Char.code &#8216;A&#8217;<br />
    let Score i x =<br />
        (i+1) * (Seq.map CharVal x |&gt; Seq.fold1 (+))<br />
    List.mapi Score sortednames |&gt; Seq.fold1 (+)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

