Last active
May 13, 2018 04:40
-
-
Save nfunato/6578105 to your computer and use it in GitHub Desktop.
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
| -- AA graph drawer (as an exercise of mapAccum) | |
| -- 2013-09-16 @nfunato | |
| import Data.List (mapAccumL, transpose) | |
| main = plot =<< getContents | |
| plot = mapM_ putStrLn . convert | |
| convert = transpose . makeVstrs . analyze . parse | |
| parse = map cconv . filter (`elem` "RCF") | |
| where cconv 'R' = (-1, '/' ) | |
| cconv 'C' = ( 0, '_' ) | |
| cconv 'F' = ( 1, '\\') | |
| analyze = mapAccumL f (0,0,0) | |
| where f (y,ymin,ymax) (d,c) = ((y+d, min y ymin, max y ymax), (y',c)) | |
| where y' = if c=='\\' then y+1 else y | |
| makeVstrs ((_,ymin,ymax),yplots) = map makeVstr yplots | |
| where makeVstr (y',c) = map (\y -> if y==y' then c else ' ') [ymin..ymax] | |
| test1 = "RCRFCRFFCCRFFRRCRRCCFRFRFF" | |
| {- | |
| *Main> plot test1 | |
| __ | |
| / \/\/\ | |
| _/\_/\ _/ \ | |
| / \__/\ / | |
| \/ | |
| -} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment