# Play scrabble with the periodic table

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.

## Rules

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'

• 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. Jun 23, 2016 at 7:24
• "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? Jun 23, 2016 at 8:06
• Can we take the list of elements as an argument to the program? Jun 23, 2016 at 8:07
• @Qwertiy, the size of the file is free, but the bytes to read it in are not. Jun 23, 2016 at 8:16
• Boron, Radium, Iodine, Nitrogen, Fluorine, Uranium, Carbon, Potassium.
– Neil
Jun 23, 2016 at 8:46

## 05AB1E, 16 bytes

œvyŒ€J})˜Ùvy²Q}O


Explained

œ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

spc~@l.


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.

### Explanation

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

• @Downvoter care to explain? Jun 23, 2016 at 16:12

## JavaScript (Firefox 48 or earlier), 103 bytes

f=(w,e=
H
He
... (list of elements not included in the byte count) ...
Uus
Uuo
)=>!w||e.match(/\w+/g).some(s=>!w.search(s,i)&&f(w.slice(s.length),e.replace(
\${s}
,
)))


# Pyth - 13 bytes

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

sm.A}RQd./rzZ


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

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

# Pyth, 11 bytes

s}RySQSM./z


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

### Explanation

• 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.