[#32185] Date#+に大きな数字を与えるとおかしな日付に — "madoka yamamoto" <yamamotomadoka@...>

こんにちは、山本と申します。

26 messages 2007/11/08
[#32186] Re: Date#+に大きな数字を与えるとおかしな日付に — Tadayoshi Funaba <tadf@...> 2007/11/08

> Dateオブジェクトに+で大きな数字を与えるとおかしくなるようです。

[#32188] Re: Date#+に大きな数字を与えるとおかしな日付に — "madoka yamamoto" <yamamotomadoka@...> 2007/11/09

山本です。

[#32191] Re: Date#+に大きな数字を与えるとおかしな日付に — tadf@... 2007/11/09

> アルゴリズムの意味がわからないで書いた、表層的なパッチなので

[#32194] Re: Date#+に大きな数字を与えるとおかしな日付に — Yukihiro Matsumoto <matz@...> 2007/11/09

Hi,

[#32200] Re: rational (Re: Date#+に大きな数字を与えるとおかしな日付に) — Tadayoshi Funaba <tadf@...> 2007/11/10

> 1.9ではRationalとComplexを組み込みに、という話はありましたが、

[#32225] Re: rational (Re: Date#+に大きな数字を与えるとおかしな日付に) — Shin-ichiro HARA <sinara@...> 2007/11/12

原です。

[#32198] [提案] Array#tail — "Yusuke ENDOH" <mame@...>

遠藤と申します。

21 messages 2007/11/09
[#32199] Re: [提案] Array#tail — Yukihiro Matsumoto <matz@...> 2007/11/10

まつもと ゆきひろです

[#32352] 1.9.1のリリース時期について — KIMURA Koichi <hogemuta@...>

木村です。

16 messages 2007/11/24
[#32353] Re: 1.9.1のリリース時期について — Yukihiro Matsumoto <matz@...> 2007/11/24

まつもと ゆきひろです

[#32403] Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — Takahiro Kambe <taca@...>

こんばんは。

32 messages 2007/11/29
[#32414] Re: Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — Urabe Shyouhei <shyouhei@...> 2007/11/30

卜部です。

[#32444] Re: Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — Yukihiro Matsumoto <matz@...> 2007/12/03

まつもと ゆきひろです

[#32488] Re: Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — Urabe Shyouhei <shyouhei@...> 2007/12/08

卜部です。

[#32525] Re: Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — "Yusuke ENDOH" <mame@...> 2007/12/10

遠藤と申します。

[#32643] Re: Next 1.8.6 patch release? (was Re: 1.9.1のリリース時期について) — "Yusuke ENDOH" <mame@...> 2007/12/19

遠藤です。

[#32409] Re: [ruby-cvs:21293] Ruby:r14056 (trunk): * signal.c (trap_signm): SIGVTALRM no longer used for green — SASADA Koichi <ko1@...>

 ささだです.

10 messages 2007/11/30

[ruby-dev:32309] default argument of Array#permutation

From: "Yusuke ENDOH" <mame@...>
Date: 2007-11-19 03:50:30 UTC
List: ruby-dev #32309
遠藤と申します。

Array#permutation はデフォルトで全要素の順列 (つまり置換) を計算すると
いいと思います。どうでしょうか。

  a = [1,2,3]
  a.permutation.to_a
    #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]


Index: array.c
===================================================================
--- array.c	(revision 13961)
+++ array.c	(working copy)
@@ -3001,11 +3001,14 @@

 /*
  *  call-seq:
+ *     ary.permutation { |p| block }          -> array
+ *     ary.permutation                        -> enumerator
  *     ary.permutation(n) { |p| block }       -> array
  *     ary.permutation(n)                     -> enumerator
  *
  * When invoked with a block, yield all permutations of length <i>n</i>
  * of the elements of <i>ary</i>, then return the array itself.
+ * If <i>n</i> is not specified, yield all permutations of all elements.
  * The implementation makes no guarantees about the order in which
  * the permutations are yielded.
  *
@@ -3013,6 +3016,7 @@
  *
  * Examples:
  *     a = [1, 2, 3]
+ *     a.permutation.to_a     #=>
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
  *     a.permutation(1).to_a  #=> [[1],[2],[3]]
  *     a.permutation(2).to_a  #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
  *     a.permutation(3).to_a  #=>
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
@@ -3021,13 +3025,15 @@
  */

 static VALUE
-rb_ary_permutation(VALUE ary, VALUE num)
+rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
 {
+    VALUE num;
     long r, n, i;

-    RETURN_ENUMERATOR(ary, 1, &num);  /* Return enumerator if no block */
-    r = NUM2LONG(num);                /* Permutation size from argument */
-    n = RARRAY_LEN(ary);              /* Array length */
+    RETURN_ENUMERATOR(ary, argc, argv);   /* Return enumerator if no block */
+    n = RARRAY_LEN(ary);                  /* Array length */
+    rb_scan_args(argc, argv, "01", &num);
+    r = NIL_P(num) ? n : NUM2LONG(num);   /* Permutation size from argument */

     if (r < 0 || n < r) {
 	/* no permutations: yield nothing */
@@ -3310,7 +3316,7 @@
     rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
     rb_define_method(rb_cArray, "choice", rb_ary_choice, 0);
     rb_define_method(rb_cArray, "cycle", rb_ary_cycle, 0);
-    rb_define_method(rb_cArray, "permutation", rb_ary_permutation, 1);
+    rb_define_method(rb_cArray, "permutation", rb_ary_permutation, -1);
     rb_define_method(rb_cArray, "combination", rb_ary_combination, 1);
     rb_define_method(rb_cArray, "product", rb_ary_product, -1);

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread

Prev Next