<?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: Håvard Krogstie</title>
    <description>The latest articles on DEV Community by Håvard Krogstie (@hkrogstie).</description>
    <link>https://dev.to/hkrogstie</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%2F1928%2F4fffbb5f-b1a5-4b6b-aaad-05ff31034f17.png</url>
      <title>DEV Community: Håvard Krogstie</title>
      <link>https://dev.to/hkrogstie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hkrogstie"/>
    <language>en</language>
    <item>
      <title>My favourite computer science text (OR "how regex works")</title>
      <dc:creator>Håvard Krogstie</dc:creator>
      <pubDate>Sat, 13 Jun 2020 14:39:41 +0000</pubDate>
      <link>https://dev.to/hkrogstie/my-favourite-computer-science-text-or-how-regex-works-4g9l</link>
      <guid>https://dev.to/hkrogstie/my-favourite-computer-science-text-or-how-regex-works-4g9l</guid>
      <description>&lt;p&gt;One of my favourite things in CS is reading about algorithms not as a tutorial, but as more of a historical presentation. My favourite example is &lt;a href="https://swtch.com/%7Ersc/regexp/regexp2.html"&gt;https://swtch.com/~rsc/regexp/regexp2.html&lt;/a&gt;,&lt;br&gt;
which discusses how Nondeterministic Finite Automata modelled as virtual machine bytecode can be used instead of traditional backtracking algorithms when regex matching. All these terms are explained in the text.&lt;/p&gt;

&lt;p&gt;The reason I like the text so much is that the algorithms are thoroughly presented and explained, with references to original papers from the 1960s by names like Rob Pike and Ken Thompson. It's nice to recognize names "in the wild", and then see examples of just what those people did. Much better than reading their Wikipedia pages imo.&lt;/p&gt;

&lt;p&gt;And more familiar (and unfamiliar) names appear as the history is discussed. The algorithm by Thompson was used in the original Unix grep. Alfred Aho (the A in awk) is one of the authors of the infamous Dragon Book, where the technique is discussed, but without clear attribution, as several people have made DFAs and NFAs from regular expressions, without necessarily saying they do (Thompson didn't, he just made the machine code).&lt;/p&gt;

&lt;p&gt;Aho is of course the guy from the Aho-Corasick string searching algorithm, which I randomly had to learn at some point to solve a hackerrank-task, but which I mainly remember specifically because the name Aho suddenly appeared everywhere else afterward (I had held the Dragon book, but didn't bother remembering any of the authors at first).&lt;/p&gt;

&lt;p&gt;Anyways, the article I shared is part 2/3 of a series, which is my favourite part for reasons discussed above, but you should absolutely read the other parts if you like it.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>regex</category>
      <category>history</category>
    </item>
    <item>
      <title>Record fraud (find an algorithm)</title>
      <dc:creator>Håvard Krogstie</dc:creator>
      <pubDate>Sat, 06 Jun 2020 12:40:33 +0000</pubDate>
      <link>https://dev.to/hkrogstie/clear-the-records-find-an-algorithm-5f01</link>
      <guid>https://dev.to/hkrogstie/clear-the-records-find-an-algorithm-5f01</guid>
      <description>&lt;p&gt;&lt;strong&gt;Difficulty:&lt;/strong&gt; Beginner&lt;/p&gt;

&lt;p&gt;You work in a start up with very unstable finances. You have a chronological list of all income (positive integers) and expenses (negative integers), and you need to share it with investors.&lt;/p&gt;

&lt;p&gt;However, you don't want the busines to appear unprofitable. In fact, you want it to seem as if the busines has never been in the red ever. You do this by selectively removing expenses from the list, removing as few as possible to avoid rasing suspicion.&lt;/p&gt;

&lt;p&gt;What does the list given to the investors look like?&lt;/p&gt;

&lt;h3&gt;
  
  
  Input
&lt;/h3&gt;

&lt;p&gt;An array of integers &lt;code&gt;history&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;An array of integers &lt;code&gt;cleared&lt;/code&gt; where&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cleared&lt;/code&gt; is a subsequece of &lt;code&gt;hisory&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sum(cleared[:n])&lt;/code&gt; is non-negative for all n&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;len(cleared)&lt;/code&gt; is maximized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If multiple outputs fulfill the requirements, return any one of them&lt;/p&gt;

&lt;h3&gt;
  
  
  Constraints
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;len(history) &amp;lt;= 100 000&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;abs(history[i]) &amp;lt;= 10^9&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[-3, 8, -4, -5, 4, -2, -3, -2, -2, 5, -6, 2, -5, -5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Possible output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[8, 4, -2, -3, -2, -2, 5, 2, -5, -5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to make an algorithm that's &lt;code&gt;O(n log n)&lt;/code&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Testing &amp;amp; things &lt;script&gt;alert('Hi');&lt;/script&gt; &lt;i&gt;Hi&lt;/i&gt; Hello um what</title>
      <dc:creator>Håvard Krogstie</dc:creator>
      <pubDate>Mon, 22 Jul 2019 21:34:56 +0000</pubDate>
      <link>https://dev.to/hkrogstie/testing-amp-things-script-alert-hi-script-2n1k</link>
      <guid>https://dev.to/hkrogstie/testing-amp-things-script-alert-hi-script-2n1k</guid>
      <description>&lt;p&gt;Hi, I'm just testing&lt;br&gt;
&amp;amp;&lt;/p&gt;



alert("Wowzers")
&lt;h1&gt;
  
  
  &amp;amp;
&lt;/h1&gt;

&lt;p&gt;&lt;a href=""&gt;&amp;amp; WHa"&amp;gt;Link: &amp;amp;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Watch what happens to the title when it is in a link tag&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/hkrogstie" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4X7UBBnR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--JoIn60wC--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/1928/4fffbb5f-b1a5-4b6b-aaad-05ff31034f17.png" alt="hkrogstie image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/hkrogstie/testing-amp-things-script-alert-hi-script-2n1k" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Testing &amp;amp;amp; things  Hi Hello um what&lt;/h2&gt;
      &lt;h3&gt;Håvard Krogstie ・ Jul 22 ・ 1 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#hiamp&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#howampareyou&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#scriptalerttestingscript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>hiamp</category>
      <category>howampareyou</category>
      <category>scriptalerttestingscript</category>
    </item>
    <item>
      <title>Remove terrible bus routes (find an algorithm)</title>
      <dc:creator>Håvard Krogstie</dc:creator>
      <pubDate>Sat, 09 Mar 2019 15:49:09 +0000</pubDate>
      <link>https://dev.to/hkrogstie/remove-terrible-bus-routes-find-an-algorithm-5782</link>
      <guid>https://dev.to/hkrogstie/remove-terrible-bus-routes-find-an-algorithm-5782</guid>
      <description>&lt;p&gt;&lt;em&gt;Here is a challenge for those who want to do some algorithms programming, similar to what you would find in algorithms competitions, such as the IOI. It is not terribly difficult, but a great way to combine pen and paper solving with programming. This task uses 2D sorting, and my python solution is ~20 lines and runs in O(n*log n) time&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Problem statement
&lt;/h1&gt;

&lt;p&gt;You are taking the bus from A to B, sometime today. You have a list of &lt;strong&gt;all possible&lt;/strong&gt; trips, with a trip being represented as the tuple &lt;code&gt;(leave_time, arrive_time)&lt;/code&gt;. The time you leave A, and the time you get to B, respectively. Both times are represented as integers.&lt;/p&gt;

&lt;p&gt;You don't care about what the route looks like, so even really bad choices are included. There may be arbitrarily many ways of getting from A to B, some worse than others.&lt;/p&gt;

&lt;p&gt;Turns out many of the trips are so bad that you would never want to take them. Therefore you would want to tidy up the list. &lt;strong&gt;Duplicates&lt;/strong&gt; should be removed, and any trip that is &lt;strong&gt;objectively worse&lt;/strong&gt; than another trip should be removed.&lt;/p&gt;

&lt;p&gt;A trip &lt;code&gt;X&lt;/code&gt; is &lt;em&gt;objectively worse&lt;/em&gt; than another trip &lt;code&gt;Y&lt;/code&gt; if &lt;code&gt;X.leave_time &amp;lt;= Y.leave_time &amp;amp;&amp;amp; X.arrive_time &amp;gt;= Y.arrive_time&lt;/code&gt;. Basically if you can leave from A later, and still arrive at B earlier, there is no point in ever taking trip X.&lt;/p&gt;

&lt;p&gt;Given the list, write a function that returns a sorted and tidied up list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Input
&lt;/h2&gt;

&lt;p&gt;Input is read from a file or the console.&lt;br&gt;
The first line contains an integer &lt;code&gt;N&lt;/code&gt; (&lt;code&gt;1 &amp;lt; N &amp;lt;= 1e5&lt;/code&gt;), the number of trips given.&lt;br&gt;
The following &lt;code&gt;N&lt;/code&gt; lines contain two integers &lt;code&gt;leave_time&lt;/code&gt; and &lt;code&gt;arrive_time&lt;/code&gt; (&lt;code&gt;1 &amp;lt;= leave_time &amp;lt;= arrive_time &amp;lt;= 1e6&lt;/code&gt;), denoting a trip in the list.&lt;/p&gt;
&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;Output is printed out in the console or to a file.&lt;br&gt;
One the first line, print the number of trips in the tidied list &lt;code&gt;M&lt;/code&gt;.&lt;br&gt;
Followed by &lt;code&gt;M&lt;/code&gt; lines, with the integers &lt;code&gt;arrive_time&lt;/code&gt; and &lt;code&gt;leave_time&lt;/code&gt; for each trip in sorted order.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sample input 1
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
15 30
12 28
15 32
8 42
15 30
10 30
25 40
28 38
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
12 28
15 30
28 38
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsit5omybhcj777a7dzpb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsit5omybhcj777a7dzpb.png" alt="Example 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each interval represents a possible trip. The &lt;code&gt;(leave_time, arrival_time)&lt;/code&gt; tuple is written on the box. If the trip is objectively worse than another, the box is red, with an explanation written on it.&lt;/p&gt;

&lt;p&gt;The routes that are left (green) are then sorted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample input 2
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30
23 59
17 82
85 90
76 95
44 87
78 78
51 88
73 80
10 31
84 95
38 56
92 96
66 71
77 98
94 98
94 98
91 99
83 98
91 94
63 77
33 69
3 63
13 54
37 80
27 40
52 92
90 98
41 91
11 96
16 65
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9
10 31
27 40
38 56
66 71
78 78
85 90
91 94
92 96
94 98
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want a solution, I will publish a commented one written in python in the comments. However, the solution is probably easier to understand if you get to it on your own.&lt;/p&gt;

</description>
      <category>challenge</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Hi, I'm HÃ¥vard Krogstie</title>
      <dc:creator>Håvard Krogstie</dc:creator>
      <pubDate>Tue, 17 Jan 2017 18:39:01 +0000</pubDate>
      <link>https://dev.to/hkrogstie/hi-im-hvard-krogstie</link>
      <guid>https://dev.to/hkrogstie/hi-im-hvard-krogstie</guid>
      <description>&lt;p&gt;I have been coding for 8 years.&lt;/p&gt;

&lt;p&gt;You can find me on Twitter as &lt;a href="https://twitter.com/HKrogstie" rel="noopener noreferrer"&gt;@HKrogstie&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Trondheim, Norway.&lt;/p&gt;

&lt;p&gt;I'm still in school.&lt;/p&gt;

&lt;p&gt;I mostly program in C++ for the time being, but only because I want a personal replacement language, and am attempting to make the compiler.&lt;/p&gt;

&lt;p&gt;I am currently learning more about language design and compiler development.&lt;br&gt;
I would love to implement my own language, but at the time being, the design changes too quickly for any compiler implementation to be made.&lt;/p&gt;

&lt;p&gt;Also extremely happy with Emacs!&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
