aoc2018-0.1.0.0: Advent of Code 2018 solutions and auto-runner

Copyright(c) Justin Le 2018
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

AOC.Common

Contents

Description

Common functions for solutions

Synopsis

Documentation

module AOC.Util

iterateMaybe :: (a -> Maybe a) -> a -> [a] Source #

Iterate until a Nothing is produced

loopMaybe :: (a -> Maybe a) -> a -> a Source #

Apply function until Nothing is produced, and return last produced value.

(!!!) :: [a] -> Int -> a Source #

Strict (!!)

dup :: a -> (a, a) Source #

A tuple of the same item twice

scanlT :: Traversable t => (b -> a -> b) -> b -> t a -> t b Source #

scanl generalized to all Traversable.

scanrT :: Traversable t => (a -> b -> b) -> b -> t a -> t b Source #

scanr generalized to all Traversable.

firstRepeated :: Ord a => [a] -> Maybe a Source #

Lazily find the first repeated item.

freqs :: (Foldable f, Ord a) => f a -> Map a Int Source #

Build a frequency map

perturbations :: (a -> [a]) -> [a] -> [[a]] Source #

Collect all possible single-item perturbations from a given perturbing function.

perturbations (\i -> [i - 1, i + 1]) [0,10,100]

[ [-1,10,100]

, [ 1,10,100] , [ 0, 9,100] , [ 0,11,100] , [ 0,10, 99] , [ 0,10,101] ]

clearOut :: (Char -> Bool) -> String -> String Source #

Clear out characters not matching a predicate

maximumVal :: Ord b => Map a b -> Maybe (a, b) Source #

Get the key-value pair corresponding to the maximum value in the map

maximumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b) Source #

Get the key-value pair corresponding to the maximum value in the map, with a custom comparing function.

'maximumVal' == 'maximumValBy' 'compare'

minimumVal :: Ord b => Map a b -> Maybe (a, b) Source #

Get the key-value pair corresponding to the minimum value in the map

minimumValBy :: (b -> b -> Ordering) -> Map a b -> Maybe (a, b) Source #

Get the key-value pair corresponding to the minimum value in the map, with a custom comparing function.

'minimumVal' == 'minimumValBy' 'compare'

maximumValNE :: Ord b => NEMap a b -> (a, b) Source #

Version of maximumVal for nonempty maps.

maximumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b) Source #

Version of maximumValBy for nonempty maps.

minimumValNE :: Ord b => NEMap a b -> (a, b) Source #

Version of minimumVal for nonempty maps.

minimumValByNE :: (b -> b -> Ordering) -> NEMap a b -> (a, b) Source #

Version of minimumValBy for nonempty maps.

deleteFinite :: KnownNat n => Finite (n + 1) -> Finite (n + 1) -> Maybe (Finite n) Source #

Delete a potential value from a Finite.

foldMapPar :: Monoid b => (a -> b) -> [a] -> b Source #

foldMap, but in parallel.

foldMapPar1 :: Semigroup b => (a -> b) -> NonEmpty a -> b Source #

foldMap1, but in parallel.

meanVar :: Fractional a => Fold a (a, a) Source #

Fold for computing mean and variance

getDown :: Down a -> a Source #

2D Maps

type Point = V2 Int Source #

2D Coordinate

mannDist :: (Foldable f, Num a, Num (f a)) => f a -> f a -> a Source #

boundingBox :: (Foldable1 f, Applicative g, Ord a) => f (g a) -> V2 (g a) Source #

Find the minimum and maximum x and y from a collection of points.

Returns V2 (V2 xMin yMin) (V2 xMax yMax).

boundingBox' :: Foldable f => f Point -> Maybe (V2 Point) Source #

A version of boundingBox that works for normal possibly-empty lists.

newtype ScanPoint Source #

It's Point, but with a newtype wrapper so we have an Ord that sorts by y first, then x

Constructors

SP 

Fields

Instances
Eq ScanPoint Source # 
Instance details

Defined in AOC.Common

Num ScanPoint Source # 
Instance details

Defined in AOC.Common

Ord ScanPoint Source # 
Instance details

Defined in AOC.Common

Show ScanPoint Source # 
Instance details

Defined in AOC.Common

Generic ScanPoint Source # 
Instance details

Defined in AOC.Common

Associated Types

type Rep ScanPoint :: Type -> Type #

Hashable ScanPoint Source # 
Instance details

Defined in AOC.Common

type Rep ScanPoint Source # 
Instance details

Defined in AOC.Common

type Rep ScanPoint = D1 (MetaData "ScanPoint" "AOC.Common" "aoc2018-0.1.0.0-Hkhvhpmf68i25W661VmcCR" True) (C1 (MetaCons "SP" PrefixI True) (S1 (MetaSel (Just "_getSP") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Point)))

displayAsciiMap Source #

Arguments

:: Char

default tile

-> Map Point Char

tile map

-> String 

Orphan instances

(Ord k, Ord p) => Ixed (OrdPSQ k p v) Source # 
Instance details

Methods

ix :: Index (OrdPSQ k p v) -> Traversal' (OrdPSQ k p v) (IxValue (OrdPSQ k p v)) #

(Ixed (v a), Index (v a) ~ Int, IxValue (v a) ~ a) => Ixed (Vector v n a) Source # 
Instance details

Methods

ix :: Index (Vector v n a) -> Traversal' (Vector v n a) (IxValue (Vector v n a)) #