ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Reverse Divisible Numbers (#161)
by Shane Emmons other posts by this author
May 4 2008 9:52AM messages near this date
Re: Reverse Divisible Numbers (#161) | Re: Reverse Divisible Numbers (#161)
On Sun, May 4, 2008 at 12:36 PM, Marcelo <marcelo.magallon@[...].com>  wrote:

>  On Sun, May 4, 2008 at 6:22 AM, Harry Kakueki <list.push@[...].com> wrote:
> 
>  >  ruby q161.rb 10000000000000000
>  >  84 numbers
> 
>  I've got 106 in that range:
> 
>  $ time ./reverse_divisible 10_000_000_000_000_000
>  106
> 
>  real    0m1.457s
>  user    0m1.364s
>  sys     0m0.092s
> 
>  The only reason why I don't post the solution yet is because I'm stuck
>  on a proof that the method is correct :-(
> 
>  Marcelo
> 
> 
Here's my attempt:
class Integer
  def divisible_by_reverse?
    return false unless self % 9 == 0
    return false if self % 10 == 0
    reverse = self.to_s.reverse
    return false if self.to_s.eql?(reverse)
    return self % reverse.to_i == 0
  end
end

max = ARGV[0] ? ARGV[0].to_i : 1_000_000
1.upto(max) { |n| puts n if n.divisible_by_reverse? }

-- 
Shane Emmons
E: semmons99@gmail.com
Thread:
Matthew Moss
Harry Kakueki
Matthew Moss
ThoML
Marcelo
Matthew Moss
Harry Kakueki
Ken Bloom
Ken Bloom
Sandro Paganotti
Ken Bloom
Matthew Moss
ThoML
ThoML
ThoML
Marcelo
ThoML
ThoML
Harry Kakueki
Marcelo
Marcelo
Shane Emmons
ThoML
Ken Bloom
Matthew Moss
Martin DeMello
Shane Emmons
Matthew Moss
ThoML
Marcelo
Rob Biedenharn
Robert Klemme
Robert Klemme
Matthew Moss
Shane Emmons
Matthew Moss

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved