<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>/dev/tty &#187; Perl</title>
	<atom:link href="http://blog.tty.nl/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tty.nl</link>
	<description>Notes on Web Development, Computer Programming, and Software Engineering</description>
	<lastBuildDate>Thu, 29 Dec 2011 10:59:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Perl Quiz, Perl Solution: Plusified Equations</title>
		<link>http://blog.tty.nl/2009/09/11/perl-quiz-perl-solution-plusified-equations/</link>
		<comments>http://blog.tty.nl/2009/09/11/perl-quiz-perl-solution-plusified-equations/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 10:09:41 +0000</pubDate>
		<dc:creator>Eduard Lohmann</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Perl Quiz of the Week]]></category>

		<guid isPermaLink="false">http://blog.tty.nl/?p=165</guid>
		<description><![CDATA[For problem definition see: The Haskell solution. Because this was a test for an applicant, I felt I should solve it too in order to get a good idea of how difficult it is. My approach was so generate the &#8230; <a href="http://blog.tty.nl/2009/09/11/perl-quiz-perl-solution-plusified-equations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For problem definition see: <a href="http://blog.tty.nl/2009/08/19/haskell-solution-to-perl-quiz-of-the-week-plusified-equations/">The Haskell solution</a>.</p>
<p>Because this was a test for an applicant, I felt I should solve it too in order to get a good idea of how difficult it is.</p>
<p>My approach was so generate the plussified expressions from smallest to largest sum. That way I can discard any expressions from one list that have a smaller sum then the least sum of the other list.</p>
<h3>The Algorithm</h3>
<ol>
<li>Generate a list of plussified expressions for each of the integers, sorted smallest to largest sum.</li>
<li>Compare the sums of the first elements of both lists. If one is less then the other remove it and repeat.</li>
<li>
<p>If the sums are equal you have found an answer.</p>
<p>You could now drop the first expression of each list and continue,<br />
        but you would miss the answers where you link the current first element of one list with<br />
        expressions in the other list that are not first, but have the same sum.<br />
        Therefore I also explicitly look for those answers with a recursive call.</p>
</li>
</ol>
<p>Questions welcome at eduard@tty.nl .</p>
<div class="codecolorer-container perl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/env perl</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span><br />
<br />
main<span style="color: #009900;">&#40;</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> main <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/^\d+$/</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;'$_' is not a valid string of digits.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">@_</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Supply exactly 2 strings of digits seperated by a space&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@answers</span> <span style="color: #339933;">=</span> find_answers<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span> plusify<span style="color: #009900;">&#40;</span><span style="color: #000066;">shift</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> plusify<span style="color: #009900;">&#40;</span><span style="color: #000066;">shift</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">print</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@answers</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Found &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@answers</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot; answers.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">return</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> plusify &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$first_digit</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$num</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/(\d)(\d+)?/</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$first_digit</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$rest</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@ways</span> <span style="color: #339933;">=</span> <span style="color: #000066;">map</span> <span style="color: #009900;">&#123;</span> &nbsp;<span style="color: #0000ff;">$first_digit</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$_</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">$first_digit</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'+'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$_</span> <span style="color: #009900;">&#125;</span> plusify<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">return</span> <span style="color: #000066;">sort</span> <span style="color: #009900;">&#123;</span> sum_expression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=&gt;</span> sum_expression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@ways</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> sum_expression &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$expression</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$sum</span> <span style="color: #339933;">+=</span> <span style="color: #0000ff;">$_</span> <span style="color: #b1b100;">for</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">qr</span><span style="color: #009900;">&#123;</span>\<span style="color: #339933;">+</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$expression</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">return</span> <span style="color: #0000ff;">$sum</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> find_answers &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$expressions_1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$expressions_2</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@expressions_1</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$expressions_1</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@expressions_2</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$expressions_2</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@answers</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@expressions_1</span> <span style="color: #b1b100;">and</span> <span style="color: #0000ff;">@expressions_2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$head_1</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@expressions_1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$head_2</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@expressions_2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sum_1</span> <span style="color: #339933;">=</span> sum_expression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$head_1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sum_2</span> <span style="color: #339933;">=</span> sum_expression<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$head_2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$sum_1</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$sum_2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@answers</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$head_1 = $sum_1 = $head_2&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@answers</span><span style="color: #339933;">,</span> find_answers<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">$head_1</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">@expressions_2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@answers</span><span style="color: #339933;">,</span> find_answers<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">@expressions_1</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">$head_2</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Effectively only shift the lowest of the heads</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">unshift</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@expressions_2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$head_2</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$sum_1</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">$sum_2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">unshift</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@expressions_1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$head_1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$sum_2</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">$sum_1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066;">return</span> <span style="color: #0000ff;">@answers</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tty.nl/2009/09/11/perl-quiz-perl-solution-plusified-equations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Quiz, Haskell Solution: Plusified Equations</title>
		<link>http://blog.tty.nl/2009/08/19/haskell-solution-to-perl-quiz-of-the-week-plusified-equations/</link>
		<comments>http://blog.tty.nl/2009/08/19/haskell-solution-to-perl-quiz-of-the-week-plusified-equations/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 11:24:01 +0000</pubDate>
		<dc:creator>Michel Rijnders</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Perl Quiz of the Week]]></category>

		<guid isPermaLink="false">http://blog.tty.nl/?p=89</guid>
		<description><![CDATA[The Quiz We are given two positive integers $L and $R we need to find Plusified expressions of both for which Eval($E_L) == Eval($E_R). So what is a plusified expression? It is an expression where we can choose whether to &#8230; <a href="http://blog.tty.nl/2009/08/19/haskell-solution-to-perl-quiz-of-the-week-plusified-equations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>The Quiz</h2>
<p>
We are given two positive integers <tt>$L</tt> and <tt>$R</tt> we need to find Plusified<br />
expressions of both for which <tt>Eval($E_L) == Eval($E_R)</tt>. So what is a plusified<br />
expression? It is an expression where we can choose whether to add a single<br />
&quot;+&quot; between any consecutive digit. So for example the number 123 has the<br />
following plusified expression:</p>
<ul>
<li>123</li>
<li>12+3</li>
<li>1+23</li>
<li>1+2+3</li>
</ul>
<p>So if we are given 123 and 96 we can form the following plusified equation:</p>
<ul>
<li>12+3 == 9+6</li>
</ul>
<p>
Your mission is to write a Perl program (or an equivalent program in any<br />
programming language) that will find all solutions to the plusified equation<br />
of two numbers given as input. To normalise the output we&#8217;ll rule that:</p>
<ol>
<li>The equations should be given one at each line.</li>
<li>They will be sorted so consecutive digits will take precedence over &quot;+&quot;&apos;s.</li>
<li>A &quot;+&quot; has no surrounding spaces.</li>
<li>The = sign does have a preceding and following space.</li>
</ol>
<h2>A Haskell Solution</h2>
<p>Listing of the complete solution:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:600px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span><br />
<br />
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>List <span style="color: green;">&#40;</span><span style="font-weight: bold;">iterate</span><span style="color: green;">&#41;</span><br />
<span style="color: #06c; font-weight: bold;">import</span> System <span style="color: green;">&#40;</span>getArgs<span style="color: green;">&#41;</span><br />
<br />
split <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Char</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span><br />
split delim s <span style="color: #339933; font-weight: bold;">=</span> <br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span> <span style="color: green;">&#40;</span>s'<span style="color: #339933; font-weight: bold;">,</span> s''<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">break</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">==</span> delim<span style="color: green;">&#41;</span> s<br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span> s' : <span style="color: #06c; font-weight: bold;">case</span> s'' <span style="color: #06c; font-weight: bold;">of</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; delim : <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> split delim <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> s''<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-weight: bold;">otherwise</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><br />
<br />
plusify <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span><br />
plusify <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: green;">&#93;</span><br />
plusify <span style="color: green;">&#40;</span>c : <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>c : <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: green;">&#93;</span><br />
plusify <span style="color: green;">&#40;</span>c : cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">concatMap</span> <span style="color: green;">&#40;</span>\cs' <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>c : cs'<span style="color: #339933; font-weight: bold;">,</span> c : '<span style="color: #339933; font-weight: bold;">+</span>' : cs'<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>plusify cs<span style="color: green;">&#41;</span><br />
<br />
combis <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span><br />
combis x y <span style="color: #339933; font-weight: bold;">=</span><br />
&nbsp; <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>l<span style="color: #339933; font-weight: bold;">,</span> r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">|</span> l <span style="color: #339933; font-weight: bold;">&lt;-</span> plusify x<span style="color: #339933; font-weight: bold;">,</span> r <span style="color: #339933; font-weight: bold;">&lt;-</span> plusify y<span style="color: #339933; font-weight: bold;">,</span> <span style="font-weight: bold;">sum</span>' l <span style="color: #339933; font-weight: bold;">==</span> <span style="font-weight: bold;">sum</span>' r<span style="color: green;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">where</span> <span style="font-weight: bold;">sum</span>' <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">sum</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">read</span> s <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> split '<span style="color: #339933; font-weight: bold;">+</span>'<br />
<br />
main <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><br />
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span><br />
&nbsp; args <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs<br />
&nbsp; <span style="font-weight: bold;">mapM_</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> \<span style="color: green;">&#40;</span>l<span style="color: #339933; font-weight: bold;">,</span> r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> l <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; = &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> r<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>combis <span style="color: green;">&#40;</span>args<span style="color: #339933; font-weight: bold;">!!</span><span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>args<span style="color: #339933; font-weight: bold;">!!</span><span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tty.nl/2009/08/19/haskell-solution-to-perl-quiz-of-the-week-plusified-equations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

