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

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Get the day of the year of a given date

Challenge

Given two positive integers \1ドル \le m \le 12\$ and \1ドル\le d \le 31\$, representing a month and days into the month, output the amount of days that have passed since January 1st, on a non-leap year. You can assume that the number of days passed will always be constrained by the number of days in the month (so \$m = 2, d = 31\$ will never be an input)

This is so the shortest code in bytes wins.

Examples

For example, \$m = 2, d = 11\$ represents February 11th. This is the 42nd day of the year (31 days in January + 11 days), so the output is 42.

Answer*

Draft saved
Draft discarded
Cancel
7
  • \$\begingroup\$ Looks like this still works: Try it online Though I wonder if some rational approximation with div would be shorter. \$\endgroup\$ Commented Jun 29, 2021 at 22:24
  • \$\begingroup\$ @xnor Nice idea! I found one that seems to work. \$\endgroup\$ Commented Jun 29, 2021 at 22:29
  • \$\begingroup\$ It looks like m%d=div(275*m)9-30+d-mod 2 m would work for 28. \$\endgroup\$ Commented Jun 29, 2021 at 23:10
  • \$\begingroup\$ @dingledooper Brilliant! \$\endgroup\$ Commented Jun 29, 2021 at 23:12
  • 2
    \$\begingroup\$ Isn't it usual to credit commenters like @Lynn for shortenings of the original solution? \$\endgroup\$ Commented Jun 30, 2021 at 14:06

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