49. n, found = 1, 0
while true
n += 1
next unless (2...n).any? { |a| n % a == 0 }
found += 1
puts quot;#{n} squared is #{n * n}quot;
break if found >= 50
end
88. def my_map(list, operation)
result = []
list.each do |item|
result << operation[item]
end
result
end
p my_map([2, 3, 5, 7], Proc.new { |x| x ** 2})
89. def my_map(list, operation)
result = []
list.each do |item|
result << yield(item)
end
result
end
p my_map([2, 3, 5, 7]) { |x| x ** 2}
90. def my_map(list, operation)
result = []
list.each do |item|
result << yield(item)
end
result
end
operation = Proc.new { |x| x ** 2 }
p my_map([2, 3, 5, 7]) ... ???
92. def my_map(list, operation)
result = []
list.each do |item|
result << yield(item)
end
result
end
operation = Proc.new { |x| x ** 2 }
p my_map([2, 3, 5, 7], &operation)
101. def make_stamp(owner)
time = Time.now
lambda do |thing|
quot;#{time}: #{thing} is owned by #{owner}quot;
end
end
sony = make_stamp(quot;Sonyquot;)
puts sony[quot;Playstationquot;]
sleep 1
microsoft = make_stamp(quot;Microsoftquot;)
puts microsoft[quot;X‐boxquot;]
puts sony[quot;Playstationquot;]