SRL Archive - Help and Support

Who can do this?


Daniel

2012-09-26 07:14:25

Curiosity: Who can do this?

[php]You are to read a partially completed crossword puzzle
(without any questions/clues) and finish it using a
given word list.

The crosswords folder contains some example partially
completed crosswords (the *.unsolved files) and a word
list (the words.txt file). The black squares on the
crossword are represented with a hash (#), the empty
squares by periods (.) and the already filled in words
as uppercase letters.

An example partially-completed crossword:
TREE#F…
.#.##A##.
.#.##S##.
.#…T.#.
##.##E##.
###..R…



Link to cwords.zip:
http://mayazcherquoi.co.cc/uploads/cwords.zip[/php]

Submit your (not necessarily Simba) code ;)

Chris

2012-09-26 07:38:14

I can't.
I have thought about a way to do this, but it's getting too complicated in my mind.

Daniel

2012-09-26 07:42:59

From: Chris
I can't.
I have thought about a way to do this, but it's getting too complicated in my mind.


Haha :p Easy for a human, not so for a computer. :p

P1ng

2012-09-26 07:49:38

I'm kind of confused as to how to do this… I downloaded the file linked in OP but when I open the words.txt all I get is: http://puu.sh/18MrM

And I don't have a program to open the unsolved files :/

Chris

2012-09-26 07:55:11

From: P1ng
I'm kind of confused as to how to do this… I downloaded the file linked in OP but when I open the words.txt all I get is: http://puu.sh/18MrM

And I don't have a program to open the unsolved files :/


You can open the unsolved files with notepad, opening the words.txt with notepad++ works for me.

Daniel

2012-09-26 08:05:43

From: P1ng
I'm kind of confused as to how to do this… I downloaded the file linked in OP but when I open the words.txt all I get is: http://puu.sh/18MrM

And I don't have a program to open the unsolved files :/


Ah, that would be because it is in UNIX format (\n only for newlines, instead of the Windows \r\n). Firefox, Notepad2, etc (with the exception of Notepad), should be able to open it just fine :)

Brandon

2012-09-26 10:17:35

Uhh I practically solved it I think.. You just go through all horizontal matches and vertical matches.. Try out which words fits and then start entering them. Solve by elimination.. Whichever has the most chars and satisfies the other spots, gets placed in..

Now I didn't finish the filling it but I practically did the algorithms for getting the horizontal matches and vertical matches. It's now only a matter of filling in each one.


#include <windows.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <map>

std::vector<std::string> HLines, VLines, WordList, HPos, VPos;

void FillHorizontal(std::string FilePath)
{
std::string Line;
std::fstream hFile(FilePath.c_str(), std::ifstream::in | std::ifstream::binary);
while (getline(hFile, Line))
{
HLines.push_back(Line);
}
hFile.close();
}

void FillVertical()
{
int K = 0, L = 0;
std::vector<std::string> Result;
for (std::string::iterator it = HLines[0].begin(); it != HLines[0].end(); ++it, L = 0, ++K)
{
std::string Temp;
for (int J = K; J < HLines[L].size(); ++L)
{
Temp += HLines[L][J];
if (L + 1 == HLines.size())
{
VLines.push_back(Temp);
break;
}
}
}
}

std::string Copy(std::string Str, int FirstChar, int Count)
{
if (FirstChar <= 0)
FirstChar = 0;
else
FirstChar -= 1;
return Str.substr(FirstChar, Count);
}

int Pos(std::string Needle, std::string Haystack, int StartPos)
{
return Haystack.find(Needle, StartPos);
}

int RPos(std::string Needle, std::string Haystack, int StartPos)
{
return Haystack.rfind(Needle, StartPos);
}

std::vector<std::string> SplitString(std::string StrToSplit, int NumberOfPieces)
{
std::string Temp = StrToSplit;
std::vector<std::string> Result;
while(Temp.size())
{
Result.push_back(Temp.substr(0, NumberOfPieces));
Temp.erase(0, NumberOfPieces);
}
return Result;
}

