{"id":22631604,"url":"https://github.com/alexandramartinez/adventofcode-2024","last_synced_at":"2026-03-19T23:17:07.404Z","repository":{"id":265919525,"uuid":"896867638","full_name":"alexandramartinez/adventofcode-2024","owner":"alexandramartinez","description":"DataWeave scripts used in the adventofcode.com site for 2024.","archived":false,"fork":false,"pushed_at":"2025-02-15T02:24:42.000Z","size":296,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T03:22:27.059Z","etag":null,"topics":["advent-of-code","advent-of-code-2024","advent-of-code-2024-dataweave","adventofcode","adventofcode2024","challenge","challenges","dataweave","dataweave-lang","dataweave-language","dataweave-playground","programming","programming-challenges","programming-exercises","programming-language","programming-languages"],"latest_commit_sha":null,"homepage":"https://adventofcode.com/2024","language":"DataWeave","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexandramartinez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-01T13:58:28.000Z","updated_at":"2025-02-15T02:24:45.000Z","dependencies_parsed_at":"2024-12-01T15:19:29.508Z","dependency_job_id":"89e248a1-fd8b-49b2-a863-1d5da106da20","html_url":"https://github.com/alexandramartinez/adventofcode-2024","commit_stats":null,"previous_names":["alexandramartinez/adventofcode-2024"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2024","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2024/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2024/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2024/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexandramartinez","download_url":"https://codeload.github.com/alexandramartinez/adventofcode-2024/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246136389,"owners_count":20729167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advent-of-code","advent-of-code-2024","advent-of-code-2024-dataweave","adventofcode","adventofcode2024","challenge","challenges","dataweave","dataweave-lang","dataweave-language","dataweave-playground","programming","programming-challenges","programming-exercises","programming-language","programming-languages"],"created_at":"2024-12-09T02:10:05.549Z","updated_at":"2026-02-27T19:40:26.122Z","avatar_url":"https://github.com/alexandramartinez.png","language":"DataWeave","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advent of Code 2024\n\nDataWeave scripts used in the [adventofcode.com](https://adventofcode.com/) site for 2024.\n\nI used the [DataWeave extension for VS Code](https://marketplace.visualstudio.com/items?itemName=MuleSoftInc.dataweave) to create these scripts. Most of them should run in the [DataWeave Playground](https://dataweave.mulesoft.com/learn/dataweave) with no issue. However, some of the more complex examples have to run with the [DataWeave CLI](https://github.com/mulesoft-labs/data-weave-cli).\n\nTo run any script with the CLI, you can use the following syntax (or use my [ProstDev Tools](https://marketplace.visualstudio.com/items?itemName=ProstDev.prostdev-tools) VSCode extension):\n\n```shell\ndw run -i payload=\u003cpath to payload file\u003e -f \u003cpath to transform.dwl file\u003e\n```\n\nFor example:\n\n```shell\ndw run -i payload=scripts/day1/part1/inputs/payload.csv -f scripts/day1/part1/transform.dwl\n```\n\nIf there's no input, just remove the `-i payload=\u003cfile\u003e` part.\n\nYou can filter the challenges using one of the following keywords (ctrl+F or cmd+F):\n- Keywords: `csv`, `math`, `regex`, `reduce`, `strings`, `lines`, `matrix`, `ordering`, `two inputs`, `rules`, `navigation`, `recursive`, `tree`, `comparisons/matching`\n\n\u003e [!TIP]\n\u003e Check out [Ryan's private leaderboard](https://adventofcode.com/2024/leaderboard/private/view/1739830)!\n\n## Similar repos\n\n[![](https://github-readme-stats.vercel.app/api/pin/?username=alexandramartinez\u0026repo=adventofcode-2023\u0026theme=neon)](https://github.com/alexandramartinez/adventofcode-2023)\n[![](https://github-readme-stats.vercel.app/api/pin/?username=alexandramartinez\u0026repo=adventofcode-2022\u0026theme=neon)](https://github.com/alexandramartinez/adventofcode-2022)\n\n## Table of Contents\n\nTotal stars: ⭐️ 31 / 50 \n\n![](https://progress-bar.xyz/62?width=500)\n\n- ⭐️⭐️ [Day 1](#-day-1)\n- ⭐️⭐️ [Day 2](#-day-2)\n- ⭐️⭐️ [Day 3](#-day-3)\n- ⭐️⭐️ [Day 4](#-day-4)\n- ⭐️ [Day 5](#-day-5)\n- ⭐️ [Day 6](#-day-6)\n- ⭐️⭐️ [Day 7](#-day-7)\n- ⭐️⭐️ [Day 8](#-day-8)\n- ⭐️ [Day 9](#-day-9)\n- ⭐️⭐️ [Day 10](#-day-10)\n- ⭐️⭐️ [Day 11](#-day-11)\n- ⭐️⭐️ [Day 12](#-day-12)\n- ⭐️⭐️ [Day 13](#-day-13)\n- ⭐️⭐️ [Day 14](#-day-14)\n- ⭐️ [Day 15](#-day-15)\n- Day 16\n- Day 17\n- Day 18\n- ⭐️ [Day 19](#-day-19)\n- Day 20\n- Day 21\n- Day 22\n- ⭐️⭐️ [Day 23](#-day-23)\n- ⭐️ [Day 24](#-day-24)\n- ⭐️ [Day 25](#-day-25)\n\n## 🔹 Day 1\n\n- Challenge: [Historian Hysteria](https://adventofcode.com/2024/day/1)\n- Keywords: `csv`, `math`\n- Example input:\n\n    ```\n    3   4\n    4   3\n    2   5\n    1   3\n    3   9\n    3   3\n    ```\n\n\u003c/details\u003e\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\ninput payload application/csv separator=\" \", header=false\noutput application/json\nvar a = payload.column_0 orderBy $\nvar b = payload.column_3 orderBy $\n---\n(0 to sizeOf(a)-1) map (abs(a[$] - b[$])) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday1%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport countBy from dw::core::Arrays\nvar p = read(payload, \"application/csv\", {header:false,separator:\" \"})\nvar a = p.column_0\nvar b = p.column_3\n---\na map ((item) -\u003e \n    (b countBy ($==item)) * item\n) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday1%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 2\n\n- Challenge: [Red-Nosed Reports](https://adventofcode.com/2024/day/2)\n- Keywords: `reduce`, `lines`\n- Example input:\n\n```\n7 6 4 2 1\n1 2 7 8 9\n9 7 6 2 1\n1 3 2 4 5\n8 6 4 4 1\n1 3 6 7 9\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport every, countBy from dw::core::Arrays\nvar decreasing = \"decreasing\"\nvar increasing = \"increasing\"\n---\n((payload splitBy \"\\n\") map (\n    (($ splitBy \" \") reduce ((number, a=[]) -\u003e \n        if (isEmpty(a)) a+{\n            prevNum: number,\n            operation: null,\n            isSafe: true\n        } else (a[-1].operation match {\n            case null -\u003e a+{\n                prevNum: number,\n                operation: if (a[-1].prevNum-number \u003e 0) decreasing else increasing,\n                isSafe: [1, 2, 3] contains abs(a[-1].prevNum - number) \n            }\n            case \"$(decreasing)\" -\u003e a+{\n                prevNum: number,\n                operation: a[-1].operation,\n                isSafe: [1, 2, 3] contains (a[-1].prevNum - number)\n            }\n            else -\u003e a+{\n                prevNum: number,\n                operation: a[-1].operation,\n                isSafe: [1, 2, 3] contains (number - a[-1].prevNum)\n            }\n        })\n    )).isSafe every $\n)) countBy $\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday2%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\nHorrible code. But I did what I had to do :(\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport every, countBy from dw::core::Arrays\nvar decreasing = \"decreasing\"\nvar increasing = \"increasing\"\nvar newp = ((payload splitBy \"\\n\") map (\n    (($ splitBy \" \") reduce ((number, a=[]) -\u003e \n        if (isEmpty(a)) a+{\n            prevNum: number,\n            operation: null,\n            isSafe: true\n        } else (a[-1].operation match {\n            case null -\u003e a+{\n                prevNum: number,\n                operation: if (a[-1].prevNum-number \u003e 0) decreasing else increasing,\n                isSafe: [1, 2, 3] contains abs(a[-1].prevNum - number) \n            }\n            case \"$(decreasing)\" -\u003e a+{\n                prevNum: number,\n                operation: a[-1].operation,\n                isSafe: [1, 2, 3] contains (a[-1].prevNum - number)\n            }\n            else -\u003e a+{\n                prevNum: number,\n                operation: a[-1].operation,\n                isSafe: [1, 2, 3] contains (number - a[-1].prevNum)\n            }\n        })\n    ))\n))\nvar safeOnes = newp filter ((item) -\u003e item.isSafe every $)\nvar unsafeOnes = newp -- safeOnes\nfun getScenarios(data) = data map ($ reduce ((number, a=[]) -\u003e\n    if (isEmpty(a)) a+{\n        prevNum: number,\n        operation: null,\n        isSafe: true\n    } else (a[-1].operation match {\n        case null -\u003e a+{\n            prevNum: number,\n            operation: if (a[-1].prevNum-number \u003e 0) decreasing else increasing,\n            isSafe: [1, 2, 3] contains abs(a[-1].prevNum - number) \n        }\n        case \"$(decreasing)\" -\u003e a+{\n            prevNum: number,\n            operation: a[-1].operation,\n            isSafe: [1, 2, 3] contains (a[-1].prevNum - number)\n        }\n        else -\u003e a+{\n            prevNum: number,\n            operation: a[-1].operation,\n            isSafe: [1, 2, 3] contains (number - a[-1].prevNum)\n        }\n    })\n))\n---\nunsafeOnes map ((firstArray) -\u003e \n    getScenarios(firstArray.prevNum map ((number, numIndex) -\u003e \n        firstArray.prevNum filter ((item, index) -\u003e index != numIndex)\n    )) filter ((item) -\u003e item.isSafe every $)\n) filter (!isEmpty($)) \nthen sizeOf($)+sizeOf(safeOnes)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday2%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 3\n\n- Challenge: [Mull It Over](https://adventofcode.com/2024/day/3)\n- Keywords: `regex`, `reduce`, `strings`\n- Example inputs:\n\n```\nxmul(2,4)%\u0026mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))\n```\n\n```\nxmul(2,4)\u0026mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n(flatten(payload scan /mul\\(\\d+,\\d+\\)/)) map do {\n    var nums = flatten($ scan /\\d+/)\n    ---\n    nums[0] * nums[1]\n} then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday3%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n(payload scan /(mul|don't|do)\\(\\d*,?\\d*\\)/) reduce ((op, a={r:0,\"do\":true}) -\u003e \n    op[0][0 to 2] match {\n        case \"mul\" -\u003e do {\n            var nums = flatten(op[0] scan /\\d+/)\n            var newR = a.r + ((nums[0] default 0) * (nums[1] default 0))\n            ---\n            {\n                r: if (a.\"do\") newR else a.r,\n                \"do\": a.\"do\"\n            }\n        }\n        case \"don\" -\u003e { r: a.r, \"do\": false }\n        else -\u003e { r: a.r, \"do\": true }\n    }\n) then $.r\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday3%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 4\n\n- Challenge: [Ceres Search](https://adventofcode.com/2024/day/4)\n- Keywords: `matrix`\n- Example inputs:\n\n```\nMMMSXXMASM\nMSAMXMSMSA\nAMXSXMAAMM\nMSAMASMSMX\nXMASAMXAMM\nXXAMMXXAMA\nSMSMSASXSS\nSAXAMASAAA\nMAMMMXMMMM\nMXMXAXMASX\n```\n\n```\nM.S\n.A.\nM.S\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nvar lines = payload splitBy \"\\n\"\nvar XMAS = \"XMAS\"\nfun getLetter(x:Number,y:Number) = if ((x\u003c0) or (y\u003c0)) \"\" else (lines[x][y] default \"\")\nfun getStr(str:String,x:Number,y:Number) = if ((x\u003c0) or (y\u003c0)) \"\" else (str[x to y])\n---\nflatten\n(lines map ((lineStr, lineidx) -\u003e \n    (lineStr splitBy \"\") map ((letter, letteridx) -\u003e\n        if (letter==\"X\") (\n            // right\n            (if (XMAS == getStr(lineStr,letteridx,letteridx+3)) 1 else 0)\n            // left\n            + (if (XMAS == getStr(lineStr,letteridx,letteridx-3)) 1 else 0)\n            // down\n            + (if (XMAS == (letter ++ getLetter(lineidx+1,letteridx) ++ getLetter(lineidx+2,letteridx) ++ getLetter(lineidx+3,letteridx))) 1 else 0)\n            // // up\n            + (if (XMAS == (letter ++ getLetter(lineidx-1,letteridx) ++ getLetter(lineidx-2,letteridx) ++ getLetter(lineidx-3,letteridx))) 1 else 0)\n            // down-right\n            + (if (XMAS == (letter ++ getLetter(lineidx+1,letteridx+1) ++ getLetter(lineidx+2,letteridx+2) ++ getLetter(lineidx+3,letteridx+3))) 1 else 0)\n            // down-left\n            + (if (XMAS == (letter ++ getLetter(lineidx+1,letteridx-1) ++ getLetter(lineidx+2,letteridx-2) ++ getLetter(lineidx+3,letteridx-3))) 1 else 0)\n            // up-right\n            + (if (XMAS == (letter ++ getLetter(lineidx-1,letteridx+1) ++ getLetter(lineidx-2,letteridx+2) ++ getLetter(lineidx-3,letteridx+3))) 1 else 0)\n            // up-left\n            + (if (XMAS == (letter ++ getLetter(lineidx-1,letteridx-1) ++ getLetter(lineidx-2,letteridx-2) ++ getLetter(lineidx-3,letteridx-3))) 1 else 0)\n        )\n        else 0\n    )\n)) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday4%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nvar lines = payload splitBy \"\\n\"\nfun getLetter(x:Number,y:Number) = if ((x\u003c0) or (y\u003c0)) \"\" else (lines[x][y] default \"\")\nvar xmas = [\"MAS\", \"SAM\"]\n---\nflatten\n(lines map ((lineStr, lineidx) -\u003e \n    (lineStr splitBy \"\") map ((letter, letteridx) -\u003e\n        if (letter==\"A\") do {\n            var topleft = getLetter(lineidx-1, letteridx-1)\n            var topright = getLetter(lineidx-1, letteridx+1)\n            var bottomleft = getLetter(lineidx+1, letteridx-1)\n            var bottomright = getLetter(lineidx+1, letteridx+1)\n            var cross1 = topleft ++ letter ++ bottomright\n            var cross2 = topright ++ letter ++ bottomleft\n            ---\n            if ( (xmas contains cross1) and (xmas contains cross2) ) 1 else 0\n        }\n        else 0\n    )\n)) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday4%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 5\n\n- Challenge: [Print Queue](https://adventofcode.com/2024/day/5)\n- Keywords: `lines`, `ordering`, `two inputs`, `rules`\n- Example input:\n\n```\n47|53\n97|13\n97|61\n97|47\n75|29\n61|13\n75|53\n29|13\n97|29\n53|29\n61|53\n97|53\n61|29\n47|13\n75|47\n97|75\n47|61\n75|61\n47|29\n75|13\n53|13\n\n75,47,61,53,29\n97,61,53,29,13\n75,29,13\n75,97,47,61,53\n61,13,29\n97,13,75,29,47\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport every from dw::core::Arrays\nimport substringBefore, substringAfter from dw::core::Strings\nvar p = payload splitBy \"\\n\\n\"\nvar orderingRules = p[0]\nvar updatesLines = p[1]splitBy \"\\n\"\nfun flatScan(a,b) = flatten(a scan b)\n---\nupdatesLines map ((line, lineidx) -\u003e do {\n    var arr = (line splitBy \",\")\n    var isCorrect = (arr map ((num, numindex) -\u003e \n        ((orderingRules flatScan \"$(num)\\|\\d+|\\d+\\|$(num)\") map (\n            ((arr[numindex+1 to -1] default \"\") contains ($ substringBefore \"|\"))\n            or ((if(numindex==0) \"\" else arr[numindex-1 to 0]) contains ($ substringAfter \"|\"))\n        )) every (!$)\n    )) every ($)\n    ---\n    if (isCorrect) arr[round(sizeOf(arr)/2)-1] as Number\n    else 0\n}) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday5%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 6\n\n- Challenge: [Guard Gallivant](https://adventofcode.com/2024/day/6)\n- Keywords: `matrix`, `navigation`, `recursive`\n- Example input:\n\n```\n....#.....\n.........#\n..........\n..#.......\n.......#..\n..........\n.#..^.....\n........#.\n#.........\n......#...\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\ntype Coordinates = {x:Number,y:Number}\nvar matrix = (payload splitBy \"\\n\") map ($ splitBy \"\")\nvar guardPositions = [\"^\", \"\u003c\", \"\u003e\", \"v\"]\nfun getChar(matrix:Array\u003cArray\u003cString\u003e\u003e,y:Number,x:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (matrix[y][x] default \"\")\nfun turnGuard(guard:String):String = guard match {\n    case \"^\" -\u003e \"\u003e\"\n    case \"\u003e\" -\u003e \"v\"\n    case \"v\" -\u003e \"\u003c\"\n    case \"\u003c\" -\u003e \"^\"\n}\nfun getInFrontCoord(guard:String,y:Number,x:Number):Coordinates = guard match {\n    case \"^\" -\u003e {y:y-1,x:x}\n    case \"\u003e\" -\u003e {y:y,x:x+1}\n    case \"\u003c\" -\u003e {y:y,x:x-1}\n    case \"v\" -\u003e {y:y+1,x:x}\n}\nfun getRoute(matrix:Array, coords=[]) = flatten(matrix map ((line, lineindex) -\u003e \n    flatten(line map ((char, charindex) -\u003e do {\n        @Lazy\n        var inFrontCoords = getInFrontCoord(char, lineindex, charindex)\n        @Lazy\n        var inFrontChar = getChar(matrix,inFrontCoords.y, inFrontCoords.x)\n        @Lazy\n        var guardCoords:Coordinates = {x:charindex,y:lineindex}\n        ---\n        if (guardPositions contains char) inFrontChar match {\n            case \".\" -\u003e getRoute(matrix update {\n                case c at [inFrontCoords.y][inFrontCoords.x] -\u003e char\n                case g at [guardCoords.y][guardCoords.x] -\u003e \".\"\n            }, coords + guardCoords)\n            case \"#\" -\u003e getRoute(matrix update {\n                case g at [guardCoords.y][guardCoords.x] -\u003e turnGuard(char)\n            }, coords)\n            else -\u003e coords\n        }\n        else null\n    }))\n))\n---\nsizeOf(getRoute(matrix) distinctBy $)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday6%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 7\n\n- Challenge: [Bridge Repair](https://adventofcode.com/2024/day/7)\n- Keywords: `math`, `lines`, `recursive`, `tree`\n- Example input:\n\n```\n190: 10 19\n3267: 81 40 27\n83: 17 5\n156: 15 6\n7290: 6 8 6 15\n161011: 16 10 13\n192: 17 8 14\n21037: 9 7 18 13\n292: 11 6 16 20\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport drop from dw::core::Arrays\nimport lines from dw::core::Strings\nfun flatScan(a, b) = flatten(a scan b)\nfun getResults(values, r=0) = do {\n    var this = values[0]\n    var next = values[1]\n    var newValues = values drop 1\n    ---\n    if (isEmpty(next)) r\n    else if (r==0) flatten([getResults(newValues, this+next), getResults(newValues, this*next)])\n    else flatten([getResults(newValues, r+next),  getResults(newValues, r*next)])\n}\n---\nlines(payload) map ((equation, equationIndex) -\u003e do {\n    var nums = equation flatScan /\\d+/\n    var result = nums[0] as Number\n    var values = nums[1 to -1] map ($ as Number)\n    ---\n    if (getResults(values) contains result) result else 0\n}) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday7%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport drop from dw::core::Arrays\nimport lines from dw::core::Strings\nfun flatScan(a, b) = flatten(a scan b)\nfun getResults(values, r=0) = do {\n    var this = values[0]\n    var next = values[1]\n    var newValues = values drop 1\n    ---\n    if (isEmpty(next)) r\n    else if (r==0) flatten([getResults(newValues, this+next), getResults(newValues, this*next), getResults(newValues, \"$this$next\" as Number)])\n    else flatten([getResults(newValues, r+next),  getResults(newValues, r*next), getResults(newValues, \"$r$next\" as Number)])\n}\n---\nlines(payload) map ((equation, equationIndex) -\u003e do {\n    var nums = equation flatScan /\\d+/\n    var result = nums[0] as Number\n    var values = nums[1 to -1] map ($ as Number)\n    ---\n    if (getResults(values) contains result) result else 0\n}) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday7%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 8\n\n- Challenge: [Resonant Collinearity](https://adventofcode.com/2024/day/8)\n- Keywords: `matrix`, `recursive`\n- Example input:\n\n```\n............\n........0...\n.....0......\n.......0....\n....0.......\n......A.....\n............\n............\n........A...\n.........A..\n............\n............\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport lines, isAlphanumeric from dw::core::Strings\noutput application/json\nfun getChar(arr:Array\u003cString\u003e,x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (arr[y][x] default \"\")\nfun isAntenna(char:String) = isAlphanumeric(char)\nfun getAntinodesBetween(coord1, coord2) = do {\n    var x1 = coord1.x + coord1.x - coord2.x\n    var y1 = coord1.y + coord1.y - coord2.y\n    var x2 = coord2.x + coord2.x - coord1.x\n    var y2 = coord2.y + coord2.y - coord1.y\n    ---\n    [\n        {\n            antinodeChar: getChar(payloadArr,x1,y1),\n            antinodeCoords: {\n                x: x1,\n                y: y1\n            }\n        },\n        {\n            antinodeChar: getChar(payloadArr,x2,y2),\n            antinodeCoords: {\n                x: x2,\n                y: y2\n            }\n        }\n    ]\n}\nvar payloadArr = lines(payload)\nvar antennas = flatten(payloadArr map ((line, y) -\u003e \n    (line splitBy \"\") map ((char, x) -\u003e \n        if (isAntenna(char)) {\n            char: char,\n            coords: {\n                x: x,\n                y: y,\n            }\n        } else {}\n    ) filter (!isEmpty($))\n) filter (!isEmpty($)))\n---\nantennas groupBy ($.char) \npluck ((frequencies, frequencyGroup, index) -\u003e do {\n    @Lazy\n    var sizeOfFrequencies = sizeOf(frequencies)\n    @Lazy\n    var numbers = 0 to sizeOfFrequencies-1\n    ---\n    if (sizeOfFrequencies \u003e= 2) \n        flatten(frequencies map ((frequency, fi) -\u003e \n            flatten((numbers - fi) map ((number) -\u003e \n                (getAntinodesBetween(frequency.coords,frequencies[number].coords) filter (!isEmpty($.antinodeChar)))\n            ))\n        ))\n    else []\n}) \nthen flatten($) distinctBy $ \nthen sizeOf($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday8%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport lines, isAlphanumeric from dw::core::Strings\noutput application/json\ntype Coords = {\n    x:Number,\n    y:Number\n}\ntype Frequency = {\n    char:String,\n    coords:Coords\n}\nfun getChar(arr:Array\u003cString\u003e,x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (arr[y][x] default \"\")\nfun isAntenna(char:String):Boolean = isAlphanumeric(char)\nfun getAntinodesBetween(coord1:Coords, coord2:Coords, times:Number) = do {\n    var x = coord1.x + ((times+1) * (coord2.x - coord1.x))\n    var y = coord1.y + ((times+1) * (coord2.y - coord1.y))\n    var char = getChar(payloadArr,x,y)\n    ---\n    [\n        ({\n            char: char,\n            coords: {\n                x: x,\n                y: y\n            }\n        }) if (!isEmpty(char)),\n    ] \n}\nvar payloadArr:Array\u003cString\u003e = lines(payload)\nvar antennas = flatten(payloadArr map ((line, y) -\u003e \n    (line splitBy \"\") map ((char, x) -\u003e \n        if (isAntenna(char)) {\n            char: char,\n            coords: {\n                x: x,\n                y: y,\n            }\n        } else {}\n    ) filter (!isEmpty($))\n) filter (!isEmpty($)))\nfun getAntinodes(frequencies,times=1,acc=[]) = do {\n    @Lazy\n    var sizeOfFrequencies = sizeOf(frequencies)\n    @Lazy\n    var numbers = 0 to sizeOfFrequencies-1\n    @Lazy\n    var newFrequencies = flatten(frequencies map ((frequency, fi) -\u003e \n            flatten((numbers - fi) map ((number) -\u003e \n                (getAntinodesBetween(frequency.coords, frequencies[number].coords, times))\n            ))\n        ))\n    ---\n    if ((sizeOfFrequencies \u003e= 2) and !isEmpty(newFrequencies))\n        getAntinodes(frequencies,times+1,acc ++ newFrequencies)\n    else acc\n}\n---\nantennas groupBy ($.char) \npluck ((frequencies) -\u003e do {\n    frequencies ++ getAntinodes(frequencies)\n}) \nthen flatten($) distinctBy $ \nthen sizeOf($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday8%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 9\n\n- Challenge: [Disk Fragmenter](https://adventofcode.com/2024/day/9)\n- Keywords: `reduce`, `strings`, `lines`\n- Example input:\n\n```\n2333133121414131402\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport divideBy from dw::core::Arrays\nvar p = (payload splitBy \"\")\nfun repeat(text: String, times: Number): Array =\n    if(times \u003c= 0) [] else (1 to times) map text\nvar files:Array = flatten((p divideBy 2) map ((item, index) -\u003e \n    repeat(index, item[0]) ++ repeat(\".\", item[1] default 0)\n))\nvar filesClean:Array = files - \".\"\nvar thisthing = (files reduce ((item, acc={ r:[], idx:-1 }) -\u003e item match {\n    case \".\" -\u003e {\n        r: acc.r + filesClean[acc.idx],\n        idx: acc.idx - 1\n    }\n    else -\u003e {\n        r: acc.r + item,\n        idx: acc.idx\n    }\n}))\n---\nthisthing.r[0 to thisthing.idx] map ($*$$) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday9%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 10\n\n- Challenge: [Hoof It](https://adventofcode.com/2024/day/10)\n- Keywords: `matrix`, `navigation`, `recursive`\n- Example input:\n\n```\n89010123\n78121874\n87430965\n96549874\n45678903\n32019012\n01329801\n10456732\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nvar lines = payload splitBy \"\\n\"\nfun getChar(x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (lines[x][y] default \"\")\nfun getRoutes(num:Number,numidx:Number,lineidx:Number) = do {\n    var nextNum = num+1\n    ---\n    if (num ~= 9) [{x:numidx,y:lineidx}]\n    else \n        (if (getChar(lineidx-1,numidx) ~= nextNum) getRoutes(nextNum,numidx,lineidx-1) else [])\n        ++\n        (if (getChar(lineidx+1,numidx) ~= nextNum) getRoutes(nextNum,numidx,lineidx+1) else [])\n        ++\n        (if (getChar(lineidx,numidx-1) ~= nextNum) getRoutes(nextNum,numidx-1,lineidx) else [])\n        ++\n        (if (getChar(lineidx,numidx+1) ~= nextNum) getRoutes(nextNum,numidx+1,lineidx) else [])\n}\n---\nflatten(lines map ((line, lineidx) -\u003e \n    (line splitBy \"\") map ((num, numidx) -\u003e \n        num match {\n            case \"0\" -\u003e sizeOf(getRoutes(0,numidx,lineidx) distinctBy $)\n            else -\u003e 0\n        }\n    )\n)) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday10%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nvar lines = payload splitBy \"\\n\"\nfun getChar(x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (lines[x][y] default \"\")\nfun getRoutes(num:Number,numidx:Number,lineidx:Number) = do {\n    var nextNum = num+1\n    ---\n    if (num ~= 9) 1\n    else \n        (if (getChar(lineidx-1,numidx) ~= nextNum) getRoutes(nextNum,numidx,lineidx-1) else 0)\n        +\n        (if (getChar(lineidx+1,numidx) ~= nextNum) getRoutes(nextNum,numidx,lineidx+1) else 0)\n        +\n        (if (getChar(lineidx,numidx-1) ~= nextNum) getRoutes(nextNum,numidx-1,lineidx) else 0)\n        +\n        (if (getChar(lineidx,numidx+1) ~= nextNum) getRoutes(nextNum,numidx+1,lineidx) else 0)\n}\n---\nflatten(lines map ((line, lineidx) -\u003e \n    (line splitBy \"\") map ((num, numidx) -\u003e \n        num match {\n            case \"0\" -\u003e getRoutes(0,numidx,lineidx)\n            else -\u003e 0\n        }\n    )\n)) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday10%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 11\n\n- Challenge: [Plutonian Pebbles](https://adventofcode.com/2024/day/11)\n- Keywords: `recursive`\n- Example input:\n\n```\nInitial arrangement:\n125 17\n\nAfter 1 blink:\n253000 1 7\n\nAfter 2 blinks:\n253 0 2024 14168\n\nAfter 3 blinks:\n512072 1 20 24 28676032\n\nAfter 4 blinks:\n512 72 2024 2 0 2 4 2867 6032\n\nAfter 5 blinks:\n1036288 7 2 20 24 4048 1 4048 8096 28 67 60 32\n\nAfter 6 blinks:\n2097446912 14168 4048 2 0 2 4 40 48 2024 40 48 80 96 2 8 6 7 6 0 3 2\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nfun removeExtraZeros(num:String):String = num as Number as String\nfun blink(arr) = flatten(arr map ((num, numidx) -\u003e \n    num match {\n        case \"0\" -\u003e \"1\"\n        case n if isEven(sizeOf(n)) -\u003e do {\n            var i = sizeOf(n)/2\n            ---\n            [removeExtraZeros(n[0 to i-1]),removeExtraZeros(n[i to -1])]\n        }\n        else -\u003e ($ * 2024) as String\n    }\n))\nfun blinkTimes(arr,times:Number=1) = times match {\n    case 0 -\u003e arr\n    else -\u003e blink(arr) blinkTimes times-1\n}\n---\nsizeOf((payload splitBy \" \") blinkTimes 25)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday11%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\nfun removeExtraZeros(num:String):String = num as Number as String\nfun blink(obj:Object) = namesOf(obj) reduce ((item, result={}) -\u003e do {\n    var itemValue = obj.\"$item\"\n    ---\n    item match {\n        case \"0\" -\u003e result update {\n            case new at .\"1\"! -\u003e (new default 0) + itemValue\n        }\n        case n if isEven(sizeOf(n)) -\u003e do {\n            var i = sizeOf(n)/2\n            var n1 = removeExtraZeros(n[0 to i-1])\n            var n2 = removeExtraZeros(n[i to -1])\n            var isSame = n1 == n2\n            ---\n            if (isSame) result update {\n                case new at .\"$n1\"! -\u003e (new default 0) + (itemValue * 2)\n            } \n            else result update {\n                case new1 at .\"$n1\"! -\u003e (new1 default 0) + itemValue\n                case new2 at .\"$n2\"! -\u003e (new2 default 0) + itemValue\n            }\n        }\n        else -\u003e result update {\n            case new at .\"$($ * 2024)\"! -\u003e (new default 0) + itemValue\n        }\n    }\n})\nfun blinkTimes(obj:Object,times:Number) = times match {\n    case 0 -\u003e obj\n    else -\u003e blink(obj) blinkTimes times-1\n}\nfun arrToObj(arr:Array,result={}) = arr match {\n    case [head ~ tail] -\u003e tail arrToObj (result update {\n        case x at .\"$head\"! -\u003e (x default 0) + 1\n    })\n    case [] -\u003e result\n}\n---\narrToObj(payload splitBy \" \") blinkTimes 75\nthen sum(valuesOf($))\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday11%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 12\n\n- Challenge: [Garden Groups](https://adventofcode.com/2024/day/12)\n- Keywords: `matrix`, `navigation`, `recursive`, `reduce`\n- Example input:\n\n```\nRRRRIICCFF\nRRRRIICCCF\nVVRRRCCFFF\nVVRCCCJFFF\nVVVVCJJCFE\nVVIVCCJJEE\nVVIIICJJEE\nMIIIIIJJEE\nMIIISIJEEE\nMMMISSJEEE\n```\n\n### ⭐️ Part 1\n\nRan with the full input in the DW CLI online [here](https://github.com/alexandramartinez/dwcli-github-actions/actions/runs/13143859945). Took less than 4 min. Not my best code :')\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport lines from dw::core::Strings\noutput application/json\ntype Coords = {\n    x:Number,\n    y:Number\n}\ntype Plant = {\n    char:String,\n    coords:Coords\n}\nvar pLines:Array\u003cString\u003e = lines(payload)\nfun getChar(arr:Array\u003cString\u003e,x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (arr[y][x] default \"\")\nfun getPlant(x:Number,y:Number):Plant = {\n    char: getChar(pLines,x,y),\n    coords: {\n        x:x,\n        y:y\n    }\n}\nfun getStringCoordsFromPlant(plant:Plant):String = \n    (plant.coords.x) ++ \",\" ++ (plant.coords.y)\nvar plants:Array\u003cPlant\u003e = flatten(pLines map ((line, y) -\u003e \n    (line splitBy \"\") map ((plant, x) -\u003e \n        getPlant(x,y)\n    )\n))\nfun getClosePlantsStrings(plants) = plants reduce ((plant,acc={}) -\u003e do {\n    var left = getPlant(plant.coords.x-1, plant.coords.y)\n    var right = getPlant(plant.coords.x+1, plant.coords.y)\n    var up = getPlant(plant.coords.x, plant.coords.y-1)\n    var down = getPlant(plant.coords.x, plant.coords.y+1)\n    ---\n    acc ++ (getStringCoordsFromPlant(plant)): [\n        (getStringCoordsFromPlant(left)) if (left.char == plant.char),\n        (getStringCoordsFromPlant(right)) if (right.char == plant.char),\n        (getStringCoordsFromPlant(up)) if (up.char == plant.char),\n        (getStringCoordsFromPlant(down)) if (down.char == plant.char)\n    ] \n})\n@TailRec()\nfun getAllClose(arr, keys, obj) = do {\n    var result = flatten(arr map ((item) -\u003e \n        obj[item] -- keys\n    )) distinctBy $\n    ---\n    if (isEmpty(result)) (keys ++ arr) \n    else getAllClose(\n        result,\n        (keys ++ arr),\n        obj\n    )\n}\nvar regionsStringCoords = flatten((plants groupBy ($.char) pluck ((plantsByRegion, tempRegion) -\u003e do {\n    var obj = (getClosePlantsStrings(plantsByRegion))\n    ---\n    (obj pluck ((value, key) -\u003e \n        getAllClose(value,[key as String],obj) orderBy $\n    )) distinctBy $\n})))\n---\nregionsStringCoords map ((region) -\u003e do {\n    var plants = region map ((str) -\u003e do {\n        var strSplit = str splitBy \",\"\n        var plant = getPlant(strSplit[0] as Number, strSplit[1] as Number)\n        var left = getPlant(plant.coords.x-1, plant.coords.y).char\n        var right = getPlant(plant.coords.x+1, plant.coords.y).char\n        var up = getPlant(plant.coords.x, plant.coords.y-1).char\n        var down = getPlant(plant.coords.x, plant.coords.y+1).char\n        var p = [\n            (left) if (left == plant.char),\n            (right) if (right == plant.char),\n            (up) if (up == plant.char),\n            (down) if (down == plant.char)\n        ]\n        ---\n        {\n            (plant),\n            area: 1,\n            perimeter: 4-sizeOf(p)\n        }\n    })\n    ---\n    sum(plants.area) * sum(plants.perimeter)\n}) \nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday12%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\nGot some help from [reddit](https://www.reddit.com/r/adventofcode/comments/1hcpyic/comment/m1q1nrj/) and ended up using the DFS algorithm mentioned there. The corner trick was amazing!\nI'm sure my code can be made way simpler but this was the first code that worked, so I just decided to leave it like that even if it's not the best :)\nSame as part 1, had to run this code with the full input in the DW CLI online [here](https://github.com/alexandramartinez/dwcli-github-actions/actions/runs/13160831089/). Took less than 4 min to run!\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport lines from dw::core::Strings\noutput application/json\ntype Coords = {\n    x:Number,\n    y:Number\n}\ntype Plant = {\n    char:String,\n    coords:Coords\n}\nvar pLines:Array\u003cString\u003e = lines(payload)\nfun getChar(arr:Array\u003cString\u003e,x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (arr[y][x] default \"\")\nfun getPlant(x:Number,y:Number):Plant = {\n    char: getChar(pLines,x,y),\n    coords: {\n        x:x,\n        y:y\n    }\n}\nfun getStringCoordsFromPlant(plant:Plant):String = \n    (plant.coords.x) ++ \",\" ++ (plant.coords.y)\nvar plants:Array\u003cPlant\u003e = flatten(pLines map ((line, y) -\u003e \n    (line splitBy \"\") map ((plant, x) -\u003e \n        getPlant(x,y)\n    )\n))\nfun getClosePlantsStrings(plants) = plants reduce ((plant,acc={}) -\u003e do {\n    var left = getPlant(plant.coords.x-1, plant.coords.y)\n    var right = getPlant(plant.coords.x+1, plant.coords.y)\n    var up = getPlant(plant.coords.x, plant.coords.y-1)\n    var down = getPlant(plant.coords.x, plant.coords.y+1)\n    ---\n    acc ++ (getStringCoordsFromPlant(plant)): [\n        (getStringCoordsFromPlant(left)) if (left.char == plant.char),\n        (getStringCoordsFromPlant(right)) if (right.char == plant.char),\n        (getStringCoordsFromPlant(up)) if (up.char == plant.char),\n        (getStringCoordsFromPlant(down)) if (down.char == plant.char)\n    ] \n})\n@TailRec()\nfun getAllClose(arr, keys, obj) = do {\n    var result = flatten(arr map ((item) -\u003e \n        obj[item] -- keys\n    )) distinctBy $\n    ---\n    if (isEmpty(result)) (keys ++ arr) \n    else getAllClose(\n        result,\n        (keys ++ arr),\n        obj\n    )\n}\nvar regionsStringCoords = flatten((plants groupBy ($.char) pluck ((plantsByRegion, tempRegion) -\u003e do {\n    var obj = (getClosePlantsStrings(plantsByRegion))\n    ---\n    (obj pluck ((value, key) -\u003e \n        getAllClose(value,[key as String],obj) orderBy $\n    )) distinctBy $\n})))\nvar corners = [\n  [\n    \"down\",\n    \"right\"\n  ],\n  [\n    \"down\",\n    \"left\"\n  ],\n  [\n    \"left\",\n    \"up\"\n  ],\n  [\n    \"right\",\n    \"up\"\n  ]\n]\nfun countCorners(sides:Array\u003cPlant\u003e,char:String) = do {\n    var upleft = 0\n    var up = 1\n    var upright = 2\n    var left = 3\n    var right = 4\n    var downleft = 5\n    var down = 6\n    var downright = 7\n    ---\n    (if ( (sides[left].char != char) and (sides[up].char != char) ) 1 else 0)\n    + (if ( (sides[right].char != char) and (sides[up].char != char) ) 1 else 0)\n    + (if ( (sides[left].char != char) and (sides[down].char != char) ) 1 else 0)\n    + (if ( (sides[right].char != char) and (sides[down].char != char) ) 1 else 0)\n    + (if ( (sides[left].char == char) and (sides[up].char == char) and (sides[upleft].char != char)) 1 else 0)\n    + (if ( (sides[right].char == char) and (sides[up].char == char) and (sides[upright].char != char)) 1 else 0)\n    + (if ( (sides[left].char == char) and (sides[down].char == char) and (sides[downleft].char != char)) 1 else 0)\n    + (if ( (sides[right].char == char) and (sides[down].char == char) and (sides[downright].char != char)) 1 else 0)\n}\n---\nregionsStringCoords map ((region) -\u003e do {\n    var plants = region map ((str) -\u003e do {\n        var strSplit = str splitBy \",\"\n        var plant = getPlant(strSplit[0] as Number, strSplit[1] as Number)\n        var left = getPlant(plant.coords.x-1, plant.coords.y)\n        var right = getPlant(plant.coords.x+1, plant.coords.y)\n        var up = getPlant(plant.coords.x, plant.coords.y-1)\n        var down = getPlant(plant.coords.x, plant.coords.y+1)\n        var upleft = getPlant(plant.coords.x-1, plant.coords.y-1)\n        var upright = getPlant(plant.coords.x+1, plant.coords.y-1)\n        var downleft = getPlant(plant.coords.x-1, plant.coords.y+1)\n        var downright = getPlant(plant.coords.x+1, plant.coords.y+1)\n        var s = [\n            upleft, //0\n            up, //1\n            upright, //2\n            left, //3\n            right, //4\n            downleft, //5\n            down, //6\n            downright //7\n        ]\n        ---\n        {\n            area: 1,\n            corners: countCorners(s,plant.char)\n        }\n    })\n    ---\n    sum(plants.area) * sum(plants.corners)\n}) \nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday12%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 13\n\n- Challenge: [Claw Contraption](https://adventofcode.com/2024/day/13)\n- Keywords: `math`, `strings`, `lines`\n- Example input:\n\n```\nButton A: X+94, Y+34\nButton B: X+22, Y+67\nPrize: X=8400, Y=5400\n\nButton A: X+26, Y+66\nButton B: X+67, Y+21\nPrize: X=12748, Y=12176\n\nButton A: X+17, Y+86\nButton B: X+84, Y+37\nPrize: X=7870, Y=6450\n\nButton A: X+69, Y+23\nButton B: X+27, Y+71\nPrize: X=18641, Y=10279\n```\n\n### ⭐️ Part 1\n\nTo be completely honest, I didn't solve this one myself cause I was trying to make huge Trees and I realized it was impossible. So, I googled and ended up [here](https://dev.to/grantdotdev/advent-of-code-24-day-13-claw-contraption-n2p). Tysm Grant! ✨\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\nvar machines = payload splitBy \"\\n\\n\"\n---\nmachines map ((machine) -\u003e do {\n    var split = machine splitBy \"\\n\"\n    var prize = {\n        x: (split[-1] splitBy \" \")[1][2 to -2] as Number,\n        y: (split[-1] splitBy \" \")[-1][2 to -1] as Number\n    }\n    var buttonA = {\n        x: (split[0] splitBy \" \")[-2][2 to -2] as Number,\n        y: (split[0] splitBy \" \")[-1][2 to -1] as Number\n    }\n    var buttonB = {\n        x: (split[1] splitBy \" \")[-2][2 to -2] as Number,\n        y: (split[1] splitBy \" \")[-1][2 to -1] as Number\n    }\n    var D = (buttonA.x * buttonB.y) - (buttonA.y * buttonB.x)\n    var Dx = (prize.x * buttonB.y) - (prize.y * buttonB.x)\n    var Dy = (buttonA.x * prize.y) - (buttonA.y * prize.x)\n    var A = Dx / D\n    var B = Dy / D\n    ---\n    (if (isInteger(A)) A * 3 else 0) + (if (isInteger(B)) B else 0)\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday13%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\nExact same code as part 1, only adding `+ 10000000000000` to both `x` and `y` fields from `var prize`\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\nvar machines = payload splitBy \"\\n\\n\"\n---\nmachines map ((machine) -\u003e do {\n    var split = machine splitBy \"\\n\"\n    var prize = {\n        x: (split[-1] splitBy \" \")[1][2 to -2] as Number + 10000000000000,\n        y: (split[-1] splitBy \" \")[-1][2 to -1] as Number + 10000000000000\n    }\n    var buttonA = {\n        x: (split[0] splitBy \" \")[-2][2 to -2] as Number,\n        y: (split[0] splitBy \" \")[-1][2 to -1] as Number\n    }\n    var buttonB = {\n        x: (split[1] splitBy \" \")[-2][2 to -2] as Number,\n        y: (split[1] splitBy \" \")[-1][2 to -1] as Number\n    }\n    var D = (buttonA.x * buttonB.y) - (buttonA.y * buttonB.x)\n    var Dx = (prize.x * buttonB.y) - (prize.y * buttonB.x)\n    var Dy = (buttonA.x * prize.y) - (buttonA.y * prize.x)\n    var A = Dx / D\n    var B = Dy / D\n    ---\n    (if (isInteger(A)) A * 3 else 0) + (if (isInteger(B)) B else 0)\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday13%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 14\n\n- Challenge: [Restroom Redoubt](https://adventofcode.com/2024/day/14)\n- Keywords: `math`, `strings`, `lines`, `recursive`\n- Example input:\n\n```\np=0,4 v=3,-3\np=6,3 v=-1,-3\np=10,3 v=-1,2\np=2,0 v=2,-1\np=0,0 v=1,3\np=3,0 v=-2,-2\np=7,6 v=-1,-3\np=3,0 v=-1,-2\np=9,3 v=2,3\np=7,3 v=-1,2\np=2,4 v=2,-3\np=9,5 v=-3,-3\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\nvar robots = payload splitBy \"\\n\"\nvar WIDTH = 101\nvar HEIGHT = 103\nvar SECONDS = 100\nvar widthMiddle = floor(WIDTH/2)\nvar heightMiddle = floor(HEIGHT/2)\ntype Coords = {\n    x:Number,\n    y:Number\n}\nfun stringToCoord(str:String):Coords = do {\n    var split = str splitBy \",\"\n    ---\n    {x:split[0] as Number, y:split[1] as Number}\n}\nfun moveRobot(position:Coords,velocity:Coords):Coords = do {\n    var x = position.x + velocity.x\n    var y = position.y + velocity.y\n    ---\n    {\n        x: if (x \u003e WIDTH-1) x-WIDTH \n            else if (x \u003c 0) WIDTH+x\n            else x,\n        y: if (y \u003e HEIGHT-1) y-HEIGHT\n            else if (y \u003c 0) HEIGHT+y\n            else y\n    }\n}\n@TailRec()\nfun moveRobotXTimes(position:Coords,velocity:Coords,times=SECONDS):Coords = do {\n    times match {\n        case 0 -\u003e position\n        else -\u003e moveRobotXTimes(\n            moveRobot(position, velocity), velocity, times-1\n        )\n    }\n}\nvar robotsAfterMoving = robots map ((robot) -\u003e do {\n    var split = robot splitBy \" \"\n    var position = stringToCoord(split[0][2 to -1])\n    var velocity = stringToCoord(split[-1][2 to -1])\n    ---\n    moveRobotXTimes(position,velocity)\n})\n---\nsizeOf(robotsAfterMoving filter (($.x \u003c widthMiddle) and ($.y \u003c heightMiddle)))\n* sizeOf(robotsAfterMoving filter (($.x \u003e widthMiddle) and ($.y \u003c heightMiddle)))\n* sizeOf(robotsAfterMoving filter (($.x \u003c widthMiddle) and ($.y \u003e heightMiddle)))\n* sizeOf(robotsAfterMoving filter (($.x \u003e widthMiddle) and ($.y \u003e heightMiddle)))\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday14%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\nomg this one was so interesting and fun!!! I ran this one in the DW CLI online [here](https://github.com/alexandramartinez/dwcli-github-actions/actions/runs/13209666287) - it took 33 minutes to finish!\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\noutput application/json\nimport countBy from dw::core::Arrays\nvar lines = payload splitBy \"\\n\"\nvar WIDTH = 101\nvar HEIGHT = 103\ntype Coords = {\n    x:Number,\n    y:Number\n}\ntype Robot = {\n    position: Coords,\n    velocity: Coords\n}\ntype Direction = \"left\" | \"up\" | \"down\" | \"right\"\nfun stringToCoord(str:String):Coords = do {\n    var split = str splitBy \",\"\n    ---\n    {x:split[0] as Number, y:split[1] as Number}\n}\nfun moveRobot(robot:Robot):Coords = do {\n    var x = robot.position.x + robot.velocity.x\n    var y = robot.position.y + robot.velocity.y\n    ---\n    {\n        x: if (x \u003e WIDTH-1) x-WIDTH \n            else if (x \u003c 0) WIDTH+x\n            else x,\n        y: if (y \u003e HEIGHT-1) y-HEIGHT\n            else if (y \u003c 0) HEIGHT+y\n            else y\n    }\n}\nfun getNewCoords(from:Coords, direction:Direction):Coords = direction match {\n    case \"left\" -\u003e {x: from.x-1, y:from.y}\n    case \"right\" -\u003e {x: from.x+1, y:from.y}\n    case \"up\" -\u003e {x: from.x, y: from.y-1}\n    case \"down\" -\u003e {x: from.x, y: from.y+1}\n}\nfun areMostTouchingOthers(arr):Boolean = do {\n    ((arr map ((item) -\u003e \n        (arr contains getNewCoords(item,\"left\"))\n        or (arr contains getNewCoords(item,\"right\"))\n        or (arr contains getNewCoords(item,\"up\"))\n        or (arr contains getNewCoords(item,\"down\"))\n    )) countBy $) \u003e= 350 // 70% of 500\n}\nvar robots:Array\u003cRobot\u003e = lines map ((robot) -\u003e do {\n    var split = robot splitBy \" \"\n    var position = stringToCoord(split[0][2 to -1])\n    var velocity = stringToCoord(split[-1][2 to -1])\n    ---\n    {\n        position:position,\n        velocity:velocity\n    }\n})\n@TailRec()\nfun keepMovingRobots(robots,counter=0) = do {\n    if (areMostTouchingOthers(robots.position)) counter\n    else keepMovingRobots(\n        robots map ((robot, index) -\u003e \n            {\n                position: moveRobot(robot),\n                velocity: robot.velocity\n            }\n        )\n        ,counter+1\n    )\n}\n---\nkeepMovingRobots(robots)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday14%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 - Spoiler/Second Script\n\n\u003cdetails\u003e\n  \u003csummary\u003eSPOILER!!!\u003c/summary\u003e\n\nI ended up checking for when at least 70% of the robots were touching each other and that seemed to do the trick :D\n\nHere's the cool pic i got!\n\n![tree](/images/day14tree.png)\n\n\u003c/details\u003e\n\nYou can check the output with the following script. Just change the `SECONDS` variable.\n\n\u003cdetails\u003e\n  \u003csummary\u003eSecond script\u003c/summary\u003e\n\n```dataweave\noutput application/json\nvar robots = payload splitBy \"\\n\"\nvar WIDTH = 101\nvar HEIGHT = 103\nvar SECONDS = 7037\ntype Coords = {\n    x:Number,\n    y:Number\n}\nfun stringToCoord(str:String):Coords = do {\n    var split = str splitBy \",\"\n    ---\n    {x:split[0] as Number, y:split[1] as Number}\n}\nfun moveRobot(position:Coords,velocity:Coords):Coords = do {\n    var x = position.x + velocity.x\n    var y = position.y + velocity.y\n    ---\n    {\n        x: if (x \u003e WIDTH-1) x-WIDTH \n            else if (x \u003c 0) WIDTH+x\n            else x,\n        y: if (y \u003e HEIGHT-1) y-HEIGHT\n            else if (y \u003c 0) HEIGHT+y\n            else y\n    }\n}\n@TailRec()\nfun moveRobotXTimes(position:Coords,velocity:Coords,times=SECONDS):Coords = do {\n    times match {\n        case 0 -\u003e position\n        else -\u003e moveRobotXTimes(\n            moveRobot(position, velocity), velocity, times-1\n        )\n    }\n}\nvar robotsAfterMoving = robots map ((robot) -\u003e do {\n    var split = robot splitBy \" \"\n    var position = stringToCoord(split[0][2 to -1])\n    var velocity = stringToCoord(split[-1][2 to -1])\n    ---\n    moveRobotXTimes(position,velocity)\n})\nvar obj = robotsAfterMoving groupBy ($.x ++ \",\" ++ $.y)\n---\n(0 to HEIGHT-1) map ((y) -\u003e\n    ((0 to WIDTH-1) map ((x) -\u003e\n        if (!isEmpty(obj[x ++ \",\" ++ y])) \"X\" else \".\"\n    )) joinBy \"\"\n)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday14%2Fpart2image\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 15\n\n- Challenge: [Warehouse Woes](https://adventofcode.com/2024/day/15)\n- Keywords: `strings`, `matrix`, `two inputs`, `navigation`, `recursive`\n- Example input:\n\n```\n########\n#..O.O.#\n##@.O..#\n#...O..#\n#.#.O..#\n#...O..#\n#......#\n########\n\n\u003c^^\u003e\u003e\u003evv\u003cv\u003e\u003ev\u003c\u003c\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport mapString from dw::core::Strings\noutput application/json\ntype Coords = {x:Number,y:Number}\nvar lines = payload splitBy \"\\n\\n\"\nvar initialMap = do {\n    var thismap = lines[0] splitBy \"\\n\"\n    ---\n    {\n        map: thismap,\n        robot: (flatten(thismap map ((line, y) -\u003e \n            (line splitBy \"\") map ((char, x) -\u003e \n                char match {\n                    case \"@\" -\u003e {x:x,y:y}\n                    else -\u003e null\n                }\n            )\n        )) filter (!isEmpty($)))[0] as Coords\n    }\n}\nvar movements = lines[1] replace \"\\n\" with \"\" splitBy \"\"\nfun getChar(arr:Array\u003cString\u003e,x:Number,y:Number):String = if ((x\u003c0) or (y\u003c0)) \"\" else (arr[y][x] default \"\")\n@TailRec()\nfun moveBoxes(thisMap, boxes:Array\u003cCoords\u003e, direction:String) = direction match {\n    case \"\u003c\" -\u003e getChar(thisMap.map, boxes[-1].x-1, boxes[-1].y) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, boxes + {x:boxes[-1].x-1, y:boxes[-1].y}, direction)\n        case \".\" -\u003e thisMap update {\n            case .robot.x -\u003e boxes[0].x\n            case .map[thisMap.robot.y] -\u003e $ mapString ((character, index) -\u003e \n                index match {\n                    case x if (thisMap.robot.x == x) -\u003e \".\"\n                    case x if (boxes[0].x == x) -\u003e \"@\"\n                    case x if (boxes[-1].x-1 == x) -\u003e \"O\"\n                    else -\u003e character\n                }\n            )\n        }\n    }\n    case \"\u003e\" -\u003e getChar(thisMap.map, boxes[-1].x+1, boxes[-1].y) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, boxes + {x:boxes[-1].x+1, y:boxes[-1].y}, direction)\n        case \".\" -\u003e thisMap update {\n            case .robot.x -\u003e boxes[0].x\n            case .map[thisMap.robot.y] -\u003e $ mapString ((character, index) -\u003e \n                index match {\n                    case x if (thisMap.robot.x == x) -\u003e \".\"\n                    case x if (boxes[0].x == x) -\u003e \"@\"\n                    case x if (boxes[-1].x+1 == x) -\u003e \"O\"\n                    else -\u003e character\n                }\n            )\n        }\n    }\n    case \"^\" -\u003e getChar(thisMap.map, boxes[-1].x, boxes[-1].y-1) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, boxes + {x:boxes[-1].x, y:boxes[-1].y-1}, direction)\n        case \".\" -\u003e thisMap update {\n            case .robot.y -\u003e boxes[0].y\n            case .map[thisMap.robot.y] -\u003e $ replace \"@\" with \".\"\n            case .map[boxes[0].y] -\u003e $[0 to boxes[0].x-1] ++ \"@\" ++ $[boxes[0].x+1 to -1]\n            case .map[boxes[-1].y-1] -\u003e $[0 to boxes[-1].x-1] ++ \"O\" ++ $[boxes[-1].x+1 to -1]\n        }\n    }\n    case \"v\" -\u003e getChar(thisMap.map, boxes[-1].x, boxes[-1].y+1) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, boxes + {x:boxes[-1].x, y:boxes[-1].y+1}, direction)\n        case \".\" -\u003e thisMap update {\n            case .robot.y -\u003e boxes[0].y\n            case .map[thisMap.robot.y] -\u003e $ replace \"@\" with \".\"\n            case .map[boxes[0].y] -\u003e $[0 to boxes[0].x-1] ++ \"@\" ++ $[boxes[0].x+1 to -1]\n            case .map[boxes[-1].y+1] -\u003e $[0 to boxes[-1].x-1] ++ \"O\" ++ $[boxes[-1].x+1 to -1]\n        }\n    }\n}\nfun moveRobot(thisMap, moveTo:String) = moveTo match {\n    case \"\u003c\" -\u003e getChar(thisMap.map, thisMap.robot.x-1, thisMap.robot.y) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, [{x:thisMap.robot.x-1, y:thisMap.robot.y}], moveTo) \n        case \".\" -\u003e thisMap update {\n            case .robot.x -\u003e $-1\n            case .map[thisMap.robot.y] -\u003e $ mapString ((character, index) -\u003e \n                index match {\n                    case x if (thisMap.robot.x == x) -\u003e \".\"\n                    case x if (thisMap.robot.x-1 == x) -\u003e \"@\"\n                    else -\u003e character\n                }\n            )\n        }\n    }\n    case \"\u003e\" -\u003e getChar(thisMap.map, thisMap.robot.x+1, thisMap.robot.y) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, [{x:thisMap.robot.x+1, y:thisMap.robot.y}], moveTo) \n        case \".\" -\u003e thisMap update {\n            case .robot.x -\u003e $+1\n            case .map[thisMap.robot.y] -\u003e $ mapString ((character, index) -\u003e \n                index match {\n                    case x if (thisMap.robot.x == x) -\u003e \".\"\n                    case x if (thisMap.robot.x+1 == x) -\u003e \"@\"\n                    else -\u003e character\n                }\n            )\n        }\n    }\n    case \"^\" -\u003e getChar(thisMap.map, thisMap.robot.x, thisMap.robot.y-1) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, [{x:thisMap.robot.x, y:thisMap.robot.y-1}], moveTo) \n        case \".\" -\u003e thisMap update {\n            case .robot.y -\u003e $-1\n            case .map[thisMap.robot.y] -\u003e $ replace \"@\" with \".\"\n            case .map[thisMap.robot.y-1] -\u003e $[0 to thisMap.robot.x-1] ++ \"@\" ++ $[thisMap.robot.x+1 to -1]\n        }\n    }\n    case \"v\" -\u003e getChar(thisMap.map, thisMap.robot.x, thisMap.robot.y+1) match {\n        case \"#\" -\u003e thisMap\n        case \"O\" -\u003e moveBoxes(thisMap, [{x:thisMap.robot.x, y:thisMap.robot.y+1}], moveTo) \n        case \".\" -\u003e thisMap update {\n            case .robot.y -\u003e $+1\n            case .map[thisMap.robot.y] -\u003e $ replace \"@\" with \".\"\n            case .map[thisMap.robot.y+1] -\u003e $[0 to thisMap.robot.x-1] ++ \"@\" ++ $[thisMap.robot.x+1 to -1]\n        }\n    }\n}\n@TailRec()\nfun keepMoving(movementsList:Array\u003cString\u003e, thisMap) = movementsList match {\n    case [headMovement ~ tailMovements] -\u003e keepMoving(\n        tailMovements,\n        thisMap moveRobot headMovement\n    )\n    case [] -\u003e thisMap\n}\n---\nkeepMoving(movements,initialMap).map map ((line, y) -\u003e \n    sum((line splitBy \"\") map ((char, x) -\u003e \n        if (char == \"O\") 100 * y + x\n        else 0\n    ))\n) then sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday15%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 19\n\n- Challenge: [Linen Layout](https://adventofcode.com/2024/day/19)\n- Keywords: `strings`, `lines`, `two inputs`, `rules`, `recursive`\n- Example input:\n\n```\nr, wr, b, g, bwu, rb, gb, br\n\nbrwrr\nbggr\ngbbr\nrrbgbr\nubwu\nbwurrg\nbrgr\nbbrgwb\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport countBy from dw::core::Arrays\nimport lines, substringAfter from dw::core::Strings\noutput application/json\nvar split = payload splitBy \"\\n\\n\"\nvar patternsList = split[0] splitBy \", \"\nfun checkDesign(initialDesign:String, currentDesign:String, acc=\"\") = do {\n    var filtered = patternsList filter (currentDesign startsWith $)\n    ---\n    if (isEmpty(currentDesign))\n        initialDesign == acc\n    else if (isEmpty(filtered)) false\n    else filtered \n    reduce ((pattern, matches=false) -\u003e \n        if (matches) true\n        else checkDesign(\n            initialDesign,\n            currentDesign substringAfter pattern,\n            acc ++ pattern\n        ) \n    )\n}\n---\n(lines(split[1]) map ((design) -\u003e \n    checkDesign(design,design)\n)) countBy $\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday19%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 23\n\n- Challenge: [LAN Party](https://adventofcode.com/2024/day/23)\n- Keywords: `lines`, `comparisons/matching`\n- Example input:\n\n```\nkh-tc\nqp-kh\nde-cg\nka-co\nyn-aq\nqp-ub\ncg-tb\nvc-aq\ntb-ka\nwh-tc\nyn-cg\nkh-ub\nta-co\nde-co\ntc-td\ntb-wq\nwh-td\nta-ka\ntd-qp\naq-cg\nwq-ub\nub-vc\nde-ta\nwq-aq\nwq-vc\nwh-yn\nka-de\nkh-ta\nco-tc\nwh-qp\ntb-vc\ntd-yn\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport lines from dw::core::Strings\noutput application/json\nvar connections = lines(payload) map ($ splitBy \"-\") reduce ((item, a={}) -\u003e \n    a update {\n        case x at .\"$(item[0])\"! -\u003e (a[item[0]] default []) + item[1]\n        case y at .\"$(item[1])\"! -\u003e (a[item[1]] default []) + item[0]\n    }\n)\nvar matches = flatten(namesOf(connections) map ((computer1) -\u003e \n    flatten(connections[computer1] map ((computer2) -\u003e do {\n        var threeMatchesOne = (connections[computer2] filter ((computer3) -\u003e connections[computer3] contains computer1))\n        ---\n        if (!isEmpty(threeMatchesOne)) \n            threeMatchesOne filter ((computer3) -\u003e (computer1 startsWith \"t\") or (computer2 startsWith \"t\") or (computer3 startsWith \"t\"))\n            map ((computer3) -\u003e\n                [computer1, computer2, computer3] orderBy $\n            )\n        else []\n    })) \n)) distinctBy $\n---\nsizeOf(matches)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday23%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport lines from dw::core::Strings\noutput application/json\nvar connections = lines(payload) map ($ splitBy \"-\") reduce ((item, a={}) -\u003e \n    a update {\n        case x at .\"$(item[0])\"! -\u003e (a[item[0]] default []) + item[1]\n        case y at .\"$(item[1])\"! -\u003e (a[item[1]] default []) + item[0]\n    }\n)\nvar list = namesOf(connections) map ((computer1) -\u003e do {\n    var cc1 = connections[computer1]\n    var list = (cc1 + computer1) orderBy $\n    var strings = (cc1 map ((computer2) -\u003e do {\n        var tocompare = (connections[computer2] + computer2) orderBy $\n        ---\n        (tocompare filter (list contains $)) joinBy \",\"\n    })) orderBy $\n    ---\n    ((strings orderBy $) groupBy $) filterObject (sizeOf($) \u003e= 2)\n    mapObject ((value, key, index) -\u003e {\n        size: sizeOf(value),\n        str: key\n    })\n})\n---\n((list filter (!isEmpty($))) orderBy -($.size))[0].str\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday23%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 24\n\n- Challenge: [Crossed Wires](https://adventofcode.com/2024/day/24)\n- Keywords: `strings`, `lines`, `two inputs`, `rules`, `recursive`, `comparisons/matching`\n- Example input:\n\n```\nx00: 1\nx01: 0\nx02: 1\nx03: 1\nx04: 0\ny00: 1\ny01: 1\ny02: 1\ny03: 1\ny04: 1\n\nntg XOR fgs -\u003e mjb\ny02 OR x01 -\u003e tnw\nkwq OR kpj -\u003e z05\nx00 OR x03 -\u003e fst\ntgd XOR rvg -\u003e z01\nvdt OR tnw -\u003e bfw\nbfw AND frj -\u003e z10\nffh OR nrd -\u003e bqk\ny00 AND y03 -\u003e djm\ny03 OR y00 -\u003e psh\nbqk OR frj -\u003e z08\ntnw OR fst -\u003e frj\ngnj AND tgd -\u003e z11\nbfw XOR mjb -\u003e z00\nx03 OR x00 -\u003e vdt\ngnj AND wpb -\u003e z02\nx04 AND y00 -\u003e kjc\ndjm OR pbm -\u003e qhw\nnrd AND vdt -\u003e hwm\nkjc AND fst -\u003e rvg\ny04 OR y02 -\u003e fgs\ny01 AND x02 -\u003e pbm\nntg OR kjc -\u003e kwq\npsh XOR fgs -\u003e tgd\nqhw XOR tgd -\u003e z09\npbm OR djm -\u003e kpj\nx03 XOR y03 -\u003e ffh\nx00 XOR y04 -\u003e ntg\nbfw OR bqk -\u003e z06\nnrd XOR fgs -\u003e wpb\nfrj XOR qhw -\u003e z04\nbqk OR frj -\u003e z07\ny03 OR x01 -\u003e nrd\nhwm AND bqk -\u003e z03\ntgd XOR rvg -\u003e z12\ntnw OR pbm -\u003e gnj\n```\n\n### ⭐️ Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport fromBinary from dw::core::Numbers\nimport lines from dw::core::Strings\noutput application/json\nvar splitPayload = payload splitBy \"\\n\\n\"\nvar wires:Object = (lines(splitPayload[0]) map ($ splitBy \": \")) reduce ((item, a={}) -\u003e \n    a ++ {\n        (item[0]): item[1] ~= 1\n    }\n)\nfun getWiresObject(gates:Array\u003cString\u003e, wiresRec) = {\n    (gates map ((gate) -\u003e do {\n        @Lazy\n        var split = gate splitBy \" \"\n        @Lazy\n        var wire1 = split[0]\n        @Lazy\n        var wire2 = split[2]\n        @Lazy\n        var wire3 = split[-1]\n        ---\n        if (!isEmpty(wiresRec[wire1]) and !isEmpty(wiresRec[wire2])) {\n            (wire3): split[1] match {\n                case \"AND\" -\u003e wiresRec[wire1] and wiresRec[wire2]\n                case \"OR\" -\u003e wiresRec[wire1] or wiresRec[wire2]\n                case \"XOR\" -\u003e wiresRec[wire1] != wiresRec[wire2]\n            }\n        }\n        else {\n            keepTrying: gate\n        }\n    }))\n}\nfun getWiresTailRec(gates:Array\u003cString\u003e, wiresRec=wires) = do {\n    var result = getWiresObject(gates, wiresRec)\n    var newGates = result.*keepTrying\n    var newWires = wiresRec ++ result\n    ---\n    if (isEmpty(newGates)) newWires \n    else getWiresTailRec(newGates, newWires - \"keepTrying\")\n}\n---\ngetWiresTailRec(lines(splitPayload[1])) \nfilterObject ($$ startsWith \"z\")\norderBy $$\nmapObject (($$): if ($) 1 else 0)\nthen fromBinary(valuesOf($)[-1 to 0] joinBy \"\")\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday24%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2 (unsolved)\n\ntbd\n\n## 🔹 Day 25\n\n- Challenge: [Code Chronicle](https://adventofcode.com/2024/day/25)\n- Keywords: `matrix`, `two inputs`, `comparisons/matching`\n- Example input:\n\n```\n#####\n.####\n.####\n.####\n.#.#.\n.#...\n.....\n\n#####\n##.##\n.#.##\n...##\n...#.\n...#.\n.....\n\n.....\n#....\n#....\n#...#\n#.#.#\n#.###\n#####\n\n.....\n.....\n#.#..\n###..\n###.#\n###.#\n#####\n\n.....\n.....\n.....\n#....\n#.#..\n#.#.#\n#####\n```\n\n### ⭐️ Part 1 \n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport every, countBy from dw::core::Arrays\noutput application/json\nfun getMap(arr) = arr map ((item) -\u003e do {\n    var lines = (item splitBy \"\\n\")[1 to -2]\n    ---\n    (0 to sizeOf(lines)-1) map (\n        sum(lines map ((line) -\u003e \n            if (line[$] == \"#\") 1 else 0\n        ))\n    )\n})\nvar arr = (payload splitBy \"\\n\\n\")\nvar locks = getMap(arr filter ($ startsWith \"#####\"))\nvar keys = getMap(arr filter ($ startsWith \".....\"))\n---\nsum(locks map ((lock, locki) -\u003e \n    (keys map ((key, keyi) -\u003e \n        (key map ((keypin, keypini) -\u003e \n            5-keypin \u003e= lock[keypini]\n        )) every $\n    )) countBy $\n))\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2024\u0026path=scripts%2Fday25%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### ⭐️⭐️ Part 2\n\n\u003e Need to finish the rest of the challenges to be unlocked x-x","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2024","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexandramartinez%2Fadventofcode-2024","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2024/lists"}