“原子”代码高尔夫球-确定同位素中的中子数


9

您的任务是将包含元素同位素的字符串作为输入,如下面的示例所示,其编码为原子序号,后跟一个空格和该元素的IUPAC化学符号:

162 Dy

并返回该同位素原子中的中子数。

在以上示例中,162具有96个中子(162个总核子,由于是66而减去66个质子),因此输出应为96

您可能会假定给定的元素将是IUPAC当前给定的114个永久性元素之一(包括fl药和肝mor),而不是通用名称,例如Uus“ un”。您还可以假定同位素的原子数不超过1000,或小于元素中的质子数。

您可能无法使用内置函数来检索有关质子或中子元素数量的数据,也不能使用代码中的任何函数将字符串或数字标记本身视为代码。

该程序使用最少的令牌以任何语言执行此操作均会获胜。但是,出于此挑战的目的,字符串中的每个字符或转换为字符串的变量名称都视为标记。

元素列表及其原子序号供参考:


啊哈哈,对,只需阅读标签Wiki。好像我误解了标签包含的内容。
Sp3000

1
通常,就语言之间的公平性而言,原子代码高尔夫优于代码高尔夫,因为它不喜欢高尔夫专用语言(例如CJam或Golfscript)。
Joe Z.

2
数字是否被视为单个令牌?就像我的答案一样,是65一个令牌还是2个令牌?
Optimizer

4
“总的来说,就语言之间的公平性而言,原子代码高尔夫优于代码高尔夫,因为它不喜欢高尔夫专用语言(例如CJam或Golfscript)。” 还是呢?;)
Martin Ender 2014年

1
如果允许内置,则可以使用用Mathematica编写的以下函数:f[i_] := {n = ElementData[#[[2]], ToString@"StandardName"] <> ToString[#[[1]]], IsotopeData[n, "NeutronNumber"]} &[i]
DavidC 2014年

Answers:


5

CJam,120 6或116个令牌

如果数字是单个令牌,那么我们将整个代码作为6个令牌:

212065132249371573644124577121541653292994215804249878509033804566332949723850494006885998432589817663973272353884582668784347806472090795216938149345570424681103578762377771127645936569136562173556524971260383556793671988140498193154122873972644190003488894117491373991987567199279175132071186860926217964652052981868515510731685503564515183920386542420190587555479397630718313762477968862282786518176572529906744217608955037610524188966159703528812103601771438848515748286560373093942224945233978303729665751831532717 128b:c~

令牌在哪里

212065132249371573644124577121541653292994215804249878509033804566332949723850494006885998432589817663973272353884582668784347806472090795216938149345570424681103578762377771127645936569136562173556524971260383556793671988140498193154122873972644190003488894117491373991987567199279175132071186860926217964652052981868515510731685503564515183920386542420190587555479397630718313762477968862282786518176572529906744217608955037610524188966159703528812103601771438848515748286560373093942224945233978303729665751831532717
128
b
:
c
~

此代码等效于以下代码,其中包含上述代码中大数字的字符串版本。但是由于有一个字符串,下面的代码有116个令牌:

ri"ᘭ᛭绊ڏ晍嬨塐弶⛡ᠸ庐ᖩે槑湘ࡊ㚋䊌栕ᄂỗ∘抁埵ໂČ槩唹ᘇ穗≧ṷ㴛勤烓≿Ⲳ㇭Ȋ嬅͙獚簜䱡数㍉㉦䩛爈拴矍㚴燌㾄䱮⃜⢴ⶏ㯗႒ݘ੡䅄瞟⮘㢧⳻⮵∼䚽珯ほֹ㳰櫣ݰ牜᫦殙ᆌ穟䖻ᄭⓚ獙஧༧撒咛啺"2F#b57b65f+:cr2*2<#2/)-

令牌(带有说明)是

r                           "Read the first input";
i                           "and convert it to integer";
"
91 character string         "Then this base converted string";
"
2
F
#                           "'s ASCII representation of each character gets converted";
b                           "to base 2**15";
57                          "which gets converted to";
b                           "base 57";
65                          "and we add 65 to each element in the base 57 array";
f
+
:
c                           "and convert each array element to character.";
r                           "Then read the next input string, which is atom's IUPAC";
2                           "double it";
*
2                           "and take only first 2 characters";
<
#                           "Find the occurrence of these 2 characters in the big string";
2                           "and divide the index by 2";
/
)                           "increment the index to counter 0 offset";
-                           "and subtract this number, which is the atomic number from"
                            "the input number of nucleons";

要运行上述字符串,请从此链接复制代码,因为SE在上载答案时会删除一些字符。

它也可以减少到109个令牌,但是SE不允许我上传我的答案,并抛出格式错误的URI异常。

输入像

162 Dy

输出就像

96

奇怪的字符串只是一个基本编码的字符串,在其Atomic number * 2 - 1索引处包含所有IUPAC名称。

在这里在线尝试


为什么数字不是单个标记?
Martin Ender 2014年

@MartinBüttner好吧,如果出于这个问题的目的,字符串不是单个标记,那么数字可能也不是:)
Optimizer

