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
lam1 = x => x > 9
lam2 = 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? })      // => !??
detect_int(n=>n%2==1, n=>n%2==0)      // => !??

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

Stats:

CreatedApr 28, 2014
PublishedApr 28, 2014
Warriors Trained1636
Total Skips256
Total Code Submissions4299
Total Times Completed713
Ruby Completions275
JavaScript Completions447
Total Stars20
% of votes with a positive feedback rating91% of 112
Total "Very Satisfied" Votes93
Total "Somewhat Satisfied" Votes17
Total "Not Satisfied" Votes2
Total Rank Assessments19
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • hencethus Avatar
  • jhoffner Avatar
  • Blind4Basics Avatar
Ad