Hm... nice, Euclid is a one-liner

a, b = b, a % b while b != 0

That’s what I like about Ruby.

The Perl equivalent is, of course:

($a, $b) = ($b, $a % $b) while $b;

Is there anywhere such a collection of mathematical algorithms in Ruby?

···


“The obvious mathematical breakthrough would be development of an easy way
to factor large prime numbers.”
– Bill Gates from The Road Ahead, p265

There are some prime number generators here:

Yours,

Tom

···

-----Original Message-----
From: Rudolf Polzer [mailto:denshimeiru-sapmctacher@durchnull.ath.cx]
Sent: Tuesday, July 29, 2003 9:37 PM
To: ruby-talk ML
Subject: Hm… nice, Euclid is a one-liner

a, b = b, a % b while b != 0

That’s what I like about Ruby.

The Perl equivalent is, of course:

($a, $b) = ($b, $a % $b) while $b;

Is there anywhere such a collection of mathematical
algorithms in Ruby?


“The obvious mathematical breakthrough would be development
of an easy way
to factor large prime numbers.”
– Bill Gates from The Road Ahead, p265

a, b = b, a % b while b.nonzero?

Just to be a bit different.

-austin

···

On Wed, 30 Jul 2003 11:36:49 +0900, Rudolf Polzer wrote:

a, b = b, a % b while b != 0


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.07.30
* 09.18.05

Saluton!

  • Tom Copeland; 2003-07-30, 13:50 UTC:

There are some prime number generators here:

http://www.rubygarden.org/ruby?OneLiners

We need ROST (Ruby One Stanza Tips) - LOST (Linux One Stanza Tips)
already exists.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

How about Ruby On Three or Fewer Lines? (better acronym)

···

On Wed July 30 2003 4:28 pm, Josef ‘Jupp’ Schugt wrote:

We need ROST (Ruby One Stanza Tips) - LOST (Linux One Stanza Tips)
already exists.

ROFL :slight_smile:

···

On Thu, 31 Jul 2003 06:56:05 +0900, Ben Giddings wrote:

On Wed July 30 2003 4:28 pm, Josef ‘Jupp’ Schugt wrote:

We need ROST (Ruby One Stanza Tips) - LOST (Linux One Stanza Tips)
already exists.

How about Ruby On Three or Fewer Lines? (better acronym)


Simon Strandgaard

I still believe RubyHaiku is the best , just replace syllables with
lines and you can do quite everything in ruby :slight_smile:

···

il Thu, 31 Jul 2003 05:56:05 +0900, Ben Giddings ben@thingmagic.com ha scritto::

On Wed July 30 2003 4:28 pm, Josef ‘Jupp’ Schugt wrote:

We need ROST (Ruby One Stanza Tips) - LOST (Linux One Stanza Tips)
already exists.

How about Ruby On Three or Fewer Lines? (better acronym)

Saluton!

  • gabriele renzi; 2003-07-30, 22:59 UTC:

I still believe RubyHaiku is the best , just replace syllables with
lines and you can do quite everything in ruby :slight_smile:

17 Lines? I thought of something sig-sized.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

Scripsit ille »Josef ‘Jupp’ Schugt« jupp@gmx.de:

  • gabriele renzi; 2003-07-30, 22:59 UTC:

I still believe RubyHaiku is the best , just replace syllables with
lines and you can do quite everything in ruby :slight_smile:

17 Lines? I thought of something sig-sized.

OK, now define what a syllable is. A token (including |, ; and others)? A
keyword or identifier? A keyword or identifier’s syllable? Or even a
token’s syllable: ; = se-mi-co-lon [probably not, I don’t know English
hyphenation]? se-mi-ko-ro-n [oops, virtually no ; allowed in the first
or third line g]?

Hehe, and then there’s the possibility to choose a word for a character.
One could call * one time “splat” and one time “asterisk” depending on
which one fits :slight_smile:

But somehow there won’t be many programs left.

I’ll try…

def euclid(x, y) # def-eu-clid-x-y
x, y = y, x%y \ # x-y-is-y-x-mod-y
while y != 0; end # while-y-not-nil-end

Well, at least it CAN be pronounced to fit…

but it doesn’t have a return value :frowning:

Can anyone fix it?

Renaming the procedure to “foo” helps, but splits up too much…

def foo(x, y) x, # def-foo-x-y-x
y = y, x%y while # y-is-y-x-mod-y-while
y != 0; x; end # y-not-nil-x-end

No, I don’t like it - too obfuscated, hard to read.

And now in distichon (one hexameter, one pentameter):

déf euclídus(x, ý) x, ý = ý, x%ý while
ý != Ó; return 'x; énd; p euclídus(4, '6)

read:

déf euclídus ex whý ex whý becomes whý, ex mod whý while
whý not zeró return éx || énd pee euclídus four síx

Doesn’t follow the rules of which syllables are long and which not at all
(ex, eu are done wrong and especially inconsequently).

Conclusion: I can’t, I am untalented in that. Perhaps someone else.

···


Doch - alles, was dazu mich trieb,
Gott! war so gut! ach, war so lieb!

Okay, here’s a go at it, trying to keep line breaks as clean as possible

steps through an array

yielding only elements

with non-nil values

class Array
def filled
each do |x| # “each do x”
next unless x
yield x
end
end
end

Still flawed in that the natural idiom is “yield x if x” but it’s a
start. This is fun!

martin

···

Rudolf Polzer denshimeiru-sapmctacher@durchnull.ath.cx wrote:

OK, now define what a syllable is. A token (including |, ; and others)? A
keyword or identifier? A keyword or identifier’s syllable? Or even a
token’s syllable: ; = se-mi-co-lon [probably not, I don’t know English
hyphenation]? se-mi-ko-ro-n [oops, virtually no ; allowed in the first
or third line g]?

“Martin DeMello” martindemello@yahoo.com schrieb im Newsbeitrag
news:7IaWa.26369$LD6.211975@news0.telusplanet.net

OK, now define what a syllable is. A token (including |, ; and
others)? A
keyword or identifier? A keyword or identifier’s syllable? Or even a
token’s syllable: ; = se-mi-co-lon [probably not, I don’t know English
hyphenation]? se-mi-ko-ro-n [oops, virtually no ; allowed in the first
or third line g]?

Okay, here’s a go at it, trying to keep line breaks as clean as possible

steps through an array

yielding only elements

with non-nil values

“false” is excluded, too.

class Array
def filled
each do |x| # “each do x”
next unless x
yield x
end
end
end

Still flawed in that the natural idiom is “yield x if x” but it’s a
start. This is fun!

Robert

···

Rudolf Polzer denshimeiru-sapmctacher@durchnull.ath.cx wrote:

Poetic license (:

martin

···

Robert Klemme bob.news@gmx.net wrote:

“Martin DeMello” martindemello@yahoo.com schrieb im Newsbeitrag

steps through an array

yielding only elements

with non-nil values

“false” is excluded, too.