Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'highline'
- require_relative 'union_find'
- def ask_for_int(cli, question)
- cli.ask(question, ->(answer) { Integer(answer) if answer =~ /^\d+$/ })
- end
- def init_connection_from(cli, max_nodes)
- %w{from to}.map do |direction|
- cli.say(direction.humanize)
- cli.choose do |menu|
- menu.choices(*(0..max_nodes - 1)) { |node| node }
- end
- end
- end
- def init_from(cli)
- size = ask_for_int(cli, 'How many nodes in the network?')
- connections = []
- loop do
- cli.say('New connection:')
- nodes = init_connection_from(cli, length)
- connections << nodes
- break if cli.agree('Finish?')
- end
- { size: size, connections: connections }
- end
- cli = HighLine.new
- user_input = init_from(cli)
- union_find = UnionFind::UnionFind.new user_input.size
- union_find.init_connections user_input.connections
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement