[RRR] Robert's Ruby Riddle: Methodical Digits

Hi list

I was just bitten very recently by a subtlety of Ruby I had completely
forgotten about.
I thought it might be a challenge to use this subtlety in order to
make the following test (the attached file contains the same code of
course) work:

----------------------------------- 8< -----------------------------------
require 'test/unit'

user\_params = ARGV\[0\.\.1\] class RRR\_002\_Methods &lt; Test::Unit::TestCase &nbsp;&nbsp;def test\_params\_without\_digits &nbsp;&nbsp;&nbsp;&nbsp;assert /^\\D\+/ === $user_params.first, user\_params\.first &nbsp;&nbsp;&nbsp;&nbsp;assert /^\\D\+/ === $user_params.last, $user_params.last
  end

  def test_rrr002
    class << the_answer = Class::new
      def answer base=10
        42.to_s base
      end
    end
    assert_equal "42", the_answer.answer
    assert_equal "22", the_answer.answer( 20 )

rrr002.rb (914 Bytes)

···

#
    # And now a little challange :wink:
    #
    class << first_answer = Class::new( the_answer )
      def answer base = 2
        "[" << eval( $user_params.first ) << "]"
      end
    end

    class << second_answer = Class::new( the_answer )
      def answer base = 2
        "[" << eval( $user_params.last ) << "]"
      end
    end

    assert_equal "[101010]", first_answer.answer
    assert_equal "[42]", second_answer.answer
  end
end
----------------------------------- 8< -----------------------------------

As you can see digits are not allowed as parameters of the program.

Apart from the solution I would like to show, there is a completely
different one (not really very interesting but maybe a challange for
newbies), I could have blocked it easily enough by restricting the
length of the parameters but why spoil the fun ;).

Take the hint, the solution is a short one, much less than the 132
characters of the second solution.

But maybe there are even more solutions than these two.

Have fun
Robert
The following whitespace is intentional of course

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Robert Dober wrote:

Take the hint, the solution is a short one, much less than the 132
characters of the second solution.

But maybe there are even more solutions than these two.

I don't know whether that's the solution you wanted, but it's short anyway:

The following whitespace is intentional of course

ruby rrr02.rb '?*.to_s(base)' '?*.to_s'
Or if the base hadn't been set to two (or there at all):
ruby rrr02.rb '?*.to_s(?c-?a)' '?*.to_s'

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Robert Dober wrote:
> Take the hint, the solution is a short one, much less than the 132
> characters of the second solution.
>
> But maybe there are even more solutions than these two.

I don't know whether that's the solution you wanted, but it's short anyway:

> The following whitespace is intentional of course
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

ruby rrr02.rb '?*.to_s(base)' '?*.to_s'
Or if the base hadn't been set to two (or there at all):
ruby rrr02.rb '?*.to_s(?c-?a)' '?*.to_s'

Did not think of this, very clever, you can really laugh at me, look what I did:

ruby rrr02.rb '"/".succ.succ + "/".succ + "/".succ.succ + "/".succ +
"/".succ.succ + "/".succ' '"/".succ.succ.succ.succ.succ +
"/".succ.succ.succ'

However what I wanted to show is the following...
SPOILER AHEAD:

ruby rrr002.rb super 'super()'

underlining the different semantics of super and super().

Cheers
Robert
But you are aware that this is not the optimal solution, right?
The solution I was thinking about is the following:

···

On Sat, Mar 15, 2008 at 4:33 PM, Sebastian Hungerecker <sepp2k@googlemail.com> wrote:

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Robert Dober wrote:

The solution I was thinking about is the following:
> --
> Jabber: sepp2k@jabber.org
> ICQ: 205544826

Your solution was my signature?

···

--
NP: 1349 - Chasing Dragons
Jabber: sepp2k@jabber.org
ICQ: 205544826

Robert Dober wrote:
> The solution I was thinking about is the following:
> > --
> > Jabber: sepp2k@jabber.org
> > ICQ: 205544826

Your solution was my signature?

What? you did not know :wink:

I have no idea what went wrong, the messages shows fine from my side:

ruby rrr002.rb super 'super()'

Cheers
Robert

···

On Sat, Mar 15, 2008 at 7:38 PM, Sebastian Hungerecker <sepp2k@googlemail.com> wrote:

--
NP: 1349 - Chasing Dragons

Jabber: sepp2k@jabber.org
ICQ: 205544826

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

That's funny. I screw up previous writings/pastings inside a post all
the time. This happens mostly when I save as a draft previously :slight_smile:

Todd

···

On Sat, Mar 15, 2008 at 1:38 PM, Sebastian Hungerecker <sepp2k@googlemail.com> wrote:

Robert Dober wrote:
> The solution I was thinking about is the following:
> > --
> > Jabber: sepp2k@jabber.org
> > ICQ: 205544826

Your solution was my signature?

That's funny. I screw up previous writings/pastings inside a post all
the time. This happens mostly when I save as a draft previously :slight_smile:

Todd

Oh I would have no problem to admit that, as I have done before...
But this time the thread looks perfectly normal from my side, do you
see the same fragment that
Sebastian saw?

Cheers
Robert

···

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

>
> That's funny. I screw up previous writings/pastings inside a post all
> the time. This happens mostly when I save as a draft previously :slight_smile:
>
> Todd
>
>
Oh I would have no problem to admit that, as I have done before...
But this time the thread looks perfectly normal from my side, do you
see the same fragment that
Sebastian saw?

At the end of your responding post, I see...

<quote>

Cheers
Robert
But you are aware that this is not the optimal solution, right?
The solution I was thinking about is the following:

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

</quote>

Todd

···

On Sun, Mar 16, 2008 at 7:45 AM, Robert Dober <robert.dober@gmail.com> wrote:

Ok thanks; I have no such massage in the thread.
So the solution seems still unknown, here you go:

ruby rrr002.rb super 'super()'

Thx again Todd
Cheers
Robert

···

On Sun, Mar 16, 2008 at 9:55 PM, Todd Benson <caduceass@gmail.com> wrote:

On Sun, Mar 16, 2008 at 7:45 AM, Robert Dober <robert.dober@gmail.com> wrote:
> >
> > That's funny. I screw up previous writings/pastings inside a post all
> > the time. This happens mostly when I save as a draft previously :slight_smile:
> >
> > Todd
> >
> >
> Oh I would have no problem to admit that, as I have done before...
> But this time the thread looks perfectly normal from my side, do you
> see the same fragment that
> Sebastian saw?

At the end of your responding post, I see...

<quote>

Cheers
Robert
But you are aware that this is not the optimal solution, right?

The solution I was thinking about is the following:

> --
> Jabber: sepp2k@jabber.org
> ICQ: 205544826
>
>

</quote>

Todd

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

That part was there, too. It was the part after your signature that
made me think it was a cut and paste mishap. Hmm...

Todd

···

On Sun, Mar 16, 2008 at 4:47 PM, Robert Dober <robert.dober@gmail.com> wrote:

Ok thanks; I have no such massage in the thread.
So the solution seems still unknown, here you go:

ruby rrr002.rb super 'super()'

Thx again Todd

Cheers
Robert