fork(1) download
  1. @arr = [1, 2, 5]
  2. @limit = 7
  3. @solution = []
  4.  
  5. def yoba_job(nodes = [], state = 0)
  6. @arr.each { |n| yoba_job(nodes.clone.push(n), state + n) if state + n <= @limit }
  7. @solution << nodes if state == @limit
  8. end
  9.  
  10. def yoba_print
  11. print @solution.map(&:sort).uniq.count
  12. end
  13.  
  14. yoba_job
  15. yoba_print
  16.  
Success #stdin #stdout 0.06s 9656KB
stdin
Standard input is empty
stdout
6