<?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"
	>
<channel>
	<title>Comments on: Raf&#8217;s Problem</title>
	<atom:link href="http://blog.tmorris.net/rafs-problem/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/rafs-problem/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Fri, 05 Dec 2008 08:09:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Christian Vest Hansen</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-21831</link>
		<dc:creator>Christian Vest Hansen</dc:creator>
		<pubDate>Sat, 01 Nov 2008 15:40:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-21831</guid>
		<description>Better late than never! (as they say)

In Clojure:

(defn f [s] (reduce #(+ (- (int %2) 96) (* %1 26)) 0 s))</description>
		<content:encoded><![CDATA[<p>Better late than never! (as they say)</p>
<p>In Clojure:</p>
<p>(defn f [s] (reduce #(+ (- (int %2) 96) (* %1 26)) 0 s))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manohar</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2183</link>
		<dc:creator>Manohar</dc:creator>
		<pubDate>Tue, 25 Mar 2008 08:20:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2183</guid>
		<description>As I am late, I give a bit more :
Scala :

def intToNBase(base : Int)(n : Int) : List[Int] = {
    def inner(ntemp : Int, res : List[Int]) : List[Int] = {
      if(ntemp == 0) res
      else if (ntemp == 1) 1::res
      else inner(ntemp/base, ntemp%base::res)
    }
    inner(n,List())
  }

  def intToBinary(n : Int) = intToNBase(2)(n)

  def NtoIntBase(base: Int)(n : List[Int]) : Int = {
    def inner(tempN : List[Int], res : Int) : Int = tempN match {
      case Nil =&#38;gt; res
      case x::xs =&#38;gt; inner(xs, x+base*res)//x +base*(inner(xs))
    }
    inner(n,0)
  }

  def f(x : String) = NtoIntBase(26)(x.toLowerCase.toList.map(_ - 'a'+1))</description>
		<content:encoded><![CDATA[<p>As I am late, I give a bit more :<br />
Scala :</p>
<p>def intToNBase(base : Int)(n : Int) : List[Int] = {<br />
    def inner(ntemp : Int, res : List[Int]) : List[Int] = {<br />
      if(ntemp == 0) res<br />
      else if (ntemp == 1) 1::res<br />
      else inner(ntemp/base, ntemp%base::res)<br />
    }<br />
    inner(n,List())<br />
  }</p>
<p>  def intToBinary(n : Int) = intToNBase(2)(n)</p>
<p>  def NtoIntBase(base: Int)(n : List[Int]) : Int = {<br />
    def inner(tempN : List[Int], res : Int) : Int = tempN match {<br />
      case Nil =&#38;gt; res<br />
      case x::xs =&#38;gt; inner(xs, x+base*res)//x +base*(inner(xs))<br />
    }<br />
    inner(n,0)<br />
  }</p>
<p>  def f(x : String) = NtoIntBase(26)(x.toLowerCase.toList.map(_ - &#8216;a&#8217;+1))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: willy</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2182</link>
		<dc:creator>willy</dc:creator>
		<pubDate>Sat, 22 Mar 2008 07:03:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2182</guid>
		<description>-- Haskell, recursive
--   will error if passed a string with a non-lowercase or non-alphabet char

import Data.Char(ord, isAsciiLower)

f :: [Char] -&#38;gt; Int
f [] = 0
f s &#124; isAsciiLower (head s) =
         (ord(head s) - ord('a') + 1) * (26 ^ ((length s) - 1)) + (f (tail s))</description>
		<content:encoded><![CDATA[<p>&#8211; Haskell, recursive<br />
&#8211;   will error if passed a string with a non-lowercase or non-alphabet char</p>
<p>import Data.Char(ord, isAsciiLower)</p>
<p>f :: [Char] -&#38;gt; Int<br />
f [] = 0<br />
f s | isAsciiLower (head s) =<br />
         (ord(head s) - ord(&#8217;a') + 1) * (26 ^ ((length s) - 1)) + (f (tail s))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Clarke</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2181</link>
		<dc:creator>Dave Clarke</dc:creator>
		<pubDate>Thu, 13 Mar 2008 09:46:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2181</guid>
		<description>Ah yes. A bit of googling lead me to the phrase: &lt;i&gt;modified base-k positional system&lt;/i&gt; also called a &lt;a href="http://en.wikipedia.org/wiki/Bijective_numeration" rel="nofollow"&gt;bijective numeration&lt;/a&gt;. This is the system you are describing..... And now I discover that this was mentioned above.</description>
		<content:encoded><![CDATA[<p>Ah yes. A bit of googling lead me to the phrase: <i>modified base-k positional system</i> also called a <a href="http://en.wikipedia.org/wiki/Bijective_numeration" onclick="javascript:pageTracker._trackPageview('/outbound/comment/en.wikipedia.org');" rel="nofollow">bijective numeration</a>. This is the system you are describing&#8230;.. And now I discover that this was mentioned above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2180</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Wed, 12 Mar 2008 20:48:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2180</guid>
		<description>Dave,
When I said "the empty String is 0", I had misinterpreted the question. Now that I understand the question, I explained why it is indeed a base 26 system being used.

Here is another explanation:

There are 26 data constructors for one type (a-z)
There are 10 data constructors for another type (0-9)
There is some bijective and total function between these two types.
This function (by implication) is converting between a base 26 and base 10 system &#38;mdash; you can call the data constructors anything.
- QED</description>
		<content:encoded><![CDATA[<p>Dave,<br />
When I said &#8220;the empty String is 0&#8243;, I had misinterpreted the question. Now that I understand the question, I explained why it is indeed a base 26 system being used.</p>
<p>Here is another explanation:</p>
<p>There are 26 data constructors for one type (a-z)<br />
There are 10 data constructors for another type (0-9)<br />
There is some bijective and total function between these two types.<br />
This function (by implication) is converting between a base 26 and base 10 system &#38;mdash; you can call the data constructors anything.<br />
- QED</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Heon</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2179</link>
		<dc:creator>Jeff Heon</dc:creator>
		<pubDate>Wed, 12 Mar 2008 17:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2179</guid>
		<description>Oupse, looks like I was wrong! It was working in the preview at least ;)</description>
		<content:encoded><![CDATA[<p>Oupse, looks like I was wrong! It was working in the preview at least <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Heon</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2178</link>
		<dc:creator>Jeff Heon</dc:creator>
		<pubDate>Wed, 12 Mar 2008 17:37:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2178</guid>
		<description>@Stefan: I like your solution. I wish I had thought of it!

We can post formatted code using &#38;lt;code&#38;gt; tags and &#38;#38;nbsp; I think.
(http://codex.wordpress.org/Writing_Code_in_Your_Posts)

Test:
&lt;code&gt;
public long raf (String s26)
{
&#38;nbsp;&#38;nbsp;long res = 0L;
&#38;nbsp;&#38;nbsp;for (int i = 0; i</description>
		<content:encoded><![CDATA[<p>@Stefan: I like your solution. I wish I had thought of it!</p>
<p>We can post formatted code using &#38;lt;code&#38;gt; tags and &#38;#38;nbsp; I think.<br />
(http://codex.wordpress.org/Writing_Code_in_Your_Posts)</p>
<p>Test:<br />
<code><br />
public long raf (String s26)<br />
{<br />
&#38;nbsp;&#38;nbsp;long res = 0L;<br />
&#38;nbsp;&#38;nbsp;for (int i = 0; i</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Clarke</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2135</link>
		<dc:creator>Dave Clarke</dc:creator>
		<pubDate>Wed, 12 Mar 2008 10:23:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2135</guid>
		<description>I probably should elaborate. Consider base-10.
The empty string is not a number.
0 is 0.
1 is 1.
2 is 2 and so forth.
00 is 0.
000 is 0.
etc etc.

Now in base-26.
The empty string is not a number.
a is 0.
b is 1.
etc
aa is 0.
aaa is 0.

This is not to say that there is no challenge in your puzzle. It's just not base-26.</description>
		<content:encoded><![CDATA[<p>I probably should elaborate. Consider base-10.<br />
The empty string is not a number.<br />
0 is 0.<br />
1 is 1.<br />
2 is 2 and so forth.<br />
00 is 0.<br />
000 is 0.<br />
etc etc.</p>
<p>Now in base-26.<br />
The empty string is not a number.<br />
a is 0.<br />
b is 1.<br />
etc<br />
aa is 0.<br />
aaa is 0.</p>
<p>This is not to say that there is no challenge in your puzzle. It&#8217;s just not base-26.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Clarke</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2137</link>
		<dc:creator>Dave Clarke</dc:creator>
		<pubDate>Wed, 12 Mar 2008 10:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2137</guid>
		<description>There is no zero digit.
It's not base 26. Otherwise, "a" would be zero and "z" would be 25.
Vidar Hokstad was right.</description>
		<content:encoded><![CDATA[<p>There is no zero digit.<br />
It&#8217;s not base 26. Otherwise, &#8220;a&#8221; would be zero and &#8220;z&#8221; would be 25.<br />
Vidar Hokstad was right.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ning</title>
		<link>http://blog.tmorris.net/rafs-problem/#comment-2177</link>
		<dc:creator>Ning</dc:creator>
		<pubDate>Wed, 12 Mar 2008 02:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/rafs-problem/#comment-2177</guid>
		<description>in Python:

  reduce(lambda x, y: x * 26 + (ord(y) - 96), "aza", 0)

or a bit longer:

  reduce(lambda x, y: x * 26 + y, map(lambda x: ord(x) - 96, "aza"))

or in Haskell:

  foldl (\x y -&#38;gt; x * 26 + Char.ord(y) - 96) 0 "aza"</description>
		<content:encoded><![CDATA[<p>in Python:</p>
<p>  reduce(lambda x, y: x * 26 + (ord(y) - 96), &#8220;aza&#8221;, 0)</p>
<p>or a bit longer:</p>
<p>  reduce(lambda x, y: x * 26 + y, map(lambda x: ord(x) - 96, &#8220;aza&#8221;))</p>
<p>or in Haskell:</p>
<p>  foldl (\x y -&#38;gt; x * 26 + Char.ord(y) - 96) 0 &#8220;aza&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
