Giter Site home page Giter Site logo

us-state-abbr-anagrams's Introduction

us-state-abbr-anagrams

Using PHP and R to find eight-letter words that are anagrams of four adjacent US state postal abbreviations

The Challenge

I heard a puzzle challenge on the radio to find a common eight-letter word spelled from the US state postal abbreviations of states that can be driven between. For more details, see the This week's challenge section of the January 31st, 2021 Sunday Puzzle page.

It sounded like an interesting problem that could easily be sovled with computer science, so I decided to give it a try.

Preparing Data

First, I pulled up a map of the United States that showed state boundaries. I went state by state, creating a list of adjacent states and making a list of their abbreviations.

The resulting file can be found here.

MySQL Setup

After that, I created a simple MySQL database for my PHP script to reference. The pairings data was loaded into the connections table. I also created a simple states table that contained the results of looking at the distinct values in the origin column of the connections table - both as a way to confirm I had entered pairings for all 48 states, and to create a list for my PHP script to work through. A combinations8 table was created to store the results of my PHP script.

The details of that database can be found here.

PHP Script to Find All Eight-Letter Combinations

I wrote a script in PHP which generated every possible four state combination based on the connections I had documented earlier. Nearly 3000 combinations were generated and written to the combinations8 table.

My script can be found here.

The CSV containing the combinations generated can be found here.

R Script to Find Anagrams

With all possible combinations in hand, I then needed to check them for anagrams that were common English word. I did not find a web API I was satisfied would be up for the task, but did find the wfindr R package that seemed perfect for the job. I deduplicated the data in my combinations8 table and exported the combinations to a CSV file for use with R. That file can be found here.

My R script looped through each of the eight-letter state abbreviation combinations and fed each through the find_word function to find any eight-letter anagrams and saved any words it found to a dataframe which was exported as a CSV once the script finished running.

My R script can be found here.

The resulting CSV of eight-letter state abbreviation strings and the anagrams found within each can be found here.

Results

My scripts found 50 eight-letter anagrams out of the nearly 3000 possible four state combinations, of which only 9 words I would consider "common":

Word Four Adjacent States
Animator IA > MO > TN > AR
Condemns MN > SD > NE > CO ; NM > CO > NE > SD
Diamonds ND > SD > IA > MO
Dioramas SD > IA > MO > AR
Flagrant FL > GA > TN > AR
Moleskin IL > MO > KS > NE
Nominate NE > IA > MO > TN
Ornament NE > MO > TN > AR
Ransomed AR > MO > NE > SD

Note: The above state combinations found the same words when checked in a different order, which is why the matched_words.csv is so much longer.

The complete list of anagrams can be found here.

us-state-abbr-anagrams's People

Contributors

ericcawthon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.