{
  "path": "/3m6zt4zk2cs22",
  "site": "at://did:plc:5qartdsce62n2wfyvtocmoob/site.standard.publication/3m6zsvqqgmk2p",
  "$type": "site.standard.document",
  "title": "advent of code: day 1",
  "content": {
    "$type": "pub.leaflet.content",
    "pages": [
      {
        "id": "019ae0d2-d7ca-7220-b325-ff635ffbebc3",
        "$type": "pub.leaflet.pages.linearDocument",
        "blocks": [
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.text",
              "facets": [],
              "plaintext": "I have not done anything like this since the last advent of code, and so felt very rusty trying to solve this one. "
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.code",
              "language": "typescript",
              "plaintext": "if (direction === \"L\") {\n   clicksToZero = position || 100;\n}",
              "syntaxHighlightingTheme": "kanagawa-dragon"
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.text",
              "facets": [
                {
                  "index": {
                    "byteEnd": 238,
                    "byteStart": 236
                  },
                  "features": [
                    {
                      "$type": "pub.leaflet.richtext.facet#code"
                    }
                  ]
                }
              ],
              "plaintext": "This is what really tripped me up as an edge case, if you start on 0 & move left, it's really 100 to zero, not 99. my answer kept being 2 short. two!!!!! and then this is just a lil trick that if it's false-y (which 0 is) then actually || it's 100 now ✨"
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.text",
              "facets": [],
              "plaintext": "tldr, final code with all of my comments:"
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.code",
              "language": "typescript",
              "plaintext": "import { sampleTurns, turns } from \"./input\";\n\nlet dialLocation: number = 50;\nlet zeroCount: number = 0;\n\nfunction clicksToZero(\n  direction: string,\n  position: number,\n  distance: number,\n): number {\n  let clicksToZero: number, remainingClicks: number;\n\n  if (direction === \"L\") {\n    clicksToZero = position || 100;\n  }\n\n  if (direction === \"R\") {\n    clicksToZero = 100 - position;\n  }\n\n  remainingClicks = distance - clicksToZero;\n\n  if (distance < clicksToZero) {\n    return 0;\n  }\n\n  return 1 + Math.floor(remainingClicks / 100);\n}\n\nfunction turnDial(instruction: string) {\n  // should do this in input.ts tomorrow\n  const direction = instruction.substring(0, 1);\n  const distanceNum = parseInt(instruction.replace(direction, \"\"), 10);\n\n  // calculate the number of times we'll hit zero, before we move the dial (!! important in step two !!)\n  zeroCount += clicksToZero(direction, dialLocation, distanceNum);\n\n  if (direction === \"L\") {\n    dialLocation -= distanceNum;\n  } else if (direction === \"R\") {\n    dialLocation += distanceNum;\n  }\n\n  dialLocation = ((dialLocation % 100) + 100) % 100;\n\n  console.log(\"After turn:\", direction, distanceNum);\n  console.log(\"Current dial location:\", dialLocation);\n}\n\nfunction solveCode() {\n  const data = turns;\n  // const data = sampleTurns;\n  data.forEach(turnDial);\n  console.log(\"The number of times the dial landed on zero:\", zeroCount);\n}\n\nsolveCode();\n",
              "syntaxHighlightingTheme": "kanagawa-dragon"
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.text",
              "facets": [],
              "plaintext": ""
            }
          },
          {
            "$type": "pub.leaflet.pages.linearDocument#block",
            "block": {
              "$type": "pub.leaflet.blocks.text",
              "facets": [],
              "plaintext": ""
            }
          }
        ]
      }
    ]
  },
  "description": "the elves have already caused too much chaos in my life",
  "publishedAt": "2025-12-02T20:52:26.527Z"
}