Instantly share code, notes, and snippets.

What would you like to do?
Advent of Groovy code, day 9
// see challenge here:
String input = /your input here/
String collapseEscape = input.replaceAll(/!./,'')
String collapseGarbage = collapseEscape.replaceAll(/<.*?>/,'')
String listString ='{}','[]')
String normCode = listString.replaceAll(/\[,/,'[')
def roseTree = evaluate(normCode)
def dfsVisit(node, Integer depth, Closure todo) {
todo(depth) // could be fused but I like the separation
for (child in node) { dfsVisit child, depth+1, todo}
def result = 0
dfsVisit(roseTree, 1) { depth -> result += depth }
println result

This comment has been minimized.

cchanley2003 commented Dec 10, 2017

Doesn't work for input of: String input = {garbage, garbage, garbage,garbage}
Changing String normCode = listString.replaceAll(/[,/,'[')
to String normCode = listString.replaceAll(/[,*+/,'[') works

I love your frege examples, btw.


This comment has been minimized.


Dierk commented Dec 13, 2017

thanks for the comment and the kind words!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment