You've got a set of tiles with the symbols from the periodic table. Each symbol appears once. You're thinking up words to make but you want to know if it's possible or not.

The Challenge

Write a program in your favourite language that will take in a string as an input parameter. You may assume that input is not null, has no spaces and consists of ASCII characters.

Your program should take that string and output a truthy value if that word can made up of symbols from the periodic table of elements, and a falsey value if the word cannot.

To make this challenge more difficult, you may not use a symbol twice. So if you use Nitrogen N you may not use N again in the same word.


Standard loopholes are not allowed. You may use symbols from elements 1-118 (Hydrogen to Unun­octium). You can find a list of all the elements here. You may read the list of symbols in from a file or input arguments if you wish.

Test Cases:

Laos - true (LaOs)
Amputation - true (AmPuTaTiON)
Heinous - true (HeINoUS)
Hypothalamus - true (HYPoThAlAmUS)
Singapore - true (SiNGaPoRe)
Brainfuck - true (BRaInFUCK)
Candycane - false

This is a code golf challenge, shortest code wins.

BEFORE YOU CLOSE AS DUPLICATE: While this may seem similar to this challenge, I feel it is different because it is not 'Generate a list of all words that are possible from the periodic table', it is 'Take in arbitrary input and determine if it can be made from the periodic table'

  • 2
    \$\begingroup\$ There's this which is more closely related but was itself closed as a duplicate of the challenge you linked. I think the fact you can only use a symbol once is the greatest differentiation between the challenges though. In terms of golfing I doubt there's a better way than brute forcing all possible words and checking if the input is among them. \$\endgroup\$ Commented Jun 23, 2016 at 7:24
  • 1
    \$\begingroup\$ "You may read the list of symbols in from a file if you wish." - how do we count it? Is size of the file added to the code length? Or we can use it for free? \$\endgroup\$
    – Qwertiy
    Commented Jun 23, 2016 at 8:06
  • 2
    \$\begingroup\$ Can we take the list of elements as an argument to the program? \$\endgroup\$
    – Emigna
    Commented Jun 23, 2016 at 8:07
  • 1
    \$\begingroup\$ @Qwertiy, the size of the file is free, but the bytes to read it in are not. \$\endgroup\$
    – JamesENL
    Commented Jun 23, 2016 at 8:16
  • 10
    \$\begingroup\$ Boron, Radium, Iodine, Nitrogen, Fluorine, Uranium, Carbon, Potassium. \$\endgroup\$
    – Neil
    Commented Jun 23, 2016 at 8:46

5 Answers 5


05AB1E, 16 bytes



œv                # for each permutation of the list of elements
  yΠ             # get all sublist of elements
    €J            # join as strings to form the words possible to spell
      })˜Ù        # convert to list of unique spellable strings
          vy²Q}   # compare each word with input word
               O  # sum giving 1 if the word is found, else 0

Warning: Extremely slow. I recommend testing on a much smaller subset of elements in the online interpreter.

Takes list of elements as first argument.
Takes word to test as second argument.
Returns 1 for true and 0 for false.

Try it online on a small subset of elements


Brachylog, 7 bytes


Call with the list of symbols (all lowercase) as Input, and the word as Output, e.g. run_from_atom('spc~@l.', ["he":"n":"o":"li"], "Nohe"). .

Warning: this is extremely inefficent when all symbols are in the list.


spc        Create a string from a permutation of a subset of the Input
   ~@l.    This string can unify with the lowercase version of the Output
  • 4
    \$\begingroup\$ @Downvoter care to explain? \$\endgroup\$
    – Fatalize
    Commented Jun 23, 2016 at 16:12

JavaScript (Firefox 48 or earlier), 103 bytes

... (list of elements not included in the byte count) ...

Pyth - 13 bytes

Just checks if any partition of lowercased input has all parts in the periodic table.


On mobile, so couldn't set up an actual test suite, but try this.

  • 1
    \$\begingroup\$ You wrote this on a phone!? \$\endgroup\$
    – JamesENL
    Commented Jun 24, 2016 at 0:53
  • \$\begingroup\$ This doesn't ensure an element is not used multiple times. Example. \$\endgroup\$ Commented Jun 24, 2016 at 11:47

Pyth, 11 bytes


Try it online. Test suite.

Written on my phone, but should work. Very slow for a large number of elements or a long string.


  • Take all partitions (./) of the input (z).
  • Sort (S) each partition (M).
  • For each partition (R), see if it is in (}) the list of all subsets (y) of the sorted (S) periodic table given as input (Q).
  • Sum (s) the resulting list of booleans.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.