in julia, given a year, report if it is a leap year. in ruby

In Julia, you can determine if a year is a leap year using the following code:

function is_leap_year(year)
    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
end

year = 2020
is_leap_year(year)  # returns true
145 chars
7 lines

In Ruby, you can check if a year is a leap year using the following code:

main.rb
def is_leap_year(year)
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
end

year = 2020
is_leap_year(year)  # returns true
138 chars
7 lines

Both implementations use the same logic to determine if a year is a leap year. The is_leap_year function checks if the year is divisible by 4 and not divisible by 100, or if it is divisible by 400. If these conditions are met, the year is considered a leap year. Otherwise, it is not a leap year.

related categories

gistlibby LogSnag