Tuesday, January 31, 2017

January 2017 1HaskellADay problems and solutions

Thursday, January 19, 2017

December 2016 1HaskellADay 1Liners

  • December 22nd, 2016:  f :: (Either a b, c) -> Either (a, c) (b, c), define f, snaps for elegance, e.g.: f (Left 4, "Hi") = Left (4, "Hi")
    • bazzargh @bazzargh uncurry (flip (join bimap . (,) ))
      • Denis Stoyanov @xgrommx need (Left 4, "Hi") = Left (4, "Hi") but your version Left ("Hi", 4)
    • Thomas D @tthomasdd Do tuple sections count? do I have access to Data.Bifunctor?
      • f (eab,c) = bimap (,c) (,c) eab
    • SocialJusticeCleric @walkstherain uncurry $ either ((Left .).(,)) ((Right .).(,))
    • Denis Stoyanov @xgrommx or f (e, a) = (join bimap (\x -> (x, a))) e
    • Nickolay Kudasov @crazy_fizruk most elegant IMO:
      f (Left a, c) = Left (a, c)
      f (Right b, c) = Right (b, c)
  • December 22nd, 2016: define a function that writes out an infinite, alternating stream of 1's and 0's as below. 
    • Philipp Maier @AkiiZedd mapM putStrLn $ join $ repeat ["0","1"]
      • Eyal Lotem @EyalL join . repeat = cycle?
    • mavant @mavant f = putStr "10" >> f
    • Eyal Lotem @EyalL mapM putStrLn $ cycle ["0","1"]
  • December 10th, 2016:
    startsWith :: [String] -> String
    points-free so that:
    startsWith ["ΜΗΛΟΝ", "ΗΔΟΝΗ"] = "ΛΟ"
    That is: (length list)+1 Char of each word
    • SocialJusticeCleric @walkstherain 
      • I prefer `uncurry (!!) . (Data.List.transpose &&& length)`
      • but `map . flip (!!) . length =<< id` only uses the Prelude
    • Nick @crazy_fizruk zipWith (!!) <*> repeat . length

Sunday, January 1, 2017

December 2016 1HaskellADay Problems and Solutions

Saturday, December 10, 2016

October 2016 1Liner 1HaskellADay problem and solutions

  • October 21st, 2016:
    You have l1 :: [(v, [(k, x)])]
    You need the transformation l2 :: [(k, [(v, x)])]
    Redistribute v and k in one line
    Props for elegance
    • Francisco T @aiceou redist xs = fromListWith (++) $ concat $ (map f xs) where f (a,ys) = map (\(x,y) -> (x,[(a,y)])) ys ... but k has to be 'Ord'

Wednesday, November 30, 2016

November 2016 1HaskellADay Problems and Solutions

Tuesday, November 1, 2016

October 2016 1HaskellADay Problems and Solutions

Saturday, October 22, 2016

September 2016 1HaskellADay 1Liners Problems and Solutions

  • September 15th, 2016:
    Given [1..n], create an infinite list of lists [[1.. n], [n+1 ... n+n], [n+n+1 ... 3n], ...]
    counting :: [Integer] -> [[Integer]]
    • joomy @cattheory
      counting = (map . (+) . fromIntegral . length) >>= iterate
  • September 30th, 2016: The reverse of August's one-liner:
    f :: (Maybe a, b) -> Maybe (a,b)
    define f. Snaps for elegance.