Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Go program: The program's first argument is the word to search for in the puzzle. The second argument is either the file path

Write a Go program: The program's first argument is the word to search for in the puzzle. The second argument is either the file path to the puzzle or "-" which means the program will read the puzzle from standard input. The puzzle is a UTF-8 encoded text file with one line per row in the puzzle. The puzzle is rectangular so all rows must have the same number of columns. If they do not then write "inconsistent line length" to standard error and exit with exit code 3.
2. Output the matches one per line in the following format. (R, C) D where R is the row (1-based), C is the column (1-based), and D is the unicode direction arrow from the set →←↓↑↘↗↙↖. The matches must be output in lexicographic order on the vector RCD.

3. Be sure to close of file descriptor. You will loose a point for each file descriptor not closed.

4. Do not use any library other than the Go standard library.

5. The source code must compile with the most recent version of the Go compiler.

6. The program must not panic under any circumstances.

7. Make sure your code is "gofmt'd". See gofmt or better use goimports or better yet configure IDE to do this formatting on file save.

Hints:

The bufio, fmt, and strings packages might be useful for this assignment.
example output
$ cat puzzle1.txt
abcdefg
hiŮklmn
pqœstuv

$ cat puzzle2.txt
cxxxefg
bxfxhi0
cxxxc10

$ go run ./cmd/wordsearch de puzzle1.txt
(1, 4) →

$ go run ./cmd/wordsearch œke puzzle1.txt ← Note: make sure this command run and print “output”
(3, 3) ↗

$ go run ./cmd/wordsearch cx puzzle2.txt
(1, 1) →
(1, 1) ↘
(3, 1) →
(3, 1) ↗
(3, 5) ←
(3, 5) ↖

$ go run ./cmd/wordsearch i puzzle2.txt
(2, 6) ←
(2, 6) ↑
(2, 6) →
(2, 6) ↓
(2, 6) ↖
(2, 6) ↗
(2, 6) ↘
(2, 6) ↙

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

Microsoft Visual C# An Introduction to Object-Oriented Programming

Authors: Joyce Farrell

7th edition

978-1337102100

More Books

Students also viewed these Programming questions

Question

Implement the method keys () for HashST.

Answered: 1 week ago

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago