feat: implemented the program
This commit is contained in:
commit
cd5de79e24
22 changed files with 930 additions and 0 deletions
36
app/Main.hs
Normal file
36
app/Main.hs
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Main (main) where
|
||||
import qualified Data.Text.IO as Text
|
||||
import Text.Megaparsec (errorBundlePretty, runParser)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Sudoku
|
||||
import qualified Sudoku.Solve as Solve
|
||||
import qualified Sudoku.Render as Render
|
||||
import Sudoku.State (State)
|
||||
import Options.Applicative (subparser, command, info, Parser, progDesc, execParser)
|
||||
import System.Exit (exitFailure)
|
||||
|
||||
data Mode
|
||||
= Solve
|
||||
| Hints
|
||||
|
||||
parseMode :: Parser Mode
|
||||
parseMode = subparser
|
||||
( command "solve" (info (pure Solve) (progDesc "Solve the supplied sudoku entirely."))
|
||||
<> command "hints" (info (pure Hints) (progDesc "Show hints for the sudoku."))
|
||||
)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
mode <- execParser (info parseMode mempty)
|
||||
input <- Text.getContents
|
||||
sudoku <- case runParser Sudoku.parse "<stdin>" input of
|
||||
Left errorBundle -> (Text.putStr . Text.pack . errorBundlePretty $ errorBundle) >> exitFailure
|
||||
Right s -> pure s
|
||||
|
||||
Text.putStr $ case mode of
|
||||
Solve -> Text.pack . show $ Solve.solve State sudoku
|
||||
Hints -> let
|
||||
hints = Solve.hints State sudoku
|
||||
|
||||
in Render.hints hints
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue