Skip to content

Instantly share code, notes, and snippets.

@lufeihaidao
Created April 13, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lufeihaidao/10588223 to your computer and use it in GitHub Desktop.
Save lufeihaidao/10588223 to your computer and use it in GitHub Desktop.
Q4 of python challenge
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