Some solutions for the julia path

This commit is contained in:
2025-08-04 19:44:03 +02:00
parent 5c52e8e34d
commit 8296c79f68
104 changed files with 4373 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
{
"authors": [
"andrej-makarov-skrt"
],
"contributors": [
"cmcaine",
"SaschaMann"
],
"files": {
"solution": [
"leap.jl"
],
"test": [
"runtests.jl"
],
"example": [
".meta/example.jl"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://web.archive.org/web/20240907033714/https://coderanch.com/t/718816/Leap"
}

View File

@@ -0,0 +1 @@
{"track":"julia","exercise":"leap","id":"d3610687536242a2866418473aae6ee8","url":"https://exercism.org/tracks/julia/exercises/leap","handle":"Kimawari","is_requester":true,"auto_approve":false}

34
julia/leap/HELP.md Normal file
View File

@@ -0,0 +1,34 @@
# Help
## Running the tests
To run the tests, run this command from within the exercise directory:
```bash
$ julia runtests.jl
```
## Submitting your solution
You can submit your solution using the `exercism submit leap.jl` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Julia track's documentation](https://exercism.org/docs/tracks/julia)
- The [Julia track's programming category on the forum](https://forum.exercism.org/c/programming/julia)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, we recommend that you submit your code and request mentoring :)
If you don't want to do that for whatever reason, then you can find the wider Julia community channels [here](https://julialang.org/community/).

40
julia/leap/README.md Normal file
View File

@@ -0,0 +1,40 @@
# Leap
Welcome to Leap on Exercism's Julia Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Introduction
A leap year (in the Gregorian calendar) occurs:
- In every year that is evenly divisible by 4.
- Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400.
Some examples:
- 1997 was not a leap year as it's not divisible by 4.
- 1900 was not a leap year as it's not divisible by 400.
- 2000 was a leap year!
~~~~exercism/note
For a delightful, four-minute explanation of the whole phenomenon of leap years, check out [this YouTube video](https://www.youtube.com/watch?v=xX96xng7sAE).
~~~~
## Instructions
Your task is to determine whether a given year is a leap year.
## Source
### Created by
- @andrej-makarov-skrt
### Contributed to by
- @cmcaine
- @SaschaMann
### Based on
CodeRanch Cattle Drive, Assignment 3 - https://web.archive.org/web/20240907033714/https://coderanch.com/t/718816/Leap

18
julia/leap/leap.jl Normal file
View File

@@ -0,0 +1,18 @@
"""
is_leap_year(year)
Return `true` if `year` is a leap year in the gregorian calendar.
"""
function divisible_by_4(year)
return year % 4 == 0
end
function divisible_by_100_and_400(year)
return year % 100 != 0 || year % 400 == 0
end
function is_leap_year(year)
return divisible_by_4(year) && divisible_by_100_and_400(year)
end

45
julia/leap/runtests.jl Normal file
View File

@@ -0,0 +1,45 @@
using Test
include("leap.jl")
@testset verbose = true "tests" begin
@testset "Year not divisible by 4: common year" begin
@test !is_leap_year(2015)
end
@testset "Year divisible by 2, not divisible by 4: common year" begin
@test !is_leap_year(1970)
end
@testset "Year divisible by 4, not divisible by 100: leap year" begin
@test is_leap_year(1996)
end
@testset "Year divisible by 4 and 5: leap year" begin
@test is_leap_year(1960)
end
@testset "Year divisible by 4, not divisible by 100: leap year" begin
@test is_leap_year(2016)
end
@testset "Year divisible by 100, not divisible by 400: common year" begin
@test !is_leap_year(2100)
end
@testset "Year divisible by 100 but not by 3: common year" begin
@test !is_leap_year(1900)
end
@testset "Year divisible by 400: leap year" begin
@test is_leap_year(2000)
end
@testset "Year divisible by 400 but not by 125: leap year" begin
@test is_leap_year(2400)
end
@testset "Year divisible by 200, not divisible by 400: common year" begin
@test !is_leap_year(1800)
end
end