Ruby 2.0

Brian Mitchell wrote:

Is this an example of a Sierpinski Triangle?

Yes.

And we (my son and I) are struggling with writing the recursive version of it in MSWLogo (and then Ruby).

We are not quite done yet, but the basic structure is ready and needs some tweaking for the perfect alignment of the triangles.

I am working on finding more cool one liners that are short enough for a sig.

Cool ... that should keep us busy for a while :slight_smile:

-- shanko

ยทยทยท

On Mon, 6 Dec 2004 12:23:06 +0900, Lyndon Samson > <lyndon.samson@gmail.com> wrote:

Subject change: In my spare time, I've been scanning the web for the perfect simulation to do as a Ruby Quiz. I don't want to do Life like everyone else does. We can do better.

So, if you can point me to a fun simulation (well described), I'll be very grateful.

If you write it up and submit it as a Ruby Quiz, you'll be my hero.

Submit address: rubyquiz@grayproductions.net

Sorry to derail the thread. We now return you to your regularly scheduled discussion of Ruby signatures...

James Edward Gray II

ยทยทยท

On Dec 5, 2004, at 9:51 PM, Brian Mitchell wrote:

I came up with a cellular automata simulator but the input and rule
set took up too much space.

Brian Mitchell wrote:

Is this an example of a Sierpinski Triangle?

Yes.

I am working on finding more cool one liners that are short enough for a sig.

actually a four liner...

ruby -rcomplex -e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w} #{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

Regards,

   Michael

ยทยทยท

On Mon, 6 Dec 2004 12:23:06 +0900, Lyndon Samson > <lyndon.samson@gmail.com> wrote:

I'd love to see more one-liners. They're a fun way to spread the Ruby gospel :slight_smile:

Cheers.

  -- CWS

ยทยทยท

On Mon, 6 Dec 2004 12:51:01 +0900, Brian Mitchell <binary42@gmail.com> wrote:

I am working on finding more cool one liners that are short enough for a sig.

I came up with a cellular automata simulator but the input and rule
set took up too much space. So I will have to find something else....
if not I will be sticking to my triangle signature. It is always fun
to try and push the limits of a language by doing things like this.

irb,

Brian Mitchell
---
T.B.D.

Brian Mitchell wrote:

I am working on finding more cool one liners that are short enough
for a sig.

I came up with a cellular automata simulator but the input and
rule set took up too much space. So I will have to find something
else.... if not I will be sticking to my triangle signature.

You inspired me to another triangle one.

ยทยทยท

--
Oliver Cromm
ruby -e'require "Matrix";a=[1];(1..10).each{|n| print " "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}'

Running that on Cygwin, I get

display: unable to open X server `'.
-e:4:in `write': Broken pipe (Errno::EPIPE)
        from -e:4:in `print'
        from -e:4
        from -e:2:in `each'
        from -e:2
        from -e:2:in `each'
        from -e:2

Probably a platform issue, but I gotta say I'm a bit surprised.

Gavin

ยทยทยท

On Monday, December 6, 2004, 10:43:50 PM, Michael wrote:

ruby -rcomplex
-e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w}
#{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

* Lyndon Samson <lyndon.samson@gmail.com> [2004-12-06]:

Stay tuned for a mail client written in or with ruby embedded that
lets you execute your sigs :wink:

Well, maybe that's overkill. This simple script is as good... :wink:

#v+
#!/usr/bin/env ruby
# Julius Plenz <jp@cvmx.de>

@exec =
@lines =
@lines << $_.chomp while gets

@lines.reverse.each do |line|
  unless line =~ /^-- $/
    @exec << line
  else
    @exec.reverse!
    ruby = IO.popen("ruby", "w+")
    @exec.each { |s| ruby.puts s }
    ruby.puts "__END__"
    ruby.each { |o| puts o }
    ruby.close
  end
end

# vim:set ft=ruby sw=2 et:
#v-

Julius

ยทยทยท

--
Julius Plenz <jp@cvmx.de> http://www.plenz.com/

You've got a type in there. It should be require "matrix" not require "Matrix".
(Or maybe it works on a windows system, because its case insensitive?)

Regards,

Brian

ยทยทยท

On Wed, 8 Dec 2004 07:22:31 +0900 Oliver Cromm <lispamateur@internet.uqam.ca> wrote:

Oliver Cromm
ruby -e'require "Matrix";a=[1];(1..10).each{|n| print " "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}'

--
Brian Schrรถder
http://www.brian-schroeder.de/

Michael Neumann <mneumann@ntecs.de> writes:

actually a four liner...

ruby -rcomplex -e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w} #{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

Wow, this is great. :slight_smile:

Josh

Gavin Sinclair wrote:

ยทยทยท

On Monday, December 6, 2004, 10:43:50 PM, Michael wrote:

ruby -rcomplex
-e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w}
#{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

Running that on Cygwin, I get

display: unable to open X server `'.
-e:4:in `write': Broken pipe (Errno::EPIPE)
        from -e:4:in `print'
        from -e:4
        from -e:2:in `each'
        from -e:2
        from -e:2:in `each'
        from -e:2

