In this example, we prove that when we set index 1 of list [0, [1, [2,[]]]] to 4, the result is [0, [4, [2, []]]].
There are two parts to this process. In part 1, we pop an element from the front of the list, store this element in a "visited" list, and decrease the index by 1. We repeat this until index is 0. At this point, we have reached the element that we want to replace.
In part 2, we pop the element to be replaced. Then we prepend the new value (4) to the "visited" list, reverse it, and then prepend the reversed list to the remaining list.
For instance, the following:
set index 1 of remaining stack [ 0, [ 1, [ 2, [ ] ] ] ] to 4 with visited : [ ]
is equal to:
set index 0 of remaining stack [ 1, [ 2, [ ] ] ] to 4 with visited : [ 0, [ ] ]
which is equal to:
result of dumping [ 4, [ 0, [ ] ] ] to [ 2, [ ] ]
which is equal to:
[ 0, [ 4, [ 2, [ ] ] ] ]
Quiz (1 point)
- result of storing value at index idx of stack elements = set index idx of remaining stack elements to value with visited : [ ]
- set index idx of remaining stack [ x, rest ] to value with visited : y = set index (idx - 1) of remaining stack rest to value with visited : [ x, y ]
- 1 - 1 = 0
- set index 0 of remaining stack [ x, rest ] to value with visited : visited = result of dumping [ value, visited ] to rest
- result of dumping [ 4, [ 0, [ ] ] ] to [ 2, [ ] ] = [ 0, [ 4, [ 2, [ ] ] ] ]
if 1 - 1 = 0, then set index (1 - 1) of remaining stack [ 1, [ 2, [ ] ] ] to 4 with visited : [ 0, [ ] ] = set index 0 of remaining stack [ 1, [ 2, [ ] ] ] to 4 with visited : [ 0, [ ] ]
if the following are true:
- a = b
- b = c
then a = c
if the following are true:
- a = b
- b = c
then a = c
if the following are true:
- a = b
- b = c
then a = c
if the following are true:
- a = b
- b = c
then a = c
Please write your proof in the table below. Each row should contain one claim. The last claim is the statement that you are trying to prove.