Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 10 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 9 bytes

14Liq:)hs

Try it online!

Explanation

14L % Push [31 28 31 30 31 30 31 31 30 31 30 31]: (*)month lengths (predefined literal)
i % Input: month, m
q % Subtract 1
: % RangeInclusive range from 1 to that
) % Index into (*)the array of month lengths: gives theits first m-1 terms in (*)
h % Implicit input: day, d. Concatenate with previous array
s % Sum of array. Implicit display

MATL, 9 bytes

14Liq:)hs

Try it online!

Explanation

14L % Push [31 28 31 30 31 30 31 31 30 31 30 31] (*) (predefined literal)
i % Input: month, m
q % Subtract 1
: % Range from 1 to that
) % Index into (*): gives the first m-1 terms in (*)
h % Implicit input: day, d. Concatenate with previous array
s % Sum of array. Implicit display

MATL, 9 bytes

14Liq:)hs

Try it online!

Explanation

14L % Push [31 28 31 30 31 30 31 31 30 31 30 31]: month lengths (predefined literal)
i % Input: month, m
q % Subtract 1
: % Inclusive range from 1 to that
) % Index into the array of month lengths: gives its first m-1 terms
h % Implicit input: day, d. Concatenate with previous array
s % Sum of array. Implicit display
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 9 bytes

14Liq:)hs

Try it online!

Explanation

14L % Push [31 28 31 30 31 30 31 31 30 31 30 31] (*) (predefined literal)
i % Input: month, m
q % Subtract 1
: % Range from 1 to that
) % Index into (*): gives the first m-1 terms in (*)
h % Implicit input: day, d. Concatenate with previous array
s % Sum of array. Implicit display

AltStyle によって変換されたページ (->オリジナル) /