in reply to Re: (Challenge) Rotateable numbers
in thread (Challenge) Rotateable numbers

No good. 33 isn't rotatable, but yours reports it as being so. (You can't strip the 347 out and compare the rest for rotatability.)

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re^3: (Challenge) Rotateable numbers
by tachyon (Chancellor) on Sep 17, 2004 at 02:47 UTC

    Given that it does not report 33 as rotatable I don't see your point. Also the digits 347 are not stripped, they are replaced with the digit 6, see the man for tr. It would not actually matter if they were stripped or replaced the original value will not be equal to the reversed value.

    sub is_rotatable{ #234567890123456789012345678901234567 $_=$_[0];y/2569347/5296/;pop==reverse } for my $i(3,33,131,141,171,25696925,101,88) { printf "%s %s rotatable\n", $i, is_rotatable( $i ) ? 'is' : 'not' } __DATA__ 3 not rotatable 33 not rotatable 131 not rotatable 141 not rotatable 171 not rotatable 25696925 is rotatable 101 is rotatable 88 is rotatable

    cheers

    tachyon

      I found the problem. It had to do with the fact that your version doesn't respect $_, while mine does.
      sub r2{ $_=$_[0];y/2569347/5296/;pop==reverse } my @tests = (0..9); print "$_: ",(r2($_)?'Yes':'No'), "\n" for @tests; __DATA__ 0: Yes 1: Yes 2: Yes 3: Yes 4: Yes 5: Yes 6: Yes 7: Yes 8: Yes 9: Yes

      Because of the way I was calling your function, I saw something wrong. However, I mistook what I saw wrong and I apologize for not knowing tr/// as well as I should have.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested