Skip to content

Instantly share code, notes, and snippets.

@ratmav
Created July 30, 2015 03:28
Show Gist options
  • Save ratmav/9f0678fe9bd2a97319b1 to your computer and use it in GitHub Desktop.
Save ratmav/9f0678fe9bd2a97319b1 to your computer and use it in GitHub Desktop.
# 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