diff options
author | Andrew Cady <d@jerkface.net> | 2021-01-09 23:50:03 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2021-01-09 23:50:03 -0500 |
commit | de177e14090e5bb6910cb791cf9a47f6bc0f9887 (patch) | |
tree | e446c70ba020cb1fae7c1688073a2cba3f282659 | |
parent | 8f811cd88ccafd6d7a05e8c5aaaaa78d3bc43444 (diff) |
avoid redundant output when bookcase is symmetrical
-rwxr-xr-x | shelf.hs | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -66,16 +66,31 @@ positions Shelf{..} = map sum $ (tail . inits) $ concatMap (: [boardThickness]) | |||
66 | 66 | ||
67 | positions' x@Shelf{..} = map (boardLength -) $ positions x | 67 | positions' x@Shelf{..} = map (boardLength -) $ positions x |
68 | 68 | ||
69 | printPositions :: Shelf -> IO () | 69 | printDadoMarkings :: Shelf -> IO () |
70 | printPositions x = do | 70 | printDadoMarkings x = do |
71 | if symmetrical | ||
72 | then putStrLn "\nDado markings (symmetrical):\n" | ||
73 | else putStrLn "\nDado markings:\n" | ||
74 | |||
71 | mapM_ putStrLn $ formatFeet <$> positions x | 75 | mapM_ putStrLn $ formatFeet <$> positions x |
72 | when (positions x /= reverse (positions' x)) $ do | 76 | |
77 | when (not symmetrical) $ do | ||
73 | putStrLn "\nReversed:\n" | 78 | putStrLn "\nReversed:\n" |
74 | mapM_ putStrLn $ formatFeet <$> positions' x | 79 | mapM_ putStrLn $ formatFeet <$> positions' x |
80 | where | ||
81 | symmetrical = positions x == reverse (positions' x) | ||
82 | |||
83 | printCutlist :: Shelf -> IO () | ||
84 | printCutlist x = do | ||
85 | putStrLn "Length:" | ||
86 | putStrLn $ formatFeet $ boardLength x | ||
87 | printDadoMarkings x | ||
88 | |||
89 | printPianoCubbies :: IO () | ||
90 | printPianoCubbies = do | ||
91 | putStrLn "Piano Cubbies" | ||
92 | putStrLn "-------------\n" | ||
93 | printCutlist pianoCubbies | ||
75 | 94 | ||
76 | main :: IO () | 95 | main :: IO () |
77 | main = do | 96 | main = printPianoCubbies |
78 | putStrLn "Piano cubbies:\n" | ||
79 | printPositions pianoCubbies | ||
80 | putStrLn "\n\nBookshelf:\n" | ||
81 | printPositions bookshelf | ||