2023 Day 2: Cube Conundrum

I spent most of the time fiddling with parsing. I’m sure there’s an easier way.

I spent most of the time forgetting to use <= instead of < :man_facepalming:.

@JeremyGrosser I looked at your code. I see how it works, but did you consider using an enumeration I/O?

I didn’t think of that! I always forget that exists. Next time!

I’ve udpated my repo with a Rust solution that relies on the pest crate to parse the input. I looked briefly at doing something similar in Ada, but the closest library that seems appropriate is Anagram, for which I don’t see a lot of documentation… and I really needed the documentation in pest.

1 Like

182 lines of Rust. Interesting. My Ada solutions are 58 and 54 lines for part 1 and 2, respectively, for a total of 112, but since I wrote two programs, the second duplicates the I/O and parsing. If I combined them, I could solve both parts in 62 lines. This helps confirm my impression that Rust is very low level.

I wouldn’t necessarily conclude that Rust requires you to work at a low level, and I’m not sure that’s true about my solution, anyway. I deliberately tried to do this with a particular crate that allows you to specify a parser (the .pest file) in that folder. In that sense I over-engineered it.

Consider that my Ada solution is over 200 lines (including comments, but that’s how you’re counting my Rust lines, too). If you remove comments, the Rust solution is more like 150 lines. Then consider double-spacing, which I use a lot of…

Added in edit: where I would agree with you (I mention this in the solution to day 3) is that Rust is a little less smart with types, offering machine-oriented types for integers, and indexing only from 0

I tend not to comment these things much, since they’re one off. I do use blank lines more than some people.

I saw that you used a parser, and so thought your code would consist of

  1. Set up parser
  2. Parse
  3. Process parsed data
  4. Report results

and so would be pretty short, maybe even shorter than my version, whcih only uses a line splitter and Ada.Strings.Fixed.Index.

Only integer indices with a fixed lower bound of zero is a common feature of low-level languages; it’s not really an index, it’s an offset. Leads to off-by-one errors, and prevents using them as maps.

Yes, this is a frustration of mine with not just Rust, but a lot of other languages as well, including some that advertise themselves as high level.

1 Like