All posts tagged Perl

Ok, so here is another coding question:

Given an input string, determine whether or not the string is composed of only abbreviations from the periodic table of elements.

This actually sounds kind of complex, like the stacking athlete question I answered previously, but it actually has a 2-line solution:

That’s right, given a string in $line, $result with be true if the string is composed solely of element name abbreviations. Simple huh? As for complexity, who knows. I don’t know enough of how regular expressions are computed to guess, but I assume it’s been made to be somewhat efficient.

Of course, additional optimizations can be made, for instance, “J” is not used in an elemental abbreviation, so any line with “J” could be disqualified (of course that requires a linear search of the data first).

Anyway, here’s the full script, in case you want to impress your friends.

I just created an SVN repository to host my various projects.  Right now it only has the source for my lone android application, a tip calculator (unique, I know).  There are 1800+ results for Tip Calculator apps in the Google play store, so I doubt I’ll be adding mine to the fray, but the wife can use it and it was a good intro to Java and Android programming.

The SVN repo is here:  It’s open for browsing, but I don’t really need any community contributions right now.  I’m using eclipse, so the apps are setup as eclipse projects.   No apks just yet, working on fixing the last few bugs.  I’ll probably create an FTP account to host the actual releases.

Anywho, that’s that.