3 ms·
Outside of an interview have you ever needed to reverse a string?
by darrylb42 6y ago
Outside of an interview have you ever needed to reverse a string?
- tgv 6y agoSorting by reversed string is not totally uncommon.
- neolog 6y agoWhat is a use case for this?
- carapace 6y agoI did this yesterday. find ... | rev | sort | rev > sorted-filelist I had several directories and I wanted to pull out the unique list of certain files (TrueType fonts) across all of them, regardless of which subdirs they were in. (I'm omitting the find CLI args for clarity; the command just finds all the *.ttf (case-insensitive) files in the dirs.) By reversing the lines before sorting them (and un-reversing them) they come out sorted and grouped by filename.
- neolog 6y agoThat's clever. But in a programming language (instead of a composition of coreutils), I would use a filename() function or something.
- tgv 6y agoAnother use case is finding words with a common ending. Can be used for finding similar inflections or rhymes (in which case you'd use some form of phonetic alphabet, which fits in normal ASCII, so the problem wouldn't arise there). I also once used it for a (very) quick&dirty spell correction algorithm, which had to run in less than 1s and had to read all data from CD-ROM.
- benibela 6y agoI have my personal library of string functions Recently I rewrote the codepoint reverse function to make it faster. The trick is to not write codepoints, but copy the bytes. One the first attempt I introduced two bugs.