Probably a platform issue, but I gotta say I'm a bit surprised.

Probably due to 'display'. The ruby code generates a .pnm image, which is then displayed using 'display' (ImageMagick).

Regards,

   Michael

Brian Schrรถder wrote:

ยทยทยท

Oliver Cromm <lispamateur@internet.uqam.ca> wrote:

ruby -e'require "Matrix";a=[1];(1..10).each{|n| print " "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}'

You've got a type in there. It should be require "matrix" not
require "Matrix". (Or maybe it works on a windows system, because
its case insensitive?)

Yes, it works on Windows, but I changed it for future use. Thanks.
--
ruby -e'require "matrix";a=[1];(1..10).each{|n| print " "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}'

But the code doesn't require rmagick, does it?

Gavin

ยทยทยท

On Tuesday, December 7, 2004, 12:15:42 AM, Michael wrote:

Gavin Sinclair wrote:

On Monday, December 6, 2004, 10:43:50 PM, Michael wrote:

ruby -rcomplex
-e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w}
#{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

Running that on Cygwin, I get

display: unable to open X server `'.
-e:4:in `write': Broken pipe (Errno::EPIPE)
        from -e:4:in `print'
        from -e:4
        from -e:2:in `each'
        from -e:2
        from -e:2:in `each'
        from -e:2

Probably a platform issue, but I gotta say I'm a bit surprised.

Probably due to 'display'. The ruby code generates a .pnm image, which
is then displayed using 'display' (ImageMagick).

A touch smaller:

ruby -e'require"matrix";a=[1];(1..10).each{|n|print" "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

ยทยทยท

On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote:

ruby -e'require "matrix";a=[1];(1..10).each{|n| print "
"*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}
'

Gavin Sinclair wrote:

ยทยทยท

On Tuesday, December 7, 2004, 12:15:42 AM, Michael wrote:

Gavin Sinclair wrote:

On Monday, December 6, 2004, 10:43:50 PM, Michael wrote:

ruby -rcomplex
-e'c,m,w,h=Complex(-0.75,0.136),50,200,100;puts"P6\n"+\
"#{w}
#{h}\n255";(0...h).each{|j|(0...w).each{|i|n,z=0,Complex(0.9*i/w,\
0.9*j/h);while n<=m&&(z-c).abs<=2;z=z*z+c;n+=1 end;print [20+n*10,0,\
rand*99].pack("C*")}}'|display

Running that on Cygwin, I get

display: unable to open X server `'.
-e:4:in `write': Broken pipe (Errno::EPIPE)
       from -e:4:in `print'
       from -e:4
       from -e:2:in `each'
       from -e:2
       from -e:2:in `each'
       from -e:2

Probably a platform issue, but I gotta say I'm a bit surprised.

Probably due to 'display'. The ruby code generates a .pnm image, which
is then displayed using 'display' (ImageMagick).

But the code doesn't require rmagick, does it?

no it doesn't require rmagick. it generates the pnm image itself (and this in 4 lines ;-).

The "display" command is there only to view the pnm image, oterhwise it would print the image on STDOUT.

Regards,

   Michael

Some obvious modifications:

ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d "*a.size%a;a<<0;a=(
Vector[*a]+Vector[*a.reverse]).to_a}'

There's still potential for further optimization but I prefer to zzzZZ.

ยทยทยท

On Wed, Dec 08, 2004 at 08:53:27AM +0900, trans. (T. Onoma) wrote:

On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote:
> ruby -e'require "matrix";a=[1];(1..10).each{|n| print "
> "*(10-n)*3,a.map{|i|\
> i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}
>'

A touch smaller:

ruby -e'require"matrix";a=[1];(1..10).each{|n|print" "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

--
Hassle-free packages for Ruby?
RPA is available from http://www.rubyarchive.org/

Mauricio Fernรกndez wrote:

ruby -e'require "matrix";a=[1];(1..10).each{|n| print "
"*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}
'

A touch smaller:

ruby -e'require"matrix";a=[1];(1..10).each{|n|print" "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

Some obvious modifications:

ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d "*a.size%a;a<<0;a=(
Vector[*a]+Vector[*a.reverse]).to_a}'

Optimal once you know the stuff - I'm learning!

There's still potential for further optimization but I prefer to zzzZZ.

a.size = n+1, better yet:

ruby -rmatrix -le'a=[1];1.upto(10){|n|print" "*(10-n)*3,"%3d "*n%a
a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

I found the Vector stuff /kakkou ii/, but without, it's shorter.
Accepting the extra indent, my shortest is:

ruby -le'a=;10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a
n.downto(1){|i|a[i]+=a[i-1]}}'

ยทยทยท

On Wed, Dec 08, 2004 at 08:53:27AM +0900, trans. (T. Onoma) wrote:

On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote:

--
Oliver C.

Mauricio Fernรกndez wrote:

ruby -e'require "matrix";a=[1];(1..10).each{|n| print "
"*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a}
'

A touch smaller:

ruby -e'require"matrix";a=[1];(1..10).each{|n|print" "*(10-n)*3,a.map{|i|\
i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

Some obvious modifications:

ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d "*a.size%a;a<<0;a=(
Vector[*a]+Vector[*a.reverse]).to_a}'

Obvious once you know the stuff - I'm learning!

There's still potential for further optimization but I prefer to zzzZZ.

a.size = n+1, better yet:

  ruby -rmatrix -le'a=[1];1.upto(10){|n|print" "*(10-n)*3,"%3d "*n%a
  a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

I found the Vector stuff /kakkou ii/, but without, it's shorter.
Accepting the extra indent, my shortest now is:

  ruby -le'a=;10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a
  n.downto(1){|i|a[i]+=a[i-1]}}'

ยทยทยท

On Wed, Dec 08, 2004 at 08:53:27AM +0900, trans. (T. Onoma) wrote:

On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote:

--
Oliver C.

Amazing. Is any one making a collection of these?

T.

ยทยทยท

On Wednesday 08 December 2004 12:52 am, Oliver Cromm wrote:

Mauricio Fernรกndez wrote:
> On Wed, Dec 08, 2004 at 08:53:27AM +0900, trans. (T. Onoma) wrote:
>> On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote:
>>> ruby -e'require "matrix";a=[1];(1..10).each{|n| print "
>>> "*(10-n)*3,a.map{|i|\
>>> i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).t
>>>o_a} '
>>
>> A touch smaller:
>>
>> ruby -e'require"matrix";a=[1];(1..10).each{|n|print"
>> "*(10-n)*3,a.map{|i|\
>> i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'
>
> Some obvious modifications:
>
> ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d
> "*a.size%a;a<<0;a=( Vector[*a]+Vector[*a.reverse]).to_a}'

Obvious once you know the stuff - I'm learning!

> There's still potential for further optimization but I prefer to zzzZZ.

a.size = n+1, better yet:

  ruby -rmatrix -le'a=[1];1.upto(10){|n|print" "*(10-n)*3,"%3d "*n%a
  a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

I found the Vector stuff /kakkou ii/, but without, it's shorter.
Accepting the extra indent, my shortest now is:

  ruby -le'a=;10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a
  n.downto(1){|i|a[i]+=a[i-1]}}'

> Some obvious modifications:
>
> ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d "*a.size%a;a<<0;a=(
> Vector[*a]+Vector[*a.reverse]).to_a}'

Obvious once you know the stuff - I'm learning!

> There's still potential for further optimization but I prefer to zzzZZ.

a.size = n+1, better yet:

Nice catch, we save 1 char.

  ruby -rmatrix -le'a=[1];1.upto(10){|n|print" "*(10-n)*3,"%3d "*n%a
  a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}'

I found the Vector stuff /kakkou ii/, but without, it's shorter.

Yes, that's what I had in mind.

Accepting the extra indent, my shortest now is:

  ruby -le'a=;10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a
  n.downto(1){|i|a[i]+=a[i-1]}}'

    ruby -e'a=;10.times{|n|a<<1;puts" "*(9-n)*3+"%6d"*(n+1)%a;n.
    times{|i|a[n]+=a[n-=1]}}'

It can be made to fit in a canonical 80-char line (actually 78):

a=;10.times{|n|a<<1;puts" "*(9-n)*3+"%6d"*(n+1)%a;n.times{|i|a[n]+=a[n-=1]}}

The indentation code might allow further optimization.

ยทยทยท

On Wed, Dec 08, 2004 at 02:52:35PM +0900, Oliver Cromm wrote:

--
Hassle-free packages for Ruby?
RPA is available from http://www.rubyarchive.org/

Check the thread [SOT]Signatures and one liners for more sigs. And there's a
duck one floating around, too.

Cheers,
Dave

i=1;loop{w=i&1==1?'v^':'^v';$><<"\e[2J\e[0;0H#{
' '*10}_\n #{i&1==1?' '*7+'<':'Quack! >'}(*)____,\n#{
' '*9}(` =~~/\n#{w*5}`---'#{w*4}";i+=sleep 1}

ยทยทยท

"trans. (T. Onoma)" <transami@runbox.com> wrote:

On Wednesday 08 December 2004 12:52 am, Oliver Cromm wrote:
> ruby -le'a=;10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a
> n.downto(1){|i|a[i]+=a[i-1]}}'

Amazing. Is any one making a collection of these?