taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.3-18

Exercise 2.3-18

not stated yet in Lean solution written

Rating08
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 2.3 of Volume 1

The task

In the List L=(a,(b,a,b),(),c,(((2))))L = (a, (b,a,b), (), c, (((2)))) find L[5,1,1]L[5,1,1] and L[3,1]L[3,1].

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Take elements one index at a time. L[i]L[i] is the iith element of LL, and L[i,j]L[i,j] is the jjth element of L[i]L[i].

Solution

Show the solution

L[5]L[5] is the fifth element, (((2)))(((2))). Then L[5,1]L[5,1] is its first element, ((2))((2)), and L[5,1,1]L[5,1,1] is the first element of that, namely (2)(2).

L[3]L[3] is the third element, the empty List ()(). It has no first element, so L[3,1]L[3,1] does not exist.

Answer: L[5,1,1]=(2)L[5,1,1] = (2), and L[3,1]L[3,1] is undefined.

Check

Python3 encoded LL as a nested list and indexed it: the element at the path (5,1,1)(5, 1, 1) is [2], and the path (3,1)(3, 1) raises an index error.

Remarks

The atom 22 would be L[5,1,1,1]L[5,1,1,1].

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.