How many element symbols can make up a word? Find out with this project! MAXIMUM 21 UNIQUE CHARACTERS Special characters will be substituted with a _! Be aware :)
How does this work? This was geniunely my biggest, most complicated project yet. On paper, it looks super easy; check input letters two at a time, check if it exists on the periodic table, if not, go back a step and check for single letter symbols, and if neither of those options, spit it out as a non element letter. The problem with this was, if you were to use words where there were different ways to write the word using symbols, there would be a unnecessary amount of non element letters. My original algorithm was greedy, making the best possible choice but only at the moment, but not thinking about how it can affect the future. For example, the word present can be writting in two ways: Pr Es e N t (this is how my original algorithm would write it. It sees that Pr can be identified as Praeseodymium, but it ends up with two "orphan" letters, e and t) P Re Se N t (this would be a more optimized spelling of the word, with only one orphan letter) To solve this, I decided it would be better if I worked backwards. If a letter was, by itself, an element symbol, it gets a score of 0. Otherwise, it receives a score of 1. Then, it adds the score of the past position to its score. If the letter and the letter before it together forms a symbol that can be identified on the periodic table, it checks if its score is greater than the score of the position two positions before, just in case there are ambiguities. If the score is either greater than, or equal to the score of the position two positions before, the pair wins. If not, it is a standalone symbol. The letters that the position "takes" is represented in the "Letters Taken" list, which is then converted back into letters and then finally, spit into the output and presented visually on your scene! This project was about seven hours of straight work.. I especially had a difficult time trying to figure out how to optimize. It's still not perfect; although it does minimize orphan letters, it still does not think about different ways to write the word. Though "non" can be written like "NoN" or "NON", it chooses the latter option cause it.. works, though it's not a big deal. If you have any suggestions at all for the project, please let me know in the comments, or better yet, remix this project for yourself! I'm excited for seeing what this community is up for.