Skip to content

Latest commit

 

History

History
121 lines (93 loc) · 2.91 KB

033-sexagenario.livemd

File metadata and controls

121 lines (93 loc) · 2.91 KB

33 - Ciclo Sexagenario Chino

CICLO SEXAGENARIO CHINO

Enunciado

Crea un función, que dado un año, indique el elemento y animal correspondiente en el ciclo sexagenario del zodíaco chino.

Solución

# https://en.wikipedia.org/wiki/Heavenly_Stems
defmodule Stem do
  @stems [
    ["Jiǎ (甲)", "Este 東", "Madera 木", "Yang 陽"],
    ["Yǐ (乙)", "Este 東", "Madera 木", "Yin 陰"],
    ["Bǐng (丙)", "Sur 南", "Fuego 火", "Yang 陽"],
    ["Dīng (丁)", "Sur 南", "Fuego 火", "Yin 陰"],
    ["Wù (戊)", "Centro 中", "Tierra 土", "Yang 陽"],
    ["Jǐ (己)", "Centro 中", "Tierra 土", "Yin 陰"],
    ["Gēng (庚)", "Oeste 西", "Metal 金", "Yang 陽"],
    ["Xīn (辛)", "Oeste 西", "Metal 金", "Yin 陰"],
    ["Rén (壬)", "Norte 北", "Agua 水", "Yang 陽"],
    ["Guǐ (癸)", "Norte 北", "Agua 水", "Yin 陰"]
  ]

  def id(year) do
    rem(year + 6, 10)
  end

  def for(year) do
    Enum.at(@stems, id(year))
    |> Enum.join(" ")
  end
end
{:module, Stem, <<70, 79, 82, 49, 0, 0, 9, ...>>, {:for, 1}}
# https://en.wikipedia.org/wiki/Earthly_Branches
defmodule Branch do
  @branches [
    ["Zǐ (子)", "Rata"],
    ["Chǒu (丑)", "Buey"],
    ["Yín (寅)", "Tigre"],
    ["Mǎo (卯)", "Conejo"],
    ["Chén (辰)", "Dragón"],
    ["Sì (巳)", "Serpiente"],
    ["Wǔ (午)", "Caballo"],
    ["Wèi (未)", "Oveja"],
    ["Shēn (申)", "Mono"],
    ["Yǒu (酉)", "Gallo"],
    ["Xū (戌)", "Perro"],
    ["Hài (亥)", "Cerdo"]
  ]

  def id(year) do
    rem(year + 8, 12)
  end

  def for(year) do
    Enum.at(@branches, id(year))
    |> Enum.join(" ")
  end
end
{:module, Branch, <<70, 79, 82, 49, 0, 0, 9, ...>>, {:for, 1}}
defmodule Solution do
  def run(year) do
    "#{year}: #{Stem.for(year)} - #{Branch.for(year)}"
  end
end
{:module, Solution, <<70, 79, 82, 49, 0, 0, 7, ...>>, {:run, 1}}
Solution.run(1989)
"1989: Jǐ (己) Centro 中 Tierra 土 Yin 陰 - Sì (巳) Serpiente"