Help us understand the problem. What is going on with this article?

第四回オフラインリアルタイムどう書くの解答例(Haskell)

More than 5 years have passed since last update.

ブロックの位置関係(距離)から判別するという鍋谷さんのアイディア( http://qiita.com/items/a2d6f70241b9e80ab17d の2つ目)に感銘を受けて。Haskellで書いてみました。

import Data.Char
import Data.List

c2i = subtract 48.ord

dist x0 y0 x1 y1 = (x1 - x0) ^ 2 + (y1 - y0) ^ 2

str2pos (x0:y0:',':x1:y1:',':x2:y2:',':x3:y3:[]) =
  [(c2i x0, c2i y0), (c2i x1, c2i y1), (c2i x2, c2i y2), (c2i x3, c2i y3)]

pattern = unwords.map show.sort.pattern'.str2pos
  where
    pattern' [] = []
    pattern' ((x, y):ps) = (foldl (\xs (x1, y1) -> (dist x y x1 y1):xs) [] ps) ++ pattern' ps

solve x = case pattern x of "1 1 1 2 4 5" -> "L"
                            "1 1 1 4 4 9" -> "I"
                            "1 1 1 2 2 4" -> "T"
                            "1 1 1 1 2 2" -> "O"
                            "1 1 1 2 2 5" -> "S"
                            _             -> "-"

main = getContents >>= putStrLn.unlines.map solve.lines
emattsan
ソフトウェアエンジニア、言語オタク
http://d.hatena.ne.jp/E_Mattsan/
esm
We build applications which work well and make customers happy.
http://www.esm.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした