In the northern hemisphere (i.e. Europe, North America, etc.), the seasons are divided like this:
- Spring: March, April, May
- Summer: June, July, August
- Autumn: September, October, November
- Winter: December, January, February

In the southern hemisphere however (i.e. Australia, South America, etc.), the seasons are divided like this:
- Spring: September, October, November
- Summer: December, January, February
- Autumn: March, April, May
- Winter: June, July, August

This difference is due to the position of the sun regarding the equator, where the northern and southern hemispheres have opposite seasons.


In this challenge, we'll take two inputs:

  • One for the month (1 <= m <= 12 or 0 <= m <= 11) (examples and test cases are all 1-indexed).
  • And one for the five 'position-groups' at the latitudes of Earth (-2 <= p <= 2), where -2 is the Antarctic, -1 is the southern hemisphere excluding the Antarctic, 0 are the Tropics in proximity of the equator, 1 is the northern hemisphere excluding the Arctic, and 2 is the Arctic.
    Although the Arctic, Antarctic and Tropics of course still have seasons, for the sake of this challenge we'll say the Arctic and Antarctic are in a constant state of Winter, and the Tropics are in a constant state of Summer.

Here a visual representation of these five groups, where -2 is the Antarctic Circle; -1 between the Tropic of Capricorn and Antarctic Circle; 0 between the Tropic of Capricorn and Tropic of Cancer; 1 between the Arctic Circle and Tropic of Cancer; and -2 the Arctic Circle.

enter image description hereenter image description here Source: COSMOS - The SAO Encyclopedia of Astronomy


One of Spring, Summer, Autumn, or Winter, following these rules:

  • Is the position input 2 or -2 (Arctic or Antarctic), always output Winter.
  • Is the position input 0 (Tropics), always output Summer.
  • Is the position input 1 (northern hemisphere), output one of the four seasons based on the month input: Spring (m = [3,5]); Summer (m = [6,8]); Autumn (m = [9,11]); Winter (m = 12 or m = [1,2]).
  • Is the position input -1 (southern hemisphere), output one of the four seasons based on the month input: Spring (m = [9,11]); Summer (m = 12 or m = [1,2]); Autumn (m = [3,5]); Winter (m = [6,8]).

Challenge rules:

  • Output any four distinct values of your choice indicating Spring, Summer, Autumn, or Winter (please state what you've used in your answer).
    -15 bytes bonus if you output Spring, Summer, Autumn, or Winter as text (case-insensitive, so can be fully lowercase or fully uppercase as well, instead of the used title-case).
  • Month input can be in any reasonable format. Can be either a 0-indexed or 1-indexed integer, Date-object, Month-String, etc.
  • Position input will always be one of these possible five inputs -2, -1, 0, 1, 2.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code.
  • Also, please add an explanation if necessary.

Test cases:

Position    1-indexed Month    Output

-2          8  (August)        Winter
-2          12 (December)      Winter
-1          3  (March)         Autumn
-1          5  (May)           Autumn
-1          8  (August)        Winter
-1          12 (December)      Summer
0           1  (January)       Summer
0           7  (July)          Summer
1           1  (January)       Winter
1           4  (April)         Spring
1           7  (July)          Summer
1           12 (December)      Winter
2           2  (February)      Winter
2           9  (September)     Winter
  • \$\begingroup\$ Why can't we just use four distinct values for the seasons? \$\endgroup\$ May 14, 2018 at 12:50
  • \$\begingroup\$ I did read that rule, that's why I asked. Also, why are you afraid of "magic-integer calculations"? \$\endgroup\$ May 14, 2018 at 12:55
  • \$\begingroup\$ I don't see anything bad with seeing only calculations, they'll be most likely used for indexing anyway. It's your challenge, but I'd say this is an unnecessary complication. EDIT: about copying, well, that's not really avoidable. \$\endgroup\$ May 14, 2018 at 12:57
  • 2
    \$\begingroup\$ I don't think any bonuses are necessary, the program still does work if it just doesn't convert the output to those strings. \$\endgroup\$ May 14, 2018 at 13:06
  • 1
    \$\begingroup\$ I think that byte bonuses to offset the byte size of text is totally fine. It's not one of those "Bonus X points if you also do this other task". The challenge is centered around the seasons, so it makes sense to incentivize actually printing the seasons. \$\endgroup\$ May 14, 2018 at 15:33

4 Answers 4


Ruby, 33 27 25 bytes


Try it online!

Return values are:

0 -> winter

1 -> spring

2 -> summer

3 -> autumn


Python 2, 29 bytes

lambda p,m:[0,m+6,6,m][p]/3%4

Try it online!

A port of G B's Ruby approach, which turned out to be a few bytes shorter than my own:

32 bytes

lambda p,m:(p%2*(p+m/3+5)or p)%4

Try it online!

An anonymous function that returns the seasons as the numbers 0 to 3, where they represent Summer, Autumn, Winter and Spring in that order.

As for printing the actual season names:

63 - 15 = 48 bytes

lambda p,m:"SAWSuuipmtnrmutiemenrnrg"[(p%2*(p+m/3+5)or p)%4::4]

Try it online!

There's the combined string if anyone wants it.


C (gcc), 78 75 (-15 bonus) = 60 bytes

Using 1-based months.

Edit: Rearranged mathematical operators and reduced.


Try it online!

  • 1
    \$\begingroup\$ You can save two bytes with (++a+m/3)%4++a+m/3&3. Also, a*a is odd precisely when a is, so checking a&1 should be fine, no? \$\endgroup\$
    – lynn
    May 16, 2018 at 13:32

05AB1E, 26 - 15 = 11 bytes

Uses the approach found by G B


Try it online! or as a Test suite


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.