Name: __________________________________________
Specifications:
public void reset()
Resets the WordMaker so that it is ready to start building a word.
public void addChar(newChar);
Adds a character to the WordMaker. If it is a letter and
WordMaker is making a word, it adds it to the end of the word. If
it is a letter and WordMaker is not making a word, it erases the
current word, and starts a new word with the letter. If it is not a
letter and WordMaker is making a word, it ends the word (unless
it is an apostrophe, treated specially as described above). If it is not
a letter and WordMaker is not making a word, it is ignored.
public boolean wordReady()
Returns true if the WordMaker has finished constructing a word,
false otherwise. After a reset, or when the WordMaker is first
constructed, it returns false. When a word has just been completed
(i.e., the first non-letter character has been added), it returns true.
Otherwise it returns false.
public String getWord()
Returns the word that the WordMaker has created when
WordReady returns true. It should not be called when WordReady
returns false.
In: Computer Science
def main():
# keeping asking user for a word or
name until user enters 0
while True:
word =
input('Enter a word/name to convert (enter 0 to quit):
').upper()
if word ==
'0': break
print(convert_to_soundex(word))
Whenever i try to run the program it tells me unintend doesn't match any outer identation level !!!!
In: Computer Science
For our current programming assignment I need to create a CleanWord method that reads in one variable string at a time and returns a cleaned word without any non letters. The instructions given to us are listed below:
“Clean word” method:
This is to be implemented as a separate method, so it can be called for either a dictionary word or book word.
The function will remove any non-letters, except an apostrophe (‘) and numbers from the word.
All letters will changed to lower case.
It will then return the updated word. The word could now be blank. The calling method will need to deal with this correctly.
I would appreciate the help!
In: Computer Science
SAMPLE PROGRAM RUN #1
Enter a word: carrot
First half: car
Second half: rot
SAMPLE PROGRAM RUN #2
Enter a word: plant
First half: pl
Second half: ant
Complete your answer by typing code below
import java.util.Scanner;
public class WordHalves
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
System.out.print("Enter a word: ");
String word = reader.nextLine();
}
}
In: Computer Science
For each of the following propositions the first word in your answer should be the word True or the word False followed by a brief explanation as to why the proposition is true or false.
assume that Frank and Athena can produce either chairs or tables. If Athena has a comparative advantage in producing chairs, then she would be able to sell chairs for a higher price than Frank.
In: Economics
Write a function bracket_by_len that takes a word as an input argument and returns the word bracketed to indicate its length. Words less than five characters long are bracketed with << >>, words five to ten letters long are bracketed with (* *), and words over ten characters long are bracketed with /+ +/. Your function should require the calling function to provide as the first argument, space for the result, and as the third argument, the amount of space available.
Program: C
In: Computer Science
Consider the word CAT
a) What would the hexadecimal representation of this word be in ASCII?
c) If we rotated the bits that represent this word 8 bits to the right, what would the word become (in letters)?
d) If we rotated the bits that represent CAT 8 places to the left, what would the word become (in letters)?
e) What would the results be (in letters) if we XORed the bits that represent CAT with the hexadecimal value 20 20 20?
f) What would the results be (in letters) if we XORed the bits that represent CAT with the hexadecimal value 13 08 13?
In: Computer Science
Use this constant dictionary as a global variable:
tile_dict = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 }
Implement function scrabblePoints(word) that returns the calculated points for the word based on the tile_dict above. The word parameter is a string. This function takes the string and evaluates the points based on each letter in the word (points per letter is set by the global dictionary). P or p is worth the same points. No points calculated for anything that is not A-Z or a-z.
[You may use upper() and isalpha() ONLY and no other method or built-in function]
Examples:
word = “PYTHON”
print(scrabblePoints(word))
returns:
14
word = “hello!!”
print(scrabblePoints(word))
returns:
8
word = “@#$=!!”
print(scrabblePoints(word))
returns:
0
In: Computer Science
|
stone Atone aLone Clone clonS cOons coNns conEs coneY Money |
Word ladders were invented by Lewis Carroll in 1878, the author of Alice in Wonderland. A ladder is a sequence of words that starts at the starting word, ends at the ending word, In a word ladder puzzle you have to change one word into another by altering a single letter at each step. Each word in the ladder must be a valid English word and must have the same length. For example, to turn stone into money, one possible ladder is given on the left. Many ladder puzzles have more than one possible solution. Your program must determine the shortest word ladder. Another path from stone to money is stone store shore chore choke choky cooky cooey coney money Instructions Your program will accept starting and ending words from the input file called "infile.txt". Then, you read the dictionary file called “dictionary.txt '' store all words in a LinkedList. Finally, you build a word ladder between starting and ending words There are several ways to solve this problem. One simple method involves using stacks and queues. The algorithm (that you must implement) works as it follows Get the starting word and search through the dictionary to find all words that are one letter different. Create stacks for each of these words, containing the starting word (pushed first) and the word that is one letter different. Enqueue each of these stacks into a queue. This will create a queue of stacks! Then dequeue the first item (which is a stack) from the queue, look at its top word and compare it with the ending word. If they equal, you are done - this stack contains the ladder. Otherwise, you find all the words one letter different from it. For each of these new words create a deep copy of the stack and push each word onto the stack. Then enqueue those stacks to the queue. And so on. You terminate the process when you reach the ending word or the queue is empty. You have to keep track of used words! Otherwise, an infinite loop occurs. Example The starting word is smart. Find all the words one letter different from smart, push them into different stacks and store stacks in the queue. This table represents a queue of stacks. ---------------------------------------------------- Now dequeue the front and find all words one letter different from the top word scart. This will spawn seven stacks:
--------------------------------------------------------------------- which we enqueue to the queue. The queue size now is 11. Again dequeue the front and find all words one letter different from the top word start. This will spawn four stacks: ---------------------------------------- Add them to the queue. The queue size now is 14. Repeat the procedure until either you find the ending word or such a word ladder does not exist. Make sure you do not run into an infinite loop! Queue You are to implement a Queue data structure based on Java’s Queue class using LinkedList. Stack You are to use Java's Stack class. Output Your program must output to the console one word ladder from the start word to the end word. Every word in the ladder must be a word that appears in the dictionary. This includes the given start and end words--if they are not in the dictionary, you should print "There is no word ladder between ..." Remember that there may be more than one ladder between the start word and the end word. Your program may output any one of these ladders. The first output word must be the start word and the last output word must be the end word. If there is no way to make a ladder from the start word to the end word, your program must output "There is no word ladder between ..." |
import java.util.*;
import java.io.*;
public class WordLadder {
private static LinkedList dict;
private static LinkedList visited;
private static String start, end;
public static void main(String[] args) throws
IOException{
// TODO Auto-generated method stub
File dictfile = new
File("dictionary.txt");
File infile = new
File("infile.txt");
dict = new
LinkedList<>();
// load the dictionary
try(
Scanner in = new
Scanner(dictfile);){
while(in.hasNext()) {
dict.add(in.next());
}
}
try(Scanner in = new
Scanner(infile);)
{
while(in.hasNext()) {
start = in.next();
end = in.next();
if(start.length()!=end.length() || !dict.contains(start) ||
!dict.contains(end) ){
System.out.println("There is no word ladder between "+start+ " and
"+end);
continue;
}
findLadder(start,end);
}
}
}
public static void findLadder(String start,String end)
{
Queue< Stack < String >>
queue = new LinkedList<>();
visited = new
LinkedList<>();
Stack< String > copiedStack =
new Stack<>();
// Left as exercise
}
public static boolean isAnEdge(String w1, String w2)
{
// Left as
exercise
}
In: Computer Science
Given a string sentence that consists of some words separated by a single space, and a string searchWord.
Write a function isPrefix to check if searchWord is a prefix of any word in sentence. A prefix of a string S is any leading contiguous substring of S. It returns the index of the word in sentence where searchWord is a prefix of this word (1-indexed).
If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.
Input: sentence = this problemo is an easy problemo, searchWord = pro
Output: 2
Explanation: pro is prefix of problemo which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.
In: Computer Science