![]() ![]() There could be interactions between those terms (maybe two relatively rare letters go well together). Of course, any given honeycomb with one of these letters will get only a tiny fraction of the points available to the letter. What letters have the most and least points? keep_all = TRUE ) letters_summarized % group_by ( letter ) %>% summarize ( n_words = n (), n_points = sum ( points )) %>% arrange ( desc ( n_points )) letters_summarized # A tibble: 25 x 3 library ( tidytext ) # unnest_tokens is a fast approach to splitting one-character-per-row letters_unnested % select ( word, points ) %>% unnest_tokens ( letter, word, token = "characters", drop = FALSE ) %>% distinct ( word, letter. Let’s quantify this, by looking at how many words each letter appears in, and how many total points they’d earn. ![]() The winning honeycomb is likely filled with common letters like E that appear in lots of words. Would you expect the winning honeycomb to have letters like X, Z, or Q? Neither would I. Heuristics: What letters appear in the highest-scoring words? It would take about 8 days to test every one this way. Since S is eliminated, there are 25 possible choices for the center letter, and \(24\choose 6\) (“24 choose 6”) possible combinations of outer letters, making 25 * choose(24, 6) = 3.36 million possible honeycombs. ![]() # … with 33 more rows sum ( honeycomb_words $ points ) # 153Ĭould we use this get_words() function to brute force every possible honeycomb? Only if we had a lot of time on our hands. get_words % filter ( str_detect ( word, center_letter )) %>% mutate ( invalid_letters = map ( letters, setdiff, all_letters )) %>% filter ( lengths ( invalid_letters ) = 0 ) %>% select ( word, points ) } honeycomb_words This data gives us a way to solve the December 24th Honeycomb puzzle that comes with the Riddler column. There are 44585 that are eligible to appear in a puzzle. # word word_length letters unique_letters points library ( tidyverse ) words % mutate ( word_length = str_length ( word )) %>% filter ( word_length >= 4, ! str_detect ( word, "s" )) %>% mutate ( letters = str_split ( word, "" ), letters = map ( letters, unique ), unique_letters = lengths ( letters )) %>% mutate ( points = ifelse ( word_length = 4, 1, word_length ) + 7 * ( unique_letters = 7 )) %>% filter ( unique_letters % arrange ( desc ( points )) words # A tibble: 44,585 x 5 We’ll do this processing with tidyverse functions. Based on the above rules, these will have at least four letters, have no more than 7 unique letters, and never contain the letter S. Our first step is to process the word list for words that could appear in a honeycomb puzzle. So in the same spirit as my Tidy Tuesday screencasts, I recorded myself solving this puzzle (though not the process of turning it into a blog post). I don’t show all the dead ends and bugs, or explain why I ended up choosing a particular path. I’ve done a lot of puzzles recently, and I realized that showing the end result isn’t a representation of my thought process. As much as I love the tidyverse, this, like the “lost boarding pass” puzzle and Emily Robinson’s evaluation of the best Pokémon team, serves as a great example of using R’s matrix operations to work efficiently with data. Solving this puzzle in R is interesting enough, but it’s particularly challenging to do so in a computationally efficient way. Which seven-letter honeycomb results in the highest possible game score? To be a valid choice of seven letters, no letter can be repeated, it must not contain the letter S (that would be too easy) and there must be at least one pangram. So in the above example, MEGAPLEX is worth 15 points. Words that use all of the seven letters in the honeycomb are known as “pangrams” and earn 7 bonus points (in addition to the points for the length of the word). Four-letter words are worth 1 point each, while five-letter words are worth 5 points, six-letter words are worth 6 points, seven-letter words are worth 7 points, etc. For example, the words GAME and AMALGAM are both acceptable words.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |