<?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>Blog do PacMan &#187; haskell</title>
	<atom:link href="http://pacman.blog.br/blog/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://pacman.blog.br/blog</link>
	<description>Varias Coisas, por Tiago Peczenyj</description>
	<lastBuildDate>Thu, 15 Jul 2010 02:04:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Não entendo o motivo pelo qual ainda ensinam pascal</title>
		<link>http://pacman.blog.br/blog/dicas/nao-entendo-o-motivo-pelo-qual-ainda-ensinam-pascal/</link>
		<comments>http://pacman.blog.br/blog/dicas/nao-entendo-o-motivo-pelo-qual-ainda-ensinam-pascal/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 00:17:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Awk]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://pacman.blog.br/blog/?p=95</guid>
		<description><![CDATA[Encontrei este exercicio em um forum de programação e informatica. Um tanto engenhoso, devo admitir, e é otimo para praticar diferentes linguagens de programação, que podem exercitar muitos paradigmas. Infelizmente o professor pediu para fazer em Pascal. o número 3025 &#8230; <a href="http://pacman.blog.br/blog/dicas/nao-entendo-o-motivo-pelo-qual-ainda-ensinam-pascal/">Continue lendo <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Encontrei este exercicio em um forum de programação e informatica. Um tanto engenhoso, devo admitir, e é otimo para praticar diferentes linguagens de programação, que podem exercitar muitos paradigmas. Infelizmente o professor pediu para fazer em Pascal.</p>
<blockquote><p>o número 3025 possui a seguinte caracteristica: 30+25=55 e 55*55=3025. Escreva um programa que escreva todas os números com quatro algarismos que possuem a citada características.</p></blockquote>
<p>Veja que solução elegante temos com ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>1000..9999<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">find_all</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">+</span>x<span style="color:#006600; font-weight:bold;">%</span>100<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">**</span><span style="color:#006666;">2</span> == x<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2025</span>, <span style="color:#006666;">3025</span>, <span style="color:#006666;">9801</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Entretanto tive a apelar para uma sujeira (alguem percebe?) na versão em haskell:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> List
<span style="color: #06c; font-weight: bold;">Prelude</span> List<span style="color: #339933; font-weight: bold;">&gt;</span> findIndices<span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>x `<span style="font-weight: bold;">div</span>` <span style="color: red;">100</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#40;</span>x `<span style="font-weight: bold;">mod</span>` <span style="color: red;">100</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">^</span><span style="color: red;">2</span> <span style="color: #339933; font-weight: bold;">==</span> x <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> x <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">1000</span><span style="color: green;">&#41;</span><span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>9999<span style="color: green;">&#93;</span>
<span style="color: green;">&#91;</span><span style="color: red;">2025</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3025</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">9801</span><span style="color: green;">&#93;</span></pre></div></div>

<p>Por fim, um simples &#8216;one liner&#8217; usando gawk</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">1000</span> <span style="color: #000000;">9900</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gawk</span> <span style="color: #ff0000;">'(int($1/100) + $1%100) == sqrt($1){print}'</span>
<span style="color: #000000;">2025</span>
<span style="color: #000000;">3025</span>
<span style="color: #000000;">9801</span></pre></div></div>

<p>É claro que a solução esperada é algo como</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include  &lt;stdio.h&gt;</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">9999</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">/</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span><span style="color:#800080;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>sqrt<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Até ANSI C é mais elegante &#8211; sem flamewars por favor, afinal todos sabem o que são <a >programadores de verdade</a> <img src='http://pacman.blog.br/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://pacman.blog.br/blog/dicas/nao-entendo-o-motivo-pelo-qual-ainda-ensinam-pascal/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
