Challenge

Following my dismal performance in the technical portion of an interview last week, I decided that I needed to regularly work on programming tasks in order to maintain my technical skills. Unfortunately most of the courses I have been taking have given me few opportunities to flex my coding skills, and my personal projects have been dwindling in need of attention. Without a current project to work on, I decided to go back to the pythonchallenge buth this time, trying Rust, which is new to me. However, while rust is capable of fairly low level access, it just doesn’t scratch the same itch as C, so after the first couple of challenges, I decided to try to solve one in C.

First, in Rust; opne a file of garbage and sort out the lower-case letters:

They are probably both horribly hacky, but they both do the job. I will try to continue this in the weeks ahead.

Edit:

I was intrigued by the performance differences between these two solutions, so I did a little testing and found that the hacky c solution scans 1250 lines of the input text in 0.005 seconds while the rust solution takes 1.282 seconds. This inspired me to write a c version that used a regex like the rust solution does:

The c solution with regex is still significantly faster than rust clocking in 0.044 seconds. Then, I was inspired by a friend to try to optimize the plain c version further, using bit-masking as tool pattern match multiple chars at a time. This was slightly problematic since the pattern is nine chars long, and a long long can only mask 8 chars; the solution was to pattern match the first 8 chars of the pattern with one bitmask, then use another smaller bitmask to check the final char in the pattern. Unfortunately this yielded no improvement over the original, clunkier version.