#Bash + coreutils, 381
Bash + coreutils, 381
base64 -d<<<H4sICPGCjVUAA3B0LnR4dABNUMuShCAMvPcveQIEoUaQAtzdmf//kO2Ol7GKEJP0I2QAOTKcBfBMPALQgIu1hKZWc6gHb3dicgodkzGcDHjBjS04pZhEYmniB2Hwqg1JBOHaWrGRcOPTLDuEOdh107ARfhjhwPAqDLyBD2tNv5V+lvjHzZPlYif2MFJmKEY7Fac3hYIl8T+GYBqekqdDiOiSajt6fYzzivdji1zL8DvlM1UjZ5fNvVk/NZaTFtUCvzQjEVxUKGLti7aMK8vc0it1An3Z+gW38PUNvo8ww8FpN3SHla3VOh5DrqIrC3XzL9s2Ido6SBX/wOjUg78BAAA=|zcat|sed -n "/\b$1\b/I="
This is simply the elements represented in a file thus:
H
HE
LI
BE
...
Note the line number of the element corresponds with the mass. In cases where there are multiple elements with the same mass, the line looks like:
AR;CA
The file is gzipped and base64 encoded. Note the element names are all in upper case to improve compression. Interestingly gzip and bzip2 had identical compressed lengths, and xz was a little bit longer.
The base64 -d
and zcat
simply convert the base64 stream back to this original file. The sed
then simply searches (case insensitively) for the input string and outputs its line number.
###Test output:
Test output:
$ for e in O Sn H Fm Ni Co; do ./pt.sh $e; done
16
119
1
257
59
59
$