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*

Count how many months are having a full 31 days by counting knuckles

How many of you that still use your own knuckle to determine whether a month is having a full 31 days or less?

You job is to write a program to count how many months, in a month range, are having a full 31 days and how many are having less than 31 days by "counting the knuckles".

Counting days of month by knuckles

Courtesy: amsi.org.au


Input

A pair of months, the first of which doesn't have to come chronologically before the second, given in any suitable format. For instance: 201703 201902 — March 2017 to February 2019. Please describe the input format you choose. Note that the input must be able to include all years from 1 to 9999. The range of months specified includes both the starting and ending months.

Output

Two integers: the number of months in the given range with 31 days and the number of months in the range with less than 31 days.

Example: 14 10 — 14 knuckles, 10 grooves (it means that in that month range we have 14 months that have a full 31 days, and 10 months that have less than 31 days).

For an input where the second month in the range comes chronologically before the first, for example 201612 201611, you have to output a pair of zero.

Examples of input and output

| Input | Output |
|---------------|-------------|
| 201703 201902 | 14 10 |
| 201701 202008 | 26 18 |
| 000101 999912 | 69993 49995 |
| 201802 201803 | 1 1 |
| 201601 201601 | 1 0 |
| 201612 201611 | 0 0 |

Rules

  • You may choose any language you like
  • One input per line
  • This is , so shortest code in bytes wins!
  • The winner will be chosen in April 9
  • Standard loopholes apply
  • PS: this is my first question in PCG, it might have some inconsistencies. Feel free to edit and confirm what's unclear for you.

Answer*

Draft saved
Draft discarded
Cancel
5
  • 1
    \$\begingroup\$ I think you can reduce some bytes by doing n=int and also perhaps some exec tomfoolery. \$\endgroup\$ Commented Mar 30, 2017 at 7:03
  • 1
    \$\begingroup\$ I think you can do 2773&1<<r%12-1>0 instead of int('101010110101'[r%12-1]) \$\endgroup\$ Commented Mar 30, 2017 at 7:53
  • \$\begingroup\$ @Loovjo I am getting error in doing so! \$\endgroup\$ Commented Mar 30, 2017 at 8:06
  • 1
    \$\begingroup\$ using print([k,t-k]) as print(k,t-k) would produce the desired result as (k,g) thereby reducing 2 bytes! \$\endgroup\$ Commented Mar 30, 2017 at 9:12
  • 1
    \$\begingroup\$ I believe you can replace split(' ') with split() \$\endgroup\$ Commented Mar 30, 2017 at 13:40

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