{- Verify output of cunningham-cards.pl Copyright 2017 Ken Takusagawa This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -} {-# LANGUAGE ScopedTypeVariables, LambdaCase #-} module Main where { import System.Environment(getArgs); import Control.Exception(assert); import Debug.Trace(trace); import Data.Function((&)); import Control.Category((>>>)); import Prelude hiding((.),(>>)); --import System.IO(hSetBuffering,stdout,BufferMode(LineBuffering)); --import Data.List; --import Control.Monad; --import Data.Maybe; --import qualified Data.Map as Map; --import Data.Map(Map); --import qualified Data.Set as Set; --import Data.Set(Set); -- to avoid the redundancy warning trace_placeholder :: (); trace_placeholder = (trace,assert) & (id >>> error) "trace_placeholder"; main :: IO(); main = getArgs >>= \case{ ["go"]->go; _ -> undefined; }; go :: IO(); go = do { getContents >>= (lines >>> map words >>> mapM_ check_line); }; check_line :: [String] -> IO (); check_line = \case { ('#':_):_ -> return (); [_b,"bit",d,"divides","2","^",n,sign,"1"] -> if (mod (2 ^ ((read n)::Integer) & alter_by sign) (read d))==0 then return (); else error n; x -> error (show x); }; alter_by :: String -> Integer -> Integer; alter_by "+" = succ; alter_by "-" = pred; alter_by s = error $ "not plus or minus: " ++ s; } --end