11
\$\begingroup\$

Objective

Given a date, spell it out in Romanized Japanese.

I/O Format

The input format is flexible. The output format is <month spelling> <day spelling>; note the space. You can freely mix cases in output. You may output trailing newline.

Mapping

Months

Month Spelling
January Ichigatsu
February Nigatsu
March Sangatsu
April Shigatsu or Yongatsu
May Gogatsu
June Rokugatsu
July Shichigatsu or Nanagatsu
August Hachigatsu
September Kugatsu or Kyuugatsu
October Juugatsu
November Juuichigatsu
December Juunigatsu

Days

Irregular ones are marked *.

Day Spelling
1st Tsuitachi*
2nd Futsuka*
3rd Mikka*
4th Yokka*
5th Itsuka*
6th Muika*
7th Nanoka*
8th Youka*
9th Kokonoka*
10th Tooka*
11th Juuichinichi
12th Juuninichi
13th Juusannichi
14th Juuyokka*
15th Juugonichi
16th Juurokunichi
17th Juunananichi
18th Juuhachinichi
19th Juukyuunichi
20th Hatsuka*
21st Nijuuichinichi
22nd Nijuuninichi
23rd Nijuusannichi
24th Nijuuyokka*
25th Nijuugonichi
26th Nijuurokunichi
27th Nijuunananichi
28th Nijuuhachinichi
29th Nijuukyuunichi
30th Sanjuunichi
31st Sanjuuichinichi

Examples

  • May 5th → Gogatsu Itsuka
  • September 29th → Kugatsu Nijuukyuunichi or Kyuugatsu Nijuukyuunichi
  • October 9th → Juugatsu Kokonoka
\$\endgroup\$
8
  • \$\begingroup\$ What does the pattern look like in the higher "regular" numbers? \$\endgroup\$
    – Someone
    Aug 29, 2023 at 15:30
  • \$\begingroup\$ @Someone Since the input is a date, there is no "higher" numbers. \$\endgroup\$ Aug 29, 2023 at 21:25
  • \$\begingroup\$ By "higher," I mean the point in the Japanese numbers where most of them are regular. \$\endgroup\$
    – Someone
    Aug 29, 2023 at 21:29
  • 2
    \$\begingroup\$ For info, I think Yongatsu Nanagatsu and Kyuugatsu are incorrect spellings. See for example for april: kotobank.jp/word/%E5%9B%9B%E6%9C%88-517316 \$\endgroup\$
    – Richard
    Aug 30, 2023 at 5:55
  • 1
    \$\begingroup\$ Similarly, I believe jyuukunichi is more common. \$\endgroup\$
    – doug
    Aug 31, 2023 at 5:41

6 Answers 6

3
\$\begingroup\$

Charcoal, 148 bytes

≔⪪”↶±UH fX>¡yüεω!Ln⎇$φL¹Kσ⎚FV” ζNθF÷θχjuu§ζθgatsu Nη¿››ηχ⁼η²⁰«F÷η²⁰§ζ÷ηχjuu¿⁼⁴﹪ηχyokka⁺§ζηnichi»«§⪪”↶±‽″÷iπλº⊗wÞαα↓✳C⍘↔ω‖σ?Hê⦃¡BUQ(U}⊞▶↔⊙” ﹪η²⁰¿⊖ηka

Try it online! Link is to verbose version of code. Outputs in lower case. Explanation:

≔⪪”...” ζ

Get a list of the base names.

Nθ

Input the month number.

F÷θχjuu

Print "juu" if it is at least 10.

§ζθgatsu 

Output the rest of the month name.

Nη

Input the day number.

¿››ηχ⁼η²⁰«

If it's greater than 10 but not 20...

F÷η²⁰§ζ÷ηχjuu

Output the tens part of the day.

¿⁼⁴﹪ηχyokka

Print "yokka" if the day ends in 4, otherwise...

⁺§ζηnichi

... print the units part of the day.

»«§⪪”...” ﹪η²⁰¿⊖ηka

Otherwise, look up the root day and append "ka" unless the day is 1.

\$\endgroup\$
3
\$\begingroup\$

Python 2, 238 bytes

Takes a month \$ m \in [1, 12] \$ and a day \$ d \in [1, 31] \$ as input, and outputs the Romaji in lowercase.

lambda m,d:m/10*'juu'+O[m%10]+'gatsu '+[O[~d%-20]+1%d*'ka',d/20*O[d/10]+'juu'+[O[d%10]+'nichi','yokka'][d%10==4]][20!=d>10]
O=',ichi,ni,san,shi,go,roku,nana,hachi,kyuu,too,kokono,you,nano,mui,itsu,yok,mik,futsu,tsuitachi,hatsu'.split(',')

Try it online!

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 236 bytes

Expects (month)(day) as integers in \$[1,12]\$ and \$[1,31]\$ respectively.

m=>d=>(a="/ichi/ni/san/shi/go/roku/nana/hachi/kyuu/futsu/mik/yok/itsu/mui/nano/you/kokono/too".split`/`,m>9?"juu":"")+a[m%10]+"gatsu "+(d<11?d-1?a[d+8]+"ka":"tsuitachi":d-20?a[d/10^d<20]+"juu"+(d%10-4?a[d%10]+"nichi":"yokka"):"hatsuka")

Try it online!

Commented

m => d =>                  // m = month, d = day
(                          //
  a = (                    // a[] is a lookup array containing:
    "/ichi/ni/.../kyuu/" + //     0-9: regular prefixes for 0 to 9
    "futsu/mik/.../too"    //   10-18: irregular prefixes for 2nd to 10th
  ).split`/`,              //
  m > 9 ? "juu" : ""       // start with "juu" if m > 9
) +                        //
a[m % 10] +                // append the regular prefix for m
"gatsu " +                 // followed by "gatsu "
(                          //
  d < 11 ?                 // if d is less than 11:
    d - 1 ?                //   if d is not equal to 1:
      a[d + 8] +           //     append the irregular prefix for d
      "ka"                 //     followed by "ka"
    :                      //   else (d = 1):
      "tsuitachi"          //     "1st" is "tsuitachi"
  :                        // else (d > 10):
    d - 20 ?               //   if d is not equal to 20:
      a[d / 10 ^ d < 20] + //     according to the tens digit of d,
                           //     append either "" or "ni" or "san"
      "juu" +              //     followed by "juu"
      (                    //     followed by:
        d % 10 - 4 ?       //       if d mod 10 is not 4:
          a[d % 10] +      //         use the regular prefix for d
          "nichi"          //         followed by "nichi"
        :                  //       else:
          "yokka"          //         use the irregular "yokka"
      )                    //
    :                      //   else (d = 20):
      "hatsuka"            //     "20th" is "hatsuka"
)                          //
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Haven't checked if it's shorter, but since mixed case is allowed, maybe something like 'IchiNiSan...'.match(/.[a-z]*/) is more compact. \$\endgroup\$ Aug 30, 2023 at 3:40
  • 1
    \$\begingroup\$ @dingledooper I considered this indeed but I wasn't sure 'mixing cases' was so loose. It would also be ugly, but I guess I can get over that... :-) \$\endgroup\$
    – Arnauld
    Aug 30, 2023 at 8:21
3
\$\begingroup\$

K (ngn/k), 273 bytes

g:m:$``ICHI`NI`SAN`SHI`GO`ROKU`SHICHI`HACHI`KU
d:($``TSUITACHI),($`FUTSU`MIK`YOK`ITSU`MUI`NANO`YOU`KOKONO`TOU`HATSU),\:$`KA
g:g,\:n:$`NICHI
g[4 7]:d[4 7]
g[7]:(-3_g[7]),"A",n
k:(-1_d),1_,/m[-1 2 3],/:\:"JYUU",/:g
k[20]:*|d
j:(,/($``JYUU),/:\:m;k)
f:"gatsu "/{(*x),_1_x}'j@'

Try it online!

I booted earlier versions. Thanks to @ngn for saving 5 bytes.

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

///, 293 bytes

/[1-/1@/
/[1/_1/
/[7/sh1/
/[4/shi/
/[9/ku/
/[//
/@/-/
/-/gatsu _/

/_1]/tsuitachi/
/_2]/futsuK/
/_3]/mikK/
/_4]/yokK/
/_5]/itsuK/
/_6]/muiK/
/_7]/nanoK/
/_8]/youK/
/_9]/kokonoK/
/_10]/tooK/
/_20]/hatsuK/

/_1/juu/
/_2/2_1/
/_3/3_1/

/4]/yokK/
/K/ka/
/]/n1/

/0//
/1/ichi/
/2/ni/
/3/san/
/5/go/
/6/roku/
/7/nana/
/8/hachi/
/9/kyuu/

Attempt This Online!

Newlines are added just for clarity and stripped before execution. Input is expected in [M-D] format and is appended at the end of the program since the language does not support any form of input.

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

Ruby, 255 235 bytes

%W() declares a space-separated array of strings, which is useful for saving bytes over a split solution. An empty string interpolation #{} is needed to make the first element an empty string.

-3 bytes by incorporating dingledooper's array scheme for storing the special day cases.

->m,d{n=%W(#{} ichi ni san yon go roku nana hachi kyuu too kokono you nano mui itsu yok mik futsu tsuitachi hatsu)
'juu'*(m/10)+n[m%10]+"gatsu "+(d==20||d<11?n[~d%-20]+'ka'*(1%d):n[d/10]*(d/20)+'juu'+(d%10==4?'yokka':n[d%10]+'nichi'))}

Attempt This Online!

\$\endgroup\$

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.