102 lines
3.9 KiB
Markdown
102 lines
3.9 KiB
Markdown
|
|
# Coding 1: What the Fox Says
|
||
|
|
|
||
|
|
This is a fairly easy warmup coding homework designed to get you used to the
|
||
|
|
mechanics of the questions/homework assignments for this class.
|
||
|
|
|
||
|
|
Remember when this went viral?
|
||
|
|
[Ylvis - The Fox (What Does The Fox Say?) [Official music video HD]](https://www.youtube.com/watch?v=jofNR_WkoCE)
|
||
|
|
|
||
|
|
## The Problem
|
||
|
|
|
||
|
|
Motivated by solving the ancient mystery you are going to figure out exactly
|
||
|
|
what the fox says from a transcript of a recording of animal sounds from the
|
||
|
|
forest. You are working with a team of scientists who have already figured out
|
||
|
|
what sounds all of the other animals make. Your task is to filter out the known
|
||
|
|
forest sounds to determine once and for all, what does the fox say?
|
||
|
|
|
||
|
|
## Input
|
||
|
|
|
||
|
|
The input consists of one line of forest noises given as a series of words
|
||
|
|
separated by spaces. The next line of input is a number n describing how many
|
||
|
|
known animal sounds there are. The next n lines describe n animal sounds given
|
||
|
|
in the format "_[animal name] goes [noise]_".
|
||
|
|
|
||
|
|
## Output
|
||
|
|
|
||
|
|
The output consists of two lines, the first is the list of sounds in order
|
||
|
|
uttered by our shy, sly fox. The last line lists the names of any other animals
|
||
|
|
heard in the recording in the order in which they were first heard with no
|
||
|
|
animal repeated (the scientists asked you for this for research purposes). The
|
||
|
|
first line should be formatted "_what the fox says: [whatever the fox did
|
||
|
|
say]_". The last line should be formatted "_also heard: [space separated list of
|
||
|
|
animals also heard in order they were heard]_". There should be NO spaces
|
||
|
|
following the last thing the fox says and the last animal name (just a new line
|
||
|
|
character).
|
||
|
|
|
||
|
|
<table>
|
||
|
|
<tr>
|
||
|
|
<td>Sample Input</td>
|
||
|
|
<td>Sample Output</td>
|
||
|
|
</tr>
|
||
|
|
<tr>
|
||
|
|
<td><pre>toot woof wa ow ow ow pa blub blub pa toot pa blub pa pa ow pow toot<br>5<br>dog goes woof<br>fish goes blub<br>elephant goes toot<br>seal goes ow<br>horse goes neigh</pre></td>
|
||
|
|
<td><pre>what the fox says: wa pa pa pa pa pa pow<br>also heard: elephant dog seal fish</pre></td>
|
||
|
|
</tr>
|
||
|
|
</table>
|
||
|
|
|
||
|
|
## Your Task
|
||
|
|
|
||
|
|
Your task is to implement two versions of the program solving the code above.
|
||
|
|
The first version (**cs412_foxsays_list.py**) should **only use** list data
|
||
|
|
structures. The second version (**cs412_foxsays_dict.py**) must utilize
|
||
|
|
maps/dictionaries and set data structures to speed up your code as much as
|
||
|
|
possible.
|
||
|
|
|
||
|
|
Gradescope is checking for dictionaries to NOT be in the first version and for a
|
||
|
|
dictionary to be in the second version.
|
||
|
|
|
||
|
|
## Test Cases
|
||
|
|
|
||
|
|
Example input/output:
|
||
|
|
|
||
|
|
### Test #1:
|
||
|
|
|
||
|
|
- Input file: [foxsays_t1_in.txt](./inputs/foxsays_t1_in.txt)
|
||
|
|
- Output file: [foxsays_t1_exp.txt](./outputs/foxsays_t1_exp.txt)
|
||
|
|
|
||
|
|
### Test #2:
|
||
|
|
|
||
|
|
- Input file: [foxsays_t2_in.txt](./inputs/foxsays_t2_in.txt)
|
||
|
|
- Output file: [foxsays_t2_exp.txt](./outputs/foxsays_t2_exp.txt)
|
||
|
|
|
||
|
|
There is a unittest file that you can download
|
||
|
|
([foxsays_unittest.py](./foxsays_unittest.py)) and use to test your program. See
|
||
|
|
the programming guidelines (located here in canvas:
|
||
|
|
[CS412_CodingAssignmentGuidelines.pdf](https://canvas.jmu.edu/courses/2112008/files/180153311?wrap=1))
|
||
|
|
which specifies how to structure your program and also how to use the unittest
|
||
|
|
file.
|
||
|
|
|
||
|
|
You can use a diff program to compare your output to these examples before
|
||
|
|
submitting to [Gradescope](http://www.gradescope.com/).
|
||
|
|
|
||
|
|
## Code Templates for this class
|
||
|
|
|
||
|
|
Your python code must utilize this template:
|
||
|
|
[cs412_code_template.py](../cs412_code_template.py)
|
||
|
|
|
||
|
|
## Turning it in
|
||
|
|
|
||
|
|
Turn in these two files (cs412_foxsays_list.py and cs412_foxsays_dict.py) to
|
||
|
|
Gradescope. Here are some larger test files to see how fast your program runs:
|
||
|
|
|
||
|
|
- [foxsays_tleader_in.txt](./inputs/foxsays_tleader_in.txt) and
|
||
|
|
[foxsays_tleader_exp.txt](./outputs/foxsays_tleader_exp.txt)
|
||
|
|
|
||
|
|
## Leaderboard/Speed Check
|
||
|
|
|
||
|
|
Your code will be checked for speed and a leaderboard posted within Gradescope.
|
||
|
|
|
||
|
|
## Acknowledgments
|
||
|
|
|
||
|
|
Problem from Kattis are used under their educational license.
|