[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] Word Blender (#108

Daniel Finnie

1/10/2007 12:28:00 AM

If you are using *nix (unix, linux) then you can run "time <ruby
program>" at the command line. This might work with Macs as well
because they are based on unix but I don't have one so I'm not sure.

From within Ruby, you can do this:
require 'benchmark'

puts Benchmark.measure do
# program code here.
end

I agree that this was one of the best Ruby Quizzes. It is simple and
yet has different, but equally good, types of solutions (regex, sets,
etc.). I also enjoyed the opportunity to explore sets and things; more
RQs that can involve the standard library would be awesome.

Dan

Jason Mayer wrote:
> On 1/9/07, Daniel Finnie <danfinnie@optonline.net> wrote:
>>
>>
>> One thing I can see to optimize in your method is all the sorting. I
>> haven't tested the performance yet, but sets might be the answer.
>>
>> require 'set'
>>
>> class String
>> def letters
>> split(//).to_set
>> end
>> end
>>
>> baseWordSet = baseWord.letters
>> dict.select {|x| x.letters.subset?(baseWordSet)}
>>
>> It's more readable, IMHO, at least.
>>
>> Dan
>
>
> I used sets in my submission, and the letters of each 6 letter word were
> split in the above fashion so as to provide faster scanning (at least
> according to one of the books I was reading the night before - please
> correct me if I'm wrong). The answers to these questions was actually what
> I was hoping to hear when I said any feedback would be appreciated :)
>
> And yes, it's definitely more readable - I wrestled with the idea of how to
> see if one array was a subset of another (and which way was more efficient)
> when I came across the concept of a set for the first time. s2.subset?(s1)
> sure made life easy and using it made it a lot easier to understand what my
> code was doing just by reading it.
>
> One last question, which I've been thinking about but not able to
> dedicate a
> lot of time to is this: how do you 'benchmark' the speed of individual
> programs? I've been wondering how fast my program is compared to others
> since I wrote it.
>
> And finally, here's to you, Mr. Ruby Quiz creator guy, for coming up with a
> Ruby quiz that really peaked my interest :)
>

8 Answers

James Gray

1/10/2007 3:58:00 AM

0

On Jan 9, 2007, at 6:28 PM, Daniel Finnie wrote:

> If you are using *nix (unix, linux) then you can run "time <ruby
> program>" at the command line. This might work with Macs as well
> because they are based on unix but I don't have one so I'm not sure.

It works on a Mac, sure.

James Edward Gray II

James Gray

1/10/2007 3:27:00 PM

0

On Jan 9, 2007, at 6:28 PM, Daniel Finnie wrote:

> I also enjoyed the opportunity to explore sets and things; more RQs
> that can involve the standard library would be awesome.

You make the quizzes and I will run them:

suggestion@rubyquiz.com

James Edward Gray II

T. W. Urp

1/10/2007 4:24:00 PM

0

Vincent Fourmond wrote long time ago:
>"Try transposing your matrix first, if that is what you need. Are you
>dealing with transformation matrices (which are not real matrices) ?"
>Yes indeed, SVG 2D transformation matrices. These matrices are 3x3.

They never taught me about transposing, just matrix multiplication, and
googel didnt help either. What is transposing (for transformation matrices)?


Cameron McBride wrote:
>"the included Matrix library in ruby is NOT FAST. There are other libs
>that do this on the C level, such as NArray, that will allow much better
>performance for some graphical uses."

Thanks. While my simple graphic
genny isnt time-critical, and a SVG file might take 2-3 seconds to render,
I will look into NArray. Is NArray what you would recommend?

Gavin Kistner

1/10/2007 9:52:00 PM

0

T. W. Urp wrote:
> Vincent Fourmond wrote long time ago:
> >"Try transposing your matrix first, if that is what you need. Are you
> >dealing with transformation matrices (which are not real matrices) ?"
> >Yes indeed, SVG 2D transformation matrices. These matrices are 3x3.
>
> They never taught me about transposing, just matrix multiplication, and
> googel didnt help either. What is transposing (for transformation matrices)?

If you have a 3x3 matrix like:
a b c
d e f
g h i
then its transpose is:
a d g
b e h
c f i

If you have a 2x3 matrix like:
a b c
d e f
then its transpose is:
a d
b e
c f

In other words, swap rows and columns. (Excel even knows how to do
this, under Paste Special.)

Gavin Kistner

1/10/2007 9:55:00 PM

0

T. W. Urp wrote:
> They never taught me about transposing, just matrix multiplication, and
> googel didnt help either. What is transposing (for transformation matrices)?

Also, RTFM :)

C:\>ri transpose
More than one method matched your request. You can refine
your search by asking for information on one of:

Array#transpose, Matrix#transpose


C:\>ri Array.transpose
--------------------------------------------------------
Array#transpose
array.transpose -> an_array
------------------------------------------------------------------------
Assumes that _self_ is an array of arrays and transposes the rows
and columns.

a = [[1,2], [3,4], [5,6]]
a.transpose #=> [[1, 3, 5], [2, 4, 6]]


C:\>ri Matrix.transpose
-------------------------------------------------------
Matrix#transpose
transpose()
------------------------------------------------------------------------
Returns the transpose of the matrix.

Matrix[[1,2], [3,4], [5,6]]
=> 1 2
3 4
5 6
Matrix[[1,2], [3,4], [5,6]].transpose
=> 1 3 5
2 4 6


(also known as t)

David Kastrup

1/10/2007 10:05:00 PM

0

"T. W. Urp" <twu@orb.free.net> writes:

> Vincent Fourmond wrote long time ago:
>>"Try transposing your matrix first, if that is what you need. Are you
>>dealing with transformation matrices (which are not real matrices) ?"
>>Yes indeed, SVG 2D transformation matrices. These matrices are 3x3.
>
> They never taught me about transposing, just matrix multiplication,
> and googel didnt help either. What is transposing (for
> transformation matrices)?

Matthew 20:16 for the dimensions.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum

T. W. Urp

1/10/2007 11:06:00 PM

0

On Wed, 10 Jan 2007 13:54:43 -0800, Phrogz wrote:
> C:\>ri transpose
> More than one method matched your request. You can refine
> your search by asking for information on one of:
>
> Array#transpose, Matrix#transpose
> C:\>ri Array.transpose
> C:\>ri Matrix.transpose

Thats very nice. I never realized such a great help tool exists! Thank you
Phrogz!! :)

M. Edward (Ed) Borasky

1/11/2007 2:46:00 AM

0

T. W. Urp wrote:
> Vincent Fourmond wrote long time ago:
>
>> "Try transposing your matrix first, if that is what you need. Are you
>> dealing with transformation matrices (which are not real matrices) ?"
>> Yes indeed, SVG 2D transformation matrices. These matrices are 3x3.
>>
>
> They never taught me about transposing, just matrix multiplication, and
> googel didnt help either. What is transposing (for transformation matrices)?
>
Given a matrix "a" with "m" rows and "n" columns

for i = 1 to m do
for j = 1 to n do
atranspose[j, i] = a[i, j]
end
end
>
> Cameron McBride wrote:
>
>> "the included Matrix library in ruby is NOT FAST. There are other libs
>> that do this on the C level, such as NArray, that will allow much better
>> performance for some graphical uses."
>>
>
> Thanks. While my simple graphic
> genny isnt time-critical, and a SVG file might take 2-3 seconds to render,
> I will look into NArray. Is NArray what you would recommend?
>
Yes!


--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.