Created
July 30, 2015 03:28
-
-
Save ratmav/9f0678fe9bd2a97319b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby 2.2.1 | |
require 'httparty' | |
URL_PREFIX = 'http://www.wholelattelove.com' | |
@leaf_url = '' | |
def response(suffix) | |
HTTParty.get(URL_PREFIX + suffix) | |
end | |
def branch(node, direction) | |
puts "Checking #{node}..." | |
@leaf_url = URL_PREFIX + "#{node[direction]}" | |
branch = response("#{node[direction]}") | |
fetch_node(branch) unless branch.include? 'game' # NOTE: Skip dead branches. | |
end | |
def fetch_node(node) | |
if node.include? 'great' | |
puts "LEAF URL: #{@leaf_url}" | |
exit # NOTE: Stop checking once the leaf is found. | |
else | |
branch(node, 'right') | |
branch(node, 'left') | |
end | |
end | |
start = response('/challenge') | |
root = response("#{start['start']}") | |
fetch_node(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment