Skip to content

Commit b54d97f

Browse files
authored
feat(7-kyu): kata/day-of-the-year (#455)
1 parent 66b4e5b commit b54d97f

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Codewars Handbook ☕️🚀
22

33
[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook)
4-
[![Solved kata 👌](https://img.shields.io/badge/solved%20kata-1373-red.svg)](https://www.codewars.com/kata/search/java)
4+
[![Solved kata 👌](https://img.shields.io/badge/solved%20kata-1374-red.svg)](https://www.codewars.com/kata/search/java)
55
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
66
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
77
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
@@ -25,7 +25,7 @@ slug.
2525

2626
| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
2727
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
28-
| - | 1 | 2 | 22 | 40 | 413 | 555 | 205 | 58 | 76 |
28+
| - | 1 | 2 | 22 | 40 | 413 | 556 | 205 | 58 | 76 |
2929

3030
**Note:** The source code is written in Java 17 and may use language features that are incompatible
3131
with Java 8, 11.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [Day of the Year](https://www.codewars.com/kata/day-of-the-year "https://www.codewars.com/kata/5a1ebe0d46d843454100004c")
2+
3+
Work out what number day of the year it is.
4+
5+
```
6+
toDayOfYear([1, 1, 2000]) => 1
7+
```
8+
9+
The argument passed into the function is an array with the format `[D, M, YYYY]`,
10+
e.g. `[1, 2, 2000]` for February 1st, 2000 or `[22, 12, 1999]` for December 22nd, 1999.
11+
12+
Don't forget to check for whether it's a [leap year](https://en.wikipedia.org/wiki/Leap_year)! Three
13+
criteria must be taken into account to identify leap years:
14+
15+
- The year can be evenly divided by 4;
16+
- If the year can be evenly divided by 100, it is NOT a leap year, unless;
17+
- The year is also evenly divisible by 400. Then it is a leap year.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import static java.time.LocalDate.of;
2+
3+
interface DateToInt {
4+
static int toDayOfYear(int[] date) {
5+
return of(date[2], date[1], date[0]).getDayOfYear();
6+
}
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import org.junit.jupiter.api.Test;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
class SolutionTest {
6+
@Test
7+
void sample() {
8+
assertEquals(145, DateToInt.toDayOfYear(new int[]{25, 5, 2022}));
9+
assertEquals(137, DateToInt.toDayOfYear(new int[]{17, 5, 1991}));
10+
assertEquals(295, DateToInt.toDayOfYear(new int[]{22, 10, 1990}));
11+
assertEquals(1, DateToInt.toDayOfYear(new int[]{1, 1, 2001}));
12+
assertEquals(1, DateToInt.toDayOfYear(new int[]{1, 1, 2000}));
13+
assertEquals(365, DateToInt.toDayOfYear(new int[]{31, 12, 2003}));
14+
assertEquals(366, DateToInt.toDayOfYear(new int[]{31, 12, 2004}));
15+
assertEquals(60, DateToInt.toDayOfYear(new int[]{29, 2, 2008}));
16+
}
17+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
- [Currying functions: multiply all elements in an array](currying-functions-multiply-all-elements-in-an-array)
118118
- [Cyclops numbers](cyclops-numbers)
119119
# D
120+
- [Day of the Year](day-of-the-year)
120121
- [Debug Sum of Digits of a Number](debug-sum-of-digits-of-a-number)
121122
- [Decimal decomposition](decimal-decomposition)
122123
- [Decimal Time Conversion](decimal-time-conversion)

0 commit comments

Comments
 (0)