[#11822] RCR: Input XML support in the base Ruby — Dave Thomas <Dave@...>

15 messages 2001/03/01

[#11960] Not Ruby, for me, for the moment at least — "Michael Kreuzer" <mkreuzer@... (nospam)>

I wrote on this newsgroup last weekend about how I was considering using

11 messages 2001/03/04

[#12023] French RUG ? — "Jerome" <jeromg@...>

Hi fellow rubyers,

16 messages 2001/03/05

[#12103] disassembling and reassembling a hash — raja@... (Raja S.)

Given a hash, h1, will the following always hold?

20 messages 2001/03/06

[#12204] FEATURE REQUEST: 'my' local variables — Leo Razoumov <see_signature@127.0.0.1>

Ruby is, indeed, a very well designed language.

64 messages 2001/03/07
[#12250] Re: FEATURE REQUEST: 'my' local variables — Leo Razoumov <see_signature@127.0.0.1> 2001/03/07

>>>>> "GK" == GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp> writes:

[#12284] Re: FEATURE REQUEST: 'my' local variables — gotoken@... (GOTO Kentaro) 2001/03/08

In message "[ruby-talk:12250] Re: FEATURE REQUEST: 'my' local variables"

[#12289] Re: FEATURE REQUEST: 'my' local variables — matz@... (Yukihiro Matsumoto) 2001/03/08

Hi,

[#12452] Re: FEATURE REQUEST: 'my' local variables — gotoken@... (GOTO Kentaro) 2001/03/12

In message "[ruby-talk:12289] Re: FEATURE REQUEST: 'my' local variables"

[#12553] Re: FEATURE REQUEST: 'my' local variables — Dave Thomas <Dave@...> 2001/03/13

matz@zetabits.com (Yukihiro Matsumoto) writes:

[#12329] Math package — Mathieu Bouchard <matju@...>

18 messages 2001/03/09

[#12330] Haskell goodies, RCR and challenge — Robert Feldt <feldt@...>

Hi,

19 messages 2001/03/09
[#12374] Re: Haskell goodies, RCR and challenge — matz@... (Yukihiro Matsumoto) 2001/03/10

Hi,

[#12349] Can Ruby-GTK display Gif Png or Jpeg files? — Phlip <phlip_cpp@...>

Ruby-san:

20 messages 2001/03/09

[#12444] class variables — Max Ischenko <max@...>

14 messages 2001/03/12

[#12606] Order, chaos, and change requests :) — Dave Thomas <Dave@...>

17 messages 2001/03/14

[#12635] email address regexp — "David Fung" <dfung@...>

i would like to locate probable email addresses in a bunch of text files,

12 messages 2001/03/14

[#12646] police warns you -- Perl is dangerous!! — Leo Razoumov <see_signature@127.0.0.1>

I just read this story on Slashdot

14 messages 2001/03/14
[#12651] Re: police warns you -- Perl is dangerous!! — pete@... (Pete Kernan) 2001/03/14

On 14 Mar 2001 11:46:35 -0800, Leo Razoumov <see_signature@127.0.0.1> wrote:

[#12691] Re: police warns you -- Perl is dangerous!! — "W. Kent Starr" <elderburn@...> 2001/03/15

On Wednesday 14 March 2001 15:40, Pete Kernan wrote:

[#12709] [OFFTOPIC] Re: police warns you -- Perl is dangerous!! — Stephen White <spwhite@...> 2001/03/16

On Fri, 16 Mar 2001, W. Kent Starr wrote:

[#12655] Re: FEATURE REQUEST: 'my' local variables — "Benjamin J. Tilly" <ben_tilly@...>

>===== Original Message From Leo Razoumov <see_signature@127.0.0.1> =====

18 messages 2001/03/14

[#12706] Library packaging — "Nathaniel Talbott" <ntalbott@...>

I have a project that I'm working on that needs to live two different lives,

30 messages 2001/03/16

[#12840] Looking for a decent compression scheme — Dave Thomas <Dave@...>

14 messages 2001/03/19

[#12895] differences between range and array — "Doug Edmunds" <dae_alt3@...>

This code comes from the online code examples for

16 messages 2001/03/20
[#12896] Re: differences between range and array — "Hee-Sob Park" <phasis@...> 2001/03/20

[#12899] Re: differences between range and array — Jim Freeze <jim@...> 2001/03/20

On Tue, 20 Mar 2001, Hee-Sob Park wrote:

[#12960] TextBox ListBox — Ron Jeffries <ronjeffries@...>

Attached is a little Spike that Chet and I are doing. It is a

13 messages 2001/03/20

[#12991] [ANN] Lapidary 0.2.0 — "Nathaniel Talbott" <ntalbott@...>

Well, here's my first major contribution to the Ruby world: Lapidary. It's a

16 messages 2001/03/20

[#13028] mkmf question — Luigi Ballabio <luigi.ballabio@...>

15 messages 2001/03/21

[#13185] Reading a file backwards — "Daniel Berger" <djberg96@...>

Hi all,

21 messages 2001/03/25
[#13197] Re: Reading a file backwards — "Daniel Berger" <djberg96@...> 2001/03/25

> Hi Dan,

[#13203] Re: Reading a file backwards — Mathieu Bouchard <matju@...> 2001/03/25

On Sun, 25 Mar 2001, Daniel Berger wrote:

[#13210] Re: Reading a file backwards — "Daniel Berger" <djberg96@...> 2001/03/25

"Mathieu Bouchard" <matju@sympatico.ca> wrote in message

[#13374] Passing an array to `exec'? — Lloyd Zusman <ljz@...>

I'd like to do the following:

15 messages 2001/03/31

[#13397] Multidimensional arrays and hashes? — Lloyd Zusman <ljz@...>

Is it possible in ruby to make use of constructs that correspond to

14 messages 2001/03/31

[ruby-talk:13162] Re: Examples for a presentation?

From: "rashworth" <rashworth@...>
Date: 2001-03-24 04:18:42 UTC
List: ruby-talk #13162
Hello, Here is a Ruby program and output to do simple
linear regression.

# Simultaneous Equations
print "Simultaneous Equations for", "\n"
print "x1 = Married, x2 = Number of Children", "\n"
# Define classArray for Sum and Product
class Array
  def inject(n)
    each { |value| n = yield(n, value) }
    n
  end
  def sum
    inject(0) { | n, value | n + value }
  end
  def product
    inject(1) { | n, value | n * value }
  end
  def sumsq
    inject(0) { | n, value | n + value*value }
  end
end

# Input Data
#   1  4..29

y=[37,25,37,47,47,49,53,19,19,37,26,13,53,51,37,47,45,33,38,
30,46,19,31,38,44,49,37]
sumy = 0
sumy = y.sum

x1=[1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1]   
# Married = 1
sumx1 = 0
sumx1 = x1.sum

x2=[2,3,2,5,0,4,1,0,4,0,0,0,3,0,0,3,3,2,0,2,0,3,1,0,2,0,2]  
# Number of children
sumx2 = 0
sumx2 = x2.sum

x3=[1,0,0,1,0,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0]   
# Cherry Hills Related = 1

x4=[0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]   
# ABC Intertional = 1

x5=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1]   
# Long Term Missionary = 1

sumx1sq = 0
sumx1sq = x1.sumsq
sumx2sq = 0
sumx2sq = x2.sumsq
sumx1y = 0
sumx2y = 0
sumx1x2 = 0
i = 0
(0..26).each do |i|
  sumx1y = sumx1y + (x1[i] * y[i])
  sumx2y = sumx2y + (x2[i] * y[i])
  sumx1x2 = sumx1x2 + (x1[i] * x2[i])
# i += i
end

n = y.length
print "n              = ", n
avgy = sumy / n
print "Average of y   = ", avgy
print "Sum of y       = ", sumy
print "Sum of x1      = ", sumx1
print "Sum of x2      = ", sumx2
print "Sum of x1 * x1 = ", sumx1sq
print "Sum of x2 * x2 = ", sumx2sq
print "Sum of x1 * y  = ", sumx1y
print "Sum of x2 * y  = ", sumx2y 
print "Sum of x1 * x2 = ", sumx1x2

D1 = [ n,     sumx1,   sumx2   ]
D2 = [ sumx1, sumx1sq, sumx1x2 ]
D3 = [ sumx2, sumx1x2, sumx2sq ]
D23 = ( sumx1sq * sumx2sq ) - ( sumx1x2 * sumx1x2 )
D13 = ( sumx1   * sumx2sq ) - ( sumx1x2 * sumx2 )
D12 = ( sumx1   * sumx1x2 ) - ( sumx1sq * sumx2 )
D   = (n * D23) - (sumx1 * D13) + (sumx2 * D12)

Nbo1 = [ sumy,   sumx1,   sumx2   ]
Nbo2 = [ sumx1y, sumx1sq, sumx1x2 ]
Nbo3 = [ sumx2y, sumx1x2, sumx2sq ]
Nbo23 = ( sumx1sq * sumx2sq ) - ( sumx1x2 * sumx1x2 )
Nbo13 = ( sumx1   * sumx2sq ) - ( sumx1x2 * sumx2 )
Nbo12 = ( sumx1   * sumx1x2 ) - ( sumx1sq * sumx2 )
Nbo   = (sumy * Nbo23) - (sumx1y * Nbo13 ) + ( sumx2y * Nbo12 )

Nb11 = [ n,     sumy,   sumx2   ]
Nb12 = [ sumx1, sumx1y, sumx1x2 ]
Nb13 = [ sumx2, sumx2y, sumx2sq ]
Nb123 = ( sumx1y * sumx2sq ) - ( sumx2y * sumx1x2 )
Nb113 = ( sumy * sumx2sq   ) - ( sumx2y * sumx2   )
Nb112 = ( sumy * sumx1x2   ) - ( sumx1y * sumx2   )
Nb1   = ( n * Nb123 ) - (sumx1 * Nb113 ) + ( sumx2 * Nb112 )

Nb21 = [ n,     sumx1,   sumy   ]
Nb22 = [ sumx1, sumx1sq, sumx1y ]
Nb23 = [ sumx2, sumx1x2, sumx2y ]
Nb223 = ( sumx1sq * sumx2y ) - ( sumx1x2 * sumx1y )
Nb213 = ( sumx1   * sumx2y ) - ( sumx1x2 * sumy   )
Nb212 = ( sumx1   * sumx1y ) - ( sumx1sq * sumy   )
Nb2   = ( n * Nb223 ) - (sumx1 * Nb213 ) + ( sumx2 * Nb212 )

bo   = Float(Nbo) / Float(D)
b1   = Float(Nb1) / Float(D)
b2   = Float(Nb2) / Float(D)
printf "%s %7.1f", " bo = ", bo, "\n"
printf "%s %7.1f", " b1 = ", b1, "\n"
printf "%s %7.1f", " b2 = ", b2, "\n"

# Compute Estimates for Each Missionary
y1  = bo + (b1 * x1[0]) + (b2 * x2[0])
y4  = bo + (b1 * x1[1]) + (b2 * x2[1])
y5  = bo + (b1 * x1[2]) + (b2 * x2[2])
y6  = bo + (b1 * x1[3]) + (b2 * x2[3])
y7  = bo + (b1 * x1[4]) + (b2 * x2[4])
y8  = bo + (b1 * x1[5]) + (b2 * x2[5])
y9  = bo + (b1 * x1[6]) + (b2 * x2[6])
y10 = bo + (b1 * x1[7]) + (b2 * x2[7])
y11 = bo + (b1 * x1[8]) + (b2 * x2[8])
y12 = bo + (b1 * x1[9]) + (b2 * x2[9])
y13 = bo + (b1 * x1[10]) + (b2 * x2[10])
y14 = bo + (b1 * x1[11]) + (b2 * x2[11])
y15 = bo + (b1 * x1[12]) + (b2 * x2[12])
y16 = bo + (b1 * x1[13]) + (b2 * x2[13])
y17 = bo + (b1 * x1[14]) + (b2 * x2[14])
y18 = bo + (b1 * x1[15]) + (b2 * x2[15])
y19 = bo + (b1 * x1[16]) + (b2 * x2[16])
y20 = bo + (b1 * x1[17]) + (b2 * x2[17])
y21 = bo + (b1 * x1[18]) + (b2 * x2[18])
y22 = bo + (b1 * x1[19]) + (b2 * x2[19])
y23 = bo + (b1 * x1[20]) + (b2 * x2[20])
y24 = bo + (b1 * x1[21]) + (b2 * x2[21])
y25 = bo + (b1 * x1[22]) + (b2 * x2[22])
y26 = bo + (b1 * x1[23]) + (b2 * x2[23])
y27 = bo + (b1 * x1[24]) + (b2 * x2[24])
y28 = bo + (b1 * x1[25]) + (b2 * x2[25])
y29 = bo + (b1 * x1[26]) + (b2 * x2[26])

printf "%s %7.1f", "#1  ", Float(y1), "\n"
printf "%s %7.1f", "#4  ", Float(y4), "\n"
printf "%s %7.1f", "#5  ", Float(y5), "\n"
printf "%s %7.1f", "#6  ", Float(y6), "\n"
printf "%s %7.1f", "#7  ", Float(y7), "\n"
printf "%s %7.1f", "#8  ", Float(y8), "\n"
printf "%s %7.1f", "#9  ", Float(y9), "\n"
printf "%s %7.1f", "#10 ", Float(y10), "\n"
printf "%s %7.1f", "#11 ", Float(y11), "\n"
printf "%s %7.1f", "#12 ", Float(y12), "\n"
printf "%s %7.1f", "#13 ", Float(y13), "\n"
printf "%s %7.1f", "#14 ", Float(y14), "\n"
printf "%s %7.1f", "#15 ", Float(y15), "\n"
printf "%s %7.1f", "#16 ", Float(y16), "\n"
printf "%s %7.1f", "#17 ", Float(y17), "\n"
printf "%s %7.1f", "#18 ", Float(y18), "\n"
printf "%s %7.1f", "#19 ", Float(y19), "\n"
printf "%s %7.1f", "#20 ", Float(y20), "\n"
printf "%s %7.1f", "#21 ", Float(y21), "\n"
printf "%s %7.1f", "#22 ", Float(y22), "\n"
printf "%s %7.1f", "#23 ", Float(y23), "\n"
printf "%s %7.1f", "#24 ", Float(y24), "\n"
printf "%s %7.1f", "#25 ", Float(y25), "\n"
printf "%s %7.1f", "#26 ", Float(y26), "\n"
printf "%s %7.1f", "#27 ", Float(y27), "\n"
printf "%s %7.1f", "#28 ", Float(y28), "\n"
printf "%s %7.1f", "#29 ", Float(y29), "\n"

yy=[y1,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18,y19,
y20,y21,y22,y23,y24,y25,y26,y27,y28,y29]

# Compute the Variance
print " Computation of the Variance","\n"
# The Variance, s sq = Sum (y - avgy)sq / (n - 1)

sumdif = 0
i = 0
(0..26).each do |i|
  sumdif = sumdif + (y[i]- avgy)*(y[i] - avgy)
end
printf "%s %7.1f", "sumdiff = ", sumdif
s = sumdif / (n - 1)
s = Math.sqrt(s) 
printf "%s %7.1f", "Variance = s = ", s
 
# Simultaneous Equations: x1 = Married, x2 = Number of Children

[37, 25, 37, 47, 47, 49, 53, 19, 19, 37, 26, 13, 53, 51, 37, 47, 45,
 33, 38, 30, 46, 19, 31, 38, 44, 49, 37]  0  1007
[ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  1,  1,
  1,  1,  1,  1,  1,  0,  1,  1,  1,  1]  0  23
[ 2,  3,  2,  5,  0,  4,  1,  0,  4,  0,  0,  0,
  3,  0,  0,  3,  3,  2,  0,  2,  0,  3,  1,  0, 2, 0, 2]  0  42
[ 1,  0,  0,  1,  0,  1,  0,  0,  0,  1,  0,  0, 0, 0, 1, 1, 0, 0, 0,
  0,  0,  0,  0,  0,  0,  1,  0]
[ 0,  0,  1,  0,  1,  1,  0,  0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0,
  0,  0,  0,  0,  0,  0,  0,  1]
[ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 1, 1, 0, 1, 1, 1, 1,
  1,  1,  1,  1,  1,  1,  0,  1]  0  23  0  128  0  0  0  0
0..26  27 n              =   27
       37 Average of y   =   37
          Sum of y       = 1007
          Sum of x1      =   23
          Sum of x2      =   42
          Sum of x1 * x1 =   23
          Sum of x2 * x2 =  128
          Sum of x1 * y  =  900
          Sum of x2 * y  = 1594
          Sum of x1 * x2 =   41
[27, 23,  42]
[23, 23,  41]
[42, 41, 128]  1263  1222  -23  5029
[1007,   23,  42]
[ 900,   23,  41]
[1594,   41, 128]   1263   1222   -23   135379
[  27, 1007,  42]
[  23,  900,  41]
[  42, 1594,  128]   49846   61948   3487   67492
[  27,   23, 1007]
[  23,   23,  900]
[  42,   41, 1594]  -238  -4625  -2461  -3413   
26.91966594   13.42056075   -0.6786637502
bo =     26.9
b1 =     13.4
b2 =     -0.7
38.98289918   38.30423543   38.98289918   36.94690793   40.34022669
37.62557168   39.66156293   40.34022669   37.62557168   40.34022669
26.91966594   26.91966594   38.30423543   40.34022669   26.91966594
38.30423543   38.30423543   38.98289918   40.34022669   38.98289918
40.34022669   38.30423543   26.24100219   40.34022669   38.98289918
40.34022669   38.98289918
#1      39.0  #4      38.3  #5      39.0  #6      36.9  #7      40.3
#8      37.6  #9      39.7  #10     40.3  #11     37.6  #12     40.3
#13     26.9  #14     26.9  #15     38.3  #16     40.3  #17     26.9
#18     38.3  #19     38.3  #20     39.0  #21     40.3  #22     39.0
#23     40.3  #24     38.3  #25     26.2  #26     40.3  #27     39.0
#28     40.3  #29     39.0
[38.98289918, 38.30423543, 38.98289918, 36.94690793, 40.34022669, 
 37.62557168, 39.66156293, 40.34022669, 37.62557168, 40.34022669, 
 26.91966594, 26.91966594, 38.30423543, 40.34022669, 26.91966594, 
 38.30423543, 38.30423543, 38.98289918, 40.34022669, 38.98289918, 
 40.34022669, 38.30423543, 26.24100219, 40.34022669, 38.98289918, 
 40.34022669, 38.98289918]

Computation of the Variance   0   0   0..26
sumdiff =   3406.0   131   11.44552314
Variance = s =       11.4 

---------- Original Message ----------------------------------
From: harryo@zipworld.com.au (Harry Ohlsen)
Reply-To: ruby-talk@ruby-lang.org
Date: Fri, 23 Mar 2001 21:40:03 +0900

>I may be giving a quick introduction to Ruby to a Linux user group
>over the weekend (ie, in the next 48 hours, Sydney time).
>
>Dave Thomas has kindly allowed me to use his slides, and I've been
>writing examples to go with some of them, over and above the code
>that's in the slides themselves.
>
>What I'd be interested in, if anyone can help me, would be some short
>code snippets that show off some of Ruby's features (and I'm pretty
>much a newbie, so I'm sure there are lots of things I don't know
>about).
>
>In particular, I would guess a lot of the audience will know perl, so
>examples of how to do things that perl can do and that people think
>are important features of perl would be useful, so when someone says
>"perl can do this; can ruby?" I'll be able to show them how it's done.
>
>Similarly for python I guess.
>
>Note, I'm not looking to say "Ruby's better than X because ...", just
>to be able to say "If you were to write stuff in ruby, you can still
>do the things you currently do in X".  Of course, if the Ruby version
>happens to be cleaner or more flexible in some way, so much the
>better.
>
>I'd prefer complete code snippets that I can actually run, but I'm
>happy to write some code to call anything you can provide ... so long
>as I understand how it works :-).
>
>Thanks in advance.
>
>

In This Thread

Prev Next