2018/day-16/day-16-part-1.rb
# Depth-first search
# Didn't needed to do this as there was an opcode with only one possibility
Depth-first search
Didn't needed to do this as there was an opcode with only one possibility
Depth - first search Didn ' t needed to do this as there was an opcode with only one possibility
def find_solution(possibilities, *rest)
  return [possibilities.first] if rest.empty?
  possibilities.each do |inst|
    copy = rest.map(&:clone)
    copy.each { |instrs| instrs.delete(inst) }
    codes = [inst].concat(find_solution(*copy))
    return codes if codes.none?(&:nil?)
  end
  [nil]
end
def find_solution ( possibilities , * rest ) return [ possibilities . first ] if rest . empty? possibilities . each do | inst | copy = rest . map ( & :clone ) copy . each { | instrs | instrs . delete ( inst ) } codes = [ inst ] . concat ( find_solution ( * copy ) ) return codes if codes . none? ( & :nil? ) end [ nil ] end
Depth-first search
Didn't needed to do this as there was an opcode with only one possibility
Depth - first search Didn ' t needed to do this as there was an opcode with only one possibility
possibilities
<not_specific>
rest
<not_specific>