169k views
3 votes
A programmer completes the user manual for a video game she has developed and realizes she has reversed the roles of goats and sheep throughout the text. Consider the programmer's goal of changing all occurrences of "goats" to "sheep" and all occurrences of "sheep" to "goats." The programmer will use the fact that the word "foxes" does not appear anywhere in the original text.

Which of the following algorithms can be used to accomplish the programmer's goal?

(A) First, change all occurrences of "goats" to "sheep." en, change all occurrences of "sheep" to "goats."
(B) First, change all occurrences of "goats" to "sheep." en, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."
(C) First, change all occurrences of "goats" to "foxes." en, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."
(D) First, change all occurrences of "goats" to "foxes." en, change all occurrences of "foxes" to "sheep." Last, change all occurrences of "sheep" to "goats."
I know that the answer is C but can someone explain to me why the answer is C?

User Alaa Ali
by
3.9k points

2 Answers

1 vote

It is C) First, change all occurrences of "goats" to "foxes." en, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."

User Hridayesh
by
4.9k points
4 votes

Answer:

(C)

Step-by-step explanation:

The way to do this would be to

First, change all occurrences of "goats" to "foxes." en, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."

This will use foxes as an intermediary since it does not exist in the code it will not affect any of the current code by using it. Therefore you would change goats to foxes, as a placeholder for goats. Then you would change sheep to goats since goats no longer exists as goats. Lastly you change foxes which is actually goats to sheep, thus getting rid of foxes and having switched only sheep for goats and vice versa

User Modern Labs
by
4.9k points