Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

3 of 18
deleted 12 characters in body
J.Doe
  • 2.7k
  • 12
  • 15

R, 346 bytes

Explanation.

Look up the atomic number in a UTF8 encoded hash string s. The hash is taken by multiplying the vector c(1,20) by the ASCII byte number of the characters of the element name, taking the sum, and taking that mod 430.

Use a quadratic fit curve to find the approximate mass from the atomic number. Eg for Lanthanum n=57 we get an approximate mass of -2.2+2.257+0.0041757^2 = 136.7483 and take the ceiling of that, 137.

Look up the correction which is an integer in [-5, 4] in another UTF8 encoded hash string, o. This is encoded with two offsets minus 5 per byte, e.g. for the 57th element, look up the 29th offset byte which is "K" or ASCII 75, take the tens place and subtract 5, e.g. 7-5 = 2. So for Lanthanum we add 2 to the quadratic fit, making 139 the mass.

function(x,n=match(sum(c(1,20)*!x)%%430,!'ÞŴŮ`uŜű ́źĪơK!ƆMÃĝğŗ"×ばつsÄÍłÕ•Üľ“ŘĐŨƕś{…ŃƀóƄÙĞĨůÒŦnqăşńŒŽÇrʼnĊƈİkžåËúÿƜ^l·–ë„ÈĮŅĬA ̈Ď_a8ƃÛd'))(-2.2+2.2*n+0.00417*n^2)%/%1+1+(!'8MK7@6+*$,5+ -887+-E9CK".8A--7-7-7)	M9%%"')[n/2+.5]%/%10^(n%%2)%%10-5
"!"=utf8ToInt

Try it online!

J.Doe
  • 2.7k
  • 12
  • 15

AltStyle によって変換されたページ (->オリジナル) /