# ChatGPT

---

Before I write the function, I have one clarification.

A leap year depends on which calendar’s rules you want to use. The most common is the **Gregorian calendar**, but other calendars (such as the Julian calendar) use different rules.

Should I implement the **Gregorian leap year rule**, namely:

- divisible by 4 → leap year,
- except years divisible by 100 → not a leap year,
- except years divisible by 400 → leap year again,

or do you want a different definition of “leap year”?

#### My response

Gregorian

Thanks for clarifying.

Below is a Rust implementation from first principles using only integer arithmetic (`%` for modulo) and boolean logic. It uses no external crates, no dependencies, and no standard library traits beyond the language’s built-in operators.

```rust
/// Returns true if the given year is a leap year
/// according to the Gregorian calendar.
///
/// Rules:
/// - Every year divisible by 4 is a leap year.
/// - Except years divisible by 100 are not leap years.
/// - Except years divisible by 400 are leap years.
fn is_leap_year(year: u32) -> bool {
    if year % 400 == 0 {
        true
    } else if year % 100 == 0 {
        false
    } else if year % 4 == 0 {
        true
    } else {
        false
    }
}

#[cfg(test)]
mod tests {
    use super::is_leap_year;

    #[test]
    fn test_leap_years() {
        assert_eq!(is_leap_year(1), false);
        assert_eq!(is_leap_year(4), true);
        assert_eq!(is_leap_year(2023), false);
        assert_eq!(is_leap_year(2024), true);
        assert_eq!(is_leap_year(2025), false);
        assert_eq!(is_leap_year(2048), true);
        assert_eq!(is_leap_year(1900), false);
        assert_eq!(is_leap_year(2100), false);
        assert_eq!(is_leap_year(1600), true);
        assert_eq!(is_leap_year(2000), true);
    }
}
```

### **Expected results**

| **Year** | **Leap Year?** |
| -------- | -------------- |
| 1        | ❌ False        |
| 4        | ✅ True         |
| 2023     | ❌ False        |
| 2024     | ✅ True         |
| 2025     | ❌ False        |
| 2048     | ✅ True         |
| 1900     | ❌ False        |
| 2100     | ❌ False        |
| 1600     | ✅ True         |
| 2000     | ✅ True         |

This implementation follows the Gregorian calendar rules exactly and should pass all of the included tests.

### Model Used:

- GPT-5.5
