<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>yz00 (yangzhen)</title>
    <link>https://ruby-china.org/yz00</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>写了一段 Ruby 代码，但是运行卡住，循环问题</title>
      <description>&lt;p&gt;2520 is the smallest nuber that can be diveded by each of the number from 1 to 10 without any remainder.
what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
朋友发来一道题来做，我一看原来是求 1 到 20 的最小公倍数，然后就写了下面的代码，运行之后输入 20 就卡住了，出不来结果，但是输得数字小点就可以算出来，是不是我的循环写的有问题，想请大家帮忙看下怎么优化一下，有资料最好（本人用的 rubyV2.1.5）&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
&lt;span class="n"&gt;jc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;  
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;&lt;span class="sh"&gt;
end
b.each do |e|         #阶乘
    jc *= e 
end
x=b.max 
co = 1*x
x.upto(jc) do |i|         
        sum=0
        b.each do |f|
            sum = (i%f) +sum
        end
        if sum == 0
            co = i
            break
    end
end
puts "The common multiple is &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;co&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;" 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      <author>yz00</author>
      <pubDate>Tue, 09 Jun 2015 00:00:40 +0800</pubDate>
      <link>https://ruby-china.org/topics/25935</link>
      <guid>https://ruby-china.org/topics/25935</guid>
    </item>
    <item>
      <title>Git 问题来请教下，谢谢大家给看看</title>
      <description>&lt;p&gt;yz00@yz00-Ideapad-Z460:~/sandbox$ touch a.rb
yz00@yz00-Ideapad-Z460:~/sandbox$ touch b.rb
yz00@yz00-Ideapad-Z460:~/sandbox$ git add a.rb
yz00@yz00-Ideapad-Z460:~/sandbox$ git commit "Update a"
error: pathspec 'Update a' did not match any file(s) known to git.&lt;/p&gt;

&lt;p&gt;为什么会报这个错呢？教程里也没说，就来问下&lt;/p&gt;</description>
      <author>yz00</author>
      <pubDate>Sat, 14 Feb 2015 19:52:21 +0800</pubDate>
      <link>https://ruby-china.org/topics/24268</link>
      <guid>https://ruby-china.org/topics/24268</guid>
    </item>
    <item>
      <title>安装 mysql2 报错，大家帮忙看下，么么哒</title>
      <description>&lt;p&gt;安装好 rails 之后，安装 mysql2 报错，如果能教下我怎么看这种错，重点在哪就万分感谢了！
yz00@yz00-Ideapad-Z460:~$  gem install mysql2
Fetching: mysql2-0.3.17.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.&lt;/p&gt;

&lt;p&gt;/home/yz00/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150214-27543-1td7th9.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.&lt;/p&gt;

&lt;p&gt;Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/yz00/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib&lt;/p&gt;

&lt;p&gt;extconf failed, exit code 1&lt;/p&gt;

&lt;p&gt;Gem files will remain installed in /home/yz00/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.17 for inspection.
Results logged to /home/yz00/.rvm/gems/ruby-2.2.0/extensions/x86-linux/2.2.0/mysql2-0.3.17/gem_make.out&lt;/p&gt;</description>
      <author>yz00</author>
      <pubDate>Sat, 14 Feb 2015 01:43:22 +0800</pubDate>
      <link>https://ruby-china.org/topics/24258</link>
      <guid>https://ruby-china.org/topics/24258</guid>
    </item>
    <item>
      <title>求助，安装 rails 失败</title>
      <description>&lt;p&gt;root@yz00-Ideapad-Z460:~# gem source -r &lt;a href="https://rubygems.org/" rel="nofollow" target="_blank"&gt;https://rubygems.org/&lt;/a&gt;
&lt;a href="https://rubygems.org/" rel="nofollow" target="_blank"&gt;https://rubygems.org/&lt;/a&gt; removed from sources
root@yz00-Ideapad-Z460:~# gem source -l
*** CURRENT SOURCES ***&lt;/p&gt;

&lt;p&gt;root@yz00-Ideapad-Z460:~# gem source -a &lt;a href="http://ruby.taobao.org" rel="nofollow" target="_blank"&gt;http://ruby.taobao.org&lt;/a&gt;
&lt;a href="http://ruby.taobao.org" rel="nofollow" target="_blank"&gt;http://ruby.taobao.org&lt;/a&gt; added to sources
root@yz00-Ideapad-Z460:~# gem source -l
*** CURRENT SOURCES ***&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ruby.taobao.org" rel="nofollow" target="_blank"&gt;http://ruby.taobao.org&lt;/a&gt;
root@yz00-Ideapad-Z460:~# gem install rails
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.4.gem (100%)
Successfully installed thread_safe-0.3.4
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.5.1.gem (100%)
Successfully installed minitest-5.5.1
Fetching: activesupport-4.2.0.gem (100%)
Successfully installed activesupport-4.2.0
Fetching: rack-1.6.0.gem (100%)
Successfully installed rack-1.6.0
Fetching: rack-test-0.6.3.gem (100%)
Successfully installed rack-test-0.6.3
Fetching: mini_portile-0.6.2.gem (100%)
Successfully installed mini_portile-0.6.2
Fetching: nokogiri-1.6.6.2.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.&lt;/p&gt;

&lt;p&gt;/usr/local/bin/ruby -r ./siteconf20150213-4741-m4wolb.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.&lt;/p&gt;

&lt;p&gt;Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/ruby
    --help
    --clean
    --use-system-libraries
/usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in &lt;code&gt;require': cannot load such file -- openssl (LoadError)
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in&lt;/code&gt;require'
    from /usr/local/lib/ruby/2.1.0/net/https.rb:22:in &lt;code&gt;&amp;lt;top (required)&amp;gt;'
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in&lt;/code&gt;require'
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in &lt;code&gt;require'
    from /usr/local/lib/ruby/gems/2.1.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:3:in&lt;/code&gt;'
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in &lt;code&gt;require'
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in&lt;/code&gt;rescue in require'
    from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in &lt;code&gt;require'
    from extconf.rb:395:in&lt;/code&gt;&lt;/p&gt;'&lt;p&gt;&lt;/p&gt;

&lt;p&gt;extconf failed, exit code 1&lt;/p&gt;

&lt;p&gt;Gem files will remain installed in /usr/local/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.1.0/extensions/x86-linux/2.1.0-static/nokogiri-1.6.6.2/gem_make.out&lt;/p&gt;

&lt;p&gt;安装 rails 时报错，就报这个错，大家帮忙看下，万分感谢！&lt;/p&gt;</description>
      <author>yz00</author>
      <pubDate>Fri, 13 Feb 2015 11:35:19 +0800</pubDate>
      <link>https://ruby-china.org/topics/24245</link>
      <guid>https://ruby-china.org/topics/24245</guid>
    </item>
  </channel>
</rss>
