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

Timeline for Periodic Table of Elements - Code Golf

Current License: CC BY-SA 3.0

30 events
when toggle format what by license comment
Jul 13, 2020 at 16:12 comment added ceilingcat 444 bytes
Jun 17, 2020 at 9:04 history edited Community Bot
Commonmark migration
Apr 13, 2017 at 12:39 history edited Community Bot
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Oct 9, 2014 at 20:03 comment added geometrian One idea I had was to try to assume that every element maps to its first two letters, and then just store the exceptions. I did a few tests, and that's not as promising an idea as it sounds. Still, I bet it might beat some answers here if anyone wants to give it a go . . .
Oct 9, 2014 at 18:10 comment added Mooing Duck I bruteforced various combinations of + and * up to mod 1000, your equation is tied for the shortest. Now I'll have to figure out how to work >>, << and ^ into my tests.
Oct 9, 2014 at 17:50 comment added Mooing Duck @squeamishossifrage: Here's what I bruteforced up to mod 584: coliru.stacked-crooked.com/a/0781764beb357213, shortest so far is what you found.
Oct 9, 2014 at 16:12 comment added Mooing Duck @squeamishossifrage: I checked, my program has hashing the abbreviations. :/
Oct 9, 2014 at 12:08 history edited r3mainer CC BY-SA 3.0
oops again
Oct 8, 2014 at 22:00 history edited r3mainer CC BY-SA 3.0
oops
Oct 8, 2014 at 21:46 comment added r3mainer @MooingDuck Are you sure? I counted 23 collisions with those parameters (e.g., "Gallium", "Plutonium" and "Silicon" all produce a value of 6)
Oct 8, 2014 at 21:44 comment added r3mainer Thanks for the improvements ugoren! (@tolos — your version works fine too, but the code is liable to throw a seg fault if it encounters any misspellings or spaces; perhaps that's what happened?)
Oct 8, 2014 at 21:41 history edited r3mainer CC BY-SA 3.0
Made improvements suggested by ugoren; character count now down to 452
S Oct 8, 2014 at 21:29 history suggested Mooing Duck CC BY-SA 3.0
Moved detailed explanations from comments to body
Oct 8, 2014 at 21:12 review Suggested edits
S Oct 8, 2014 at 21:29
Oct 8, 2014 at 21:09 comment added Mooing Duck I found that (hash+(c&31)+51)*211%324 uses a smaller modulo, but I doubt it would shave off many (any?) bytes...
Oct 7, 2014 at 21:14 comment added ugoren Save one more by if(*p<65?h-=*p++-34,0:1) replacing the else. And, I think, one more by replacing :1 with :h--.
Oct 7, 2014 at 21:01 comment added ugoren Nice one. Save some chars with: 1. (h+c%32+74)*311%441. 2. Drop p and use s. 3. main(c) saves one comma.
Oct 7, 2014 at 17:16 comment added user21677 Any idea why while(h)h-=*p>64?({for(h--;*++p>96;);0;}):*p++-34; seg faults (one less char)? Reference at gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
Oct 7, 2014 at 15:17 comment added r3mainer @Harshdeep — The hash function maps text strings to values from 0 to 440. "Tin" hashes to zero, so "Sn" is at the start of the table. The next 7 positions are empty. To keep the code compact, this is indicated by the ASCII value 34+7=41 (")"). Next comes "Copper" (8), four empty cells (34+4=38="&"), and "Vanadium" (13). After calculating a hash, the program steps through the table, subtracting 1 for every capital letter followed by 0 or more lowercase letters, and subtracting (ASCII VALUE)-34 for every non-alphabet character. When the value reaches zero, we have found the correct result.
Oct 7, 2014 at 14:15 comment added Harshdeep @squeamishossifrage can you please explain how did you arrive at the char* in a bit more detail. Thanks. (I hope to learn something new today)
Oct 7, 2014 at 8:48 comment added Jim Balter If you think about the grammar, it's unambiguous and has to be allowed ... it just looks ambiguous to us. Oh, and you caught another one I didn't! Congratulations on this ... I tried hard to tighten the algorithm but you got everything right.
Oct 7, 2014 at 8:19 comment added r3mainer @JimBalter Ah, I didn't even realise you could do that. Thanks!
Oct 7, 2014 at 8:18 history edited r3mainer CC BY-SA 3.0
deleted 3 characters in body
Oct 7, 2014 at 5:13 comment added Jim Balter Make that 464 ... you have an unnecessary pair of braces.
Oct 7, 2014 at 1:06 comment added r3mainer @soktinpk Brute forced it :-) This was the only one with a hash size of ≤512 that had no collisions. I didn't check alternative spellings though, and there might be better functions with different algorithms (e.g. using XOR instead of addition).
Oct 7, 2014 at 1:00 comment added soktinpk How did you find that hash function?!
Oct 7, 2014 at 0:56 history edited r3mainer CC BY-SA 3.0
added 114 characters in body
Oct 7, 2014 at 0:45 history edited r3mainer CC BY-SA 3.0
deleted 4 characters in body
Oct 7, 2014 at 0:38 history edited r3mainer CC BY-SA 3.0
deleted 6 characters in body
Oct 7, 2014 at 0:25 history answered r3mainer CC BY-SA 3.0
toggle format

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