Created
September 16, 2013 02:24
-
-
Save uehaj/6576076 to your computer and use it in GitHub Desktop.
第13回オフラインリアルタイムどう書くの参考問題をFregeで解く ref: http://qiita.com/uehaj/items/944cd9903c3827f1d1bc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shortestPath' :: Int -> Int -> Int | |
| shortestPath' n maxn | |
| | n==0 = 0 | |
| | n==1 = 1 | |
| | n > maxn = maxBound::Int | |
| | even(n) = (shortestPath' (n `div` 2) (maxn-2)) + 1 | |
| | otherwise = minimum [(shortestPath' (n-1) (maxn-2)) + 1, (shortestPath' (n+1) (maxn-2)) + 1] | |
| shortestPath :: Int -> Int | |
| shortestPath n = shortestPath' n (n*2) | |
| main args = do | |
| println (shortestPath 59 == 9) | |
| println (shortestPath 10 == 5) | |
| println (shortestPath 11 == 6) | |
| println (shortestPath 12 == 5) | |
| println (shortestPath 13 == 6) | |
| println (shortestPath 14 == 6) | |
| println (shortestPath 15 == 6) | |
| println (shortestPath 16 == 5) | |
| println (shortestPath 17 == 6) | |
| println (shortestPath 18 == 6) | |
| println (shortestPath 27 == 8) | |
| println (shortestPath 28 == 7) | |
| println (shortestPath 29 == 8) | |
| println (shortestPath 30 == 7) | |
| println (shortestPath 31 == 7) | |
| println (shortestPath 32 == 6) | |
| println (shortestPath 33 == 7) | |
| println (shortestPath 34 == 7) | |
| println (shortestPath 35 == 8) | |
| println (shortestPath 41 == 8) | |
| println (shortestPath 71 == 9) | |
| println (shortestPath 1023 == 12) | |
| println (shortestPath 1024 == 11) | |
| println (shortestPath 1025 == 12) | |
| println (shortestPath 1707 == 17) | |
| println (shortestPath 683 == 15) | |
| println (shortestPath 123 == 10) | |
| println (shortestPath 187 == 11) | |
| println (shortestPath 237 == 12) | |
| println (shortestPath 5267 == 18) | |
| println (shortestPath 6737 == 18) | |
| println (shortestPath 14796 == 20) | |
| println (shortestPath 18998 == 20) | |
| println (shortestPath 23820 == 20) | |
| println (shortestPath 30380 == 21) | |
| println (shortestPath 31119 == 21) | |
| println (shortestPath 33301 == 20) | |
| println (shortestPath 33967 == 21) | |
| println (shortestPath 35443 == 22) | |
| println (shortestPath 35641 == 22) | |
| println (shortestPath 43695 == 23) | |
| println (shortestPath 44395 == 23) | |
| println (shortestPath 44666 == 22) | |
| println (shortestPath 987 == 14) | |
| println (shortestPath 1021 == 13) | |
| println (shortestPath 1019 == 13) | |
| println (shortestPath 1015 == 13) | |
| println (shortestPath 1007 == 13) | |
| println (shortestPath 1011 == 14) | |
| println (shortestPath 1003 == 14) | |
| println (shortestPath 983 == 14) | |
| println (shortestPath 999 == 14) | |
| println (shortestPath 2731 == 18) | |
| println (shortestPath 6827 == 20) | |
| println (shortestPath 10923 == 21) | |
| println (shortestPath 27307 == 23) | |
| println (shortestPath 43691 == 24) | |
| println (shortestPath 109227 == 26) | |
| println (shortestPath 174763 == 27) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment