Last active
August 29, 2015 14:05
-
-
Save johnrees/e9beede3740487b9616a to your computer and use it in GitHub Desktop.
problem 88
This file contains 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
min = 2 | |
max = 100 | |
min.upto(max) do |count| | |
puts "k=#{count}" | |
a = (1..count).to_a | |
options = a.repeated_combination(count).to_a | |
for option in options.reverse | |
addition_total = 0 | |
multiplication_total = 1 | |
for number in option do | |
addition_total += number | |
multiplication_total *= number | |
end | |
if addition_total == multiplication_total | |
puts "#{addition_total} = #{option}" | |
break | |
end | |
end | |
end |
This file contains 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
➜ Desktop ruby 88.rb | |
k=2 | |
4 = [2, 2] | |
k=3 | |
6 = [1, 2, 3] | |
k=4 | |
8 = [1, 1, 2, 4] | |
k=5 | |
8 = [1, 1, 2, 2, 2] | |
k=6 | |
12 = [1, 1, 1, 1, 2, 6] | |
k=7 | |
12 = [1, 1, 1, 1, 1, 3, 4] | |
k=8 | |
12 = [1, 1, 1, 1, 1, 2, 2, 3] | |
k=9 | |
15 = [1, 1, 1, 1, 1, 1, 1, 3, 5] | |
k=10 | |
16 = [1, 1, 1, 1, 1, 1, 1, 1, 4, 4] | |
k=11 | |
16 = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4] | |
k=12 | |
16 = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2] | |
k=13 | |
18 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3] | |
k=14 | |
20 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 5] | |
k=15 | |
24 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 8] | |
k=16 | |
24 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 6] | |
k=17 | |
24 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 6] | |
k=18 | |
24 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4] | |
k=19 | |
24 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3] | |
k=20 | |
28 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment