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\$ you can omit get- and you can to use param($m,$d) instead function s($m,$d): param($m,$d)1+(New-Timespan -st (Date -day 1 -mo 1) -e (Date -day $d -mo $m)).Days. Try it online! \$\endgroup\$ Commented Jun 30, 2021 at 5:55
  • \$\begingroup\$ @mazzy - Date doesn't work on a default installation of PowerShell 5 on Windows 10. TIO uses PowerShell 6 with Linux as the substrate. \$\endgroup\$ Commented Jun 30, 2021 at 10:45
  • \$\begingroup\$ I've tested it now on Windows. It's work with PS5, PS4. see also Joey's tip \$\endgroup\$ Commented Jun 30, 2021 at 14:26
  • \$\begingroup\$ It doesn't work with mine - it tells me that The term 'date' is not recognized as the name of a cmdlet, function, script file, or operable program.. \$\endgroup\$ Commented Jun 30, 2021 at 14:29
  • 1
    \$\begingroup\$ FWIW, I never assume that any particular alias exists when I write PowerShell code. \$\endgroup\$ Commented Jun 30, 2021 at 14:36

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