{"id":18793201,"url":"https://github.com/alexandramartinez/adventofcode-2023","last_synced_at":"2026-01-25T13:01:43.934Z","repository":{"id":210949025,"uuid":"727792477","full_name":"alexandramartinez/adventofcode-2023","owner":"alexandramartinez","description":"DataWeave scripts used in the adventofcode.com site for 2023.","archived":false,"fork":false,"pushed_at":"2024-11-12T22:01:01.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T15:18:31.580Z","etag":null,"topics":["advent-of-code","advent-of-code-2023","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/2023","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,"zenodo":null}},"created_at":"2023-12-05T15:28:59.000Z","updated_at":"2024-11-12T22:01:05.000Z","dependencies_parsed_at":"2023-12-05T18:30:28.528Z","dependency_job_id":"64d9c79a-3ee0-4b32-8f62-daf6a45693bb","html_url":"https://github.com/alexandramartinez/adventofcode-2023","commit_stats":null,"previous_names":["alexandramartinez/adventofcode-2023"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexandramartinez/adventofcode-2023","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2023","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2023/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2023/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2023/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexandramartinez","download_url":"https://codeload.github.com/alexandramartinez/adventofcode-2023/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandramartinez%2Fadventofcode-2023/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28753411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T10:25:12.305Z","status":"ssl_error","status_checked_at":"2026-01-25T10:25:11.933Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-2023","adventofcode","challenge","challenges","dataweave","dataweave-lang","dataweave-language","dataweave-playground","programming","programming-challenges","programming-exercises","programming-language","programming-languages"],"created_at":"2024-11-07T21:23:57.505Z","updated_at":"2026-01-25T13:01:43.917Z","avatar_url":"https://github.com/alexandramartinez.png","language":"DataWeave","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advent of Code 2023\n\nDataWeave scripts used in the [adventofcode.com](https://adventofcode.com/) site for 2023.\n\n## Similar repos\n\n[![](https://github-readme-stats.vercel.app/api/pin/?username=alexandramartinez\u0026repo=adventofcode-2022\u0026theme=neon)](https://github.com/alexandramartinez/adventofcode-2022)\n[![](https://github-readme-stats.vercel.app/api/pin/?username=alexandramartinez\u0026repo=adventofcode-2015\u0026theme=neon)](https://github.com/alexandramartinez/adventofcode-2015)\n\n## 🔹 Day 1\n\nLive stream @ twitch.tv/mulesoft_community: [It's that time of the year again 🌲 Let's play Advent of Code 2023 with DataWeave ✨](https://www.twitch.tv/videos/1995939015)\n\n### Part 1\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport lines, isNumeric from dw::core::Strings\n\noutput application/json\n---\nlines(payload) map ((line) -\u003e do {\n    var nums = line filter (isNumeric($))\n    ---\n    (nums[0] ++ nums[-1]) as Number\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\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\nimport lines, isNumeric from dw::core::Strings\noutput application/json\nvar regex = /one|two|three|four|five|six|seven|eight|nine|ten|\\d/\nvar numbers = {\n    one: \"1\",\n    two: \"2\",\n    three: \"3\",\n    four: \"4\",\n    five: \"5\",\n    six: \"6\",\n    seven: \"7\",\n    eight: \"8\",\n    nine: \"9\"\n}\n---\nlines(payload) map ((line) -\u003e do {\n    var cleanLine = line\n        replace \"one\" with \"onee\"\n        replace \"two\" with \"twoo\"\n        replace \"three\" with \"threee\"\n        replace \"five\" with \"fivee\"\n        replace \"seven\" with \"sevenn\"\n        replace \"eight\" with \"eightt\"\n        replace \"nine\" with \"ninee\"\n    var nums = flatten(cleanLine scan regex) map ((n) -\u003e \n        if (isNumeric(n)) n\n        else numbers[n]\n    )\n    ---\n    (nums[0] ++ nums[-1]) as Number\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\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\nLive stream @ twitch.tv/mulesoft_community: [First stream of the year!! ~ Advent of Code 2023 Day 2](https://www.twitch.tv/videos/2027472277)\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport every from dw::core::Arrays\nimport lines from dw::core::Strings\noutput application/json\nvar maxRed = 12\nvar maxGreen = 13\nvar maxBlue = 14\n---\nlines(payload) map ((game, gameidx) -\u003e do {\n    var sets = game[8 to -1] splitBy \";\" map (\n        trim($) splitBy \",\" reduce ((item, acc={}) -\u003e \n            acc ++ {\n                ((item scan /red|green|blue/)[0][0]): (item scan /\\d+/)[0][0] as Number\n            }\n        )\n    )\n    ---\n    {\n        game: gameidx+1,\n        sets: sets,\n        isPossible: (sets reduce (set, acc=[]) -\u003e (\n            acc \n            + ((set.red default 0) \u003c= maxRed)\n            + ((set.green default 0) \u003c= maxGreen)\n            + ((set.blue default 0) \u003c= maxBlue)\n        )) every $\n    }\n}) \nfilter $.isPossible\nthen $.game\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\u0026path=scripts%2Fday2%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n### Part 2\n\nLive stream @ twitch.tv/mulesoft_community: [Playing Advent of Code with DataWeave once more! (Programming challenges)](https://www.twitch.tv/videos/2029366733)\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\n---\nlines(payload) map ((game, gameidx) -\u003e do {\n    var sets = game[8 to -1] splitBy \";\" map (\n        trim($) splitBy \",\" reduce ((item, acc={}) -\u003e \n            acc ++ {\n                ((item scan /red|green|blue/)[0][0]): (item scan /\\d+/)[0][0] as Number\n            }\n        )\n    )\n    fun getMaxNumber(color:String): Number = (\n        max(sets[color] default []) default 1\n    )\n    ---\n    getMaxNumber(\"red\") \n    * getMaxNumber(\"green\") \n    * getMaxNumber(\"blue\")\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\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\nLive streams @ twitch.tv/mulesoft_community: \n\n1. [Playing Advent of Code with DataWeave once more! (Programming challenges)](https://www.twitch.tv/videos/2029366733)\n2. [DataWeave, Advent of Code, reading your suggestions!](https://www.twitch.tv/videos/2034364533)\n\n\u003e [!CAUTION]\n\u003e I made a horrible code for this one. I'm really embarrassed about this. Check out Ignacio's code instead :'D  https://github.com/iglosiggio/aoc2023/blob/main/aoc2023day3ex1.dwl\n\n*Bad Alex :(*\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport update from dw::util::Values\nimport some from dw::core::Arrays\noutput application/json\nvar linesArr = (payload splitBy \"\\n\")\nvar regexForChars = /[^\\d.\\s]/\nvar mainArray = linesArr reduce ((line, acc=[]) -\u003e do {\n    acc ++ (flatten(line scan /\\d+/) map ((number) -\u003e do {\n        var regexExactNumberMatch = (\"(?\u003c!\\d)$(number)(?!\\d)\" as Regex)\n        var exactNumberMatchesIdxs = flatten(line find regexExactNumberMatch)\n        var firstIndex = (line find regexExactNumberMatch)[0][0]\n        var lastIndex = (firstIndex + (sizeOf(number)-1))\n        var firstIndexToCheck = if ((firstIndex-1) \u003e= 0) firstIndex-1 else firstIndex\n        var lastIndexToCheck = if ((lastIndex+1) \u003e sizeOf(line)-1) lastIndex else lastIndex+1\n        var currentLineIdx = (linesArr find line)[0]\n        var previousLineIdx = currentLineIdx - 1\n        var nextLineIdx = currentLineIdx + 1\n        var isPartAbove = if (previousLineIdx \u003e= 0) \n                linesArr[previousLineIdx][firstIndexToCheck to lastIndexToCheck] contains regexForChars\n            else false\n        var isPartBelow = if (nextLineIdx \u003e (sizeOf(linesArr)-1)) false\n            else linesArr[nextLineIdx][firstIndexToCheck to lastIndexToCheck] contains regexForChars\n        var isPartNext = line[firstIndexToCheck to lastIndexToCheck] contains regexForChars\n        ---\n        {\n            line: line,\n            number: number as Number,\n            firstIndex: firstIndex,\n            exactNumberMatchesIdxs: exactNumberMatchesIdxs,\n            isDupNum: sizeOf(exactNumberMatchesIdxs) \u003e1,\n            isPart: [isPartAbove, isPartBelow, isPartNext] some $\n        }\n    }))\n})\n---\ndo {\n    var resultWithDups = sum((mainArray filter $.isPart).number)\n    var dupNums = sum((mainArray filter $.isPart and $.isDupNum).number distinctBy $)\n    var duplicatesNotChecked = ((mainArray filter $.isDupNum filter ($$ mod 2) != 0) map do {\n            var firstIndex = $.exactNumberMatchesIdxs[-1] // decided to assume there's only 2 matches per line :')\n            var lastIndex = (firstIndex + (sizeOf($.number)-1))\n            var firstIndexToCheck = if ((firstIndex-1) \u003e= 0) firstIndex-1 else firstIndex\n            var lastIndexToCheck = if ((lastIndex+1) \u003e sizeOf($.line)-1) lastIndex else lastIndex+1\n            var currentLineIdx = (linesArr find $.line)[0]\n            var previousLineIdx = currentLineIdx - 1\n            var nextLineIdx = currentLineIdx + 1\n            var isPartAbove = if (previousLineIdx \u003e= 0) \n                    linesArr[previousLineIdx][firstIndexToCheck to lastIndexToCheck] contains regexForChars\n                else false\n            var isPartBelow = if (nextLineIdx \u003e (sizeOf(linesArr)-1)) false\n                else linesArr[nextLineIdx][firstIndexToCheck to lastIndexToCheck] contains regexForChars\n            var isPartNext = $.line[firstIndexToCheck to lastIndexToCheck] contains regexForChars\n            ---\n            {\n                line: $.line,\n                number: $.number as Number,\n                exactNumberMatchesIdxs: $.exactNumberMatchesIdxs,\n                firstIndex: firstIndex,\n                isPart: [isPartAbove, isPartBelow, isPartNext] some $\n            }\n        }) filter $.isPart then sum($.number)\n    ---\n    {\n        resultWithDups: resultWithDups, // suming up everything that is considered a part (even duplicates per line)\n        dupNums: dupNums, // suming up the duplicate numbers that are a part (to remove them from the previous count)\n        duplicatesNotChecked: duplicatesNotChecked, // suming up the duplicates that are a part that were not previously checked correctly\n        finalResult: resultWithDups - dupNums + duplicatesNotChecked // final operations :')\n    }\n} \n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\u0026path=scripts%2Fday3%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 4\n\n\u003e [!NOTE]\n\u003e I couldn't solve Part 2, but check out [this amazing script](https://github.com/iglosiggio/aoc2023/blob/main/aoc2023day4ex2.dwl) to solve it.\n\n### Part 1\n\nLive stream @ twitch.tv/mulesoft_community: \n\n- [Solving Advent of Code puzzles with DataWeave (day 4 part 1)](https://www.twitch.tv/videos/2235381320)\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\nimport countBy from dw::core::Arrays\nimport lines, substringBefore, substringAfter from dw::core::Strings\noutput application/json\nfun getNumbers(numbers) = flatten(numbers scan /\\d+/)\n---\nlines(payload) map ((line) -\u003e do {\n    var cardName = (line substringBefore \":\")\n    var numbers = (line substringAfter \":\") splitBy \"|\"\n    var winningNumbers = getNumbers(numbers[0])\n    var actualNumbers = getNumbers(numbers[1])\n    var matchingNumbers = winningNumbers countBy (actualNumbers contains $)\n    var score = matchingNumbers match {\n        case 1 -\u003e 1\n        case 0 -\u003e 0\n        else -\u003e 2 pow matchingNumbers-1\n    }\n    ---\n    // for debugging purposes\n    // {\n    //     (cardName): {\n    //         winning: winningNumbers,\n    //         actual: actualNumbers,\n    //         matchingNumbers: matchingNumbers,\n    //         score: score\n    //     }\n    // }\n\n    // actual needed code\n    score\n})\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\u0026path=scripts%2Fday4%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n## 🔹 Day 15\n\n### Part 1\n\nLive stream @ twitch.tv/mulesoft_community: \n\n- [More Advent of Code puzzles with DataWeave! (day 15 part 1)](https://www.twitch.tv/videos/2249213036)\n\n\u003cdetails\u003e\n  \u003csummary\u003eScript\u003c/summary\u003e\n\n```dataweave\n%dw 2.0\noutput application/json\nimport charCode from dw::core::Strings\nfun getnum(currentvalue, asciicode) = ((currentvalue + asciicode) * 17) mod 256\nfun getResult(string, r=0) = do {\n    @Lazy\n    var newR = r getnum charCode(string)\n    ---\n    if (!isEmpty(string))\n        string[1 to -1] getResult newR\n    else r\n}\n---\n(payload splitBy \",\") map getResult($)\nthen sum($)\n```\n\u003c/details\u003e\n\n\u003ca href=\"https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo\u0026repo=alexandramartinez%2Fadventofcode-2023\u0026path=scripts%2Fday15%2Fpart1\"\u003e\u003cimg width=\"300\" src=\"/images/dwplayground-button.png\"\u003e\u003ca\u003e\n\n---\n\n## Other repos\n\n- Ryan Hoegg's [adventofcode2023](https://github.com/rhoegg/adventofcode2023)\n- Ignacio Esteban Losiggio's [aoc2023](https://github.com/iglosiggio/aoc2023)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2023","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexandramartinez%2Fadventofcode-2023","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandramartinez%2Fadventofcode-2023/lists"}