Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

The actual weights are encoded in the same fashion as in Martin Büttner's answerMartin Büttner's answer, with three minor modifications:

The actual weights are encoded in the same fashion as in Martin Büttner's answer, with three minor modifications:

The actual weights are encoded in the same fashion as in Martin Büttner's answer, with three minor modifications:

added 17 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

If the permalink doesn't work for youin your browser, you can copy the code from [this paste][2].

In supported browserbrowsers, you can [verify all test cases][3] at once.

If the permalink doesn't work for you, copy the code from [this paste][2].

In supported browser, you can [verify all test cases][3] at once.

If the permalink doesn't work in your browser, you can copy the code from [this paste][2].

In supported browsers, you can [verify all test cases][3] at once.

added 1790 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 175175 174 bytes

0000000: 7232316222faaf6c3e227b693138302b257d2f296322  r21b"..l>"{i180+%}/)c"
0000016: 492439c643444f5047141001b8815154e24cbed77b960221dce3cc4eb9561f953aaf640771c048ca3b9926c1  I$9.CDOPG!...N.V.QT.L:.d.{q.H.;.&.
000002c: 57e80828e518eb270b0fbf7dd32d658a5a2b110990784d033768588e2545069a202e128f0e238546134bdb31  W..(M.7hX.%E.'. ..}.-e.Z+#.F.K.x1
0000042: 6b3db3da42867a4a92e6e9c231db4b134685230e8f12c2e9e6924a7a8642dab33d6b789009112b5a8a652dd3  k=..B.zJ..Jz.B.1.K=kx.F.#.+Z.e-.
0000058: 2e209a0645258e586837034dc126993bca48c07107647dbf0f0b27eb18e52808e857967bd7be4ce2545181b8  }. ..E%'.Xh7.M.&(.;.HW.q{.d.L.TQ..
000006e: af3a951f56b94ecce3dc21022223292245f275992df401101447504f4443c6392449222322f43a606ce335e0  .:..V.N...!GPODC."#)"E9$I"#".u:`l.-5.
0000084: 174afe45a3761ecc9491a5c1aaf87cbf9c4bfd7cd1fb4356e76914357218e3942869eb8ab3f97e2e161ef061  .J.E.vCV.i.5r...(i...|.~.K.|..a
000009a: 24fdfb155721cb22323538623762364365723c3a2b59c310c6cbe922323538623762364365723e3a2b    $  Y...W!."258b7b6Cer<."258b7b6Cer>:+

If the permalink doesn't work for you, copy the code from [this paste][2].

In supported browser, you can [verify all test cases][3] at once.

Idea

The actual weights are encoded in the same fashion as in Martin Büttner's answer, with three minor modifications:

  • 12's are replaced with 6's instead of 7's.
  • The encoding is done in base 7 instead of base 8.
  • The order of the elements is reversed.

The difference between our answers lies in how the element abbreviations are stored.

In this approach, we hash all 100 element abbreviations into 8-bit characters, by doing the following:

  • Take the element name (treated as the array of its code points) and apply base 21 conversion.

Examples: "H"21b yields 72, "He"21b yields 1613 = 21 × 72 + 101.

  • Successively compute the residue of the division by 430, 355, 288 and 242.

Example: 1613 430% 355% 288% 242% yields 35.

  • Increment and cast to character.

Example: 35)c yields $.

Code

r         e# Read a whitespace-separated token from STDIN.
21b       e# Convert to intger, using base 21 conversion.
"ú¯l>"    e# Push that string.
{i180+%}/ e# Cast each char to integer, add 180 and apply modular division.
)c        e# Add 1 and cast to character.

"!ÜãÌN¹V:¯dqÀHÊ;&ÁM7hX%E .#FKÛ1ÂéæJzBÚ³=kx  +Ze-Ó}¿'ëå(èW{×¾LâTQ¸GPODCÆ9$I"

          e# Push that string.
          e# "He", e.g., is hashed to '$', which is the second char from the right.

#         e# Compute the index of the character hash in the string.

"ô:`lã5àCVçi5rã(ië³ù~.ðaYÃÆËé"

          e# Push that string.

 258b7b   e# Convert from base 258 to base 7.
 6Cer     e# Replace 6's with 12's.
 >        e# Keep only weight differences before the hashes occurrence.
 :+       e# Push the sum of the weight differences.

[1]: http://cjam.aditsu.net/#code=r21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22I%249%C3%86CDOPG%14%10%01%C2%B8%C2%81QT%C3%A2L%C2%BE%C3%97%7B%C2%96W%C3%A8%08(%C3%A5%18%C3%AB'%0B%0F%C2%BF%7D%C3%93-e%C2%8AZ%2B%11%09%C2%90xk%3D%C2%B3%C3%9AB%C2%86zJ%C2%92%C3%A6%C3%A9%C3%821%C3%9BK%13F%C2%85%23%0E%C2%8F%12.%20%C2%9A%06E%25%C2%8EXh7%03M%C3%81%26%C2%99%3B%C3%8AH%C3%80q%07d%C2%AF%3A%C2%95%1FV%C2%B9N%C3%8C%C3%A3%C3%9Cc%22%02!%02%22%23)%22E%C3%B2u%C2%99%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%B4%17J%C3%BEE%C2%A3v%1E%C3%8C%C2%94%C2%91%C2%A5%C3%81%C2%AA%C3%B8%7C%C2%BF%C2%9CK%C3%BD%7C%C3%91%C3%BB%24%C3%BD%C3%BB%15W!%C3%8B%22258b7b6Cer%3C%3A%2B&input=Pt%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B&input=Pt [2]: http://pastebin.com/KNKBR8uAhttp://pastebin.com/Y1pscnmg [3]: http://cjam.aditsu.net/#code=qN%2F%7BS%25~21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22%02!%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B%60%3D%7D%25&input=1%20H%0A4%20He%0A7%20Li%0A9%20Be%0A11%20B%0A12%20C%0A14%20N%0A16%20O%0A19%20F%0A20%20Ne%0A23%20Na%0A24%20Mg%0A27%20Al%0A28%20Si%0A31%20P%0A32%20S%0A35%20Cl%0A39%20K%0A40%20Ar%0A40%20Ca%0A45%20Sc%0A48%20Ti%0A51%20V%0A52%20Cr%0A55%20Mn%0A56%20Fe%0A59%20Co%0A59%20Ni%0A64%20Cu%0A65%20Zn%0A70%20Ga%0A73%20Ge%0A75%20As%0A79%20Se%0A80%20Br%0A84%20Kr%0A85%20Rb%0A88%20Sr%0A89%20Y%0A91%20Zr%0A93%20Nb%0A96%20Mo%0A98%20Tc%0A101%20Ru%0A103%20Rh%0A106%20Pd%0A108%20Ag%0A112%20Cd%0A115%20In%0A119%20Sn%0A122%20Sb%0A127%20I%0A128%20Te%0A131%20Xe%0A133%20Cs%0A137%20Ba%0A139%20La%0A140%20Ce%0A141%20Pr%0A144%20Nd%0A145%20Pm%0A150%20Sm%0A152%20Eu%0A157%20Gd%0A159%20Tb%0A163%20Dy%0A165%20Ho%0A167%20Er%0A169%20Tm%0A173%20Yb%0A175%20Lu%0A178%20Hf%0A181%20Ta%0A184%20W%0A186%20Re%0A190%20Os%0A192%20Ir%0A195%20Pt%0A197%20Au%0A201%20Hg%0A204%20Tl%0A207%20Pb%0A209%20Bi%0A209%20Po%0A210%20At%0A222%20Rn%0A223%20Fr%0A226%20Ra%0A227%20Ac%0A231%20Pa%0A232%20Th%0A237%20Np%0A238%20U%0A243%20Am%0A244%20Pu%0A247%20Bk%0A247%20Cm%0A251%20Cf%0A252%20Es%0A257%20Fm

CJam, 175 bytes

0000000: 7232316222faaf6c3e227b693138302b257d2f296322  r21b"..l>"{i180+%}/)c"
0000016: 492439c643444f5047141001b8815154e24cbed77b96  I$9.CDOPG.....QT.L..{.
000002c: 57e80828e518eb270b0fbf7dd32d658a5a2b11099078  W..(...'...}.-e.Z+...x
0000042: 6b3db3da42867a4a92e6e9c231db4b134685230e8f12  k=..B.zJ....1.K.F.#...
0000058: 2e209a0645258e586837034dc126993bca48c0710764  . ..E%.Xh7.M.&.;.H.q.d
000006e: af3a951f56b94ecce3dc21022223292245f275992df4  .:..V.N...!."#)"E.u.-.
0000084: 174afe45a3761ecc9491a5c1aaf87cbf9c4bfd7cd1fb  .J.E.v........|..K.|..
000009a: 24fdfb155721cb22323538623762364365723c3a2b    $...W!."258b7b6Cer<:+

If the permalink doesn't work for you, copy the code from [this paste][2].

[1]: http://cjam.aditsu.net/#code=r21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22I%249%C3%86CDOPG%14%10%01%C2%B8%C2%81QT%C3%A2L%C2%BE%C3%97%7B%C2%96W%C3%A8%08(%C3%A5%18%C3%AB'%0B%0F%C2%BF%7D%C3%93-e%C2%8AZ%2B%11%09%C2%90xk%3D%C2%B3%C3%9AB%C2%86zJ%C2%92%C3%A6%C3%A9%C3%821%C3%9BK%13F%C2%85%23%0E%C2%8F%12.%20%C2%9A%06E%25%C2%8EXh7%03M%C3%81%26%C2%99%3B%C3%8AH%C3%80q%07d%C2%AF%3A%C2%95%1FV%C2%B9N%C3%8C%C3%A3%C3%9C!%02%22%23)%22E%C3%B2u%C2%99-%C3%B4%17J%C3%BEE%C2%A3v%1E%C3%8C%C2%94%C2%91%C2%A5%C3%81%C2%AA%C3%B8%7C%C2%BF%C2%9CK%C3%BD%7C%C3%91%C3%BB%24%C3%BD%C3%BB%15W!%C3%8B%22258b7b6Cer%3C%3A%2B&input=Pt [2]: http://pastebin.com/KNKBR8uA

CJam, 175 174 bytes

0000000: 7232316222faaf6c3e227b693138302b257d2f296322  r21b"..l>"{i180+%}/)c"
0000016: 0221dce3cc4eb9561f953aaf640771c048ca3b9926c1  .!...N.V..:.d.q.H.;.&.
000002c: 4d033768588e2545069a202e128f0e238546134bdb31  M.7hX.%E.. ....#.F.K.1
0000042: c2e9e6924a7a8642dab33d6b789009112b5a8a652dd3  ....Jz.B..=kx...+Z.e-.
0000058: 7dbf0f0b27eb18e52808e857967bd7be4ce2545181b8  }...'...(..W.{..L.TQ..
000006e: 01101447504f4443c6392449222322f43a606ce335e0  ...GPODC.9$I"#".:`l.5.
0000084: 4356e76914357218e3942869eb8ab3f97e2e161ef061  CV.i.5r...(i....~....a
000009a: 59c310c6cbe922323538623762364365723e3a2b      Y....."258b7b6Cer>:+

If the permalink doesn't work for you, copy the code from [this paste][2].

In supported browser, you can [verify all test cases][3] at once.

Idea

The actual weights are encoded in the same fashion as in Martin Büttner's answer, with three minor modifications:

  • 12's are replaced with 6's instead of 7's.
  • The encoding is done in base 7 instead of base 8.
  • The order of the elements is reversed.

The difference between our answers lies in how the element abbreviations are stored.

In this approach, we hash all 100 element abbreviations into 8-bit characters, by doing the following:

  • Take the element name (treated as the array of its code points) and apply base 21 conversion.

Examples: "H"21b yields 72, "He"21b yields 1613 = 21 × 72 + 101.

  • Successively compute the residue of the division by 430, 355, 288 and 242.

Example: 1613 430% 355% 288% 242% yields 35.

  • Increment and cast to character.

Example: 35)c yields $.

Code

r         e# Read a whitespace-separated token from STDIN.
21b       e# Convert to intger, using base 21 conversion.
"ú¯l>"    e# Push that string.
{i180+%}/ e# Cast each char to integer, add 180 and apply modular division.
)c        e# Add 1 and cast to character.

"!ÜãÌN¹V:¯dqÀHÊ;&ÁM7hX%E .#FKÛ1ÂéæJzBÚ³=kx  +Ze-Ó}¿'ëå(èW{×¾LâTQ¸GPODCÆ9$I"

          e# Push that string.
          e# "He", e.g., is hashed to '$', which is the second char from the right.

#         e# Compute the index of the character hash in the string.

"ô:`lã5àCVçi5rã(ië³ù~.ðaYÃÆËé"

          e# Push that string.

 258b7b   e# Convert from base 258 to base 7.
 6Cer     e# Replace 6's with 12's.
 >        e# Keep only weight differences before the hashes occurrence.
 :+       e# Push the sum of the weight differences.

[1]: http://cjam.aditsu.net/#code=r21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22%02!%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B&input=Pt [2]: http://pastebin.com/Y1pscnmg [3]: http://cjam.aditsu.net/#code=qN%2F%7BS%25~21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22%02!%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B%60%3D%7D%25&input=1%20H%0A4%20He%0A7%20Li%0A9%20Be%0A11%20B%0A12%20C%0A14%20N%0A16%20O%0A19%20F%0A20%20Ne%0A23%20Na%0A24%20Mg%0A27%20Al%0A28%20Si%0A31%20P%0A32%20S%0A35%20Cl%0A39%20K%0A40%20Ar%0A40%20Ca%0A45%20Sc%0A48%20Ti%0A51%20V%0A52%20Cr%0A55%20Mn%0A56%20Fe%0A59%20Co%0A59%20Ni%0A64%20Cu%0A65%20Zn%0A70%20Ga%0A73%20Ge%0A75%20As%0A79%20Se%0A80%20Br%0A84%20Kr%0A85%20Rb%0A88%20Sr%0A89%20Y%0A91%20Zr%0A93%20Nb%0A96%20Mo%0A98%20Tc%0A101%20Ru%0A103%20Rh%0A106%20Pd%0A108%20Ag%0A112%20Cd%0A115%20In%0A119%20Sn%0A122%20Sb%0A127%20I%0A128%20Te%0A131%20Xe%0A133%20Cs%0A137%20Ba%0A139%20La%0A140%20Ce%0A141%20Pr%0A144%20Nd%0A145%20Pm%0A150%20Sm%0A152%20Eu%0A157%20Gd%0A159%20Tb%0A163%20Dy%0A165%20Ho%0A167%20Er%0A169%20Tm%0A173%20Yb%0A175%20Lu%0A178%20Hf%0A181%20Ta%0A184%20W%0A186%20Re%0A190%20Os%0A192%20Ir%0A195%20Pt%0A197%20Au%0A201%20Hg%0A204%20Tl%0A207%20Pb%0A209%20Bi%0A209%20Po%0A210%20At%0A222%20Rn%0A223%20Fr%0A226%20Ra%0A227%20Ac%0A231%20Pa%0A232%20Th%0A237%20Np%0A238%20U%0A243%20Am%0A244%20Pu%0A247%20Bk%0A247%20Cm%0A251%20Cf%0A252%20Es%0A257%20Fm

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading