[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: loops and branching
From:       "Christoffer Sawicki" <christoffer.sawicki () gmail ! com>
Date:       2006-11-30 22:11:22
Message-ID: 1a991fa30611301411x84d0c73qda186fb4fe977afb () mail ! gmail ! com
[Download RAW message or body]

> if leapi%4 == 0 && (leapi%400 == 0 || leapi%100 != 0)
>         puts leapi
> else
> end
>
> while (leapi + (4 - leapi%4)) <= leapf
>         leapi = (leapi + (4 - leapi%4))
>         if leapi%4 == 0 && (leapi%400 == 0 || leapi%100 != 0)
>                 puts leapi
>         else
>         end
> end

(leapi..leapf).select do |x|
  (x % 4 == 0) && (x % 100 != 0) || (x % 400 == 0)
end

-- 
Christoffer Sawicki
http://vemod.net/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic