Some cleanup and optparse
This commit is contained in:
parent
ebdb931e32
commit
d5208cfa34
3 changed files with 33 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*.cabal
|
*.cabal
|
||||||
|
result*
|
||||||
|
|
41
Main.hs
41
Main.hs
|
@ -3,20 +3,39 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Attoparsec.Text (parseOnly)
|
import Data.Attoparsec.Text (parseOnly)
|
||||||
|
import Data.Either (fromRight)
|
||||||
|
import Options.Applicative
|
||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
|
|
||||||
import INAST
|
import INAST
|
||||||
import INSolver
|
import INSolver
|
||||||
|
|
||||||
|
data FCInsurersOpt = FCInsurersOpt
|
||||||
|
{ path :: FilePath
|
||||||
|
, intInput :: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fCInsurersOpt :: Parser FCInsurersOpt
|
||||||
|
fCInsurersOpt = FCInsurersOpt
|
||||||
|
<$> strOption
|
||||||
|
( long "network"
|
||||||
|
<> metavar "PATH"
|
||||||
|
<> help "the path to a file that defines a network" )
|
||||||
|
<*> option auto
|
||||||
|
( long "input"
|
||||||
|
<> metavar "INT"
|
||||||
|
<> help "an integer input to the network" )
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = fcinsurers =<< execParser opts
|
||||||
inputNetwork <- T.readFile "./input.network"
|
where
|
||||||
T.putStrLn "Using the following input network:"
|
opts = info (fCInsurersOpt <**> helper)
|
||||||
T.putStrLn inputNetwork
|
( fullDesc
|
||||||
T.putStrLn "Parsed AST:"
|
<> progDesc "A small command line program that outputs a list of the \
|
||||||
let Right insnet = parseOnly insuranceNetworkParser inputNetwork
|
\ fewest contributing insurers (by their integer ids)"
|
||||||
print insnet
|
<> header "Fewest Contributing Insurers (in23)" )
|
||||||
T.putStrLn "Problem solution, input=3:"
|
|
||||||
print $ solve (3::Int) insnet
|
fcinsurers :: FCInsurersOpt -> IO ()
|
||||||
T.putStrLn "Problem solution, input=6:"
|
fcinsurers (FCInsurersOpt p i) = do
|
||||||
print $ solve (6::Int) insnet
|
inputNetwork <- T.readFile p
|
||||||
|
print $ fromRight [] $ solve i <$> parseOnly insuranceNetworkParser inputNetwork
|
||||||
|
|
|
@ -5,8 +5,9 @@ ghc-options: -Wall -threaded
|
||||||
dependencies:
|
dependencies:
|
||||||
- base == 4.*
|
- base == 4.*
|
||||||
- attoparsec
|
- attoparsec
|
||||||
- text
|
|
||||||
- mtl
|
- mtl
|
||||||
|
- optparse-applicative
|
||||||
|
- text
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
in23:
|
in23:
|
||||||
|
|
Loading…
Reference in a new issue