9
Your task is to take an string containing an isotope of an element as input, encoded like the following example with the atomic number followed by a space and the IUPAC chemical symbol for the element:
162 Dy
and return the number of neutrons in an atom of that isotope.
In the above example, dysprosium-162 has 96 neutrons (162 total nucleons, minus 66 protons because it's dysprosium), so the output should be 96
.
You may assume that the element given will be one of the 114 elements currently given permanent names by the IUPAC (including flerovium and livermorium) and not a generic name such as Uus
for "ununseptium". You may also assume that the atomic number of the isotope will not exceed 1000, or be less than the number of protons in the element.
You may not use built-ins to retrieve data about the proton or neutron number of elements, or use any function within your code that evaluates a string or number token as code on its own.
The program to use the fewest tokens to do this in any language wins. However, for the purpose of this challenge, every character in a string, or a variable name converted into a string, counts as a token.
List of elements and their atomic number for reference:
{
"H": 1,
"He": 2,
"Li": 3,
"Be": 4,
"B": 5,
"C": 6,
"N": 7,
"O": 8,
"F": 9,
"Ne": 10,
"Na": 11,
"Mg": 12,
"Al": 13,
"Si": 14,
"P": 15,
"S": 16,
"Cl": 17,
"Ar": 18,
"K": 19,
"Ca": 20,
"Sc": 21,
"Ti": 22,
"V": 23,
"Cr": 24,
"Mn": 25,
"Fe": 26,
"Co": 27,
"Ni": 28,
"Cu": 29,
"Zn": 30,
"Ga": 31,
"Ge": 32,
"As": 33,
"Se": 34,
"Br": 35,
"Kr": 36,
"Rb": 37,
"Sr": 38,
"Y": 39,
"Zr": 40,
"Nb": 41,
"Mo": 42,
"Tc": 43,
"Ru": 44,
"Rh": 45,
"Pd": 46,
"Ag": 47,
"Cd": 48,
"In": 49,
"Sn": 50,
"Sb": 51,
"Te": 52,
"I": 53,
"Xe": 54,
"Cs": 55,
"Ba": 56,
"La": 57,
"Ce": 58,
"Pr": 59,
"Nd": 60,
"Pm": 61,
"Sm": 62,
"Eu": 63,
"Gd": 64,
"Tb": 65,
"Dy": 66,
"Ho": 67,
"Er": 68,
"Tm": 69,
"Yb": 70,
"Lu": 71,
"Hf": 72,
"Ta": 73,
"W": 74,
"Re": 75,
"Os": 76,
"Ir": 77,
"Pt": 78,
"Au": 79,
"Hg": 80,
"Tl": 81,
"Pb": 82,
"Bi": 83,
"Po": 84,
"At": 85,
"Rn": 86,
"Fr": 87,
"Ra": 88,
"Ac": 89,
"Th": 90,
"Pa": 91,
"U": 92,
"Np": 93,
"Pu": 94,
"Am": 95,
"Cm": 96,
"Bk": 97,
"Cf": 98,
"Es": 99,
"Fm": 100,
"Md": 101,
"No": 102,
"Lr": 103,
"Rf": 104,
"Db": 105,
"Sg": 106,
"Bh": 107,
"Hs": 108,
"Mt": 109,
"Ds": 110,
"Rg": 111,
"Cn": 112,
"Fl": 114,
"Lv": 116
}
Ahaha right, just read the tag wiki. Seems like I misunderstood what the tag encompassed. – Sp3000 – 2014-12-10T04:53:07.853
So by tokens, you mean
K
ora
in CJam are single tokens just likeString
amd.repeat
are ? – Optimizer – 2014-12-10T05:52:21.037@Optimizer Yes, exactly. – Joe Z. – 2014-12-10T05:54:34.710
1In general, atomic code golf is better than code golf in terms of fairness between languages because it doesn't favour golfing-specific languages like CJam or Golfscript. – Joe Z. – 2014-12-10T05:56:22.337
Yes, none of those elements will be entered as input. – Joe Z. – 2014-12-10T06:29:54.017
2Are numbers considered as single token ? Like in my answer, is
65
a single token or 2 tokens ? – Optimizer – 2014-12-10T08:09:46.750Those are naturally disallowed. – Joe Z. – 2014-12-10T08:27:23.327
How are tokens counted in function calls. Is
f(a,b)
3, 4, 5 or 6 tokens? – Martin Ender – 2014-12-10T08:44:53.607@JoeZ. What about my numbers query ? – Optimizer – 2014-12-10T08:47:16.037
4"In general, atomic code golf is better than code golf in terms of fairness between languages because it doesn't favour golfing-specific languages like CJam or Golfscript." Or does it? ;) – Martin Ender – 2014-12-10T09:25:35.793
1If built-ins were allowed, the following function, written in Mathematica, might be used:
f[i_] := {n = ElementData[#[[2]], ToString@"StandardName"] <> ToString[#[[1]]], IsotopeData[n, "NeutronNumber"]} &[i]
– DavidC – 2014-12-10T15:29:01.880