QUICK

QUICK

YOU HAVE TEN SECONDS TO WRITE A FUNCTION IN YOUR FAVORITE PROGRAMMING LANGUAGE THAT CALCULATES THE NUMBER OF DAYS FOR ANY GIVEN MONTH (ASSUMING YEAR >= 0 IN GREGORIAN CALENDAR)

OR THIS BIRD IS GOING TO STAB YOU

Attached: 1520888289684.jpg (412x430, 24K)

Other urls found in this thread:

godbolt.org/g/JJfwBn
twitter.com/SFWRedditGifs

no

REFERENCE SOLUTION

int leapyear(int year) {
if(year % 400 == 0) {
return 1;
}

if(year % 100 == 0) {
return 0;
}

if(year % 4 == 0) {
return 1;
}

return 0;
}

int dayspermonth(int year, int month) {
if(month == 2) {
if(leapyear(year)) {
return 29;
}

return 28;
}

if(month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}

return 31;
}

Attached: 1412011173618.png (480x650, 418K)

[month goes here]

DO IT FAGGOT

Attached: a02.png (526x389, 273K)

I missed seeing these threads

If (programming skill = 1) {
Write program
}
Else learn programming

Attached: image15.jpg (452x564, 56K)

int dayspermonth(int year, int month) {
int leap = !(year % 400 && (year % 100 || year % 4));
return 30 + (month % 2) - (month == 2) * (2 - leap);
}

bump

>using in as bool
You madman

>what is C

n => 31 - ( n + !!(n+1&8))%2 - 3*!!!((n+1)%12) etc...

