<?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>Omnia sunt communia &#187; python</title>
	<atom:link href="http://www.blog.amrlima.info/archives/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blog.amrlima.info</link>
	<description>gnu/linux, cultura livre e outras divagações</description>
	<lastBuildDate>Fri, 20 Jan 2012 20:18:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Paradoxo de São Petersburgo: um teste</title>
		<link>http://www.blog.amrlima.info/archives/1137</link>
		<comments>http://www.blog.amrlima.info/archives/1137#comments</comments>
		<pubDate>Sun, 08 May 2011 15:52:49 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Programação]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[paradoxo são petersburgo]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=1137</guid>
		<description><![CDATA[Estava a ler estatística quando me deparei com este interessante paradoxo.
Este paradoxo, terá sido pela primeira vez publicado por Daniel Bernoulli(1700-1782) (se bem que tenha sido introduzido por Nicolas Bernoulli a Montmort em 1713) Supõe-se que dois indivíduos Pedro e Paulo concordam em jogar um jogo baseado em lançar uma moeda. Neste jogo, lança-se sucessivamente [...]]]></description>
			<content:encoded><![CDATA[<p>Estava a ler estatística quando me deparei com este interessante paradoxo.</p>
<blockquote><p>Este paradoxo, terá sido pela primeira vez publicado por Daniel Bernoulli(1700-1782) (se bem que tenha sido introduzido por Nicolas Bernoulli a Montmort em 1713) Supõe-se que dois indivíduos Pedro e Paulo concordam em jogar um jogo baseado em lançar uma moeda. Neste jogo, lança-se sucessivamente a moeda até dar cara, então, se a moeda tiver aparecido à n-ésima tentativa, Paulo dará a Pedro 2n-1 moedas. A questão que se coloca é sobre quanto deve Pedro pagar a Paulo pelo privilégio de jogar tal jogo?</p>
<p>Intuitivamente, talvez se indicasse uma qualquer quantia finita, mas na verdade, seja qual for a quantia que Pedro invista por cada jogo, se ele tiver dinheiro suficiente para jogar número suficiente de vezes ele deverá sair a lucrar. Em cada jogo ele tem œ de probabilidade de ganhar uma moeda, (œ)2 de ganhar duas moedas e assim sucessivamente, tendo portanto (œ)n de probabilidade de ganhar 2n-1 moedas. Como probabilisticamente é suposto por cada n jogos, ganhar (œ).1+(œ)2.2+&#8230;+(œ)n.2n-1 moedas e este somatório, quando n tende para infinito, tende também para infinito, conclui-se que se jogar número suficiente de jogos, poderá ganhar uma quantia de dinheiro superior a qualquer valor estabelecido. <a href="http://www.educ.fc.ul.pt/icm/icm2003/icm25/outrosparadoxosd.htm" target="_blank">Fonte</a></p></blockquote>
<p>Como estava aborrecido decidir por isto em código <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (Python).</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> throw_coin<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  <span style="color: #483d8b;">''</span><span style="color: #483d8b;">'Head is 0, Tail is 1'</span><span style="color: #483d8b;">''</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
  games = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Number of games: '</span><span style="color: black;">&#41;</span>
  payment = <span style="color: #ff4500;">100</span> <span style="color: #808080; font-style: italic;"># This is to define the money the player has to pay to be hable</span>
                <span style="color: #808080; font-style: italic;"># to play the game</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Initial player payment is %d&quot;</span> <span style="color: #66cc66;">%</span> payment
  cash = <span style="color: #ff4500;">0</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span> <span style="color: black;">&#40;</span>games<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
    throws = <span style="color: #ff4500;">0</span>
    throws = throws + <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span>throw_coin<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>: <span style="color: #808080; font-style: italic;"># throw coin until head comes up</span>
      throws = throws + <span style="color: #ff4500;">1</span>
&nbsp;
    cash = cash + <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">**</span> <span style="color: black;">&#40;</span>throws - <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Equivalent to  2^(i-1)</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Throws %d&quot;</span> <span style="color: #66cc66;">%</span> throws
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;You have wone: %d euros so far!&quot;</span> <span style="color: #66cc66;">%</span> cash
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;You won %d €! You payed %d in advance. You result was %d €!&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>cash
  , payment, cash - payment<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
  main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/1137/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prime factors code in C and Python</title>
		<link>http://www.blog.amrlima.info/archives/865</link>
		<comments>http://www.blog.amrlima.info/archives/865#comments</comments>
		<pubDate>Thu, 14 Jan 2010 23:07:11 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Programação]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[factors]]></category>
		<category><![CDATA[Prime numbers]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=865</guid>
		<description><![CDATA[Today someone spoke about prime factors and I thought it was something interesting to code. I needed to practice my C so I&#8217;ve coded it in C. Here it goes:

#include &#60;stdio.h&#62;
#define VMAX 25
&#160;
int main&#40;&#41;
&#123;
    /*Prime numbers &#60; 100 */
    int primes&#91;VMAX&#93; = &#123;2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97&#125;;
    int factors&#91;VMAX&#93; = &#123;&#125;; [...]]]></description>
			<content:encoded><![CDATA[<p>Today someone spoke about <a href="http://en.wikipedia.org/wiki/Prime_factor">prime factors</a> and I thought it was something interesting to code. I needed to practice my C so I&#8217;ve coded it in C. Here it goes:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#define VMAX 25</span>
&nbsp;
<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: #808080; font-style: italic;">/*Prime numbers &lt; 100 */</span>
    <span style="color: #993333;">int</span> primes<span style="color: #009900;">&#91;</span>VMAX<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #339933;">,</span><span style="color: #0000dd;">5</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span><span style="color: #339933;">,</span><span style="color: #0000dd;">11</span><span style="color: #339933;">,</span><span style="color: #0000dd;">13</span><span style="color: #339933;">,</span><span style="color: #0000dd;">17</span><span style="color: #339933;">,</span><span style="color: #0000dd;">19</span><span style="color: #339933;">,</span><span style="color: #0000dd;">23</span><span style="color: #339933;">,</span><span style="color: #0000dd;">29</span><span style="color: #339933;">,</span><span style="color: #0000dd;">31</span><span style="color: #339933;">,</span><span style="color: #0000dd;">37</span><span style="color: #339933;">,</span><span style="color: #0000dd;">41</span><span style="color: #339933;">,</span><span style="color: #0000dd;">43</span><span style="color: #339933;">,</span><span style="color: #0000dd;">47</span><span style="color: #339933;">,</span><span style="color: #0000dd;">53</span><span style="color: #339933;">,</span><span style="color: #0000dd;">59</span><span style="color: #339933;">,</span><span style="color: #0000dd;">61</span><span style="color: #339933;">,</span><span style="color: #0000dd;">67</span><span style="color: #339933;">,</span><span style="color: #0000dd;">71</span><span style="color: #339933;">,</span><span style="color: #0000dd;">73</span><span style="color: #339933;">,</span><span style="color: #0000dd;">79</span><span style="color: #339933;">,</span><span style="color: #0000dd;">83</span><span style="color: #339933;">,</span><span style="color: #0000dd;">89</span><span style="color: #339933;">,</span><span style="color: #0000dd;">97</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> factors<span style="color: #009900;">&#91;</span>VMAX<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*Prime factors*/</span>
    <span style="color: #993333;">int</span> repeat<span style="color: #009900;">&#91;</span>VMAX<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*Store times each factor repeats*/</span>
    <span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> n<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Type a number to find it's prime factors: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    scanf<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*Start to divide the number by prime numbers while a is not 1*/</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>VMAX<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;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>a <span style="color: #339933;">!=</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>a <span style="color: #339933;">%</span> primes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
&nbsp;
            a <span style="color: #339933;">=</span> a <span style="color: #339933;">/</span> primes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            factors<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> primes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*The prime factor is the one being used*/</span>
            n<span style="color: #339933;">++;</span> <span style="color: #808080; font-style: italic;">/*Count how many times each prime is used*/</span>
            <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>a <span style="color: #339933;">%</span> primes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> n <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
        repeat<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
        n <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*Reinitialize counter*/</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Prime factors:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>VMAX<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/*Print all factors in the array != 0*/</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>factors<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #808080; font-style: italic;">/*Since x ^ 0 = 1, we have to print x ^ 1 instead*/</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>repeat<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</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 ^ 1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> factors<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">else</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d ^ %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> factors<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> repeat<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</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>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I really like python but unfortunately I haven&#8217;t had the time to code anything with python. Now it&#8217;s learning C  , then C++ and so on. But this time I wanted to code this in python also. I&#8217;m a bit out of practice and my brain was thinking in C. But here it goes.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env/python</span>
VMAX = <span style="color: #ff4500;">25</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Prime numbers &lt; 100</span>
primes = <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">11</span>,<span style="color: #ff4500;">13</span>,<span style="color: #ff4500;">17</span>,<span style="color: #ff4500;">19</span>,<span style="color: #ff4500;">23</span>,<span style="color: #ff4500;">29</span>,<span style="color: #ff4500;">31</span>,<span style="color: #ff4500;">37</span>,<span style="color: #ff4500;">41</span>,<span style="color: #ff4500;">43</span>,<span style="color: #ff4500;">47</span>,<span style="color: #ff4500;">53</span>,<span style="color: #ff4500;">59</span>,<span style="color: #ff4500;">61</span>,<span style="color: #ff4500;">67</span>,<span style="color: #ff4500;">71</span>,<span style="color: #ff4500;">73</span>,<span style="color: #ff4500;">79</span>,<span style="color: #ff4500;">83</span>,<span style="color: #ff4500;">89</span>,<span style="color: #ff4500;">97</span><span style="color: black;">&#93;</span>
factors = <span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">*</span>VMAX <span style="color: #808080; font-style: italic;">#Prime factors</span>
repeat = <span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">*</span>VMAX <span style="color: #808080; font-style: italic;">#Store times each factor repeats</span>
i = <span style="color: #ff4500;">0</span>
n = <span style="color: #ff4500;">0</span>
k = <span style="color: #ff4500;">0</span>
&nbsp;
a = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Type a number to find it's prime factors:&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Start to divide the number by prime numbers while a is not 1</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>VMAX<span style="color: black;">&#41;</span>: 
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>a <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: black;">&#40;</span><span style="color: #008000;">int</span> <span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> primes<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
&nbsp;
        a = <span style="color: #008000;">int</span> <span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> / primes<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">print</span> primes<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
        factors<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> = primes<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># The prime factor is the one being used</span>
&nbsp;
        n = n + <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;">#*Count how many times each prime is used</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> n
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">int</span> <span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> primes<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
        n = <span style="color: #ff4500;">0</span> <span style="color: #808080; font-style: italic;">#Reinitialize counter</span>
    repeat<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> = n
    n = <span style="color: #ff4500;">0</span>
    k = k + <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Prime factors:&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Print all factors in the array != 0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>VMAX<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>factors<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>=<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;">#Since x ^ 0 = 1, we have to print x ^ 1 instead</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>repeat<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> factors<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>: <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s ^ %s &quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>factors<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>, repeat<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/865/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>O que tem ocupado o meu tempo</title>
		<link>http://www.blog.amrlima.info/archives/674</link>
		<comments>http://www.blog.amrlima.info/archives/674#comments</comments>
		<pubDate>Sun, 29 Mar 2009 23:20:09 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Traduções]]></category>
		<category><![CDATA[actualização]]></category>
		<category><![CDATA[banshee]]></category>
		<category><![CDATA[fantasdic]]></category>
		<category><![CDATA[gnome-packagekit]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=674</guid>
		<description><![CDATA[Para além de trabalho até dizer chega que, infelizmente, ainda vai durar mais quase uma semana, o meu tempo livre (produtivo) tem sido ocupado com traduções e scripts em python.
Nas traduções actualizei vários módulos para estarem a 100% na altura do lançamento: fantasdic, gnome-packagekit, banshee e gparted (este estava pouco mais de 20% traduzido). O [...]]]></description>
			<content:encoded><![CDATA[<p>Para além de trabalho até dizer chega que, infelizmente, ainda vai durar mais quase uma semana, o meu tempo livre (produtivo) tem sido ocupado com traduções e scripts em python.</p>
<p>Nas traduções actualizei vários módulos para estarem a 100% na altura do lançamento: fantasdic, gnome-packagekit, banshee e gparted (este estava pouco mais de 20% traduzido). O <a href="http://projects.gnome.org/fantasdic/" target="_blank">fantasdic</a> é um dicionário que permite configurar várias fontes de dicionários, incluindo o google translate. O <a href="http://www.packagekit.org/pk-intro.html" target="_blank">gnome-packagekit</a> é um gestor gráfico de pacotes que pode utilizar vários motores (apt, yum, conary etc) e é utilzado por omissão, que eu saiba, no <a href="http://fedoraproject.org/" target="_blank">Fedora</a> e no <a href="http://www.foresightlinux.org/" target="_blank">Foresight Linux</a>. Está aqui no meu Fedora agora mesmo também <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  O <a href="http://banshee-project.org/" target="_blank">Banshee</a> toda a gente conhece, é uma aplicação de gestão e reprodução de multimédia para o GNOME desenvolvida em GTK#.</p>
<p>Há uns dias foi feita também uma pequena revisão ao Gcompris.</p>
<p>Apesar do tempo livre ser pouco vou arranjando umas horitas para traduzir o que me deixa bastante contente.</p>
<p>Continuo a brincar com python e dbus, nomeadamente com o meu script musictracker que coloca a música e o artista que estamos a ouvir no banshee no estado do pidgin. Está um pouco mais polido agora, já gere alguns erros e coloca também o número de vezes que já ouvi uma música no estado. Um dia destes quando isto estiver mais &#8220;usável&#8221; posto aqui o script.</p>
<p>Ando também a ver a API do WordPress e talvez faça qualquer coisa para rapidamente postar pela linha de comandos. <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Inútil? quase, mas divertido!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/674/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python scripts and lots of work</title>
		<link>http://www.blog.amrlima.info/archives/605</link>
		<comments>http://www.blog.amrlima.info/archives/605#comments</comments>
		<pubDate>Tue, 03 Mar 2009 21:32:36 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[gnome]]></category>
		<category><![CDATA[Pessoal]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[tradução]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[translations]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=605</guid>
		<description><![CDATA[In my free time I&#8217;ve been playing with dbus and some python scripts.I&#8217;ll post some of my clumsy, but usefull (to me) results. Now I&#8217;m too busy with work and GNOME translations. Release is almost here and for the first time I&#8217;m translating a main component  !
More news in the next days.
]]></description>
			<content:encoded><![CDATA[<p>In my free time I&#8217;ve been playing with dbus and some python scripts.I&#8217;ll post some of my clumsy, but usefull (to me) results. Now I&#8217;m too busy with work and GNOME translations. Release is almost here and for the first time I&#8217;m translating a main component <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> !</p>
<p>More news in the next days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/605/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you want a &#8220;show desktop&#8221; button in docky?</title>
		<link>http://www.blog.amrlima.info/archives/558</link>
		<comments>http://www.blog.amrlima.info/archives/558#comments</comments>
		<pubDate>Tue, 03 Feb 2009 14:15:14 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[docky]]></category>
		<category><![CDATA[gnome-do show desktop]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=558</guid>
		<description><![CDATA[If  you do, this post is for you!
How do you get one? First this show desktop button ONLY works with compiz (for now at least). Here goes the instructions:
1 &#8211; Activate desktop effects aka compiz
2 &#8211; Activate the dbus plugin
2 &#8211; Download my show_desktop.py python script, save it somewhere safe and make executable.
3 &#8211; Create [...]]]></description>
			<content:encoded><![CDATA[<p>If  you do, this post is for you!</p>
<p>How do you get one? First this show desktop button ONLY works with compiz (for now at least). Here goes the instructions:</p>
<p>1 &#8211; Activate desktop effects aka compiz</p>
<p>2 &#8211; Activate the dbus plugin</p>
<p>2 &#8211; Download my<a href="http://dl.getdropbox.com/u/281158/show_desktop.py" target="_blank"> show_desktop.py</a> python script, save it somewhere safe and make executable.</p>
<p>3 &#8211; Create a menu entry for the script in GNOME&#8217;s main menu and assign a nice desktop icon from a theme of your choise</p>
<p>4 -Add the menu entry to your docky.</p>
<p>5 &#8211; Enjoy your new &#8220;show desktop&#8221; botton!</p>
<p>Here goes the absolutely necessary screenshot <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a title="show_desktop por amrlima, no Flickr" href="http://www.flickr.com/photos/21196653@N04/3250707932/"><img src="http://farm4.static.flickr.com/3362/3250707932_4bb039fb1d.jpg" alt="show_desktop" width="500" height="174" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/558/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Resoluções de ano novo não é comigo mas&#8230;</title>
		<link>http://www.blog.amrlima.info/archives/520</link>
		<comments>http://www.blog.amrlima.info/archives/520#comments</comments>
		<pubDate>Tue, 30 Dec 2008 00:12:29 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Pessoal]]></category>
		<category><![CDATA[ano novo]]></category>
		<category><![CDATA[deb]]></category>
		<category><![CDATA[exercício]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[resoluções]]></category>
		<category><![CDATA[Traduções]]></category>

		<guid isPermaLink="false">http://www.blog.amrlima.info/?p=520</guid>
		<description><![CDATA[Este ano parece-me que vai ser &#8211; mais um &#8211; de loucos,logo vai ser necessário para manter o rumo a nível não pessoal. A nível profissional prevejo tempos turbulentos com possíveis mudanças mais cedo ou mais tarde&#8230; Mas isso fica para outra altura. Nestas resoluções vou colocar apenas o que quero realizar no meu tempo [...]]]></description>
			<content:encoded><![CDATA[<p>Este ano parece-me que vai ser &#8211; mais um &#8211; de loucos,logo vai ser necessário para manter o rumo a nível não pessoal. A nível profissional prevejo tempos turbulentos com possíveis mudanças mais cedo ou mais tarde&#8230; Mas isso fica para outra altura. Nestas resoluções vou colocar apenas o que quero realizar no meu tempo livre.</p>
<p>- Aprender a criar pacotes para Ubuntu/Debian (já fiz pelo menos um que funciona <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) e ver se me torno relativamente bom nisso.</p>
<p>- Avançar na minha aprendizagem de python que tem estado parada. Criar programas com mais de 50 linhas de código <img src='http://www.blog.amrlima.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>- Avançar com o meu site-projecto</p>
<p>- Voltar a fazer exercício físico. Bicicleta era o ideal, mas sem máquina é difícil&#8230; corrida terá de ser.</p>
<p>- Continuar a contribuir com traduções para o GNOME</p>
<p>E acho que já chega. Sendo muitas para tão pouco tempo disponível, vai ser difícil cumprir todas, mas é preferível pensar em grande.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/520/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dear lazy web&#8230;</title>
		<link>http://www.blog.amrlima.info/archives/95</link>
		<comments>http://www.blog.amrlima.info/archives/95#comments</comments>
		<pubDate>Tue, 15 Apr 2008 11:27:00 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://amrlima.wordpress.com/2008/04/15/dear-lazzy-web/</guid>
		<description><![CDATA[Dear lazy web, I&#8217;m trying to learn python. The book I&#8217;m following is &#8220;Beginning Python&#8221;, but it&#8217;s sometimes complex to make the examples in the book because they use ALOT the interactive python console, so typing mistakes are common and I have to retype many lines (It&#8217;s really annoying!).
Can anyone suggest a good book/tutorial for [...]]]></description>
			<content:encoded><![CDATA[<p><span class="blsp-spelling-error">Dear lazy web, I&#8217;m trying to learn python. The book I&#8217;m following is &#8220;Beginning Python&#8221;, but it&#8217;s sometimes complex to make the examples in the book because they use ALOT the interactive python console, so typing mistakes are common and I have to retype many lines (It&#8217;s really annoying!).</span></p>
<p>Can anyone suggest a good book/tutorial for python (beginner)? That would be very nice! Please leave a comment!</p>
<p>And a good python IDE for linux?</p>
<div class="blogger-post-footer">whatever free is : tudo o que é livre</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/95/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning python, can I do it?</title>
		<link>http://www.blog.amrlima.info/archives/92</link>
		<comments>http://www.blog.amrlima.info/archives/92#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:49:00 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Sem categoria]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://amrlima.wordpress.com/2008/04/14/learning-python-can-i-do-it-2/</guid>
		<description><![CDATA[One thing I&#8217;ve always wanted to do is to learn to program. I didn&#8217;t study programing in college, biology and geology were my thing. Anyway I&#8217;ve been a computer enthusiast and now I&#8217;ll try to learn some programing.
I&#8217; m starting with python, it&#8217;s seems to be easy for a beginner. I don&#8217;t want to start [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve always wanted to do is to learn to program. I didn&#8217;t study programing in college, biology and geology were my thing. Anyway I&#8217;ve been a computer enthusiast and now I&#8217;ll try to learn some programing.</p>
<p>I&#8217; m starting with python, it&#8217;s seems to be easy for a beginner. I don&#8217;t want to start with C/C++ since I know that would probably scare me off on the first days.</p>
<p>Now I&#8217;m reading &#8220;<a href="http://www.diesel-ebooks.com/cgi-bin/item/0471760315/Beginning-Python-eBook.html" target="_blank">Beginning Python</a>&#8220;. It&#8217;s seems a nice book, written in a easy to read fashion.</p>
<p>I&#8217;ll make some updates to my progress soon.</p>
<div class="blogger-post-footer">whatever free is : tudo o que é livre</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/92/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning python, can I do it?</title>
		<link>http://www.blog.amrlima.info/archives/65</link>
		<comments>http://www.blog.amrlima.info/archives/65#comments</comments>
		<pubDate>Sun, 13 Apr 2008 14:22:28 +0000</pubDate>
		<dc:creator>amrlima</dc:creator>
				<category><![CDATA[Software Livre]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://amrlima.wordpress.com/?p=40</guid>
		<description><![CDATA[One thing I&#8217;ve always wanted to do is to learn to program. I didn&#8217;t study programing in college, biology and geology were my thing. Anyway I&#8217;ve been a computer enthusiast and now I&#8217;ll try to learn some programing.
I&#8217; m starting with python, it&#8217;s seems to be easy for a beginner. I don&#8217;t want to start [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve always wanted to do is to learn to program. I didn&#8217;t study programing in college, biology and geology were my thing. Anyway I&#8217;ve been a computer enthusiast and now I&#8217;ll try to learn some programing.</p>
<p>I&#8217; m starting with python, it&#8217;s seems to be easy for a beginner. I don&#8217;t want to start with C/C++ since I know that would probably scare me off on the first days.</p>
<p>Now I&#8217;m reading &#8220;<a href="http://www.diesel-ebooks.com/cgi-bin/item/0471760315/Beginning-Python-eBook.html" target="_blank">Beginning Python</a>&#8220;. It&#8217;s seems a nice book, written in a easy to read fashion.</p>
<p>I&#8217;ll make some updates to my progress soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.amrlima.info/archives/65/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

