Chinese zodiac: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 28:
{{trans|C++}}
 
<langsyntaxhighlight lang=11l>V animals = [‘Rat’, ‘Ox’, ‘Tiger’, ‘Rabbit’, ‘Dragon’, ‘Snake’, ‘Horse’, ‘Goat’, ‘Monkey’, ‘Rooster’, ‘Dog’, ‘Pig’]
V elements = [‘Wood’, ‘Fire’, ‘Earth’, ‘Metal’, ‘Water’]
 
Line 44:
 
L(year) [1935, 1938, 1968, 1972, 1976, 2017]
print(year‘ is the year of the ’getElement(year)‘ ’getAnimal(year)‘ (’getYY(year)‘).’)</langsyntaxhighlight>
 
{{out}}
Line 58:
=={{header|360 Assembly}}==
{{trans|VBScript}}
<syntaxhighlight lang=text>* Chinese zodiac 10/03/2019
CHINEZOD CSECT
USING CHINEZOD,R13 base register
Line 124:
XDEC DS CL12 temp for xdeco
REGEQU
END CHINEZOD</langsyntaxhighlight>
{{out}}
<pre>
Line 137:
 
=={{header|Action!}}==
<langsyntaxhighlight lang=Action!>DEFINE PTR="CARD"
 
PTR ARRAY animals(12),elements(5),stems(10),branches(12),yinYangs(2)
Line 201:
c=GetCycle(y) PrintB(c) Print("/60") PutE()
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Chinese_zodiac.png Screenshot from Atari 8-bit computer]
Line 218:
{{works with|GNAT|8.3.0}}
 
<langsyntaxhighlight lang=Ada>
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 335:
end loop;
end Main;
</syntaxhighlight>
</lang>
 
