<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: René Vidríales Trujillo</title>
    <description>The latest articles on DEV Community by René Vidríales Trujillo (@renecvt).</description>
    <link>https://dev.to/renecvt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F18735%2Ffaf17568-11fa-4b37-805b-9b9c0faef7f8.jpeg</url>
      <title>DEV Community: René Vidríales Trujillo</title>
      <link>https://dev.to/renecvt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/renecvt"/>
    <language>en</language>
    <item>
      <title>Project Euler | #1 - Multiples of 3 and 5</title>
      <dc:creator>René Vidríales Trujillo</dc:creator>
      <pubDate>Tue, 14 Jan 2020 07:17:44 +0000</pubDate>
      <link>https://dev.to/renecvt/project-euler-1-multiples-of-3-and-5-2ll4</link>
      <guid>https://dev.to/renecvt/project-euler-1-multiples-of-3-and-5-2ll4</guid>
      <description>&lt;p&gt;Hello! This is the start of a personal new years resolution which I hope will help me grow as a developer and will assist me with my writing and problem solving skills. Let's begin.&lt;/p&gt;

&lt;p&gt;First and foremost, let's define some things before diving into the actual solution I came up with.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Project Euler?
&lt;/h2&gt;

&lt;p&gt;From their site:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OK so, this sounds easy. Project Euler is composed of 687 problems and each problem requires some mathematical knowledge and programming skills. Any programming language can be used. For today's problem I will be using Haskell.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Haskell?
&lt;/h2&gt;

&lt;p&gt;From the &lt;a href="https://wiki.haskell.org/Introduction#What_is_Haskell.3F"&gt;Haskell Wiki&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Haskell is a modern, standard, non-strict, purely-functional programming language. It provides all the features sketched above, including polymorphic typing, lazy evaluation and higher-order functions. It also has an innovative type system which supports a systematic form of overloading and a module system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I'd love to write more about this language, but I think that it deserves a whole post. In my opinion I believe this definition is enough for you to get an idea of what Haskell is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Haskell?
&lt;/h2&gt;

&lt;p&gt;I chose this language because I have used it before at school and I loved it! &lt;/p&gt;

&lt;p&gt;It was challenging for me because my programming background was very object oriented so I didn't know almost anything about the functional paradigm. I like how Haskell manages lists, flows which depend on conditionals, it's lazy evaluation, among other great things.&lt;/p&gt;

&lt;p&gt;Let's dive into the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem definition
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Problem 1 | &lt;a href="https://projecteuler.net/problem=1"&gt;Multiples of 3 and 5&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.&lt;br&gt;
Find the sum of all the multiples of 3 or 5 below 1000.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think about how can you solve it with your favourite language. Or you could try to lay it down first with a flowchart. Options are endless.&lt;/p&gt;

&lt;p&gt;As for me, I tend to write things down on paper when they are complicated or have many constraints. After laying it down on paper I then implement a solution based on the criteria and constraints I got. &lt;/p&gt;

&lt;p&gt;Following this approach I get bugs most of the times, but I believe this bugs are good because often I find validations or new constraints that I hadn't planned for when I was first sketching it down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Without much further ado, this is the solution I came up with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mod&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mod&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This can be expressed as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fill a list with numbers ranging from 1 to 999 which are divisible by three or five. Then, compute the sum of all the values in the list.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that's it! I won't spoil you with the answer. Solve it yourself and, have fun!&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

</description>
      <category>projecteuler</category>
      <category>haskell</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
