Created
April 13, 2014 15:16
-
-
Save lufeihaidao/10588223 to your computer and use it in GitHub Desktop.
Q4 of python challenge
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
require "open-uri" | |
n=12345 | |
loop do | |
flag = '' | |
open("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=#{n}") do |f| | |
s=f.read | |
flag = s if s=~/htm/ | |
n=(s=~/div/ ? n/2 : s.split[-1].to_i) | |
end | |
if !flag.empty? | |
puts flag | |
break | |
end | |
end | |
# 需要注意的是,我本来是把 break 放在 open 这个 block 里的,我以为当 s 匹配到 htm 时, | |
# 接着 break 就可以退出了。但是 ruby 的 break 是退出最临近的 block,所以 loop 还是会 | |
# 死循环下去。因此不得不加了一个 flag。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment