Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
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.
19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
require "date"
def unlucky_days(year)
unlucky = 0
1.upto(12).each do |month|
date = Date.new(year, month, 13)
unlucky += 1 if date.wday == 5
end
unlucky
end
JavaScript
Live demo on CodePen
Brilliant solution, very simple and effective. Although I think
? 1 : 0is not necessary :pYes. It's not really necessary because
trueis turn into 1, andfalseto 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:
My python sol :
Elixir:
Perl solution, using the core library Time::Piece.
It works because grep in scalar context returns the number of trues.
//Go
package kata
import
(
"time"
)
func UnluckyDays(year int) int {
unlucky:=0
for m:=1;m<=12;m++ {
}
return unlucky
}
Python