{"id":21858037,"url":"https://github.com/alexandramartinez/adventofcode-2015","last_synced_at":"2026-02-09T15:09:39.242Z","repository":{"id":262526709,"uuid":"887379517","full_name":"alexandramartinez/adventofcode-2015","owner":"alexandramartinez","description":"DataWeave scripts used in the adventofcode.com site for 2015.","archived":false,"fork":false,"pushed_at":"2024-11-28T18:29:45.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T14:22:42.154Z","etag":null,"topics":["advent-of-code","adventofcode","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/2015","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-11-12T16:35:59.000Z","updated_at":"2024-11-28T18:29:49.000Z","dependencies_parsed_at":"2024-11-19T20:46:31.317Z","dependency_job_id":null,"html_url":"https://github.com/alexandramartinez/adventofcode-2015","commit_stats":null,"previous_names":["alexandramartinez/adventofcode-2015"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2015","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2015/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2015/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2015/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexandramartinez","download_url":"https://codeload.github.com/alexandramartinez/adventofcode-2015/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244857508,"owners_count":20522024,"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","adventofcode","challenge","challenges","dataweave","dataweave-lang","dataweave-language","dataweave-playground","programming","programming-challenges","programming-exercises","programming-language","programming-languages"],"created_at":"2024-11-28T02:41:44.918Z","updated_at":"2026-02-09T15:09:34.204Z","avatar_url":"https://github.com/alexandramartinez.png","language":"DataWeave","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advent of Code 2015\n\nDataWeave scripts used in the [adventofcode.com](https://adventofcode.com/) site for 2015.\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## 🔹 Day 1\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\n---\npayload \nreplace \"(\" with \"1,\"\nreplace \")\" with \"-1,\"\nsplitBy \",\"\nmap $ as Number\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\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\n%dw 2.0\nfun getResult(data, index=0, sum=0) = \n    if (!isEmpty(data)) do {\n        var newSum = data[0] as Number + sum\n        var currentIndex = index+1\n        ---\n        if (newSum == -1)\n            currentIndex\n        else\n            getResult(data[1 to -1], currentIndex, newSum)\n    }\n    else index\n---\npayload \nreplace \"(\" with \"1,\"\nreplace \")\" with \"-1,\"\nsplitBy \",\"\nthen getResult($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday1%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 2\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nfun getSingleResult(data) = do {\n    var d = data splitBy \"x\" map $ as Number orderBy $\n    var slack = d[0] * d[1]\n    ---\n    (2*d[0]*d[1]) + (2*d[1]*d[2]) + (2*d[2]*d[0]) + slack\n}\n---\nsum(payload splitBy \"\\n\" map getSingleResult($))\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday2%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\nfun getSingleResult(data) = do {\n    var d = data splitBy \"x\" map $ as Number orderBy $\n    var ribbon = d[0] + d[0] + d[1] + d[1]\n    ---\n    d[0]*d[1]*d[2] + ribbon\n}\n---\nsum(payload splitBy \"\\n\" map getSingleResult($))\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday2%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 3\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\ntype House = { x:Number, y:Number }\nvar west = \"\u003c\" // left\nvar east = \"\u003e\" // right\nvar north = \"^\" // up\nvar south = \"v\" // down\nvar start:House = { x:0, y:0 }\nfun move(direction:String, house:House):House =\n    direction match {\n        case d if d == west -\u003e { x: house.x-1, y: house.y }\n        case d if d == east -\u003e { x: house.x+1, y: house.y }\n        case d if d == north -\u003e { x: house.x, y: house.y+1 }\n        case d if d == south -\u003e { x: house.x, y: house.y-1 }\n        else -\u003e house\n    }\n---\npayload splitBy \"\" reduce ((direction, houses=[start]) -\u003e \n    houses + move(direction, houses[-1])\n) distinctBy $\nthen sizeOf ($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\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%dw 2.0\ntype House = { x:Number, y:Number }\nvar west = \"\u003c\" // left\nvar east = \"\u003e\" // right\nvar north = \"^\" // up\nvar south = \"v\" // down\nvar start:House = { x:0, y:0 }\nfun move(direction:String, house:House):House =\n    direction match {\n        case d if d == west -\u003e { x: house.x-1, y: house.y }\n        case d if d == east -\u003e { x: house.x+1, y: house.y }\n        case d if d == north -\u003e { x: house.x, y: house.y+1 }\n        case d if d == south -\u003e { x: house.x, y: house.y-1 }\n        else -\u003e house\n    }\nfun getHouses(directions:Array):Array = \n    directions reduce ((direction, houses=[start]) -\u003e \n        houses + move(direction, houses[-1])\n    ) \nvar p = payload splitBy \"\"\nvar svrs = [(p filter (($$ mod 2) == 0)), (p filter (($$ mod 2) != 0))]\nvar santa = getHouses(svrs[0])\nvar robosanta = getHouses(svrs[1])\n---\nsanta ++ robosanta\ndistinctBy $\nthen sizeOf ($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday3%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 4\n\n\u003e [!NOTE]\n\u003e None of these scripts will run from the DW Playground. Part 1 can be run from vscode but Part 2 needs to run from the CLI.\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport MD5 from dw::Crypto\nvar secretKey = \"yzbqklnj\"\nfun getCorrectHash(number:Number) =\n    if (MD5((secretKey ++ number as String) as Binary) startsWith \"00000\")\n        number\n    else getCorrectHash(number+1)\n---\ngetCorrectHash(0)\n```\n\u003c/details\u003e\n\n### Part 2\n\n\u003e [!NOTE]\n\u003e I had to run this from the [DataWeave CLI](https://github.com/mulesoft-labs/data-weave-cli) because vscode was timing out. After you install it, you can run it with `dw run -f MyModule.dwl`\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport MD5 from dw::Crypto\nvar secretKey = \"yzbqklnj\"\nfun getCorrectHash(number:Number) =\n    if (MD5((secretKey ++ number as String) as Binary) startsWith \"000000\")\n        number\n    else getCorrectHash(number+1)\n---\ngetCorrectHash(0)\n```\n\u003c/details\u003e\n\n## 🔹 Day 5\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport countBy from dw::core::Arrays\n---\npayload splitBy \"\\n\" map do {\n    var vowels = sizeOf(flatten($ scan /[aeiou]/))\n    var doubleLetters = sizeOf(flatten($ scan /(.)\\1/))\n    var notThese = sizeOf(flatten($ scan /ab|cd|pq|xy/))\n    ---\n    (notThese == 0) and (doubleLetters \u003e= 2) and (vowels \u003e= 3)\n} countBy $\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday5%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 countMatches from dw::core::Strings\nimport countBy, some from dw::core::Arrays\n---\npayload splitBy \"\\n\" map ((line) -\u003e do {\n    var letterPairs = (line splitBy \"\" map ((letter, letterIndex) -\u003e \n        line[letterIndex to letterIndex+1]\n    ))[0 to -2] map (line countMatches $) some ($\u003e=2)\n    var otherThing = sizeOf(flatten(line scan /(.).\\1/)) \u003e= 1\n    ---\n    letterPairs and otherThing \n}) countBy $\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday5%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 6\n\n### Part 1\n\nOk, I tried several approaches here and I didn't want to just discard the ones that didn't work, so I'm keeping them here.\n\n- **[Attempt 1 - tailrec](/scripts/day6/part1/attempt1.dwl)** - For some reason this script was not processed as Tail Recursive??? I'm pretty sure it is. But ohwell. Had to discard the whole thing bc the payload is 300 lines (more than 255) so I was getting the `StackOverflow` error.\n- **[Attempt 2 - reduce + mapleafvalues](/scripts/day6/part1/attempt2.dwl)** - This one works perfectly fine when testing with a smaller matrix. But since the challenge is a 0,999 matrix, this solution times out.\n- **[Attempt 3 - i dont even know](/scripts/day6/part1/attempt3.dwl)**\n\n## 🔹 Day 8\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\nimport try from dw::Runtime\nvar newp = (payload splitBy \"\\n\") map {\n    code: sizeOf($),\n    memory: do {\n        var t = try(() -\u003e read($, \"json\"))\n        ---\n        (if (t.success) t.result else read($) replace /\\\\x[A-F0-9a-f]{1}[A-F0-9a-f]{1}/ with \"x\")\n        then sizeOf($)\n    }\n}\n---\nsum(newp.code) - sum(newp.memory)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\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 try from dw::Runtime\nvar newp = (payload splitBy \"\\n\") map {\n    code: sizeOf($),\n    part2: sizeOf(write($))\n}\n---\nsum(newp.part2) - sum(newp.code)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2015\u0026path=scripts%2Fday8%2Fpart2\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2015","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexandramartinez%2Fadventofcode-2015","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2015/lists"}