Skip to content

Instantly share code, notes, and snippets.

View rajkumar-p's full-sized avatar

Rajkumar rajkumar-p

View GitHub Profile
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let upAnimVC = UpAnimationViewController()
window?.rootViewController = upAnimVC
window?.makeKeyAndVisible()
return true
}
@rajkumar-p
rajkumar-p / getWordsReachableInNSteps.cpp
Created January 17, 2013 13:45
Get words reachable in N steps
vector<string> getWordsReachableInNSteps(element *start, int nSteps) {
vector<string> reachableWords;
queue<element *> Q;
list<element *>::iterator linksIterator;
start->distanceFromSource = 0;
Q.push(start);
while(! Q.empty()) {
element *t_element = Q.front();
@rajkumar-p
rajkumar-p / findLongestLadder.cpp
Created January 17, 2013 13:41
Find the longest ladder using the ladder data structure
string findLongestLadder(vector<element> &wordListDS) {
int wordListSize = wordListDS.size();
int longestLadderSize= 0;
string longestLadder;
for (int i = 0; i < wordListSize; ++i) {
if (wordListDS.at(i).noOfLadders > longestLadderSize) {
longestLadderSize = wordListDS.at(i).noOfLadders;
longestLadder = wordListDS.at(i).word;
}
@rajkumar-p
rajkumar-p / getNextWordsForWord.cpp
Created January 17, 2013 13:36
Get next words using ladder data structure
vector<string> getNextWordsForWord(element &entry) {
vector<string> nextWords;
list<element *>::iterator linksIterator;
for (linksIterator = entry.links.begin();
linksIterator != entry.links.end(); ++linksIterator)
{
nextWords.push_back((*linksIterator)->word);
}
@rajkumar-p
rajkumar-p / updateNumberOfLadders.cpp
Created January 17, 2013 13:19
Update number of ladders
void updateNumberOfLadders(vector<element> &wordListDS) {
int wordListSize = wordListDS.size();
for (int i = 0; i < wordListSize; ++i)
{
wordListDS.at(i).noOfLadders = wordListDS.at(i).links.size();
}
}
@rajkumar-p
rajkumar-p / buildLadderDataStructure.cpp
Created January 17, 2013 13:12
Build ladder data structure
void buildLadderDataStructure(vector<element> &wordListDS)
{
int wordListSize = wordListDS.size();
for (int i = 0; i < wordListSize; ++i)
{
for (int j = i + 1; j < wordListSize; ++j)
{
element e1 = wordListDS.at(i);
element e2 = wordListDS.at(j);
@rajkumar-p
rajkumar-p / initializeVector.cpp
Created January 15, 2013 15:28
Initialize the vector of elements
// Maps a word to the index in the vector
map<string, int> wordToVectorIndex;
// Push the word to the vector
while (cin >> word)
{
element e;
e.word = word;
e.noOfLadders = 0;
e.isVisited = ELEMENT_NOT_VISITED;
@rajkumar-p
rajkumar-p / element.cpp
Last active December 11, 2015 03:38
Structure of a single element
struct element
{
string word;
int noOfLadders;
list<element *> links;
elementVisitHistory isVisited;
int distanceFromSource;
};
@rajkumar-p
rajkumar-p / findLongestLadder.cpp
Created January 15, 2013 08:04
Naive algorithm to find the longest ladder
string findLongestLadder(vector<string> wordList)
{
int wordListSize = wordList.size();
unsigned int longestLadderSize = 0;
string longestLadder;
for (int i = 0; i < wordListSize; ++i)
{
vector<string> t_vector = getNextWordsForWord(wordList[i], wordList);
if (longestLadderSize < t_vector.size())
@rajkumar-p
rajkumar-p / getNextWordsForWord.cpp
Created January 15, 2013 07:31
Naive algorithm to get the next words in a word ladder
vector<string> getNextWordsForWord(string word, vector<string> wordList)
{
vector<string> nextWords;
for (size_t i = 0; i < wordList.size(); ++i)
{
int diff = getDiffCount(word, wordList[i]);
if (diff == 1)
{