<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javascript on May&#39;s Blog</title>
    <link>https://maymeow.blog/tags/javascript/</link>
    <description>Recent content in Javascript on May&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    <copyright>Copyright © 2020, May Meow.</copyright>
    <lastBuildDate>Fri, 05 Dec 2025 09:55:54 +0200</lastBuildDate>
    <atom:link href="https://maymeow.blog/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>🎄 Advent of Code &#39;25 Day 5: Cafeteria</title>
      <link>https://maymeow.blog/posts/aoc25-day5-cafeteria/</link>
      <pubDate>Fri, 05 Dec 2025 09:55:54 +0200</pubDate>
      <guid>https://maymeow.blog/posts/aoc25-day5-cafeteria/</guid>
      <description>&lt;p&gt;Day 5 felt like running a little data pipeline: we ingest ranges, normalize them, and answer two slightly different queries.&lt;/p&gt;&#xA;&lt;h2 id=&#34;part-1--checking-the-available-ids&#34;&gt;Part 1 – Checking the available IDs&lt;/h2&gt;&#xA;&lt;p&gt;The database lists “fresh” ID ranges followed by a blank line and then the list of available items we need to classify. My approach:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Parse the ranges and IDs.&lt;/li&gt;&#xA;&lt;li&gt;Sort and merge overlapping or adjacent ranges so we end up with disjoint intervals.&lt;/li&gt;&#xA;&lt;li&gt;For each ID, run a binary search to see whether it lands inside any merged interval.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; Merging ranges costs &lt;code&gt;O(R log R)&lt;/code&gt; where &lt;code&gt;R&lt;/code&gt; is the number of range lines. Each ID lookup is &lt;code&gt;O(log R)&lt;/code&gt;, so the total runtime is &lt;code&gt;O(R log R + I log R)&lt;/code&gt;; memory stays &lt;code&gt;O(R)&lt;/code&gt; for the merged intervals.&lt;/p&gt;</description>
    </item>
    <item>
      <title>🎄 Advent of Code &#39;25 Day 4: Printing Department</title>
      <link>https://maymeow.blog/posts/aoc25-day4-printing-department/</link>
      <pubDate>Thu, 04 Dec 2025 08:23:54 +0200</pubDate>
      <guid>https://maymeow.blog/posts/aoc25-day4-printing-department/</guid>
      <description>&lt;p&gt;Forklifts, paper rolls, and lots of adjacency checks: Day 4 turned into a neat graph-like puzzle. Here’s how I solved both parts and what their complexity looks like.&lt;/p&gt;&#xA;&lt;h2 id=&#34;part-1--finding-accessible-rolls&#34;&gt;Part 1 – Finding accessible rolls&lt;/h2&gt;&#xA;&lt;p&gt;Each roll of paper is represented by &lt;code&gt;@&lt;/code&gt; on a grid. A roll is accessible if fewer than four of the eight neighboring cells also contain rolls. The solver:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Parses the grid from &lt;code&gt;input.txt&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Walks every cell; when it finds an &lt;code&gt;@&lt;/code&gt;, it counts the occupied neighbors using the eight-direction offsets.&lt;/li&gt;&#xA;&lt;li&gt;Increments the answer whenever the neighbor count is &lt;code&gt;&amp;lt; 4&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; Let the grid be &lt;code&gt;H x W&lt;/code&gt;. We inspect each cell once and examine up to eight neighbors, so runtime is &lt;code&gt;O(H * W)&lt;/code&gt; with &lt;code&gt;O(1)&lt;/code&gt; auxiliary memory.&lt;/p&gt;</description>
    </item>
    <item>
      <title>🎄 Advent of Code &#39;25 Day 3: Lobby</title>
      <link>https://maymeow.blog/posts/aoc25-day3-lobby/</link>
      <pubDate>Wed, 03 Dec 2025 11:23:54 +0200</pubDate>
      <guid>https://maymeow.blog/posts/aoc25-day3-lobby/</guid>
      <description>&lt;p&gt;I spent Day 3 hanging out in the lobby with a pile of battery banks and a stubborn escalator. Here is how I cracked both puzzles using a pair of lean JavaScript scripts (&lt;code&gt;part1.js&lt;/code&gt; and &lt;code&gt;part2.js&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;h2 id=&#34;part-1--two-batteries-one-number&#34;&gt;Part 1 – Two batteries, one number&lt;/h2&gt;&#xA;&lt;p&gt;Each bank is a string of digits. I needed the largest possible two-digit value that preserves order. Rather than evaluate every pair, I sweep the string once while tracking the best &amp;ldquo;first&amp;rdquo; digit seen so far. Every new digit forms a candidate pair with that best digit; if the candidate beats the running maximum, I store it, and if the new digit is even better as a first digit, I promote it. This greedy pass extracts the answer for a bank in linear time.&lt;/p&gt;</description>
    </item>
    <item>
      <title>🎄 Advent of Code &#39;25 Day 2: Gift Shop</title>
      <link>https://maymeow.blog/posts/aoc25-day2-gift-shop/</link>
      <pubDate>Tue, 02 Dec 2025 09:07:54 +0200</pubDate>
      <guid>https://maymeow.blog/posts/aoc25-day2-gift-shop/</guid>
      <description>&lt;p&gt;Day 2 was all about spotting playful ID patterns inside huge numerical ranges. Here’s how both parts came together.&lt;/p&gt;&#xA;&lt;h2 id=&#34;input-parsing-shared-by-both-parts&#34;&gt;Input parsing shared by both parts&lt;/h2&gt;&#xA;&lt;p&gt;The puzzle input is one comma-separated line of inclusive ranges (&lt;code&gt;start-end&lt;/code&gt;). I parse everything as &lt;code&gt;BigInt&lt;/code&gt; so that the gigantic IDs stay precise. After that, each part does its own math on top of the same parsed data.&lt;/p&gt;&#xA;&lt;h2 id=&#34;part-1--double-half-ids&#34;&gt;Part 1 – Double-half IDs&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Condition.&lt;/strong&gt; An ID is invalid if it is exactly two copies of some digit string (e.g., &lt;code&gt;64 64&lt;/code&gt;). If the repeated block has length &lt;code&gt;h&lt;/code&gt;, then the ID equals &lt;code&gt;pattern * 10^h + pattern&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>🎄 Advent of Code &#39;25 Day 1: Secret Entrance</title>
      <link>https://maymeow.blog/posts/aoc25-day1-secret-entrance/</link>
      <pubDate>Mon, 01 Dec 2025 10:02:54 +0200</pubDate>
      <guid>https://maymeow.blog/posts/aoc25-day1-secret-entrance/</guid>
      <description>&lt;p&gt;For Day 1 I had to open a safe with a dial numbered 0–99. Here’s how both halves of the puzzle fell.&lt;/p&gt;&#xA;&lt;h2 id=&#34;part-1--counting-end-of-rotation-zeros&#34;&gt;Part 1 – Counting end-of-rotation zeros&lt;/h2&gt;&#xA;&lt;p&gt;The dial starts at 50 and each instruction looks like &lt;code&gt;L68&lt;/code&gt; or &lt;code&gt;R48&lt;/code&gt;. I only needed to know how many times the dial ended on 0 &lt;strong&gt;after finishing&lt;/strong&gt; each rotation.&lt;/p&gt;&#xA;&lt;p&gt;Implementation notes:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Parse every instruction once.&lt;/li&gt;&#xA;&lt;li&gt;Track the current dial position; rotate by converting &lt;code&gt;L&lt;/code&gt; to negative steps and &lt;code&gt;R&lt;/code&gt; to positive steps.&lt;/li&gt;&#xA;&lt;li&gt;Apply the delta with &lt;code&gt;(position + delta) mod 100&lt;/code&gt; keeping values non-negative.&lt;/li&gt;&#xA;&lt;li&gt;Increment the answer whenever the resulting position equals 0.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;This runs in O(n) with n rotations and needs only a handful of integers.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