std::vector<std::string> SplitString(std::string StringToSplit, std::string Delimiter)
{
std::vector<std::string> Result;
size_t Pos = StringToSplit.find_first_of(Delimiter);
while(Pos != std::string::npos)
{
if(Pos > 0)
{
Result.push_back(StringToSplit.substr(0, Pos));
}
StringToSplit = StringToSplit.substr(Pos + 1);
Pos = StringToSplit.find_first_of(Delimiter);
}
if(StringToSplit.length() > 0)
{
Result.push_back(StringToSplit);
}
return Result;
}

std::vector<std::string> Posibilities(std::vector<std::string>& Lines)
{
int Offset = 0;
std::vector<std::string> Result;

for (std::vector<std::string>::iterator it = Lines.begin(); it != Lines.end(); ++it)
{
std::vector<std::string> Temp = SplitString(*it, "#");
for (std::vector<std::string>::iterator iter = Temp.begin(); iter != Temp.end(); ++iter)
if (iter->size() > 1)
Result.push_back(*iter);
}
return Result;
}

void FillWordList(std::string WordListPath)
{
std::string Line;
std::fstream hFile(WordListPath.c_str(), std::ifstream::in | std::ifstream::binary);
while (getline(hFile, Line))
{
WordList.push_back(Line);
}
hFile.close();
}

bool WordMatch(std::string Word, std::string SecondWord, char IgnoreChar)
{
for (int I = 0; I < Word.size(); ++I)
{
if ((Word[I] != IgnoreChar) && (Word[I] != SecondWord[I]))
return false;
}
return true;
}

std::vector<std::string> WordScrape(std::string WordToCompare, std::vector<std::string> &ListOfWords)
{
std::vector<std::string> Result;

for (std::vector<std::string>::iterator it = ListOfWords.begin(); it != ListOfWords.end(); ++it)
{
if (WordToCompare.size() == it->size())
{
if (WordMatch(WordToCompare, *it, '.'))
{
Result.push_back(*it);
}
}
}
return Result;
}

std::vector<std::vector<std::string> > FindHMatches()
{

std::vector<std::vector<std::string> > HorizontalMatches;

for (std::vector<std::string>::iterator it = HPos.begin(); it != HPos.end(); ++it)
{
if (Pos(".", *it, 0) != -1)
{
HorizontalMatches.push_back(WordScrape(*it, WordList));
}
}
return HorizontalMatches;
}

std::vector<std::vector<std::string> > FindVMatches()
{

std::vector<std::vector<std::string> > VerticalMatches;

for (std::vector<std::string>::iterator it = VPos.begin(); it != VPos.end(); ++it)
{
if (Pos(".", *it, 0) != -1)
{
VerticalMatches.push_back(WordScrape(*it, WordList));
}
}
return VerticalMatches;
}

int main()
{
FillWordList("C:/Users/Brandon/Desktop/crossword/words.txt");
FillHorizontal("C:/Users/Brandon/Desktop/crossword/example0.unsolved");
FillVertical();
HPos = Posibilities(HLines);
VPos = Posibilities(VLines);
}

If I have some free time, just bump this thread.. If I see it, I'll finish the program if you don't. :P I did it on my break in class :l

masterBB

2012-09-26 11:59:41

I don't really understand the trouble with this? Just loop through all possible ways of filling it, break when it errors and exit when it is solved.

e: I got the birthday from my lil sister now, so I got some time to check this out in +/- 6 hours.

Home

2012-09-26 12:09:14

Can someone explain it little bit more. I don't understand what needs to be done.

~Home

Chris

2012-09-26 12:26:00

The crossword puzzles have to be finished by a script, all possible words are inside a text file and the puzzle is in its own text file.

I would start off making a script to load the puzzle into a 2D string array.

J J

2012-09-26 14:51:22

Just managed to read all the words seperated in Simba. Takes like 40 seconds to do it, but it works.

length: 233615

Also helpful for the puzzle
Length: 6
TREE#FERN

.#.##A##O

.#.##S##R

.#…T.#M

##.##E##A

###..R..L

Brandon

2012-09-26 15:00:40

:l I didn't read that we had to do it in Simba/Pascal script :l That's be extremely slow!! Well for bruteforcing a puzzle like that.

Meh just translate my code and it'll work. Well all that was needed was the filler. Just to fill in the puzzle with all the possible matches from FindHMatches and FindVMatches.

The thing I posted does all of that calculations and reading and operations in less than 3 seconds :P

putonajonny

2012-09-26 15:09:01

I'd attempt this but my simba won't even compile when I put the array in.

J J

2012-09-26 15:09:11

From: Brandon
:l I didn't read that we had to do it in Simba/Pascal script :l That's be extremely slow!! Well for bruteforcing a puzzle like that.

Meh just translate my code and it'll work. Well all that was needed was the filler. Just to fill in the puzzle with all the possible matches from FindHMatches and FindVMatches.

The thing I posted does all of that calculations and reading and operations in less than 3 seconds :P

Yup the limitations of Simba/Pascal haha. Oh well, it's fun to work around it but yeah it's extremely slow for even converting the word list. I don't even want to know how long it will take to generate the solve. We'll see if I can manage to get it working.

Daniel

2012-09-27 03:19:35

It doesn't have to be in Simba <_>

What are you all talking about? <_>

J J

2012-09-27 07:16:51

Well before you edited it hehe.
From: Daniel
Submit your (not necessarily Simba) code ;)


I'll post what I have Simba wise later in an attachment I think :) Might work on this using Java but we'll see about that.

Daniel

2012-09-27 09:08:44

Lol, J J, won't run :p

Output:

Length: 6
TREE#FERN

.#.##A##O

.#.##S##R

.#...T.#M

##.##E##A

###..R..L

T
R
E
E
#
F
E
R
N


.
#
.
#
#
A
#
#
O


.
#
.
#
#
S
#
#
R


.
#
.
.
.
T
.
#
M


#
#
.
#
#
E
#
#
A


#
#
#
.
.
R
.
.
L


Spot @ 1, 0
found horizontal end west side
found horizontal end east side
horizontal: (1, 0)
Spot @ 1, 2
found horizontal end west side
found horizontal end east side
horizontal: (1, 2)
horizontal word spot found
spot length: 1
s < 0
s < 0
Spot @ 2, 0
found horizontal end west side
found horizontal end east side
horizontal: (1, 0)
Spot @ 2, 2
found horizontal end west side
found horizontal end east side
horizontal: (1, 2)
horizontal word spot found
spot length: 1
s < 0
s < 0
Spot @ 3, 0
found horizontal end west side
found horizontal end east side
horizontal: (1, 0)
Spot @ 3, 2
found horizontal end west side
found horizontal end east side
horizontal: (1, 2)
horizontal word spot found
spot length: 1
s < 0
s < 0
Spot @ 4, 2
found horizontal end west side
found horizontal end east side
horizontal: (1, 2)
horizontal word spot found
spot length: 1
s < 0
s < 0
Spot @ 5, 3
found horizontal end west side
horizontal: (4, 3)
Spot @ 5, 4
found horizontal end west side
horizontal: (4, 4)
Spot @ 5, 6
found horizontal end west side
horizontal: (4, 6)
horizontal word spot found
spot length: 2
s < 0
s < 0
Error: Out Of Range at line 140

Line indicated by error:

s := GetLetters(Puzzle[k][j]);

Although, I can see where you went wrong :p

J J

2012-09-27 09:15:04

Yeah I actually wasn't finished yet, but I'm going to spend the spare time that I have on the scripting competition instead of this. Once my script for that is done I'll take a look at this again if no-one has finished it yet - which I doubt.

The solving is just WIP, you can see the idea indeed. I'll take a look at it in a week or so as the competition has been ended by then anyways.

Daniel

2012-10-02 01:27:17

No other takers? :p

I wonder if it'd be plausible to use sim annealing.

Daniel

2012-11-07 04:24:21

Has anybody actually managed to complete this yet? :p