Created
October 26, 2011 01:38
-
-
Save OJ/1315146 to your computer and use it in GitHub Desktop.
Solution to the Ruler Problem in Haskll
This file contains 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
ruler :: Int -> Int -> String | |
ruler h s = ruler' (2 ^ h * s + 1) h 1 [] [] | |
where | |
outChar c r = if (c `mod` (2 ^ r)) == 1 then '|' else ' ' | |
ruler' _ 0 _ _ a = unlines $ reverse a | |
ruler' w r c l a = let nl = (outChar c r) : l | |
in if c == w then ruler' w (r - 1) 1 [] (nl : a) | |
else ruler' w r (c + 1) nl a | |
-- to diplay results: | |
-- putStrLn $ ruler 6 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment