<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>coder . cl</title>
	
	<link>http://coder.cl</link>
	<description>web developer &amp; system programmer</description>
	<lastBuildDate>Fri, 24 Feb 2012 12:22:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/coder-cl" /><feedburner:info uri="coder-cl" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>where can I work?</title>
		<link>http://feedproxy.google.com/~r/coder-cl/~3/bfyBfw0LfeU/</link>
		<comments>http://coder.cl/2012/02/where-can-i-work/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 12:22:04 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=2275</guid>
		<description><![CDATA[Passionate programmers are always seeking a good place to work, with good and nice programming languages and very good expectations. &#171;Where can I work?&#187; Is one the biggest questions that someone can ask to himself. There are big companies almost everywhere, great corporations where you can build up your career. But you should be able [...]]]></description>
			<content:encoded><![CDATA[<p>Passionate programmers are always seeking a good place to work, with good and nice programming languages and very good expectations. <i>&laquo;Where can I work?&raquo;</i> Is one the biggest questions that someone can ask to himself. There are big companies almost everywhere, great corporations where you can build up your career. But you should be able &mdash; as developer &mdash; to see your environment. Big companies, like retail ones, are not hiring developers directly, with some big exceptions like Amazon, but it is a foreign company, so most of those big companies are using outsourcing and externalizing their development services.</p>
<p><span id="more-2275"></span></p>
<p>There are various types of companies, I think that the biggest market is owned by outsourcing companies. But on outsourcing companies you will not grow enough to reach a management position or software architect position, because those companies using outsourcing services have their own architects and managers. Probably you can grow at least as lead developer, but usually those big companies using outsourcing services will not offer any stable position to you due to the contract that was signed by both parts of the sold service.</p>
<p>On that kind of companies, the fact that their programming language usage is restricted only to those languages supported by other well known companies, so that number languages is very limited, and probably you will only find Java, C# NET, Visual Basic NET, ABAP4, Cobol, and on very strange cases standard C under POSIX or SUSv2/3 platforms. Big corporations do no like those languages that are considered academic like OCaml or Haskell &mdash; but this is only an ignorant point of view because those languages commonly have a Scientific usage, so they are not really academic languages, because you can see distributed models &mdash; including job queues &mdash; implemented over those languages. Probably other big companies are using languages like PHP but for small tasks, rather than <i>enterprise applications</i>, and rarely other languages like Erlang.</p>
<p>Some languages like Python and Ruby, are really productive due to its syntax and multi-paradigm approach. We have various of those cool languages running over the Java Virtual Machine and NET runtime, for example on the Java side we have Jython, JRuby, Scala, Clojure among other languages that can make your development tasks really effective. On the NET side we have IronPython, IronRuby, F# and similar languages. The problem is the fact that there are very few companies using those variants, and those companies commonly use the basic implementation of standard C# NET and standard Java. The reason is simple, the lack of interest from developers to learn new languages are making the usage of any other language impossible due to the lack of developers supporting that language. For example there are some companies leaving all their C language programs and changing them by Java programs due to the lack of developers supporting the C language.</p>
<p><i>&laquo;What is the kind of problems handled on those companies?&raquo;</i>. Another good question. The fact that depending on which language will be used in your projects, will determine the kind of problems that you will be solving. If you are an algorithm lover, you are lost as Java or NET developer. Most applications are Web Based applications consuming a SOA architecture, so you will have the job of consuming those services and you will probably never see the real logic of those problems that are solved by those services, because they rely on a Cobol or ABAP4 backends very far from you. So, your real job will be data insertion and extraction with technology related to XML and JSON, where both are hard to understand if you are not able to handle data structures like trees once you need to process an XML tree or a JSON tree recursively. Remember that you cannot use parallel programming or similar stuff on application containers, because that problem is already solved and most problems are reduced to problems with <img src='http://s.wordpress.com/latex.php?latex=P&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P' title='P' class='latex' /> time and <img src='http://s.wordpress.com/latex.php?latex=O%28n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='O(n)' title='O(n)' class='latex' /> complexity.</p>
<p>Due to the lack of risk assumption, those companies will never use a product which is not supported by another well known company, so, probably you will never see Apache Hadoop and some cool MapReduce implementation, and even you will not see a cool implementation of a MapReduce task in a cloud based environment like Amazon Elastic MapReduce, because most data managed by those companies is <i>private</i>.</p>
<p>So, the remaining companies are medium and small companies if you do not want to participate of that mechanic process and you want to use almost all your knowledge to solve problems. There are companies which are stuck on Web Development. Those companies are building dynamic web sites based on FOSS projects like content managers or blogs. That is not an option if you really want to develop applications and apply your knowledge. So, leave those jobs for people that well paid mechanic tasks, and non-well paid but lazy tasks. The next question is <i>&laquo;where are present algorithmic problems&raquo;?</i> and <i>&laquo;where can I work&raquo;?</i>. Well, the answer seems to be easy to solve. Algorithmic problems are present on those companies making <i>products</i>, a company that sell products &mdash; no matter if those products are desktop or SaaS products &mdash; they always need a good and creative programmer to solve hard problems.</p>
<p>Medium and small sized companies are using Message Queues, Job Queues and similar software, including architectures like OpenMP for parallel solutions. Every day we have more data to process, we have integration with social networks, third party services among too much stuff should be handled by <i>real applications</i>, not simple content managers. So we must take advantage of that software that can allow us to solve real problems in less time than linear processing, so we usually implement parallel or distributed processing reducing the computing time. I think that the best example are startups, once a startup grows and its processing requirement grow and they become useful applications for their customers, the amount of data requires a bigger processing capacity.</p>
<p>Also there are some good medium companies selling FOSS technologies allowing that kind of processing to their customers, which are usually big companies. They are doing a good job I think because they are introducing relatively new technology into their business process, allowing parallel and distributed processing, shortening processing time and getting early results due to their applications implementation. So, take advantage of the interview and ask for some technology of your interest, if the company rely on plain C# or Java, your job will probably be a boring job&hellip;</p>
<p><br/></p>
<h3>some illustrating anti-examples</h3>
<p><i>case A, the <img src='http://s.wordpress.com/latex.php?latex=O%28n%5E2%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='O(n^2)' title='O(n^2)' class='latex' /> implementer</i>: on one of those big companies I&#8217;ve seen an algorithm implementation with <img src='http://s.wordpress.com/latex.php?latex=O%28n%5E2%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='O(n^2)' title='O(n^2)' class='latex' /> complexity searching a value on a string cube due to searching algorithm used &mdash; with a very basic approach on searching algorithms and lack of knowledge on newer algorithms. So, seems to be common for some programmers to get stuck on that knowledge that was acquired when they were studying.</p>
<p><i>case B, the cpu can do it architect</i>: there was a software architect solving a <img src='http://s.wordpress.com/latex.php?latex=O%28n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='O(n)' title='O(n)' class='latex' /> algorithm in linear time. That&#8217;s OK, but for a very small <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />, once that <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> has grown, the process got stuck for hours. So, no parallel programming or distributed computing was used to solve that problem. They cannot use relatively new technology like MapReduce because it is not still supported by any big corporations yet, and probably there was not enough knowledge to apply.</p>
<p><br/></p>
<h3>some illustrating good examples</h3>
<p><i>case A, the mapreduce architect</i>: on one of those service oriented companies they have decided to create a product, very specific for a customer, their architect was capable to solve a hard problem using Apache Hadoop and non linear time algorithms, the resulting solution was fast enough to be integrated with web services with almost real time responses, but with asynchronous requests due to the problem complexity, and they have a good account manager capable to sell Apache Hadoop as part of their product, both with good knowledge of distributed and parallel solutions.</p>
<p><i>case B, the polyglot programmer</i>: there was application build on top of FOSS technologies, and the architect have designed a good application, and a big problem was required to be solved, a new hardware provide has sent a new device and they were requiring add support for that device on Linux. They were luck, because most of their programmers were polyglot programmers knowing C as part of their known programming languages. They do not missed their customer and they were able to make a new business bringing support for that new PKI device.</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2012 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2012. | <a href="http://coder.cl/2012/02/where-can-i-work/">Permalink</a> | <a href="http://coder.cl/2012/02/where-can-i-work/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<p><a href="http://feedads.g.doubleclick.net/~a/BXIpknq08RsCDCI_G6paDb-SIXM/0/da"><img src="http://feedads.g.doubleclick.net/~a/BXIpknq08RsCDCI_G6paDb-SIXM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/BXIpknq08RsCDCI_G6paDb-SIXM/1/da"><img src="http://feedads.g.doubleclick.net/~a/BXIpknq08RsCDCI_G6paDb-SIXM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/coder-cl/~4/bfyBfw0LfeU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2012/02/where-can-i-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://coder.cl/2012/02/where-can-i-work/</feedburner:origLink></item>
		<item>
		<title>haskell and emacs</title>
		<link>http://feedproxy.google.com/~r/coder-cl/~3/IOhI3FoEsNk/</link>
		<comments>http://coder.cl/2012/02/haskell-and-emacs/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 12:17:04 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=2262</guid>
		<description><![CDATA[I think that I have a very nice integration between Haskell and Emacs. The first stuff that you should do to work with Haskell under Emacs, is to integrate the haskell-mode in Emacs with the proper hook to get the haskell-mode fully functional and working fine with Haskell code, so you can use Emacs as [...]]]></description>
			<content:encoded><![CDATA[<p>I think that I have a very nice integration between Haskell and Emacs. The first stuff that you should do to work with Haskell under Emacs, is to integrate the haskell-mode in Emacs with the proper hook to get the haskell-mode fully functional and working fine with Haskell code, so you can use Emacs as most likely an IDE rather than a simple text editor. That can be done thanks to the powerful Emacs Lisp interpreter that has embedded the Emacs editor.</p>
<p><span id="more-2262"></span></p>
<pre name="code" class="brush:lisp;">

(defun dmw-haskell-pointfree-region ()
  "Executes the Haskell pointfree too on the marked region."
  (interactive)
  (let ((pfcmd (format "pointfree %s"
                       (shell-quote-argument (buffer-substring-no-properties
                                              (region-beginning)
                                              (region-end))))))
    (message (format "%s" (shell-command-to-string pfcmd)))))

(defun dmw-haskell-pointfree-replace ()
  "Replaces the marked region with the Haskell pointfree evaluation."
  (interactive)
  (let ((pfcmd (format "pointfree %s"
                       (shell-quote-argument (buffer-substring-no-properties
                                              (region-beginning)
                                              (region-end))))))
    (shell-command-on-region (region-beginning) (region-end) pfcmd t)))

(defun dmw-haskell-hlint-buffer ()
  "Runs hlint on the currently edited file."
  (interactive)
  (set (make-local-variable 'compile-command)
       (let ((file (file-name-nondirectory buffer-file-name)))
         (format "hlint %s" file)))
  (message compile-command)
  (compile compile-command))

(defun dmw-haskell-mode-hook ()
  "Haskell Mode Hook."
  (setq haskell-program-name "/usr/bin/ghci"
        indent-tabs-mode nil)
  (turn-on-haskell-doc-mode)
  (turn-on-haskell-indentation)
  (turn-on-haskell-decl-scan)
  (capitalized-words-mode t)
  (define-key haskell-mode-map "\C-c\C-p" 'dmw-haskell-pointfree-region)
  (define-key haskell-mode-map "\C-c\C-r" 'dmw-haskell-pointfree-replace)
  (define-key haskell-mode-map "\C-c\C-c" 'dmw-haskell-hlint-buffer)
  (message "&gt;&gt;&gt; done dmw-haskell-mode-hook..."))
</pre>
<p>So, some nice thing about this mode-hook, is the fact that it can search for documentation on each function using <tt>C-c M-/</tt> and find definitions using <tt>C-c M-.</tt>. With two custom commands which can allow you to use <i>Pointfree</i> &mdash; which can be installed using cabal &mdash; and <i>Hlint</i> &mdash; which can be found usually under your operating system without problems and can be installed using cabal too. So, to use <i>Hlint</i> with this hook, you can start it with <tt>C-c C-c</tt> or <tt>C-c C-v</tt>, and you can see if there is a point free style replacement for the selected expression &mdash; using Emacs region selection &mdash; with the binding <tt>C-c C-p</tt>, and if you like the point free style replacement, you can replace the selected region with the point free style expression using the binding <tt>C-c C-r</tt>.</p>
<p>I will try to add more nice stuff to my Haskell hook, probably something like searching modules and ordering imports, because would be nice to have similar stuff running under Emacs, to allow more easy to handle Haskell edition under Emacs. Enjoy!</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2012 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2012. | <a href="http://coder.cl/2012/02/haskell-and-emacs/">Permalink</a> | <a href="http://coder.cl/2012/02/haskell-and-emacs/#comments">No comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<p><a href="http://feedads.g.doubleclick.net/~a/PEFj4Hk35dnK4g4eJLBjQM1QL4k/0/da"><img src="http://feedads.g.doubleclick.net/~a/PEFj4Hk35dnK4g4eJLBjQM1QL4k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/PEFj4Hk35dnK4g4eJLBjQM1QL4k/1/da"><img src="http://feedads.g.doubleclick.net/~a/PEFj4Hk35dnK4g4eJLBjQM1QL4k/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/coder-cl/~4/IOhI3FoEsNk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2012/02/haskell-and-emacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://coder.cl/2012/02/haskell-and-emacs/</feedburner:origLink></item>
		<item>
		<title>challenge 2012.02.13 intermediate</title>
		<link>http://feedproxy.google.com/~r/coder-cl/~3/6H-fTSa75QA/</link>
		<comments>http://coder.cl/2012/02/challenge-2012-02-13-intermediate/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 16:11:19 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=2250</guid>
		<description><![CDATA[Here is the another combinatorics challenge with a level intermediate on the programming forum. Still I think that they are very easy to solve. Here is the solution in Haskell, where not real combinatorics are required to supply a solution, instead word elements are used as numbers to find word matches in the text file, [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the another combinatorics challenge with a level <i>intermediate</i> on the programming forum. Still I think that they are very easy to solve. Here is the solution in Haskell, where not real combinatorics are required to supply a solution, instead word elements are used as numbers to find word matches in the text file, without too many libraries and lines of code.</p>
<p><span id="more-2250"></span></p>
<blockquote><p>
Your challenge today is to write a program that can find the amount of anagrams within a .txt file. For example, &#8220;snap&#8221; would be an anagram of &#8220;pans&#8221;, and &#8220;skate&#8221; would be an anagram of &#8220;stake&#8221;.
</p></blockquote>
<pre name="code" class="brush:haskell;">

module Main where

import Data.Char
import Data.List
import Data.Maybe
import Data.String.Utils
import System.Environment

liftLine :: String -&gt; [Int]
liftLine l = fmap ord $ strip l

matchWord :: [Int] -&gt; [Int] -&gt; Maybe [Int]
matchWord w1 w2 = if sort w1 == sort w2
                     then Just w2
                     else Nothing

findMatches :: [Int] -&gt; [[Int]] -&gt; [String]
findMatches x xs = fmap (fmap chr . fromJust)
                   $ filter (/= Nothing)
                   $ fmap (matchWord x) xs

main :: IO ()
main = do [n, w] &lt;- getArgs
          f &lt;- readFile n
          let words = fmap liftLine $ lines f
              wmatch = liftLine w
              in mapM_ putStrLn $ findMatches wmatch words
</pre>
<p>Where the code above can be compiled using <tt>ghc --make prog.hs -o prog</tt> or can be executed using <tt>runghc prog.hs text-file word</tt>. With the text file bellow:</p>
<pre name="code" class="brush:bash;">
snap
pans
skate
stake
takes
kates
tekas
ketas
</pre>
<p>Its output is as follows:</p>
<pre name="code" class="brush:bash;">
13:02 [dmw@www:0 exercises]$ ./challenge20120213 challenge20120213.txt kates
skate
stake
takes
kates
tekas
ketas
</pre>
<p>Enjoy&#8230;</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2012 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2012. | <a href="http://coder.cl/2012/02/challenge-2012-02-13-intermediate/">Permalink</a> | <a href="http://coder.cl/2012/02/challenge-2012-02-13-intermediate/#comments">4 comments</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<p><a href="http://feedads.g.doubleclick.net/~a/3D8h6VbPLjU064_13mdnlf-2h5g/0/da"><img src="http://feedads.g.doubleclick.net/~a/3D8h6VbPLjU064_13mdnlf-2h5g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3D8h6VbPLjU064_13mdnlf-2h5g/1/da"><img src="http://feedads.g.doubleclick.net/~a/3D8h6VbPLjU064_13mdnlf-2h5g/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/coder-cl/~4/6H-fTSa75QA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2012/02/challenge-2012-02-13-intermediate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://coder.cl/2012/02/challenge-2012-02-13-intermediate/</feedburner:origLink></item>
		<item>
		<title>combinatorics problem in haskell</title>
		<link>http://feedproxy.google.com/~r/coder-cl/~3/YGQXweEW6_s/</link>
		<comments>http://coder.cl/2012/02/combinatorics-problem-in-haskell/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 20:19:52 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=2238</guid>
		<description><![CDATA[Here is another challenge called difficult, but seems to be quite easy to solve. It is a simple feasible operation search algorithm between lists of numbers, so it is not so complex to solve and took few minutes to get it working on Haskell, because Haskell provides various tools to work with algorithms. Also this [...]]]></description>
			<content:encoded><![CDATA[<p>Here is another challenge called difficult, but seems to be quite easy to solve. It is a simple feasible operation search algorithm between lists of numbers, so it is not so complex to solve and took few minutes to get it working on Haskell, because Haskell provides various tools to work with algorithms. Also this solution does the extra credit, no matter if the list has up to four integers.</p>
<p><span id="more-2238"></span></p>
<blockquote>
<p>Today, your challenge is to create a program that will take a series of numbers (5, 3, 15), and find how those numbers can add, subtract, multiply, or divide in various ways to relate to each other. This string of numbers should result in 5 * 3 = 15, or 15 /3 = 5, or 15/5 = 3. When you are done, test your numbers with the following strings:</p>
<p><br/></p>
<ul>
<li>4, 2, 8</li>
<li>6, 2, 12</li>
<li>6, 2, 3</li>
<li>9, 12, 108</li>
<li>4, 16, 64</li>
</ul>
<p>For extra credit, have the program list all possible combinations.<br />
for even more extra credit, allow the program to deal with strings of greater than three numbers. For example, an input of (3, 5, 5, 3) would be 3 * 5 = 15, 15/5 = 3. When you are finished, test them with the following strings.</p>
<ul>
<li>2, 4, 6, 3</li>
<li>1, 1, 2, 3</li>
<li>4, 4, 3, 4</li>
<li>8, 4, 3, 6</li>
<li>9, 3, 1, 7</li>
</ul>
</blockquote>
<p>Here is the full solution in Haskell, just to practice a little. Compile it using <tt>ghc --make prog.hs -o prog</tt> or run it using <tt>runghc prog.hs input.txt</tt></p>
<pre name="code" class="brush:haskell;">

module Main where

import Data.String.Utils
import Data.List
import Data.Maybe
import Math.Combinat.Sets
import System.Environment
import Text.Printf

data OperationResult = OperationResult {
     oper              :: Int -&gt; [Int] -&gt; Bool
     , msg             :: String
}

availableOperations :: [OperationResult]
availableOperations =
                    [
                    OperationResult { oper = testMatchMul,
                                      msg = &quot;mul&quot; },
                    OperationResult { oper = testMatchDiv,
                                      msg = &quot;div&quot; },
                    OperationResult { oper = testMatchSum,
                                      msg = &quot;add&quot; },
                    OperationResult { oper = testMatchSub,
                                      msg = &quot;sub&quot; }
                    ]

liftLine :: String -&gt; [Int]
liftLine l = sort $ fmap ( read . strip ) $ split &quot;,&quot; l

matchMessage :: String -&gt; [Int] -&gt; Int -&gt; String
matchMessage s xs n = printf &quot;%s does %s with %s&quot;
                      s ( show n ) ( show xs )

testMatchMul :: Int -&gt; [Int] -&gt; Bool
testMatchMul n xs = n == foldr (*) 1 xs

testMatchDiv :: Int -&gt; [Int] -&gt; Bool
testMatchDiv n xs = dm == n &amp;&amp; dr == 0
                    where (dm,dr) = divMod ( head xs ) ( last xs )

testMatchSum :: Int -&gt; [Int] -&gt; Bool
testMatchSum n xs = n == foldr (+) 0 xs

testMatchSub :: Int -&gt; [Int] -&gt; Bool
testMatchSub n xs = n == foldr (-) 0 xs

applyOperation :: [Int] -&gt; Int -&gt; OperationResult -&gt; Maybe String
applyOperation xs x y = if oper y x xs
                           then Just $ matchMessage ( msg y ) xs x
                           else Nothing

matchOperation :: [OperationResult] -&gt; [Int] -&gt; Int -&gt; [Maybe String]
matchOperation ops xs x = fmap (applyOperation xs x) ops

findMatch :: [Int] -&gt; [Int] -&gt; [String]
findMatch rs xs = fmap fromJust
                  $ filter ( /= Nothing )
                  $ join []
                  $ fmap (matchOperation availableOperations rs) xs

createCombinations :: [[Int]] -&gt; [[Int]]
createCombinations xs = join [] $ fmap (choose 2) xs

procResults :: [String] -&gt; IO ()
procResults = foldr ((&gt;&gt;) . putStrLn) (putStrLn &quot;End!&quot;)

main :: IO ()
main = do [i] &lt;- getArgs
          f &lt;- readFile i
          let rows = fmap liftLine $ lines f
              comb = createCombinations rows
              oset = join [] $ nub $ join []
                     $ fmap (\ x -&gt; fmap (findMatch x) rows ) comb
              in procResults oset
                 &gt;&gt; print comb
</pre>
<p>Where having a sample input file with three numbers per line as follows:</p>
<pre name="code" class="brush:bash;">
4, 2, 8
6, 2, 12
6, 2, 3
9, 12, 108
4, 16, 64
</pre>
<p>Should be processed as follows:</p>
<pre name="code" class="brush:bash;">

08:21 [dmw@www:1 exercises]$ ghc --make challenge20120212.hs -o challenge20120212
[1 of 1] Compiling Main             ( challenge20120212.hs, challenge20120212.o )
Linking challenge20120212 ...
08:21 [dmw@www:1 exercises]$ ./challenge20120212 ./challenge20120212.txt
mul does 8 with [2,4]
add does 6 with [2,4]
mul does 16 with [2,8]
add does 12 with [4,8]
add does 8 with [2,6]
mul does 12 with [2,6]
mul does 6 with [2,3]
add does 9 with [3,6]
mul does 108 with [9,12]
mul does 64 with [4,16]
End!
[[2,4],[2,8],[4,8],[2,6],[2,12],[6,12],[2,3],[2,6],[3,6],[9,12],[9,108],[12,108],[4,16],[4,64],[16,64]]
</pre>
<p>Also, this program can process files with lines containing up to 4 numbers, no matter how many of them are present on the file, it will try all combinations thanks to the <tt>Math.Combinat.Sets</tt> module which is used to create the proper permutations with each line which are converted to Int lists with the <tt>liftLine</tt> function. Probably this is a kind of very basic MapReduce and non distributed implementation where you have various sets of unique permutations &mdash; or antisymmetric power of each list &mdash; and operations to check whether are executed.</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2012 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2012. | <a href="http://coder.cl/2012/02/combinatorics-problem-in-haskell/">Permalink</a> | <a href="http://coder.cl/2012/02/combinatorics-problem-in-haskell/#comments">6 comments</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<p><a href="http://feedads.g.doubleclick.net/~a/fnL8XzaZ3Y7V0fYn8NSYQJ9LMWw/0/da"><img src="http://feedads.g.doubleclick.net/~a/fnL8XzaZ3Y7V0fYn8NSYQJ9LMWw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/fnL8XzaZ3Y7V0fYn8NSYQJ9LMWw/1/da"><img src="http://feedads.g.doubleclick.net/~a/fnL8XzaZ3Y7V0fYn8NSYQJ9LMWw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/coder-cl/~4/YGQXweEW6_s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2012/02/combinatorics-problem-in-haskell/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://coder.cl/2012/02/combinatorics-problem-in-haskell/</feedburner:origLink></item>
		<item>
		<title>small programming exercise</title>
		<link>http://feedproxy.google.com/~r/coder-cl/~3/mCmqJ4c4G7Y/</link>
		<comments>http://coder.cl/2012/02/small-programming-exercise/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 15:42:49 +0000</pubDate>
		<dc:creator>Daniel Molina Wegener</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://coder.cl/?p=2231</guid>
		<description><![CDATA[On a programming forum I have found a small programming problem about guessing numbers. I have implemented its solutions this morning using Haskell, only to practice a little some Haskell programming. The problem is quite easy to solve. I have used lists instead of arithmetic operations to reach the final number without errors, avoiding user [...]]]></description>
			<content:encoded><![CDATA[<p>On a programming forum I have found a small programming problem about guessing numbers. I have implemented its solutions this morning using Haskell, only to practice a little some Haskell programming. The problem is quite easy to solve. I have used lists instead of arithmetic operations to reach the final number without errors, avoiding user mistakes.</p>
<p><span id="more-2231"></span></p>
<blockquote><p>
we all know the classic &laquo;guessing game&raquo; with higher or lower prompts. lets do a role reversal; you create a program that will guess numbers between 1-100, and respond appropriately based on whether users say that the number is too high or too low. Try to make a program that can guess your number based on user input and great code!
</p></blockquote>
<p>And here is my solution &mdash; where it has some validations to avoid the wrong input.</p>
<pre name="code" class="brush:haskell;">

module Main where

import System.IO.Unsafe
import Text.Printf

promptOptions :: String
promptOptions = &quot;[Yes (y), Higher (h), Lower (l)]&quot;

queryNumber :: Int -&gt; String
queryNumber n = printf &quot;Is your number %s? %s&quot;
                       ( show n ) promptOptions

printNumber :: Int -&gt; String
printNumber n = printf &quot;Your number is %s&quot;
                       ( show n )

promptNumber :: Int -&gt; IO String
promptNumber n = putStrLn ( queryNumber n ) &gt;&gt; getLine

reduceList :: String -&gt; Int -&gt; [Int] -&gt; [Int]
reduceList m n xs | m == &quot;h&quot; = filter (&gt; n) xs
                  | m == &quot;l&quot; = filter (&lt; n) xs
                  | m == &quot;y&quot; = [n]
                  | otherwise = xs

searchNumber :: [Int] -&gt; IO ()
searchNumber m = let ln = length m `div` 2
                     nm = m !! ln
                     mn = unsafePerformIO $ promptNumber nm
                     rs = reduceList mn nm m
                     in case length rs of
                             1 -&gt; putStrLn $ printNumber $ head rs
                             _ -&gt; searchNumber rs

main :: IO ()
main = do putStrLn &quot;Is your number odd (o) or even (e)?&quot;
          x &lt;- getLine
          case x of
               &quot;e&quot; -&gt; searchNumber $ filter odd [ 1 .. 100 ]
               &quot;o&quot; -&gt; searchNumber $ filter even [ 1 .. 100 ]
               _   -&gt; main
</pre>
<p>To compile this program with GHC, try <tt>ghc --make prog.hs -o prog</tt>, also it works with <tt>runghc prog.hs</tt>.</p>
<br/><hr height="1px" width="50%" />
<div style='text-align: center !important;'><b>Copyright © 2012 Daniel Molina Wegener</b><br/><b>Atribución-No Comercial-Sin Derivadas 2.0 Chile</b><br/><a target='_new' rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/cl/"><img alt="Creative Commons License" style="border-width:0" src="http://coder.cl.qfl.wpcdn.arcostream.com/cc88x31.png" /></a></div>
<br/><hr height="1px" width="100%" />
<p><small>© Daniel Molina Wegener for <a href="http://coder.cl">coder . cl</a>, 2012. | <a href="http://coder.cl/2012/02/small-programming-exercise/">Permalink</a> | <a href="http://coder.cl/2012/02/small-programming-exercise/#comments">One comment</a><br/>Post tags: <br/></small></p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-6234432850133541";
/* main-feed */
google_ad_slot = "0763600725";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<p><a href="http://feedads.g.doubleclick.net/~a/WlZ8vdjhr4IYNyWwYjkvcgdHq1I/0/da"><img src="http://feedads.g.doubleclick.net/~a/WlZ8vdjhr4IYNyWwYjkvcgdHq1I/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WlZ8vdjhr4IYNyWwYjkvcgdHq1I/1/da"><img src="http://feedads.g.doubleclick.net/~a/WlZ8vdjhr4IYNyWwYjkvcgdHq1I/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/coder-cl/~4/mCmqJ4c4G7Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://coder.cl/2012/02/small-programming-exercise/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://coder.cl/2012/02/small-programming-exercise/</feedburner:origLink></item>
	</channel>
</rss><!-- This Quick Cache file was built for (  coder.cl/feed/ ) in 0.37733 seconds, on Feb 24th, 2012 at 11:44 pm UTC. --><!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 25th, 2012 at 12:44 am UTC --><!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --><!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  coder.cl/feed/ ) in 0.00050 seconds, on Feb 24th, 2012 at 11:49 pm UTC. -->

