Monday, December 3, 2018

November 2018 1HaskellADay Problems and Solutions

Friday, November 2, 2018

October 2018 1HaskellADay Problems and Solutions

Friday, October 5, 2018

August 2018 1HaskellADay problems and solutions

Thursday, August 2, 2018

July 2018 1HaskellADay Problems and Solutions

Tuesday, July 3, 2018

June 2018 1HaskellADay Problems and Solutions

Monday, June 4, 2018

May 2018 1HaskellADay Problems and Solutions

Thursday, May 3, 2018

April 2018 1HaskellADay Problems and Solutions

Friday, April 13, 2018

February 2018 1 Liner 1HaskellADay Problems and Solutions

  • February 8th, 2018: We have maybe :: b -> (a -> b) -> Maybe a -> b. But we don't have list? Or do we? Define list:
    list :: b -> ([a] -> b) -> [a] -> b
    list nullanswer flist lst = undefined
  • BONUS: Both Maybe a and [a] are binary types, ... so is MonadPlus:

    Maybe a = Nothing | Just a
    List a = Cons a (List a) | Nil
    MonadPlus m => mzero | m a `mplus` m a

    Is there some generalization that maybe and list are functions of? What is that generalization?
  • February 6th, 2018:
    You have f :: a -> [b] -> [c]
    But instead of just one a you have [a]
    Define g :: [a] -> [b] -> [c]
    in terms of f
    • Daniel @leptonyu g as bs = foldl (\xs a -> f a bs ++ xs) [] as
    • ptdr_bot @m0rth0n g as bs = flip f bs =<< as
    • Victoria C @ToriconPrime g as bs = concat $ fmap ($ bs) (fmap f as)
    • matt @themattchan g = flip $ concatMap . flip f
    • Nicoλas @BeRewt g = flip (flip (>>=) . flip f) Or: g as bs = as >>= flip f bs
    • Sangeet Kar @sangeet_kar g = foldMap f

Monday, April 2, 2018

March 2018 1HaskellADay problems and solutions

Thursday, March 1, 2018

February 2018 1HaskellADay problems and solutions

Tuesday, February 6, 2018

January 2018 1Liner 1HaskellADay problems and solutions

  • January 8th, 2018: from Nicoλas‏ @BeRewt
    A small @1HaskellADay, old-school. Define foo:

    > foo 3 [1..5]
    [([1,2,3], 4), ([2,3,4], 5)]

    > foo 2 [1..4]
    [([1,2], 3), ([2,3], 4)]

    > foo 2 [1..20]
    [([1,2],3), ([2,3],4), ..., ([18,19],20)]

    > foo 20 [1..2]
    []
    • Demiurge With a Teletype @mrkgrnao
      foo n
        = tails
        # filter (length # (> n))
        # map (splitAt n # second head)

      (#) = flip (.)
    • Andreas Källberg @Anka213
      I haven't tested it, but this should work:
      foo n xs = [ (hd,x) | (hd , x:_) <- n="" splitat=""> tails xs ]
    • <- n="" splitat="">Nicoλas @BeRewt foo n = zip <$> fmap (take n) . tails <*> drop n
  • January 5th, 2018: You have the following DAG-paths:

    a -> b -> c -> e
    a -> b -> d -> e
    q -> r -> s
    w -> x
    y -> z

    and many more.

    From a path, provide a bi-directional encoding* given maximum graph depth is, say, 7, max number of roots is, say, 10, and max number of nodes is, say, 1000.
    • *bi-directional encoding of a graph path:

      DAG path -> enc is unique for an unique DAG path
      enc -> DAG path yields the same DAG path that created the unique enc.

      *DAG: "Directed, acyclic graph."
  • January 5th, 2018: given s :: Ord k => a -> (k,[v])

    define f using s

    f :: Ord k => [a] -> Map k [v]

    with no duplicate k in [a]
    • Christian Bay @the_greenbourne f = foldr (\e acc -> uncurry M.insert (s e) acc) M.empty
      • me: you can curry away the acc variable easily
      • Christian Bay @the_greenbourne You're right :)
        f = foldr (uncurry M.insert . s) M.empty
    • Bazzargh @bazzargh fromList.(map s) ?
      • me: Yuppers

Wednesday, January 31, 2018

January 2018 1HaskellADay Problems and Solutions

Friday, January 5, 2018

December 2017 1HaskellADay 1Liners problems and solutions

  • December 29th, 2017:
    given f :: Monad m => n -> a -> m (Maybe b)
    define g :: Monad m => n -> a -> m (a, Maybe b)
    using f and ... arrows? Kleisli category?
    • Bazzargh @bazzargh (\n a->liftM ((,) a) (f n a)) ... according to pointfree.io, that's `liftM2 fmap (,) . f` but I can't pretend to get the transformation
  • December 29th, 2017:
    given f :: a -> b
    define g :: [a] -> [Maybe c] -> [(b, c)]

    >>> g [1,2,3] [Just 7, Nothing, Just 10]
    [("1",7),("3",10)]

    when f = show
    • matt @themattchan
      g = catMaybes ... zipWith (fmap . (,) . f)
      where (...) = (.).(.)
    • garrison @GarrisonLJ g a b = map (f.id***fromJust) . filter (isJust . snd) $ zip a b
    • TJ Takei @karoyakani g = (catMaybes .) . zipWith ((<$>) . (,) . f)
  • December 29th, 2017: define f :: [(a,b)] -> ([a], [b])
    • Андреев Кирилл @nonaem00 and matt @themattchan unzip
    • Victoria C @ToriconPrime f = fmap fst &&& fmap snd
      • (in a vacuum, a more general type signature would be inferred, but the compiler limits itself as instruct)

Tuesday, January 2, 2018

December 2017 1HaskellADay problems and solutions