
Title:
Proc Solution  Intro to Computer Science

Description:

In order to solve this problem, you need to have a good understanding

of what the original function, proc, does.

So let's take the two cases that really embody the output of this function.

There are 2 inputs, but the output only depends on the value of A.

Specifically, the value of the function test on a.

If test(a) is true, then we return the second parameter b.

If test(a) is false, we return the first parameter a.

That's what we need to check in each of these functions. Let's start looking at them.

In proc1, if test(x), which is the first parameter is true we return y.

This matches with the original function.

If test of the fist parameter is true, we return the second, as we do in proc1.

If test of the first parameter is false, we return that parameter x.

Test x is false, which is equivalent to test a is false,

and in both cases we return a and x,

which are just different names for the same variable in this function.

This is equivalent.

Let's look at this second functionproc2.

Notice here that this condition is based on the value of b.

We know this can't possibly be equivalent to proc, our original function,

because the output here is not dependent on the value of b.

We can tell right away that this is false. This is not equivalent to our original function.

Let's look at proc3.

The structure here is a little different, but let's work our way through it both examples.

In the event that test(a) is true, we set result to b and rereturn result.

As our original function did, if test(a) is true, we return b.

If test(a) is false, we simply return result, which was set at the beginning to a.

So the overall functionality is that if test(a) is true, we return a.

This matches with our original function definition.

So this is equivalent to proc.

Now we have the last functionproc4.

It might throw you off that you see 'udacity' in quotes here, which is not present

in any other function, but it's important we work our way through the problem.

If test(a) is true, then not test(a) is false.

We return b.

If test(a) is true, we return b.

That matches with the original definition.

If test(a) is false, not test(a) is true,

so we set b to 'udacity,' but then we return a.

If test(a) is false, we change the value of b,

but we don't do anything with itwe just return a.

The result is the same as our original function proc.