Question 25
The program below contains variables whose values are defined with lambda functions.
If num = 5, which of the following produces the smallest value? [3 marks]
f4(f3(f1(f2(num))))f4(f1(f2(f3(num))))f3(f2(f1(f4(num))))f2(f3(f2(f3(num))))f1(f4(f2(f3(num))))
Solution
f4(f3(f1(f2(num))))
= f4(f3(f1(int(5**3)))) = f4(f3(f1(125)))
= f4(f3(125 * 125)) = f4(f3(15625))
= f4(15625 // 2) = f4(7812)
= 31248
f4(f1(f2(f3(num))))
= f4(f1(f2(5 // 2))) = f4(f1(f2(2)))
= f4(f1(int(2 ** 3))) = f4(f1(8))
= f4(8 * 8) = f4(64)
= 64 * 4 = 256
f3(f2(f1(f4(num))))
= f3(f2(f1(5 * 4))) = f3(f2(f1(20)))
= f3(f2(20 * 20)) = f3(f2(400))
= f3(int(400**3)) = f3(64000000)
= 64000000 // 2 = 32000000
f2(f3(f2(f3(num))))
= f2(f3(f2(5 // 2))) = f2(f3(f2(2)))
= f2(f3(int(2**3))) = f2(f3(8))
= f2(8 // 2) = f2(4)
= int(4**3) = 64
f1(f4(f2(f3(num))))
= f1(f4(f2(5 // 2))) = f1(f4(f2(2)))
= f1(f4(int(2**3))) = f1(f4(8))
= f1(8 * 4) = f1(32)
= 32 * 32 = 1024
Hence, f2(f3(f2(f3(num)))) yields the smallest result out of all the given options.