def days_per_month(month, year = Time.now.year)
return 29 if month == 2 && Date.gregorian_leap?(year)
[nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
end

You're hired.

Bring it. How bad could a bird stab be?

>what is stdbool.h

everyone in this thread gets 0/10

Attached: Untitled.png (806x149, 60K)

>BIRD
>not BIRB
newfags these days ffs...

Vrey effective

Given that he has no hands to hold the knife with, stabbing seems afwully inefficient for that birb and vastly inferior to just fucking pecking.
stupid birb

Not ANSI C89.

= is assignment
== is comparation

Attached: JoseArguelles-ValumVotan.png (200x300, 106K)

Human check calendar
Human find number of days on Calculator
Human report number of days on Jow Forums thread.

This month has 30 days.

From the leftPad dept:
import com.github.nscala_time.time.Imports._
val dom = org.joda.time.chrono.GregorianChronology.getInstance.dayOfMonth

def daysIn(y: Int, m: Int) = dom.getMaximumValue(new LocalDate(y,m,1))

>please report this upstream
>closed notabug

why would you use bloat if you don't have to

Attached: amakejres.png (380x377, 276K)

Not iso c11

Why the fuck are you using C89 for new code in 2018? Are you retarded?

I don't. I use node.js

def days(month, year):
while not (time.day() == 1 and time.month() == month() and time.year() == year):
time.sleep(1 day)
dayCount = 1
while time.month() == month:
time.sleep(1 day)
dayCount += 1
return dayCount

SELECT months, number_of_days
FROM months_table
WHERE months = [any_given_month];


ok guys what do I win?

Why of course.
godbolt.org/g/JJfwBn

That'll be 3 wholesome loli pictures, thank you very much.

Attached: Screenshot from 2018-04-21 02-01-36.png (1444x656, 117K)

joke's on you. I don't work with dates. I work with UNIX timestamps

calm down mr birc

What the flying fuck man.

Attached: booblevel.png (1280x720, 863K)

His programming skills is not = 1

I cant Code

> =
And so are yours.

javascript, 69 bytes

m => 30+!(1

an assignment evaluates to true. if he didn't have any skills, he has them now.

looks like you're the brainlet, after all.

(printf "OP is a faggot")

you used an array and spent 1.664 kilobits to store 24 bits of information.

the absolute state of this generation.

$now = new DateTime();
$month = $now->format('m');
$var = number;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
$now->modify('+1 day');
$month_now = $now->format('m');
if ($month == $month_now) $var++;
//repeat 31 times
echo $var;

The compiler will optimize it.

public static int GetDays(int p_year, int p_month)
{
if ( DateTime.MaxValue.Year < p_year || p_year < DateTime.MinValue.Year
|| 12 < p_month || p_month < 0)
{
Console.WriteLine(String.Format("Impossible Year/Month! Year: {0} Month:{1}", p_year, p_month));
return 0;
}

return DateTime.DaysInMonth(p_year, p_month);
}

Attached: 902.jpg (600x484, 30K)

doubtful

[X] Doubt

Attached: 1523959870994.png (300x162, 31K)

I thought Ruby was an interpreted language?

bump

BIRDMIN NO

>Hey guys, I just found this new thing called the "turnary operator"! It's pretty neat!

Attached: 1495492753619.png (1172x675, 32K)

turnary

that's a new one. I think you should contribute to this thread. you'd fit right in.

kek

God damnit. I couldn't even open a new file in 10 secs.

Attached: IMG_20180406_022757.jpg (505x512, 34K)

Oh no, I ruined my meme by misspelling "ternary". How embarrassing!

Attached: 1495590078065.gif (537x537, 1.7M)

can you please explain what the fuck you just did?

user did some code golf

I made a mistake. I forgot some leap years because I was looking at some other dunce's code ITT as reference.

put this in your javascript console
f = m => 30+!(1>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
!(1 30, april in the year 0 has 30 days.

!((m-1)%12)*2

basically the same thing, ensures that februaries evaluate to zero, negate that, and multipy it by 2. 30 - true * 2 -> 28

the rest is pretty much the same a bunch more times for leap years.

would you like to know more?

Attached: 1523815233645.jpg (255x302, 21K)

Ah I see

Attached: 1516920734815.png (644x500, 66K)

>what is dive knifing

DateTime.DaysInMonth

that was hard

if (bird.isGoingToStabMe())
bird.setTarget(originalPoster);

Nice one Sandeep!

def DaysInMonth month year
if month == 2
return year % 4 ? 29 : 28
end
month % 2 ? 31 : 30
end

>What are july and august

July is a myth.

>this nigger thinks julius and augustus were real emperors worthy of tribute

what do you think DECEMber stands for? it's the last month of the year? can you count?

testing

onions
basedboy

>leap years have 29 days and normal years have 28 days in february

don't fuck with this boi, he's clearly brilliant and you don't understand his complex logics.

Just no, just no sir.

private static readonly int[] DaysToMonth365 = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
private static readonly int[] DaysToMonth366 = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};

public static bool IsLeapYear(int year) => year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);

public static int DaysInMonth(int year, int month)
{
int[] days = IsLeapYear(year) ? DaysToMonth366 : DaysToMonth365;
return days[month] - days[month - 1];
}


From the .net reference source. I'm not sure why they did it this way.

S-S-S-SOLID

sudo npm install answerToGayQuestion -S

OP, even in the Gregorian calendar, there was never a year 0.

from datetime import date

def days(y, m):
d = date(y + 1 if m == 12 else y, m % 12 + 1, 1) - date(y, m, 1)
return d.days

>= is assignment

Depends on the language.

Not in languages where = is used for pattern matching. Maybe you should git gud

daysInMonth(month,year)
i month=2 q $s(year%4=0:29,1:28)
i month'

ES6 is objectively the superior choice here.
//Assuming Jan = 1, Feb = 2, ...
const getDaysInMonth = (year, month) =>
new Date(year, month, 0).getDate();

This nigga thinks its 2015

>tfw can't use ESNext without transpiler

Attached: 1508430311960.jpg (640x559, 42K)

Open excel spread sheet
OPEN FORMULA BOX
=DAY(EOMONTH(A2,0))
close formula box
open formula box in another cell
link that cell to the above cell
type in the month into the second cell

Attached: _38460399_westobit._11.7_jpg.jpg (238x178, 12K)

int DaysInMonth(string month, int year) {
int numberOfDay;

year %= 4;

if (year == 1 || year == 2 || year == 3) {
switch(month) {
case "JAN":
numberOfDays = 31;
break;
case "FEB":
numberOfDays = 28;
break;
case "MAR":
numberOfDays = 31;
break;
case "APR":
numberOfDays = 30;
break;
case "MAY":
numberOfDays = 31;
break;
case "JUN":
numberOfDays = 30;
break;
case "JUL":
numberOfDays = 31;
break;
case "AUG":
numberOfDays = 31;
break;
case "SEP":
numberOfDays = 30;
break;
case "OCT":
numberOfDays = 31;
break;
case "NOV":
numberOfDays = 30;
break;
case "DEC":
numberOfDays = 31;
break;
}
}
if (year == 0) {
switch(month) {
case "JAN":
numberOfDays = 31;
break;
case "FEB":
numberOfDays = 29;
break;
case "MAR":
numberOfDays = 31;
break;
case "APR":
numberOfDays = 30;
break;
case "MAY":
numberOfDays = 31;
break;
case "JUN":
numberOfDays = 30;
break;
case "JUL":
numberOfDays = 31;
break;
case "AUG":
numberOfDays = 31;
break;
case "SEP":
numberOfDays = 30;
break;
case "OCT":
numberOfDays = 31;
break;
case "NOV":
numberOfDays = 30;
break;
case "DEC":
numberOfDays = 31;
break;
}
}

return numberOfDays;
}

>implying you don't compile to js from another language

what are you, a basedlet?

[31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30][month]

import thethingyouwereaskingfor
thethingyouwereaskingfor()