{{out}}
Line 351:
=={{header|ALGOL 68}}==
{{Trans|AWK}}
<langsyntaxhighlight lang=algol68>BEGIN # Chinese Zodiac #
# returns s right-padded with blanks to w characters, or s if s is already at least w characters long #
PRIO PAD = 1;
Line 373:
print( ( whole( year, -4 ), " ", element PAD 7, " ", animal PAD 7, " ", yy, newline ) )
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 390:
{{Trans|JavaScript}}
{{Trans|Haskell}}
<langsyntaxhighlight lang=AppleScript>on run
-- TRADITIONAL STRINGS ---------------------------------------------------
Line 656:
map(result, items 1 thru ¬
minimum({length of xs, length of ys, length of zs}) of xs)
end zip3</langsyntaxhighlight>
{{Out}}
<pre>1935 乙亥 木 豬 阴
Line 688:
=={{header|AutoHotkey}}==
Chinese Animal/Element/Yin/Yang Characters Copied From "AppleScript"
<langsyntaxhighlight lang=AutoHotkey>Chinese_zodiac(year){
Animal := StrSplit("Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig", ",")
AnimalCh := StrSplit("鼠牛虎兔龍蛇馬羊猴鸡狗豬")
Line 714:
Bn := BranchName[Mod12]
return year "`t" S B " " Sn "-" Bn " `t" E " " Ec " " En "`t" A " " Ac " " An "`t" YY " " Yr
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight lang=AutoHotkey>loop 12
{
n := 1983+A_Index
Line 721:
}
MsgBox % output "`n" Chinese_zodiac(2017)
return</langsyntaxhighlight>
{{out}}
<pre>1984 甲子 jiă-zĭ Wood 木 mù Rat 鼠 shǔ yáng 阳 1/60
Line 739:
 
=={{header|AWK}}==
<langsyntaxhighlight lang=AWK>
# syntax: GAWK -f CHINESE_ZODIAC.AWK
BEGIN {
Line 755:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 770:
 
=={{header|BASIC256}}==
<langsyntaxhighlight lang=BASIC256>
# Chinese zodiac
 
Line 795:
Next i
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 809:
=={{header|Befunge}}==
 
<langsyntaxhighlight lang=befunge>0" :raeY">:#,_55+"< /8"&>+:66+%00p:55+v
v"Aspect: "0++88*5%2\0\+1%"<":p01++66/2%<
>00g5g7-0" :laminA"10g5g"<"+0" :tnemelE"v
Line 816:
$'-4;AGLS[_ %*06yang yin Rat Ox Tiger R |
abbit Dragon Snake Horse Goat Monkey Roo |
ster Dog Pig Wood Fire Earth Metal Water |</langsyntaxhighlight>
 
{{out}}
Line 828:
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang=c>#include <math.h>
#include <stdio.h>
 
Line 862:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>1935 is the year of the Wood Pig (yin).
Line 873:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang=csharp>using System;
 
namespace ChineseZodiac {
Line 899:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>1935 is the year of the Wood Pig (yin). 乙亥
Line 911:
 
=={{header|C++}}==
<langsyntaxhighlight lang=cpp>#include <iostream>
#include <cmath>
 
Line 951:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 963:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang=clojure>(def base-year 4)
(def celestial-stems ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
(def terrestrial-branches ["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"])
Line 992:
(defn -main [& args]
(doseq [years (map read-string args)]
(chinese-zodiac years)))</langsyntaxhighlight>
 
{{out}}
Line 1,008:
=={{header|Commodore BASIC}}==
{{works with|Commodore 64/128}}
<langsyntaxhighlight lang=basic>1000 rem display the chinese zodiac for a given year
1010 poke 53281,7: rem yellow background
1020 poke 53280,2: rem red border
Line 1,078:
3310 rem year-mod function
3320 def fnym(d) = y - int(y/d)*d
3330 return</langsyntaxhighlight>
{{Out}}
https://i.imgur.com/f3Fo1xm.png
Line 1,084:
=={{header|Common Lisp}}==
{{trans|Ruby}}
<langsyntaxhighlight lang=lisp>; Any CE Year that was the first of a 60-year cycle
(defconstant base-year 1984)
 
Line 1,139:
(loop for cz in (apply #'chinese-zodiac (mapcar #'read-from-string (get-args)))
doing
(format t "~{~a: ~a~a (~a-~a, ~a ~a; ~a)~%~}" cz))</langsyntaxhighlight>
 
{{Out}}
Line 1,156:
=={{header|D}}==
{{trans|haskell}}
<langsyntaxhighlight lang=D>import std.stdio;
 
// 10 heavenly stems
Line 1,213:
}
}
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,248:
{{libheader| System.Math}}
{{Trans|C#}}
<langsyntaxhighlight lang=Delphi>
program Chinese_zodiac;
 
Line 1,336:
CloseFile(Outfile);
Readln;
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,356:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang=lisp>CNZODIAC
=LAMBDA(y,
APPENDCOLS(
Line 1,495:
)
)
)</langsyntaxhighlight>
 
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<langsyntaxhighlight lang=lisp>APPENDCOLS
=LAMBDA(xs,
LAMBDA(ys,
Line 1,539:
)
)
)</langsyntaxhighlight>
 
{{Out}}
Line 1,754:
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang=fsharp>
open System
 
Line 1,776:
Console.ReadLine() |> ignore
0 // return an integer exit code
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,790:
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: circular formatting io kernel math qw sequences
sequences.repeating ;
IN: rosetta-code.zodiac
Line 1,820:
[ zodiac print ] each ;
 
MAIN: zodiac-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 1,834:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang=freebasic>dim as string yy(0 to 1) = {"yang", "yin"}
dim as string elements(0 to 4) = {"Wood", "Fire", "Earth", "Metal", "Water"}
dim as string animals(0 to 11) = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",_
Line 1,851:
print outstr
next i</langsyntaxhighlight>
{{out}}
<pre>
Line 1,870:
 
=={{header|Go}}==
<langsyntaxhighlight lang=go>package main
 
import "fmt"
Line 1,900:
yr, e, a, yy, cy, sb)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,912:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang=groovy>class Zodiac {
final static String[] animals = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
final static String[] elements = ["Wood", "Fire", "Earth", "Metal", "Water"]
Line 1,932:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>1935 is the year of the Wood Pig (yin). 乙亥
Line 1,945:
=={{header|Haskell}}==
(We can use Chinese characters in Haskell names, as long as the first character is lower-case alphabetic)
<langsyntaxhighlight lang=haskell>import Data.Array (Array, listArray, (!))
 
------------------- TRADITIONAL STRINGS ------------------
Line 2,048:
<$> zip fieldWidths (f生肖五行年份 y)
where
justifyLeft n c s = take n (s <> replicate n c)</langsyntaxhighlight>
{{Out}}
<pre>1935 乙亥 木 豬 阴
Line 2,079:
 
=={{header|J}}==
<langsyntaxhighlight lang=J> ELEMENTS=: _4 |. 2 # ;:'Wood Fire Earth Metal Water'
YEARS=: 1935 1938 1968 1972 1976 2017
 
Line 2,120:
1976 丙 辰 ( yang )
2017 丁 酉 ( yin )
</syntaxhighlight>
</lang>
 
=={{header|Java}}==
<langsyntaxhighlight lang=Java>public class Zodiac {
 
final static String animals[]={"Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"};
Line 2,151:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,168:
===ES6===
{{Trans|Haskell}}
<langsyntaxhighlight lang=JavaScript>(() => {
"use strict";
 
Line 2,354:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>1935 乙亥 木 豬 阴
Line 2,388:
{{trans|Python}}
 
<langsyntaxhighlight lang=julia>function chinese(year::Int)
pinyin = Dict(
"甲" => "jiă",
Line 2,445:
curryr = Dates.year(now())
yrs = [1935, 1938, 1968, 1972, 1976, curryr]
foreach(println, map(chinese, yrs))</langsyntaxhighlight>
 
{{out}}
Line 2,456:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang=scala>// version 1.1.2
 
class ChineseZodiac(val year: Int) {
Line 2,503:
println("---- ------- --------- ------- ------- ------ -----")
for (year in years) println(ChineseZodiac(year))
}</langsyntaxhighlight>
 
{{out}}
Line 2,520:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang=lua>local ANIMALS = {"Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"}
local ELEMENTS = {"Wood","Fire","Earth","Metal","Water"}
 
Line 2,553:
zodiac(1972)
zodiac(1976)
zodiac(2017)</langsyntaxhighlight>
{{out}}
<pre>1935 is the year of the Wood Pig (yin)
Line 2,563:
 
=={{header|Maple}}==
<langsyntaxhighlight lang=Maple>
zodiac:=proc(year::integer)
local year60,yinyang,animal,element;
Line 2,572:
return sprintf("%a",cat(year," is the year of the ",element[(year60 mod 10)+1]," ",animal[(year60 mod 12)+1]," (",yinyang[(year60 mod 2)+1],")"));
end proc:
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>pinyin = <|"甲" -> "jiă", "乙" -> "yĭ", "丙" -> "bĭng", "丁" -> "dīng",
"戊" -> "wù", "己" -> "jĭ", "庚" -> "gēng", "辛" -> "xīn",
"壬" -> "rén", "癸" -> "gŭi", "子" -> "zĭ", "丑" -> "chŏu",
Line 2,613:
calculate[1968]
calculate[1972]
calculate[1976]</langsyntaxhighlight>
{{out}}
<pre>1935: 乙亥 (yĭ-hài, Wood Pig; yin)
Line 2,625:
=={{header|Modula-2}}==
{{trans|C++}}
<langsyntaxhighlight lang=modula2>MODULE ChineseZodiac;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
Line 2,677:
 
ReadChar
END ChineseZodiac.</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Rust}}
<langsyntaxhighlight lang=nim>import strformat
 
const ANIMALS: array[12, string] = ["Rat", "Ox",
Line 2,725:
echo "---- ------- ------ ------- ------ ------ -----"
for year in years:
echo &"{chineseZodiac(year)}"</langsyntaxhighlight>
 
{{out}}
Line 2,744:
{{works with|Extended Pascal}}
The built-in functions <tt>pred</tt> and <tt>succ</tt> accepting a second (optional) parameter is an Extended Pascal (ISO 10206) extension, as well as the possibility of specifying <tt>record</tt> literals.
<langsyntaxhighlight lang=pascal>type
animalCycle = (rat, ox, tiger, rabbit, dragon, snake,
horse, goat, monkey, rooster, dog, pig);
Line 2,764:
aspect: succ(yang, year mod 2);
]
end;</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>sub zodiac {
my $year = shift;
my @animals = qw/Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig/;
Line 2,787:
 
printf("%4d: %s%s (%s-%s) %s %s; %s - year %d of the cycle\n", zodiac($_))
for (1935, 1938, 1968, 1972, 1976, 2017);</langsyntaxhighlight>
{{out}}
<pre>
Line 2,799:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">animals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Rat"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Ox"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Tiger"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Rabbit"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Dragon"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Snake"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Horse"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Goat"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Monkey"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Rooster"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Dog"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Pig"</span><span style="color: #0000FF;">},</span>
Line 2,815:
<span style="color: #0000FF;">{</span><span style="color: #000000;">year</span><span style="color: #0000FF;">,</span><span style="color: #000000;">element</span><span style="color: #0000FF;">,</span><span style="color: #000000;">animal</span><span style="color: #0000FF;">,</span><span style="color: #000000;">yy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cycle</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,829:
{{trans|Prolog}}
{{works with|Picat}}
<langsyntaxhighlight lang=Picat>
animals({"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"}).
 
Line 2,875:
printf("%d is the year of the %w %w (%w). %w%w\n", Year, Element, Animal, YinYang, ElementChar, AnimalChar)
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,890:
=={{header|PowerShell}}==
{{trans|Ruby}}
<langsyntaxhighlight lang=PowerShell>
function Get-ChineseZodiac
{
Line 2,976:
}
}
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang=PowerShell>
1935, 1938, 1968, 1972, 1976 | Get-ChineseZodiac | Format-Table
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,991:
</pre>
Defaults to the current year:
<langsyntaxhighlight lang=PowerShell>
Get-ChineseZodiac
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,005:
</pre>
Using the '''Year''' property of a <code>[DateTime]</code> object:
<langsyntaxhighlight lang=PowerShell>
Get-Date "11/8/2016" | Get-ChineseZodiac
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,019:
</pre>
Emulate the Ruby script's output:
<langsyntaxhighlight lang=PowerShell>
$zodiacs = 1935, 1938, 1968, 1972, 1976 | Get-ChineseZodiac
 
Line 3,032:
$zodiac.YearOfCycle
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,045:
{{trans|Java}}
{{works with|GNU Prolog}}
<langsyntaxhighlight lang=Prolog>
:- initialization(main).
 
Line 3,104:
nl
)).
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,118:
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang=pureBasic>EnableExplicit
#BASE=4
#SPC=Chr(32)
Line 3,169:
Stem: : Data.s "jiă\yĭ\bĭng\dīng\wù\jĭ\gēng\xīn\rén\gŭi"
Branch: : Data.s "zĭ\chŏu\yín\măo\chén\sì\wŭ\wèi\shēn\yŏu\xū\hài"
EndDataSection</langsyntaxhighlight>
{{Out}}
<pre>Year Element Animal Aspect YearOfCycle ASCII Chinese
Line 3,182:
=={{header|Python}}==
{{trans|Ruby}}
<langsyntaxhighlight lang=Python>
# coding: utf-8
 
Line 3,247:
years = [1935, 1938, 1968, 1972, 1976, current_year]
for year in years:
calculate(year)</langsyntaxhighlight>
 
 
Or, segmenting tokens just in time, and writing out wiki tables:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang=python>'''Chinese zodiac'''
 
from functools import (reduce)
Line 3,409:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
{| class="wikitable"
Line 3,560:
{{trans|Common Lisp}}
 
<langsyntaxhighlight lang=racket>#lang racket
 
(require racket/date)
Line 3,605:
(module+ test
(for ((ce-year (in-list '(1935 1938 1941 1947 1968 1972 1976))))
(apply printf "~a: ~a~a (~a-~a, ~a ~a; ~a)~%" (chinese-zodiac ce-year))))</langsyntaxhighlight>
 
{{out}}
Line 3,621:
{{trans|Ruby}}
 
<syntaxhighlight lang=raku perl6line>sub Chinese-zodiac ( Int $year ) {
my @heaven = <甲 jiă 乙 yĭ 丙 bĭng 丁 dīng 戊 wù 己 jĭ 庚 gēng 辛 xīn 壬 rén 癸 gŭi>.pairup;
my @earth = <子 zĭ 丑 chŏu 寅 yín 卯 măo 辰 chén 巳 sì 午 wŭ 未 wèi 申 shēn 酉 yŏu 戌 xū 亥 hài>.pairup;
Line 3,648:
printf "%d: %s (%s, %s %s; %s - year %d in the cycle)\n",
$_, .&Chinese-zodiac<Han pinyin element animal aspect cycle>
for 1935, 1938, 1968, 1972, 1976, 1984, Date.today.year;</langsyntaxhighlight>
 
{{out}}
Line 3,660:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
yinyang = ["yang", "yin"]
elements = ["Wood", "Fire", "Earth", "Metal", "Water"]
Line 3,676:
? output
next
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,690:
This is written as a command-line tool that takes a list of CE year numbers as arguments and outputs their information; if no arguments are supplied, it displays the information for the current year.
 
<langsyntaxhighlight lang=ruby># encoding: utf-8
pinyin = {
'甲' => 'jiă',
Line 3,755:
print stem_han, branch_han
puts " (#{stem_pinyin}-#{branch_pinyin}, #{element} #{animal}; #{aspect} - year #{index} of the cycle)"
end</langsyntaxhighlight>
 
{{Output}}
Line 3,770:
=={{header|Rust}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=Rust>fn chinese_zodiac(year: usize) -> String {
static ANIMALS: [&str; 12] = [
"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
Line 3,824:
println!("{}", chinese_zodiac(year));
}
}</langsyntaxhighlight>
{{out}}
<pre>Year Chinese Pinyin Element Animal Aspect Cycle
Line 3,837:
 
=={{header|Scala}}==
<langsyntaxhighlight lang=Scala>object Zodiac extends App {
val years = Seq(1935, 1938, 1968, 1972, 1976, 1984, 1985, 2017, 2018)
 
Line 3,872:
+ animalChars((year - 4) % 12))
}
}</langsyntaxhighlight>
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/O6MUr27/0 ScalaFiddle (JavaScript)] or by [https://scastie.scala-lang.org/KXC0j71ORFaQxNZSCCZ1Aw Scastie (JVM)].
 
Line 3,881:
The library [http://seed7.sourceforge.net/libraries/console.htm console.s7i] defines STD_CONSOLE.
 
<langsyntaxhighlight lang=seed7>$ include "seed7_05.s7i";
include "console.s7i";
 
Line 3,902:
([0] ("yang", "yin"))[year rem 2] <& "). " <& elementChars[year rem 2][eIdx] <& animalChars[aIdx]);
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,918:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang=ruby>func zodiac(year) {
var animals = %w(Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig)
var elements = %w(Wood Fire Earth Metal Water)
Line 3,938:
[1935, 1938, 1968, 1972, 1976, 2017].each { |year|
printf("%4d: %s%s (%s-%s) %s %s; %s - year %d of the cycle\n", zodiac(year))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,950:
 
=={{header|tbas}}==
<langsyntaxhighlight lang=qbasic>
DATA "甲","乙","丙","丁","戊","己","庚","辛","壬","癸"
DECLARE celestial$(10)
Line 4,021:
PRINT TAB(50);"year";index;"of the cycle"
NEXT
</syntaxhighlight>
</lang>
<pre>
$ tbas chinZod.bas
Line 4,037:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang=Tcl>
proc cn_zodiac year {
set year0 [expr $year-4]
Line 4,055:
return $res
}
</langsyntaxhighlight><pre>
% cn_zodiac 1984
甲子 jia3-zi3 Wood Rat (yang) year 1
Line 4,064:
=={{header|uBasic/4tH}}==
{{works with|R3}}
<syntaxhighlight lang=text>dim @y(2) ' yin or yang
dim @e(5) ' the elements
dim @a(12) ' the animals
Line 4,096:
d@ = (a@ - 4) % 12
Return (Join(Str (a@), " is the year of the ", @e(c@), " ", @a(d@), " (", @y(b@), ")."))
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,272:
=={{header|UTFool}}==
 
<langsyntaxhighlight lang=UTFool>
···
http://rosettacode.org/wiki/Chinese_zodiac
Line 4,312:
System.out.printf " %-2s/60 %-7s %s\n\n", cycle \ 60 + 1,
wuxing[2][stem / 2], shengxiao[2][branch]
</syntaxhighlight>
</lang>
 
=={{header|VBScript}}==
To run in console mode with cscript.
<langsyntaxhighlight lang=vb>' Chinese zodiac - VBS
 
Animals = array( "Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig" )
Line 4,331:
msgbox xYear & " is the year of the " & yElement & " " & yAnimal & " (" & yYinYang & ").",, _
xYear & " : " & nn & "/60"
next </langsyntaxhighlight>
{{out}}
<pre>
Line 4,345:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang=vbnet>Module Module1
 
ReadOnly ANIMALS As String() = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"}
Line 4,375:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>1935 is the year of the Wood Pig (yin). 乙亥
Line 4,388:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>const (
animal_string = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
Line 4,413:
println("$yr: $e $a, $yy, Cycle year $cy $sb")
}
}</langsyntaxhighlight>
 
{{out}}
Line 4,423:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang=ecmascript>import "/fmt" for Fmt
 
class ChineseZodiac {
Line 4,466:
System.print("---- ------- --------- ------- ------- ------ -----")
ChineseZodiac.init()
for (year in years) System.print(ChineseZodiac.new(year))</langsyntaxhighlight>
 
{{out}}
Line 4,484:
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang=Yabasic>
dim Animals$(12) : for a = 0 to 11 : read Animals$(a) : next a
dim Elements$(5) : for a = 0 to 4 : read Elements$(a): next a
Line 4,505:
data "Yang","Yin"
data 1935, 1938, 1968, 1972, 1976, 1984, 2017
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,520:
=={{header|zkl}}==
{{trans|Ruby}}
<langsyntaxhighlight lang=zkl>fcn ceToChineseZodiac(ce_year){ // --> list of strings
# encoding: utf-8
var [const] pinyin=SD( // create some static variables, SD is small fixed dictionary
Line 4,551:
return(stem_han,branch_han,
stem_pinyin,branch_pinyin, element,animal,aspect)
}</langsyntaxhighlight>
<langsyntaxhighlight lang=zkl>foreach ce_year in (T(1935,1938,1968,1972,1976,Time.Clock.UTC[0])){
println("%d: %s%s (%s-%s, %s %s; %s)"
.fmt(ce_year,ceToChineseZodiac(ce_year).xplode()));
}</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits