Questions
stone Atone aLone Clone clonS cOons coNns conEs coneY Money Word ladders were invented by Lewis...

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.

----------------------------------------------------
| scart | start   | swart | smalt | smarm |
| smart | smart | smart | smart | smart   |
----------------------------------------------------

Now dequeue the front and find all words one letter different from the top word scart. This will spawn seven stacks:

---------------------------------------------------------------------
| scant | scatt | scare | scarf | scarp | scars   | scary |
| scart | scart | scart | scart | scart | scart   | scart |
| smart | smart | smart | smart | smart | smart | smart |    ----------------------------------------------------------------------

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:

----------------------------------------
| sturt   | stare | stark | stars |
| start   | start   | start   | start   |
| smart | smart | smart | smart |
----------------------------------------

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< String > dict;
   private static LinkedList< String > 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
}
      

Output:

[line, fine]

[dear, fear]

There is no word ladder between stone and money

[fake, lake, lase, last, cast, cost, coat]

[like, line, fine, fire, fore, core, cord, cold, hold, held, help]

There is no word ladder between blue and pink

[face, fake, lake, like]

[help, held, hold, cold, cord, core, fore, fire, fine, find, mind]

[lice, line, fine, fire, fore, core, cord, cold, hold, held, help]

There is no word ladder between door and lice

  

In: Computer Science

Prove that if two non-equal letters are interchanged in a ISBN code word the error will...

Prove that if two non-equal letters are interchanged in a ISBN code word the error will be detected (the word is no longer an ISBN code word)

In: Advanced Math

Given the following memory values and address instruction with an accumulator. Determine the values with the...

Given the following memory values and address instruction with an accumulator. Determine the values with the following instructions load into accumulator.

Word 16 contains 22

Word 18 contains 24

Word 20 contains 26

Word 22 contains 28

Word 24 contains 30

Word 26 contains 32

Word 28 contains 34

i. LOAD IMMEDIATE 16

ii. LOAD DIRECT 16

iii. LOAD INDIRECT 16

iv. LOAD IMMEDIATE 18

v. LOAD DIRECT 18

vi. LOAD INDIRECT 20

vii. LOAD IMMEDIATE 24

viii. LOAD DIRECT 26

ix. LOAD INDIRECT 22

x. LOAD DIRECT 28

[10 Marks]

In: Computer Science

Write a program to allow a user to play the game Hangman. DO NOT USE AN...

Write a program to allow a user to play the game Hangman. DO NOT USE AN ARRAY

The program will generate a random number (between 1 and 4581) to pick a word from the file - this is the word you then have to guess.

Note: if the random number you generate is 42, you need the 42nd word - so loop 41 times picking up the word from the file and not doing anything with it, it is the 42nd you need. Here is how you will do this:

String word:

for (int k=0; k<41; k++)

{word=scnr.nextLine();

}//end loop and now pick up the word you want

word=scnr.nextLine() //this is the one you want

The user will be allowed to guess a letter as many times as it takes - but 10 wrong guesses and they lose!!

Eventually either they won or lost. In case they lost print out the answer.

Code language: Java using JGrasp or NetBeans

In: Computer Science

Python3  Please add comments Write a program that implements the word guessing game - There is a...

Python3  Please add comments

Write a program that implements the word guessing game

- There is a secret word

- The user enters letters one at a time, if the letter appears in the secret word, it is revealed. Otherwise, it counts as a wrong guess.

If the user reveals all the letters in the word before getting too many wrong guesses then they win!

Otherwise, they lose.

1 - define secret word

2 - create a revealed letter list that starts empty

2. set wrong guess count to 0

3. ask the user for a letter

4. is the letter in the secret word?

5. if so: add it to the revealed letters list

create a blank string

for each letter in the secret word, if the letter in

revealed letter list, add that letter to string,

otherwise add an underscore to string

6. if letter not in secret word, add one to wrong guess

7. repeat from step 3

In: Computer Science

in java (just a line of code will do) Your program will read in the text...

in java (just a line of code will do)

Your program will read in the text file, word by word. You are to ignore leading and trailing punctuation and capitalization (i.e., "Castle", "castle?", and "CASTLE" are all equivalent to castle). Convert all words to lower case on input, or you can use case-insensitive comparisons - your choice. You will be putting the words into several implementations of linked lists and comparing the results. If, after trimming punctuation, a "word" consists of no letters, then discard the word. Such a case might arise if your word-reading strategy assumes that every word is delimited by spaces, in which case, a dash would constitute a "word", but would not contain any letters, so it would be discarded (for example, "comparisons - your choice" should be three words, though your space-delimited parser might identify "-" as a fourth "word", but the “-“ should be discarded).

In: Computer Science

What is a warrant statement? (use your own word). What does it mean to interpret? (use...

  1. What is a warrant statement? (use your own word).
  2. What does it mean to interpret? (use your own word).
  3. What is classification? Why is classification important? (use your own word).
  4. What is analysis? What is an analytic essay? (use your own word).
  5. Thanks

In: Economics

Write a C++ program that inputs (cin) a word from the keyboard and generates several different...

Write a C++ program that inputs (cin) a word from the keyboard and generates several different scrambles of the word without using vectors. The input word can be from 4 to 10 letters in length. The number of scrambles produced depends on the number of letters in the word. e.g. the 4 letter word “lose” would have 4 different scrambles produced and the seven letter word “edition” would have seven different scrambles.

Here is a candidate example:     

Input: FLOOR

                Scrambles: ROOLF, OOLFR, OLFRO, LOORF, OORFL

Your program must use the same block of code for each input word. There is also the rand() random number generator available.

Test you program with these words:

salt
asteroid
manipulate

In: Computer Science

I wrote this code and it produces a typeError, so please can you fix it? import...

I wrote this code and it produces a typeError, so please can you fix it?

import random

def first_to_a_word():

print("###### First to a Word ######")
print("Instructions:")
print("You will take turns choosing letters one at a time until a word is formed.")
print("After each letter is chosen you will have a chance to confirm whether or not a word has been formed.")
print("When a word is formed, the player who played the last letter wins!")
print("One of you has been chosen at random to initiate the game.")
print()
print("Note: Words must be longer than a single letter!")
print()

  
#inputs / randomNumGen
player1 = input("Enter player 1's name: ")
player2 = input("Enter player 2's name: ")
random_number = random.randint(0, 1)
  
#output function
def output_func(player1, player2, random_number):
if random_number == 0:
word = input(player1, 'please enter a character: ')
print(player1, 'input:', word)
else:
word = input(player2, 'please enter a character: ')
print(player2, 'input:', word)
  
return word
  
#initial variables
word_confirm = ''
counter = 0
word_array = []
  
#character input loop
while word_confirm != 'yes':
  
#function call
word = output_func(player1, player2, random_number)
  
#append
word_array.append(word)
  
#alternate players turns
if random_number == 0:
random_number = 1
else:
random_number = 0
  
#check for exit after >=3 letters formed
if counter >= 2:
print('You have formed the letters:') #three letters
word_confirm = input('Has the word been formed? (type "yes" or "no"): ')
word_confirm = word_confirm.lower()
  
counter += 1
  
complete_word = ''
i = 0
while i < len(word_array):
  
complete_word += word_array[i]
i += 1
  
if random_number == 1:
print(player1, 'Wins!')
print('The word was:', complete_word)
else:
print(player2, 'Wins!')
print('The word was:', complete_word)
  
  

first_to_a_word()

In: Computer Science

Write a Java program that directs the user to enter a single word (of at least...

Write a Java program that directs the user to enter a single word (of at least four characters in length) as input and then prints the word out in reverse in the pattern shown below (please note that the spaces added between each letter are important and should be part of the program you write):

<Sample Output

Enter a word (at least four characters in length): cat

Word must be at least four characters in length, please try again. Enter a word (at least four characters in length): mountain

ח

ni

nia

niat

niatn

niatnu

naitanui

niat nuom

<End Output

If the user enters more than a single word, your program should perform the pattern with only the first word entered by the user:
Enter a word (at least four characters in length): Eggs Benedict

s

sg

sgg

sggE

<End Output

Create a complete class for your program named Rearrange Word and paste the entire class into the text box provided. Your class must contain a main method, and you should create at least two additional methods in your class to carry out the task described (one to reverse the word, the other to print out the reversed word in the pattern shown). Your program does not need to prompt the user for additional input beyond the first successful entry, it can simply terminate once the task has been completed.

In: Computer Science