Friday 13th or Black Friday is considered as an unlucky day. Calculate how many unlucky days are in the given year.
Can you find the number of Friday 13th in the given year? Good luck!
Input: Year as an integer.
Output: Number of Black Fridays in the year as an integer.
Examples:
unluckyDays(2015) == 3
unluckyDays(1986) == 1
Note: In Ruby years will start from 1593.
This challenge comes from user suic. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (12)
JavaScript
Live demo on CodePen
Brilliant solution, very simple and effective. Although I think
? 1 : 0
is not necessary :pYes. It's not really necessary because
true
is turn into 1, andfalse
to 0. I have a second version using that and a reducer in the demo.Javascript shorty
Javascript:
You can determine the number of Fridays in a given year as the number of days between the 13th of one and the next month is fixed. All you need to know is the day of January 13th and whether the year is a leap-year.
In one single Smalltalk line, because we can:
Perl solution, using the core library Time::Piece.
It works because grep in scalar context returns the number of trues.
Elixir:
My python sol :
//Go
package kata
import
(
"time"
)
func UnluckyDays(year int) int {
unlucky:=0
for m:=1;m<=12;m++ {
}
return unlucky
}
Python