Skip to content

Commit

Permalink
reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
michalporeba committed Jan 10, 2024
1 parent 6e85e4f commit 5eb7841
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions exercises/practice/leap/.approaches/case/snippet.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def leap_year?(year) do
case { rem(year, 400), rem(year, 100), rem(year, 4) } do
{ 0, _, _ } -> true
{ _, 0, _ } -> false
{ _, _, 0 } -> true
{ _, _, _ } -> false
end
case { rem(year, 400), rem(year, 100), rem(year, 4) } do
{ 0, _, _ } -> true
{ _, 0, _ } -> false
{ _, _, 0 } -> true
{ _, _, _ } -> false
end
end
12 changes: 6 additions & 6 deletions exercises/practice/leap/.approaches/cond/snippet.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def leap_year?(year) do
cond do
divides?(year, 400) -> true
divides?(year, 100) -> false
divides?(year, 4) -> true
true -> false
end
cond do
divides?(year, 400) -> true
divides?(year, 100) -> false
divides?(year, 4) -> true
true -> false
end
end
7 changes: 4 additions & 3 deletions exercises/practice/leap/.approaches/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ all the numbers are non-negative, both could work, depending on the approach.

## General solution

To check if a year is divisible by `n`, we can do `rem(year, n) == 0`. We can define a function to make the intent clearer.
To check if a year is divisible by `n`, we can do `rem(year, n) == 0`.
We can define a function to make the intent clearer.

```elixir
defp divides?(number, divisor), do: rem(number, divisor) == 0
```

Any approach to the problem will perform this check three times to check if a year is equally divisible by 4, 100 and 400.
What will differ is what Elixir features we will use to combine the checks.
Any approach to the problem will perform this check three times to see if a year is equally divisible by 4, 100 and 400.
What will differ between approaches is what Elixir features we will use to combine the checks.

## Approach: Boolean Operators

Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/leap/.approaches/operators/snippet.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def leap_year?(year) do
divides?(year, 400)
or (not(divides?(year, 100)))
and divides?(year, 4)
divides?(year, 400)
or (not(divides?(year, 100)))
and divides?(year, 4)
end

0 comments on commit 5eb7841

Please sign in to comment.