From: Alphonse 23 Date: 2013-06-01T12:38:47+09:00 Subject: Re: Eloquent Ruby Kaprekar's Number Peter Hickman wrote in post #1110835: > Your new version is much clearer. But I will nitpick anyway :) > > midpoint = (num_len / 2) > > left = num_square[0...midpoint].to_i > right = num_square[midpoint..-1].to_i > > There is no need to do the -1 / +1 thing by using the ... range > operator. > > However the fact that it is ... rather than .. is easy to overlook when > reading code so I can understand peoples reluctance to use it. That doesn't compile for me. this does though: def kaprekar?(num) return false if num.zero? num_square = (num**2).to_s num_len = num_square.length midpoint = (num_len / 2) left = num_square[0..midpoint-1].to_i right = num_square[midpoint..-1].to_i num == left + right end -- Posted via http://www.ruby-forum.com/.