8
this post was submitted on 02 Dec 2024
8 points (100.0% liked)
NotAwfulTech
6 readers
5 users here now
a community for posting cool tech news you don’t want to sneer at
non-awfulness of tech is not required or else we wouldn’t have any posts
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
2-1: I have quickly run out of hecks to give. This is the sort of problem that gives prolog programmers feelings of smug superiority.
spoiler
As usual the second part has punished me for my cowboy code, so I'll have to take a different more annoying tack (maybe tomorrow). Or you know I could just double down on the haphazard approach...
I decided to double down on 2-2, since bad code is one of life's little pleasures. Where we're going we won't need big-oh notation
spoiler
Commentary
Doing this "efficiently" should be possible. since you only need ~2-ish look-back you should be able to score reports in O(n) time. One complication is you might get the direction wrong, need to consider that erasing one of the first two elements could change the direction. But that requires thinking, and shoving all the permutations into a function with ungodly amounts of copying does not.re: 2-2
yeah that’s what I ended up thinking. Just try the brute force and if it’s too slow, maybe I’ll try be smarter about it.re: 2-2
I was convinced that some of the Perl gods in the subreddit would reveal some forgotten lore that solved this in one line but looks like my brute force method of removing one element at a time was the way to go.
I am now less sleep deprived so can say how to do better somewhat sensibly, albeit I cannot completely escape from C++s verbosity:
2-2
Updated code:
2-2