5
\$\begingroup\$
  • Task:
    With the minimum amount of bytes, determine today's Zodiac sign using the programming language of your choice.
  • Rules:
    This is code golf, the answer with the fewest characters wins. The initialization of getting the current date into a variable (e.g. var now = new Date();) does not add to the count. Leap years must be handled correctly.
  • Limitations:
    You cannot use any other library functions for handling dates, nor predefined lists. In particular, participants would have to calculate the ordinal day of the year themselves if needed.
  • Input:
    The current date in the proleptic Gregorian calendar with numeric year, month (1–12) and day of the month (1–28…31).
  • Output:
    A single Unicode symbol indicating the current one of the twelve Zodiac signs from Western astrology, as used in horoscopes and listed below:
  1. ♈︎ Aries: March 21 – April 19
  2. ♉︎ Taurus: April 20 – May 20
  3. ♊︎ Gemini: May 21 – June 21
  4. ♋︎ Cancer: June 22 – July 22
  5. ♌︎ Leo: July 23 – August 22
  6. ♍︎ Virgo: August 23 – September 22
  7. ♎︎ Libra: September 23 – October 22
  8. ♏︎ Scorpio: October 23 – November 22
  9. ♐︎ Sagittarius: November 23 – December 21
  10. ♑︎ Capricorn: December 22 – January 19
  11. ♒︎ Aquarius: January 20 – February 18
  12. ♓︎ Pisces: February 19 – March 20

The actual dates might differ by one day depending on the year, but for this task the above date ranges are considered accurate for every year.

Example

The sign for today, 28 February 2022, is Pisces, so the correct output would be ♓︎.

Related challenges

\$\endgroup\$
5
  • 7
    \$\begingroup\$ The rule about getting the current date into a variable is an assumption about language features, which should be avoided. You should probably just stick to standard I/O rules. Also, it's currently a bit unclear what the input exactly is. Can we just take a month and a day? (Translating that into a zodiac sign is the core of the challenge anyway.) \$\endgroup\$
    – Arnauld
    Feb 28 at 14:35
  • \$\begingroup\$ To me, it sounds like the input to your code is the day, month, and year, all one-indexed; any code that gets the current date using language facilities does so only to format that date as input to the code. I do agree that it's a bit poorly explained in that regard. \$\endgroup\$
    – nununoisy
    Feb 28 at 14:49
  • 1
    \$\begingroup\$ I did not want to give languages that have a global now object or something like that an advantage, so if your language does not have something like that, you can still assume that there is a variable that has this information. You are right that this boils down to: you have a month number and a day number. \$\endgroup\$
    – Crissov
    Feb 28 at 14:49
  • 5
    \$\begingroup\$ Possible duplicate \$\endgroup\$ Feb 28 at 17:27
  • \$\begingroup\$ Thanks @DigitalTrauma I assume there would be a challenge like this but did not find the one you are linking to. However, with symbol output I expect slightly different results. \$\endgroup\$
    – Crissov
    Feb 28 at 18:13

4 Answers 4

5
\$\begingroup\$

JavaScript (Node.js),  64  62 bytes

Expects (month)(day).

This version builds the UTF-8 encoding of the code point (from 0xE2 0x99 0x88 for Aries to 0xE2 0x99 0x93 for Pisces).

m=>d=>Buffer([226,153,136+(m+=9^d<24+~"1342321"[m%12])%12])+''

Try it online!

ES6, 63 bytes

Using the more straightforward String.fromCharCode() with a direct code point is one byte longer.

m=>d=>String.fromCharCode(9800+(m+=9^d<24+~"1342321"[m%12])%12)

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ what does Buffer do? \$\endgroup\$
    – DialFrost
    Mar 1 at 1:19
  • \$\begingroup\$ Buffers are related to strings. \$\endgroup\$
    – Someone
    Mar 1 at 1:24
  • 2
    \$\begingroup\$ @DialFrost Buffer is a Node thing. And what really should be used here is Buffer.from(array), followed by .toString('utf8'). \$\endgroup\$
    – Arnauld
    Mar 1 at 1:25
  • \$\begingroup\$ I like how you used standard programming language and didn’t need many more bytes than others with golfing languages. \$\endgroup\$
    – Crissov
    Mar 17 at 11:58
2
\$\begingroup\$

Jelly, 27 bytes

“£f{ẋ’b5⁸ị+19>_@⁸_3%12+⁽#1Ọ

A dyadic Link accepting an integer, month, on the left and an integer, day, on the right that yields a character.

Try it online! Or see a whole year.

How?

“£f{ẋ’b5⁸ị+19>_@⁸_3%12+⁽#1Ọ - Link: M; D
“£f{ẋ’                      - 53343748
      b5                    - to base five -> [1, 0, 2, 1, 2, 3, 4, 4, 4, 4, 4, 3]
        ⁸ị                  - get the item at 1-indexed index M
          +19               - add nineteen to it
             >              - is that greater than D? -> 1 or 0
              _@⁸           - subtract from M -> M-1 or M
                 _3         - subtract three (offset since characters start at March)
                   %12      - modulo twelve
                       ⁽#1  - 9800
                      +     - add
                          Ọ - cast to character
\$\endgroup\$
2
\$\begingroup\$

Retina 0.8.2, 112 bytes

T`d`k-m`1.-
T`d`l`.-
T`b-m`c-mb`.-3|[bce]-2|[df]-2[1-9]|[gm]-2[2-9]|[h-l]-2[3-9]|c-19
.(.).+
$1
T`e-mb-d`♈-♓

Try it online! Link includes test cases. Takes input in the format mm-dd. Does not output a Unicode variation selector, but the output looks fine in TIO to me. Explanation:

T`d`k-m`1.-

Change October to December to k to m, which will become Scorpio to Capricorn.

T`d`l`.-

Change January to September to b to j, which will become Aquarius to Libra.

T`b-m`c-mb`.-3|[bce]-2|[df]-2[1-9]|[gm]-2[2-9]|[h-l]-2[3-9]|c-19

Increment the encoded sign if the day is past the cutoff date for the next sign.

.(.).+
$1

Delete everything except the encoded sign.

T`e-mb-d`♈-♓

Decode to a Unicode Zodiac sign.

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 31 bytes

Nθ℅⁺⁹⁸⁰⁰﹪⁺⁸⁺θ›N⁺¹⁸I§”)⊞⌊4\`ζ”θ¹²

Try it online! Link is to verbose version of code. Takes separate month and day as inputs. Explanation:

Nθ                           First input as a number
              N              Second input as a number
             ›               Is greater than
                    ”...”    Compressed string `310212344444`
                   §         Cyclically indexed by
                         θ   Input month
                  I          Cast to integer
               ⁺             Plus
                ¹⁸           Literal integer `18`
           ⁺                 Plus
            θ                Input month
         ⁺                   Plus
          ⁸                  Literal integer `8`
        ﹪                    Modulo
                          ¹² Literal integer `12`
   ⁺                         Plus
    ⁹⁸⁰⁰                     Literal integer `9800`
  ℅                          Convert to Unicode
                             Implicitly print
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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