7 kyu

sum_eq_n?

257 of 256jastuccio

Description:

Define a method sum_eq_n? which takes an array of integers and an additional integer, n, as arguments and returns true if any two elements in the array of integers sum to n. An empty array should sum to zero by definition.

Examples:

sum_eq_n?([1, 2, 3, 4], 6) == true  # 4 + 2 = 6
sum_eq_n?([1, 2, 3, 4], 8) == false # Not possible
sum_eq_n?([], 0) == true # An empty array should sum to 0
sum_eq_n?([], 1) == false # Not possible

I saw this on stackoverflow and thought it would make an interesting kata.

Arrays
Fundamentals

Stats:

CreatedJan 14, 2015
PublishedJan 14, 2015
Warriors Trained466
Total Skips61
Total Code Submissions979
Total Times Completed256
Ruby Completions257
Total Stars2
% of votes with a positive feedback rating86% of 74
Total "Very Satisfied" Votes59
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes5
Total Rank Assessments43
Average Assessed Rank
6 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • jastuccio Avatar
  • CrazyMerlyn Avatar
  • cliffstamp Avatar
Ad