6 kyu
Name That Integer
275 of 713hencethus
Description:
Ruby
Write a method detect_int
that returns the first positive integer for which an arbitrary number of lambdas returns true. If no arguments are passed in, then detect_int
should return 1
.
For example:
lam1 = lambda { |x| x > 9 }
lam2 = lambda { |x| x**0.5 % 1 == 0 }
detect_int # => 1
detect_int lam1 # => 10
detect_int lam2 # => 1
detect_int lam1, lam2 # => 16
The testing rubric will never ask for a number that does not exist, like:
detect_int(lambda { |x| x.odd? }, lambda { |x| x.even? }) // => !??
Note that loops constructed using the loop { block }
syntax are limited to 5000 iterations, but solutions will not be constrained to integers less than 5000.
For examples, see the example test cases.
Fundamentals
Similar Kata:
Stats:
Created | Apr 28, 2014 |
Published | Apr 28, 2014 |
Warriors Trained | 1636 |
Total Skips | 256 |
Total Code Submissions | 4299 |
Total Times Completed | 713 |
Ruby Completions | 275 |
JavaScript Completions | 447 |
Total Stars | 20 |
% of votes with a positive feedback rating | 91% of 112 |
Total "Very Satisfied" Votes | 93 |
Total "Somewhat Satisfied" Votes | 17 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 19 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |