Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Advent of Code
jason_1
Member Posts: 25 PRO
So has anyone here ever done Advent of Code before using Onshape FeatureScript? I didn't see any mention on this forum and I'm wondering, if anyone's used FS for it before. I just did Day 1 this year and it worked great and I was also able to plot out a fun graphical representation of the data (with a regen time of 1.2s). I'd be interested in seeing how other people would approach the problem though, especially how to best "read" the input
2
Comments
sketching all the vertical and horizontal sketch segments in day 5 was pretty simple, but is there a simple way to find the number or places where the line segments intersect? All of the queries or evaluate functions that might sound relevant at first aren't made to work with sketches as far as I know. Are there ways to query using sketch parts in a sketch?
You're right that using points will probably be faster, but spheres worked surprisingly fast and what's the point of using Onshape if you're not going to make unnecessary 3D geometry plus if you zoom in you can see that my points are actually festive baubles each colored in one of Formlabs' 16 named color kit resin colors. All "bonus points" here are just making up for the fact that I really don't know what I'm doing (I'd love to see other's code though!) and skipped two full days. But day 6 was pretty fun...
I'm pumped that you're watching the videos! I know my release pace is pretty low right now, but I try to make up for it in quality. I've got another one about 75% done, but not sure when I'll have time to finish it.
As for your question about how to "read" the input, I assume you mean how to process and format the inputs. If so, have you tried using the built-in regex capability in the find/replace tool. Here's an example from Day3. I am only just getting started in learning some regex, but there are tons of tutorials.
The other direction I looked into was directly importing the data into the onshape doc and learning how to use imports directly (I've only done it with 3D geometry) but it appears that I'd have to convert it to JSON or CSV or something first since the AoC inputs are all .txt files.
Have you looked at day 9 yet? I personally skipped Bingo in favor of focusing on ones that were more interesting visually in 3D (also it was a weekend day). The second pic is 9.1 visualized which is pretty neat, but the first pic is actually solving 9.2 -- basically it's plotting cylinders at every non-9 point such that they overlap with non-diagonal neighbors. All these cylinders are also 1 cubic mm so that when all bodies get boolean unioned you are left with the "basins" only and the volume of those remaining bodies is their "size" value (i.e. number of cylinders that were merged to create them). This works fine for ~one quadrant of the input but fails for the whole thing.
I then tried a version where I modeled the points as cuboids and plotted *only* the 9s so that there were much fewer points and that each body had far fewer tris to render. This was able to produce a similar output (see "pixel art" ver below) but also fails for the full input data set
IR for AS/NZS 1100
This is the code for that:
I favor the analytical approach you suggested. Maybe you could find a point at parameter [0.5,0.5] on each face. Next, take your giant array of all points, and iterate over each one, subtracting it from the main array and using isin() to see if there's a match. If true, do nothing. If false, add the corresponding faces to their own big array to analyze later. I've not tested this, but something like that could work.