I'm hosting my solutions on repl.it, and this one they don't let me finish calculating - I'm gonna have to look for some better optimization in order to let it finish within the resource boundary they set.
Anyway, I was able to handle the calculation locally and got the answers. I used the instructions to create sets of visited points, and then used set intersection to find the crossings. From there, it was finding either the minimum distance from the origin, or finding the minimum walk distance.
(nsaoc2019.day3(:require[clojure.string:asst][clojure.set:refer[intersection]]))(defnnext-step[last-posdirection](let[[xy]last-pos](condp=direction\U[x(incy)]\D[x(decy)]\R[(incx)y]\L[(decx)y])))(defnwalk"Provide the list of coords passed when moving a direction"[current-pathstep](let[direction(firststep)distance(inc(Integer/parseInt(st/join(reststep))))start-from(lastcurrent-path)](applyconjcurrent-path(rest(takedistance(iterate#(next-step%direction)start-from))))))(defnall-wire-coords[steps](loop[path[[00]]stepssteps](if(empty?steps)(restpath); remove initial [0 0] coordinate(recur(walkpath(firststeps))(reststeps)))))(defnp2019-03-part1[input](let[lines(st/split-linesinput)wires(map#(all-wire-coords(st/split%#","))lines)crosses(applyintersection(map#(into#{}%)wires))](->>crosses(map(fn[[xy]](+(Math/absx)(Math/absy))))(applymin))))(defnwalk-distance[wirescoord](let[first-wire(firstwires)second-wire(lastwires)](+(inc(.indexOffirst-wirecoord))(inc(.indexOfsecond-wirecoord)))))(defnp2019-03-part2[input](let[lines(st/split-linesinput)wires(map#(all-wire-coords(st/split%#","))lines)crosses(applyintersection(map#(into#{}%)wires))](->>crosses(map(fn[coord](walk-distancewirescoord)))(applymin))))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Woo! Day 3 is in the bag. :D
I'm hosting my solutions on repl.it, and this one they don't let me finish calculating - I'm gonna have to look for some better optimization in order to let it finish within the resource boundary they set.
Anyway, I was able to handle the calculation locally and got the answers. I used the instructions to create sets of visited points, and then used set intersection to find the crossings. From there, it was finding either the minimum distance from the origin, or finding the minimum walk distance.