Challenge 3: Lazy Evaluation on an Infinite Range — Solution result = (1..Float::INFINITY).lazy .select { |n| n % 3 == 0 } .select { |n| n > 100 } .first(5) puts result.inspect # Without .lazy, (1..Float::INFINITY).select { ... }.select { ... } would # try to eagerly build a complete intermediate array from EVERY number in # the infinite range before .first(5) ever got a chance to run — since the # range never ends, the program would simply hang forever, never reaching # the .first(5) line at all. .lazy makes each .select only pull one value # at a time, on demand, so .first(5) can stop the whole chain the moment # it has collected 5 matching results. =begin Output: [102, 105, 108, 111, 114] Notes: - .lazy converts the range into a lazy enumerator immediately, before either .select call runs. - Each .select in the chain is itself lazy — it doesn't build an intermediate array, it just wraps the previous step with an additional filter condition, all evaluated lazily together. - .first(5) is what actually triggers evaluation, pulling values through the whole lazy chain one at a time until 5 pass both select conditions, then stopping immediately — it never touches the range beyond 114. =end