Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5. (Exhaustive Search, 8 points for functional correctness, 7 points for performance) An anagram puzzle is a puzzle where the objective is to rearrange

image text in transcribedimage text in transcribedimage text in transcribed

5. (Exhaustive Search, 8 points for functional correctness, 7 points for performance) An anagram puzzle is a puzzle where the objective is to rearrange the letters of a word or phrase into another word or phrase, usually without reusing any words from the original. For example, the letters in the three words "locale plasma tedium" can be rearranged into three different words, "mallet palace sodium", as shown below: ma 1 dium XXXIII palace An anagram puzzle can be solved by exhaustive search. Complete the JavaScript function findThree WordAnagram in anagram.ja in your fork of the homework repository so that it takes a list of words in the original phrase and a list of words that may appear in the solution (defaulting to a dictionary of six-letter words from vocabulary.ja) and either returns undefined if there is no three-word anagram of the original phrase or else a sorted list of three new words that form an anagram. For example, the result of calling findThreeWordAnagram (['locale', 'plasma', 'tedium']) would be the list ['mallet', 'palace', 'sodium'] because those words appear in the default dictionary, do not include any of the input words, and form a three-word anagram of the input phrase. Unit tests to check functional correctness are provided in anagram. test.js, and you can run them using the test-once: anagram: small and test-once: anagram: large NPM scripts for small and large inputs, respectively. A nave exhaustive search will run very slowly on larger inputs. To earn the points for performance, find a way to reduce the search space so that the algorithm solves the puzzles in the unit tests within the generous 15-seconds-per-puzzle time limit. The unit tests associated with the test-once: anagram: large script have been configured to fail if this time limit is exceeded, so you can use them to check performance. Finally, use the project's built-in linter to check your code style. Any eslint-disable directives will be ignored by the autograder, so do not use them to hide warnings in your local copy, or you may miss code style problems that will cost you points. 1 MN my nung lo 2 3 4 5 6 7 8 9 10 55 } chars. sort(); 11 return chars.join(); 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import { SIX_LETTER_VOCABULARY} function combineWordsAndSort Letters (words) { const chars = []; for (let i = 0; i < words.length; i++) { for (let j = 0; j < words [i].length; j++) { chars.push(words [i].charAt(j). to LowerCase()); 33 34 35 36 37 38 39 40 41 42 43 44 } } export function findThreeWordAnagram (words, vocabulary = SIX_LETTER_VOCABULARY) { const sorted = combineWordsAndSortLetters (words); } for (let i = 0; i < vocabulary.length; i++) { for (let j = i + 1; j < vocabulary.length; j++) { for (let k = j + 1; k < vocabulary.length; k++) { const others = [vocabulary[i], vocabulary [j], vocabulary [k]]; let found = false; for (let x = 0; x < words.length && found; x++) { for (let y = 0; y < others.length; y++) { if (words [x].toLowerCase() } from './vocabulary.js'; found = true; break; } png if (found) { continue; } // return undefined; === others [y].toLowerCase()) { if (sorted === combineWordsAndSortLetters (others)) { return others; > found

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

please dont use chat gpt or other AI 6 6 2 . .

Answered: 1 week ago