LoginSignup
0

More than 5 years have passed since last update.

第3回 オフラインリアルタイムどう書く解答(haskell)

Posted at

コードをアップするまでが勉強会、ということで勉強会ではRubyで解いたけれどhaskellで。
問題はこちら。http://nabetani.sakura.ne.jp/hena/ord3ynode/
haskellのIO処理がまだ解っていないので問題はリテラルで埋め込んでます。

-- solveの第一引数に問題のリテラルを
main = print $ solve "llllllrllrlbrrr" ('B','A')

route::(Char,Char)->[Char]
route ('A','B') = ['E','C','A']
route ('A','C') = ['B','F','A']
route ('A','D') = ['F','E','A']
route ('B','A') = ['C','D','B']
route ('B','C') = ['F','A','B']
route ('B','E') = ['D','F','B']
route ('C','A') = ['D','B','C']
route ('C','B') = ['A','E','C']
route ('C','F') = ['E','D','C']
route ('D','A') = ['B','C','D']
route ('D','E') = ['F','B','D']
route ('D','F') = ['C','E','D']
route ('E','B') = ['C','A','E']
route ('E','D') = ['A','F','E']
route ('E','F') = ['D','C','E']
route ('F','C') = ['A','B','F']
route ('F','D') = ['E','A','F']
route ('F','E') = ['B','D','F']

conv::Char->Int
conv 'r' = 0
conv 'l' = 1
conv 'b' = 2

solve::String->(Char,Char)->String
solve [] (_, to) = [to]
solve (x:xs) (fm, to) = to:(solve xs (to, (route (fm, to))!!(conv x)))

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