<?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>Forem: Stephanie Hope</title>
    <description>The latest articles on Forem by Stephanie Hope (@smh30).</description>
    <link>https://forem.com/smh30</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%2F139511%2F9f9de59f-18a7-4568-bee1-e594a0888972.jpg</url>
      <title>Forem: Stephanie Hope</title>
      <link>https://forem.com/smh30</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/smh30"/>
    <language>en</language>
    <item>
      <title>Learning things about PHP during Advent of Code (Days 1-3)</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Wed, 04 Dec 2019 07:01:35 +0000</pubDate>
      <link>https://forem.com/smh30/learning-things-about-php-during-advent-of-code-days-1-3-32ej</link>
      <guid>https://forem.com/smh30/learning-things-about-php-during-advent-of-code-days-1-3-32ej</guid>
      <description>&lt;p&gt;Last year, I found out about Advent of Code a few days after it began, and never managed to get caught up. I had to drop it in the first week due to being busy with university work, but came back a few times over the past year and eventually ended up stuck on Day 11. &lt;/p&gt;

&lt;p&gt;I'm hoping that a year later I'm able to get a bit further. This time I'll be doing the puzzles in PHP, since that's what I'm using in my internship at the moment. My very first observation, after using Java last year, was that getting the input file in is so much easier now!&lt;/p&gt;

&lt;p&gt;I found Day 1 fairly straightforward, and made a few initial mistakes on Day 2 but was able to fix them. Day 3 seemed like a big jump in difficulty. It took me a while to get my head around what needed to be done, and then when I (thought I) had it, I wasn't sure if my code was even working it took so long to finish. That's the solution I posted in the thread &lt;a href="https://dev.to/smh30/comment/ieec"&gt;here&lt;/a&gt;. It took over 7 minutes to run.&lt;/p&gt;

&lt;p&gt;I knew that there had to be something I could do, so I looked up other ways to check if something was in an array. I found out about the key_exists() method, and after changing my code so the array used keys (like the maps I'm familiar with from Java) I managed to decrease the run time from over 7 minutes to around 0.1 seconds!&lt;/p&gt;

&lt;p&gt;I was amazed that this small change produced such a huge improvement. Looking at &lt;a href="https://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions"&gt;this Stackoverflow question and its answers&lt;/a&gt; I learned that arrays in PHP are actually hashmaps, and that searching for a key is O(1) while searching for a value is O(n) - I've never really learned about Big O notation, but I do know that O(1) is better (best?).&lt;/p&gt;

&lt;p&gt;My final code is like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"input3.txt"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$wire1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;","&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nv"&gt;$wire2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;","&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="nv"&gt;$wire1_posn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trace_wire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$wire2_posn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trace_wire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$time&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;find_intersections&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire1_posn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$wire2_posn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; min distance = &lt;/span&gt;&lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="s2"&gt;, min time = &lt;/span&gt;&lt;span class="nv"&gt;$time&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;find_intersections&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$wire2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$distances&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire1&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$posn&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;key_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$wire2&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;","&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$posn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nv"&gt;$distances&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="nv"&gt;$times&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$wire1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$posn&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$wire2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$posn&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$distances&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$times&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;trace_wire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$x&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;span class="nv"&gt;$y&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;span class="nv"&gt;$steps&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;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$wire&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$direction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nv"&gt;$distance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"U"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&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;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$wire_posn&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"D"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&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;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$wire_posn&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"L"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&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;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$wire_posn&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$direction&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"R"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&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;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$distance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$wire_posn&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$steps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$wire_posn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I hope I keep learning useful things this month! &lt;/p&gt;

&lt;p&gt;(My other solutions can be found on my GitHub, &lt;a href="https://github.com/smh30/AdventCode2019"&gt;here&lt;/a&gt;.)&lt;/p&gt;

</description>
      <category>adventofcode</category>
      <category>php</category>
      <category>beginners</category>
    </item>
    <item>
      <title>back-to-front or front-to-back?</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Sat, 22 Jun 2019 10:34:02 +0000</pubDate>
      <link>https://forem.com/smh30/back-to-front-or-front-to-back-25am</link>
      <guid>https://forem.com/smh30/back-to-front-or-front-to-back-25am</guid>
      <description>&lt;p&gt;For a course I'm taking next semester I will be building a web app. It's nothing very complex - different types of users can view and create/update different types of stored information. The point of this course is more the opportunity to try out new technologies than to create a great product. &lt;/p&gt;

&lt;p&gt;I intend to use Spring (or Spring Boot? I haven't yet figured out the difference) for the backend and probably Angular for the frontend. I have never used either of these frameworks before, nor do I have any idea how they work.&lt;/p&gt;

&lt;p&gt;Which side should I start working from? I'd at least like to be able to make a start on figuring out one end before I start to confuse myself by mixing the two.&lt;/p&gt;

&lt;p&gt;I've tentatively selected Angular over React or Vue for the frontend because I've heard it's popular / in demand here in New Zealand, but is there a solid reason I should consider using something else?&lt;/p&gt;

&lt;p&gt;Do you know of any extremely beginner-friendly resources I should look at for any of these frameworks? I'm hoping to spend the next couple of weeks starting to get familiar with them before the semester begins.&lt;/p&gt;

</description>
      <category>help</category>
      <category>java</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A beginner tries basic accessibility testing</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Mon, 10 Jun 2019 10:45:49 +0000</pubDate>
      <link>https://forem.com/smh30/a-beginner-tries-basic-accessibility-testing-5gka</link>
      <guid>https://forem.com/smh30/a-beginner-tries-basic-accessibility-testing-5gka</guid>
      <description>&lt;p&gt;I've just finished building my first client website - just a very basic &lt;a href="https://johnwoodtakapuna.nz"&gt;single page thing&lt;/a&gt; but hey, everyone has to start somewhere. &lt;/p&gt;

&lt;p&gt;I wanted to make sure it was accessible, so I tested it using both the Axe extension for Firefox, which I'd used in an assignment in the past, and Chrome's Lighthouse testing which I've seen referenced in other articles. I'm aware that these tools &lt;a href="https://dev.to/adrianengine/accessibility-beyond-scores-369b"&gt;aren't perfect&lt;/a&gt; but I figured it's a solid start.&lt;/p&gt;

&lt;p&gt;The initial result was... not great.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AjBAVPBx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r5o6w3ix0kgn2eqz9g36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AjBAVPBx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r5o6w3ix0kgn2eqz9g36.png" alt="Lighthouse results showing 53% for acceessibility"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One thing I found though, is that with a small site like this a small number of issues can really lower the score, and conversely fixing even the easiest will really improve it.&lt;/p&gt;

&lt;p&gt;Two of the four issues highlighted in the Lighthouse report were due to things I'd just mistakenly left in the HTML. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[id]&lt;/code&gt; attributes on the page are not unique&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I had accidentally used the same id on two similar sections of the page. Easily fixed by changing one of them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lists do not contain only &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; elements and script supporting elements (&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Due to some kind of copy/paste mix-up, a list contained an empty paragraph. Removed it, et voila:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6T_qBd1---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/amixqn8qhztakgmzsq22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6T_qBd1---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/amixqn8qhztakgmzsq22.png" alt="Accessibility score = 70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I guess these kinds of things don't happen to people with more experience, but for me it was nice to see that a minute or so improved the score so much.&lt;/p&gt;

&lt;p&gt;Then onto the other issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image elements do not have &lt;code&gt;[alt]&lt;/code&gt; attributes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Six items were failing on this point. I'd added &lt;code&gt;[alt]&lt;/code&gt; text on a few other images used on the page, but these ones were purely decorative so I hadn't bothered. But if it was being flagged up, obviously there was something else I needed to do!&lt;/p&gt;

&lt;p&gt;After a quick search I found that &lt;a href="https://www.w3.org/WAI/tutorials/images/decorative/"&gt;when images are purely presentational they should have empty alt text&lt;/a&gt; &lt;code&gt;[alt=""]&lt;/code&gt; to indicate this fact. Another easy fix! I felt like I was on a roll!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Links do not have a discernible name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This one gave me more drama than all the others combined&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://dequeuniversity.com/rules/axe/3.1/link-name?application=lighthouse"&gt;linked information in Lighthouse&lt;/a&gt; didn't help me out much. It was all very much about making sure text is associated with every link, which obviously is generally a good thing! In my case, though, the links in question were images which also had a text link to the same location beneath them. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EhRpj4II--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1hprg2n9at6j5zhjobwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EhRpj4II--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1hprg2n9at6j5zhjobwj.png" alt='Icon of plastic bottle with link reading "Plastic Waste" below it'&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I tried applying &lt;code&gt;[tabindex="-1"]&lt;/code&gt; to the images, so that they couldn't be focused by the keyboard. Though they were no longer tab focusable and thus to my limited understanding shouldn't be presented to a screen reader looking for links, the error remained.&lt;/p&gt;

&lt;p&gt;After quite a long time searching around for ways to fix this, I was just about on the verge of giving up, but decided to check Axe and see if it had any other issues still remaining. It only had the same one, but it turned out that its solution advice was much more helpful to me.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VQ88mT6S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/91zcc1nbi6rc0pd1n30f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VQ88mT6S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/91zcc1nbi6rc0pd1n30f.png" alt='""'&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the advice from Lighthouse had been regarding adding text, but this gave me other options. &lt;/p&gt;

&lt;p&gt;First I tried adding &lt;code&gt;[role="presentation"]&lt;/code&gt;, since that sounded the quickest. Unfortunately, I wasn't that lucky, as I somewhat suspected would be the case as a link whose role is presentation doesn't make sense.&lt;/p&gt;

&lt;p&gt;The solution turned out to be in the third suggestion in the list: "&lt;code&gt;aria-labelledby&lt;/code&gt; attribute does not exist, references elements that do not exist or references elements that are empty". Indicating that the icons are labelled by the text link that follows them seems to have fixed the issue, at least as far as both Lighthouse and Axe are concerned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N5h-u0Oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/thjx0qzi3r4dhpq79t41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N5h-u0Oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/thjx0qzi3r4dhpq79t41.png" alt="Lighthouse results showing 100% for acceessibility"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My lesson from this first foray into accessibility testing is that there's no need to be afraid, with the help of tools and googling it's quite achievable. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>a11y</category>
    </item>
    <item>
      <title>What's the best way to store data for my very basic app?</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Thu, 30 May 2019 11:12:23 +0000</pubDate>
      <link>https://forem.com/smh30/what-s-the-best-way-to-store-data-for-my-very-basic-app-1ke5</link>
      <guid>https://forem.com/smh30/what-s-the-best-way-to-store-data-for-my-very-basic-app-1ke5</guid>
      <description>&lt;p&gt;I'm creating a very simple app to visualise my progress and grades in my courses, which is something I used to do on paper back in undergrad. I figured it would be a nice simple project which would actually be of use, if only to me.&lt;/p&gt;

&lt;p&gt;I've started out creating it as a web app, creating SVG using Javascript. However, I've run into a snag with how to actually get the data in. I want to be able to use a form (or similar) to add new data when I receive grades, but I don't know how to store and access that data. &lt;/p&gt;

&lt;p&gt;From my research, it seems that I can't access a database using Javascript, and I also can't access a local JSON file. Is there another way to have this data stored and be able to be updated and saved? Do I need to create a Java servlet just so that I can read/write a JSON file? (Java is the only backend I know so far, but if there's something else that will make it easier, let me know!) Is this the time to learn one of these mysterious frameworks everyone's on about?&lt;/p&gt;

&lt;p&gt;My other alternative is to give in and do the whole thing in Java, but I'd like to have the possibility of putting it online eventually rather than having it tied into a desktop app.&lt;/p&gt;

&lt;p&gt;Any advice?&lt;/p&gt;

</description>
      <category>help</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>java</category>
    </item>
    <item>
      <title>Isolation and community</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Thu, 04 Apr 2019 08:43:05 +0000</pubDate>
      <link>https://forem.com/smh30/isolation-and-community-3gma</link>
      <guid>https://forem.com/smh30/isolation-and-community-3gma</guid>
      <description>&lt;p&gt;I had a blessed introduction into this field, so I'm a bit delayed in discovering how isolating it can feel - but boy, it's hitting me recently. This post isn't necessarily about coding but maybe more about the university experience, so I'm not sure that this is the right venue for it - but I still feel like writing it is worthwhile for me.&lt;/p&gt;

&lt;p&gt;Over the summer I took a 12 week intensive course, and despite going in with fears that everyone else would be stereotypical 'computer guys' lacking social skills and I wouldn't connect with anyone, that didn't eventuate. In fact, of the nine students who finished the course seven were women, and by the end of the semester the whole class felt like friends (or to some extent like we'd been through a war together 😅)&lt;/p&gt;

&lt;p&gt;At the end of that course, while chatting with our teacher he mentioned that at least our further studies (seven of us continued to the follow-up course, which is more of a typical University experience) would be less intense. I suppose that in terms of sheer hours required that's been the case, but I've found this semester so far much more stressful. The summer course was one cohesive unit, so the workload was balanced and controlled by a single teacher as opposed to the times now when four lecturers set assignments due at the same time - as well as the fact that the practical, coding assignments over the summer were much more enjoyable and felt more relevant than writing research reports and giving presentations.&lt;/p&gt;

&lt;p&gt;What's really making it feel harder for me, though, is the loss of the camaraderie of my summer course-mates. Helping each other and commiserating through the tough parts was hugely more comfortable than showing up at lectures, sitting in silence, then leaving alone. I realised last week that there have been many days where I didn't have a single reciprocal human interaction - to the point where being asked for directions on campus was a highlight of my day.&lt;/p&gt;

&lt;p&gt;As a shy person, I find it hard to know how to counteract this situation, especially at this point in the semester - maybe in the first week it makes sense to start up a conversation with someone new, but not so much half-way through. I feel an extra level of inadequacy as most of my classmates have completed a full CS degree rather than the 12 week course I did, so I'm constantly doubting my usefulness.&lt;/p&gt;

&lt;p&gt;The reason this is on my mind tonight in particular is that I had my first experience of feeling like a part of the 'I.T. community' tonight. While I was working on an assignment at Starbucks, a man who'd seen what I was working on came up to me asking if I was a web developer. He was a self-taught student, complete with a textbook in his hand. We had a chat (after I disabused him of the notion that I know anything) about how hard it is to learn things in such a broad field, and about the scariness of the job market, among other things. It was so nice to feel less alone in this journey for a while, even if we're taking different paths.&lt;/p&gt;

&lt;p&gt;Being a failboat, I didn't write down his name or get his contact details, but: if you're reading this, man from Starbucks in Hamilton, I believe in you! And thanks for helping me believe in myself just a bit more as well.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>personal</category>
      <category>community</category>
    </item>
    <item>
      <title>Nevertheless, Stephanie Coded</title>
      <dc:creator>Stephanie Hope</dc:creator>
      <pubDate>Fri, 08 Mar 2019 19:44:56 +0000</pubDate>
      <link>https://forem.com/smh30/nevertheless-stephanie-coded--3mk6</link>
      <guid>https://forem.com/smh30/nevertheless-stephanie-coded--3mk6</guid>
      <description>&lt;h2&gt;
  
  
  I started to code in late 2018 because...
&lt;/h2&gt;

&lt;p&gt;I loved the idea of a job where I could point at something and say "I helped make that". Coming from an analytical laboratory background, that wasn't something that often happened, and I was looking for a change.&lt;/p&gt;

&lt;h2&gt;
  
  
  I deserve credit for...
&lt;/h2&gt;

&lt;p&gt;Taking the plunge and leaving my job of many years to go back to University. The course I took over the summer was a 12-week bootcamp-style course in web development and Java, and I passed with an A+. I'm now studying towards a Masters in Information Technology, at age 32.&lt;/p&gt;

&lt;h2&gt;
  
  
  I hope to see my school/work/developer/tech community...
&lt;/h2&gt;

&lt;p&gt;Continue to improve in its inclusion of women and minorities. I was encouraged (and, sadly, surprised) that my class of 9 students over the summer consisted of 7 women and only 2 men. But I note that every industry speaker who gave a talk to us was a white male. I'd like to see more diverse mentors being invited by the University.&lt;/p&gt;

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