Last active
August 29, 2015 14:22
-
-
Save lukebergen/8643955e2f65bda7e47b to your computer and use it in GitHub Desktop.
A solution to problem 5 on https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_100s(digits, i=0) | |
if i == digits.length - 1 | |
eval(digits) == 100 ? [digits] : [] | |
else | |
[find_100s(digits[0..i] + "+" + digits[i+1..-1], i+2), find_100s(digits[0..i] + "-" + digits[i+1..-1], i+2), find_100s(digits, i+1)] | |
end | |
end | |
puts find_100s("123456789") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment