import Data.Array (Array, listArray, (!))


ats :: Array Int (Char, String)
ats =
  listArray (0, 9) $
    zip
      
      ""
      (words "ji y bng dng w j gng xn rn gi")

ads :: Array Int (String, String)
ads =
  listArray (0, 11) $
    zip
      
      (chars "")
      ( words $
          "z chu yn mo chn s "
            <> "w wi shn yu x hi"
      )

aws :: Array Int (String, String, String)
aws =
  listArray (0, 4) $
    zip3
      
      (chars "")
      (words "m hu t jn shu")
      (words "wood fire earth metal water")

axs :: Array Int (String, String, String)
axs =
  listArray (0, 11) $
    zip3
      
      (chars "")
      ( words $
          "sh ni h t lng sh "
            <> "m yng hu j gu zh"
      )
      ( words $
          "rat ox tiger rabbit dragon snake "
            <> "horse goat monkey rooster dog pig"
      )

ays :: Array Int (String, String)

ays =
  listArray (0, 1) $
    zip (chars "") (words "yng yn")

chars :: String -> [String]
chars = (flip (:) [] <$>)


f y =
  let i = y - 4
      i = rem i 10
      i = rem i 12
      (h, p) = ats ! i
      (h, p) = ads ! i
      (h, p, e) = aws ! quot i 2
      (h, p, e) = axs ! i
      (h, p) = ays ! rem i 2
   in 
      [ [show y, h: h, h, h, h],
        
        [[], p <> p, p, p, p],
        
        [ [],
          show (rem i 60 + 1) <> "/60",
          e,
          e,
          []
        ]
      ]


main :: IO ()
main =
  mapM_ putStrLn $
    showYear
      <$> [1935, 1938, 1968, 1972, 1976, 1984, 2017]


fieldWidths :: [[Int]]
fieldWidths =
  [ [6, 10, 7, 8, 3],
    [6, 11, 8, 8, 4],
    [6, 11, 8, 8, 4]
  ]

showYear :: Int -> String
showYear y =
  unlines $
    ( \(ns, xs) ->
        concat $
          uncurry (`justifyLeft` ' ')
            <$> zip ns xs
    )
      <$> zip fieldWidths (f y)
  where
    justifyLeft n c s = take n (s <> replicate n c)