summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-01-09 23:50:03 -0500
committerAndrew Cady <d@jerkface.net>2021-01-09 23:50:03 -0500
commitde177e14090e5bb6910cb791cf9a47f6bc0f9887 (patch)
treee446c70ba020cb1fae7c1688073a2cba3f282659
parent8f811cd88ccafd6d7a05e8c5aaaaa78d3bc43444 (diff)
avoid redundant output when bookcase is symmetrical
-rwxr-xr-xshelf.hs31
1 files changed, 23 insertions, 8 deletions
diff --git a/shelf.hs b/shelf.hs
index e5b615d..c7b66e7 100755
--- a/shelf.hs
+++ b/shelf.hs
@@ -66,16 +66,31 @@ positions Shelf{..} = map sum $ (tail . inits) $ concatMap (: [boardThickness])
66 66
67positions' x@Shelf{..} = map (boardLength -) $ positions x 67positions' x@Shelf{..} = map (boardLength -) $ positions x
68 68
69printPositions :: Shelf -> IO () 69printDadoMarkings :: Shelf -> IO ()
70printPositions x = do 70printDadoMarkings 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
83printCutlist :: Shelf -> IO ()
84printCutlist x = do
85 putStrLn "Length:"
86 putStrLn $ formatFeet $ boardLength x
87 printDadoMarkings x
88
89printPianoCubbies :: IO ()
90printPianoCubbies = do
91 putStrLn "Piano Cubbies"
92 putStrLn "-------------\n"
93 printCutlist pianoCubbies
75 94
76main :: IO () 95main :: IO ()
77main = do 96main = printPianoCubbies
78 putStrLn "Piano cubbies:\n"
79 printPositions pianoCubbies
80 putStrLn "\n\nBookshelf:\n"
81 printPositions bookshelf