ruby challenge 4

follow the chain

This challenge has a link that goes to ;

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

and it tells you that ‘the next nothing is 92512’. So the challenge is to enter the each nothing in order to return the next nothing. Easy enough, till they throw you a couple of challenges a few dozen nothings in. After adjusting the script a couple of times I ended up with;

#!/usr/bin/ruby
nothing = 12345
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
require 'open-uri'
while nothing > 0
  nNothing = open(url + nothing.to_s).read
  puts nNothing
  if nNothing.split(" ")[1] == "Divide"
    nothing /= 2
  else
  nothing = nNothing.split("nothing is ")[1].to_i
  end
end

I started out using regex to grab the numbers, but they quickly nix that method.

Next challenge 5; Peak Hell

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s