etude3.rb
# Find a longest path for 9 points keychain
# Key format: numbers in a row: 123456789 or 154 or 391 etc
# Iterator
# Filter incorrect keys
# Calculate length of the key
Find a longest path for 9 points keychain
Key format: numbers in a row: 123456789 or 154 or 391 etc
Iterator
Filter incorrect keys
Calculate length of the key
Find a longest path for 9 points keychain Key format : numbers in a row : 123456789 or 154 or 391 etc Iterator Filter incorrect keys Calculate length of the key
def iterate_keys(extra_numbers)
  extra_numbers.each do |x|
    iterate_keys(extra_numbers - [x]) {|y| yield [x]+y}
  end
  yield []
end
def iterate_keys ( extra_numbers ) extra_numbers . each do | x | iterate_keys ( extra_numbers - [ x ] ) { | y | yield [ x ] + y } end yield [ ] end
Find a longest path for 9 points keychain
Key format: numbers in a row: 123456789 or 154 or 391 etc
Iterator
Filter incorrect keys
Calculate length of the key
Find a longest path for 9 points keychain Key format : numbers in a row : 123456789 or 154 or 391 etc Iterator Filter incorrect keys Calculate length of the key
extra_numbers