<?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>Qualsiasi &#187; C</title>
	<atom:link href="http://www.qualsiasi.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qualsiasi.net</link>
	<description>perchè a tutti piace il qualunquismo.</description>
	<lastBuildDate>Thu, 05 Jan 2012 22:12:46 +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>Facebook puzzles, le mie soluzioni</title>
		<link>http://www.qualsiasi.net/2011/facebook-puzzles-le-mie-soluzioni/</link>
		<comments>http://www.qualsiasi.net/2011/facebook-puzzles-le-mie-soluzioni/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 22:33:21 +0000</pubDate>
		<dc:creator>Qualsiasi</dc:creator>
				<category><![CDATA[programmazione]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.qualsiasi.net/?p=213</guid>
		<description><![CDATA[Periodicamente cercherò, nel tempo libero, di risolvere alcuni dei puzzle &#8220;più facili&#8221; che si possono trovare in questa pagina: http://www.facebook.com/careers/puzzles.php. Sono dei simpatici modi di esercitarsi a programmare, e nel caso risolviate in modo giusto ed efficiente alcuni di quelli più difficili &#8211; c&#8217;è il rischio di venire contattati da Facebook per un posto di [...]]]></description>
			<content:encoded><![CDATA[<p>Periodicamente cercherò, nel tempo libero, di risolvere alcuni dei puzzle &#8220;più facili&#8221; che si possono trovare in questa pagina: <a href="http://www.facebook.com/careers/puzzles.php">http://www.facebook.com/careers/puzzles.php</a>. Sono dei simpatici modi di esercitarsi a programmare, e nel caso risolviate in modo giusto ed efficiente alcuni di quelli più difficili &#8211; c&#8217;è il rischio di venire contattati da Facebook per un posto di lavoro (mica male eh?).</p>
<p>I primi di cui invio la soluzione sono banali &#8211; quelli di prova. Di seguito la mia proposta di soluzione al problema che si chiama &#8220;<a href="http://www.facebook.com/careers/puzzles.php?puzzle_id=7">Hoppity Hop!</a>&#8221; (in Java)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">facebookpuzzles</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileNotFoundException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author Qualsiasi
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HoppityHop <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> f_name<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> numero<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
    HoppityHop<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> filename<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    f_name <span style="color: #339933;">=</span> filename<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">File</span> in <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>f_name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Scanner scan <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Scanner<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    numero <span style="color: #339933;">=</span> scan.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #339933;">=</span> numero<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>3 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>5 <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hoppity<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: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>3 <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>5 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hophop<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: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>3 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>5 <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hop<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: #009900;">&#125;</span>
&nbsp;
     <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ovviamente l&#8217;oggetto va istanziato, il costruttore prevede il nome del file contenente il numero come parametro e poi si chiama il metodo &#8220;run()&#8221;.</p>
<p>E ora l&#8217;ancor più banale soluzione, in C, a <a href="http://www.facebook.com/careers/puzzles.php?puzzle_id=3">Meep meep!</a> &#8211; il secondo puzzle.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include </span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* non leggere argv[1] */</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Meep meep!<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: #009900;">&#125;</span></pre></div></div>

<p>Alla prossima.</p>
 <img src="http://www.qualsiasi.net/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=213" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.qualsiasi.net/2011/facebook-puzzles-le-mie-soluzioni/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anno 2004: Scrivevo codice che ora non capisco</title>
		<link>http://www.qualsiasi.net/2009/anno-2004-scrivevo-codice-che-ora-non-capisco/</link>
		<comments>http://www.qualsiasi.net/2009/anno-2004-scrivevo-codice-che-ora-non-capisco/#comments</comments>
		<pubDate>Thu, 14 May 2009 20:30:11 +0000</pubDate>
		<dc:creator>Qualsiasi</dc:creator>
				<category><![CDATA[programmazione]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[rewind]]></category>

		<guid isPermaLink="false">http://www.qualsiasi.net/?p=75</guid>
		<description><![CDATA[Cavolo, la passione per la programmazione e lo scripting risale praticamente alla prima superiore, quando si usava il pascal a scuola. Turbo Pascal per la precisione. Un linguaggio da matematici. Adesso per lo più uso PHP e Bash, ma ovviamente sono passato per il periodo C, anzi, tutt&#8217;ora reputo il C potentissimo, ma lo uso [...]]]></description>
			<content:encoded><![CDATA[<p>Cavolo, la passione per la programmazione e lo scripting risale praticamente alla prima superiore, quando si usava il pascal a scuola. Turbo Pascal per la precisione. Un linguaggio da matematici. Adesso per lo più uso PHP e Bash, ma ovviamente sono passato per il periodo C, anzi, tutt&#8217;ora reputo il C potentissimo, ma lo uso solo quando ne ho strettamente bisogno.</p>
<p>Oggi, anzi, poco fa, ho riscoperto la mia cartella &#8220;projects&#8221; che ha sempre contenuto esperimenti vari più che veri progetti, e ho trovato il cuore pulsante di un MUD (si, ci giocavo. si, ho smesso). Riguardando il codice, che alla fine non fa altro che aprire una porta in ascolto, scrivere &#8220;Ciao&#8221; e stare in ascolto da tutti i client facendo un echo di quello che riceve, mi sono accorto che&#8230; tutto sommato non ero proprio un pischello, ma c&#8217;era molto copia-incolla nei miei programmi.</p>
<p>Ecco cosa mi ha colpito:</p>
<blockquote><p>tmp_size = sizeof tmp_sockaddr;<br />
if (getpeername(tmp_socket, (struct sockaddr *) &amp;tmp_sockaddr, &amp;tmp_size) &lt; 0) printf(&#8220;[WARNING] Can&#8217;t perform getpeername().\n&#8221;);</p></blockquote>
<p>Mah, è ipnotico. Lol.</p>
 <img src="http://www.qualsiasi.net/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=75" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.qualsiasi.net/2009/anno-2004-scrivevo-codice-che-ora-non-capisco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

