Skip to content

Instantly share code, notes, and snippets.

@huntwelch
Created September 16, 2016 21:45
Show Gist options
  • Select an option

  • Save huntwelch/23d3e3111573b41510ff3385578a0494 to your computer and use it in GitHub Desktop.

Select an option

Save huntwelch/23d3e3111573b41510ff3385578a0494 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <stdio.h>
char first( std::string word )
{
return word[0];
}
std::string rest( std::string word )
{
return word.substr(1, word.length()-1);
}
int main ( int argc, char *argv[] )
{
std::string word = argv[1];
char letter = first(word);
std::string follow = rest(word);
std::ifstream file("/usr/share/dict/words");
if( !file.is_open() ) return 0;
std::string arry[235885];
for( int i=0; i<235885; ++i ) {
file >> arry[i];
}
std::string checkword;
std::string spoon_1;
std::string spoon_2;
char fetter;
std::string lollow;
bool exists;
for( int i=0; i<235885; ++i ) {
checkword = arry[i];
if( checkword.length() == 1 ) continue;
fetter = first(checkword);
if( fetter == letter ) continue;
if( isupper(fetter) ) continue;
lollow = rest(checkword);
spoon_1 = fetter + follow;
spoon_2 = letter + lollow;
exists = std::find(std::begin(arry), std::end(arry), spoon_1) != std::end(arry);
if( !exists ) continue;
exists = std::find(std::begin(arry), std::end(arry), spoon_2) != std::end(arry);
if( !exists ) continue;
std::cout << spoon_1 << ' ' << spoon_2 + '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment