Skip to content

Commit

Permalink
Problem 76
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbantuelle committed Aug 27, 2018
1 parent de3aaf1 commit ba66203
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 076.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'pp'

def possibilities(decomposition)
if decomposition.size > 2
combinations = decomposition.combination(2).to_a.uniq
combinations.each do |c|
composition = decomposition.clone
composition.delete_at(composition.index(c[0]))
composition.delete_at(composition.index(c[1]))
composition << (c[0] + c[1])
composition_string = composition.sort.join
unless $found[composition_string]
$found[composition_string] = true
possibilities(composition)
end
end
end
end

answers = []
3.upto(15) do |target|
decomposition = Array.new(target) { 1 }
$found = {decomposition.join => true}

start_time = Time.now
possibilities(decomposition)
answers << $found.size
end
pp answers.join(',')

0 comments on commit ba66203

Please sign in to comment.