-7
\$\begingroup\$

Task

When running the program must show the season according to the host computer's current time.

Rules

  • The output must be either: Spring, Winter, Summer or Autumn.

  • The capitalization does not matter.

  • The output must not contain anything else the the season names stated above.

  • A season is 3 months and january is in this case the start of spring. (Northern hemisphere)

Testcase

(program ran in January)

Output:

Spring

(program ran in April)

Output:

Summer

Scoring

This is . Shortest answer in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ Can we return one of 0, 1, 2, 3 instead of Spring, Winter, Summer, Autumn? \$\endgroup\$ – Stephen May 20 '17 at 16:59
  • 9
    \$\begingroup\$ What ranges of dates are in each season? \$\endgroup\$ – Rohan Jhunjhunwala May 20 '17 at 16:59
  • \$\begingroup\$ And in mine, spring starts from march \$\endgroup\$ – Mr. Xcoder May 20 '17 at 17:45
  • \$\begingroup\$ What if I live in the Southern Hemisphere? \$\endgroup\$ – Ian Miller May 21 '17 at 15:59
  • \$\begingroup\$ @IanMiller do you have other seasons there? for this challenge you need to output the season as in january is the start of spring december is the end of winter etc \$\endgroup\$ – Luc H May 21 '17 at 17:37
2
\$\begingroup\$

05AB1E, 25 16 bytes

“Ž¹Ž€È±–„“#žf3÷è

Explanation:

“Ž¹Ž€È±–„“        Push the string 'spring summer autumn winter'
          #       Split on spaces
           žf     Push month
             3÷   Integer divided by 3
               è  Index

Try it online!

| improve this answer | |
\$\endgroup\$
6
\$\begingroup\$

Jelly, 40 bytes

“¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢»ŒV’:3ị“ȷ14ċ⁵¶<b_þṭ»Ḳ¤

Jelly has no native date functionality, yet this program prints Spring in January, February and March; Summer in April, May and June; Autumn in July, August, and September; and Winter in October, November and December.

Try it online!

How?

“¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢»ŒV’:3ị“ȷ14ċ⁵¶<b_þṭ»Ḳ¤ - Main link: no arguments
“¡ɗNʂ:ḲO¶Z{ṅ{Ḳ®⁵⁹¢»                      - compressed string: " time.gmtime().tm_mon"
                   ŒV                    - evaluate Python code - gets the month, January=1 ... December=12 (the time module has been imported in the interpreter for the time formatting atom ŒT)
                     ’                   - decrement
                     :3                  - integer divide by three
                                       ¤ - nilad followed by link(s) as a nilad:
                         “ȷ14ċ⁵¶<b_þṭ»   - compressed string "Summer Autumn Winter Spring"
                                      Ḳ  - split on spaces
                        ị                - index into (1-based)
                                         - implicit print
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ That is stupidly clever. Take a +1. \$\endgroup\$ – caird coinheringaahing May 22 '17 at 18:32
1
\$\begingroup\$

Japt, 32 30 27 bytes

`spÎAdä>H©umØC`qd gKg z3

Try it online


Explanation

A compressed string of lowercase, separated season names delimited with d is decompressed by enclosing it in backticks. qd splits the string into an array on ds. The g method gets the element at the index of the current month (Kg) floor divided by 3 (z3).

| improve this answer | |
\$\endgroup\$

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