- December 30th, 2015: You have a string of 'digits' in base whatever to convert to an Int
debase :: [Int] -> Int -> Int
debase [12,21,3] 26 ~> 8661
Define debase - Gautier DI FOLCO @gautier_difolco
import Data.Bifunctor
debase = curry (sum . uncurry (zipWith (*)) . bimap reverse (flip iterate 1 . (*))) - bazzargh @bazzargh
debase a b = sum $ zipWith (*) (reverse a) (map (b^) [0..]) - obadz @obadzz
or debase l b = foldl (\ p n -> p * b + n) 0 l - bazzargh @bazzargh
that's better than mine. how about:
flip (foldl1 . ((+) .) . (*)) - December 12th, 2015: #math You have this sequence: [1,1,1,1,1,1,2,1,1,1,3,3] What is this pattern? Is there one? Write #haskell to generate this list.
- December 3rd, 2015: Lens-y again Points-free-itize the following correctName :: Row -> Row correctName r = set lastName (init (view lastName r)) r
- December 3rd, 2015: Let's get a little lens-y with this one: accumer :: Getter a t a -> t -> [a] -> [a] accumer f s acc = ans where ans = view f s:acc
- Define the curried-accumer function that curries away the acc-argument.
- What would the curried definition be if the function type were: accumer :: Getter a t a -> t -> Set a -> Set a
- December 3rd, 2015: define minimax :: Ord eh => eh -> (eh, eh) -> (eh, eh) such that, e.g.: minimax 1 (2,3) ~> (1,3) minimax 10 (2,3) ~> (2,10)
- Thomas Dietert @thomasdietert In that case, minimax n (x,y) = (minimum [n,x,y], maximum [n,x,y])
- joomy @cattheory minimax = liftM2 (***) min max
- December 1st, 2015: define (->>) :: (a -> m ()) -> (a -> m ()) -> a -> m () All monadic effects must be evaluated.
- Jérôme @phollow (->>) f g a = f a >> g a
- then liftM2 (>>)
- Nicoλas @BeRewt but the full applicative is: liftA2 (*>)
Incorporates strong typing over predicate logic programming, and, conversely, incorporates predicate logic programming into strongly typed functional languages. The style of predicate logic is from Prolog; the strongly typed functional language is Haskell.
Tuesday, January 5, 2016
December 2015 1HaskellADay 1-Liners
One-liners
Monday, January 4, 2016
December 2015 1HaskellADay Problems and Solutions
December 2015
- December 30th, 2015: For today's #haskell problem we convert valid airport IATA codes to ints and back http://lpaste.net/9126537884587786240 And a Happy New Year solution: http://lpaste.net/2748656525433110528 Safe travels should you be Haskelling by air!
- December 28th, 2015: So, remember ADVENT? What happens when your INV becomes full? Today's #haskell problem looks at that http://lpaste.net/5153847668711096320
- December 23rd, 2015: Warm and fuzzy December, so we have a warm and fuzzy #haskell problem for today http://lpaste.net/6855091060834566144
- December 21st, 2015: For today's #haskell problem we are to deduce stock splits using LOGIC and SCIENCE http://lpaste.net/7920293407518359552
- December 18th, 2015: Today's #haskell problem... 'may' be thematic with that 'Star ...' what was the name of that movie? http://lpaste.net/7186856307830292480 Gosh! Star ... something! eh, whatevs: just let the Wookie win (always the best policy) http://lpaste.net/4229765238565634048
- December 17th, 2015: For today's #haskell problem we look at reporting out periodically on an investment and, BONUS! charting it! http://lpaste.net/638111979885559808 And we've charted our AAPL investment growth, too! http://lpaste.net/5472780506909114368
- December 16th, 2015: For (coming onto) today's #haskell problem we demask the masked data to unmaskify it, yo! http://lpaste.net/3793517022239784960 And then the solution unmasked that masked data! (that's convenient.) http://lpaste.net/5286190256939335680
- December 15th, 2015: So yesterday we masked some rows, but what happened to the masking dictionary? Today's #haskell problem we save it http://lpaste.net/7703498271758483456 Ah! So that's where that cipher went! http://lpaste.net/2548817005729808384
- December 14th, 2015: We look at a way of masking data for today's #haskell problem http://lpaste.net/4428582328419221504 And the solution gives us some lovely masked rows http://lpaste.net/7169250386480463872
- December 11th, 2015: Today's #haskell problem asks: WHAT DOES THE TRANSFORMED JSON SAY! http://lpaste.net/5253460432890363904 (okay, that was weaksauce)
- December 10th, 2015: For today's #Haskell problem we try to find relevancy in our daily lives http://lpaste.net/4994238781251911680 ...well, in #JSON, which is the same thing.
- December 9th, 2015: Today's #haskell problem asks you to read in some rows of #JSON http://lpaste.net/3949063995918385152 We'll be looking into this data set through the week "Watcha readin'?" "JSON." "Cool! ... No, ... wait." http://lpaste.net/218583096285462528
- December 8th, 2015: My main man, magic Mike (m^5 to his friends) said: "You're doing it wrong."Do it right for today's #haskell problem http://lpaste.net/6186236014281883648 A first stab at the solution, not taking into account splits, is posted at http://lpaste.net/6854975053767901184 And the split-adjusted solution here: http://lpaste.net/2656933684896071680 ~3700%-gain. It's time for me to sing the "You're the Top"-song to @MacNN_Mike
- December 7th, 2015: In today's #haskell problem we cry «On y va!» and have at it! http://lpaste.net/5243343693259210752 En garde, you pesky investment problem, you! The solution shows Dr. Evil does NOT get ONE MILLION DOLLARS! http://lpaste.net/177540921380831232 Nor piranhas with laser beams on their heads, either.
- December 4th, 2015: We write a web-proxy to help out poor, little Ajax go cross domain for today's #haskell problem http://lpaste.net/5120963316033781760
- December 3rd, 2015: We meet the Ip-man for today's #haskell problem. Hiya! http://lpaste.net/8926203451507998720 Today's solution shares a little-known fact http://lpaste.net/5525895581479731200 AND ALSO uses <$> as well! Is there a weekly limit on these thingies?
- December 2nd, 2015: Synthetic data generation for today's #haskell problem http://lpaste.net/4208367754446635008 NOT ONLY did we write a Synthetic data generator in a day http://lpaste.net/6059310371951345664 but we learned all 50 states AND used <$> and <*> – BONUS!
- December 1st, 2015: In today's #haskell problem, we see @geophf lose his cool. http://lpaste.net/6645397898311761920 No... wait... That's not news now, is it. (RID analysis). Unwordin' down-low on the arrr-eye-dee, LIKE A GANGSTA! http://lpaste.net/7371239202307964928
Subscribe to:
Posts (Atom)