pythonchallenge.com 4在红宝石溶液中

问题描述

比下面的ruby代码,是否有一个“更好/替代/更具可读性”的解决方案来http://www.pythonchallenge.com/pc/def/linkedlist.php? 我能理解,但对我来说似乎不太清楚...
#!/usr/bin/env ruby -w
# encoding: utf-8

require \'net/http\'

Net::HTTP.start \'www.pythonchallenge.com\' do |http|
  nothing = 12345

  nothing = case http.get(\"/pc/def/linkedlist.php?nothing=#{nothing}\").body
    when /(\\d+)$/ then $1.to_i
    when /by two/ then nothing / 2
    when /\\.html/ then puts $`
  end while nothing
end
    

解决方法

        没关系,但让我们尝试使其更具可读性:
#!/usr/bin/env ruby -w
# encoding: utf-8

require \'net/http\'

Net::HTTP.start \'www.pythonchallenge.com\' do |http|
  next_one = 12345

  while next_one
    response = http.get(\"/pc/def/linkedlist.php?nothing=#{next_one}\").body

    case response 
      when /Divide by two and keep going./ then
        next_one = next_one / 2
      when /and the next nothing is (\\d+)/ then
        next_one = $1.to_i
      else
        puts \"Solution url: www.pythonchallenge.com/pc/def/linkedlist.php?nothing=#{next_one}\"
        next_one = false
    end
  end

end
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...