Skip to content
The beaver is a proud and noble animal

The beaver is a proud and noble animal

Notes from a bemused canuck

  • Home
  • About
  • Bookmarks
  • Pictures
  • Resume
  • Wine
  • Random Recipe
  • Toggle search form

Words written in Periodic Table elements

Posted on July 19, 2018July 23, 2018 By admin

This is how my brain works.

This morning, on my way to work, I remembered a t-shirt from a TV show we’re currently binging on with the word “sarcasm” written using element symbols from the periodic table:

I then started to wondered about how I would go about finding all the words that would be written using element symbols. So when I got into work, I quickly hacked this together. Out of a starting word set of 58109 words, I find 7417 “periodic” words. The longest word, and one of several with the most component elements (13) is:

Internationalisation, elements=In,Te,Rn,At,I,O,Na,Li,S,At,I,O,N

Other amusing ones are:

Inarticulateness, elements=In,Ar,Ti,Cu,La,Te,Ne,S,S
Supersaturation, elements=S,U,P,Er,S,At,U,Ra,Ti,O,N
Consciousnesses, elements=CO,N,Sc,I,O,U,Sn,Es,Se,S
Procrastination, elements=Pr,O,Cr,As,Ti,Na,Ti,O,N
Hyperinflation, elements=H,Y,P,Er,In,F,La,Ti,O,N
Falsification, elements=F,Al,Si,F,I,Ca,Ti,O,N,S
Perniciousness, elements=P,Er,Ni,C,I,O,U,Sn,Es,S
Perambulations, elements=P,Er,Am,B,U,La,Ti,O,N,S
Pontifications, elements=Po,N,Ti,F,I,Ca,Ti,O,N,S
Hallucinations, elements=H,Al,Lu,C,In,At,I,O,N,S
Voluptuousness, elements=V,O,Lu,Pt,U,O,U,Sn,Es,S
Sensationalism, elements=Se,N,S,At,I,O,Na,Li,Sm

And many, many more.

I then added a little tweak to filter out words that use repetitions of elements, and that brings down the number of “periodic” words to 5483. In that case, the longest word, and one of several with the most component elements (10) is:

Reclassification, elements=Re,Cl,As,Si,F,I,Ca,Ti,O,N


package wordlist;

import java.io.*;
import java.util.*;

public class PeriodicWordFinder {

    private TreeSet<String> words;
    private TreeSet<String> elements;
    private ArrayList<PeriodicWord> periodicWords;

    public PeriodicWordFinder() {
        init();
    }

    private void init(){
        try{
            words = read("wordlist.txt");
            elements = new TreeSet<>(new AlphaLengthComparaator());
            elements.addAll(read("elements.txt"));
            periodicWords = new ArrayList<>();

            System.out.println("words.size() = " + words.size());
            System.out.println("elements.size() = " + elements.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private TreeSet<String> read(String fileName) throws Exception{
        TreeSet<String> retval = new TreeSet<>();
        InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName);
        BufferedReader in = new BufferedReader(new InputStreamReader(stream));
        String line;
        while ((line = in.readLine()) != null){
            line = line.toUpperCase().trim();
            //no elements contain Q or J
            if (line.contains("Q") || line.contains("J")){
                continue;
            }
            retval.add(line);
        }
        in.close();
        return retval;
    }

    private void findWords(boolean onlyUniqueElements) {
        for(String word : words){
            PeriodicWord pWord = new PeriodicWord(word);
            if ( periodicWord(pWord) ){
                //if the word only contains unique instances of elements, or we don't care
                if (checkUniqueElements(pWord) || !onlyUniqueElements) {
                    System.out.println("found: " + pWord);
                    periodicWords.add(pWord);
                }
            }
        }
    }

    private boolean periodicWord(PeriodicWord word) {
        if (word.getWord().length() == 0)
            return true;

        for (String element : elements){
            if (word.getWord().startsWith(element)){
                word.getElements().add(element);
                word.setWord(word.getWord().substring(element.length()));
                return periodicWord(word);
            }
        }
        return false;
    }

    private boolean checkUniqueElements(PeriodicWord pWord) {
        //if elements are duplicated, size of hashset will be different than size of original list
        return (pWord.getElements().size() == new HashSet<>(pWord.getElements()).size());
    }


    public static void main(String[] args){
        PeriodicWordFinder ew = new PeriodicWordFinder();
        ew.findWords(true);
    }

    private class AlphaLengthComparaator implements Comparator<String>{
        @Override
        public int compare(String o1, String o2) {
            Integer l1 = o1.length();
            Integer l2 = o2.length();
            int lengthComparison = l1.compareTo(l2);
            if (lengthComparison == 0){
                return o1.compareTo(o2);
            } else {
                return l1.compareTo(l2)*-1;
            }
        }
    }

    private class PeriodicWord {

        private String word; //will get mangled during recursion
        private String initialWord; //keep track of initial word
        private ArrayList<String> elements; //will get updated during recursion

        public PeriodicWord(String word) {
            this.initialWord = word;
            this.word = word;
        }

        public void setWord(String word) {
            this.word = word;
        }

        public String getWord() {
            return word;
        }

        public ArrayList<String> getElements() {
            if (elements == null)
                elements = new ArrayList<>();
            return elements;
        }

        @Override
        public String toString() {
            return initialWord +", elements=" + String.join(",", elements);
        }
    }
}

  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
uncategorized Tags:geek, random shit, work

Post navigation

Previous Post: Makin’ pancakes 
Next Post: Optimized solution for periodic words

Related Posts

  • Mood glass-o-meter random shit
  • Last day of workshop bobble the little blue owl
  • Braindead owl bobble the little blue owl
  • Need a change of scenery stress
  • Comptoir Suisse 2018, 2nd try random shit
  • I want to go home ducks

Power to the beaver!

Show me the beaver!
July 2018
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Jun   Aug »

Quote of the day

+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
--(Terry Pratchett, Hogfather)

Random Posts

  • Taikoza
  • Have you hugged your geek today?
  • Today&apos;s deranged link brought to you by K-Tel
  • [Gallery] Victor Ostrovsky
  • Oh Japan, you so Neko cray cray!
reading leopard

Tags

bobble the little blue owl boobies brought to you by the fda cats chonk christmas comics computers are evil covid-19 dealing with idiots dilbert dog ducks galleries geek god bless the land of the free holidays house I am Canadian land of cheese and chocolate linked news lolcat london news from the stupid not my dog nsfw pets pictures potd2014 qotd random shit re-member recipes relationship shrill slice of life stress Tao the british way The Peanut things i miss travel video wine work

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2025 The beaver is a proud and noble animal.

Powered by PressBook Premium theme

 

Loading Comments...