Chinese zodiac: Difference between revisions

Content added Content deleted
(→‎{{header|Excel}}: Added a draft for Excel LAMBDA)
Line 1,199: Line 1,199:
1985 is the year of the Wood Ox (yin). 乙丑
1985 is the year of the Wood Ox (yin). 乙丑
2017 is the year of the Fire Rooster (yin). 丁酉</pre>
2017 is the year of the Fire Rooster (yin). 丁酉</pre>

=={{header|Excel}}==
===LAMBDA===

Binding the name to the following lambda expressions in the Name Manager of the Excel WorkBook:

(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])

{{Works with|Office 365 betas 2021}}
<lang lisp>CNZODIAC
=LAMBDA(y,
APPENDCOLS(
APPENDCOLS(
APPENDCOLS(
CNYEARNAME(y)
)(
CNYEARELEMENT(y)
)
)(
CNYEARANIMAL(y)
)
)(
CNYEARYINYANG(y)
)
)


CNYEARANIMAL
=LAMBDA(y,
LET(
shengxiao, {
"鼠","shǔ","rat";
"牛","niú","ox";
"虎","hǔ","tiger";
"兔","tù","rabbit";
"龍","lóng","dragon";
"蛇","shé","snake";
"馬","mǎ","horse";
"羊","yáng","goat";
"猴","hóu","monkey";
"鸡","jī","rooster";
"狗","gǒu","dog";
"豬","zhū","pig"
},
iYear, y - 4,
iBranch, 1 + MOD(iYear, 12),
TRANSPOSE(
INDEX(shengxiao, iBranch)
)
)
)


CNYEARELEMENT
=LAMBDA(y,
LET(
wuxing, {
"木","mù","wood";
"火","huǒ","fire";
"土","tǔ","earth";
"金","jīn","metal";
"水","shuǐ","water"
},
iYear, y - 4,
iStem, MOD(iYear, 10),

TRANSPOSE(
INDEX(
wuxing,
1 + QUOTIENT(
iStem,
2
)
)
)
)
)


CNYEARNAME
=LAMBDA(y,
LET(
tiangan, {
"甲","jiă";
"乙","yĭ";
"丙","bĭng";
"丁","dīng";
"戊","wù";
"己","jĭ";
"庚","gēng";
"辛","xīn";
"壬","rén";
"癸","gŭi"
},
dizhi, {
"子","zĭ";
"丑","chŏu";
"寅","yín";
"卯","măo";
"辰","chén";
"巳","sì";
"午","wŭ";
"未","wèi";
"申","shēn";
"酉","yŏu";
"戌","xū";
"亥","hài"
},

iYear, y - 4,
iStem, 1 + MOD(iYear, 10),
iBranch, 1 + MOD(iYear, 12),
iIndex, 1 + MOD(iYear, 60),
stem, INDEX(tiangan, iStem),
branch, INDEX(dizhi, iBranch),
APPENDROWS(
APPENDROWS(
CONCAT(INDEX(stem, 1), INDEX(branch, 1))
)(
CONCAT(INDEX(stem, 2), INDEX(branch, 2))
)
)(iIndex & "/60")
)
)


CNYEARYINYANG
=LAMBDA(y,
LET(
yinyang, {
"阳","yáng", "bright";
"阴","yīn", "dark"
},
TRANSPOSE(
INDEX(
yinyang,
1 + MOD(y - 4, 2)
)
)
)
)</lang>

and also assuming the following generic bindings in the Name Manager for the WorkBook:

<lang lisp>APPENDCOLS
=LAMBDA(xs,
LAMBDA(ys,
LET(
nx, COLUMNS(xs),
colIndexes, SEQUENCE(1, nx + COLUMNS(ys)),
rowIndexes, SEQUENCE(MAX(ROWS(xs), ROWS(ys))),

IFERROR(
IF(nx < colIndexes,
INDEX(ys, rowIndexes, colIndexes - nx),
INDEX(xs, rowIndexes, colIndexes)
),
NA()
)
)
)
)


APPENDROWS
=LAMBDA(xs,
LAMBDA(ys,
LET(
nx, ROWS(xs),
rowIndexes, SEQUENCE(nx + ROWS(ys)),
colIndexes, SEQUENCE(
1,
MAX(COLUMNS(xs), COLUMNS(ys))
),

IFERROR(
IF(rowIndexes <= nx,
INDEX(xs, rowIndexes, colIndexes),
INDEX(ys, rowIndexes - nx, colIndexes)
),
NA()
)
)
)
)</lang>

{{Out}}
The formula in cell B2 defines a dynamic array, populating the grid '''B2:E4'''

{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="5" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=CNZODIAC(A2)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
| C
| D
| E
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="font-weight:bold" | Year
| style="font-weight:bold" | Name
| style="font-weight:bold" | Element
| style="font-weight:bold" | Animal
| style="font-weight:bold" | Yinyang
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right" | 1935
| style="background-color:#cbcefb" | 乙亥
| 木
| 豬
| 阴
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
|
| yĭhài
| mù
| zhū
| yīn
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
|
| 12/60
| wood
| pig
| dark
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| style="text-align:right" | 1938
| 戊寅
| 土
| 虎
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 6
|
| wùyín
| tǔ
| hǔ
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 7
|
| 15/60
| earth
| tiger
| bright
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 8
| style="text-align:right" | 1968
| 戊申
| 土
| 猴
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 9
|
| wùshēn
| tǔ
| hóu
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 10
|
| 45/60
| earth
| monkey
| bright
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 11
| style="text-align:right" | 1972
| 壬子
| 水
| 鼠
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 12
|
| rénzĭ
| shuǐ
| shǔ
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 13
|
| 49/60
| water
| rat
| bright
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 14
| style="text-align:right" | 1976
| 丙辰
| 火
| 龍
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 15
|
| bĭngchén
| huǒ
| lóng
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 16
|
| 53/60
| fire
| dragon
| bright
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 17
| style="text-align:right" | 1984
| 甲子
| 木
| 鼠
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 18
|
| jiăzĭ
| mù
| shǔ
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 19
|
| 1/60
| wood
| rat
| bright
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 20
| style="text-align:right" | 2017
| 丁酉
| 火
| 鸡
| 阴
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 21
|
| dīngyŏu
| huǒ
| jī
| yīn
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 22
|
| 34/60
| fire
| rooster
| dark
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 23
| style="text-align:right" | 2021
| 辛丑
| 金
| 牛
| 阴
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 24
|
| xīnchŏu
| jīn
| niú
| yīn
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 25
|
| 38/60
| metal
| ox
| dark
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 26
| style="text-align:right" | 2022
| 壬寅
| 水
| 虎
| 阳
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 27
|
| rényín
| shuǐ
| hǔ
| yáng
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 28
|
| 39/60
| water
| tiger
| bright
|}


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==