Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Çë½ÌRubyµÄÒ»¸öÎÊÌâ¡£

RubyµÄÒ»¸ö¹ØÓÚÇóÊý×éµÄËùÓÐ×Ó¼¯µÄ³ÌÐò£¬
ÏÂÃæµÄforÑ­»·ÖеĶÔÏóÇø¼äÅжϣ¬»áÐÞ¸ÄjµÄÖµÂ𣿻¹ÓÐj+a..j+bµÄ¶ÔÏóÇø¼äÊÇÔõô±ä»¯µÄ£¿

ÎÒÔö¼Ó´òÓ¡¿´ÖµµÄ±ä»¯±È½ÏÆæ¹Ö¡­¡­

class Array

  def powerset
    num = 2**size
    ps = Array.new(num, [])
    self.each_index do |i|
      a = 2**i
      b = 2**(i+1) - 1
      j = 0
      while j < num-1
        for j in j+a..j+b
          ps[j] += [self[i]]
        end
        j += 1
      end
    end
    ps
  end

end

x = [1, 2, 3]
y = x.powerset
p y
j+a..j+b ÊÇÒ»¸öÇø¼ä¡£ÔÚrubyÖУ¬Èç¹ûÄãÏë´Ó1µ½10Ñ­»·
¾ÍÊÇ1..10.each
Ϊʲô»áÕâÑù£¬ÒòΪÔÚrubyÖÐËùÓÐÄÚÈݶ¼±»¿´×÷¶ÔÏó£¬ËùÒÔ³öÏÖÄã¸Ð¾õÆæ¹ÖµÄµØ·½¡£

j+a..j+bÔÚʲôʱºò¼ÆËãÄØ?ÿ´ÎjÖµµÄ±ä»¯¶¼»áÒýÆðÇø¼äµÄ¸Ä±äÂð?

Õâ¸öµØ·½±È½ÏÄÑÒÔÀí½â¡£


ÒѾ­Ã÷°×ÁË£¬¶àл£¡
´úÂëÊÇThe Ruby WayÖеÄÀý×Ó¡£

RubyÖеÄforÀàËÆµü´úÆ÷£¬ÏȼÆËãÇø¼ä±í´ïʽµÄÖµ£¬½«Çø¼äµÄÿ¸öÖµ¸³¸øÑ­»·±äÁ¿£¬ÔÙÖ´ÐÐÑ­»·Ìå¡£
ÖØÒªµÄÊÇ£ºÑ­»·±äÁ¿²»ÊÇÑ­»·µÄ¾Ö²¿±äÁ¿£¬Í˳öÑ­»·ºó£¬ÈÔÈ»ÓÐÒâÒå¡£Òò´ËÔì³ÉÁËÀý×ÓÖеÄj±äÁ¿µÄ±ä»¯¡£

¸Ð¾õRubyµÄForÑ­»·ºÍC/C++ÍêÈ«ÊÇåÄÒìµÄ¡£


Ïà¹ØÎÊ´ð£º

Ë­ÖªµÀºÃÓõÄRuby IDE£¿

Ë­ÖªµÀºÃÓõÄRuby IDE£¿


·¹ý°ï¶¥

°ï¶¥

cheng_erÄãÕâ¸öÍ·Ïñ±ÈÎҵϹ»Æ°¡.

ÓÑÇéUp£¡~

´¿¶¥

ÒýÓÃ
cheng_erÄãÕâ¸öÍ·Ïñ±ÈÎҵϹ»Æ°¡.


ÕâÄêÍ·,Ææ¹ÖµÄÊÂÇéÔõôÕâô¶àÄØÎÒ¾Í˵
......

Çë½Ì Ruby ´úÂë ת»»³É java´úÂë

Ruby ´úÂëÈçÏ£º
class Array
  def uniq_by
seen = {}
select{ |x|
  v = yield(x)
  !seen[v] && (seen[v]=true)
}
  end
end

Çója ......

rubyÖеÄorµ½µ×ÊÇʲôÒâ˼£¿

Python code:
puts true or false
puts false or true
ΪʲôÉÏÃæµÄÊä³ötrue£¬ÏÂÃæµÄÊä³öfalse£¿ÄѵÀÖ»ÈÏorÇ°ÃæµÄ£¿

¾Ý˵orºóÃæÊÇÖ±½ÓÊ¡ÂԵ쬲»ÖªµÀÊDz»ÊÇÕâÑù¡£
Â¥ÉϵĴ𰸺ÃÏñ²»ÊÇÎÒÏëÒªµÄ

rubyÉçÇøÔõ ......

rubyºÍMinGWµÄÒ»´ÎÈÚºÏ - C/C++ / C++ ÓïÑÔ

Ï£Íû¸ø´ó¼ÒÌṩһЩеÄ˼·.
ÎÒÃÇÔÚʹÓÃC±à³Ìʱ»áÓöµ½Ò»¸öÎÊÌ⣬±ÈÈçÍ·ÎļþµÄÒ»¸öº¯Êý°üº¬ÔÚÒ»¸ölib ÖУ¬µ«ÊÇ
ÔÚʵ¼ÊÁ¬½ÓÖÐÎÒÃDz»ÖªµÀËüÔÚÄĸö¿âÖС£Ò²Ðí¿ÉÐеÄÒ»ÖÖ°ì·¨ÊÇÖ±½ÓÉÏÍø²éѯij¸ö
º¯ÊýµÄÒÀÀµÌõ¼þ£¬Õâ¶Ô ......

[¹ØÓÚJavaºÍRuby]Çóǰ±²Ö¸µ¼ - Java / Web ¿ª·¢

ÎÒÏÖÔÚ²»µÃ²»ÃæÁÙÒ»¸öÑ¡Ôñ£º A£¬Ìø²Û¼ÌÐø×öJ2EE. B,תÐÍ×örailsµÄ¿ª·¢
ÔÚй«Ë¾¹¤×÷ÒѾ­°ëÄ꣬Õâ±ßµÄ·ÕΧ±È½ÏÇáËÉÓä¿ì£¬µ«ÊÇÎÒ¸ºÔðµÄÒ»¸öJavaÏîÄ¿ÒѾ­ÉÏÏߣ¬°´ÕÕpmµÄÒªÇó£¬ÈÃÎÒתÐÍ×örails¿ª·¢¡£¾ÍÎÒѧϰrailsµÄ¹ý³ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