Tuesday, June 14, 2016

May 2016 1Liners

  • May 24th, 2016:
    Given f :: a -> [a] -> b, g :: a -> c
    Write h :: c -> [c] -> b, point-free, in terms of f and g
    where h x y = f (g x) (map g y)
  • May 16th, 2016: The next 3 #1Liner are of a piece, using
    data CmpV a =
       Vec { len :: Int, top :: a,  elts :: [a],
             cmp :: CmpV a -> CmpV a -> Ordering }
    • Give the point-free definition of:
      twoVs :: CmpV a -> CmpV b -> ([a], [b])
    • instance Ord (CmpV a) where
         compare v1 = uncurry (cmp v1) .  (v1,)

      Make compare point-free by removing v1 from above definition
    • An Ord-instance needs an Eq-instance:
      instance Eq a => Eq (CmpV a) where
         v1 == v2 = elts v1 == elts v2

      point-free-itize (==)
  • May 16th, 2016: You have the following lambda:
    \x y -> x == y || fn x y
    where fn :: a -> a -> Bool
    • obadz @obadzz without any fancy uses of the (a ->) Applicative :)
      curry $ foldr (||) False . flip map [(==), fn] . flip uncurry
    • obadz @obadzz with fancy use of (a ->) Applicative :)
      curry $ liftA2 (||) (uncurry (==)) (uncurry fn)
    • Noah Luck Easterly @walkstherain
      curry $ uncurry (||) . (uncurry (==) &&& uncurry fn)
  • May 5th, 2016:
    sames :: Eq a => [a] -> [a] -> Int
    Counts equal values at the same indices in two lists.
    What is the point-free definition?
    • joomy @cattheory
      sames = curry (length . filter (uncurry (==)) . uncurry zip)
    • bazzargh @bazzargh and then Fatih Karakurt @karakfa
      ((length . filter id) .) . zipWith (==)
    • me: sum <<- fromenum="" li="" nbsp="" zipwith="">
    • Noah Luck Easterly @walkstherain
      sames = ((sum . map fromEnum) .) . zipWith (==)
      • `getSum . foldMap (Sum . fromEnum)` seems better than `foldr (bool id succ) 0` but both satisfy `[Bool] -> Int`
    • Андреев Кирилл @nonaem00
      let it = (length .) . (filter id .)  . zipWith (==)

Wednesday, June 1, 2016

May 2016 1HaskellADay Problems and Solutions

May 2016

  • May 31st, 2016: Today's #haskell problem gets a subsequence of DNA from ... DNA! http://lpaste.net/1527607897389793280 Today's #haskell solution: DNA subsequence GOT http://lpaste.net/5828328688629841920
  • May 30th, 2016: We find the number of RNA strands that can generate a protein ... modulo reasonableness for today's #haskell problem http://lpaste.net/7114368903530151936 Today's #haskell solution shows us there are 'more than a few' RNA strands to compose some proteins http://lpaste.net/3827843057999413248
  • May 27th, 2016: For today's #haskell problem we sing: No woman, Nah Trie! http://lpaste.net/8137189406290214912 Or: Breath-first Trie Traversal via the branches. We take breathing-lessons for today's #haskell solution http://lpaste.net/2088953736360624128
  • May 26th, 2016: For today's #haskell problem we label the nodes of a Trie ... http://lpaste.net/658981668358455296 or at least we ... TRIE to! *groan Today's #haskell solution is a depth-first traversal of a Triehttp://lpaste.net/7964088321452277760
  • May 25th, 2016: Today's #haskell problem ask you to exercise your probability muscles and look at some allele-pairingshttp://lpaste.net/7098281613896712192 That's all.
  • May 24th, 2016: Reverse Palindromes in DNA strands?Yes. http://lpaste.net/4547532761941934080 Today's #haskell problem. Turns out there are lots of palindromes in DNA strands as today's #haskell solution shows. http://lpaste.net/8959978868165312512 Go figure.
  • May 23rd, 2016: Splice, splice, baby! We get all Vanilla Ice with RNA with today's #haskell problem http://lpaste.net/2811938573572374528 We get our protein when with today's hand-rolled List-y-(\\) #haskell solution http://lpaste.net/5823105188059152384
  • May 20th, 2016: For today's #haskell problem we consider the weighty matter of ... weighing matter http://lpaste.net/7500383126527410176 The weight's the thing Wherein I'll catch the conscience of the King ... no ... weight ...Today's #haskell solution http://lpaste.net/7743348996965400576
  • May 19th, 2016: Today's #haskell problem looks at the Carmina Buranahttp://lpaste.net/684224423812661248 ... uh, no, it doesn't: Open Reading Frames.  Today's #haskell solution sequences DNA strands to proteins http://lpaste.net/792645775074000896
  • May 18th, 2016: If at first you do not succeed, trie and trie again today's #haskell problem http://lpaste.net/8558987235213443072 #trie #datatype 
  • May 17th, 2016: "Houston. We have a problem." #bigdata factors into today's #haskell problem of longest monotonic sequenceshttp://lpaste.net/6778179741435297792
  • May 16th, 2016: Today's #Haskell problem asks for longest monotonic increasing/decreasing sequences ... in the small ... http://lpaste.net/7252474989977272320 So, the #haskell solution works against small data set, but since it's bifurcating, against large data sets? ... http://lpaste.net/7003206401061289984
  • May 13th, 2016: #Rosalind is impatient. She doesn't have all day! Let's find a real-world solution to today's #haskell problem http://lpaste.net/8254705170412208128 Finding the longest common gene subsequence of 100 strands each 1000 nucleotides long in #haskell http://lpaste.net/2468395370904813568 Can you find faster?
  • May 12th, 2016: We propose a little problem from Set Theory for today's #haskell problem http://lpaste.net/4050317579338645504 And we have today's #haskell in-a-perfect-world solution of the set-intersection of all subsequenceshttp://lpaste.net/1682855623517011968
  • May 11th, 2016: Today's #haskell problem is all about the inods ... not 'inodes,' but 'internal nodes of an unrooted binary tree.' http://lpaste.net/7455193258755358720 "inods?" you say? "Of an unrooted binary tree?" you say? That would be pred . pred for today's #haskell solution http://lpaste.net/4766815087493120000
  • May 10th, 2016: For today's #haskell problem we take it to the next level, see? and get variable-length strings as enumerated tokens http://lpaste.net/3180555571975684096 We pulled the powerSet Set.fromList Set.toList switcheroo for today's #haskell solution. http://lpaste.net/7501776843414962176
  • May 9th, 2016: For today's #haskell problem we sing our A, B, Cs ... #Rosalind-style! http://lpaste.net/1445499963915108352 Today's #Haskell solution enumerates lexed tokens http://lpaste.net/503582828101894144
  • May 6th, 2016: For today's #haskell problem we ask #Rosalind and she says 'Permutations.' So that's what we do! http://lpaste.net/6558920694606856192 This is the dawning of the age of Aquarius! "Hair" a movie about perms for today's #haskell solution http://lpaste.net/934285743432400896 @NickiElson3D 
  • May 5th, 2016: Today's #haskell problem: p-distance Matriceshttp://lpaste.net/818771459840147456 Believe you me: you will get a LOT of continued employment with these Today's #haskell solution is filed under #jobsecurity http://lpaste.net/5076187573303377920 #distanceMatrix
  • May 4th, 2016: Today's #haskell problem we look at completing a graph into the Tree of Life http://lpaste.net/1315899789614776320 #Rosalind Today's #haskell solution is graph-y, or also take the approach of @bazzargh http://lpaste.net/1052721051462533120
  • May 3rd, 2016: Today's #haskell problem looks at overlapping graphs, specifically for DNA strands from rosalind.info http://lpaste.net/8920617631791185920 Did you know a list is a graph? Today's #haskell solution was an elaboration of `isSuffixOf` http://lpaste.net/5785600391169179648 #Rosalind 
  • May 2nd, 2016: For today's #haskell problem we look at transforming our data into d3: "Data-driven document"-JSONhttp://lpaste.net/224067301371019264 For the #haskell solution we get a bird's-eye view of the Top5s stocks http://lpaste.net/7060337987313205248