[#6862] Re: http_get.rb — 青山 和光 <PXN11625@...>

In-Reply-To: [ruby-list:6844] Re: http_get.rb

15 messages 1998/03/01

[#6906] ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...>

藤本です、こんにちは。

25 messages 1998/03/03
[#6907] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/03

まつもと ゆきひろです

[#6908] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6911] Re: ruby's Icon ? — OZAWA Sakuro <ozawa@...> 1998/03/03

小澤さくです。

[#6912] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6914] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんばんは。

[#6918] manual 1.18b index — WATANABE Tetsuya <tetsu@...>

ruby-man-1.1b8 で、name タグがついているものを拾い集めて

17 messages 1998/03/04
[#6921] Re: manual 1.18b index — matz@... (Yukihiro Matsumoto) 1998/03/04

まつもと ゆきひろです

[#6954] Re: ruby's Icon ? — nosuzuki@... (Norio Suzuki)

こんばんは。鈴木教郎です。

18 messages 1998/03/04
[#6964] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/05

まつもと ゆきひろです

[#7023] infinity — Tadayoshi Funaba <tadf@...>

ふなばです。

41 messages 1998/03/09
[#7029] Re: infinity — shugo@... (Shugo Maeda) 1998/03/09

前田です。

[#7033] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/09

けいじゅ@日本ラショナルソフトウェアです.

[#7041] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803091741.CAA05774.keiju@cupmail0.rational.com>

[#7048] Re: infinity — keiju@... (Keiju ISHITSUKA) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7049] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7051] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7054] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7050] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803100359.MAA08628.keiju@cupmail0.rational.com>

[#7259] Socket#shutdown — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

16 messages 1998/03/28
[#7260] Re: Socket#shutdown — matz@... (Yukihiro Matsumoto) 1998/03/28

まつもと ゆきひろです

[#7265] Re: Socket#shutdown — keiju@... (石塚圭樹 ) 1998/03/29

けいじゅ@日本ラショナルソフトウェアです.

[ruby-list:7013] modulo

From: toyofuku@...
Date: 1998-03-08 16:57:38 UTC
List: ruby-list #7013
  豊福@パパイヤです。

  下のような剰余系のプログラムを書いて一応動くの
ですがもっとうまい方法を教えて下さい。

(1) 元の +,-,*,/ を使って *,/ を再定義しているの
  ですが、元の +,-,*,/ を alias して使っているので
  例えば x * b - y * a を x.ml(b).mn(y.ml(a)) と
  書くように非常に可読性が悪くなっています。

(2) 最初は +,- も再定義していたのですが
  for i 1..100 というのではまりました。i を増加
  していくのにも再定義した + が使われるのですね。
  当り前ですが。これはしょうがないだろうな。


# 剰余系での演算
# 合成数のケースはちょっと面倒なので後まわし

$mod = 0

def modulo(n)
  $mod = n.abs
end

class Fixnum
  alias pl +
  alias mn -
  alias ml *
  alias dv /
  # def + (other); super; end
  # def - (other); super; end
  def * (other); super; end
  def / (other); super; end
  def divmod(other)
    x = self.dv(other)
    # y = self - x * other
    y = self.mn(x.ml(other))
    return x, y
  end
end

class Bignum
  alias pl +
  alias mn -
  alias ml *
  alias dv /
  # def + (other); super; end
  # def - (other); super; end
  def * (other); super; end
  def / (other); super; end
  def divmod(other)
    x = self.dv(other)
    # y = self - x * other
    y = self.mn(x.ml(other))
    return x, y
  end
end

class Integer
  def mod
    if ($mod == 0)
      return self
    else
      void, x = self.divmod($mod)
      x = x.pl($mod) if (x < 0)
      return x
    end
  end

  def inv
    x = self
    y = $mod
    klist = []
    void, a = x.divmod(y)
    a = a.pl(y) if (a < 0)
    b = y
    while b != 0
      k, a = a.divmod(b)
      klist.push(k)
      a, b = b, a
    end
    klist.pop

    a, b = 1, 0
    while (k = klist.pop) do
      # a, b = k * a + b, a
      a, b = k.ml(a).pl(b), a
    end
    # x * b - y * a
    if (x.ml(b).mn(y.ml(a)) < 0)
      #a = y - a
      b = y.mn(b)
    end
    return b
  end

  #def +(other)
  #  self.pl(other).mod
  #end

  #def -(other)
  #  self.mn(other).mod
  #end

  def *(other)
    self.ml(other).mod
  end

  def /(other)
    if ($mod == 0)
      self.dv(other)
    else
      self.ml(other.inv).mod
    end
  end
end
---
			豊福@パパイヤ
			unbound@papaya.juice.or.jp
			toyofuku@juice.or.jp

In This Thread

Prev Next