diff --git a/bench/Problems/P61Bench.hs b/bench/Problems/P61Bench.hs index a93b00c..afbb126 100644 --- a/bench/Problems/P61Bench.hs +++ b/bench/Problems/P61Bench.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2021 Yoo Chung License: GPL-3.0-or-later diff --git a/ninetynine.cabal b/ninetynine.cabal index 0da43a9..8a6ac15 100644 --- a/ninetynine.cabal +++ b/ninetynine.cabal @@ -21,7 +21,7 @@ homepage: https://ninetynine.haskell.chungyc.org/ bug-reports: https://github.com/chungyc/ninetynine/issues author: Yoo Chung maintainer: dev@chungyc.org -copyright: Copyright (C) 2023 Yoo Chung +copyright: Copyright (C) 2024 Yoo Chung license: GPL-3.0-or-later license-file: LICENSE build-type: Simple diff --git a/src/Problems/Graphs.hs b/src/Problems/Graphs.hs index 4fa6f51..7c20c47 100644 --- a/src/Problems/Graphs.hs +++ b/src/Problems/Graphs.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Supporting definitions for graph problems Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Problems/P50.hs b/src/Problems/P50.hs index b099a54..c227d7d 100644 --- a/src/Problems/P50.hs +++ b/src/Problems/P50.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Huffman codes Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Problems/P91.hs b/src/Problems/P91.hs index d979685..24d91f7 100644 --- a/src/Problems/P91.hs +++ b/src/Problems/P91.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Knight's tour Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Problems/P98.hs b/src/Problems/P98.hs index c4bc5f3..e3ed87b 100644 --- a/src/Problems/P98.hs +++ b/src/Problems/P98.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Nonograms Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Problems/P99.hs b/src/Problems/P99.hs index 0c6219f..2e63909 100644 --- a/src/Problems/P99.hs +++ b/src/Problems/P99.hs @@ -12,6 +12,7 @@ import Problems.Crosswords import qualified Solutions.P99 as Solution -- $setup +-- >>> :set -Wno-x-partial -- >>> import Data.Maybe (fromJust) -- >>> import Problems.Crosswords diff --git a/src/Solutions/P10.hs b/src/Solutions/P10.hs index 6af597c..2c33bff 100644 --- a/src/Solutions/P10.hs +++ b/src/Solutions/P10.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Run-length encoding of a list Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P11.hs b/src/Solutions/P11.hs index 6977a41..cc2f7e4 100644 --- a/src/Solutions/P11.hs +++ b/src/Solutions/P11.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Modified run-length encoding Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P36.hs b/src/Solutions/P36.hs index 1f77f5b..96d5289 100644 --- a/src/Solutions/P36.hs +++ b/src/Solutions/P36.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: List of prime factors and their multiplicities Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P44.hs b/src/Solutions/P44.hs index 138ae4f..46b299a 100644 --- a/src/Solutions/P44.hs +++ b/src/Solutions/P44.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Gaussian primes Copyright: Copyright (C) 2022 Yoo Chung diff --git a/src/Solutions/P50.hs b/src/Solutions/P50.hs index 00ebca8..0d17e24 100644 --- a/src/Solutions/P50.hs +++ b/src/Solutions/P50.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Huffman codes Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P79.hs b/src/Solutions/P79.hs index 2623624..9c462e2 100644 --- a/src/Solutions/P79.hs +++ b/src/Solutions/P79.hs @@ -8,7 +8,7 @@ Some solutions to "Problems.P79" of Ninety-Nine Haskell "Problems". -} module Solutions.P79 (calculatePostfix) where -import Control.Monad (guard, mzero) +import Control.Monad (mzero) import Control.Monad.Identity import Control.Monad.State import Control.Monad.Trans.Maybe @@ -70,6 +70,8 @@ push x = modify (x:) pop :: Calculation Integer pop = do xs <- get - guard $ not $ null xs - put $ tail xs - return $ head xs + case xs of + [] -> mzero + (x:xs') -> do + put xs' + return x diff --git a/src/Solutions/P82.hs b/src/Solutions/P82.hs index d504908..200cc30 100644 --- a/src/Solutions/P82.hs +++ b/src/Solutions/P82.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Cycles with a given vertex Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P84.hs b/src/Solutions/P84.hs index 3ddf342..7423025 100644 --- a/src/Solutions/P84.hs +++ b/src/Solutions/P84.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Construct minimum spanning tree Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P85.hs b/src/Solutions/P85.hs index 431b60c..171be2b 100644 --- a/src/Solutions/P85.hs +++ b/src/Solutions/P85.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Graph isomorphism Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P91.hs b/src/Solutions/P91.hs index e0bf605..1be8abb 100644 --- a/src/Solutions/P91.hs +++ b/src/Solutions/P91.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Knight's tour Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P92.hs b/src/Solutions/P92.hs index ed7e514..f85129d 100644 --- a/src/Solutions/P92.hs +++ b/src/Solutions/P92.hs @@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-} +{-# OPTIONS_GHC -Wno-x-partial #-} {- | Description: Graceful tree labeling diff --git a/src/Solutions/P97.hs b/src/Solutions/P97.hs index eaacbb8..abeb77a 100644 --- a/src/Solutions/P97.hs +++ b/src/Solutions/P97.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Sudoku Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P98.hs b/src/Solutions/P98.hs index 7105b47..c9cf170 100644 --- a/src/Solutions/P98.hs +++ b/src/Solutions/P98.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {- | Description: Nonograms Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P99.hs b/src/Solutions/P99.hs index 7574a03..8d6f4f2 100644 --- a/src/Solutions/P99.hs +++ b/src/Solutions/P99.hs @@ -153,7 +153,9 @@ findSites g orient = concatMap (evalState find . initial) $ zip [0..] g , fssChars = [] , fssLocs = [] } - step = modify $ \st -> st { fssSpots = tail $ fssSpots st + step = modify $ \st -> st { fssSpots = case fssSpots st of + [] -> error "no more spots" + (_:xs) -> xs , fssPos = 1 + fssPos st } @@ -289,7 +291,10 @@ guess' :: RandomGen g => Partial -> State g (Maybe Partial) guess' p = do tiebreakers <- do gen <- state split return (randoms gen :: [Int]) - let siteIndex = snd $ head $ sortOn count $ zip tiebreakers $ Map.keys $ candidates p + let sitePicks = sortOn count $ zip tiebreakers $ Map.keys $ candidates p + let siteIndex = snd $ case sitePicks of + (x:_) -> x + [] -> error "no more sites" wordList <- state $ randomPermute $ candidates p ! siteIndex state $ tryGuesses p siteIndex wordList where diff --git a/stack.yaml b/stack.yaml index f627bc1..3bf16ac 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,7 +5,7 @@ # Resolver to choose a 'specific' stackage snapshot or a compiler version. # A snapshot resolver dictates the compiler version and the set of packages # to be used for project dependencies. -resolver: lts-22.23 +resolver: nightly-2024-05-29 # User packages to be built. packages: diff --git a/test/Problems/P08Spec.hs b/test/Problems/P08Spec.hs index 4461238..a573a40 100644 --- a/test/Problems/P08Spec.hs +++ b/test/Problems/P08Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P09Spec.hs b/test/Problems/P09Spec.hs index dfe6270..d59cb15 100644 --- a/test/Problems/P09Spec.hs +++ b/test/Problems/P09Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P10Spec.hs b/test/Problems/P10Spec.hs index d20287b..d3d9c77 100644 --- a/test/Problems/P10Spec.hs +++ b/test/Problems/P10Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P11Spec.hs b/test/Problems/P11Spec.hs index edb1687..3bbfdeb 100644 --- a/test/Problems/P11Spec.hs +++ b/test/Problems/P11Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P19Spec.hs b/test/Problems/P19Spec.hs index 4982248..14e46c9 100644 --- a/test/Problems/P19Spec.hs +++ b/test/Problems/P19Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P23Spec.hs b/test/Problems/P23Spec.hs index 042a992..72d4637 100644 --- a/test/Problems/P23Spec.hs +++ b/test/Problems/P23Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P24Spec.hs b/test/Problems/P24Spec.hs index abcd0c2..eb545d2 100644 --- a/test/Problems/P24Spec.hs +++ b/test/Problems/P24Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P25Spec.hs b/test/Problems/P25Spec.hs index 9c55620..00a84ed 100644 --- a/test/Problems/P25Spec.hs +++ b/test/Problems/P25Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P38Spec.hs b/test/Problems/P38Spec.hs index 5970edc..e03ad67 100644 --- a/test/Problems/P38Spec.hs +++ b/test/Problems/P38Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P81Spec.hs b/test/Problems/P81Spec.hs index f29f71f..04bcb01 100644 --- a/test/Problems/P81Spec.hs +++ b/test/Problems/P81Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P82Spec.hs b/test/Problems/P82Spec.hs index 738405c..3c50a1c 100644 --- a/test/Problems/P82Spec.hs +++ b/test/Problems/P82Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P87Spec.hs b/test/Problems/P87Spec.hs index 718285f..d305e5f 100644 --- a/test/Problems/P87Spec.hs +++ b/test/Problems/P87Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P88Spec.hs b/test/Problems/P88Spec.hs index 41a2afa..b0ceea0 100644 --- a/test/Problems/P88Spec.hs +++ b/test/Problems/P88Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P91Spec.hs b/test/Problems/P91Spec.hs index ad5e70b..1b2a551 100644 --- a/test/Problems/P91Spec.hs +++ b/test/Problems/P91Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P97Spec.hs b/test/Problems/P97Spec.hs index f99d689..ff0be1c 100644 --- a/test/Problems/P97Spec.hs +++ b/test/Problems/P97Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P98Spec.hs b/test/Problems/P98Spec.hs index f40c434..20f56ec 100644 --- a/test/Problems/P98Spec.hs +++ b/test/Problems/P98Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P99Spec.hs b/test/Problems/P99Spec.hs index f4ce086..b38f23a 100644 --- a/test/Problems/P99Spec.hs +++ b/test/Problems/P99Spec.hs @@ -135,7 +135,8 @@ addToSolution g (w,x,y,False) -- I.e., we don't like sites that we didn't add ourselves. -- Reject grids which have 2x2 blank areas. isValid :: [[Maybe Char]] -> Bool -isValid g = all isValidRows $ zip g $ tail g +isValid [] = False +isValid g@(_:gs) = all isValidRows $ zip g gs where isValidRows ([], []) = True isValidRows (Just _ : Just _ : _, Just _ : Just _ : _) = False