LoginSignup
0
0

More than 1 year has passed since last update.

【Haskell】アラビア数字をマヤ数字にする

Last updated at Posted at 2021-12-26

マヤ数字って何?って人はココを参照。大まかにいうと、20進法を採用している数字の体系です。

方針

  1. 入力値を10進法から20進法に変換する
  2. 各桁ごとにマヤ数字表記にする
  3. スペースを置いて可読性を高めた上で出力する

頑張るとこうなる

enmaya :: Int -> String
enmaya n = unwords $ map enmaya1 $ vig n

vig :: Int -> [Int]
vig x
    | x < 0 = error "never put such numbers"
    | x < 20 = [x]
    | otherwise = vig (x `div` 20) ++ [mod x 20]

enmaya1 :: Int -> String
enmaya1 0 = "O"
enmaya1 1 = "."
enmaya1 5 = "_"
enmaya1 m
    | m < 5  = enmaya1 (m - 1) ++ "."
    | m < 20 = enmaya1 (m - 5) ++ "_"

マヤ数字の話で盛り上がったので書きました。たのしかった(๑˃̵ᴗ˂̵)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0