{"id":39789,"date":"2018-07-19T07:29:04","date_gmt":"2018-07-19T07:29:04","guid":{"rendered":"https:\/\/www.flubu.com\/blog\/?p=39789"},"modified":"2018-07-23T09:54:22","modified_gmt":"2018-07-23T09:54:22","slug":"words-written-in-periodic-table-elements","status":"publish","type":"post","link":"https:\/\/www.flubu.com\/blog\/2018\/07\/19\/words-written-in-periodic-table-elements\/","title":{"rendered":"Words written in Periodic Table elements"},"content":{"rendered":"<p>This is how my brain works. <\/p>\n<p>This morning, on my way to work, I remembered a t-shirt from a TV show we&#8217;re currently binging on with the word &#8220;sarcasm&#8221; written using element symbols from the periodic table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"39790\" data-permalink=\"https:\/\/www.flubu.com\/blog\/2018\/07\/19\/words-written-in-periodic-table-elements\/sarcasm-2\/\" data-orig-file=\"https:\/\/www.flubu.com\/blog\/wp-content\/uploads\/2018\/07\/sarcasm.png\" data-orig-size=\"377,117\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sarcasm\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.flubu.com\/blog\/wp-content\/uploads\/2018\/07\/sarcasm.png\" src=\"https:\/\/www.flubu.com\/blog\/wp-content\/uploads\/2018\/07\/sarcasm.png\" alt=\"\" width=\"377\" height=\"117\" class=\"aligncenter size-full wp-image-39790\" \/><\/p>\n<p>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 &#8220;periodic&#8221; words. The longest word, and one of several with the most component elements (13) is:<\/p>\n<p>Internationalisation, elements=In,Te,Rn,At,I,O,Na,Li,S,At,I,O,N <\/p>\n<p>Other amusing ones are: <\/p>\n<p>Inarticulateness, elements=In,Ar,Ti,Cu,La,Te,Ne,S,S<br \/>\nSupersaturation, elements=S,U,P,Er,S,At,U,Ra,Ti,O,N<br \/>\nConsciousnesses, elements=CO,N,Sc,I,O,U,Sn,Es,Se,S<br \/>\nProcrastination, elements=Pr,O,Cr,As,Ti,Na,Ti,O,N<br \/>\nHyperinflation, elements=H,Y,P,Er,In,F,La,Ti,O,N<br \/>\nFalsification, elements=F,Al,Si,F,I,Ca,Ti,O,N,S<br \/>\nPerniciousness, elements=P,Er,Ni,C,I,O,U,Sn,Es,S<br \/>\nPerambulations, elements=P,Er,Am,B,U,La,Ti,O,N,S<br \/>\nPontifications, elements=Po,N,Ti,F,I,Ca,Ti,O,N,S<br \/>\nHallucinations, elements=H,Al,Lu,C,In,At,I,O,N,S<br \/>\nVoluptuousness, elements=V,O,Lu,Pt,U,O,U,Sn,Es,S<br \/>\nSensationalism, elements=Se,N,S,At,I,O,Na,Li,Sm<\/p>\n<p>And many, many more.<\/p>\n<p>I then added a little tweak to filter out words that use repetitions of elements, and that brings down the number of &#8220;periodic&#8221; words to 5483. In that case, the longest word, and one of several with the most component elements (10) is:<\/p>\n<p>Reclassification, elements=Re,Cl,As,Si,F,I,Ca,Ti,O,N<\/p>\n<pre class=\"brush: java; collapse: true; light: false; title: Click to view the full source code; toolbar: true; notranslate\" title=\"Click to view the full source code\">\r\n\r\npackage wordlist;\r\n\r\nimport java.io.*;\r\nimport java.util.*;\r\n\r\npublic class PeriodicWordFinder {\r\n\r\n    private TreeSet&lt;String&gt; words;\r\n    private TreeSet&lt;String&gt; elements;\r\n    private ArrayList&lt;PeriodicWord&gt; periodicWords;\r\n\r\n    public PeriodicWordFinder() {\r\n        init();\r\n    }\r\n\r\n    private void init(){\r\n        try{\r\n            words = read(&quot;wordlist.txt&quot;);\r\n            elements = new TreeSet&lt;&gt;(new AlphaLengthComparaator());\r\n            elements.addAll(read(&quot;elements.txt&quot;));\r\n            periodicWords = new ArrayList&lt;&gt;();\r\n\r\n            System.out.println(&quot;words.size() = &quot; + words.size());\r\n            System.out.println(&quot;elements.size() = &quot; + elements.size());\r\n        } catch (Exception e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n\r\n    private TreeSet&lt;String&gt; read(String fileName) throws Exception{\r\n        TreeSet&lt;String&gt; retval = new TreeSet&lt;&gt;();\r\n        InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName);\r\n        BufferedReader in = new BufferedReader(new InputStreamReader(stream));\r\n        String line;\r\n        while ((line = in.readLine()) != null){\r\n            line = line.toUpperCase().trim();\r\n            \/\/no elements contain Q or J\r\n            if (line.contains(&quot;Q&quot;) || line.contains(&quot;J&quot;)){\r\n                continue;\r\n            }\r\n            retval.add(line);\r\n        }\r\n        in.close();\r\n        return retval;\r\n    }\r\n\r\n    private void findWords(boolean onlyUniqueElements) {\r\n        for(String word : words){\r\n            PeriodicWord pWord = new PeriodicWord(word);\r\n            if ( periodicWord(pWord) ){\r\n                \/\/if the word only contains unique instances of elements, or we don't care\r\n                if (checkUniqueElements(pWord) || !onlyUniqueElements) {\r\n                    System.out.println(&quot;found: &quot; + pWord);\r\n                    periodicWords.add(pWord);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    private boolean periodicWord(PeriodicWord word) {\r\n        if (word.getWord().length() == 0)\r\n            return true;\r\n\r\n        for (String element : elements){\r\n            if (word.getWord().startsWith(element)){\r\n                word.getElements().add(element);\r\n                word.setWord(word.getWord().substring(element.length()));\r\n                return periodicWord(word);\r\n            }\r\n        }\r\n        return false;\r\n    }\r\n\r\n    private boolean checkUniqueElements(PeriodicWord pWord) {\r\n        \/\/if elements are duplicated, size of hashset will be different than size of original list\r\n        return (pWord.getElements().size() == new HashSet&lt;&gt;(pWord.getElements()).size());\r\n    }\r\n\r\n\r\n    public static void main(String&#x5B;] args){\r\n        PeriodicWordFinder ew = new PeriodicWordFinder();\r\n        ew.findWords(true);\r\n    }\r\n\r\n    private class AlphaLengthComparaator implements Comparator&lt;String&gt;{\r\n        @Override\r\n        public int compare(String o1, String o2) {\r\n            Integer l1 = o1.length();\r\n            Integer l2 = o2.length();\r\n            int lengthComparison = l1.compareTo(l2);\r\n            if (lengthComparison == 0){\r\n                return o1.compareTo(o2);\r\n            } else {\r\n                return l1.compareTo(l2)*-1;\r\n            }\r\n        }\r\n    }\r\n\r\n    private class PeriodicWord {\r\n\r\n        private String word; \/\/will get mangled during recursion\r\n        private String initialWord; \/\/keep track of initial word\r\n        private ArrayList&lt;String&gt; elements; \/\/will get updated during recursion\r\n\r\n        public PeriodicWord(String word) {\r\n            this.initialWord = word;\r\n            this.word = word;\r\n        }\r\n\r\n        public void setWord(String word) {\r\n            this.word = word;\r\n        }\r\n\r\n        public String getWord() {\r\n            return word;\r\n        }\r\n\r\n        public ArrayList&lt;String&gt; getElements() {\r\n            if (elements == null)\r\n                elements = new ArrayList&lt;&gt;();\r\n            return elements;\r\n        }\r\n\r\n        @Override\r\n        public String toString() {\r\n            return initialWord +&quot;, elements=&quot; + String.join(&quot;,&quot;, elements);\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is how my brain works. This morning, on my way to work, I remembered a t-shirt from a TV show we&#8217;re currently binging on with the word &#8220;sarcasm&#8221; 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&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/www.flubu.com\/blog\/2018\/07\/19\/words-written-in-periodic-table-elements\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Words written in Periodic Table elements&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[17,132,40],"class_list":["post-39789","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-geek","tag-random-shit","tag-work"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3u9vK-alL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts\/39789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/comments?post=39789"}],"version-history":[{"count":4,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts\/39789\/revisions"}],"predecessor-version":[{"id":39800,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/posts\/39789\/revisions\/39800"}],"wp:attachment":[{"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/media?parent=39789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/categories?post=39789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flubu.com\/blog\/wp-json\/wp\/v2\/tags?post=39789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}