Advent of Code 2020 - BaseA Style (Day 18)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Discussion thread for day 18 of the Advent of Code : https://adventofcode.com/2020/day/18
- Labels:
- Advent of Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here's me, lots of lovely regex today. 1.4s runtime.
Macro 1 Steps:
1) remove parentheses from any single number, e.g. (10) -> 10
2) parse the resulting text to split for the first operation found
3) if no operation is found, we only have a whole number so send it to output
4) calculate first operation and bring string back together. e.g. 4+6*3 -> 10*3
5) repeat until all operations processed
Macro 2. This is a little bit more involved due to the stricter order of operations. The steps here are:
1) remove single number parentheses
2) create waterfall of filters based on order of ops
2.1) any plain addition, e.g. 3*6+4 -> 3*10
2.2) contains addition but needs multiplication in parentheses done first. e.g. (3*6)+4 -> 18+4
2.3) only multiplaction left
2.4) only whole numbers -> output result
3) iteration outputs
3.1) send new strings back to repeat process
3.2) output all strings from each iteration, this helped with debugging and getting the parse logic correct for 2.2
I tried at first in macro 1 to do the regex parsing and function all in one formula tool along the lines of this
regex_replace([data],"(.*?)(\d+)([\+\*])(\d+)(\.*)", "$1" +ToString(ToNumber("$2")...
But I came up short so if anyone can smush the parsing and operation into one formula tool I'd love to see it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Regex and substrings everywhere... 0.6s tho
Internal macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@jdunkerley79 neat. I couldn't work out getting into fewer formula tools.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here is my solve. It's a bit 'tooly'. I figured there was a better way to solve this after I was an hour in, but by that point in the evening I was too stubborn and tired to turn back.
Thanks for detailing your solve @Balders. I may give it another go with a similar strategy.
Anyway, I ended up with 3 iterative macros; one to solve the parenthesis groupings and the other two to apply the logic for either part.
Parenthesis Grouping Macro
Part 1 Iterative
Part 2 Iterative
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I solved the problem via brute force and lots of copying and pasting tools instead of a macro. I'm posting my workflow here for comedic relief
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Day18!
Today I don't use any macro...
AS anonymous user #1105310
https://github.com/AkimasaKajitani/AdventOfCode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I'm trying to understand better how to replace macros with combinations of generate rows & multirows. Having fun even if the formulas inside are terrible to debug...(can't imagine inheriting one workflow where someone did something like this...)
EDIT: I solved it by adding an || to the condition.
Previous
I again created the iterative first, then the generate rows
My regex is so so, and probably overcomplicated the formula, will need to investigate that neat workflow by @jdunkerley79 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here's part 1. After making the effort to minimize the use of macros in previous days, I just gave in today and built an iterative one in about the same time that it takes me to ensure that the parentheses line up in nested IIF statements in the non-macro versions built previously. Runs quickly as well, 0.3s, since it only iterates once per level of parentheses and my input set was never nested more that 2 deep.
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
