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 Answer

added 1388 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 273 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a 2-vector encoded with UTF-8 and modding three times in succession. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sum(+x*+"")%%740%%623%%278,+'{ćWZ}èċæŸ+Ó>qÿƒ!2Eo&ē_u1⁄28`h›’Hb‰1ĎŽ‹@-if9ÃÛ%ù]V‚:LkXlÙDRŠ•˜OU·m,Sμ5TËt6cC7#­/ąz1A')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

A mention to this 275 byte solution which nearly beats the R record by encoding three mass differences in mixed base 6,5.

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 273 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a 2-vector encoded with UTF-8 and modding three times in succession. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sum(+x*+"")%%740%%623%%278,+'{ćWZ}èċæŸ+Ó>qÿƒ!2Eo&ē_u1⁄28`h›’Hb‰1ĎŽ‹@-if9ÃÛ%ù]V‚:LkXlÙDRŠ•˜OU·m,Sμ5TËt6cC7#­/ąz1A')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 273 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a 2-vector encoded with UTF-8 and modding three times in succession. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sum(+x*+"")%%740%%623%%278,+'{ćWZ}èċæŸ+Ó>qÿƒ!2Eo&ē_u1⁄28`h›’Hb‰1ĎŽ‹@-if9ÃÛ%ù]V‚:LkXlÙDRŠ•˜OU·m,Sμ5TËt6cC7#­/ąz1A')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

A mention to this 275 byte solution which nearly beats the R record by encoding three mass differences in mixed base 6,5.

deleted 10 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 280273 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a base 36 case insensitive number2-vector encoded with UTF-8 and modding with 908, then 591, then 321three times in succession. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(strtoisum(x,36+x*+"")%%908%%591%%321%%740%%623%%278,+'#·Yû÷Ù<v„BypšŠàé‡ÿ6ĉčCrfœK":øá”^Q7|P+'{o–Ħ‹U ̄ćWZ}úzÕČ“μèċæŸ+Ó>qÿƒ!2Eo&ē_u1⁄28`h›’Hb‰1ĎŽ‹@-ÒžÃ$’ NĭTE%]DWöJ3™Ć=…_~Óñ'if9ÃÛ%ù]V‚:LkXlÙDRŠ•˜OU·m,Sμ5TËt6cC7#­/ąz1A')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online! Try it online!

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 280 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name as a base 36 case insensitive number and modding with 908, then 591, then 321. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(strtoi(x,36)%%908%%591%%321,+'#·Yû÷Ù<v„BypšŠàé‡ÿ6ĉčCrfœK":øá”^Q7|P{o–Ħ‹U ̄}úzÕČ“μ-ÒžÃ$’ NĭTE%]DWöJ3™Ć=…_~Óñ')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 273 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a 2-vector encoded with UTF-8 and modding three times in succession. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sum(+x*+"")%%740%%623%%278,+'{ćWZ}èċæŸ+Ó>qÿƒ!2Eo&ē_u1⁄28`h›’Hb‰1ĎŽ‹@-if9ÃÛ%ù]V‚:LkXlÙDRŠ•˜OU·m,Sμ5TËt6cC7#­/ąz1A')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

deleted 30 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) 287(削除) 287 (削除ここまで) 280 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by multiplying the vector c(5,407) by the ASCII byte number of the characters oftaking the element name, taking the sum, and taking that mod 428. The hash was selected by as a brute force search to minimize bytecountbase 36 case insensitive number and is itself encoded as UTF8modding with 908, then 591, then 321. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sumstrtoi(+"Ɨ"*+x)%%428x,+"×ばつűŅĘŶ2Ly@¡ĠÄ36)%%908%%591%%321,Â5]ŮĮŷÃõEt<7Ţ’ûĊƋJů©[ďc?Ŧ_l·xohőĤ6ĉÑð`UƂKŸ2аSoßōFÉ"+'#·Yû÷Ù<v„BypšŠàé‡ÿ6ĉčCrfœK":øá”^Q7|P{o–Ħ‹U ̄}úzÕČ“μ-ÒžÃ$’ NĭTE%]DWöJ3™Ć=…_~Óñ')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online! Try it online!

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) 287 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by multiplying the vector c(5,407) by the ASCII byte number of the characters of the element name, taking the sum, and taking that mod 428. The hash was selected by a brute force search to minimize bytecount and is itself encoded as UTF8. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(sum(+"Ɨ"*+x)%%428,+"×ばつűŅĘŶ2Ly@¡ĠÄ,Â5]ŮĮŷÃõEt<7Ţ’ûĊƋJů©[ďc?Ŧ_l·xohőĤ6ĉÑð`UƂKŸ2аSoßōFÉ")])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

R, (削除) 301 (削除ここまで) (削除) 289 (削除ここまで) (削除) 287 (削除ここまで) 280 bytes

Explanation.

Look up the index of the mass sorted atomic number in a UTF8 encoded hash string s. The hash is taken by taking the element name as a base 36 case insensitive number and modding with 908, then 591, then 321. The operator + is used for the UTF8 to integer vector conversion.

Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as 9*d1 + d2 where d1 is the difference of the nth element and d2 is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.

function(x)sum(c(o%%9,o%/%9)[1:match(strtoi(x,36)%%908%%591%%321,+'#·Yû÷Ù<v„BypšŠàé‡ÿ6ĉčCrfœK":øá”^Q7|P{o–Ħ‹U ̄}úzÕČ“μ-ÒžÃ$’ NĭTE%]DWöJ3™Ć=…_~Óñ')])
"+"=utf8ToInt
o=+"0%..%$%% 
p

&00(1"

Try it online!

Post Undeleted by J.Doe
Post Deleted by J.Doe
added 117 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
edited body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
Golfed off a bit more by hash improvement
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
Changed hash to reduce bytecount
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 1 character in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
Improved offset hash
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 5 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 9 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 1 character in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
added 75 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 241 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 8 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
deleted 12 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
added 3 characters in body
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading
Source Link
J.Doe
  • 2.7k
  • 12
  • 15
Loading

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