Jump to content

Recommended Posts

Today I was bored and made a word search solver. I felt really proud of myself, but none of my friends are online to share it with :). So I thought you guys might like it. Here is the link:

 

http://johnjacquay.com/sandbox/crossword/

 

Here is a sample for you to input:

 

U E I H U U A W G Z C W S R E 
Q R W K Q X Y E W X Y L I R K 
Y D S J B B J J J N H C E N D 
Y N C U C F V I P J P V Z U U 
Y U E O A P A M G G C F J I D 
P H P T E S F O C R V T X T V 
G V R V C O E I C O V N Y U S 
M F R A R V A Q N O O G S H L 
D R A U U V R O Y I K L W X F 
X E M F P A T X A R R W E D M 
X A L T T W N C L Y U U D S W 
J K F E U S C E F N A T Q C T 
T S J X D E Q N H E T E I A F 
W P U R T K P H P F R E A K S 
E G V Y L Z J K X K Z F A R M 

 

Words:

 

COOLEST
FORUM
FREAKS
PHP
PHPFREAKS

Link to comment
https://forums.phpfreaks.com/topic/176490-check-out-my-word-search-solver/
Share on other sites

  • Wrong forum.
  • Where's the fun if you don't show us the source code?

 

Also, when I enter

 

test
estt

 

and searches for te, the vertical match isn't found.

 

That's strange, I just tested your example and it worked. Also, here is the source:

 

<?php
if ( $_POST['puzzle'] && $_POST['words'] ) {
$words = explode("\n", str_replace(" ", "", trim($_POST['words'])));
$letter_rows = explode("\n", str_replace(" ", "", trim($_POST['puzzle'])));

$letters = array();

foreach ( $words as $word_index => $word ) {
	$words[$word_index] = strtolower(trim($word));
}

$row_index = 0;
foreach ( $letter_rows as $letter_row ) {
	$letter_row = strtolower(trim($letter_row));
	for ( $n = 0; $n < strlen($letter_row); $n++ ) {
		$letters[$row_index][] = substr($letter_row, $n, 1);
	}
	$row_index++;
}

$width = count($letters[0]);
$height = count($letters);

$highlight = array();
$temphighlight = array();
$newletters = array();

$angles = array(
	0 => array(
		'x' => -1,
		'y' => -1
	), 
	1 => array(
		'x' => 0,
		'y' => -1
	),
	2 => array(
		'x' => 1,
		'y' => -1
	),
	3 => array(
		'x' => -1,
		'y' => 0
	),
	4 => array(
		'x' => 1,
		'y' => 0
	),
	5 => array(
		'x' => -1,
		'y' => 1
	),
	6 => array(
		'x' => 0,
		'y' => 1
	),
	7 => array(
		'x' => 1,
		'y' => 1
	)
);

foreach ( $letters as $row_index => $letter_row ) {
	foreach ( $letter_row as $letter_index => $letter ) {
		$newletters[$row_index][$letter_index] = '>' . $letters[$row_index][$letter_index];
		foreach ( $words as $word_index => $word ) {
			foreach ( $angles as $index_add_index => $index_add ) {
				$found_index = 0;
				$temphighlight = array();
				for ( $n = 0; $n < strlen($word); $n++ ) {
					if ( substr($word, $n, 1) == $letters[($index_add['y'] * $n) + $row_index][($index_add['x'] * $n) + $letter_index] ) {
						$found_index++;

						$temphighlight[$n]['y'] = ($index_add['y'] * $n) + $row_index;
						$temphighlight[$n]['x'] = ($index_add['x'] * $n) + $letter_index;

						if ( strlen($word) == $found_index ) {
							//echo 'Word "' . $word . '" Found At Angle ' . $index_add_index . "<br />";
							$highlight[] = $temphighlight;
							break 1;
						}
					} else {
						break 1;
					}
				}
			}
		}
	}	
}

foreach ( $highlight as $word ) {
	foreach ( $word as $coord ) {
		$newletters[$coord['y']][$coord['x']] = ' style="background-color: red;">' . $letters[$coord['y']][$coord['x']];
	}	
}


echo '<table>';
foreach ( $newletters as $row ) {
	echo '<tr>';	
	foreach ( $row as $letter ) {
		echo '<td';
		echo $letter;
		echo '</td>';
	}
	echo '</tr>';
}
echo '</table>';

}


?>

Give it a rest, he made something out of boredom, I imagine he cares less about XssMe warnings. Maybe find a different hobby? -- gotta be something you like to other than running Firefox plugins against random sites and colouring text. Wait, colouring, now there's an idea! I'm sure you can put that talent to better use.

Give it a rest, he made something out of boredom, I imagine he cares less about XssMe warnings. Maybe find a different hobby? -- gotta be something you like to other than running Firefox plugins against random sites and colouring text. Wait, colouring, now there's an idea! I'm sure you can put that talent to better use.

 

lol.

The word search solver is awesome - I suck at word searches, and one of my teachers actually grades them ;-;. Thanks.

 

Give it a rest, he made something out of boredom, I imagine he cares less about XssMe warnings. Maybe find a different hobby? -- gotta be something you like to other than running Firefox plugins against random sites and colouring text. Wait, colouring, now there's an idea! I'm sure you can put that talent to better use.

Ooh, rage.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.