1
这给硼和铟的结果带来了错误,因为两个元素的字母以开头BI出现在它们之前。
Martin Ender 2014年

^您的意思是硼和碘。铟是In
Joe Z. 2014年

还有,伙计们。B和我的那个错误已修复。
Optimizer

1

具有exec,17个令牌的Python 3

exec(int.to_bytes(42580960806925240587487231677747050990110980939298529158008049507419456038066480774222358994792932281429500848123044123619998194774734911333011516763318834841258668032468977581617546825403043048781904307873076644287421190283925612029151422009703963147720234582458918676020358978146687598642493196719470433413287097024943497230356536978257362073205770196031226838532057690859535911353521203287284228407660035870497366713816359382867026152168356178620422021081074864815228071041303891869741111572003521808946355179139580269537828514345177247630946236685801543450404664783011350766913659964138280312012942354586269107632396118108534925651704031851802293836135007879834261627022944650861299698061444211422731907625,295,'big'))

没有exec,35个令牌的Python 3

m,n=input().split()
print(int(m)-(0x50000003c00000000000000000000000000000000000000000000000000000000000000000000000000000000008c00000000000000000000000000000000000000000000000000000000d80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000116880005ad0000d002b832400000000000000000000000000000004c0000064f8000003806a0088015660000000000000000000000000000b00000000000ac0000000016efd12c0004b60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017a700760005400f400000000000001700a56c000000000000000000000000000004c0000000000000000000000000000000000000000000000000000000000000000002ee6000000000700000029e00522c0000000000000000000000000003680000002a3200000000000c00032800000000000000000000000000000e91c000ce000000000000000c000000000000e400000000000000000000000000000004800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009a000006200000000000000000000000000000000000000000000000000006c0000043000000000000509008000000000000000000000000000000000000000000000000000000000000082000007c0000000000000000000000000000000ae00000019390000000000068000000000000000000000000000000000fc06388000000000000000000000000000000000000000000000000108000000006e0000000000000000000000000000d2000000000000000000000000000074037300001be1808800000000c4e98000050000000000000000000000000000000046000000000061014f580001000000e0000000000000000000000000013eaa12400000017c680000002f0000059000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009c04a2f7001000007880e0001300d408012000060a0000000000000000000>>7*int(n,36)&127))

Ruby with eval,17个令牌

eval [22146635005300445083784033446026580324048447941091204274213253110537099437818224958820496527991920943430421799402248351995854377736142191462062582991150146209770141259010870255095388946677505144127700666745571877848513432112199556183753919673308110291261587736766001750331575554182707626697924148465335917814388410868486650419909619279250674754531982074694183257024218097391705830277480110741636037821082572926228904583257826932150641336017429157246896262085081972165351023141358378905645164343005169041637147077645200273099823888392038731180787177889720531999846231330677441270444855911286469030157575699579420898896870179419644019549285098577609138033580761786048462145007410.to_s(16)].pack('H*')

Javascript,49个令牌

m=prompt().split(/ /);
alert(m[0]-(function(){
_H_He_Li_Be_B_C_N_O_F_Ne_Na_Mg_Al_Si_P_S_Cl_Ar_K_Ca_Sc_Ti_V_Cr_Mn_Fe_Co_Ni_Cu_Zn_Ga_Ge_As_Se_Br_Kr_Rb_Sr_Y_Zr_Nb_Mo_Tc_Ru_Rh_Pd_Ag_Cd_In_Sn_Sb_Te_I_Xe_Cs_Ba_La_Ce_Pr_Nd_Pm_Sm_Eu_Gd_Tb_Dy_Ho_Er_Tm_Yb_Lu_Hf_Ta_W_Re_Os_Ir_Pt_Au_Hg_Tl_Pb_Bi_Po_At_Rn_Fr_Ra_Ac_Th_Pa_U_Np_Pu_Am_Cm_Bk_Cf_Es_Fm_Md_No_Lr_Rf_Db_Sg_Bh_Hs_Mt_Ds_Rg_Cn_Uut_Fl_Uup_Lv_
}).toString().split(/_/).indexOf(m[1]))

只是为了说明在原子代码高尔夫中将大整数/符号/变量计数为N个标记 :)


是否禁止evalexec打击的工作?
乔Z. 2014年

@JoeZ。仍然容易受到“大整数查找表”攻击,请参阅更新。
kennytm 2014年

这样看来,这个问题从一开始就形成了。
Joe Z. 2014年

0

Javascript,42个令牌(?)

alert(parseInt(x=prompt().split(" "))-Object.getOwnPropertyNames({__H_HeLiBeB_C_N_O_F_NeNaMgAlSiP_S_ClArK_CaScTiV_CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY_ZrNbMoTcRuRhPdAgCdInSnSbTeI_XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW_ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU_NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCn__Fl__Lv:0})[0].indexOf(x[1])/2)

PS:在哪里可以找到一些脚本来计算令牌?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.