On Tue, Dec 11, 2012 at 9:50 AM, Hieu Le <[email protected]> wrote:
> This is my function:
>
>
>
> puts 'Begin year:'
> beginyear = gets.chomp
> puts 'End year:'
> endyear = gets.chomp
> puts 'The leap years between ' + beginyear + ' and ' + endyear + ':'
>
> beginyear = beginyear.to_i
> endyear = endyear.to_i
> if endyear < beginyear
>         puts 'Note: Begin year < End year'
> else
>         while (beginyear <= endyear)
>                 if
>                 (((beginyear % 4 == 0) and (beginyear %100 !=0)) or
> (beginyear % 400 == 0))
>        puts beginyear.to_s
>
>      end
>      (beginyear = beginyear.to_i + 1)
>    end
> end

Here's mine

require 'date'

puts 'Begin year:'
beginyear = Integer(gets)

puts 'End year:'
endyear = Integer(gets)

puts "Leap years between #{beginyear} and #{endyear}:"

for y in beginyear..endyear
  puts y if Date.new(y, 1, 1).leap?
end

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to