Hi Friends.
My first Code :
···
-----------------
q = 1
w = 2
while q < w
s1 = 1
puts s1
q += 1
end
-----------------
My last code :
-----------------
q = 1
w = 2
while q < w
s[q] = 1
puts s[q]
q += 1
end
-----------------
Why does not work ?
--
Posted via http://www.ruby-forum.com/.
My last code :
-----------------
q = 1
w = 2
while q < w
s[q] = 1
puts s[q]
q += 1
end
-----------------
Why does not work ?
You should be declaring s as an array: s
s =
=>
q = 1
=> 1
w = 2
=> 2
while q < w
.. s[q] = 1
.. puts s[q]
.. q += 1
.. end
1
=> nil
···
--
Posted via http://www.ruby-forum.com/\.
Michael Linfield wrote:
My last code :
-----------------
q = 1
w = 2
while q < w
s[q] = 1
puts s[q]
q += 1
end
-----------------
Why does not work ?
You should be declaring s as an array: s
s =
=>
q = 1
=> 1
w = 2
=> 2
while q < w
.. s[q] = 1
.. puts s[q]
.. q += 1
.. end
1
=> nil
Note that it would be far more idiomatic to use s.each. Never use += to
step through subscripts in Ruby.
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
thank you friends.
i want show all details array.for password brute forcer.
sample : 1 character
···
-------------
a = [1,2,3]
q1 = 0
while q1 < a.length
x = ''
x += a[q].to_s+a[q1].to_s
puts x
q1 += 1
end
-------------
sample : 2 character
-------------
a = [1,2,3]
q = 0
while q <a.length
q1 = 0
while q1 < a.length
x = ''
x += a[q].to_s+a[q1].to_s
puts x
q1 += 1
end
q += 1
end
-------------
sample : 3 character
-------------
a = [1,2,3]
z = 0
while z <a.length
q = 0
while q <a.length
q1 = 0
while q1 < a.length
x = ''
x += a[z].to_s+a[q].to_s+a[q1].to_s
puts x
q1 += 1
end
q += 1
end
z += 1
end
-------------
And ....
i want show dynamic.
sample :
------
a = [1,2,3]
start_length = 2
end_length = 3
------
11
12
13
21
22
23
31
32
33
111
112
113
.
.
.
331
332
333
.
Thank You.
--
Posted via http://www.ruby-forum.com/.
Sajjad Po wrote:
I want create a program like this.
Download ba
It'd be faster to use a compiled language to do something of that sort.
Ruby can do it, but not nearly as quick as C#/C++
···
--
Posted via http://www.ruby-forum.com/\.
Michael Linfield wrote:
Sajjad Po wrote:
I want create a program like this.
Download ba
It'd be faster to use a compiled language to do something of that sort.
Ruby can do it, but not nearly as quick as C#/C++
I wonder how big the time difference would be. It seems to me that most
of the time would be spent in stepping through arrays -- and that would
be about the same speed in Ruby and C.
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
For something small such as testing lets say a million keys, the
difference would be minimal. However, when you're brute forcing, you
generally are testing a million keys/hashes a second, and when using
algorithms that move that much data through it every second, C++ can
make all the difference in the world.
Benchmarks show the difference of milliseconds, even nanoseconds, but
those add up quick when throwing a million keys a second at them.
···
--
Posted via http://www.ruby-forum.com/.
Michael Linfield wrote:
For something small such as testing lets say a million keys, the
difference would be minimal. However, when you're brute forcing, you
generally are testing a million keys/hashes a second, and when using
algorithms that move that much data through it every second, C++ can
make all the difference in the world.
Not impressed with this explanation. Most of the stuff in a Ruby
brute-forced is already implemented in C anyway in MRI (e.g. Array), or
easily can be if the optimization proves necessary (e.g. the math).
There's really nothing to be gained from avoiding Ruby.
Benchmarks show the difference of milliseconds, even nanoseconds, but
those add up quick when throwing a million keys a second at them.
And have you done those benchmarks?
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
Not impressed with this explanation.
It wasn't supposed to be an involved explanation... there is only so
much time in the day.
And have you done those benchmarks?
N being the recursive function.
N CPU secs Time(sec)
3 0.05 468
7 0.28 484
11 3.83 724
N CPU secs Time(sec)
3 2.06 2,424
7 14.21 2,532
···
--
Posted via http://www.ruby-forum.com/\.
C++ GNU
N CPU secs Time(sec)
3 0.05 468
7 0.28 484
11 3.83 724
Ruby 1.9
N CPU secs Time(sec)
3 2.06 2,424
7 14.21 2,532
Forgot to add which one was which.
···
--
Posted via http://www.ruby-forum.com/\.
Michael Linfield wrote:
C++ GNU
N CPU secs Time(sec)
3 0.05 468
7 0.28 484
11 3.83 724
Ruby 1.9
N CPU secs Time(sec)
3 2.06 2,424
7 14.21 2,532
Forgot to add which one was which.
I am *extremely* surprised by this. What's the source code you're
using? Unless I missed something, I don't think I saw it...
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
Marnen states:
"Note that it would be far more idiomatic to use s.each. Never use +=
to step through subscripts in Ruby."
An example based on Sajjad's original code would be helpful. Thanks in
advance.
- Steve W.
···
--
Posted via http://www.ruby-forum.com/.
Steve Wilhelm wrote:
Marnen states:
"Note that it would be far more idiomatic to use s.each. Never use +=
to step through subscripts in Ruby."
An example based on Sajjad's original code would be helpful.
Then write one!
If you're not sure how, do what you can and post it
here. I'm sure I or someone else will be happy to look over it.
Thanks in
advance.
- Steve W.
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
It's a recursive function that calculates the fibonacci sequence..
If I really felt the need to impress you, then I could go type it up
again..
It's only about 7 lines of code if it's really that important to you.
Then write one!
If you're not sure how, do what you can and post it
here. I'm sure I or someone else will be happy to look over it.
If this matter is of this much importance to you, then just as you
stated yourself, go write the code and I or someone else here would be
happy to look over it.
Calculating Fibonacci isn't hard. I'm quite sure a smart guy such as
yourself can figure it out.
···
--
Posted via http://www.ruby-forum.com/\.
Marnen Laibow-Koser wrote:
Steve Wilhelm wrote:
Marnen states:
"Note that it would be far more idiomatic to use s.each. Never use +=
to step through subscripts in Ruby."
An example based on Sajjad's original code would be helpful.
Then write one!
If you're not sure how, do what you can and post it
here. I'm sure I or someone else will be happy to look over it.
Thanks in
advance.
- Steve W.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Okay, Sajjad's original code was
q = 1
w = 2
while q < w
s[q] = 1
puts s[q]
q += 1
end
It was suggested to use s.each. The problem as I see it is that Sajjad
is trying to populate the array s with ones.
I think what Sajjad wanted was:
q, w = 1, 2
s = Array.new(w - q) { 1 }
It doesn't quite do what the original code attempts, because Sajjad's
code starts at array index 1 instead of 0. I do know know if that is
what he actually intended or if it is another bug.
Is there a better way to populate an array with default values using
array's each method?
···
--
Posted via http://www.ruby-forum.com/\.
Michael Linfield wrote:
It's a recursive function that calculates the fibonacci sequence..
If I really felt the need to impress you, then I could go type it up
again..
It's only about 7 lines of code if it's really that important to you.
There's no point in posting benchmarks if you're not going to show the
code that's being benchmarked.
Then write one!
If you're not sure how, do what you can and post it
here. I'm sure I or someone else will be happy to look over it.
If this matter is of this much importance to you, then just as you
stated yourself, go write the code and I or someone else here would be
happy to look over it.
Calculating Fibonacci isn't hard. I'm quite sure a smart guy such as
yourself can figure it out.
Huh? I think you're misattributing your quotes and getting confused as
a result.
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.
That's a problem right there. Ruby has extremely slow method
invocation because of all the dispatch rules.
If you really want to compare Ruby to C when crunching numbers / doing
array operations, write an iterative solution for a fairer test.
-greg
···
On Wed, Dec 2, 2009 at 2:00 PM, Michael Linfield <globyy3000@hotmail.com> wrote:
It's a recursive function that calculates the fibonacci sequence..
Steve Wilhelm wrote:
I think what Sajjad wanted was:
q, w = 1, 2
s = Array.new(w - q) { 1 }
It doesn't quite do what the original code attempts, because Sajjad's
code starts at array index 1 instead of 0. I do know know if that is
what he actually intended or if it is another bug.
Is there a better way to populate an array with default values using
array's each method?
q, w = 1, 2
s = Array.new(w - q) { |i| i.zero? ? 0 : 1 }
How's that? ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)
Otherwise, brute-forcing like that is really just using permutations..
So how about this?
http://trevoke.net/blog/2008/12/20/lexicographic-permutations-in-ruby/
I didn't include explanations for the code, but you can check out the
other blog if you'd like. It does the permutation and runs a block for
each permutations.
···
--
Posted via http://www.ruby-forum.com/\.
Steve Wilhelm wrote:
Marnen Laibow-Koser wrote:
Steve Wilhelm wrote:
Marnen states:
"Note that it would be far more idiomatic to use s.each. Never use +=
to step through subscripts in Ruby."
An example based on Sajjad's original code would be helpful.
Then write one!
If you're not sure how, do what you can and post it
here. I'm sure I or someone else will be happy to look over it.
Thanks in
advance.
- Steve W.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Okay, Sajjad's original code was
q = 1
w = 2
while q < w
s[q] = 1
puts s[q]
q += 1
end
It was suggested to use s.each. The problem as I see it is that Sajjad
is trying to populate the array s with ones.
I think what Sajjad wanted was:
q, w = 1, 2
s = Array.new(w - q) { 1 }
I think you're probably right.
It doesn't quite do what the original code attempts, because Sajjad's
code starts at array index 1 instead of 0. I do know know if that is
what he actually intended or if it is another bug.
Is there a better way to populate an array with default values using
array's each method?
No, I made the wrong suggestion. Sorry.
Best,
···
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.