Created
July 28, 2012 03:40
-
-
Save JosephLenton/3191671 to your computer and use it in GitHub Desktop.
Times wordsearch answer finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script> | |
String.prototype.reverse = function() { | |
return this.split('').reverse().join(''); | |
} | |
var searchName = function( name, lines ) { | |
for ( var j = 0; j < lines.length; j++ ) { | |
if ( lines[j].indexOf(name) !== -1 ) { | |
return true; | |
} | |
} | |
return false; | |
} | |
var reverseArr = function( lines ) { | |
var reverse = new Array( lines.length ); | |
for ( var i = 0; i < lines.length; i++ ) { | |
reverse[i] = lines[i].reverse(); | |
} | |
return reverse; | |
} | |
var linesToColumns = function( lines ) { | |
var lineLen = lines[0].length; | |
var columns = new Array( lineLen ); | |
for ( var i = 0; i < lineLen; i++ ) { | |
var column = new Array( lines.length ); | |
for ( var j = 0; j < lines.length; j++ ) { | |
var line = lines[j]; | |
column[j] = line.charAt(i); | |
} | |
columns[i] = column.join(''); | |
} | |
return columns; | |
} | |
var lines = [ | |
"vkholmestxfja", | |
"gjzqzroslvvrp", | |
"eunnlnnovettg", | |
"iadegobpmgzpr", | |
"hejzbaoeaolze", | |
"cfatykfqroefd", | |
"ttnesnipcding", | |
"irufgeptzhtor", | |
"rnqwjkrbzesea", | |
"seeevnffewijv", | |
"otrlbarandrne", | |
"bumlcrnmbbhoz", | |
"tlsslnascqcsw" | |
]; | |
var reverseLines = reverseArr( lines ), | |
columns = linesToColumns( lines ), | |
reverseColumns = reverseArr( columns ); | |
var names = "christie redgrave pinsent holmes edgar rand ovett cram wells goodhew ritchie ranken". | |
split( ' ' ); | |
var found = {}; | |
for ( var i = 0; i < names.length; i++ ) { | |
var name = names[i]; | |
found[name] = | |
searchName( name, lines ) || | |
searchName( name, reverseLines ) || | |
searchName( name, columns ) || | |
searchName( name, reverseColumns ); | |
} | |
for ( var k in found ) { | |
if ( found.hasOwnProperty(k) ) { | |
if ( found[k] ) { | |
document.write( "found\t " + k + '<br>' ); | |
} else { | |
document.write( "not found\t " + k + '<br>' ); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment