{"id":75366,"date":"2018-02-20T23:50:30","date_gmt":"2018-02-20T23:50:30","guid":{"rendered":"https:\/\/writemyessayfree.com\/a-popular-diversion-in-the-united-states"},"modified":"2017-08-18T07:01:25","modified_gmt":"2017-08-18T07:01:25","slug":"a-popular-diversion-in-the-united-states","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/a-popular-diversion-in-the-united-states\/","title":{"rendered":"A popular diversion in the United States"},"content":{"rendered":"<p>A popular diversion in the United States, \u201cword find\u201d (or \u201cword<\/p>\n<p>search\u201d) puzzles ask the player to find each of a given set of words in a square&amp;nbsp;table filled with single letters. A word can read horizontally (left or right),&amp;nbsp;vertically (up or down), or along a 45 degree diagonal (in any of the four&amp;nbsp;directions) formed by consecutively adjacent cells of the table; it may wrap&amp;nbsp;around the table\u2019s boundaries, but it must read in the same direction with no&amp;nbsp;zigzagging. The same cell of the table may be used in different words, but, in a&amp;nbsp;given word, the same cell may be used no more than once. Write a computer&amp;nbsp;program for solving this puzzle.<\/p>\n<p>Trying to write it java first and then pseudo code. Need help.<\/p>\n<p>&amp;nbsp;<\/p>\n<p>public class WordSearch {<\/p>\n<p>private static ArrayList board = new ArrayList()<\/p>\n<p>private static Scanner scanner<\/p>\n<p>public static void readBoard() {<\/p>\n<p>while (true) {<\/p>\n<p>line = input next line<\/p>\n<p>if (line equals NULL)<\/p>\n<p>exit from loop<\/p>\n<p>Delete all spaces in line, convert to Uppercase and add to board } }<\/p>\n<p>&amp;nbsp;<\/p>\n<p>public static void printBoard() {<\/p>\n<p>rows = getRows();<\/p>\n<p>for (row=0 to rows)<\/p>\n<p>print board.get(row); }<\/p>\n<p>public static int getRows() {<\/p>\n<p>return the number of rows }<\/p>\n<p>public static int getCols() {<\/p>\n<p>return the number of columns }<\/p>\n<p>public static void createScanner() {<\/p>\n<p>try {<\/p>\n<p>scanner = new Scanner(new java.io.File(\u201cWordSearchInput.txt\u201d)); }<\/p>\n<p>catch (Exception e) {<\/p>\n<p>exit from program } }<\/p>\n<p>public static void processWords() {<\/p>\n<p>while (scanner has a next word) {<\/p>\n<p>word = scanner.next();<\/p>\n<p>findWord(word); }<\/p>\n<p>&amp;nbsp;<\/p>\n<p>public static void findWord(String word) {<\/p>\n<p>rows = get the number of rows<\/p>\n<p>cols = get the number of columns<\/p>\n<p>for (row=0 to rows)<\/p>\n<p>for (col=0 to cols)<\/p>\n<p>findWord(word,row,col); }<\/p>\n<p>public static void findWord(String word, int row, int col) {<\/p>\n<p>for (drow=-1 to 1)<\/p>\n<p>for (dcol=-1 to 1)<\/p>\n<p>findWord(word,row,col,drow,dcol); }<\/p>\n<p>public static void findWord(String word, int row, int col, int drow, int dcol) {<\/p>\n<p>rows = get the number of rows<\/p>\n<p>cols = get the number of columns<\/p>\n<p>for (offset=0 to word.length) {<\/p>\n<p>targetRow = row + offset*drow;<\/p>\n<p>targetCol = col + offset*dcol;<\/p>\n<p>if ((targetRow is less than 0) OR<\/p>\n<p>(targetRow is greater than equal to rows) OR<\/p>\n<p>(targetCol is less than 0) OR<\/p>\n<p>(targetCol is greater than equal to cols))<\/p>\n<p>return<\/p>\n<p>boardChar = board.get(targetRow).charAt(targetCol);<\/p>\n<p>wordChar = word.charAt(offset);<\/p>\n<p>if (boardChar not equal to wordChar)<\/p>\n<p>\/\/ mismatch, so we\u2019re done<\/p>\n<p>return }<\/p>\n<p>print (word, row, col, drow, dcol); }<\/p>\n<p>&amp;nbsp;<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>createScanner();<\/p>\n<p>readBoard();<\/p>\n<p>printBoard();<\/p>\n<p>processWords(); } }<\/p>\n<p>}<\/p>\n<p>&amp;nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A popular diversion in the United States, \u201cword find\u201d (or \u201cword search\u201d) puzzles ask the player to find each of a given set of words in a square&amp;nbsp;table filled with single letters. A word can read horizontally (left or right),&amp;nbsp;vertically <a href=\"https:\/\/www.benedictsol.com\/blogs\/a-popular-diversion-in-the-united-states\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-75366","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/75366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=75366"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/75366\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=75366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=75366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=75366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}