Riddler: Spelling Bee Honeycomb

Simulation with matrixes

Published

January 5, 2020

Notable topics: Simulation with matrixes

Recorded on: 2020-01-05

Timestamps by: Alex Cookson

View code

Screencast

Timestamps

read_lines

Using read_lines function to import a plain text file (.txt)

str_detect

Using str_detect function to filter out words that do not contain the letter "g"

str_split

Using str_split function to get a list of a word's individual letters

setdiff

Using setdiff function to find words with invalid letters (letters that are not in the puzzle honeycomb) -- also needs map function (at 4:35)

Changing existing code to make a function that will calculate scores for letter combinations

n_distinct

Noticing the rule about bonus points for pangrams and using n_distinct function to determine if a word gets those points

map
purrr

Using map function to eliminate duplicate letters from each word's list of component letters

acast
reshape2

Using acast function from reshape2 package to create a matrix of words by letters

Using a the words/letters matrix to find valid words for a given letter combination

%*%

Using the matrix multiplication operator %*% to find the number of "forbidden" letters for each word

microbenchmark
microbenchmark

Using microbenchmark function from microbenchmark package to test how long it takes to run a function

combn

Using combn function to get the actual combinations of 6 letters (not just the count)

map

Using map function to get scores for different combinations of letters created above

which.max

Using which.max function to find the position of the max value in a vector

t

Using t function to transpose a matrix

Summary of screencast